@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param array &$validated=array() validated content |
45 | 45 | * @return boolean true if no validation error, false otherwise |
46 | 46 | */ |
47 | - public function validate($cname, array $expand, array $content, &$validated=array()) |
|
47 | + public function validate($cname, array $expand, array $content, &$validated = array()) |
|
48 | 48 | { |
49 | 49 | $form_name = self::form_name($cname, $this->id, $expand); |
50 | 50 | |
@@ -56,28 +56,28 @@ discard block |
||
56 | 56 | if (!$this->is_readonly($cname, $form_name)) |
57 | 57 | { |
58 | 58 | $value = self::get_array($content, $form_name); |
59 | - if (!isset($value)) return; // value not transmitted --> nothing to validate |
|
60 | - $valid =& self::get_array($validated, $form_name, true); |
|
59 | + if (!isset($value)) return; // value not transmitted --> nothing to validate |
|
60 | + $valid = & self::get_array($validated, $form_name, true); |
|
61 | 61 | |
62 | 62 | if (!$value && $this->attrs['needed']) |
63 | 63 | { |
64 | - self::set_validation_error($form_name,lang('Field must not be empty !!!'),''); |
|
64 | + self::set_validation_error($form_name, lang('Field must not be empty !!!'), ''); |
|
65 | 65 | } |
66 | 66 | $type = $this->type ? $this->type : $this->attrs['type']; |
67 | 67 | $value_attr = $type == 'radio' ? 'set_value' : 'selected_value'; |
68 | 68 | // defaults for set and unset values |
69 | 69 | $selected_value = true; |
70 | 70 | $unselected_value = false; |
71 | - if (array_key_exists($value_attr, $this->attrs) || array_key_exists('unselected_value',$this->attrs)) |
|
71 | + if (array_key_exists($value_attr, $this->attrs) || array_key_exists('unselected_value', $this->attrs)) |
|
72 | 72 | { |
73 | - if(array_key_exists($value_attr, $this->attrs)) |
|
73 | + if (array_key_exists($value_attr, $this->attrs)) |
|
74 | 74 | { |
75 | 75 | // Expand any content stuff |
76 | - $selected_value = self::expand_name($this->attrs[$value_attr], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'],$expand['cont']); |
|
76 | + $selected_value = self::expand_name($this->attrs[$value_attr], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
77 | 77 | } |
78 | - if(array_key_exists('unselected_value',$this->attrs)) |
|
78 | + if (array_key_exists('unselected_value', $this->attrs)) |
|
79 | 79 | { |
80 | - $unselected_value = self::expand_name($this->attrs['unselected_value'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'],$expand['cont']); |
|
80 | + $unselected_value = self::expand_name($this->attrs['unselected_value'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | if ($type == 'radio') |
@@ -87,14 +87,14 @@ discard block |
||
87 | 87 | { |
88 | 88 | $valid = $value; |
89 | 89 | } |
90 | - elseif ( !$options && $selected_value && $value == $selected_value) |
|
90 | + elseif (!$options && $selected_value && $value == $selected_value) |
|
91 | 91 | { |
92 | 92 | // Options set in template, not in sel_options |
93 | 93 | $valid = $selected_value; |
94 | 94 | } |
95 | 95 | elseif (!isset($valid)) |
96 | 96 | { |
97 | - $valid = ''; // do not overwrite value of an other radio-button of the same group (identical name)! |
|
97 | + $valid = ''; // do not overwrite value of an other radio-button of the same group (identical name)! |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | elseif (in_array((string)$selected_value, (array)$value)) |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | $this->id = $reader->getAttribute('id'); |
100 | 100 | |
101 | 101 | // Update content? |
102 | - if(self::$cont == null) |
|
102 | + if (self::$cont == null) |
|
103 | 103 | self::$cont = is_array(self::$request->content) ? self::$request->content : array(); |
104 | - if($this->id && is_array(self::$cont[$this->id])) |
|
104 | + if ($this->id && is_array(self::$cont[$this->id])) |
|
105 | 105 | { |
106 | 106 | $old_cont = self::$cont; |
107 | 107 | self::$cont = self::$cont[$this->id]; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | // read all attributes |
111 | 111 | $this->set_attrs($reader); |
112 | 112 | |
113 | - while($reader->read() && $reader->depth > $depth) |
|
113 | + while ($reader->read() && $reader->depth > $depth) |
|
114 | 114 | { |
115 | 115 | if ($reader->nodeType == XMLReader::ELEMENT && $reader->depth > $depth) |
116 | 116 | { |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | // Reset content as we leave |
122 | - if($old_cont) { |
|
122 | + if ($old_cont) { |
|
123 | 123 | self::$cont = $old_cont; |
124 | 124 | } |
125 | 125 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object |
158 | 158 | * @return Template current object or clone, if any attribute was set |
159 | 159 | */ |
160 | - public function set_attrs($xml, $cloned=true) |
|
160 | + public function set_attrs($xml, $cloned = true) |
|
161 | 161 | { |
162 | 162 | $reader = self::get_reader($xml); |
163 | 163 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | |
175 | 175 | // read and set all attributes |
176 | 176 | $template = $this; |
177 | - while($reader->moveToNextAttribute()) |
|
177 | + while ($reader->moveToNextAttribute()) |
|
178 | 178 | { |
179 | 179 | if ($reader->name != 'id' && $template->attr[$reader->name] != $reader->value) |
180 | 180 | { |
181 | 181 | if (!$cloned) |
182 | 182 | { |
183 | 183 | $template = clone($this); |
184 | - $cloned = true; // only clone it once, otherwise we loose attributes! |
|
184 | + $cloned = true; // only clone it once, otherwise we loose attributes! |
|
185 | 185 | } |
186 | 186 | // $reader->value is an object and therefore assigned by reference |
187 | 187 | // this is important to not loose content when validating dynamic generated tabs as in settings! |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | if ($legacy_options && $reader->name == 'options') |
199 | 199 | { |
200 | 200 | $legacy_options = explode(',', $legacy_options); |
201 | - foreach(self::csv_split($value, count($legacy_options)) as $n => $val) |
|
201 | + foreach (self::csv_split($value, count($legacy_options)) as $n => $val) |
|
202 | 202 | { |
203 | 203 | if ($legacy_options[$n] && (string)$val !== '') $template->attrs[$legacy_options[$n]] = $val; |
204 | 204 | } |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | // Add in anything in the modification array |
210 | - if(is_array(self::$request->modifications[$this->id])) |
|
210 | + if (is_array(self::$request->modifications[$this->id])) |
|
211 | 211 | { |
212 | - $this->attrs = array_merge($this->attrs,self::$request->modifications[$this->id]); |
|
212 | + $this->attrs = array_merge($this->attrs, self::$request->modifications[$this->id]); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return $template; |
@@ -230,32 +230,32 @@ discard block |
||
230 | 230 | * @param string $enclosure ='"' |
231 | 231 | * @return array |
232 | 232 | */ |
233 | - public static function csv_split($str,$num=null,$delimiter=',',$enclosure='"') |
|
233 | + public static function csv_split($str, $num = null, $delimiter = ',', $enclosure = '"') |
|
234 | 234 | { |
235 | - if (strpos($str,$enclosure) === false) |
|
235 | + if (strpos($str, $enclosure) === false) |
|
236 | 236 | { |
237 | - return is_null($num) ? explode($delimiter,$str) : explode($delimiter,$str,$num); // no need to run this more expensive code |
|
237 | + return is_null($num) ? explode($delimiter, $str) : explode($delimiter, $str, $num); // no need to run this more expensive code |
|
238 | 238 | } |
239 | - $parts = explode($delimiter,$str); |
|
240 | - for($n = 0; isset($parts[$n]); ++$n) |
|
239 | + $parts = explode($delimiter, $str); |
|
240 | + for ($n = 0; isset($parts[$n]); ++$n) |
|
241 | 241 | { |
242 | - $part =& $parts[$n]; |
|
242 | + $part = & $parts[$n]; |
|
243 | 243 | if ($part[0] === $enclosure) |
244 | 244 | { |
245 | - while (isset($parts[$n+1]) && substr($part,-1) !== $enclosure) |
|
245 | + while (isset($parts[$n + 1]) && substr($part, -1) !== $enclosure) |
|
246 | 246 | { |
247 | 247 | $part .= $delimiter.$parts[++$n]; |
248 | 248 | unset($parts[$n]); |
249 | 249 | } |
250 | - $part = substr(str_replace($enclosure.$enclosure,$enclosure,$part),1,-1); |
|
250 | + $part = substr(str_replace($enclosure.$enclosure, $enclosure, $part), 1, -1); |
|
251 | 251 | } |
252 | 252 | } |
253 | - $parts_renum = array_values($parts); // renumber the parts (in case we had to concat them) |
|
253 | + $parts_renum = array_values($parts); // renumber the parts (in case we had to concat them) |
|
254 | 254 | |
255 | 255 | if ($num > 0 && count($parts_renum) > $num) |
256 | 256 | { |
257 | - $parts_renum[$num-1] = implode($delimiter,array_slice($parts_renum,$num-1,count($parts_renum)-$num+1)); |
|
258 | - $parts_renum = array_slice($parts_renum,0,$num); |
|
257 | + $parts_renum[$num - 1] = implode($delimiter, array_slice($parts_renum, $num - 1, count($parts_renum) - $num + 1)); |
|
258 | + $parts_renum = array_slice($parts_renum, 0, $num); |
|
259 | 259 | } |
260 | 260 | return $parts_renum; |
261 | 261 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | { |
283 | 283 | throw new Api\Exception\WrongParameter(__METHOD__."('$class', ".array2string($widgets).") $class is no subclass of ".__CLASS__.'!'); |
284 | 284 | } |
285 | - foreach((array)$widgets as $widget) |
|
285 | + foreach ((array)$widgets as $widget) |
|
286 | 286 | { |
287 | 287 | self::$widget_registry[$widget] = $class; |
288 | 288 | } |
@@ -307,15 +307,15 @@ discard block |
||
307 | 307 | |
308 | 308 | if (!$widget_registry) // not in instance cache --> rescan from filesystem |
309 | 309 | { |
310 | - foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
|
310 | + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
|
311 | 311 | { |
312 | - if(substr($path, -4) == '.php') |
|
312 | + if (substr($path, -4) == '.php') |
|
313 | 313 | { |
314 | 314 | try |
315 | 315 | { |
316 | 316 | include_once($path); |
317 | 317 | } |
318 | - catch(Exception $e) |
|
318 | + catch (Exception $e) |
|
319 | 319 | { |
320 | 320 | error_log($e->getMessage()); |
321 | 321 | } |
@@ -323,18 +323,18 @@ discard block |
||
323 | 323 | } |
324 | 324 | |
325 | 325 | // Use hook to load custom widgets from other apps |
326 | - $widgets = Api\Hooks::process('etemplate2_register_widgets',array(),true); |
|
327 | - foreach($widgets as $list) |
|
326 | + $widgets = Api\Hooks::process('etemplate2_register_widgets', array(), true); |
|
327 | + foreach ($widgets as $list) |
|
328 | 328 | { |
329 | 329 | if (is_array($list)) |
330 | 330 | { |
331 | - foreach($list as $class) |
|
331 | + foreach ($list as $class) |
|
332 | 332 | { |
333 | 333 | try |
334 | 334 | { |
335 | - class_exists($class); // trigger autoloader |
|
335 | + class_exists($class); // trigger autoloader |
|
336 | 336 | } |
337 | - catch(Exception $e) |
|
337 | + catch (Exception $e) |
|
338 | 338 | { |
339 | 339 | error_log($e->getMessage()); |
340 | 340 | } |
@@ -357,22 +357,22 @@ discard block |
||
357 | 357 | * @param string|XMLReader $xml |
358 | 358 | * @param string $id =null |
359 | 359 | */ |
360 | - public static function factory($type, $xml, $id=null) |
|
360 | + public static function factory($type, $xml, $id = null) |
|
361 | 361 | { |
362 | - $class_name =& self::$widget_registry[$type]; |
|
362 | + $class_name = & self::$widget_registry[$type]; |
|
363 | 363 | |
364 | 364 | if (!isset($class_name)) |
365 | 365 | { |
366 | - list($basetype) = explode('-',$type); |
|
366 | + list($basetype) = explode('-', $type); |
|
367 | 367 | if (//dont think this is used: !class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$type)) && |
368 | 368 | !class_exists($class_name = __CLASS__.'\\'.ucfirst($basetype)) && |
369 | 369 | // widgets supplied by application in class ${app}_widget_etemplate or ${app}_${subtype}_widget_etemplate |
370 | 370 | !(isset($GLOBALS['egw_info']['apps'][$basetype]) && |
371 | - (class_exists($class_name = str_replace('-','_',$type).'_etemplate_widget') || |
|
371 | + (class_exists($class_name = str_replace('-', '_', $type).'_etemplate_widget') || |
|
372 | 372 | class_exists($class_name = $basetype.'_etemplate_widget')))) |
373 | 373 | { |
374 | 374 | // Try for base type, it's probably better than the root |
375 | - if(self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
375 | + if (self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
376 | 376 | { |
377 | 377 | $class_name = self::$widget_registry[$basetype]; |
378 | 378 | } |
@@ -393,22 +393,22 @@ discard block |
||
393 | 393 | { |
394 | 394 | // Class in widget registry, but not loaded |
395 | 395 | // Try for a base class |
396 | - $subtypes = explode('-',$type); |
|
396 | + $subtypes = explode('-', $type); |
|
397 | 397 | $basetype = $subtypes[0]; |
398 | - $class_name = __CLASS__.'\\'.implode('\\',array_map('ucfirst',$subtypes)); |
|
399 | - if(!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
398 | + $class_name = __CLASS__.'\\'.implode('\\', array_map('ucfirst', $subtypes)); |
|
399 | + if (!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
400 | 400 | { |
401 | 401 | // Try for base type, it's probably better than the root |
402 | 402 | $class_name = self::$widget_registry[$basetype]; |
403 | 403 | } |
404 | - if(!class_exists($class_name)) |
|
404 | + if (!class_exists($class_name)) |
|
405 | 405 | { |
406 | 406 | // Fall back to widget class, we can not ignore it, as the widget may contain other widgets |
407 | 407 | $class_name = __CLASS__; |
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
411 | - if(!$xml) |
|
411 | + if (!$xml) |
|
412 | 412 | { |
413 | 413 | if (empty($type)) $type = 'widget'; |
414 | 414 | $xml = "<$type id='$id'/>"; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | if ($type == 'template' && $id && ($template = Widget\Template::instance($id))) |
420 | 420 | { |
421 | 421 | // references can set different attributes like: class, span, content (namespace) |
422 | - return $template->set_attrs($xml, false); // false = need to clone template, if attributs are set! |
|
422 | + return $template->set_attrs($xml, false); // false = need to clone template, if attributs are set! |
|
423 | 423 | } |
424 | 424 | return new $class_name($xml); |
425 | 425 | } |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | * @param string $type =null |
432 | 432 | * @return Widget|NULL |
433 | 433 | */ |
434 | - public function getElementById($id, $type=null) |
|
434 | + public function getElementById($id, $type = null) |
|
435 | 435 | { |
436 | - foreach($this->children as $child) |
|
436 | + foreach ($this->children as $child) |
|
437 | 437 | { |
438 | 438 | if ($child->id === $id && (is_null($type) || $child->type === $type)) |
439 | 439 | { |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | public function getElementsByType($type) |
457 | 457 | { |
458 | 458 | $elements = array(); |
459 | - foreach($this->children as $child) |
|
459 | + foreach ($this->children as $child) |
|
460 | 460 | { |
461 | 461 | if ($child->type === $type) |
462 | 462 | { |
@@ -476,14 +476,14 @@ discard block |
||
476 | 476 | * @param array $params =array('') parameter(s) first parameter has to be the cname, second $expand! |
477 | 477 | * @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children |
478 | 478 | */ |
479 | - public function run($method_name, $params=array(''), $respect_disabled=false) |
|
479 | + public function run($method_name, $params = array(''), $respect_disabled = false) |
|
480 | 480 | { |
481 | 481 | // maintain $expand array name-expansion |
482 | 482 | $cname = $params[0]; |
483 | - $expand =& $params[1]; |
|
483 | + $expand = & $params[1]; |
|
484 | 484 | if ($expand['cname'] && $expand['cname'] !== $cname) |
485 | 485 | { |
486 | - $expand['cont'] =& self::get_array(self::$request->content, $cname); |
|
486 | + $expand['cont'] = & self::get_array(self::$request->content, $cname); |
|
487 | 487 | $expand['cname'] = $cname; |
488 | 488 | } |
489 | 489 | if ($respect_disabled && ($disabled = $this->attrs['disabled'] && self::check_disabled($this->attrs['disabled'], $expand))) |
@@ -496,22 +496,22 @@ discard block |
||
496 | 496 | // Some parameter checking to avoid fatal errors |
497 | 497 | $call = true; |
498 | 498 | $method = new ReflectionMethod($this, $method_name); |
499 | - foreach($method->getParameters() as $index => $param) |
|
499 | + foreach ($method->getParameters() as $index => $param) |
|
500 | 500 | { |
501 | - if(!$param->isOptional() && !array_key_exists($index,$params)) |
|
501 | + if (!$param->isOptional() && !array_key_exists($index, $params)) |
|
502 | 502 | { |
503 | 503 | error_log("Missing required parameter {$param->getPosition()}: {$param->getName()}"); |
504 | 504 | $call = false; |
505 | 505 | } |
506 | - if($param->isArray() && !is_array($params[$index])) |
|
506 | + if ($param->isArray() && !is_array($params[$index])) |
|
507 | 507 | { |
508 | 508 | error_log("$method_name expects an array for {$param->getPosition()}: {$param->getName()}"); |
509 | 509 | $params[$index] = (array)$params[$index]; |
510 | 510 | } |
511 | 511 | } |
512 | - if($call) call_user_func_array(array($this, $method_name), $params); |
|
512 | + if ($call) call_user_func_array(array($this, $method_name), $params); |
|
513 | 513 | } |
514 | - foreach($this->children as $child) |
|
514 | + foreach ($this->children as $child) |
|
515 | 515 | { |
516 | 516 | // If type has something that can be expanded, we need to expand it so the correct method is run |
517 | 517 | $this->expand_widget($child, $expand); |
@@ -526,15 +526,15 @@ discard block |
||
526 | 526 | * @param Widget& $child Widget to check & expand if needed |
527 | 527 | * @param array& $expand Expansion array |
528 | 528 | */ |
529 | - protected function expand_widget(Widget &$child, array &$expand) |
|
529 | + protected function expand_widget(Widget&$child, array &$expand) |
|
530 | 530 | { |
531 | - if(strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false) |
|
531 | + if (strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false) |
|
532 | 532 | { |
533 | - $type = self::expand_name($child->attrs['type'],$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
534 | - $id = self::expand_name($child->id,$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
533 | + $type = self::expand_name($child->attrs['type'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
534 | + $id = self::expand_name($child->id, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
535 | 535 | $attrs = $child->attrs; |
536 | 536 | unset($attrs['type']); |
537 | - $expanded_child = self::factory($type, false,$id); |
|
537 | + $expanded_child = self::factory($type, false, $id); |
|
538 | 538 | $expanded_child->id = $id; |
539 | 539 | $expanded_child->type = $type; |
540 | 540 | $expanded_child->attrs = $attrs + array('type' => $type); |
@@ -557,14 +557,14 @@ discard block |
||
557 | 557 | { |
558 | 558 | if (($not = $disabled[0] == '!')) |
559 | 559 | { |
560 | - $disabled = substr($disabled,1); |
|
560 | + $disabled = substr($disabled, 1); |
|
561 | 561 | } |
562 | - list($value,$check) = $vals = explode('=',$disabled); |
|
562 | + list($value, $check) = $vals = explode('=', $disabled); |
|
563 | 563 | |
564 | 564 | // use expand_name to be able to use @ or $ |
565 | 565 | $val = self::expand_name($value, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
566 | 566 | $check_val = self::expand_name($check, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
567 | - $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val,$val) : $val == $check_val); |
|
567 | + $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val, $val) : $val == $check_val); |
|
568 | 568 | if ($not) $result = !$result; |
569 | 569 | |
570 | 570 | //error_log(__METHOD__."('".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')); |
@@ -606,33 +606,33 @@ discard block |
||
606 | 606 | * "del[$cont[id]]" expands to "del[123]" if $cont = array('id' => 123) |
607 | 607 | * @return string the expanded name |
608 | 608 | */ |
609 | - protected static function expand_name($name,$c,$row,$c_='',$row_='',$cont='') |
|
609 | + protected static function expand_name($name, $c, $row, $c_ = '', $row_ = '', $cont = '') |
|
610 | 610 | { |
611 | 611 | $is_index_in_content = $name[0] == '@'; |
612 | - if (($pos_var=strpos($name,'$')) !== false) |
|
612 | + if (($pos_var = strpos($name, '$')) !== false) |
|
613 | 613 | { |
614 | 614 | if (!$cont) |
615 | 615 | { |
616 | 616 | $cont = array(); |
617 | 617 | } |
618 | 618 | if (!is_numeric($c)) $c = self::chrs2num($c); |
619 | - $col = self::num2chrs($c-1); // $c-1 to get: 0:'@', 1:'A', ... |
|
620 | - $col_ = self::num2chrs($c_-1); |
|
619 | + $col = self::num2chrs($c - 1); // $c-1 to get: 0:'@', 1:'A', ... |
|
620 | + $col_ = self::num2chrs($c_ - 1); |
|
621 | 621 | $row_cont = $cont[$row]; |
622 | 622 | $col_row_cont = $cont[$col.$row]; |
623 | 623 | |
624 | - eval('$name = "'.str_replace('"','\\"',$name).'";'); |
|
625 | - unset($col_, $row_, $row_cont, $col_row_cont); // quiten IDE warning about used vars, they might be used in above eval! |
|
624 | + eval('$name = "'.str_replace('"', '\\"', $name).'";'); |
|
625 | + unset($col_, $row_, $row_cont, $col_row_cont); // quiten IDE warning about used vars, they might be used in above eval! |
|
626 | 626 | } |
627 | 627 | if ($is_index_in_content) |
628 | 628 | { |
629 | 629 | if ($name[1] == '@' && is_array(self::$request->content)) |
630 | 630 | { |
631 | - $name = self::get_array(self::$request->content,substr($name,2)); |
|
631 | + $name = self::get_array(self::$request->content, substr($name, 2)); |
|
632 | 632 | } |
633 | - elseif(is_array($cont)) |
|
633 | + elseif (is_array($cont)) |
|
634 | 634 | { |
635 | - $name = self::get_array($cont,substr($name,1)); |
|
635 | + $name = self::get_array($cont, substr($name, 1)); |
|
636 | 636 | } |
637 | 637 | else |
638 | 638 | { |
@@ -654,11 +654,11 @@ discard block |
||
654 | 654 | $min = ord('A'); |
655 | 655 | $max = ord('Z') - $min + 1; |
656 | 656 | |
657 | - $num = 1+ord($chrs{0})-$min; |
|
657 | + $num = 1 + ord($chrs{0}) - $min; |
|
658 | 658 | if (strlen($chrs) > 1) |
659 | 659 | { |
660 | 660 | $num *= 1 + $max - $min; |
661 | - $num += 1+ord($chrs{1})-$min; |
|
661 | + $num += 1 + ord($chrs{1}) - $min; |
|
662 | 662 | } |
663 | 663 | return $num; |
664 | 664 | } |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | */ |
690 | 690 | public function __toString() |
691 | 691 | { |
692 | - return '['.get_class($this).'] ' . |
|
692 | + return '['.get_class($this).'] '. |
|
693 | 693 | $this->type.($this->attrs['type'] && $this->attrs['type'] != $this->type ? '('.$this->attrs['type'].')' : '').'#'.$this->id; |
694 | 694 | } |
695 | 695 | |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | */ |
699 | 699 | public function __clone() |
700 | 700 | { |
701 | - foreach($this->children as $child_num => $child) { |
|
701 | + foreach ($this->children as $child_num => $child) { |
|
702 | 702 | $this->children[$child_num] = clone $child; |
703 | 703 | } |
704 | 704 | } |
@@ -709,16 +709,16 @@ discard block |
||
709 | 709 | * @param string $indent ='' |
710 | 710 | * @return string |
711 | 711 | */ |
712 | - public function toXml($indent='') |
|
712 | + public function toXml($indent = '') |
|
713 | 713 | { |
714 | 714 | echo "$indent<$this->type"; |
715 | 715 | if ($this->id) echo ' id="'.htmlspecialchars($this->id).'"'; |
716 | - foreach($this->attrs as $name => $value) |
|
716 | + foreach ($this->attrs as $name => $value) |
|
717 | 717 | { |
718 | 718 | if ($name == 'options' && $this->legacy_options && (!is_array($this->legacy_options) || |
719 | 719 | isset($this->legacy_options[$this->attrs['type'] ? $this->attrs['type'] : $this->type]))) |
720 | 720 | { |
721 | - continue; // do NOT output already converted legacy options |
|
721 | + continue; // do NOT output already converted legacy options |
|
722 | 722 | } |
723 | 723 | echo ' '.$name.'="'.htmlspecialchars($value).'"'; |
724 | 724 | } |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | if ($this->children) |
728 | 728 | { |
729 | 729 | echo ">\n"; |
730 | - foreach($this->children as $child) |
|
730 | + foreach ($this->children as $child) |
|
731 | 731 | { |
732 | 732 | $child->toXml($indent."\t"); |
733 | 733 | } |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | * @param array $expand =null values for keys 'c', 'row', 'c_', 'row_', 'cont' |
751 | 751 | * @return string complete form-name |
752 | 752 | */ |
753 | - static function form_name($cname,$name,array $expand=null) |
|
753 | + static function form_name($cname, $name, array $expand = null) |
|
754 | 754 | { |
755 | 755 | if ($expand && !empty($name)) |
756 | 756 | { |
@@ -758,18 +758,18 @@ discard block |
||
758 | 758 | } |
759 | 759 | if (count($name_parts = explode('[', $name, 2)) > 1) |
760 | 760 | { |
761 | - $name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1],0,-1))); |
|
761 | + $name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1], 0, -1))); |
|
762 | 762 | } |
763 | 763 | if (!empty($cname)) |
764 | 764 | { |
765 | - array_unshift($name_parts,$cname); |
|
765 | + array_unshift($name_parts, $cname); |
|
766 | 766 | } |
767 | 767 | $form_name = array_shift($name_parts); |
768 | 768 | if (count($name_parts)) |
769 | 769 | { |
770 | 770 | // RB: not sure why this business with entity encoding for square brakets, it messes up validation |
771 | 771 | //$form_name .= '['.implode('][',$name_parts).']'; |
772 | - $form_name .= '['.implode('][',$name_parts).']'; |
|
772 | + $form_name .= '['.implode('][', $name_parts).']'; |
|
773 | 773 | } |
774 | 774 | return $form_name; |
775 | 775 | } |
@@ -786,36 +786,36 @@ discard block |
||
786 | 786 | * @param bool $skip_empty returns false if $idx is not present in $arr |
787 | 787 | * @return mixed reference to $arr[$idx] or null if $idx is not set and not $reference_into |
788 | 788 | */ |
789 | - static function &get_array(&$arr,$_idx,$reference_into=False,$skip_empty=False) |
|
789 | + static function &get_array(&$arr, $_idx, $reference_into = False, $skip_empty = False) |
|
790 | 790 | { |
791 | 791 | if (!is_array($arr)) |
792 | 792 | { |
793 | 793 | throw new Api\Exception\AssertionFailed(__METHOD__."(\$arr,'$_idx',$reference_into,$skip_empty) \$arr is no array!"); |
794 | 794 | } |
795 | - if (is_object($_idx)) return false; // given an error in php5.2 |
|
795 | + if (is_object($_idx)) return false; // given an error in php5.2 |
|
796 | 796 | |
797 | 797 | // Make sure none of these are left |
798 | - $idx = str_replace(array('[',']'), array('[',']'), $_idx); |
|
798 | + $idx = str_replace(array('[', ']'), array('[', ']'), $_idx); |
|
799 | 799 | |
800 | 800 | // Handle things expecting arrays - ends in [] |
801 | - if(substr($idx,-2) == "[]") |
|
801 | + if (substr($idx, -2) == "[]") |
|
802 | 802 | { |
803 | - $idx = substr($idx,0,-2); |
|
803 | + $idx = substr($idx, 0, -2); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | if (count($idxs = explode('[', $idx, 2)) > 1) |
807 | 807 | { |
808 | - $idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1],0,-1))); |
|
808 | + $idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1], 0, -1))); |
|
809 | 809 | } |
810 | 810 | $pos = &$arr; |
811 | - foreach($idxs as $idx) |
|
811 | + foreach ($idxs as $idx) |
|
812 | 812 | { |
813 | 813 | if (!is_array($pos) && (!$reference_into || $reference_into && isset($pos))) |
814 | 814 | { |
815 | 815 | //if ($reference_into) error_log(__METHOD__."(".(strlen($s=array2string($arr))>512?substr($s,0,512).'...':$s).", '$idx', ".array2string($reference_into).", ".array2string($skip_empty).") ".function_backtrace()); |
816 | 816 | return null; |
817 | 817 | } |
818 | - if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
818 | + if ($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
819 | 819 | $pos = &$pos[$idx]; |
820 | 820 | } |
821 | 821 | return $pos; |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | */ |
834 | 834 | static function set_array(&$_arr, $_idx, $_value) |
835 | 835 | { |
836 | - $ref =& self::get_array($_arr, $_idx, true); |
|
836 | + $ref = & self::get_array($_arr, $_idx, true); |
|
837 | 837 | if (true) $ref = $_value; |
838 | 838 | } |
839 | 839 | |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | * @param string $form_name =null form_name, to not calculate him again |
848 | 848 | * @return boolean |
849 | 849 | */ |
850 | - public function is_readonly($cname='', $form_name=null) |
|
850 | + public function is_readonly($cname = '', $form_name = null) |
|
851 | 851 | { |
852 | 852 | if (!isset($form_name)) |
853 | 853 | { |
@@ -857,11 +857,11 @@ discard block |
||
857 | 857 | $form_name = self::form_name($cname, $this->id, $expand); |
858 | 858 | } |
859 | 859 | $readonly = $this->attrs['readonly'] || self::$request->readonlys[$form_name] || |
860 | - self::get_array(self::$request->readonlys,$form_name) === true || |
|
860 | + self::get_array(self::$request->readonlys, $form_name) === true || |
|
861 | 861 | isset(self::$request->readonlys['__ALL__']) && ( |
862 | 862 | // Exceptions to all |
863 | 863 | self::$request->readonlys[$form_name] !== false && |
864 | - self::get_array(self::$request->readonlys,$form_name) !== false |
|
864 | + self::get_array(self::$request->readonlys, $form_name) !== false |
|
865 | 865 | ); |
866 | 866 | |
867 | 867 | //error_log(__METHOD__."('$cname') this->id='$this->id' --> form_name='$form_name': attrs[readonly]=".array2string($this->attrs['readonly']).", readonlys['$form_name']=".array2string(self::$request->readonlys[$form_name]).", readonlys[$form_name]=".array2string(self::get_array(self::$request->readonlys,$form_name)).", readonlys['__ALL__']=".array2string(self::$request->readonlys['__ALL__'])." returning ".array2string($readonly)); |
@@ -881,12 +881,12 @@ discard block |
||
881 | 881 | * @param string|boolean $error error-message already translated or false to reset all existing error for given name |
882 | 882 | * @param string $cname =null set it to '', if the name is already a form-name, defaults to self::$name_vars |
883 | 883 | */ |
884 | - public static function set_validation_error($name,$error,$cname=null) |
|
884 | + public static function set_validation_error($name, $error, $cname = null) |
|
885 | 885 | { |
886 | 886 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
887 | 887 | error_log(__METHOD__."('$name','$error','$cname') ".function_backtrace()); |
888 | 888 | |
889 | - if ($cname) $name = self::form_name($cname,$name); |
|
889 | + if ($cname) $name = self::form_name($cname, $name); |
|
890 | 890 | |
891 | 891 | if ($error === false) |
892 | 892 | { |
@@ -909,18 +909,18 @@ discard block |
||
909 | 909 | * @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars |
910 | 910 | * @return boolean true if there are not ignored validation errors, false otherwise |
911 | 911 | */ |
912 | - public static function validation_errors($ignore_validation='',$cname='') |
|
912 | + public static function validation_errors($ignore_validation = '', $cname = '') |
|
913 | 913 | { |
914 | 914 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
915 | 915 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors); |
916 | 916 | if (!$ignore_validation) return count(self::$validation_errors) > 0; |
917 | 917 | |
918 | - foreach(array_values(self::$validation_errors) as $name) |
|
918 | + foreach (array_values(self::$validation_errors) as $name) |
|
919 | 919 | { |
920 | - if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); |
|
920 | + if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/', '\\1\\2', $name); |
|
921 | 921 | |
922 | 922 | // treat $ignoare_validation only as regular expression, if it starts with a slash |
923 | - if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) || |
|
923 | + if ($ignore_validation[0] == '/' && !preg_match($ignore_validation, $name) || |
|
924 | 924 | $ignore_validation[0] != '/' && $ignore_validation != $name) |
925 | 925 | { |
926 | 926 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') name='$name' ($error) not ignored!!!</p>\n"; |
@@ -957,14 +957,14 @@ discard block |
||
957 | 957 | * @param mixed $val if not NULL sets attribute else returns it |
958 | 958 | * @return reference to attribute |
959 | 959 | */ |
960 | - public static function &setElementAttribute($name,$attr,$val) |
|
960 | + public static function &setElementAttribute($name, $attr, $val) |
|
961 | 961 | { |
962 | 962 | //error_log(__METHOD__."('$name', '$attr', ...) request=".get_class(self::$request).", response=".get_class(self::$response).function_backtrace()); |
963 | - $ref =& self::$request->modifications[$name][$attr]; |
|
964 | - if(self::$request && self::$response && (!isset($this) || $val != $this->attrs[$attr])) |
|
963 | + $ref = & self::$request->modifications[$name][$attr]; |
|
964 | + if (self::$request && self::$response && (!isset($this) || $val != $this->attrs[$attr])) |
|
965 | 965 | { |
966 | 966 | // In an AJAX response - automatically add |
967 | - self::$response->generic('assign',array( |
|
967 | + self::$response->generic('assign', array( |
|
968 | 968 | 'etemplate_exec_id' => self::$request->id(), |
969 | 969 | 'id' => $name, |
970 | 970 | 'key' => $attr, |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | * @param boolean $disabled =true disable or enable a cell, default true=disable |
989 | 989 | * @return reference to attribute |
990 | 990 | */ |
991 | - public function disableElement($name,$disabled=True) |
|
991 | + public function disableElement($name, $disabled = True) |
|
992 | 992 | { |
993 | 993 | return self::setElementAttribute($name, 'disabled', $disabled); |
994 | 994 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | |
47 | 47 | Api\Framework::includeCSS('/api/templates/default/etemplate2.css'); |
48 | 48 | |
49 | - Api\Framework::includeCSS('api','widget_browser',false); |
|
49 | + Api\Framework::includeCSS('api', 'widget_browser', false); |
|
50 | 50 | |
51 | 51 | // load translations |
52 | 52 | Api\Translation::add_app('etemplate'); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | return $mime; |
48 | 48 | } |
49 | - return lang('%1 file',strtoupper($ext)).' ('.$mime.')'; |
|
49 | + return lang('%1 file', strtoupper($ext)).' ('.$mime.')'; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | if (empty($_ext)) |
65 | 65 | { |
66 | - return 'text/plain';//assume no extension is a text file |
|
66 | + return 'text/plain'; //assume no extension is a text file |
|
67 | 67 | } |
68 | 68 | $ext = strtolower($_ext); |
69 | 69 | if (!array_key_exists($ext, self::$mime_extension_map)) |
@@ -188,24 +188,24 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public static function analyze_data($data) |
190 | 190 | { |
191 | - if(!is_writeable(@$GLOBALS['egw_info']['server']['temp_dir'])) |
|
191 | + if (!is_writeable(@$GLOBALS['egw_info']['server']['temp_dir'])) |
|
192 | 192 | { |
193 | 193 | //nothing we can do but bail out |
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | |
197 | 197 | mt_srand(time()); |
198 | - $filename = $GLOBALS['egw_info']['server']['temp_dir'] . '/' |
|
199 | - . md5( time() + mt_rand() ) . '.tmp'; |
|
198 | + $filename = $GLOBALS['egw_info']['server']['temp_dir'].'/' |
|
199 | + . md5(time() + mt_rand()).'.tmp'; |
|
200 | 200 | |
201 | 201 | $fp = @fopen($filename, 'ab'); |
202 | - if(!$fp || !$data) |
|
202 | + if (!$fp || !$data) |
|
203 | 203 | { |
204 | 204 | //houston we have a problem - bail out |
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | - if(!fwrite($fp, $data)) |
|
208 | + if (!fwrite($fp, $data)) |
|
209 | 209 | { |
210 | 210 | //bail out again |
211 | 211 | return false; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | |
216 | 216 | $mime = self::analyze_file($filename); |
217 | 217 | |
218 | - unlink($filename);//remove the temp file |
|
218 | + unlink($filename); //remove the temp file |
|
219 | 219 | |
220 | 220 | return $mime; |
221 | 221 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @var array of extenstion to mime mappings |
234 | 234 | */ |
235 | 235 | static $mime_extension_map = array( |
236 | - 'txt' => 'text/plain', // should be first, so text/plain maps back to .txt |
|
236 | + 'txt' => 'text/plain', // should be first, so text/plain maps back to .txt |
|
237 | 237 | '3dml' => 'text/vnd.in3d.3dml', |
238 | 238 | '3ds' => 'image/x-3ds', |
239 | 239 | '3g2' => 'video/3gpp2', |
@@ -29,7 +29,7 @@ |
||
29 | 29 | class Exception extends \Exception |
30 | 30 | { |
31 | 31 | // nothing fancy yet |
32 | - function __construct($msg=null,$code=100,\Exception $previous=null) |
|
32 | + function __construct($msg = null, $code = 100, \Exception $previous = null) |
|
33 | 33 | { |
34 | 34 | return parent::__construct($msg, $code, $previous); |
35 | 35 | } |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * @return adLDAP |
134 | 134 | * @throws adLDAPException |
135 | 135 | */ |
136 | - public static function get_adldap(array &$config=null) |
|
136 | + public static function get_adldap(array &$config = null) |
|
137 | 137 | { |
138 | 138 | static $adldap = array(); |
139 | - if (!$config) $config =& $GLOBALS['egw_info']['server']; |
|
139 | + if (!$config) $config = & $GLOBALS['egw_info']['server']; |
|
140 | 140 | |
141 | 141 | if (!isset($adldap[$config['ads_domain']])) |
142 | 142 | { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!"); |
145 | 145 | |
146 | 146 | $base_dn_parts = array(); |
147 | - foreach(explode('.', $config['ads_domain']) as $dc) |
|
147 | + foreach (explode('.', $config['ads_domain']) as $dc) |
|
148 | 148 | { |
149 | 149 | $base_dn_parts[] = 'DC='.$dc; |
150 | 150 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param int $account_id |
173 | 173 | * @return string|NULL |
174 | 174 | */ |
175 | - protected function get_sid($account_id=null) |
|
175 | + protected function get_sid($account_id = null) |
|
176 | 176 | { |
177 | 177 | static $domain_sid = null; |
178 | 178 | if (!isset($domain_sid)) |
@@ -207,14 +207,14 @@ discard block |
||
207 | 207 | * @param boolean $set_if_empty =false true set from DN of "Domain Users" group # |
208 | 208 | * @return string |
209 | 209 | */ |
210 | - public function ads_context($set_if_empty=false) |
|
210 | + public function ads_context($set_if_empty = false) |
|
211 | 211 | { |
212 | 212 | if (empty($this->frontend->config[self::ADS_CONTEXT])) |
213 | 213 | { |
214 | 214 | if ($set_if_empty && ($dn = $this->id2name(-self::DOMAIN_USERS_GROUP, 'account_dn'))) |
215 | 215 | { |
216 | 216 | $dn = preg_replace('/^CN=.*?,(CN|OU)=/i', '$1=', $dn); |
217 | - Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT]=$dn, 'phpgwapi'); |
|
217 | + Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT] = $dn, 'phpgwapi'); |
|
218 | 218 | } |
219 | 219 | else |
220 | 220 | { |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param boolean $reconnect =false true: reconnect even if already connected |
252 | 252 | * @return resource |
253 | 253 | */ |
254 | - public function ldap_connection($reconnect=false) |
|
254 | + public function ldap_connection($reconnect = false) |
|
255 | 255 | { |
256 | 256 | if (($reconnect || !($ds = $this->adldap->getLdapConnection())) && |
257 | 257 | // call connect, thought I dont know how it can be not connected ... |
@@ -415,8 +415,7 @@ discard block |
||
415 | 415 | $data = Api\Translation::convert($_data, 'utf-8'); |
416 | 416 | |
417 | 417 | // no need to calculate sid, if already calculated |
418 | - $sid = is_string($data['objectsid']) ? $data['objectsid'] : |
|
419 | - $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
418 | + $sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
420 | 419 | $account_id = -self::sid2account_id($sid); |
421 | 420 | |
422 | 421 | $group = array( |
@@ -430,10 +429,8 @@ discard block |
||
430 | 429 | 'account_lastname' => lang('Group'), |
431 | 430 | 'account_fullname' => lang('Group').' '.$data['samaccountname'][0], |
432 | 431 | 'account_email' => $data['mail'][0], |
433 | - 'account_created' => !isset($data['whencreated'][0]) ? null : |
|
434 | - self::_when2ts($data['whencreated'][0]), |
|
435 | - 'account_modified' => !isset($data['whenchanged'][0]) ? null : |
|
436 | - self::_when2ts($data['whenchanged'][0]), |
|
432 | + 'account_created' => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]), |
|
433 | + 'account_modified' => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]), |
|
437 | 434 | 'account_description' => $data['description'][0], |
438 | 435 | 'mailAllowed' => true, |
439 | 436 | ); |
@@ -453,7 +450,7 @@ discard block |
||
453 | 450 | { |
454 | 451 | if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'g', self::$group_attributes))) |
455 | 452 | { |
456 | - return false; // group not found |
|
453 | + return false; // group not found |
|
457 | 454 | } |
458 | 455 | $group = $this->_ldap2group(array_shift($data)); |
459 | 456 | |
@@ -476,8 +473,7 @@ discard block |
||
476 | 473 | $data = Api\Translation::convert($_data, 'utf-8'); |
477 | 474 | |
478 | 475 | // no need to calculate sid, if already calculated |
479 | - $sid = is_string($data['objectsid']) ? $data['objectsid'] : |
|
480 | - $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
476 | + $sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
481 | 477 | $account_id = self::sid2account_id($sid); |
482 | 478 | |
483 | 479 | $user = array( |
@@ -493,22 +489,18 @@ discard block |
||
493 | 489 | 'account_email' => $data['mail'][0], |
494 | 490 | 'account_fullname' => $data['displayname'][0], |
495 | 491 | 'account_phone' => $data['telephonenumber'][0], |
496 | - 'account_status' => $data['useraccountcontrol'][0] & 2 ? false : 'A', |
|
497 | - 'account_expires' => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : |
|
498 | - $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]), |
|
499 | - 'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : |
|
500 | - $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])), |
|
501 | - 'account_created' => !isset($data['whencreated'][0]) ? null : |
|
502 | - self::_when2ts($data['whencreated'][0]), |
|
503 | - 'account_modified' => !isset($data['whenchanged'][0]) ? null : |
|
504 | - self::_when2ts($data['whenchanged'][0]), |
|
492 | + 'account_status' => $data['useraccountcontrol'][0]&2 ? false : 'A', |
|
493 | + 'account_expires' => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]), |
|
494 | + 'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])), |
|
495 | + 'account_created' => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]), |
|
496 | + 'account_modified' => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]), |
|
505 | 497 | ); |
506 | 498 | // expired accounts are NOT active |
507 | 499 | if ($user['account_expires'] !== -1 && $user['account_expires'] < time()) |
508 | 500 | { |
509 | 501 | $user['account_status'] = false; |
510 | 502 | } |
511 | - $user['person_id'] = $user['account_guid']; // id of contact |
|
503 | + $user['person_id'] = $user['account_guid']; // id of contact |
|
512 | 504 | //error_log(__METHOD__."(".array2string($data).") returning ".array2string($user)); |
513 | 505 | return $user; |
514 | 506 | } |
@@ -538,7 +530,7 @@ discard block |
||
538 | 530 | { |
539 | 531 | if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'u', self::$user_attributes))) |
540 | 532 | { |
541 | - return false; // user not found |
|
533 | + return false; // user not found |
|
542 | 534 | } |
543 | 535 | $user = $this->_ldap2user(array_shift($data)); |
544 | 536 | |
@@ -561,10 +553,10 @@ discard block |
||
561 | 553 | */ |
562 | 554 | protected static function _when2ts($_when) |
563 | 555 | { |
564 | - static $utc=null; |
|
556 | + static $utc = null; |
|
565 | 557 | if (!isset($utc)) $utc = new \DateTimeZone('UTC'); |
566 | 558 | |
567 | - list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
|
559 | + list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
|
568 | 560 | $datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc); |
569 | 561 | if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone); |
570 | 562 | |
@@ -579,7 +571,7 @@ discard block |
||
579 | 571 | * @param array $old =null current data |
580 | 572 | * @return int|false account_id or false on error |
581 | 573 | */ |
582 | - protected function _save_group(array &$data, array $old=null) |
|
574 | + protected function _save_group(array &$data, array $old = null) |
|
583 | 575 | { |
584 | 576 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
585 | 577 | |
@@ -590,7 +582,7 @@ discard block |
||
590 | 582 | 'account_description' => 'description', |
591 | 583 | ); |
592 | 584 | $attributes = array(); |
593 | - foreach($new2adldap as $egw => $adldap) |
|
585 | + foreach ($new2adldap as $egw => $adldap) |
|
594 | 586 | { |
595 | 587 | $attributes[$adldap] = (string)$data[$egw]; |
596 | 588 | } |
@@ -627,11 +619,11 @@ discard block |
||
627 | 619 | 'account_description' => 'description', |
628 | 620 | ); |
629 | 621 | $ldap = array(); |
630 | - foreach($egw2adldap as $egw => $adldap) |
|
622 | + foreach ($egw2adldap as $egw => $adldap) |
|
631 | 623 | { |
632 | 624 | if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw]) |
633 | 625 | { |
634 | - switch($egw) |
|
626 | + switch ($egw) |
|
635 | 627 | { |
636 | 628 | case 'account_description': |
637 | 629 | $ldap[$adldap] = !empty($data[$egw]) ? $data[$egw] : array(); |
@@ -644,7 +636,7 @@ discard block |
||
644 | 636 | } |
645 | 637 | } |
646 | 638 | // attributes not (yet) suppored by adldap |
647 | - if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap))) |
|
639 | + if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap))) |
|
648 | 640 | { |
649 | 641 | error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret)); |
650 | 642 | return false; |
@@ -660,7 +652,7 @@ discard block |
||
660 | 652 | * @param array $old =null current data |
661 | 653 | * @return int|false account_id or false on error |
662 | 654 | */ |
663 | - protected function _save_user(array &$data, array $old=null) |
|
655 | + protected function _save_user(array &$data, array $old = null) |
|
664 | 656 | { |
665 | 657 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
666 | 658 | if (!isset($data['account_fullname']) && !empty($data['account_firstname']) && !empty($data['account_lastname'])) |
@@ -680,12 +672,12 @@ discard block |
||
680 | 672 | 'account_status' => 'enabled', |
681 | 673 | ); |
682 | 674 | $attributes = array(); |
683 | - foreach($new2adldap as $egw => $adldap) |
|
675 | + foreach ($new2adldap as $egw => $adldap) |
|
684 | 676 | { |
685 | 677 | if ($egw == 'account_passwd' && (empty($data[$egw]) || |
686 | 678 | !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) |
687 | 679 | { |
688 | - continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
|
680 | + continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
|
689 | 681 | } |
690 | 682 | if (isset($data[$egw])) $attributes[$adldap] = $data[$egw]; |
691 | 683 | } |
@@ -722,7 +714,7 @@ discard block |
||
722 | 714 | 'account_firstname' => 'firstname', |
723 | 715 | 'account_lastname' => 'surname', |
724 | 716 | 'account_email' => 'email', |
725 | - 'account_fullname' => 'display_name', // handeled currently in rename above, as not supported by adLDAP |
|
717 | + 'account_fullname' => 'display_name', // handeled currently in rename above, as not supported by adLDAP |
|
726 | 718 | 'account_passwd' => 'password', |
727 | 719 | 'account_status' => 'enabled', |
728 | 720 | 'account_primary_group' => 'primarygroupid', |
@@ -735,7 +727,7 @@ discard block |
||
735 | 727 | // for a new entry set certain values (eg. profilePath) to in setup configured value |
736 | 728 | if ($new_entry) |
737 | 729 | { |
738 | - foreach($this->frontend->config as $name => $value) |
|
730 | + foreach ($this->frontend->config as $name => $value) |
|
739 | 731 | { |
740 | 732 | if (substr($name, 0, 8) == 'ads_new_') |
741 | 733 | { |
@@ -743,22 +735,22 @@ discard block |
||
743 | 735 | } |
744 | 736 | } |
745 | 737 | } |
746 | - foreach($egw2adldap as $egw => $adldap) |
|
738 | + foreach ($egw2adldap as $egw => $adldap) |
|
747 | 739 | { |
748 | 740 | if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw]) |
749 | 741 | { |
750 | - switch($egw) |
|
742 | + switch ($egw) |
|
751 | 743 | { |
752 | 744 | case 'account_passwd': |
753 | 745 | if (!empty($data[$egw]) && ($this->adldap->getUseSSL() || $this->adldap->getUseTLS())) |
754 | 746 | { |
755 | - $attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS |
|
747 | + $attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS |
|
756 | 748 | } |
757 | 749 | break; |
758 | 750 | case 'account_primary_group': |
759 | 751 | // setting a primary group seems to fail, if user is no member of that group |
760 | 752 | if (isset($old['memberships'][$data[$egw]]) || |
761 | - $this->adldap->group()->addUser($group=$this->id2name($data[$egw]), $data['account_id'])) |
|
753 | + $this->adldap->group()->addUser($group = $this->id2name($data[$egw]), $data['account_id'])) |
|
762 | 754 | { |
763 | 755 | $old['memberships'][$data[$egw]] = $group; |
764 | 756 | $ldap[$adldap] = abs($data[$egw]); |
@@ -769,11 +761,10 @@ discard block |
||
769 | 761 | $ldap['userPrincipalName'] = $data[$egw].'@'.$this->frontend->config['ads_domain']; |
770 | 762 | break; |
771 | 763 | case 'account_expires': |
772 | - $attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : |
|
773 | - self::convertUnixTimeToWindowsTime($data[$egw]); |
|
764 | + $attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : self::convertUnixTimeToWindowsTime($data[$egw]); |
|
774 | 765 | break; |
775 | 766 | case 'account_status': |
776 | - if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
767 | + if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
777 | 768 | $attributes[$adldap] = $data[$egw] == 'A'; |
778 | 769 | break; |
779 | 770 | case 'account_lastpwd_change': |
@@ -795,7 +786,7 @@ discard block |
||
795 | 786 | } |
796 | 787 | //elseif ($attributes) error_log(__METHOD__."(".array2string($data).") adldap->user()->modify('$data[account_lid]', ".array2string($attributes).') returned '.array2string($ret).' '.function_backtrace()); |
797 | 788 | // attributes not (yet) suppored by adldap |
798 | - if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap))) |
|
789 | + if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap))) |
|
799 | 790 | { |
800 | 791 | error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret).' ('.ldap_error($ds).') '.function_backtrace()); |
801 | 792 | return false; |
@@ -868,11 +859,11 @@ discard block |
||
868 | 859 | $query = Api\Ldap::quote(strtolower($param['query'])); |
869 | 860 | |
870 | 861 | $accounts = array(); |
871 | - if($param['type'] !== 'groups') |
|
862 | + if ($param['type'] !== 'groups') |
|
872 | 863 | { |
873 | 864 | if (!empty($query) && $query != '*') |
874 | 865 | { |
875 | - switch($param['query_type']) |
|
866 | + switch ($param['query_type']) |
|
876 | 867 | { |
877 | 868 | case 'all': |
878 | 869 | default: |
@@ -903,14 +894,14 @@ discard block |
||
903 | 894 | $membership_filter = '(|(memberOf='.$this->id2name((int)$param['type'], 'account_dn').')(PrimaryGroupId='.abs($param['type']).'))'; |
904 | 895 | $filter = $filter ? "(&$membership_filter$filter)" : $membership_filter; |
905 | 896 | } |
906 | - foreach($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data) |
|
897 | + foreach ($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data) |
|
907 | 898 | { |
908 | 899 | $account = $this->_ldap2user($data); |
909 | 900 | if ($param['active'] && !$this->frontend->is_active($account)) |
910 | 901 | { |
911 | 902 | continue; |
912 | 903 | } |
913 | - $account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$account['account_id']); |
|
904 | + $account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $account['account_id']); |
|
914 | 905 | $accounts[$account_id] = $account; |
915 | 906 | } |
916 | 907 | } |
@@ -919,9 +910,9 @@ discard block |
||
919 | 910 | $query = Api\Ldap::quote(strtolower($param['query'])); |
920 | 911 | |
921 | 912 | $filter = null; |
922 | - if(!empty($query) && $query != '*') |
|
913 | + if (!empty($query) && $query != '*') |
|
923 | 914 | { |
924 | - switch($param['query_type']) |
|
915 | + switch ($param['query_type']) |
|
925 | 916 | { |
926 | 917 | case 'all': |
927 | 918 | default: |
@@ -935,23 +926,23 @@ discard block |
||
935 | 926 | } |
936 | 927 | $filter = "(|(cn=$query)(description=$query))"; |
937 | 928 | } |
938 | - foreach($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data) |
|
929 | + foreach ($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data) |
|
939 | 930 | { |
940 | 931 | $accounts[$account_id] = $this->_ldap2group($data); |
941 | 932 | } |
942 | 933 | } |
943 | 934 | // sort the array |
944 | 935 | $this->_callback_sort = strtoupper($param['sort']); |
945 | - $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
|
936 | + $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']); |
|
946 | 937 | $sortedAccounts = $accounts; |
947 | - uasort($sortedAccounts,array($this,'_sort_callback')); |
|
938 | + uasort($sortedAccounts, array($this, '_sort_callback')); |
|
948 | 939 | $account_search[$unl_serial]['data'] = $sortedAccounts; |
949 | 940 | |
950 | 941 | $account_search[$unl_serial]['total'] = $this->total = count($accounts); |
951 | 942 | } |
952 | 943 | // return only the wanted accounts |
953 | 944 | reset($sortedAccounts); |
954 | - if(is_numeric($start) && is_numeric($offset)) |
|
945 | + if (is_numeric($start) && is_numeric($offset)) |
|
955 | 946 | { |
956 | 947 | $account_search[$serial]['data'] = array_slice($sortedAccounts, $start, $offset); |
957 | 948 | $account_search[$serial]['total'] = $this->total; |
@@ -982,19 +973,19 @@ discard block |
||
982 | 973 | * @param array $b |
983 | 974 | * @return int |
984 | 975 | */ |
985 | - protected function _sort_callback($a,$b) |
|
976 | + protected function _sort_callback($a, $b) |
|
986 | 977 | { |
987 | - foreach($this->_callback_order as $col ) |
|
978 | + foreach ($this->_callback_order as $col) |
|
988 | 979 | { |
989 | - if($this->_callback_sort != 'DESC') |
|
980 | + if ($this->_callback_sort != 'DESC') |
|
990 | 981 | { |
991 | - $cmp = strcasecmp( $a[$col], $b[$col] ); |
|
982 | + $cmp = strcasecmp($a[$col], $b[$col]); |
|
992 | 983 | } |
993 | 984 | else |
994 | 985 | { |
995 | - $cmp = strcasecmp( $b[$col], $a[$col] ); |
|
986 | + $cmp = strcasecmp($b[$col], $a[$col]); |
|
996 | 987 | } |
997 | - if ( $cmp != 0 ) |
|
988 | + if ($cmp != 0) |
|
998 | 989 | { |
999 | 990 | return $cmp; |
1000 | 991 | } |
@@ -1013,9 +1004,9 @@ discard block |
||
1013 | 1004 | * @param array $accounts =array() array to add filtered accounts too, default empty array |
1014 | 1005 | * @return array account_id => account_lid or values for $attrs pairs |
1015 | 1006 | */ |
1016 | - protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array()) |
|
1007 | + protected function filter($attr_filter, $account_type = null, array $attrs = null, array $accounts = array()) |
|
1017 | 1008 | { |
1018 | - switch($account_type) |
|
1009 | + switch ($account_type) |
|
1019 | 1010 | { |
1020 | 1011 | case 'u': |
1021 | 1012 | $type_filter = '(samaccounttype='.adLDAP::ADLDAP_NORMAL_ACCOUNT.')'; |
@@ -1040,25 +1031,25 @@ discard block |
||
1040 | 1031 | } |
1041 | 1032 | else |
1042 | 1033 | { |
1043 | - foreach($attr_filter as $attr => $value) |
|
1034 | + foreach ($attr_filter as $attr => $value) |
|
1044 | 1035 | { |
1045 | 1036 | $filter .= '('.$attr.'='.$this->adldap->utilities()->ldapSlashes($value).')'; |
1046 | 1037 | } |
1047 | 1038 | } |
1048 | 1039 | $filter .= $type_filter.')'; |
1049 | 1040 | } |
1050 | - $sri = ldap_search($ds=$this->ldap_connection(), $context=$this->ads_context(), $filter, |
|
1041 | + $sri = ldap_search($ds = $this->ldap_connection(), $context = $this->ads_context(), $filter, |
|
1051 | 1042 | $attrs ? $attrs : self::$default_attributes); |
1052 | 1043 | if (!$sri) |
1053 | 1044 | { |
1054 | 1045 | if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...'); |
1055 | - $sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter, |
|
1046 | + $sri = ldap_search($ds = $this->ldap_connection(true), $context = $this->ads_context(), $filter, |
|
1056 | 1047 | $attrs ? $attrs : self::$default_attributes); |
1057 | 1048 | } |
1058 | 1049 | |
1059 | 1050 | if ($sri && ($allValues = ldap_get_entries($ds, $sri))) |
1060 | 1051 | { |
1061 | - foreach($allValues as $key => $data) |
|
1052 | + foreach ($allValues as $key => $data) |
|
1062 | 1053 | { |
1063 | 1054 | if ($key === 'count') continue; |
1064 | 1055 | |
@@ -1072,7 +1063,7 @@ discard block |
||
1072 | 1063 | |
1073 | 1064 | if ($data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT && $rid < self::MIN_ACCOUNT_ID) |
1074 | 1065 | { |
1075 | - continue; // ignore system accounts incl. "Administrator" |
|
1066 | + continue; // ignore system accounts incl. "Administrator" |
|
1076 | 1067 | } |
1077 | 1068 | $accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] = |
1078 | 1069 | $attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8'); |
@@ -1096,7 +1087,7 @@ discard block |
||
1096 | 1087 | * @param string $account_type u = user, g = group, default null = try both |
1097 | 1088 | * @return int|false numeric account_id or false on error ($name not found) |
1098 | 1089 | */ |
1099 | - public function name2id($name, $which='account_lid', $account_type=null) |
|
1090 | + public function name2id($name, $which = 'account_lid', $account_type = null) |
|
1100 | 1091 | { |
1101 | 1092 | static $to_ldap = array( |
1102 | 1093 | 'account_lid' => 'samaccountname', |
@@ -1108,7 +1099,7 @@ discard block |
||
1108 | 1099 | $ret = false; |
1109 | 1100 | if (isset($to_ldap[$which])) |
1110 | 1101 | { |
1111 | - foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid) |
|
1102 | + foreach ($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid) |
|
1112 | 1103 | { |
1113 | 1104 | unset($account_lid); |
1114 | 1105 | $ret = $account_id; |
@@ -1128,9 +1119,9 @@ discard block |
||
1128 | 1119 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
1129 | 1120 | * @return string/false converted value or false on error ($account_id not found) |
1130 | 1121 | */ |
1131 | - public function id2name($account_id, $which='account_lid') |
|
1122 | + public function id2name($account_id, $which = 'account_lid') |
|
1132 | 1123 | { |
1133 | - return $this->frontend->id2name($account_id,$which); |
|
1124 | + return $this->frontend->id2name($account_id, $which); |
|
1134 | 1125 | } |
1135 | 1126 | |
1136 | 1127 | /** |
@@ -1142,9 +1133,9 @@ discard block |
||
1142 | 1133 | */ |
1143 | 1134 | function update_lastlogin($_account_id, $ip) |
1144 | 1135 | { |
1145 | - unset($_account_id, $ip); // not used, but required by function signature |
|
1136 | + unset($_account_id, $ip); // not used, but required by function signature |
|
1146 | 1137 | |
1147 | - return false; // not longer supported |
|
1138 | + return false; // not longer supported |
|
1148 | 1139 | } |
1149 | 1140 | |
1150 | 1141 | /** |
@@ -1184,21 +1175,21 @@ discard block |
||
1184 | 1175 | * @param int $account_id uidnumber |
1185 | 1176 | * @return int number of added or removed memberships |
1186 | 1177 | */ |
1187 | - function set_memberships($groups,$account_id) |
|
1178 | + function set_memberships($groups, $account_id) |
|
1188 | 1179 | { |
1189 | 1180 | if (!($account = $this->id2name($account_id))) return; |
1190 | 1181 | $current = array_keys($this->memberships($account_id)); |
1191 | 1182 | |
1192 | 1183 | $changed = 0; |
1193 | - foreach(array( |
|
1194 | - 'add' => array_diff($groups, $current), // add account to all groups he is currently not in |
|
1195 | - 'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in |
|
1184 | + foreach (array( |
|
1185 | + 'add' => array_diff($groups, $current), // add account to all groups he is currently not in |
|
1186 | + 'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in |
|
1196 | 1187 | ) as $op => $memberships) |
1197 | 1188 | { |
1198 | 1189 | $func = $op.($account_id > 0 ? 'User' : 'Group'); |
1199 | - foreach($memberships as $gid) |
|
1190 | + foreach ($memberships as $gid) |
|
1200 | 1191 | { |
1201 | - $ok = $this->adldap->group()->$func($group=$this->id2name($gid), $account); |
|
1192 | + $ok = $this->adldap->group()->$func($group = $this->id2name($gid), $account); |
|
1202 | 1193 | //error_log(__METHOD__.'('.array2string($groups).", $account_id) $func('$group', '$account') returned ".array2string($ok)); |
1203 | 1194 | $changed += (int)$ok; |
1204 | 1195 | } |
@@ -1220,15 +1211,15 @@ discard block |
||
1220 | 1211 | $current = array_keys($this->members($gid)); |
1221 | 1212 | |
1222 | 1213 | $changed = 0; |
1223 | - foreach(array( |
|
1224 | - 'add' => array_diff($users, $current), // add members currently not in |
|
1225 | - 'remove' => array_diff($current, $users), // remove members only currently in |
|
1214 | + foreach (array( |
|
1215 | + 'add' => array_diff($users, $current), // add members currently not in |
|
1216 | + 'remove' => array_diff($current, $users), // remove members only currently in |
|
1226 | 1217 | ) as $op => $members) |
1227 | 1218 | { |
1228 | - foreach($members as $account_id) |
|
1219 | + foreach ($members as $account_id) |
|
1229 | 1220 | { |
1230 | 1221 | $func = $op.($account_id > 0 ? 'User' : 'Group'); |
1231 | - $ok = $this->adldap->group()->$func($group, $account=$this->id2name($account_id)); |
|
1222 | + $ok = $this->adldap->group()->$func($group, $account = $this->id2name($account_id)); |
|
1232 | 1223 | //error_log(__METHOD__.'('.array2string($users).", $account_id) $func('$group', '$account') returned ".array2string($ok)); |
1233 | 1224 | $changed += (int)$ok; |
1234 | 1225 | } |
@@ -1253,7 +1244,7 @@ discard block |
||
1253 | 1244 | */ |
1254 | 1245 | public $charset = 'iso-8859-1'; |
1255 | 1246 | |
1256 | - function __construct(array $options=array()) |
|
1247 | + function __construct(array $options = array()) |
|
1257 | 1248 | { |
1258 | 1249 | if (isset($options['charset'])) |
1259 | 1250 | { |
@@ -1340,19 +1331,19 @@ discard block |
||
1340 | 1331 | public function create($attributes) |
1341 | 1332 | { |
1342 | 1333 | // Check for compulsory fields |
1343 | - if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; } |
|
1344 | - if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; } |
|
1345 | - if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; } |
|
1346 | - if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; } |
|
1347 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
1348 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
1349 | - |
|
1350 | - if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){ |
|
1334 | + if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; } |
|
1335 | + if (!array_key_exists("firstname", $attributes)) { return "Missing compulsory field [firstname]"; } |
|
1336 | + if (!array_key_exists("surname", $attributes)) { return "Missing compulsory field [surname]"; } |
|
1337 | + if (!array_key_exists("email", $attributes)) { return "Missing compulsory field [email]"; } |
|
1338 | + if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
|
1339 | + if (empty($attributes["container"])) { return "Container attribute must be an array or string."; } |
|
1340 | + |
|
1341 | + if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) { |
|
1351 | 1342 | throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
1352 | 1343 | } |
1353 | 1344 | |
1354 | 1345 | if (!array_key_exists("display_name", $attributes)) { |
1355 | - $attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"]; |
|
1346 | + $attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"]; |
|
1356 | 1347 | } |
1357 | 1348 | |
1358 | 1349 | // Translate the schema |
@@ -1375,20 +1366,20 @@ discard block |
||
1375 | 1366 | // Determine the container |
1376 | 1367 | if (is_array($attributes['container'])) { |
1377 | 1368 | $attributes["container"] = array_reverse($attributes["container"]); |
1378 | - $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
|
1369 | + $attributes["container"] = "OU=".implode(",OU=", $attributes["container"]); |
|
1379 | 1370 | } |
1380 | 1371 | // we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2 |
1381 | 1372 | unset($add['unicodePwd']); |
1382 | 1373 | |
1383 | 1374 | // Add the entry |
1384 | - $result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
|
1375 | + $result = ldap_add($ds = $this->adldap->getLdapConnection(), $dn = "CN=".$add["cn"][0].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add); |
|
1385 | 1376 | if ($result != true) { |
1386 | 1377 | error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
1387 | 1378 | return false; |
1388 | 1379 | } |
1389 | 1380 | |
1390 | 1381 | // now password can be added to still disabled account |
1391 | - if (array_key_exists("password",$attributes)) |
|
1382 | + if (array_key_exists("password", $attributes)) |
|
1392 | 1383 | { |
1393 | 1384 | if (!$this->setPassword($dn, $attributes['password'])) return false; |
1394 | 1385 | |
@@ -1415,13 +1406,13 @@ discard block |
||
1415 | 1406 | */ |
1416 | 1407 | public function encodePassword($password) |
1417 | 1408 | { |
1418 | - $password="\"".$password."\""; |
|
1409 | + $password = "\"".$password."\""; |
|
1419 | 1410 | if (function_exists('mb_convert_encoding')) |
1420 | 1411 | { |
1421 | 1412 | return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
1422 | 1413 | } |
1423 | - $encoded=""; |
|
1424 | - for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
1414 | + $encoded = ""; |
|
1415 | + for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; } |
|
1425 | 1416 | return $encoded; |
1426 | 1417 | } |
1427 | 1418 | |
@@ -1438,7 +1429,7 @@ discard block |
||
1438 | 1429 | */ |
1439 | 1430 | public function setPassword($dn, $password) |
1440 | 1431 | { |
1441 | - $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
|
1432 | + $result = ldap_mod_replace($ds = $this->adldap->getLdapConnection(), $dn, array( |
|
1442 | 1433 | 'unicodePwd' => $this->encodePassword($password), |
1443 | 1434 | )); |
1444 | 1435 | if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
@@ -1466,7 +1457,7 @@ discard block |
||
1466 | 1457 | * @param string $old_password old password for password change, if supported |
1467 | 1458 | * @return bool |
1468 | 1459 | */ |
1469 | - public function password($username, $password, $isGUID = false, $old_password=null) |
|
1460 | + public function password($username, $password, $isGUID = false, $old_password = null) |
|
1470 | 1461 | { |
1471 | 1462 | if ($username === NULL) { return false; } |
1472 | 1463 | if ($password === NULL) { return false; } |
@@ -1480,7 +1471,7 @@ discard block |
||
1480 | 1471 | return false; |
1481 | 1472 | } |
1482 | 1473 | |
1483 | - $add=array(); |
|
1474 | + $add = array(); |
|
1484 | 1475 | |
1485 | 1476 | if (empty($old_password) || !function_exists('ldap_modify_batch')) { |
1486 | 1477 | $add["unicodePwd"][0] = $this->encodePassword($password); |
@@ -1502,11 +1493,11 @@ discard block |
||
1502 | 1493 | ); |
1503 | 1494 | $result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods); |
1504 | 1495 | } |
1505 | - if ($result === false){ |
|
1496 | + if ($result === false) { |
|
1506 | 1497 | $err = ldap_errno($this->adldap->getLdapConnection()); |
1507 | 1498 | if ($err) { |
1508 | - $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
1509 | - if($err == 53) { |
|
1499 | + $msg = 'Error '.$err.': '.ldap_err2str($err).'.'; |
|
1500 | + if ($err == 53) { |
|
1510 | 1501 | $msg .= ' Your password might not match the password policy.'; |
1511 | 1502 | } |
1512 | 1503 | throw new adLDAPException($msg); |
@@ -1544,13 +1535,13 @@ discard block |
||
1544 | 1535 | $mod = $this->adldap->adldap_schema($attributes); |
1545 | 1536 | |
1546 | 1537 | // Check to see if this is an enabled status update |
1547 | - if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
1538 | + if (!$mod && !array_key_exists("enabled", $attributes)) { |
|
1548 | 1539 | return false; |
1549 | 1540 | } |
1550 | 1541 | |
1551 | 1542 | // Set the account control attribute (only if specified) |
1552 | - if (array_key_exists("enabled", $attributes)){ |
|
1553 | - if ($attributes["enabled"]){ |
|
1543 | + if (array_key_exists("enabled", $attributes)) { |
|
1544 | + if ($attributes["enabled"]) { |
|
1554 | 1545 | $controlOptions = array("NORMAL_ACCOUNT"); |
1555 | 1546 | } |
1556 | 1547 | else { |
@@ -1564,14 +1555,14 @@ discard block |
||
1564 | 1555 | if ($mod) |
1565 | 1556 | { |
1566 | 1557 | // Do the update |
1567 | - $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
|
1558 | + $result = @ldap_modify($ds = $this->adldap->getLdapConnection(), $userDn, $mod); |
|
1568 | 1559 | if ($result == false) { |
1569 | 1560 | if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***'; |
1570 | 1561 | error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
1571 | 1562 | return false; |
1572 | 1563 | } |
1573 | 1564 | } |
1574 | - if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
1565 | + if (array_key_exists("password", $attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
1575 | 1566 | { |
1576 | 1567 | return false; |
1577 | 1568 | } |
@@ -1594,10 +1585,10 @@ discard block |
||
1594 | 1585 | */ |
1595 | 1586 | public function create($attributes) |
1596 | 1587 | { |
1597 | - if (!is_array($attributes)){ return "Attributes must be an array"; } |
|
1598 | - if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; } |
|
1599 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
1600 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
1588 | + if (!is_array($attributes)) { return "Attributes must be an array"; } |
|
1589 | + if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; } |
|
1590 | + if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
|
1591 | + if (empty($attributes["container"])) { return "Container attribute must be an array or string."; } |
|
1601 | 1592 | |
1602 | 1593 | //$member_array = array(); |
1603 | 1594 | //$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com"; |
@@ -1613,9 +1604,9 @@ discard block |
||
1613 | 1604 | // Determine the container |
1614 | 1605 | if (is_array($attributes['container'])) { |
1615 | 1606 | $attributes["container"] = array_reverse($attributes["container"]); |
1616 | - $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
|
1607 | + $attributes["container"] = "OU=".implode(",OU=", $attributes["container"]); |
|
1617 | 1608 | } |
1618 | - $result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
|
1609 | + $result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add); |
|
1619 | 1610 | if ($result != true) { |
1620 | 1611 | return false; |
1621 | 1612 | } |
@@ -1646,10 +1637,10 @@ discard block |
||
1646 | 1637 | * @author Port by Andreas Gohr <[email protected]> |
1647 | 1638 | * @return string |
1648 | 1639 | */ |
1649 | - public function ldapSlashes($str){ |
|
1640 | + public function ldapSlashes($str) { |
|
1650 | 1641 | return preg_replace_callback( |
1651 | 1642 | '/([\x00-\x1F\*\(\)\\\\])/', |
1652 | - function ($matches) { |
|
1643 | + function($matches) { |
|
1653 | 1644 | return "\\".join("", unpack("H2", $matches[1])); |
1654 | 1645 | }, |
1655 | 1646 | $str |
@@ -198,38 +198,38 @@ discard block |
||
198 | 198 | if ($data['account_passwd']) |
199 | 199 | { |
200 | 200 | // if password it's not already entcrypted, do so now |
201 | - if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']) && |
|
202 | - !preg_match('/^[0-9a-f]{32}$/',$data['account_passwd'])) // md5 hash |
|
201 | + if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd']) && |
|
202 | + !preg_match('/^[0-9a-f]{32}$/', $data['account_passwd'])) // md5 hash |
|
203 | 203 | { |
204 | 204 | $data['account_passwd'] = Api\Auth::encrypt_sql($data['account_passwd']); |
205 | 205 | } |
206 | 206 | $to_write['account_pwd'] = $data['account_passwd']; |
207 | 207 | $to_write['account_lastpwd_change'] = time(); |
208 | 208 | } |
209 | - if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change']=0; |
|
209 | + if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change'] = 0; |
|
210 | 210 | if (!(int)$data['account_id'] || !$this->id2name($data['account_id'])) |
211 | 211 | { |
212 | 212 | if ($to_write['account_id'] < 0) $to_write['account_id'] *= -1; |
213 | 213 | |
214 | - if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = ''; // is NOT NULL! |
|
215 | - if (!isset($to_write['account_status'])) $to_write['account_status'] = ''; // is NOT NULL! |
|
214 | + if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = ''; // is NOT NULL! |
|
215 | + if (!isset($to_write['account_status'])) $to_write['account_status'] = ''; // is NOT NULL! |
|
216 | 216 | |
217 | 217 | // postgres requires the auto-id field to be unset! |
218 | 218 | if (isset($to_write['account_id']) && !$to_write['account_id']) unset($to_write['account_id']); |
219 | 219 | |
220 | - if (!in_array($to_write['account_type'],array('u','g')) || |
|
221 | - !$this->db->insert($this->table,$to_write,false,__LINE__,__FILE__)) return false; |
|
220 | + if (!in_array($to_write['account_type'], array('u', 'g')) || |
|
221 | + !$this->db->insert($this->table, $to_write, false, __LINE__, __FILE__)) return false; |
|
222 | 222 | |
223 | 223 | if (!(int)$data['account_id']) |
224 | 224 | { |
225 | - $data['account_id'] = $this->db->get_last_insert_id($this->table,'account_id'); |
|
225 | + $data['account_id'] = $this->db->get_last_insert_id($this->table, 'account_id'); |
|
226 | 226 | if ($data['account_type'] == 'g') $data['account_id'] *= -1; |
227 | 227 | } |
228 | 228 | } |
229 | 229 | else // update of existing account |
230 | 230 | { |
231 | 231 | unset($to_write['account_id']); |
232 | - if (!$this->db->update($this->table,$to_write,array('account_id' => abs($data['account_id'])),__LINE__,__FILE__)) |
|
232 | + if (!$this->db->update($this->table, $to_write, array('account_id' => abs($data['account_id'])), __LINE__, __FILE__)) |
|
233 | 233 | { |
234 | 234 | return false; |
235 | 235 | } |
@@ -278,16 +278,16 @@ discard block |
||
278 | 278 | { |
279 | 279 | if (!(int)$account_id) return false; |
280 | 280 | |
281 | - $contact_id = $this->id2name($account_id,'person_id'); |
|
281 | + $contact_id = $this->id2name($account_id, 'person_id'); |
|
282 | 282 | |
283 | - if (!$this->db->delete($this->table,array('account_id' => abs($account_id)),__LINE__,__FILE__)) |
|
283 | + if (!$this->db->delete($this->table, array('account_id' => abs($account_id)), __LINE__, __FILE__)) |
|
284 | 284 | { |
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | if ($contact_id) |
288 | 288 | { |
289 | 289 | if (!isset($this->contacts)) $this->contacts = new Api\Contacts(); |
290 | - $this->contacts->delete($contact_id,false); // false = allow to delete accounts (!) |
|
290 | + $this->contacts->delete($contact_id, false); // false = allow to delete accounts (!) |
|
291 | 291 | } |
292 | 292 | return true; |
293 | 293 | } |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | if (!(int)$account_id) return false; |
304 | 304 | |
305 | 305 | $memberships = array(); |
306 | - if(($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id))) |
|
306 | + if (($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id))) |
|
307 | 307 | { |
308 | - foreach($gids as $gid) |
|
308 | + foreach ($gids as $gid) |
|
309 | 309 | { |
310 | - $memberships[(string) $gid] = $this->id2name($gid); |
|
310 | + $memberships[(string)$gid] = $this->id2name($gid); |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 | return $memberships; |
@@ -319,17 +319,17 @@ discard block |
||
319 | 319 | * @param array $groups array with gidnumbers |
320 | 320 | * @param int $account_id numerical account-id |
321 | 321 | */ |
322 | - function set_memberships($groups,$account_id) |
|
322 | + function set_memberships($groups, $account_id) |
|
323 | 323 | { |
324 | 324 | if (!(int)$account_id) return; |
325 | 325 | |
326 | 326 | $acl = new Api\Acl($account_id); |
327 | 327 | $acl->read_repository(); |
328 | - $acl->delete('phpgw_group',false); |
|
328 | + $acl->delete('phpgw_group', false); |
|
329 | 329 | |
330 | - foreach($groups as $group) |
|
330 | + foreach ($groups as $group) |
|
331 | 331 | { |
332 | - $acl->add('phpgw_group',$group,1); |
|
332 | + $acl->add('phpgw_group', $group, 1); |
|
333 | 333 | } |
334 | 334 | $acl->save_repository(); |
335 | 335 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | if (!is_numeric($account_id)) $account_id = $this->name2id($account_id); |
346 | 346 | |
347 | 347 | $members = array(); |
348 | - foreach($this->db->select($this->table, 'account_id,account_lid', |
|
348 | + foreach ($this->db->select($this->table, 'account_id,account_lid', |
|
349 | 349 | $this->db->expression(Api\Acl::TABLE, array( |
350 | 350 | 'acl_appname' => 'phpgw_group', |
351 | 351 | 'acl_location' => $account_id, |
@@ -364,15 +364,15 @@ discard block |
||
364 | 364 | * @param array $members array with uidnumber or uid's |
365 | 365 | * @param int $gid gidnumber of group to set |
366 | 366 | */ |
367 | - function set_members($members,$gid) |
|
367 | + function set_members($members, $gid) |
|
368 | 368 | { |
369 | - $GLOBALS['egw']->acl->delete_repository('phpgw_group',$gid,false); |
|
369 | + $GLOBALS['egw']->acl->delete_repository('phpgw_group', $gid, false); |
|
370 | 370 | |
371 | 371 | if (is_array($members)) |
372 | 372 | { |
373 | - foreach($members as $id) |
|
373 | + foreach ($members as $id) |
|
374 | 374 | { |
375 | - $GLOBALS['egw']->acl->add_repository('phpgw_group',$gid,$id,1); |
|
375 | + $GLOBALS['egw']->acl->add_repository('phpgw_group', $gid, $id, 1); |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | } |
@@ -407,20 +407,20 @@ discard block |
||
407 | 407 | ); |
408 | 408 | |
409 | 409 | // fetch order of account_fullname from Api\Accounts::format_username |
410 | - if (strpos($param['order'],'account_fullname') !== false) |
|
410 | + if (strpos($param['order'], 'account_fullname') !== false) |
|
411 | 411 | { |
412 | - $param['order'] = str_replace('account_fullname', preg_replace('/[ ,]+/',',',str_replace(array('[',']'),'', |
|
413 | - Api\Accounts::format_username('account_lid','account_firstname','account_lastname'))), $param['order']); |
|
412 | + $param['order'] = str_replace('account_fullname', preg_replace('/[ ,]+/', ',', str_replace(array('[', ']'), '', |
|
413 | + Api\Accounts::format_username('account_lid', 'account_firstname', 'account_lastname'))), $param['order']); |
|
414 | 414 | } |
415 | - $order = str_replace(array_keys($order2contact),array_values($order2contact),$param['order']); |
|
415 | + $order = str_replace(array_keys($order2contact), array_values($order2contact), $param['order']); |
|
416 | 416 | // allways add 'account_lid', as it is only valid one for groups |
417 | 417 | if (strpos($order, 'account_lid') === false) |
418 | 418 | { |
419 | - $order .= ($order?',':'').'account_lid'; |
|
419 | + $order .= ($order ? ',' : '').'account_lid'; |
|
420 | 420 | } |
421 | 421 | if ($param['sort']) $order = implode(' '.$param['sort'].',', explode(',', $order)).' '.$param['sort']; |
422 | 422 | |
423 | - $search_cols = array('account_lid','n_family','n_given','email'); |
|
423 | + $search_cols = array('account_lid', 'n_family', 'n_given', 'email'); |
|
424 | 424 | $join = $this->contacts_join; |
425 | 425 | $email_cols = array('email'); |
426 | 426 | |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | } |
437 | 437 | |
438 | 438 | $filter = array(); |
439 | - switch($param['type']) |
|
439 | + switch ($param['type']) |
|
440 | 440 | { |
441 | 441 | case 'accounts': |
442 | 442 | $filter['owner'] = 0; |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | case 'groupmembers': |
452 | 452 | case 'groupmembers+memberships': |
453 | 453 | $members = array(); |
454 | - foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp => $name) |
|
454 | + foreach ((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp => $name) |
|
455 | 455 | { |
456 | 456 | unset($name); |
457 | 457 | $members = array_unique(array_merge($members, array_keys((array)$this->members($grp)))); |
@@ -486,13 +486,13 @@ discard block |
||
486 | 486 | } |
487 | 487 | if ($param['active']) |
488 | 488 | { |
489 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),Api\Contacts\Sql::ACOUNT_ACTIVE_FILTER); |
|
489 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), Api\Contacts\Sql::ACOUNT_ACTIVE_FILTER); |
|
490 | 490 | } |
491 | 491 | $criteria = array(); |
492 | 492 | $wildcard = $param['query_type'] == 'start' || $param['query_type'] == 'exact' ? '' : '%'; |
493 | 493 | if (($query = $param['query'])) |
494 | 494 | { |
495 | - switch($param['query_type']) |
|
495 | + switch ($param['query_type']) |
|
496 | 496 | { |
497 | 497 | case 'start': |
498 | 498 | $query .= '*'; |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | case 'all': |
501 | 501 | default: |
502 | 502 | case 'exact': |
503 | - foreach($search_cols as $col) |
|
503 | + foreach ($search_cols as $col) |
|
504 | 504 | { |
505 | 505 | $criteria[$col] = $query; |
506 | 506 | } |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | case 'email': |
522 | 522 | $criteria['email'] = $query; |
523 | 523 | // Group email |
524 | - if(in_array(Api\Mail\Smtp\Sql::TABLE, $this->db->table_names(true))) |
|
524 | + if (in_array(Api\Mail\Smtp\Sql::TABLE, $this->db->table_names(true))) |
|
525 | 525 | { |
526 | 526 | $criteria[Api\Mail\Smtp\Sql::TABLE.'.mail_value'] = $query; |
527 | 527 | } |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | if (!isset($this->contacts)) $this->contacts = new Api\Contacts(); |
532 | 532 | |
533 | 533 | $accounts = array(); |
534 | - foreach((array) $this->contacts->search($criteria, |
|
535 | - array_merge(array(1,'n_given','n_family','id','created','modified',$this->table.'.account_id AS account_id'),$email_cols), |
|
536 | - $order,"account_lid,account_type,account_status,account_expires,account_primary_group,account_description", |
|
537 | - $wildcard,false,$query[0] == '!' ? 'AND' : 'OR', |
|
534 | + foreach ((array)$this->contacts->search($criteria, |
|
535 | + array_merge(array(1, 'n_given', 'n_family', 'id', 'created', 'modified', $this->table.'.account_id AS account_id'), $email_cols), |
|
536 | + $order, "account_lid,account_type,account_status,account_expires,account_primary_group,account_description", |
|
537 | + $wildcard, false, $query[0] == '!' ? 'AND' : 'OR', |
|
538 | 538 | $param['offset'] ? array($param['start'], $param['offset']) : (is_null($param['start']) ? false : $param['start']), |
539 | - $filter,$join) as $contact) |
|
539 | + $filter, $join) as $contact) |
|
540 | 540 | { |
541 | 541 | if ($contact) |
542 | 542 | { |
@@ -576,13 +576,13 @@ discard block |
||
576 | 576 | * @param string $account_type u = user, g = group, default null = try both |
577 | 577 | * @return int/false numeric account_id or false on error ($name not found) |
578 | 578 | */ |
579 | - function name2id($name,$which='account_lid',$account_type=null) |
|
579 | + function name2id($name, $which = 'account_lid', $account_type = null) |
|
580 | 580 | { |
581 | 581 | if ($account_type === 'g' && $which != 'account_lid') return false; |
582 | 582 | |
583 | 583 | $where = array(); |
584 | 584 | $cols = 'account_id'; |
585 | - switch($which) |
|
585 | + switch ($which) |
|
586 | 586 | { |
587 | 587 | case 'account_fullname': |
588 | 588 | $table = $this->contacts_table; |
@@ -613,11 +613,11 @@ discard block |
||
613 | 613 | } |
614 | 614 | else |
615 | 615 | { |
616 | - $where[] = 'account_id IS NOT NULL'. // otherwise contacts with eg. the same email hide the accounts! |
|
617 | - ($table == $this->contacts_table ? " AND contact_tid != 'D'" : ''); // ignore deleted accounts contact-data |
|
616 | + $where[] = 'account_id IS NOT NULL'.// otherwise contacts with eg. the same email hide the accounts! |
|
617 | + ($table == $this->contacts_table ? " AND contact_tid != 'D'" : ''); // ignore deleted accounts contact-data |
|
618 | 618 | |
619 | 619 | } |
620 | - if (!($rs = $this->db->select($table,$cols,$where,__LINE__,__FILE__)) || !($row = $rs->fetch())) |
|
620 | + if (!($rs = $this->db->select($table, $cols, $where, __LINE__, __FILE__)) || !($row = $rs->fetch())) |
|
621 | 621 | { |
622 | 622 | //error_log(__METHOD__."('$name', '$which', ".array2string($account_type).") db->select('$table', '$cols', ".array2string($where).") returned ".array2string($rs).' '.function_backtrace()); |
623 | 623 | return false; |
@@ -634,9 +634,9 @@ discard block |
||
634 | 634 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
635 | 635 | * @return string/false converted value or false on error ($account_id not found) |
636 | 636 | */ |
637 | - function id2name($account_id,$which='account_lid') |
|
637 | + function id2name($account_id, $which = 'account_lid') |
|
638 | 638 | { |
639 | - return $this->frontend->id2name($account_id,$which); |
|
639 | + return $this->frontend->id2name($account_id, $which); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
@@ -648,14 +648,14 @@ discard block |
||
648 | 648 | */ |
649 | 649 | function update_lastlogin($account_id, $ip) |
650 | 650 | { |
651 | - $previous_login = $this->db->select($this->table,'account_lastlogin',array('account_id'=>abs($account_id)),__LINE__,__FILE__)->fetchColumn(); |
|
651 | + $previous_login = $this->db->select($this->table, 'account_lastlogin', array('account_id'=>abs($account_id)), __LINE__, __FILE__)->fetchColumn(); |
|
652 | 652 | |
653 | - $this->db->update($this->table,array( |
|
653 | + $this->db->update($this->table, array( |
|
654 | 654 | 'account_lastloginfrom' => $ip, |
655 | 655 | 'account_lastlogin' => time(), |
656 | - ),array( |
|
656 | + ), array( |
|
657 | 657 | 'account_id' => abs($account_id), |
658 | - ),__LINE__,__FILE__); |
|
658 | + ), __LINE__, __FILE__); |
|
659 | 659 | |
660 | 660 | return $previous_login; |
661 | 661 | } |
@@ -54,26 +54,26 @@ discard block |
||
54 | 54 | * @throws Exception if connection to backend could not be established |
55 | 55 | * @param array $params eg. array('localhost'[,'localhost:11211',...]) |
56 | 56 | */ |
57 | - function __construct(array $params=null) |
|
57 | + function __construct(array $params = null) |
|
58 | 58 | { |
59 | - check_load_extension('memcache',true); |
|
59 | + check_load_extension('memcache', true); |
|
60 | 60 | $this->memcache = new \Memcache(); |
61 | 61 | |
62 | - if (!$params) $params = array('localhost'); // some reasonable default |
|
62 | + if (!$params) $params = array('localhost'); // some reasonable default |
|
63 | 63 | |
64 | 64 | $ok = false; |
65 | - foreach($params as $host_port) |
|
65 | + foreach ($params as $host_port) |
|
66 | 66 | { |
67 | - $parts = explode(':',$host_port); |
|
67 | + $parts = explode(':', $host_port); |
|
68 | 68 | $host = array_shift($parts); |
69 | - $port = $parts ? array_shift($parts) : 11211; // default port |
|
69 | + $port = $parts ? array_shift($parts) : 11211; // default port |
|
70 | 70 | |
71 | - $ok = $this->memcache->addServer($host,$port) || $ok; |
|
71 | + $ok = $this->memcache->addServer($host, $port) || $ok; |
|
72 | 72 | //error_log(__METHOD__."(".array2string($params).") memcache->addServer('$host',$port) = ".(int)$ok); |
73 | 73 | } |
74 | 74 | if (!$ok) |
75 | 75 | { |
76 | - throw new Exception (__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
76 | + throw new Exception(__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
77 | 77 | } |
78 | 78 | $this->igbinary_available = function_exists('igbinary_serialize') && function_exists('igbinary_unserialize'); |
79 | 79 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param int $expiration =0 |
87 | 87 | * @return boolean true on success, false on error, incl. key already exists in cache |
88 | 88 | */ |
89 | - function add(array $keys,$data,$expiration=0) |
|
89 | + function add(array $keys, $data, $expiration = 0) |
|
90 | 90 | { |
91 | 91 | return $this->memcache->add(self::key($keys), |
92 | 92 | $this->igbinary_available ? igbinary_serialize($data) : serialize($data), |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param int $expiration =0 |
102 | 102 | * @return boolean true on success, false on error |
103 | 103 | */ |
104 | - function set(array $keys,$data,$expiration=0) |
|
104 | + function set(array $keys, $data, $expiration = 0) |
|
105 | 105 | { |
106 | 106 | return $this->memcache->set(self::key($keys), |
107 | 107 | $this->igbinary_available ? igbinary_serialize($data) : serialize($data), |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | function get(array $keys) |
118 | 118 | { |
119 | - if (($data = $this->memcache->get($key=self::key($keys))) === false) |
|
119 | + if (($data = $this->memcache->get($key = self::key($keys))) === false) |
|
120 | 120 | { |
121 | 121 | //error_log(__METHOD__."(".array2string($keys).") key='$key' NOT found!"); |
122 | 122 | return null; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | { |
136 | 136 | $locations = array_pop($keys); |
137 | 137 | $prefix = self::key($keys); |
138 | - foreach($locations as &$location) |
|
138 | + foreach ($locations as &$location) |
|
139 | 139 | { |
140 | 140 | $location = $prefix.'::'.$location; |
141 | 141 | } |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | return array(); |
145 | 145 | } |
146 | 146 | $ret = array(); |
147 | - $prefix_len = strlen($prefix)+2; |
|
148 | - foreach($multiple as $location => $data) |
|
147 | + $prefix_len = strlen($prefix) + 2; |
|
148 | + foreach ($multiple as $location => $data) |
|
149 | 149 | { |
150 | - $key = substr($location,$prefix_len); |
|
150 | + $key = substr($location, $prefix_len); |
|
151 | 151 | //error_log(__METHOD__."(".array2string($locations).") key='$key' found ".bytes($data)." bytes)."); |
152 | 152 | $ret[$key] = $this->igbinary_available && $data[1] !== ':' ? igbinary_unserialize($data) : unserialize($data); |
153 | 153 | } |
@@ -175,6 +175,6 @@ discard block |
||
175 | 175 | */ |
176 | 176 | private function key(array $keys) |
177 | 177 | { |
178 | - return implode('::',$keys); |
|
178 | + return implode('::', $keys); |
|
179 | 179 | } |
180 | 180 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param boolean $verbose =false true: echo failed checks |
29 | 29 | * @return int number of failed checks |
30 | 30 | */ |
31 | - function check($verbose=false) |
|
31 | + function check($verbose = false) |
|
32 | 32 | { |
33 | 33 | // set us up as provider for Api\Cache class |
34 | 34 | $GLOBALS['egw_info']['server']['install_id'] = md5(microtime(true)); |
@@ -37,27 +37,27 @@ discard block |
||
37 | 37 | Api\Cache::$default_provider = get_class($this); |
38 | 38 | |
39 | 39 | $failed = 0; |
40 | - foreach(array( |
|
40 | + foreach (array( |
|
41 | 41 | Api\Cache::TREE => 'tree', |
42 | 42 | Api\Cache::INSTANCE => 'instance', |
43 | 43 | ) as $level => $label) |
44 | 44 | { |
45 | 45 | $locations = array(); |
46 | - foreach(array('string',123,true,false,null,array(),array(1,2,3)) as $data) |
|
46 | + foreach (array('string', 123, true, false, null, array(), array(1, 2, 3)) as $data) |
|
47 | 47 | { |
48 | 48 | $location = md5(microtime(true).$label.serialize($data)); |
49 | - $get_before_set = $this->get(array($level,__CLASS__,$location)); |
|
49 | + $get_before_set = $this->get(array($level, __CLASS__, $location)); |
|
50 | 50 | if (!is_null($get_before_set)) |
51 | 51 | { |
52 | 52 | if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
53 | 53 | ++$failed; |
54 | 54 | } |
55 | - if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
|
55 | + if (($set = $this->set(array($level, __CLASS__, $location), $data, 10)) !== true) |
|
56 | 56 | { |
57 | 57 | if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
58 | 58 | ++$failed; |
59 | 59 | } |
60 | - $get_after_set = $this->get(array($level,__CLASS__,$location)); |
|
60 | + $get_after_set = $this->get(array($level, __CLASS__, $location)); |
|
61 | 61 | if ($get_after_set !== $data) |
62 | 62 | { |
63 | 63 | if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | } |
66 | 66 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
67 | 67 | { |
68 | - $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
|
68 | + $mget_after_set = $this->mget(array($level, __CLASS__, array($location))); |
|
69 | 69 | if ($mget_after_set[$location] !== $data) |
70 | 70 | { |
71 | 71 | if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
72 | 72 | ++$failed; |
73 | 73 | } |
74 | 74 | } |
75 | - $add_after_set = $this->add(array($level,__CLASS__,$location), 'other-data'); |
|
75 | + $add_after_set = $this->add(array($level, __CLASS__, $location), 'other-data'); |
|
76 | 76 | if ($add_after_set !== false) |
77 | 77 | { |
78 | 78 | if ($verbose) echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
79 | 79 | ++$failed; |
80 | 80 | } |
81 | - if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
|
81 | + if (($delete = $this->delete(array($level, __CLASS__, $location))) !== true) |
|
82 | 82 | { |
83 | 83 | if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
84 | 84 | ++$failed; |
85 | 85 | } |
86 | - $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
|
86 | + $get_after_delete = $this->get(array($level, __CLASS__, $location)); |
|
87 | 87 | if (!is_null($get_after_delete)) |
88 | 88 | { |
89 | 89 | if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
94 | 94 | { |
95 | 95 | $locations[$location] = $data; |
96 | - $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
|
96 | + $mget_after_delete = $this->mget(array($level, __CLASS__, array($location))); |
|
97 | 97 | if (isset($mget_after_delete[$location])) |
98 | 98 | { |
99 | 99 | if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | $locations[$location] = $data; |
106 | 106 | } |
107 | - $add_after_delete = $this->add(array($level,__CLASS__,$location), $data, 10); |
|
107 | + $add_after_delete = $this->add(array($level, __CLASS__, $location), $data, 10); |
|
108 | 108 | if ($add_after_delete !== true) |
109 | 109 | { |
110 | 110 | if ($verbose) echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | else |
114 | 114 | { |
115 | - $get_after_add = $this->get(array($level,__CLASS__,$location)); |
|
115 | + $get_after_add = $this->get(array($level, __CLASS__, $location)); |
|
116 | 116 | if ($get_after_add !== $data) |
117 | 117 | { |
118 | 118 | if ($verbose) echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | } |
123 | 123 | // get all above in one request |
124 | 124 | $keys = array_keys($locations); |
125 | - $keys_bogus = array_merge(array('not-set'),array_keys($locations),array('not-set-too')); |
|
125 | + $keys_bogus = array_merge(array('not-set'), array_keys($locations), array('not-set-too')); |
|
126 | 126 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
127 | 127 | { |
128 | - $mget = $this->mget(array($level,__CLASS__,$keys)); |
|
129 | - $mget_bogus = $this->mget(array($level,__CLASS__,$keys_bogus)); |
|
128 | + $mget = $this->mget(array($level, __CLASS__, $keys)); |
|
129 | + $mget_bogus = $this->mget(array($level, __CLASS__, $keys_bogus)); |
|
130 | 130 | /* Api\Cache::getCache() gives a different result, as it does NOT use $level direkt |
131 | 131 | } |
132 | 132 | else |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | function flush(array $keys) |
162 | 162 | { |
163 | - unset($keys); // required by function signature |
|
163 | + unset($keys); // required by function signature |
|
164 | 164 | return false; |
165 | 165 | } |
166 | 166 | } |