| [ PHPXref.com ] | [ Generated: Sun Jul 20 18:38:40 2008 ] | [ METAjour 2.1 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @author Jan H. Andersen <jha@ipwsystems.dk> 4 * @author Martin R. Larsen <mrl@ipwsystems.dk> 5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s} 6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 7 * @package METAjour 8 * @subpackage view 9 */ 10 11 /** 12 * Helper class focused on creating misc form elements 13 * It is used only by the views, but is not descended from basic_view so no 14 * information about context, objectid etc is available in the class. Any 15 * information must be passed as parameters to the methods. Only userhandler 16 * can be expected. 17 */ 18 19 class basic_field { 20 var $userhandler; 21 var $view; 22 function basic_field(&$view) { 23 $this->view = &$view; 24 $this->userhandler =& GetUserHandler(); 25 } 26 27 function userSelection($objectid, $fieldname) { 28 $result .= '<select name="'.$fieldname.'[]" style="width: 260px;" size=8 multiple>'; 29 $arr = array(); 30 if ($objectid) { 31 $obj = owRead($objectid); 32 $arr = $obj->getmembers(); 33 } 34 $cobj = owNew('user'); 35 $cobj->setsort_col('name'); 36 $cobj->setfilter_nameonly(true); 37 $cobj->setlistaccess(true); 38 $cobj->listobjects(); 39 $z = 0; 40 $sel = ''; 41 if (!is_array($arr)) $sel = ' SELECTED'; 42 $result .= '<option value=""'.$sel.'>'.$this->view->gl('select_none').'</option>'; 43 while ($z < $cobj->elementscount) { 44 $sel = ''; 45 if (is_array($arr) && in_array($cobj->elements[$z]['objectid'],$arr)) $sel = ' SELECTED'; 46 $result .= '<option value="'.$cobj->elements[$z]['objectid'].'"'.$sel.'>'.$cobj->elements[$z]['name'].'</option>'; 47 $z++; 48 } 49 unset($cobj); 50 $result .= '</select>'; 51 return $result; 52 } 53 54 function usergroupSelection($objectid, $fieldname) { 55 $result .= '<select name="'.$fieldname.'[]" style="width: 260px;" size=8 multiple>'; 56 $arr = array(); 57 if ($objectid) { 58 $obj = owRead($objectid); 59 $arr = $obj->getgroupmemberships($objectid); 60 } 61 $cobj = owNew('usergroup'); 62 $cobj->setsort_col('name'); 63 $cobj->setfilter_nameonly(true); 64 $cobj->setlistaccess(true); 65 $cobj->listobjects(); 66 $z = 0; 67 while ($z < $cobj->elementscount) { 68 $sel = ''; 69 if (is_array($arr) && in_array($cobj->elements[$z]['objectid'],$arr)) $sel = ' SELECTED'; 70 $result .= '<option value="'.$cobj->elements[$z]['objectid'].'"'.$sel.'>'.$cobj->elements[$z]['name'].'</option>'; 71 $z++; 72 } 73 unset($cobj); 74 $result .= '</select>'; 75 return $result; 76 } 77 78 function categorySelection($objectid, $fieldname, $datatype = '') { 79 $result .= '<select name="'.$fieldname.'[]" style="width: 260px;" size=8 multiple>'; 80 $result .= '<option value="0">'.$this->view->gl('select_none').'</option>'; 81 if ($objectid != NULL) $obj = owRead($objectid); 82 $cobj = owNew('category'); 83 $cobj->setsort_col('name'); 84 $cobj->setlistaccess(true); 85 $cobj->listobjects(); 86 $z = 0; 87 /* usually we want to display the categories available to the current 88 datatype, but in some situations we want to display the categories 89 available to a different datatype, for instance when we import 90 data using sys_view_import */ 91 if ($datatype == '') $datatype = $this->view->otype; 92 while ($z < $cobj->elementscount) { 93 if ($cobj->elements[$z]['datatype'] == $datatype || $cobj->elements[$z]['datatype'] == '') { 94 $sel = ''; 95 if ($objectid != NULL && $obj->ismember($cobj->elements[$z]['objectid'])) $sel = ' SELECTED'; 96 $result .= '<option value="'.$cobj->elements[$z]['objectid'].'"'.$sel.'>'.$cobj->elements[$z]['name'].'</option>'; 97 } 98 $z++; 99 } 100 unset($cobj); 101 102 $result .= '</select>'; 103 return $result; 104 } 105 106 function webAccessSelection($objectid, $fieldname) { 107 $result .= '<select name="'.$fieldname.'[]" style="width: 260px;" size=8 multiple>'; 108 $arr = array(); 109 if ($objectid != NULL) { 110 $obj = owRead($objectid); 111 $tarr = $obj->getaccess(); 112 } 113 if (is_array($tarr)) { 114 foreach ($tarr as $carr) { 115 if ($carr['user_read']) $arr[] = $carr['user_read']; 116 if ($carr['group_read']) $arr[] = $carr['group_read']; 117 } 118 } 119 120 $cobj = owNew('user'); 121 $cobj->setsort_col('name'); 122 $cobj->setfilter_nameonly(true); 123 $cobj->setlistaccess(true); 124 $cobj->listobjects(); 125 $z = 0; 126 $sel = ''; 127 if (!is_array($tarr)) $sel = ' SELECTED'; 128 $result .= '<option value=""'.$sel.'>'.$this->view->gl('select_all').'</option>'; 129 while ($z < $cobj->elementscount) { 130 $sel = ''; 131 if (in_array($cobj->elements[$z]['objectid'],$arr)) $sel = ' SELECTED'; 132 $result .= '<option value="'.$cobj->elements[$z]['objectid'].'"'.$sel.'>'.$cobj->elements[$z]['name'].'</option>'; 133 $z++; 134 } 135 unset($cobj); 136 137 $cobj = owNew('usergroup'); 138 $cobj->setsort_col('name'); 139 $cobj->setfilter_nameonly(true); 140 $cobj->setlistaccess(true); 141 $cobj->listobjects(); 142 $z = 0; 143 while ($z < $cobj->elementscount) { 144 $sel = ''; 145 if (in_array($cobj->elements[$z]['objectid'],$arr)) $sel = ' SELECTED'; 146 $result .= '<option value="-'.$cobj->elements[$z]['objectid'].'"'.$sel.'>['.$cobj->elements[$z]['name'].']</option>'; 147 $z++; 148 } 149 unset($cobj); 150 151 $result .= '</select>'; 152 return $result; 153 } 154 155 function sysAccessSelection($objectid, $fieldname) { 156 $result .= '<select name="'.$fieldname.'[]" style="width: 260px;" size=8 multiple>'; 157 $arr = array(); 158 if ($objectid != NULL) { 159 $obj = owRead($objectid); 160 $tarr = $obj->getaccess(); 161 } 162 if (is_array($tarr)) { 163 foreach ($tarr as $carr) { 164 if ($carr['user_write']) $arr[] = $carr['user_write']; 165 if ($carr['group_write']) $arr[] = $carr['group_write']; 166 } 167 } 168 169 $cobj = owNew('user'); 170 $cobj->setsort_col('name'); 171 $cobj->setfilter_nameonly(true); 172 $cobj->setlistaccess(true); 173 $cobj->listobjects(); 174 $z = 0; 175 $sel = ''; 176 if (!is_array($tarr)) $sel = ' SELECTED'; 177 $result .= '<option value=""'.$sel.'>'.$this->view->gl('select_owner').'</option>'; 178 while ($z < $cobj->elementscount) { 179 $sel = ''; 180 if (in_array($cobj->elements[$z]['objectid'],$arr)) $sel = ' SELECTED'; 181 $result .= '<option value="'.$cobj->elements[$z]['objectid'].'"'.$sel.'>'.$cobj->elements[$z]['name'].'</option>'; 182 $z++; 183 } 184 unset($cobj); 185 186 $cobj = owNew('usergroup'); 187 $cobj->setsort_col('name'); 188 $cobj->setfilter_nameonly(true); 189 $cobj->setlistaccess(true); 190 $cobj->listobjects(); 191 $z = 0; 192 while ($z < $cobj->elementscount) { 193 $sel = ''; 194 if (in_array($cobj->elements[$z]['objectid'],$arr)) $sel = ' SELECTED'; 195 $result .= '<option value="-'.$cobj->elements[$z]['objectid'].'"'.$sel.'>['.$cobj->elements[$z]['name'].']</option>'; 196 $z++; 197 } 198 unset($cobj); 199 200 $result .= '</select>'; 201 return $result; 202 } 203 204 /** 205 * @todo Move all the following functions to appropriate methods in the view hierarchy 206 */ 207 208 function listallobjects($type, $value, $emptynone = false) { 209 $obj = owNew($type); 210 211 if (in_array('default',$obj->getviews())) { 212 $std = true; 213 $res = '<option value="0">'.$this->view->gl('select_standard').'</option>'; 214 } else { 215 $std = false; 216 if ($emptynone) { 217 $res = '<option value="">'.$this->view->gl('select_none').'</option>'; 218 } else { 219 $res = '<option value="0">'.$this->view->gl('select_none').'</option>'; 220 } 221 } 222 223 $obj->setlistaccess(true); 224 225 $obj->setsort_col('name'); 226 $obj->listobjects(); 227 $z = 0; 228 if (is_array($value)) { 229 $selected = array(); 230 $unselected = array(); 231 while ($z < $obj->elementscount) { 232 if ($std && $obj->elements[$z]['standard'] == 1) { 233 $standard = ' '.$this->view->gl('select_standard'); 234 } else { 235 $standard = ''; 236 } 237 238 if (in_array($obj->elements[$z]['objectid'],$value)) { 239 $selected[$obj->elements[$z]['objectid']] = $obj->elements[$z]['name'] . $standard; 240 } else { 241 $unselected[$obj->elements[$z]['objectid']] = $obj->elements[$z]['name'] . $standard; 242 } 243 $z++; 244 } 245 246 foreach ($selected as $objectid=>$name) { 247 $res .='<option value="' . $objectid . '" SELECTED>' . $name."\n"; 248 } 249 foreach ($unselected as $objectid=>$name) { 250 $res .='<option value="' . $objectid . '">' . $name."\n"; 251 } 252 253 } else { 254 while ($z < $obj->elementscount) { 255 if ($std && $obj->elements[$z]['standard'] == 1) { 256 $standard = ' '.$this->view->gl('select_standard'); 257 } else { 258 $standard = ''; 259 } 260 $selection = ''; 261 if (is_array($value)) { 262 if (in_array($obj->elements[$z]['objectid'],$value)) $selection = ' SELECTED'; 263 } else { 264 if ($obj->elements[$z]['objectid'] == $value) $selection = ' SELECTED'; 265 } 266 $name = $obj->elements[$z]['name'] . $standard; 267 if ($type == 'item') $name = $obj->elements[$z]['name'] . ' ' . $obj->elements[$z]['content1']; 268 $res .='<option value="' . $obj->elements[$z]['objectid'] . '"'.$selection.'>' .$name. "\n"; 269 $z++; 270 } 271 272 } 273 return $res; 274 } 275 276 function listallusers($value) { 277 $obj = owNew('user'); 278 $obj->setlistaccess(true); 279 $obj->setfilter_nameonly(true); 280 $obj->setsort_col('name'); 281 $obj->listobjects(); 282 $z = 0; 283 while ($z < $obj->elementscount) { 284 $selection = ''; 285 if ($obj->elements[$z]['objectid'] == $value) $selection = ' SELECTED'; 286 $res .='<option value="' . $obj->elements[$z]['objectid'] . '"'.$selection.'>' . $obj->elements[$z]['name'] ."\n"; 287 $z++; 288 } 289 return $res; 290 } 291 292 function listallcategories($value) { 293 $res = '<option value="0">'.$this->view->gl('select_category').'</option>'; 294 $obj = owNew('category'); 295 $obj->setlistaccess(true); 296 $obj->setsort_col('name'); 297 $obj->listobjects(); 298 $z = 0; 299 while ($z < $obj->elementscount) { 300 $selection = ''; 301 if ($obj->elements[$z]['objectid'] == $value) $selection = ' SELECTED'; 302 303 if ($obj->elements[$z]['datatype'] == $this->view->otype || $obj->elements[$z]['datatype'] == '') 304 $res .='<option value="' . $obj->elements[$z]['objectid'] . '"'.$selection.'>' . $obj->elements[$z]['name'] . "\n"; 305 $z++; 306 } 307 return $res; 308 } 309 310 311 function listAllLanguages($value=null) { 312 $res = '<option value="">'.$this->view->gl('select_language').'</option>'; 313 $languages = system::getlanguages(); 314 for($i = 0, $n = sizeOf($languages); $i < $n; $i++) { 315 $selection = ""; 316 if ($languages[$i]['langcode'] == $value) $selection = ' SELECTED'; 317 $res .='<option value="' . $languages[$i]['langcode'] . '"'.$selection.'>' . $languages[$i]['language'] . " (". $languages[$i]['langcode'] . ")\n"; 318 } 319 return $res; 320 } 321 322 323 function listCountries($value=null) { 324 $res = '<option value="">'.$this->view->gl('select_country').'</option>'; 325 $languages = system::getCountries(); 326 for($i = 0, $n = sizeOf($languages); $i < $n; $i++) { 327 $selection = ""; 328 if ($languages[$i]['countrycode'] == $value) $selection = ' SELECTED'; 329 $res .='<option value="' . $languages[$i]['countrycode'] . '"'.$selection.'>' . $languages[$i]['country'] . " (". $languages[$i]['countrycode'] . ")\n"; 330 } 331 return $res; 332 } 333 334 function listallclasses($value) { 335 $res = '<option value="">'.$this->view->gl('select_table').'</option>'; 336 $datatypes = owListCore(); 337 $dt = array(); 338 foreach ($datatypes as $cur) { 339 $idx = owDatatypeDesc($cur); 340 $dt[$idx]['datatype'] = $cur; 341 $dt[$idx]['datatypename'] = $idx; 342 $dt[$idx]['selected'] = ''; 343 if ($cur == $value) $dt[$idx]['selected'] = ' SELECTED'; 344 } 345 ksort($dt); 346 foreach ($dt as $cur) { 347 $res .='<option value="'.$cur['datatype'].'"'.$cur['selected'].'>'.$cur['datatypename']."</option>\n"; 348 } 349 return $res; 350 } 351 352 function listallapps($value) { 353 $apps = owGetApps(); 354 foreach ($apps as $app) { 355 $selected = ''; 356 if (is_array($value)) { 357 if (in_array($app['app'], $value)) $selected = ' SELECTED'; 358 } else { 359 if ($app['app'] == $value) $selected = ' SELECTED'; 360 } 361 $res .='<option value="'.$app['app'].'"'.$selected.'>'.$app['name']."</option>\n"; 362 } 363 return $res; 364 } 365 366 function tmpGetExtName($value) { 367 if ($this->