| Total Complexity | 262 |
| Total Lines | 947 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Select often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Select, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class Select extends Etemplate\Widget |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * If the selectbox has this many rows, give it a search box automatically |
||
| 32 | */ |
||
| 33 | const SEARCH_ROW_LIMIT = PHP_INT_MAX; // Automatic disabled, only explicit |
||
| 34 | |||
| 35 | /** |
||
| 36 | * These types are either set or cached on the client side, so we don't send |
||
| 37 | * their options unless asked via AJAX |
||
| 38 | */ |
||
| 39 | public static $cached_types = array( |
||
| 40 | 'select-account', |
||
| 41 | 'select-app', |
||
| 42 | 'select-bool', |
||
| 43 | 'select-country', |
||
| 44 | // DOW needs some server-side pre-processing to unpack the options, |
||
| 45 | // so can't be skipped. |
||
| 46 | //'select-dow', |
||
| 47 | 'select-number', |
||
| 48 | 'select-priority', |
||
| 49 | 'select-percent', |
||
| 50 | 'select-year', |
||
| 51 | 'select-month', |
||
| 52 | 'select-day', |
||
| 53 | 'select-hour', |
||
| 54 | 'select-lang', |
||
| 55 | 'select-timezone' |
||
| 56 | ); |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | protected static $monthnames = array( |
||
| 62 | 0 => '', |
||
| 63 | 1 => 'January', |
||
| 64 | 2 => 'February', |
||
| 65 | 3 => 'March', |
||
| 66 | 4 => 'April', |
||
| 67 | 5 => 'May', |
||
| 68 | 6 => 'June', |
||
| 69 | 7 => 'July', |
||
| 70 | 8 => 'August', |
||
| 71 | 9 => 'September', |
||
| 72 | 10 => 'October', |
||
| 73 | 11 => 'November', |
||
| 74 | 12 => 'December' |
||
| 75 | ); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Constructor |
||
| 79 | * |
||
| 80 | * @param string|XMLReader $xml string with xml or XMLReader positioned on the element to construct |
||
|
|
|||
| 81 | * @throws Api\Exception\WrongParameter |
||
| 82 | */ |
||
| 83 | public function __construct($xml = '') |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Parse and set extra attributes from xml in template object |
||
| 100 | * |
||
| 101 | * Reimplemented to parse our differnt attributes |
||
| 102 | * |
||
| 103 | * @param string|XMLReader $xml |
||
| 104 | * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object |
||
| 105 | * @return Template current object or clone, if any attribute was set |
||
| 106 | * @todo Use legacy_attributes instead of leaving it to typeOptions method to parse them |
||
| 107 | */ |
||
| 108 | public function set_attrs($xml, $cloned=true) |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | const UNAVAILABLE_CAT_POSTFIX = '-unavailable'; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Validate input |
||
| 137 | * |
||
| 138 | * @param string $cname current namespace |
||
| 139 | * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' |
||
| 140 | * @param array $content |
||
| 141 | * @param array &$validated=array() validated content |
||
| 142 | */ |
||
| 143 | public function validate($cname, array $expand, array $content, &$validated=array()) |
||
| 144 | { |
||
| 145 | $form_name = self::form_name($cname, $this->id, $expand); |
||
| 146 | $widget_type = $this->attrs['type'] ? $this->attrs['type'] : $this->type; |
||
| 147 | $multiple = $this->attrs['multiple'] || $this->getElementAttribute($form_name, 'rows') > 1; |
||
| 148 | |||
| 149 | $ok = true; |
||
| 150 | if (!$this->is_readonly($cname, $form_name)) |
||
| 151 | { |
||
| 152 | $value = $value_in = self::get_array($content, $form_name); |
||
| 153 | |||
| 154 | $allowed2 = self::selOptions($form_name, true); // true = return array of option-values |
||
| 155 | $type_options = self::typeOptions($this, |
||
| 156 | // typeOptions thinks # of rows is the first thing in options |
||
| 157 | ($this->attrs['rows'] && strpos($this->attrs['options'], $this->attrs['rows']) !== 0 ? $this->attrs['rows'].','.$this->attrs['options'] : $this->attrs['options'])); |
||
| 158 | $allowed = array_merge($allowed2,array_keys($type_options)); |
||
| 159 | |||
| 160 | // add option children's values too, "" is not read, therefore we cast to string |
||
| 161 | foreach($this->children as $child) |
||
| 162 | { |
||
| 163 | if ($child->type == 'option') $allowed[] = (string)$child->attrs['value']; |
||
| 164 | } |
||
| 165 | |||
| 166 | if (!$multiple || $this->attrs['multiple'] === "dynamic") $allowed[] = ''; |
||
| 167 | |||
| 168 | foreach((array) $value as $val) |
||
| 169 | { |
||
| 170 | // handle empty-label for all widget types |
||
| 171 | if ((string)$val === '' && in_array('', $allowed)) continue; |
||
| 172 | |||
| 173 | switch ($widget_type) |
||
| 174 | { |
||
| 175 | case 'select-account': |
||
| 176 | // If in allowed options, skip account check to support app-specific options |
||
| 177 | if(count($allowed) > 0 && in_array($val, $allowed)) continue 2; // +1 for switch |
||
| 178 | |||
| 179 | // validate accounts independent of options know to server |
||
| 180 | $account_type = $this->attrs['account_type'] ? $this->attrs['account_type'] : 'accounts'; |
||
| 181 | $type = $GLOBALS['egw']->accounts->exists($val); |
||
| 182 | //error_log(__METHOD__."($cname,...) form_name=$form_name, widget_type=$widget_type, account_type=$account_type, type=$type"); |
||
| 183 | if (!$type || $type == 1 && in_array($account_type, array('groups', 'owngroups', 'memberships')) || |
||
| 184 | $type == 2 && $account_type == 'users' || |
||
| 185 | in_array($account_type, array('owngroups', 'memberships')) && |
||
| 186 | !in_array($val, $GLOBALS['egw']->accounts->memberships( |
||
| 187 | $GLOBALS['egw_info']['user']['account_id'], true)) |
||
| 188 | ) |
||
| 189 | { |
||
| 190 | self::set_validation_error($form_name, lang("'%1' is NOT allowed ('%2')!", $val, |
||
| 191 | !$type?'not found' : ($type == 1 ? 'user' : 'group')),''); |
||
| 192 | $value = ''; |
||
| 193 | break 2; |
||
| 194 | } |
||
| 195 | break; |
||
| 196 | |||
| 197 | case 'select-timezone': |
||
| 198 | if (!calendar_timezones::tz2id($val)) |
||
| 199 | { |
||
| 200 | self::set_validation_error($form_name, lang("'%1' is NOT a valid timezone!", $val)); |
||
| 201 | } |
||
| 202 | break; |
||
| 203 | |||
| 204 | default: |
||
| 205 | if(!in_array($val, $allowed)) |
||
| 206 | { |
||
| 207 | self::set_validation_error($form_name,lang("'%1' is NOT allowed ('%2')!", $val, implode("','",$allowed)),''); |
||
| 208 | $value = ''; |
||
| 209 | break 2; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | } |
||
| 213 | if ($ok && $value === '' && $this->attrs['needed']) |
||
| 214 | { |
||
| 215 | self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),''); |
||
| 216 | } |
||
| 217 | if (!$multiple && is_array($value) && count($value) > 1) |
||
| 218 | { |
||
| 219 | $value = array_shift($value); |
||
| 220 | } |
||
| 221 | // some widgets sub-types need some post-processing |
||
| 222 | // ToDo: move it together with preprocessing to clientside |
||
| 223 | switch ($widget_type) |
||
| 224 | { |
||
| 225 | case 'select-dow': |
||
| 226 | $dow = 0; |
||
| 227 | foreach((array)$value as $val) |
||
| 228 | { |
||
| 229 | $dow |= $val; |
||
| 230 | } |
||
| 231 | $value = $dow; |
||
| 232 | break; |
||
| 233 | |||
| 234 | case 'select-country': |
||
| 235 | $legacy_options = $this->attrs['rows'] && strpos($this->attrs['options'], $this->attrs['rows']) !== 0 ? |
||
| 236 | $this->attrs['rows'].','.$this->attrs['options'] : $this->attrs['options']; |
||
| 237 | list(,$country_use_name) = explode(',', $legacy_options); |
||
| 238 | if ($country_use_name && $value) |
||
| 239 | { |
||
| 240 | $value = Api\Country::get_full_name($value); |
||
| 241 | } |
||
| 242 | break; |
||
| 243 | |||
| 244 | case 'select-cat': |
||
| 245 | // unavailable cats need to be merged in again |
||
| 246 | $unavailable_name = $form_name.self::UNAVAILABLE_CAT_POSTFIX; |
||
| 247 | if (isset(self::$request->preserv[$unavailable_name])) |
||
| 248 | { |
||
| 249 | if ($this->attrs['multiple']) |
||
| 250 | { |
||
| 251 | $value = array_merge($value, (array)self::$request->preserv[$unavailable_name]); |
||
| 252 | } |
||
| 253 | elseif(!$value) // for single cat, we only restore unavailable one, if no other was selected |
||
| 254 | { |
||
| 255 | $value = self::$request->preserv[$unavailable_name]; |
||
| 256 | } |
||
| 257 | } |
||
| 258 | break; |
||
| 259 | case 'select-bitwise': |
||
| 260 | // Sum up into a single value |
||
| 261 | $sum = 0; |
||
| 262 | foreach((array) $value as $val) |
||
| 263 | { |
||
| 264 | $sum += $val; |
||
| 265 | } |
||
| 266 | $value = $sum; |
||
| 267 | break; |
||
| 268 | } |
||
| 269 | if (isset($value)) |
||
| 270 | { |
||
| 271 | self::set_array($validated, $form_name, $value); |
||
| 272 | //error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed)); |
||
| 273 | } |
||
| 274 | } |
||
| 275 | else |
||
| 276 | { |
||
| 277 | //error_log($this . "($form_name) is read-only, skipping validate"); |
||
| 278 | } |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Fill type options in self::$request->sel_options to be used on the client |
||
| 283 | * |
||
| 284 | * @param string $cname |
||
| 285 | * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' |
||
| 286 | */ |
||
| 287 | public function beforeSendToClient($cname, array $expand=null) |
||
| 288 | { |
||
| 289 | //error_log(__METHOD__."('$cname') this->id=$this->id, this->type=$this->type, this->attrs=".array2string($this->attrs)); |
||
| 290 | $matches = null; |
||
| 291 | if ($cname == '$row') // happens eg. with custom-fields: $cname='$row', this->id='#something' |
||
| 292 | { |
||
| 293 | $form_name = $this->id; |
||
| 294 | } |
||
| 295 | // happens with fields in nm-header: $cname='nm', this->id='${row}[something]' or '{$row}[something]' |
||
| 296 | elseif (preg_match('/(\${row}|{\$row})\[([^]]+)\]$/', $this->id, $matches)) |
||
| 297 | { |
||
| 298 | $form_name = $matches[2]; |
||
| 299 | } |
||
| 300 | // happens in auto-repeat grids: $cname='', this->id='something[{$row}]' |
||
| 301 | elseif (preg_match('/([^[]+)\[({\$row})\]$/', $this->id, $matches)) |
||
| 302 | { |
||
| 303 | $form_name = $matches[1]; |
||
| 304 | } |
||
| 305 | // happens with autorepeated grids: this->id='some[$row_cont[thing]][else]' --> just use 'else' |
||
| 306 | elseif (preg_match('/\$row.*\[([^]]+)\]$/', $this->id, $matches)) |
||
| 307 | { |
||
| 308 | $form_name = $matches[1]; |
||
| 309 | } |
||
| 310 | else |
||
| 311 | { |
||
| 312 | $form_name = self::form_name($cname, $this->id, $expand); |
||
| 313 | } |
||
| 314 | if (!is_array(self::$request->sel_options[$form_name])) self::$request->sel_options[$form_name] = array(); |
||
| 315 | $type = $this->attrs['type'] ? $this->attrs['type'] : $this->type; |
||
| 316 | if ($type != 'select' && $type != 'menupopup') |
||
| 317 | { |
||
| 318 | // Check selection preference, we may be able to skip reading some data |
||
| 319 | $select_pref = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection']; |
||
| 320 | if($this->attrs['type'] == 'select-account' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $select_pref == 'none') |
||
| 321 | { |
||
| 322 | // Preserve but do not send the value if preference is 'none' |
||
| 323 | self::$request->preserv[$this->id] = self::$request->content[$this->id]; |
||
| 324 | unset(self::$request->content[$this->id]); |
||
| 325 | $this->attrs['readonly'] = true; |
||
| 326 | } |
||
| 327 | if(!in_array($type, self::$cached_types)) |
||
| 328 | { |
||
| 329 | // adding type specific options here, while keep further options set by app code |
||
| 330 | // we need to make sure to run only once for auto-repeated rows, because |
||
| 331 | // array_merge used to keep options from app would otherwise add |
||
| 332 | // type-specific ones multiple time (and of cause better performance) |
||
| 333 | $no_lang = null; |
||
| 334 | static $form_names_done = array(); |
||
| 335 | if (!isset($form_names_done[$form_name]) && |
||
| 336 | ($type_options = self::typeOptions($this, |
||
| 337 | // typeOptions thinks # of rows is the first thing in options |
||
| 338 | ($this->attrs['rows'] && strpos($this->attrs['options'], $this->attrs['rows']) !== 0 ? $this->attrs['rows'].','.$this->attrs['options'] : $this->attrs['options']), |
||
| 339 | $no_lang, $this->attrs['readonly'], self::get_array(self::$request->content, $form_name), $form_name))) |
||
| 340 | { |
||
| 341 | self::fix_encoded_options($type_options); |
||
| 342 | |||
| 343 | self::$request->sel_options[$form_name] = array_merge(self::$request->sel_options[$form_name], $type_options); |
||
| 344 | |||
| 345 | // if no_lang was modified, forward modification to the client |
||
| 346 | if ($no_lang != $this->attrs['no_lang']) |
||
| 347 | { |
||
| 348 | self::setElementAttribute($form_name, 'no_lang', $no_lang); |
||
| 349 | } |
||
| 350 | } |
||
| 351 | $form_names_done[$form_name] = true; |
||
| 352 | } |
||
| 353 | } |
||
| 354 | |||
| 355 | // Make sure s, etc. are properly encoded when sent, and not double-encoded |
||
| 356 | $options = (isset(self::$request->sel_options[$form_name]) ? $form_name : $this->id); |
||
| 357 | if(is_array(self::$request->sel_options[$options])) |
||
| 358 | { |
||
| 359 | if(in_array($this->attrs['type'], self::$cached_types) && !isset($form_names_done[$options])) |
||
| 360 | { |
||
| 361 | // Fix any custom options from application |
||
| 362 | self::fix_encoded_options(self::$request->sel_options[$options],true); |
||
| 363 | $form_names_done[$options] = true; |
||
| 364 | } |
||
| 365 | // Turn on search, if there's a lot of rows (unless explicitly set) |
||
| 366 | if(!array_key_exists('search',$this->attrs) && count(self::$request->sel_options[$options]) >= self::SEARCH_ROW_LIMIT) |
||
| 367 | { |
||
| 368 | self::setElementAttribute($form_name, "search", true); |
||
| 369 | } |
||
| 370 | if(!self::$request->sel_options[$options]) |
||
| 371 | { |
||
| 372 | unset(self::$request->sel_options[$options]); |
||
| 373 | } |
||
| 374 | } |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Fix already html-encoded options, eg. "&nbps" AND optinal re-index array to keep order |
||
| 379 | * |
||
| 380 | * Get run automatic for everything in $sel_options by etemplate_new::exec / etemplate_new::fix_sel_options |
||
| 381 | * |
||
| 382 | * @param array $options |
||
| 383 | * @param boolean $use_array_of_objects Re-indexes options, making everything more complicated |
||
| 384 | */ |
||
| 385 | public static function fix_encoded_options(array &$options, $use_array_of_objects=null) |
||
| 431 | } |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Get options from $sel_options array for a given selectbox name |
||
| 436 | * |
||
| 437 | * @param string $name |
||
| 438 | * @param boolean $return_values =false true: return array with option values, instead of value => label pairs |
||
| 439 | * @return array |
||
| 440 | */ |
||
| 441 | public static function selOptions($name, $return_values=false) |
||
| 442 | { |
||
| 443 | $options = array(); |
||
| 444 | |||
| 445 | // Check for exact match on name |
||
| 446 | if (isset(self::$request->sel_options[$name]) && is_array(self::$request->sel_options[$name])) |
||
| 447 | { |
||
| 448 | $options += self::$request->sel_options[$name]; |
||
| 449 | } |
||
| 450 | |||
| 451 | // Check for non-trivial name like a[b] |
||
| 452 | $name_parts = explode('[',str_replace(array('[',']',']'),array('['),$name)); |
||
| 453 | if(!$options) |
||
| 454 | { |
||
| 455 | $options = (array)self::get_array(self::$request->sel_options,$name); |
||
| 456 | if(is_numeric(end($name_parts)) && $options['label'] && $options['value']) |
||
| 457 | { |
||
| 458 | // Too deep, we got a single option |
||
| 459 | $options = array(); |
||
| 460 | } |
||
| 461 | } |
||
| 462 | |||
| 463 | // Check for base of name in root of sel_options |
||
| 464 | if(!$options) |
||
| 465 | { |
||
| 466 | if (count($name_parts)) |
||
| 467 | { |
||
| 468 | $org_name = $name_parts[count($name_parts)-1]; |
||
| 469 | if (isset(self::$request->sel_options[$org_name]) && is_array(self::$request->sel_options[$org_name])) |
||
| 470 | { |
||
| 471 | $options += self::$request->sel_options[$org_name]; |
||
| 472 | } |
||
| 473 | elseif (isset(self::$request->sel_options[$name_parts[0]]) && is_array(self::$request->sel_options[$name_parts[0]])) |
||
| 474 | { |
||
| 475 | $options += self::$request->sel_options[$name_parts[0]]; |
||
| 476 | } |
||
| 477 | } |
||
| 478 | } |
||
| 479 | |||
| 480 | // Check for options-$name in content |
||
| 481 | if (is_array(self::$request->content['options-'.$name])) |
||
| 482 | { |
||
| 483 | $options += self::$request->content['options-'.$name]; |
||
| 484 | } |
||
| 485 | if ($return_values) |
||
| 486 | { |
||
| 487 | $values = array(); |
||
| 488 | foreach($options as $key => $val) |
||
| 489 | { |
||
| 490 | if (is_array($val)) |
||
| 491 | { |
||
| 492 | if (isset($val['value']) && count(array_filter(array_keys($val), 'is_int')) == 0) |
||
| 493 | { |
||
| 494 | $values[] = $val['value']; |
||
| 495 | } |
||
| 496 | else if ((isset($val['label']) || isset($val['title'])) && count($val) == 1 || |
||
| 497 | isset($val['title']) && isset($val['label']) && count($val) == 2) |
||
| 498 | { |
||
| 499 | // key => {label, title} |
||
| 500 | $values[] = $key; |
||
| 501 | } |
||
| 502 | else // optgroup |
||
| 503 | { |
||
| 504 | foreach($val as $k => $v) |
||
| 505 | { |
||
| 506 | $values[] = is_array($v) && isset($v['value']) ? $v['value'] : $k; |
||
| 507 | } |
||
| 508 | } |
||
| 509 | } |
||
| 510 | else |
||
| 511 | { |
||
| 512 | $values[] = $key; |
||
| 513 | } |
||
| 514 | } |
||
| 515 | //error_log(__METHOD__."('$name', TRUE) options=".array2string($options).' --> values='.array2string($values)); |
||
| 516 | $options = $values; |
||
| 517 | } |
||
| 518 | else if (end($options) && is_array(end($options)) && isset(end($options)['value'])) |
||
| 519 | { |
||
| 520 | $values = array(); |
||
| 521 | foreach($options as $index => $option) |
||
| 522 | { |
||
| 523 | if(is_array($option) && isset($option['value'])) |
||
| 524 | { |
||
| 525 | $values[$option['value']] = $option['label']; |
||
| 526 | } |
||
| 527 | else |
||
| 528 | { |
||
| 529 | $values[$index] = $option; |
||
| 530 | } |
||
| 531 | } |
||
| 532 | $options = $values; |
||
| 533 | } |
||
| 534 | //error_log(__METHOD__."('$name') returning ".array2string($options)); |
||
| 535 | return $options; |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Fetch options for certain select-box types |
||
| 540 | * |
||
| 541 | * @param string|Select $widget_type Type of widget, or actual widget to get attributes since $legacy_options are legacy |
||
| 542 | * @param string $_legacy_options options string of widget |
||
| 543 | * @param boolean $no_lang =false initial value of no_lang attribute (some types set it to true) |
||
| 544 | * @param boolean $readonly =false for readonly we dont need to fetch all options, only the one for value |
||
| 545 | * @param mixed $value =null value for readonly |
||
| 546 | * @param string $form_name =null |
||
| 547 | * @return array with value => label pairs |
||
| 548 | */ |
||
| 549 | public static function typeOptions($widget_type, $_legacy_options, &$no_lang=false, $readonly=false, &$value=null, $form_name=null) |
||
| 853 | } |
||
| 854 | |||
| 855 | /** |
||
| 856 | * Get available apps as options |
||
| 857 | * |
||
| 858 | * @param string $type2 ='installed[:home;groupdav; ...]' 'user'=apps of current user, |
||
| 859 | * 'enabled', 'installed' (default), 'all' = not installed ones too. In order to |
||
| 860 | * exclude apps explicitly we can list them (app name separator is ';') in front of the type. |
||
| 861 | * |
||
| 862 | * @return array app => label pairs sorted by label |
||
| 863 | */ |
||
| 864 | public static function app_options($type2) |
||
| 865 | { |
||
| 866 | $apps = array(); |
||
| 867 | $parts = explode(":", $type2); |
||
| 868 | $exceptions = explode(";", $parts[1]); |
||
| 869 | $type2 = $parts[0]; |
||
| 870 | |||
| 871 | foreach ($GLOBALS['egw_info']['apps'] as $app => $data) |
||
| 872 | { |
||
| 873 | if ($type2 == 'enabled' && (!$data['enabled'] || !$data['status'] || $data['status'] == 3 || in_array($app, $exceptions))) |
||
| 874 | { |
||
| 875 | continue; // app not enabled (user can not have run rights for these apps) |
||
| 876 | } |
||
| 877 | if (($type2 != 'user' || $GLOBALS['egw_info']['user']['apps'][$app]) && !in_array($app, $exceptions)) |
||
| 878 | { |
||
| 879 | $apps[$app] = lang($app); |
||
| 880 | } |
||
| 881 | } |
||
| 882 | if ($type2 == 'all') |
||
| 883 | { |
||
| 884 | $dir = opendir(EGW_SERVER_ROOT); |
||
| 885 | while ($file = readdir($dir)) |
||
| 886 | { |
||
| 887 | if (@is_dir(EGW_SERVER_ROOT."/$file/setup") && $file[0] != '.' && |
||
| 888 | !isset($apps[$app = basename($file)])) |
||
| 889 | { |
||
| 890 | $apps[$app] = $app . ' (*)'; |
||
| 891 | } |
||
| 892 | } |
||
| 893 | closedir($dir); |
||
| 894 | } |
||
| 895 | natcasesort($apps); |
||
| 896 | return $apps; |
||
| 897 | } |
||
| 898 | |||
| 899 | /** |
||
| 900 | * internal function to format account-data |
||
| 901 | * |
||
| 902 | * @param int $id |
||
| 903 | * @param array $acc =null optional values for keys account_(type|lid|lastname|firstname) to not read them again |
||
| 904 | * @param int $longnames =0 |
||
| 905 | * @param boolean $show_type =false true: return array with values for keys label and icon, false: only label |
||
| 906 | * @return string|array |
||
| 907 | */ |
||
| 908 | public static function accountInfo($id,$acc=null,$longnames=0,$show_type=false) |
||
| 954 | } |
||
| 955 | |||
| 956 | /** |
||
| 957 | * Some select options are fairly static, but can only be generated on the server |
||
| 958 | * so we generate them here, then cache them client-side |
||
| 959 | * |
||
| 960 | * @param string $type |
||
| 961 | * @param Array|String $attributes |
||
| 962 | * @param string $value Optional current value, to make sure it's included |
||
| 963 | */ |
||
| 964 | public static function ajax_get_options($type, $attributes, $value = null) |
||
| 975 | } |
||
| 976 | } |
||
| 977 | Etemplate\Widget::registerWidget(__NAMESPACE__.'\\Select', array('selectbox', 'listbox', 'select', 'menupopup')); |
||
| 978 |