1<?php 2 3require_once(PHPGW_INCLUDE_ROOT . SEP . 'sitemgr' . SEP . 'inc' . SEP . 'class.module.inc.php'); 4 5 class Modules_BO 6 { 7 var $so; 8 9 function Modules_BO() 10 { 11 //all sitemgr BOs should be instantiated via a globalized Common_BO object, 12 $this->so = CreateObject('sitemgr.Modules_SO', true); 13 } 14 15 function getmoduleid($modulename) 16 { 17 return $this->so->getmoduleid($modulename); 18 } 19 20 function getmodule($module_id) 21 { 22 return $this->so->getmodule($module_id); 23 } 24 25 function savemoduleproperties($module_id,$element,$contentarea,$cat_id) 26 { 27 $module = $this->getmodule($module_id); 28 $moduleobject = $this->createmodule($module['module_name']); 29 if ($moduleobject->validate_properties($element)) 30 { 31 $this->so->savemoduleproperties($module_id,$element,$contentarea,$cat_id); 32 } 33 } 34 35 function deletemoduleproperties($module_id,$contentarea,$cat_id) 36 { 37 $this->so->deletemoduleproperties($module_id,$contentarea,$cat_id); 38 } 39 40 41 //this is identical to CreateObect in phpgwapi/functions.inc.php, but looks into sitemgr/modules instead of appname/inc 42 function createmodule($modulename) 43 { 44 45 global $phpgw_info, $phpgw; 46 47 //if (is_object(@$GLOBALS['phpgw']->log) && $class != 'phpgwapi.error' && $class != 'phpgwapi.errorlog') 48 //{ 49 //$GLOBALS['phpgw']->log->write(array('text'=>'D-Debug, dbg: %1','p1'=>'This class was run: '.$class,'file'=>__FILE__,'line'=>__LINE__)); 50 //} 51 52 /* error_reporting(0); */ 53 //list($appname,$classname) = explode(".", $class); 54 55 $classname = 'module_' . $modulename; 56 57 if (!isset($GLOBALS['phpgw_info']['flags']['included_classes'][$classname]) || 58 !$GLOBALS['phpgw_info']['flags']['included_classes'][$classname]) 59 { 60 if(@file_exists(PHPGW_INCLUDE_ROOT.'/sitemgr/modules/class.'.$classname.'.inc.php')) 61 { 62 include(PHPGW_INCLUDE_ROOT.'/sitemgr/modules/class.'.$classname.'.inc.php'); 63 $GLOBALS['phpgw_info']['flags']['included_classes'][$classname] = True; 64 } 65 else 66 { 67 $GLOBALS['phpgw_info']['flags']['included_classes'][$classname] = False; 68 } 69 } 70 if($GLOBALS['phpgw_info']['flags']['included_classes'][$classname]) 71 { 72 if ($p1 == '_UNDEF_' && $p1 != 1) 73 { 74 eval('$obj = new ' . $classname . ';'); 75 } 76 else 77 { 78 $input = array($p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9,$p10,$p11,$p12,$p13,$p14,$p15,$p16); 79 $i = 1; 80 $code = '$obj = new ' . $classname . '('; 81 while (list($x,$test) = each($input)) 82 { 83 if (($test == '_UNDEF_' && $test != 1 ) || $i == 17) 84 { 85 break; 86 } 87 else 88 { 89 $code .= '$p' . $i . ','; 90 } 91 $i++; 92 } 93 $code = substr($code,0,-1) . ');'; 94 eval($code); 95 } 96 /* error_reporting(E_ERROR | E_WARNING | E_PARSE); */ 97 return $obj; 98 } 99 } 100 101 102 function getallmodules() 103 { 104 return $this->so->getallmodules(); 105 } 106 107 function findmodules() 108 { 109 $incdir = PHPGW_SERVER_ROOT . SEP . 'sitemgr' . SEP . 'modules'; 110 if (is_dir($incdir)) 111 { 112 $d = dir($incdir); 113 while ($entry = $d->read()) 114 { 115 if (preg_match ("/class\.module_(.*)\.inc\.php$/", $entry, $module)) 116 { 117 $modulename = $module[1]; 118 $moduleobject = $this->createmodule($modulename); 119 if ($moduleobject) 120 { 121 $this->so->registermodule($modulename,$moduleobject->description); 122 } 123 } 124 } 125 $d->close(); 126 } 127 } 128 129 function savemodulepermissions($contentarea,$cat_id,$modules) 130 { 131 $this->so->savemodulepermissions($contentarea,$cat_id,$modules); 132 } 133 134 //this function looks for a configured value for the combination contentareara,cat_id 135 function getpermittedmodules($contentarea,$cat_id) 136 { 137 return $this->so->getpermittedmodules($contentarea,$cat_id); 138 } 139 140 //this function looks for a module's configured propertiese for the combination contentareara,cat_id 141 //if module_id is 0 the fourth argument should provide modulename 142 function getmoduleproperties($module_id,$contentarea,$cat_id,$modulename=False) 143 { 144 return $this->so->getmoduleproperties($module_id,$contentarea,$cat_id,$modulename); 145 } 146 147 //this function calculates the permitted modules by asking first for a value contentarea/cat_id 148 //if it does not find one, climbing up the category hierarchy until the site wide value for the same contentarea 149 //and if it still does not find a value, looking for __PAGE__/cat_id, and again climbing up until the master list 150 function getcascadingmodulepermissions($contentarea,$cat_id) 151 { 152 $cat_ancestorlist = ($cat_id != CURRENT_SITE_ID) ? $GLOBALS['Common_BO']->cats->getCategoryancestorids($cat_id) : array(); 153 $cat_ancestorlist[] = CURRENT_SITE_ID; 154 155 $cat_ancestorlist_temp = $cat_ancestorlist; 156 157 do 158 { 159 $cat_id = array_shift($cat_ancestorlist_temp); 160 161 while($cat_id !== NULL) 162 { 163 $permitted = $this->so->getpermittedmodules($contentarea,$cat_id); 164 if ($permitted) 165 { 166 return $permitted; 167 } 168 $cat_id = array_shift($cat_ancestorlist_temp); 169 } 170 $contentarea = ($contentarea != "__PAGE__") ? "__PAGE__" : False; 171 $cat_ancestorlist_temp = $cat_ancestorlist; 172 } while($contentarea); 173 return array(); 174 } 175 176 //this function calculates the properties by climbing up the hierarchy tree in the same way as 177 //getcascadingmodulepermissions does 178 function getcascadingmoduleproperties($module_id,$contentarea,$cat_id,$modulename=False) 179 { 180 $cat_ancestorlist = ($cat_id != CURRENT_SITE_ID) ? $GLOBALS['Common_BO']->cats->getCategoryancestorids($cat_id) : array(); 181 $cat_ancestorlist[] = CURRENT_SITE_ID; 182 183 $cat_ancestorlist_temp = $cat_ancestorlist; 184 185 do 186 { 187 $cat_id = array_shift($cat_ancestorlist_temp); 188 189 while($cat_id !== NULL) 190 { 191 $properties = $this->so->getmoduleproperties($module_id,$contentarea,$cat_id,$modulename); 192 //we have to check for type identity since properties can be NULL in case of unchecked checkbox 193 if ($properties !== false) 194 { 195 return $properties; 196 } 197 $cat_id = array_shift($cat_ancestorlist_temp); 198 } 199 $contentarea = ($contentarea != "__PAGE__") ? "__PAGE__" : False; 200 $cat_ancestorlist_temp = $cat_ancestorlist; 201 } while($contentarea); 202 } 203 }