@@ -311,6 +311,8 @@ discard block |
||
311 | 311 | * @param string $path |
312 | 312 | * @param array &$dav |
313 | 313 | * @param array &$allow |
314 | + * @param integer[] $dav |
|
315 | + * @param boolean $allow |
|
314 | 316 | */ |
315 | 317 | function OPTIONS($path, &$dav, &$allow) |
316 | 318 | { |
@@ -606,7 +608,7 @@ discard block |
||
606 | 608 | * @param string $path / or /<username>/ |
607 | 609 | * @param int $user |
608 | 610 | * @param int $depth |
609 | - * @return string|boolean http status or true|false |
|
611 | + * @return boolean http status or true|false |
|
610 | 612 | */ |
611 | 613 | protected function add_home(array &$files, $path, $user, $depth) |
612 | 614 | { |
@@ -738,7 +740,7 @@ discard block |
||
738 | 740 | * @param string $path /<username>/ |
739 | 741 | * @param int $app |
740 | 742 | * @param int $user |
741 | - * @return string|boolean http status or true|false |
|
743 | + * @return boolean http status or true|false |
|
742 | 744 | */ |
743 | 745 | protected function add_shared(array &$files, $path, $app, $user) |
744 | 746 | { |
@@ -1380,7 +1382,7 @@ discard block |
||
1380 | 1382 | * @param int|string $id |
1381 | 1383 | * @param array $attach array of array with values for keys 'name', 'params', 'value' |
1382 | 1384 | * @param boolean $delete_via_put |
1383 | - * @return boolean false on error, eg. invalid managed id, for false an xml-error body has been send |
|
1385 | + * @return null|false false on error, eg. invalid managed id, for false an xml-error body has been send |
|
1384 | 1386 | */ |
1385 | 1387 | public static function handle_attach($app, $id, $attach, $delete_via_put=false) |
1386 | 1388 | { |
@@ -1584,7 +1586,7 @@ discard block |
||
1584 | 1586 | * @param string $managed_id |
1585 | 1587 | * @param string $app =null app-name to check against path |
1586 | 1588 | * @param string|int $id =null id to check agains path |
1587 | - * @return string|boolean "/apps/$app/$id/something" or false if not found or not belonging to given $app/$id |
|
1589 | + * @return false|string "/apps/$app/$id/something" or false if not found or not belonging to given $app/$id |
|
1588 | 1590 | */ |
1589 | 1591 | static public function managed_id2path($managed_id, $app=null, $id=null) |
1590 | 1592 | { |
@@ -1783,7 +1785,7 @@ discard block |
||
1783 | 1785 | * MKCOL method handler |
1784 | 1786 | * |
1785 | 1787 | * @param array general parameter passing array |
1786 | - * @return bool true on success |
|
1788 | + * @return string true on success |
|
1787 | 1789 | */ |
1788 | 1790 | function MKCOL($options) |
1789 | 1791 | { |
@@ -1796,7 +1798,7 @@ discard block |
||
1796 | 1798 | * MOVE method handler |
1797 | 1799 | * |
1798 | 1800 | * @param array general parameter passing array |
1799 | - * @return bool true on success |
|
1801 | + * @return string true on success |
|
1800 | 1802 | */ |
1801 | 1803 | function MOVE($options) |
1802 | 1804 | { |
@@ -1809,7 +1811,7 @@ discard block |
||
1809 | 1811 | * COPY method handler |
1810 | 1812 | * |
1811 | 1813 | * @param array general parameter passing array |
1812 | - * @return bool true on success |
|
1814 | + * @return string true on success |
|
1813 | 1815 | */ |
1814 | 1816 | function COPY($options, $del=false) |
1815 | 1817 | { |
@@ -1822,7 +1824,7 @@ discard block |
||
1822 | 1824 | * LOCK method handler |
1823 | 1825 | * |
1824 | 1826 | * @param array general parameter passing array |
1825 | - * @return bool true on success |
|
1827 | + * @return string|boolean true on success |
|
1826 | 1828 | */ |
1827 | 1829 | function LOCK(&$options) |
1828 | 1830 | { |
@@ -1856,7 +1858,7 @@ discard block |
||
1856 | 1858 | * UNLOCK method handler |
1857 | 1859 | * |
1858 | 1860 | * @param array general parameter passing array |
1859 | - * @return bool true on success |
|
1861 | + * @return string true on success |
|
1860 | 1862 | */ |
1861 | 1863 | function UNLOCK(&$options) |
1862 | 1864 | { |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | 'inbox' => array( |
118 | 118 | 'resourcetype' => array(self::CALDAV => 'schedule-inbox'), |
119 | 119 | 'app' => 'calendar', |
120 | - 'user-only' => true, // display just in user home |
|
120 | + 'user-only' => true, // display just in user home |
|
121 | 121 | ), |
122 | 122 | 'outbox' => array( |
123 | 123 | 'resourcetype' => array(self::CALDAV => 'schedule-outbox'), |
124 | 124 | 'app' => 'calendar', |
125 | - 'user-only' => true, // display just in user home |
|
125 | + 'user-only' => true, // display just in user home |
|
126 | 126 | ), |
127 | 127 | 'infolog' => array( |
128 | 128 | 'resourcetype' => array(self::GROUPDAV => 'vtodo-collection', self::CALDAV => 'calendar'), |
@@ -229,14 +229,14 @@ discard block |
||
229 | 229 | if ($this->debug > 2) error_log('groupdav: $_SERVER='.array2string($_SERVER)); |
230 | 230 | |
231 | 231 | // setting our own exception handler, to be able to still log the requests |
232 | - set_exception_handler(array(__CLASS__,'exception_handler')); |
|
232 | + set_exception_handler(array(__CLASS__, 'exception_handler')); |
|
233 | 233 | |
234 | 234 | // crrnd: client refuses redundand namespace declarations |
235 | 235 | // setting redundand namespaces as the default for (Cal|Card|Group)DAV, as the majority of the clients either require or can live with it |
236 | 236 | $this->crrnd = false; |
237 | 237 | |
238 | 238 | // identify clients, which do NOT support path AND full url in <D:href> of PROPFIND request |
239 | - switch(($agent = Handler::get_agent())) |
|
239 | + switch (($agent = Handler::get_agent())) |
|
240 | 240 | { |
241 | 241 | case 'kde': // KAddressbook (at least in 3.5 can NOT subscribe / does NOT find addressbook) |
242 | 242 | $this->client_require_href_as_url = true; |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | if ($this->debug) error_log(__METHOD__."() HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]' --> '$agent' --> client_requires_href_as_url=$this->client_require_href_as_url, crrnd(client refuses redundand namespace declarations)=$this->crrnd"); |
258 | 258 | |
259 | 259 | // adding EGroupware version to X-Dav-Powered-By header eg. "EGroupware 1.8.001 CalDAV/CardDAV/GroupDAV server" |
260 | - $this->dav_powered_by = str_replace('EGroupware','EGroupware '.$GLOBALS['egw_info']['server']['versions']['phpgwapi'], |
|
260 | + $this->dav_powered_by = str_replace('EGroupware', 'EGroupware '.$GLOBALS['egw_info']['server']['versions']['phpgwapi'], |
|
261 | 261 | $this->dav_powered_by); |
262 | 262 | |
263 | 263 | parent::__construct(); |
264 | 264 | // hack to allow to use query parameters in WebDAV, which HTTP_WebDAV_Server interprets as part of the path |
265 | - list($this->_SERVER['REQUEST_URI']) = explode('?',$this->_SERVER['REQUEST_URI']); |
|
265 | + list($this->_SERVER['REQUEST_URI']) = explode('?', $this->_SERVER['REQUEST_URI']); |
|
266 | 266 | /*if (substr($this->_SERVER['REQUEST_URI'],-13) == '/;add-member/') |
267 | 267 | { |
268 | 268 | $_GET['add-member'] = ''; |
@@ -277,15 +277,15 @@ discard block |
||
277 | 277 | } |
278 | 278 | else |
279 | 279 | { |
280 | - $this->current_user_principal = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:") . |
|
281 | - '//' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '/'; |
|
280 | + $this->current_user_principal = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:"). |
|
281 | + '//'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'/'; |
|
282 | 282 | } |
283 | 283 | $this->current_user_principal .= 'principals/users/'.$GLOBALS['egw_info']['user']['account_lid'].'/'; |
284 | 284 | |
285 | 285 | // if client requires pathes instead of URLs |
286 | 286 | if (!$this->client_require_href_as_url) |
287 | 287 | { |
288 | - $this->current_user_principal = parse_url($this->current_user_principal,PHP_URL_PATH); |
|
288 | + $this->current_user_principal = parse_url($this->current_user_principal, PHP_URL_PATH); |
|
289 | 289 | } |
290 | 290 | $this->accounts = $GLOBALS['egw']->accounts; |
291 | 291 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | { |
303 | 303 | if (isset($this->root[$app]['app'])) $app = $this->root[$app]['app']; |
304 | 304 | |
305 | - return Handler::app_handler($app,$this); |
|
305 | + return Handler::app_handler($app, $this); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | function OPTIONS($path, &$dav, &$allow) |
316 | 316 | { |
317 | - unset($allow); // not used, but required by function signature |
|
317 | + unset($allow); // not used, but required by function signature |
|
318 | 318 | |
319 | 319 | // locking support |
320 | 320 | if (!in_array('2', $dav)) $dav[] = '2'; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | } |
352 | 352 | if ($app !== 'calendar') // CardDAV |
353 | 353 | { |
354 | - $dav[] = 'addressbook'; // CardDAV uses "addressbook" NOT "addressbook-access" |
|
354 | + $dav[] = 'addressbook'; // CardDAV uses "addressbook" NOT "addressbook-access" |
|
355 | 355 | } |
356 | 356 | //error_log(__METHOD__."('$path') --> app='$app' --> DAV: ".implode(', ', $dav)); |
357 | 357 | } |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * @param array return array for file properties |
364 | 364 | * @return bool true on success |
365 | 365 | */ |
366 | - function PROPFIND(&$options, &$files, $method='PROPFIND') |
|
366 | + function PROPFIND(&$options, &$files, $method = 'PROPFIND') |
|
367 | 367 | { |
368 | 368 | if ($this->debug) error_log(__CLASS__."::$method(".array2string($options).')'); |
369 | 369 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | |
373 | 373 | // parse path in form [/account_lid]/app[/more] |
374 | 374 | $id = $app = $user = $user_prefix = null; |
375 | - if (!self::_parse_path($options['path'],$id,$app,$user,$user_prefix) && $app && !$user && $user !== 0) |
|
375 | + if (!self::_parse_path($options['path'], $id, $app, $user, $user_prefix) && $app && !$user && $user !== 0) |
|
376 | 376 | { |
377 | 377 | if ($this->debug > 1) error_log(__CLASS__."::$method: user='$user', app='$app', id='$id': 404 not found!"); |
378 | 378 | return '404 Not Found'; |
@@ -404,9 +404,9 @@ discard block |
||
404 | 404 | $files['files'][] = $this->add_collection('/principals/', array( |
405 | 405 | 'displayname' => lang('Accounts'), |
406 | 406 | )); |
407 | - foreach($this->accounts->search(array('type' => 'both','order'=>'account_lid')) as $account) |
|
407 | + foreach ($this->accounts->search(array('type' => 'both', 'order'=>'account_lid')) as $account) |
|
408 | 408 | { |
409 | - $this->add_home($files, $path.$account['account_lid'].'/', $account['account_id'], $options['depth'] == 'infinity' ? 'infinity' : $options['depth']-1); |
|
409 | + $this->add_home($files, $path.$account['account_lid'].'/', $account['account_id'], $options['depth'] == 'infinity' ? 'infinity' : $options['depth'] - 1); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | return true; |
@@ -418,14 +418,14 @@ discard block |
||
418 | 418 | if ($app != 'principals' && !isset($GLOBALS['egw_info']['user']['apps'][$this->root[$app]['app'] ? $this->root[$app]['app'] : $app])) |
419 | 419 | { |
420 | 420 | if ($this->debug) error_log(__CLASS__."::$method(path=$options[path]) 403 Forbidden: no app rights for '$app'"); |
421 | - return "403 Forbidden: no app rights for '$app'"; // no rights for the given app |
|
421 | + return "403 Forbidden: no app rights for '$app'"; // no rights for the given app |
|
422 | 422 | } |
423 | 423 | if (($handler = self::app_handler($app))) |
424 | 424 | { |
425 | 425 | if ($method != 'REPORT' && !$id) // no self URL for REPORT requests (only PROPFIND) or propfinds on an id |
426 | 426 | { |
427 | 427 | // KAddressbook doubles the folder, if the self URL contains the GroupDAV/CalDAV resourcetypes |
428 | - $files['files'][0] = $this->add_app($app,$app=='addressbook'&&$handler->get_agent()=='kde',$user, |
|
428 | + $files['files'][0] = $this->add_app($app, $app == 'addressbook' && $handler->get_agent() == 'kde', $user, |
|
429 | 429 | $this->_slashify($options['path'])); |
430 | 430 | |
431 | 431 | // Hack for iOS 5.0.1 addressbook to stop asking directory gateway permissions with depth != 0 |
@@ -436,9 +436,9 @@ discard block |
||
436 | 436 | $this->log(__CLASS__."::$method(".array2string($options).') Enabling hack for iOS 5.0.1 addressbook: force Depth: 0 on PROPFIND for directory gateway!'); |
437 | 437 | return true; |
438 | 438 | } |
439 | - if (!$options['depth']) return true; // depth 0 --> show only the self url |
|
439 | + if (!$options['depth']) return true; // depth 0 --> show only the self url |
|
440 | 440 | } |
441 | - return $handler->propfind($this->_slashify($options['path']),$options,$files,$user,$id); |
|
441 | + return $handler->propfind($this->_slashify($options['path']), $options, $files, $user, $id); |
|
442 | 442 | } |
443 | 443 | return '501 Not Implemented'; |
444 | 444 | } |
@@ -452,10 +452,10 @@ discard block |
||
452 | 452 | * @param array $supported_privileges =null default $this->supported_privileges |
453 | 453 | * @return array with values for keys 'path' and 'props' |
454 | 454 | */ |
455 | - public function add_collection($path, array $props = array(), array $privileges=array('read','read-acl','read-current-user-privilege-set'), array $supported_privileges=null) |
|
455 | + public function add_collection($path, array $props = array(), array $privileges = array('read', 'read-acl', 'read-current-user-privilege-set'), array $supported_privileges = null) |
|
456 | 456 | { |
457 | 457 | // resourcetype: collection |
458 | - $props['resourcetype'][] = self::mkprop('collection',''); |
|
458 | + $props['resourcetype'][] = self::mkprop('collection', ''); |
|
459 | 459 | |
460 | 460 | if (!isset($props['getcontenttype'])) $props['getcontenttype'] = 'httpd/unix-directory'; |
461 | 461 | |
@@ -471,16 +471,16 @@ discard block |
||
471 | 471 | * @param array $supported_privileges =null default $this->supported_privileges |
472 | 472 | * @return array with values for keys 'path' and 'props' |
473 | 473 | */ |
474 | - public function add_resource($path, array $props = array(), array $privileges=array('read','read-current-user-privilege-set'), array $supported_privileges=null) |
|
474 | + public function add_resource($path, array $props = array(), array $privileges = array('read', 'read-current-user-privilege-set'), array $supported_privileges = null) |
|
475 | 475 | { |
476 | 476 | // props for all collections: current-user-principal and principal-collection-set |
477 | 477 | $props['current-user-principal'] = array( |
478 | - self::mkprop('href',$this->current_user_principal)); |
|
478 | + self::mkprop('href', $this->current_user_principal)); |
|
479 | 479 | $props['principal-collection-set'] = array( |
480 | - self::mkprop('href',$this->base_uri.'/principals/')); |
|
480 | + self::mkprop('href', $this->base_uri.'/principals/')); |
|
481 | 481 | |
482 | 482 | // required props per WebDAV standard |
483 | - foreach(array( |
|
483 | + foreach (array( |
|
484 | 484 | 'displayname' => basename($path), |
485 | 485 | 'getetag' => 'none', |
486 | 486 | 'getcontentlength' => '', |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | if (is_null($supported_privileges)) $supported_privileges = $this->supported_privileges; |
497 | 497 | if ($this->prop_requested('current-user-privilege-set') === true) |
498 | 498 | { |
499 | - foreach($privileges as $name) |
|
499 | + foreach ($privileges as $name) |
|
500 | 500 | { |
501 | 501 | $props['current-user-privilege-set'][] = self::mkprop('privilege', array( |
502 | 502 | is_array($name) ? self::mkprop($name['ns'], $name['name'], '') : self::mkprop($name, ''))); |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | } |
505 | 505 | if ($this->prop_requested('supported-privilege-set') === true) |
506 | 506 | { |
507 | - foreach($supported_privileges as $name => $data) |
|
507 | + foreach ($supported_privileges as $name => $data) |
|
508 | 508 | { |
509 | 509 | $props['supported-privilege-set'][] = $this->supported_privilege($name, $data, $path); |
510 | 510 | } |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | if ($this->debug > 1) error_log(__METHOD__."(path='$path', props=".array2string($props).')'); |
518 | 518 | |
519 | 519 | // convert simple associative properties to HTTP_WebDAV_Server ones |
520 | - foreach($props as $name => &$prop) |
|
520 | + foreach ($props as $name => &$prop) |
|
521 | 521 | { |
522 | 522 | if (!is_array($prop) || !isset($prop['name'])) |
523 | 523 | { |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | * @param string $path =null path to match with $data['*only*'] |
545 | 545 | * @return array of self::mkprop() arrays |
546 | 546 | */ |
547 | - protected function supported_privilege($name, $data, $path=null) |
|
547 | + protected function supported_privilege($name, $data, $path = null) |
|
548 | 548 | { |
549 | 549 | $props = array(); |
550 | 550 | $props[] = self::mkprop('privilege', array(is_array($data) && $data['*ns*'] ? |
@@ -552,12 +552,12 @@ discard block |
||
552 | 552 | $props[] = self::mkprop('description', is_array($data) ? $data['*description*'] : $data); |
553 | 553 | if (is_array($data)) |
554 | 554 | { |
555 | - foreach($data as $name => $data) |
|
555 | + foreach ($data as $name => $data) |
|
556 | 556 | { |
557 | 557 | if ($name[0] == '*') continue; |
558 | 558 | if (is_array($data) && $data['*only*'] && strpos($path, $data['*only*']) === false) |
559 | 559 | { |
560 | - continue; // wrong path |
|
560 | + continue; // wrong path |
|
561 | 561 | } |
562 | 562 | $props[] = $this->supported_privilege($name, $data, $path); |
563 | 563 | } |
@@ -573,20 +573,20 @@ discard block |
||
573 | 573 | * @param boolean $return_prop =false if true return the property array with values for 'name', 'xmlns', 'attrs', 'children' |
574 | 574 | * @return boolean|string|array true: $name explicitly requested (or autoindex), "all": allprop or "names": propname requested, false: $name was not requested |
575 | 575 | */ |
576 | - function prop_requested($name, $ns=null, $return_prop=false) |
|
576 | + function prop_requested($name, $ns = null, $return_prop = false) |
|
577 | 577 | { |
578 | 578 | if (!is_array($this->propfind_options) || !isset($this->propfind_options['props'])) |
579 | 579 | { |
580 | - $ret = true; // no props set, should happen only in autoindex, we return true to show all available props |
|
580 | + $ret = true; // no props set, should happen only in autoindex, we return true to show all available props |
|
581 | 581 | } |
582 | 582 | elseif (!is_array($this->propfind_options['props'])) |
583 | 583 | { |
584 | - $ret = $this->propfind_options['props']; // "all": allprop or "names": propname |
|
584 | + $ret = $this->propfind_options['props']; // "all": allprop or "names": propname |
|
585 | 585 | } |
586 | 586 | else |
587 | 587 | { |
588 | 588 | $ret = false; |
589 | - foreach($this->propfind_options['props'] as $prop) |
|
589 | + foreach ($this->propfind_options['props'] as $prop) |
|
590 | 590 | { |
591 | 591 | if ($prop['name'] == $name && (is_null($ns) || $prop['xmlns'] == $ns)) |
592 | 592 | { |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | $account = $this->accounts->read($account_lid); |
622 | 622 | |
623 | 623 | $calendar_user_address_set = array( |
624 | - self::mkprop('href','urn:uuid:'.$account['account_lid']), |
|
624 | + self::mkprop('href', 'urn:uuid:'.$account['account_lid']), |
|
625 | 625 | ); |
626 | 626 | if ($user < 0) |
627 | 627 | { |
@@ -632,29 +632,29 @@ discard block |
||
632 | 632 | { |
633 | 633 | $principalType = 'users'; |
634 | 634 | $displayname = $account['account_fullname']; |
635 | - $calendar_user_address_set[] = self::mkprop('href','mailto:'.$account['account_email']); |
|
635 | + $calendar_user_address_set[] = self::mkprop('href', 'mailto:'.$account['account_email']); |
|
636 | 636 | } |
637 | - $calendar_user_address_set[] = self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account['account_lid'].'/'); |
|
637 | + $calendar_user_address_set[] = self::mkprop('href', $this->base_uri.'/principals/'.$principalType.'/'.$account['account_lid'].'/'); |
|
638 | 638 | |
639 | 639 | if ($depth && $path == '/') |
640 | 640 | { |
641 | 641 | $displayname = 'EGroupware (Cal|Card|Group)DAV server'; |
642 | 642 | } |
643 | 643 | |
644 | - $displayname = Translation::convert($displayname, Translation::charset(),'utf-8'); |
|
644 | + $displayname = Translation::convert($displayname, Translation::charset(), 'utf-8'); |
|
645 | 645 | // self url |
646 | 646 | $props = array( |
647 | 647 | 'displayname' => $displayname, |
648 | - 'owner' => $path == '/' ? '' : array(self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/')), |
|
648 | + 'owner' => $path == '/' ? '' : array(self::mkprop('href', $this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/')), |
|
649 | 649 | ); |
650 | 650 | |
651 | 651 | if ($path != '/') |
652 | 652 | { |
653 | 653 | // add props modifyable via proppatch from client, eg. jqcalendar stores it's preferences there |
654 | - foreach((array)$GLOBALS['egw_info']['user']['preferences']['groupdav'] as $name => $value) |
|
654 | + foreach ((array)$GLOBALS['egw_info']['user']['preferences']['groupdav'] as $name => $value) |
|
655 | 655 | { |
656 | - list($prop,$prop4path,$ns) = explode(':', $name, 3); |
|
657 | - if ($prop4path == $path && (!in_array($ns,self::$ns_needs_explicit_named_props) || |
|
656 | + list($prop, $prop4path, $ns) = explode(':', $name, 3); |
|
657 | + if ($prop4path == $path && (!in_array($ns, self::$ns_needs_explicit_named_props) || |
|
658 | 658 | isset(self::$proppatch_props[$prop]) && self::$proppatch_props[$prop] === $ns)) |
659 | 659 | { |
660 | 660 | $props[] = self::mkprop($ns, $prop, $value); |
@@ -666,19 +666,19 @@ discard block |
||
666 | 666 | |
667 | 667 | if ($depth) |
668 | 668 | { |
669 | - foreach($this->root as $app => $data) |
|
669 | + foreach ($this->root as $app => $data) |
|
670 | 670 | { |
671 | - if (!$GLOBALS['egw_info']['user']['apps'][$data['app'] ? $data['app'] : $app]) continue; // no rights for the given app |
|
671 | + if (!$GLOBALS['egw_info']['user']['apps'][$data['app'] ? $data['app'] : $app]) continue; // no rights for the given app |
|
672 | 672 | if (!empty($data['user-only']) && ($path == '/' || $user < 0)) continue; |
673 | 673 | |
674 | - $files['files'][] = $this->add_app($app,false,$user,$path.$app.'/'); |
|
674 | + $files['files'][] = $this->add_app($app, false, $user, $path.$app.'/'); |
|
675 | 675 | |
676 | 676 | // only add global /addressbook-accounts/ as the one in home-set is added (and controled) by add_shared |
677 | 677 | if ($path == '/' && $app == 'addressbook' && |
678 | 678 | !$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) |
679 | 679 | { |
680 | - $file = $this->add_app($app,false,0,$path.$app.'-accounts/'); |
|
681 | - $file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared',''); |
|
680 | + $file = $this->add_app($app, false, 0, $path.$app.'-accounts/'); |
|
681 | + $file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER, 'shared', ''); |
|
682 | 682 | $files['files'][] = $file; |
683 | 683 | } |
684 | 684 | // added shared calendars or addressbooks |
@@ -701,12 +701,12 @@ discard block |
||
701 | 701 | * @param int $depth =0 |
702 | 702 | * @return string|boolean http status or true|false |
703 | 703 | */ |
704 | - protected function add_resources_collection(array &$files, $path, $depth=0) |
|
704 | + protected function add_resources_collection(array &$files, $path, $depth = 0) |
|
705 | 705 | { |
706 | 706 | if (!isset($GLOBALS['egw_info']['user']['apps']['resources'])) |
707 | 707 | { |
708 | 708 | if ($this->debug) error_log(__METHOD__."(path=$path) 403 Forbidden: no app rights for 'resources'"); |
709 | - return "403 Forbidden: no app rights for 'resources'"; // no rights for the given app |
|
709 | + return "403 Forbidden: no app rights for 'resources'"; // no rights for the given app |
|
710 | 710 | } |
711 | 711 | list(,$what) = explode('/', $path); |
712 | 712 | if (($is_location = ($what == 'locations'))) |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | } |
720 | 720 | if ($depth) |
721 | 721 | { |
722 | - foreach(Principals::get_resources() as $resource) |
|
722 | + foreach (Principals::get_resources() as $resource) |
|
723 | 723 | { |
724 | 724 | if ($is_location == Principals::resource_is_location($resource)) |
725 | 725 | { |
@@ -751,11 +751,11 @@ discard block |
||
751 | 751 | $handler = $this->app_handler($app); |
752 | 752 | if (($shared = $handler->get_shared())) |
753 | 753 | { |
754 | - foreach($shared as $id => $owner) |
|
754 | + foreach ($shared as $id => $owner) |
|
755 | 755 | { |
756 | - $file = $this->add_app($app,false,$id,$path.$owner.'/'); |
|
756 | + $file = $this->add_app($app, false, $id, $path.$owner.'/'); |
|
757 | 757 | // mark other users calendar as shared (iOS 5.0.1 AB does NOT display AB marked as shared!) |
758 | - if ($app == 'calendar') $file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared',''); |
|
758 | + if ($app == 'calendar') $file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER, 'shared', ''); |
|
759 | 759 | $files[] = $file; |
760 | 760 | } |
761 | 761 | } |
@@ -785,11 +785,11 @@ discard block |
||
785 | 785 | { |
786 | 786 | if ($account < 0) |
787 | 787 | { |
788 | - $name = lang('Group').' '.$this->accounts->id2name($account,'account_lid'); |
|
788 | + $name = lang('Group').' '.$this->accounts->id2name($account, 'account_lid'); |
|
789 | 789 | } |
790 | 790 | else |
791 | 791 | { |
792 | - $name = $this->accounts->id2name($account,'account_fullname'); |
|
792 | + $name = $this->accounts->id2name($account, 'account_fullname'); |
|
793 | 793 | } |
794 | 794 | if (empty($name)) $name = '#'.$account; |
795 | 795 | } |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | * @param string $path ='/' |
806 | 806 | * @return array with values for keys 'path' and 'props' |
807 | 807 | */ |
808 | - protected function add_app($app,$no_extra_types=false,$user=null,$path='/') |
|
808 | + protected function add_app($app, $no_extra_types = false, $user = null, $path = '/') |
|
809 | 809 | { |
810 | 810 | if ($this->debug) error_log(__METHOD__."(app='$app', no_extra_types=$no_extra_types, user='$user', path='$path')"); |
811 | 811 | $user_preferences = $GLOBALS['egw_info']['user']['preferences']; |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | if (!isset($displayname)) $displayname = $this->account_name($user); |
835 | 835 | |
836 | 836 | $props = array( |
837 | - 'owner' => array(self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/')), |
|
837 | + 'owner' => array(self::mkprop('href', $this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/')), |
|
838 | 838 | ); |
839 | 839 | |
840 | 840 | switch ($app) |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | $props['displayname'] = lang('All addressbooks'); |
852 | 852 | break; |
853 | 853 | } |
854 | - elseif(!$user && !$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) |
|
854 | + elseif (!$user && !$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) |
|
855 | 855 | { |
856 | 856 | unset($props['owner']); |
857 | 857 | $props['displayname'] = lang($app).' '.lang('Accounts'); |
@@ -864,40 +864,40 @@ discard block |
||
864 | 864 | |
865 | 865 | // rfc 5995 (Use POST to add members to WebDAV collections): we use collection path with add-member query param |
866 | 866 | // leaving it switched off, until further testing, because OS X iCal seem to ignore it and OS X Addressbook uses POST to full URL without ?add-member |
867 | - if ($app && !in_array($app,array('inbox','outbox','principals'))) // not on inbox, outbox or principals |
|
867 | + if ($app && !in_array($app, array('inbox', 'outbox', 'principals'))) // not on inbox, outbox or principals |
|
868 | 868 | { |
869 | - $props['add-member'][] = self::mkprop('href',$this->base_uri.$path.'?add-member'); |
|
869 | + $props['add-member'][] = self::mkprop('href', $this->base_uri.$path.'?add-member'); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | // add props modifyable via proppatch from client, eg. calendar-color, see self::$proppatch_props |
873 | 873 | $ns = null; |
874 | - foreach((array)$GLOBALS['egw_info']['user']['preferences'][$app] as $name => $value) |
|
874 | + foreach ((array)$GLOBALS['egw_info']['user']['preferences'][$app] as $name => $value) |
|
875 | 875 | { |
876 | 876 | unset($ns); |
877 | - list($prop,$prop4user,$ns) = explode(':', $name, 3); |
|
877 | + list($prop, $prop4user, $ns) = explode(':', $name, 3); |
|
878 | 878 | if ($prop4user == (string)$user && isset(self::$proppatch_props[$prop]) && !isset($ns)) |
879 | 879 | { |
880 | 880 | $props[$prop] = self::mkprop(self::$proppatch_props[$prop], $prop, $value); |
881 | 881 | //error_log(__METHOD__."() explicit ".self::$proppatch_props[$prop].":$prop=".array2string($value)); |
882 | 882 | } |
883 | 883 | // props in arbitrary namespaces not mentioned in self::$ns_needs_explicit_named_props |
884 | - elseif(isset($ns) && !in_array($ns,self::$ns_needs_explicit_named_props)) |
|
884 | + elseif (isset($ns) && !in_array($ns, self::$ns_needs_explicit_named_props)) |
|
885 | 885 | { |
886 | 886 | $props[] = self::mkprop($ns, $prop, $value); |
887 | 887 | //error_log(__METHOD__."() arbitrary $ns:$prop=".array2string($value)); |
888 | 888 | } |
889 | 889 | } |
890 | 890 | |
891 | - foreach((array)$this->root[$app] as $prop => $values) |
|
891 | + foreach ((array)$this->root[$app] as $prop => $values) |
|
892 | 892 | { |
893 | - switch($prop) |
|
893 | + switch ($prop) |
|
894 | 894 | { |
895 | 895 | case 'resourcetype'; |
896 | 896 | if (!$no_extra_types) |
897 | 897 | { |
898 | - foreach($this->root[$app]['resourcetype'] as $ns => $type) |
|
898 | + foreach ($this->root[$app]['resourcetype'] as $ns => $type) |
|
899 | 899 | { |
900 | - $props['resourcetype'][] = self::mkprop($ns,$type,''); |
|
900 | + $props['resourcetype'][] = self::mkprop($ns, $type, ''); |
|
901 | 901 | } |
902 | 902 | // add /addressbook/ as directory gateway |
903 | 903 | if ($path == '/addressbook/') |
@@ -908,13 +908,13 @@ discard block |
||
908 | 908 | break; |
909 | 909 | case 'app': |
910 | 910 | case 'user-only': |
911 | - break; // no props, already handled |
|
911 | + break; // no props, already handled |
|
912 | 912 | default: |
913 | 913 | if (is_array($values)) |
914 | 914 | { |
915 | - foreach($values as $ns => $value) |
|
915 | + foreach ($values as $ns => $value) |
|
916 | 916 | { |
917 | - $props[$prop] = self::mkprop($ns,$prop,$value); |
|
917 | + $props[$prop] = self::mkprop($ns, $prop, $value); |
|
918 | 918 | } |
919 | 919 | } |
920 | 920 | else |
@@ -927,20 +927,20 @@ discard block |
||
927 | 927 | // add other handler specific properties |
928 | 928 | if (($handler = self::app_handler($app))) |
929 | 929 | { |
930 | - if (method_exists($handler,'extra_properties')) |
|
930 | + if (method_exists($handler, 'extra_properties')) |
|
931 | 931 | { |
932 | 932 | $props = $handler->extra_properties($props, $displayname, $this->base_uri, $user, $path); |
933 | 933 | } |
934 | 934 | // add ctag if handler implements it |
935 | - if (method_exists($handler,'getctag') && $this->prop_requested('getctag') === true) |
|
935 | + if (method_exists($handler, 'getctag') && $this->prop_requested('getctag') === true) |
|
936 | 936 | { |
937 | 937 | $props['getctag'] = self::mkprop( |
938 | - self::CALENDARSERVER,'getctag',$handler->getctag($path,$user)); |
|
938 | + self::CALENDARSERVER, 'getctag', $handler->getctag($path, $user)); |
|
939 | 939 | } |
940 | 940 | // add sync-token url if handler supports sync-collection report |
941 | 941 | if (isset($props['supported-report-set']['sync-collection']) && $this->prop_requested('sync-token') === true) |
942 | 942 | { |
943 | - $props['sync-token'] = $handler->get_sync_token($path,$user); |
|
943 | + $props['sync-token'] = $handler->get_sync_token($path, $user); |
|
944 | 944 | } |
945 | 945 | } |
946 | 946 | if ($handler && !is_null($user)) |
@@ -963,7 +963,7 @@ discard block |
||
963 | 963 | { |
964 | 964 | if ($this->debug > 1) error_log(__METHOD__.'('.array2string($options).')'); |
965 | 965 | |
966 | - return $this->PROPFIND($options,$files,'REPORT'); |
|
966 | + return $this->PROPFIND($options, $files, 'REPORT'); |
|
967 | 967 | } |
968 | 968 | |
969 | 969 | /** |
@@ -987,13 +987,13 @@ discard block |
||
987 | 987 | if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
988 | 988 | |
989 | 989 | $id = $app = $user = null; |
990 | - if (!$this->_parse_path($options['path'],$id,$app,$user) || $app == 'principals') |
|
990 | + if (!$this->_parse_path($options['path'], $id, $app, $user) || $app == 'principals') |
|
991 | 991 | { |
992 | 992 | return $this->autoindex($options); |
993 | 993 | } |
994 | 994 | if (($handler = self::app_handler($app))) |
995 | 995 | { |
996 | - return $handler->get($options,$id,$user); |
|
996 | + return $handler->get($options, $id, $user); |
|
997 | 997 | } |
998 | 998 | error_log(__METHOD__."(".array2string($options).") 501 Not Implemented"); |
999 | 999 | return '501 Not Implemented'; |
@@ -1011,9 +1011,9 @@ discard block |
||
1011 | 1011 | 'depth' => 1, |
1012 | 1012 | ); |
1013 | 1013 | $files = array(); |
1014 | - if (($ret = $this->PROPFIND($propfind_options,$files)) !== true) |
|
1014 | + if (($ret = $this->PROPFIND($propfind_options, $files)) !== true) |
|
1015 | 1015 | { |
1016 | - return $ret; // no collection |
|
1016 | + return $ret; // no collection |
|
1017 | 1017 | } |
1018 | 1018 | header('Content-type: text/html; charset='.Translation::charset()); |
1019 | 1019 | echo "<html>\n<head>\n\t<title>".'EGroupware (Cal|Card|Group)DAV server '.htmlspecialchars($options['path'])."</title>\n"; |
@@ -1024,10 +1024,10 @@ discard block |
||
1024 | 1024 | |
1025 | 1025 | echo '<h1>(Cal|Card|Group)DAV '; |
1026 | 1026 | $path = '/groupdav.php'; |
1027 | - foreach(explode('/',$this->_unslashify($options['path'])) as $n => $name) |
|
1027 | + foreach (explode('/', $this->_unslashify($options['path'])) as $n => $name) |
|
1028 | 1028 | { |
1029 | 1029 | $path .= ($n != 1 ? '/' : '').$name; |
1030 | - echo Html::a_href(htmlspecialchars($name.'/'),$path); |
|
1030 | + echo Html::a_href(htmlspecialchars($name.'/'), $path); |
|
1031 | 1031 | } |
1032 | 1032 | echo "</h1>\n"; |
1033 | 1033 | |
@@ -1047,18 +1047,18 @@ discard block |
||
1047 | 1047 | ); |
1048 | 1048 | $n = 0; |
1049 | 1049 | $collection_props = null; |
1050 | - foreach($files['files'] as $file) |
|
1050 | + foreach ($files['files'] as $file) |
|
1051 | 1051 | { |
1052 | 1052 | if (!isset($collection_props)) |
1053 | 1053 | { |
1054 | 1054 | $collection_props = $this->props2array($file['props']); |
1055 | 1055 | echo '<h3>'.lang('Collection listing').': '.htmlspecialchars($collection_props['DAV:displayname'])."</h3>\n"; |
1056 | - continue; // own entry --> displaying properies later |
|
1056 | + continue; // own entry --> displaying properies later |
|
1057 | 1057 | } |
1058 | - if(!$n++) |
|
1058 | + if (!$n++) |
|
1059 | 1059 | { |
1060 | 1060 | echo "<table>\n\t<tr class='th'>\n\t\t<th>#</th>\n\t\t<th>".lang('Name')."</th>"; |
1061 | - foreach($props2show as $label) |
|
1061 | + foreach ($props2show as $label) |
|
1062 | 1062 | { |
1063 | 1063 | echo "\t\t<th>".lang($label)."</th>\n"; |
1064 | 1064 | } |
@@ -1068,9 +1068,9 @@ discard block |
||
1068 | 1068 | //echo $file['path']; _debug_array($props); |
1069 | 1069 | $class = $class == 'row_on' ? 'row_off' : 'row_on'; |
1070 | 1070 | |
1071 | - if (substr($file['path'],-1) == '/') |
|
1071 | + if (substr($file['path'], -1) == '/') |
|
1072 | 1072 | { |
1073 | - $name = basename(substr($file['path'],0,-1)).'/'; |
|
1073 | + $name = basename(substr($file['path'], 0, -1)).'/'; |
|
1074 | 1074 | } |
1075 | 1075 | else |
1076 | 1076 | { |
@@ -1078,14 +1078,14 @@ discard block |
||
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | echo "\t<tr class='$class'>\n\t\t<td>$n</td>\n\t\t<td>". |
1081 | - Html::a_href(htmlspecialchars($name),'/groupdav.php'.strtr($file['path'], array( |
|
1081 | + Html::a_href(htmlspecialchars($name), '/groupdav.php'.strtr($file['path'], array( |
|
1082 | 1082 | '%' => '%25', |
1083 | 1083 | '#' => '%23', |
1084 | 1084 | '?' => '%3F', |
1085 | 1085 | )))."</td>\n"; |
1086 | - foreach($props2show as $prop => $label) |
|
1086 | + foreach ($props2show as $prop => $label) |
|
1087 | 1087 | { |
1088 | - echo "\t\t<td>".($prop=='DAV:getlastmodified'&&!empty($props[$prop])?date('Y-m-d H:i:s',$props[$prop]):$props[$prop])."</td>\n"; |
|
1088 | + echo "\t\t<td>".($prop == 'DAV:getlastmodified' && !empty($props[$prop]) ? date('Y-m-d H:i:s', $props[$prop]) : $props[$prop])."</td>\n"; |
|
1089 | 1089 | } |
1090 | 1090 | echo "\t</tr>\n"; |
1091 | 1091 | } |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | } |
1100 | 1100 | echo '<h3>'.lang('Properties')."</h3>\n"; |
1101 | 1101 | echo "<table>\n\t<tr class='th'><th>".lang('Namespace')."</th><th>".lang('Name')."</th><th>".lang('Value')."</th></tr>\n"; |
1102 | - foreach($collection_props as $name => $value) |
|
1102 | + foreach ($collection_props as $name => $value) |
|
1103 | 1103 | { |
1104 | 1104 | $class = $class == 'row_on' ? 'row_off' : 'row_on'; |
1105 | 1105 | $parts = explode(':', $name); |
@@ -1147,11 +1147,11 @@ discard block |
||
1147 | 1147 | 'wrap' => 0, |
1148 | 1148 | )); |
1149 | 1149 | } |
1150 | - if (($href=preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i',$value))) |
|
1150 | + if (($href = preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i', $value))) |
|
1151 | 1151 | { |
1152 | - $value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/','/').')?([^<]+)\<\/(D:)?href\>/i','<\\1href><a href="\\2\\3">\\3</a></\\4href>',$value); |
|
1152 | + $value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/', '/').')?([^<]+)\<\/(D:)?href\>/i', '<\\1href><a href="\\2\\3">\\3</a></\\4href>', $value); |
|
1153 | 1153 | } |
1154 | - $ret = $value[0] == '<' || strpos($value, "\n") !== false ? '<pre>'.htmlspecialchars($value).'</pre>' : htmlspecialchars($value); |
|
1154 | + $ret = $value[0] == '<' || strpos($value, "\n") !== false ? '<pre>'.htmlspecialchars($value).'</pre>' : htmlspecialchars($value); |
|
1155 | 1155 | |
1156 | 1156 | if ($href) |
1157 | 1157 | { |
@@ -1169,10 +1169,10 @@ discard block |
||
1169 | 1169 | protected function props2array(array $props) |
1170 | 1170 | { |
1171 | 1171 | $arr = array(); |
1172 | - foreach($props as $prop) |
|
1172 | + foreach ($props as $prop) |
|
1173 | 1173 | { |
1174 | 1174 | $ns_hash = array('DAV:' => 'D'); |
1175 | - switch($prop['ns']) |
|
1175 | + switch ($prop['ns']) |
|
1176 | 1176 | { |
1177 | 1177 | case 'DAV:'; |
1178 | 1178 | $ns = 'DAV'; |
@@ -1191,10 +1191,10 @@ discard block |
||
1191 | 1191 | } |
1192 | 1192 | if (is_array($prop['val'])) |
1193 | 1193 | { |
1194 | - $prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs='', $ns_hash); |
|
1194 | + $prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs = '', $ns_hash); |
|
1195 | 1195 | // hack to show real namespaces instead of not (visibly) defined shortcuts |
1196 | 1196 | unset($ns_hash['DAV:']); |
1197 | - $value = strtr($v=$this->prop_value($prop['val']),array_flip($ns_hash)); |
|
1197 | + $value = strtr($v = $this->prop_value($prop['val']), array_flip($ns_hash)); |
|
1198 | 1198 | } |
1199 | 1199 | else |
1200 | 1200 | { |
@@ -1217,13 +1217,13 @@ discard block |
||
1217 | 1217 | // POST to the collection URL plus a UID like name component (like for regular PUT) to create new entrys |
1218 | 1218 | if (isset($_GET['add-member']) || Handler::get_agent() == 'cfnetwork') |
1219 | 1219 | { |
1220 | - $_GET['add-member'] = ''; // otherwise we give no Location header |
|
1220 | + $_GET['add-member'] = ''; // otherwise we give no Location header |
|
1221 | 1221 | return $this->PUT($options); |
1222 | 1222 | } |
1223 | 1223 | if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
1224 | 1224 | |
1225 | 1225 | $id = $app = $user = null; |
1226 | - $this->_parse_path($options['path'],$id,$app,$user); |
|
1226 | + $this->_parse_path($options['path'], $id, $app, $user); |
|
1227 | 1227 | |
1228 | 1228 | if (($handler = self::app_handler($app))) |
1229 | 1229 | { |
@@ -1239,12 +1239,12 @@ discard block |
||
1239 | 1239 | if (isset($options['stream'])) |
1240 | 1240 | { |
1241 | 1241 | $options['content'] = ''; |
1242 | - while(!feof($options['stream'])) |
|
1242 | + while (!feof($options['stream'])) |
|
1243 | 1243 | { |
1244 | - $options['content'] .= fread($options['stream'],8192); |
|
1244 | + $options['content'] .= fread($options['stream'], 8192); |
|
1245 | 1245 | } |
1246 | 1246 | } |
1247 | - return $handler->post($options,$id,$user); |
|
1247 | + return $handler->post($options, $id, $user); |
|
1248 | 1248 | } |
1249 | 1249 | } |
1250 | 1250 | return '501 Not Implemented'; |
@@ -1283,7 +1283,7 @@ discard block |
||
1283 | 1283 | return '403 Forbidden'; |
1284 | 1284 | } |
1285 | 1285 | |
1286 | - switch($action) |
|
1286 | + switch ($action) |
|
1287 | 1287 | { |
1288 | 1288 | case 'attachment-add': |
1289 | 1289 | $matches = null; |
@@ -1295,8 +1295,8 @@ discard block |
||
1295 | 1295 | } |
1296 | 1296 | $path = null; |
1297 | 1297 | if (!($to = self::fopen_attachment($handler->app, $handler->get_id($entry), $filename, $this->_SERVER['CONTENT_TYPE'], $path)) || |
1298 | - isset($options['stream']) && ($copied=stream_copy_to_stream($options['stream'], $to)) === false || |
|
1299 | - isset($options['content']) && ($copied=fwrite($to, $options['content'])) === false) |
|
1298 | + isset($options['stream']) && ($copied = stream_copy_to_stream($options['stream'], $to)) === false || |
|
1299 | + isset($options['content']) && ($copied = fwrite($to, $options['content'])) === false) |
|
1300 | 1300 | { |
1301 | 1301 | return '403 Forbidden'; |
1302 | 1302 | } |
@@ -1339,8 +1339,8 @@ discard block |
||
1339 | 1339 | } |
1340 | 1340 | } |
1341 | 1341 | if (!($to = Vfs::fopen($path, 'w')) || |
1342 | - isset($options['stream']) && ($copied=stream_copy_to_stream($options['stream'], $to)) === false || |
|
1343 | - isset($options['content']) && ($copied=fwrite($to, $options['content'])) === false) |
|
1342 | + isset($options['stream']) && ($copied = stream_copy_to_stream($options['stream'], $to)) === false || |
|
1343 | + isset($options['content']) && ($copied = fwrite($to, $options['content'])) === false) |
|
1344 | 1344 | { |
1345 | 1345 | self::xml_error(self::mkprop(self::CALDAV, 'valid-managed-id-parameter', '')); |
1346 | 1346 | return '403 Forbidden'; |
@@ -1382,23 +1382,23 @@ discard block |
||
1382 | 1382 | * @param boolean $delete_via_put |
1383 | 1383 | * @return boolean false on error, eg. invalid managed id, for false an xml-error body has been send |
1384 | 1384 | */ |
1385 | - public static function handle_attach($app, $id, $attach, $delete_via_put=false) |
|
1385 | + public static function handle_attach($app, $id, $attach, $delete_via_put = false) |
|
1386 | 1386 | { |
1387 | 1387 | error_log(__METHOD__."('$app', $id, attach=".array2string($attach).", delete_via_put=".array2string($delete_via_put).')'); |
1388 | 1388 | |
1389 | 1389 | if (!Link::file_access($app, $id, Acl::EDIT)) |
1390 | 1390 | { |
1391 | 1391 | error_log(__METHOD__."('$app', $id, ...) no rights to update attachments"); |
1392 | - return; // no rights --> nothing to do |
|
1392 | + return; // no rights --> nothing to do |
|
1393 | 1393 | } |
1394 | - if (!is_array($attach)) $attach = array(); // could be PEAR_Error if not set |
|
1394 | + if (!is_array($attach)) $attach = array(); // could be PEAR_Error if not set |
|
1395 | 1395 | |
1396 | 1396 | if ($delete_via_put) |
1397 | 1397 | { |
1398 | - foreach(Vfs::find(Link::vfs_path($app, $id, '', true), array('type' => 'F')) as $path) |
|
1398 | + foreach (Vfs::find(Link::vfs_path($app, $id, '', true), array('type' => 'F')) as $path) |
|
1399 | 1399 | { |
1400 | 1400 | $found = false; |
1401 | - foreach($attach as $key => $attr) |
|
1401 | + foreach ($attach as $key => $attr) |
|
1402 | 1402 | { |
1403 | 1403 | if ($attr['params']['MANAGED-ID'] === self::path2managed_id($path)) |
1404 | 1404 | { |
@@ -1415,7 +1415,7 @@ discard block |
||
1415 | 1415 | } |
1416 | 1416 | } |
1417 | 1417 | // turn inline attachments into managed ones |
1418 | - foreach($attach as $key => $attr) |
|
1418 | + foreach ($attach as $key => $attr) |
|
1419 | 1419 | { |
1420 | 1420 | if (!empty($attr['params']['FMTTYPE'])) |
1421 | 1421 | { |
@@ -1428,7 +1428,7 @@ discard block |
||
1428 | 1428 | self::xml_error(self::mkprop(self::CALDAV, 'valid-managed-id', '')); |
1429 | 1429 | return false; |
1430 | 1430 | } |
1431 | - if($path == ($link = Link::vfs_path($app, $id, Vfs::basename($path)))) |
|
1431 | + if ($path == ($link = Link::vfs_path($app, $id, Vfs::basename($path)))) |
|
1432 | 1432 | { |
1433 | 1433 | error_log(__METHOD__."('$app', $id, ...) trying to modify existing MANAGED-ID --> ignored! ".array2string($attr)); |
1434 | 1434 | continue; |
@@ -1436,8 +1436,8 @@ discard block |
||
1436 | 1436 | // reuse valid managed-id --> symlink attachment |
1437 | 1437 | if (Vfs::file_exists($link)) |
1438 | 1438 | { |
1439 | - if (Vfs::readlink($link) === $path) continue; // no need to recreate identical link |
|
1440 | - Vfs::unlink($link); // symlink will fail, if $link exists |
|
1439 | + if (Vfs::readlink($link) === $path) continue; // no need to recreate identical link |
|
1440 | + Vfs::unlink($link); // symlink will fail, if $link exists |
|
1441 | 1441 | } |
1442 | 1442 | if (!Vfs::symlink($path, $link)) |
1443 | 1443 | { |
@@ -1445,9 +1445,9 @@ discard block |
||
1445 | 1445 | } |
1446 | 1446 | continue; |
1447 | 1447 | } |
1448 | - if (!($to = self::fopen_attachment($app, $id, $filename=$attr['params']['FILENAME'], $attr['params']['FMTTYPE'], $path)) || |
|
1448 | + if (!($to = self::fopen_attachment($app, $id, $filename = $attr['params']['FILENAME'], $attr['params']['FMTTYPE'], $path)) || |
|
1449 | 1449 | // Horde Icalendar does NOT decode automatic |
1450 | - ($copied=fwrite($to, $attr['params']['ENCODING'] == 'BASE64' ? base64_decode($attr['value']) : $attr['value'])) === false) |
|
1450 | + ($copied = fwrite($to, $attr['params']['ENCODING'] == 'BASE64' ? base64_decode($attr['value']) : $attr['value'])) === false) |
|
1451 | 1451 | { |
1452 | 1452 | error_log(__METHOD__."('$app', $id, ...) failed to add attachment ".array2string($attr).") "); |
1453 | 1453 | continue; |
@@ -1472,16 +1472,16 @@ discard block |
||
1472 | 1472 | * @param string &$path =null on return path opened |
1473 | 1473 | * @return resource |
1474 | 1474 | */ |
1475 | - protected static function fopen_attachment($app, $id, $_filename, $mime=null, &$path=null) |
|
1475 | + protected static function fopen_attachment($app, $id, $_filename, $mime = null, &$path = null) |
|
1476 | 1476 | { |
1477 | 1477 | $filename = empty($_filename) ? 'attachment' : Vfs::basename($_filename); |
1478 | 1478 | |
1479 | - if (strpos($mime, ';')) list($mime) = explode(';', $mime); // in case it contains eg. charset info |
|
1479 | + if (strpos($mime, ';')) list($mime) = explode(';', $mime); // in case it contains eg. charset info |
|
1480 | 1480 | |
1481 | 1481 | $ext = !empty($mime) ? MimeMagic::mime2ext($mime) : ''; |
1482 | 1482 | |
1483 | 1483 | $matches = null; |
1484 | - if (!$ext || substr($filename, -strlen($ext)-1) == '.'.$ext || |
|
1484 | + if (!$ext || substr($filename, -strlen($ext) - 1) == '.'.$ext || |
|
1485 | 1485 | preg_match('/\.([^.]+)$/', $filename, $matches) && MimeMagic::ext2mime($matches[1]) == $mime) |
1486 | 1486 | { |
1487 | 1487 | $parts = explode('.', $filename); |
@@ -1492,7 +1492,7 @@ discard block |
||
1492 | 1492 | { |
1493 | 1493 | $ext = '.'.$ext; |
1494 | 1494 | } |
1495 | - for($i = 1; $i < 100; ++$i) |
|
1495 | + for ($i = 1; $i < 100; ++$i) |
|
1496 | 1496 | { |
1497 | 1497 | $path = Link::vfs_path($app, $id, $filename.($i > 1 ? '-'.$i : '').$ext, true); |
1498 | 1498 | if (!Vfs::stat($path)) break; |
@@ -1538,7 +1538,7 @@ discard block |
||
1538 | 1538 | */ |
1539 | 1539 | public static function add_attach($app, $id, array &$attributes, array &$parameters) |
1540 | 1540 | { |
1541 | - foreach(Vfs::find(Link::vfs_path($app, $id, '', true), array( |
|
1541 | + foreach (Vfs::find(Link::vfs_path($app, $id, '', true), array( |
|
1542 | 1542 | 'type' => 'F', |
1543 | 1543 | 'need_mime' => true, |
1544 | 1544 | ), true) as $path => $stat) |
@@ -1546,7 +1546,7 @@ discard block |
||
1546 | 1546 | // handle symlinks --> return target size and mime-type |
1547 | 1547 | if (($target = Vfs::readlink($path))) |
1548 | 1548 | { |
1549 | - if (!($stat = Vfs::stat($target))) continue; // broken or inaccessible symlink |
|
1549 | + if (!($stat = Vfs::stat($target))) continue; // broken or inaccessible symlink |
|
1550 | 1550 | |
1551 | 1551 | // check if target is in /apps, probably reused MANAGED-ID --> return it |
1552 | 1552 | if (substr($target, 0, 6) == '/apps/') |
@@ -1558,7 +1558,7 @@ discard block |
||
1558 | 1558 | $parameters['ATTACH'][] = array( |
1559 | 1559 | 'MANAGED-ID' => self::path2managed_id($path), |
1560 | 1560 | 'FMTTYPE' => $stat['mime'], |
1561 | - 'SIZE' => (string)$stat['size'], // Horde_Icalendar renders int as empty string |
|
1561 | + 'SIZE' => (string)$stat['size'], // Horde_Icalendar renders int as empty string |
|
1562 | 1562 | 'FILENAME' => Vfs::basename($path), |
1563 | 1563 | ); |
1564 | 1564 | // if we have attachments, set X-attribute to enable deleting them by put |
@@ -1586,7 +1586,7 @@ discard block |
||
1586 | 1586 | * @param string|int $id =null id to check agains path |
1587 | 1587 | * @return string|boolean "/apps/$app/$id/something" or false if not found or not belonging to given $app/$id |
1588 | 1588 | */ |
1589 | - static public function managed_id2path($managed_id, $app=null, $id=null) |
|
1589 | + static public function managed_id2path($managed_id, $app = null, $id = null) |
|
1590 | 1590 | { |
1591 | 1591 | $path = base64_decode($managed_id); |
1592 | 1592 | |
@@ -1596,7 +1596,7 @@ discard block |
||
1596 | 1596 | } |
1597 | 1597 | elseif (!empty($app) && !empty($id)) |
1598 | 1598 | { |
1599 | - list(,,$a,$i) = explode('/', $path); |
|
1599 | + list(,, $a, $i) = explode('/', $path); |
|
1600 | 1600 | if ($a !== $app || $i !== (string)$id) |
1601 | 1601 | { |
1602 | 1602 | $path = false; |
@@ -1624,7 +1624,7 @@ discard block |
||
1624 | 1624 | 'displayname' => self::DAV, |
1625 | 1625 | 'calendar-description' => self::CALDAV, |
1626 | 1626 | 'addressbook-description' => self::CARDDAV, |
1627 | - 'calendar-color' => self::ICAL, // only mentioned that old prefs still work |
|
1627 | + 'calendar-color' => self::ICAL, // only mentioned that old prefs still work |
|
1628 | 1628 | 'calendar-order' => self::ICAL, |
1629 | 1629 | 'default-alarm-vevent-date' => self::CALDAV, |
1630 | 1630 | 'default-alarm-vevent-datetime' => self::CALDAV, |
@@ -1642,11 +1642,11 @@ discard block |
||
1642 | 1642 | |
1643 | 1643 | // parse path in form [/account_lid]/app[/more] |
1644 | 1644 | $id = $app = $user = $user_prefix = null; |
1645 | - self::_parse_path($options['path'],$id,$app,$user,$user_prefix); // allways returns false if eg. !$id |
|
1645 | + self::_parse_path($options['path'], $id, $app, $user, $user_prefix); // allways returns false if eg. !$id |
|
1646 | 1646 | if ($app == 'principals' || $id || $options['path'] == '/') |
1647 | 1647 | { |
1648 | 1648 | if ($this->debug > 1) error_log(__METHOD__.": user='$user', app='$app', id='$id': 404 not found!"); |
1649 | - foreach($options['props'] as &$prop) |
|
1649 | + foreach ($options['props'] as &$prop) |
|
1650 | 1650 | { |
1651 | 1651 | $prop['status'] = '403 Forbidden'; |
1652 | 1652 | } |
@@ -1654,10 +1654,10 @@ discard block |
||
1654 | 1654 | } |
1655 | 1655 | // store selected props in preferences, eg. calendar-color, see self::$proppatch_props |
1656 | 1656 | $need_save = array(); |
1657 | - foreach($options['props'] as &$prop) |
|
1657 | + foreach ($options['props'] as &$prop) |
|
1658 | 1658 | { |
1659 | 1659 | if ((isset(self::$proppatch_props[$prop['name']]) && self::$proppatch_props[$prop['name']] === $prop['xmlns'] || |
1660 | - !in_array($prop['xmlns'],self::$ns_needs_explicit_named_props))) |
|
1660 | + !in_array($prop['xmlns'], self::$ns_needs_explicit_named_props))) |
|
1661 | 1661 | { |
1662 | 1662 | if (!$app) |
1663 | 1663 | { |
@@ -1686,7 +1686,7 @@ discard block |
||
1686 | 1686 | } |
1687 | 1687 | else |
1688 | 1688 | { |
1689 | - $prop['status'] = '409 Conflict'; // could also be "403 Forbidden" |
|
1689 | + $prop['status'] = '409 Conflict'; // could also be "403 Forbidden" |
|
1690 | 1690 | } |
1691 | 1691 | } |
1692 | 1692 | if ($need_save) |
@@ -1695,7 +1695,7 @@ discard block |
||
1695 | 1695 | // call calendar-hook, if default-alarms are changed, to sync them to calendar prefs |
1696 | 1696 | if (class_exists('calendar_hooks')) |
1697 | 1697 | { |
1698 | - foreach($need_save as $name) |
|
1698 | + foreach ($need_save as $name) |
|
1699 | 1699 | { |
1700 | 1700 | list($name) = explode(':', $name); |
1701 | 1701 | if (in_array($name, array('default-alarm-vevent-date', 'default-alarm-vevent-datetime'))) |
@@ -1720,22 +1720,22 @@ discard block |
||
1720 | 1720 | if (isset($options['stream'])) |
1721 | 1721 | { |
1722 | 1722 | $options['content'] = ''; |
1723 | - while(!feof($options['stream'])) |
|
1723 | + while (!feof($options['stream'])) |
|
1724 | 1724 | { |
1725 | - $options['content'] .= fread($options['stream'],8192); |
|
1725 | + $options['content'] .= fread($options['stream'], 8192); |
|
1726 | 1726 | } |
1727 | 1727 | } |
1728 | 1728 | |
1729 | 1729 | if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
1730 | 1730 | |
1731 | 1731 | $id = $app = $user = $prefix = null; |
1732 | - if (!$this->_parse_path($options['path'],$id,$app,$user,$prefix)) |
|
1732 | + if (!$this->_parse_path($options['path'], $id, $app, $user, $prefix)) |
|
1733 | 1733 | { |
1734 | 1734 | return '404 Not Found'; |
1735 | 1735 | } |
1736 | 1736 | if (($handler = self::app_handler($app))) |
1737 | 1737 | { |
1738 | - $status = $handler->put($options,$id,$user,$prefix); |
|
1738 | + $status = $handler->put($options, $id, $user, $prefix); |
|
1739 | 1739 | |
1740 | 1740 | // set default stati: true --> 204 No Content, false --> should be already handled |
1741 | 1741 | if (is_bool($status)) $status = $status ? '204 No Content' : '400 Something went wrong'; |
@@ -1765,13 +1765,13 @@ discard block |
||
1765 | 1765 | if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
1766 | 1766 | |
1767 | 1767 | $id = $app = $user = null; |
1768 | - if (!$this->_parse_path($options['path'],$id,$app,$user)) |
|
1768 | + if (!$this->_parse_path($options['path'], $id, $app, $user)) |
|
1769 | 1769 | { |
1770 | 1770 | return '404 Not Found'; |
1771 | 1771 | } |
1772 | 1772 | if (($handler = self::app_handler($app))) |
1773 | 1773 | { |
1774 | - $status = $handler->delete($options,$id); |
|
1774 | + $status = $handler->delete($options, $id); |
|
1775 | 1775 | // set default stati: true --> 204 No Content, false --> should be already handled |
1776 | 1776 | if (is_bool($status)) $status = $status ? '204 No Content' : '400 Something went wrong'; |
1777 | 1777 | return $status; |
@@ -1811,7 +1811,7 @@ discard block |
||
1811 | 1811 | * @param array general parameter passing array |
1812 | 1812 | * @return bool true on success |
1813 | 1813 | */ |
1814 | - function COPY($options, $del=false) |
|
1814 | + function COPY($options, $del = false) |
|
1815 | 1815 | { |
1816 | 1816 | if ($this->debug) error_log('self::'.($del ? 'MOVE' : 'COPY').'('.array2string($options).')'); |
1817 | 1817 | |
@@ -1827,8 +1827,8 @@ discard block |
||
1827 | 1827 | function LOCK(&$options) |
1828 | 1828 | { |
1829 | 1829 | $id = $app = $user = null; |
1830 | - self::_parse_path($options['path'],$id,$app,$user); |
|
1831 | - $path = Vfs::app_entry_lock_path($app,$id); |
|
1830 | + self::_parse_path($options['path'], $id, $app, $user); |
|
1831 | + $path = Vfs::app_entry_lock_path($app, $id); |
|
1832 | 1832 | |
1833 | 1833 | if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$path"); |
1834 | 1834 | |
@@ -1836,16 +1836,16 @@ discard block |
||
1836 | 1836 | $handler = self::app_handler($app); |
1837 | 1837 | |
1838 | 1838 | // TODO recursive locks on directories not supported yet |
1839 | - if (!$id || !empty($options['depth']) || !$handler->check_access(Acl::EDIT,$id)) |
|
1839 | + if (!$id || !empty($options['depth']) || !$handler->check_access(Acl::EDIT, $id)) |
|
1840 | 1840 | { |
1841 | 1841 | return '409 Conflict'; |
1842 | 1842 | } |
1843 | - $options['timeout'] = time()+300; // 5min. hardcoded |
|
1843 | + $options['timeout'] = time() + 300; // 5min. hardcoded |
|
1844 | 1844 | |
1845 | 1845 | // dont know why, but HTTP_WebDAV_Server passes the owner in D:href tags, which get's passed unchanged to checkLock/PROPFIND |
1846 | 1846 | // that's wrong according to the standard and cadaver does not show it on discover --> strip_tags removes eventual tags |
1847 | - if (($ret = Vfs::lock($path,$options['locktoken'],$options['timeout'],strip_tags($options['owner']), |
|
1848 | - $options['scope'],$options['type'],isset($options['update']),false)) && !isset($options['update'])) // false = no ACL check |
|
1847 | + if (($ret = Vfs::lock($path, $options['locktoken'], $options['timeout'], strip_tags($options['owner']), |
|
1848 | + $options['scope'], $options['type'], isset($options['update']), false)) && !isset($options['update'])) // false = no ACL check |
|
1849 | 1849 | { |
1850 | 1850 | return $ret ? '200 OK' : '409 Conflict'; |
1851 | 1851 | } |
@@ -1861,11 +1861,11 @@ discard block |
||
1861 | 1861 | function UNLOCK(&$options) |
1862 | 1862 | { |
1863 | 1863 | $id = $app = $user = null; |
1864 | - self::_parse_path($options['path'],$id,$app,$user); |
|
1865 | - $path = Vfs::app_entry_lock_path($app,$id); |
|
1864 | + self::_parse_path($options['path'], $id, $app, $user); |
|
1865 | + $path = Vfs::app_entry_lock_path($app, $id); |
|
1866 | 1866 | |
1867 | 1867 | if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$path"); |
1868 | - return Vfs::unlock($path,$options['token']) ? '204 No Content' : '409 Conflict'; |
|
1868 | + return Vfs::unlock($path, $options['token']) ? '204 No Content' : '409 Conflict'; |
|
1869 | 1869 | } |
1870 | 1870 | |
1871 | 1871 | /** |
@@ -1877,7 +1877,7 @@ discard block |
||
1877 | 1877 | function checkLock($path) |
1878 | 1878 | { |
1879 | 1879 | $id = $app = $user = null; |
1880 | - self::_parse_path($path,$id,$app,$user); |
|
1880 | + self::_parse_path($path, $id, $app, $user); |
|
1881 | 1881 | |
1882 | 1882 | return Vfs::checkLock(Vfs::app_entry_lock_path($app, $id)); |
1883 | 1883 | } |
@@ -1891,7 +1891,7 @@ discard block |
||
1891 | 1891 | function ACL(&$options) |
1892 | 1892 | { |
1893 | 1893 | $id = $app = $user = null; |
1894 | - self::_parse_path($options['path'],$id,$app,$user); |
|
1894 | + self::_parse_path($options['path'], $id, $app, $user); |
|
1895 | 1895 | |
1896 | 1896 | if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$options[path]"); |
1897 | 1897 | |
@@ -1921,7 +1921,7 @@ discard block |
||
1921 | 1921 | * @param string &$user_prefix =null |
1922 | 1922 | * @return boolean true on success, false on error |
1923 | 1923 | */ |
1924 | - function _parse_path($path,&$id,&$app,&$user,&$user_prefix=null) |
|
1924 | + function _parse_path($path, &$id, &$app, &$user, &$user_prefix = null) |
|
1925 | 1925 | { |
1926 | 1926 | if ($this->debug) |
1927 | 1927 | { |
@@ -1950,7 +1950,7 @@ discard block |
||
1950 | 1950 | } |
1951 | 1951 | } |
1952 | 1952 | elseif (($account_id = $this->accounts->name2id($parts[0], 'account_lid')) || |
1953 | - ($account_id = $this->accounts->name2id($parts[0]=urldecode($parts[0])))) |
|
1953 | + ($account_id = $this->accounts->name2id($parts[0] = urldecode($parts[0])))) |
|
1954 | 1954 | { |
1955 | 1955 | // /$user/$app/... |
1956 | 1956 | $user = array_shift($parts); |
@@ -1974,7 +1974,7 @@ discard block |
||
1974 | 1974 | { |
1975 | 1975 | $account_id = 0; |
1976 | 1976 | } |
1977 | - elseif($app == 'resource' || $app == 'location') |
|
1977 | + elseif ($app == 'resource' || $app == 'location') |
|
1978 | 1978 | { |
1979 | 1979 | if (!Principals::read_resource($res_id = (int)$username)) |
1980 | 1980 | { |
@@ -1984,7 +1984,7 @@ discard block |
||
1984 | 1984 | $app = 'calendar'; |
1985 | 1985 | } |
1986 | 1986 | elseif (!($account_id = $this->accounts->name2id($username, 'account_lid')) && |
1987 | - !($account_id = $this->accounts->name2id($username=urldecode($username)))) |
|
1987 | + !($account_id = $this->accounts->name2id($username = urldecode($username)))) |
|
1988 | 1988 | { |
1989 | 1989 | return false; |
1990 | 1990 | } |
@@ -2009,11 +2009,11 @@ discard block |
||
2009 | 2009 | $id = array_pop($parts); |
2010 | 2010 | |
2011 | 2011 | $ok = ($id || isset($_GET['add-member']) && $_SERVER['REQUEST_METHOD'] == 'POST') && |
2012 | - ($user || $user === 0) && in_array($app,array('addressbook','calendar','infolog','principals')); |
|
2012 | + ($user || $user === 0) && in_array($app, array('addressbook', 'calendar', 'infolog', 'principals')); |
|
2013 | 2013 | |
2014 | 2014 | if ($this->debug) |
2015 | 2015 | { |
2016 | - error_log(__METHOD__."('$path') returning " . ($ok ? 'true' : 'false') . ": id='$id', app='$app', user='$user', user_prefix='$user_prefix'"); |
|
2016 | + error_log(__METHOD__."('$path') returning ".($ok ? 'true' : 'false').": id='$id', app='$app', user='$user', user_prefix='$user_prefix'"); |
|
2017 | 2017 | } |
2018 | 2018 | return $ok; |
2019 | 2019 | } |
@@ -2035,7 +2035,7 @@ discard block |
||
2035 | 2035 | */ |
2036 | 2036 | function ServeRequest() |
2037 | 2037 | { |
2038 | - if ((self::$log_level=$GLOBALS['egw_info']['user']['preferences']['groupdav']['debug_level']) === 'r' || |
|
2038 | + if ((self::$log_level = $GLOBALS['egw_info']['user']['preferences']['groupdav']['debug_level']) === 'r' || |
|
2039 | 2039 | self::$log_level === 'f' || $this->debug) |
2040 | 2040 | { |
2041 | 2041 | self::$request_starttime = microtime(true); |
@@ -2055,7 +2055,7 @@ discard block |
||
2055 | 2055 | * |
2056 | 2056 | * @param string $extra ='' extra text to add below request-log, eg. exception thrown |
2057 | 2057 | */ |
2058 | - protected function log_request($extra='') |
|
2058 | + protected function log_request($extra = '') |
|
2059 | 2059 | { |
2060 | 2060 | if (self::$request_starttime) |
2061 | 2061 | { |
@@ -2063,7 +2063,7 @@ discard block |
||
2063 | 2063 | { |
2064 | 2064 | $msg_file = $GLOBALS['egw_info']['server']['files_dir']; |
2065 | 2065 | $msg_file .= '/groupdav'; |
2066 | - if (!file_exists($msg_file) && !mkdir($msg_file,0700)) |
|
2066 | + if (!file_exists($msg_file) && !mkdir($msg_file, 0700)) |
|
2067 | 2067 | { |
2068 | 2068 | error_log(__METHOD__."() Could NOT create directory '$msg_file'!"); |
2069 | 2069 | return; |
@@ -2076,19 +2076,19 @@ discard block |
||
2076 | 2076 | } |
2077 | 2077 | else |
2078 | 2078 | { |
2079 | - $msg_file .= str_replace('/','!',$_SERVER['HTTP_USER_AGENT']).'.log'; |
|
2079 | + $msg_file .= str_replace('/', '!', $_SERVER['HTTP_USER_AGENT']).'.log'; |
|
2080 | 2080 | } |
2081 | 2081 | $content = '*** '.$_SERVER['REMOTE_ADDR'].' '.date('c')."\n"; |
2082 | 2082 | } |
2083 | 2083 | $content .= $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' HTTP/1.1'."\n"; |
2084 | 2084 | // reconstruct headers |
2085 | - foreach($_SERVER as $name => $value) |
|
2085 | + foreach ($_SERVER as $name => $value) |
|
2086 | 2086 | { |
2087 | - list($type,$name) = explode('_',$name,2); |
|
2087 | + list($type, $name) = explode('_', $name, 2); |
|
2088 | 2088 | if ($type == 'HTTP' || $type == 'CONTENT') |
2089 | 2089 | { |
2090 | - $content .= str_replace(' ','-',ucwords(strtolower(($type=='HTTP'?'':$type.' ').str_replace('_',' ',$name)))). |
|
2091 | - ': '.($name=='AUTHORIZATION'?'Basic ***************':$value)."\n"; |
|
2090 | + $content .= str_replace(' ', '-', ucwords(strtolower(($type == 'HTTP' ? '' : $type.' ').str_replace('_', ' ', $name)))). |
|
2091 | + ': '.($name == 'AUTHORIZATION' ? 'Basic ***************' : $value)."\n"; |
|
2092 | 2092 | } |
2093 | 2093 | } |
2094 | 2094 | $content .= "\n"; |
@@ -2099,29 +2099,29 @@ discard block |
||
2099 | 2099 | $content .= 'HTTP/1.1 '.$this->_http_status."\n"; |
2100 | 2100 | $content .= 'Date: '.str_replace('+0000', 'GMT', gmdate('r'))."\n"; |
2101 | 2101 | $content .= 'Server: '.$_SERVER['SERVER_SOFTWARE']."\n"; |
2102 | - foreach(headers_list() as $line) |
|
2102 | + foreach (headers_list() as $line) |
|
2103 | 2103 | { |
2104 | 2104 | $content .= $line."\n"; |
2105 | 2105 | } |
2106 | 2106 | if (($c = ob_get_flush())) $content .= "\n"; |
2107 | - if (self::$log_level !== 'f' && strlen($c) > 1536) $c = substr($c,0,1536)."\n*** LOG TRUNKATED\n"; |
|
2107 | + if (self::$log_level !== 'f' && strlen($c) > 1536) $c = substr($c, 0, 1536)."\n*** LOG TRUNKATED\n"; |
|
2108 | 2108 | $content .= $c; |
2109 | 2109 | if ($extra) $content .= $extra; |
2110 | 2110 | if ($this->to_log) $content .= "\n### ".implode("\n### ", $this->to_log)."\n"; |
2111 | - $content .= $this->_http_status[0] == '4' && substr($this->_http_status,0,3) != '412' || |
|
2112 | - $this->_http_status[0] == '5' ? '###' : '***'; // mark failed requests with ###, instead of *** |
|
2113 | - $content .= sprintf(' %s --> "%s" took %5.3f s',$_SERVER['REQUEST_METHOD'].($_SERVER['REQUEST_METHOD']=='REPORT'?' '.$this->propfind_options['root']['name']:'').' '.$_SERVER['PATH_INFO'],$this->_http_status,microtime(true)-self::$request_starttime)."\n\n"; |
|
2111 | + $content .= $this->_http_status[0] == '4' && substr($this->_http_status, 0, 3) != '412' || |
|
2112 | + $this->_http_status[0] == '5' ? '###' : '***'; // mark failed requests with ###, instead of *** |
|
2113 | + $content .= sprintf(' %s --> "%s" took %5.3f s', $_SERVER['REQUEST_METHOD'].($_SERVER['REQUEST_METHOD'] == 'REPORT' ? ' '.$this->propfind_options['root']['name'] : '').' '.$_SERVER['PATH_INFO'], $this->_http_status, microtime(true) - self::$request_starttime)."\n\n"; |
|
2114 | 2114 | |
2115 | - if ($msg_file && ($f = fopen($msg_file,'a'))) |
|
2115 | + if ($msg_file && ($f = fopen($msg_file, 'a'))) |
|
2116 | 2116 | { |
2117 | - flock($f,LOCK_EX); |
|
2118 | - fwrite($f,$content); |
|
2119 | - flock($f,LOCK_UN); |
|
2117 | + flock($f, LOCK_EX); |
|
2118 | + fwrite($f, $content); |
|
2119 | + flock($f, LOCK_UN); |
|
2120 | 2120 | fclose($f); |
2121 | 2121 | } |
2122 | 2122 | else |
2123 | 2123 | { |
2124 | - foreach(explode("\n",$content) as $line) |
|
2124 | + foreach (explode("\n", $content) as $line) |
|
2125 | 2125 | { |
2126 | 2126 | error_log($line); |
2127 | 2127 | } |
@@ -2135,7 +2135,7 @@ discard block |
||
2135 | 2135 | * @param string|array $xml_error string with name for empty element in DAV NS or array with props |
2136 | 2136 | * @param string $human_readable =null human readable error message |
2137 | 2137 | */ |
2138 | - public static function xml_error($xml_error, $human_readable=null) |
|
2138 | + public static function xml_error($xml_error, $human_readable = null) |
|
2139 | 2139 | { |
2140 | 2140 | header('Content-type: application/xml; charset=utf-8'); |
2141 | 2141 | |
@@ -2152,7 +2152,7 @@ discard block |
||
2152 | 2152 | $xml->writeElement('responsedescription', $human_readable); |
2153 | 2153 | } |
2154 | 2154 | |
2155 | - $xml->endElement(); // DAV:error |
|
2155 | + $xml->endElement(); // DAV:error |
|
2156 | 2156 | $xml->endDocument(); |
2157 | 2157 | echo $xml->outputMemory(); |
2158 | 2158 | } |
@@ -2168,7 +2168,7 @@ discard block |
||
2168 | 2168 | if (is_string($props)) $props = self::mkprop($props, ''); |
2169 | 2169 | if (isset($props['name'])) $props = array($props); |
2170 | 2170 | |
2171 | - foreach($props as $prop) |
|
2171 | + foreach ($props as $prop) |
|
2172 | 2172 | { |
2173 | 2173 | if (isset($prop['ns']) && $prop['ns'] !== 'DAV:') |
2174 | 2174 | { |
@@ -2220,7 +2220,7 @@ discard block |
||
2220 | 2220 | { |
2221 | 2221 | // logging exception as regular egw_execption_hander does |
2222 | 2222 | $headline = null; |
2223 | - _egw_log_exception($e,$headline); |
|
2223 | + _egw_log_exception($e, $headline); |
|
2224 | 2224 | |
2225 | 2225 | // exception handler sending message back to the client as basic auth message |
2226 | 2226 | $error = str_replace(array("\r", "\n"), array('', ' | '), $e->getMessage()); |
@@ -2231,7 +2231,7 @@ discard block |
||
2231 | 2231 | // if our own logging is active, log the request plus a trace, if enabled in server-config |
2232 | 2232 | if (self::$request_starttime && isset(self::$instance)) |
2233 | 2233 | { |
2234 | - self::$instance->_http_status = '401 Unauthorized'; // to correctly log it |
|
2234 | + self::$instance->_http_status = '401 Unauthorized'; // to correctly log it |
|
2235 | 2235 | if ($GLOBALS['egw_info']['server']['exception_show_trace']) |
2236 | 2236 | { |
2237 | 2237 | self::$instance->log_request("\n".$e->getTraceAsString()."\n"); |
@@ -2253,7 +2253,7 @@ discard block |
||
2253 | 2253 | */ |
2254 | 2254 | static function generate_uid($_appName, $_eventID) |
2255 | 2255 | { |
2256 | - if(empty($_appName) || empty($_eventID)) return false; |
|
2256 | + if (empty($_appName) || empty($_eventID)) return false; |
|
2257 | 2257 | |
2258 | 2258 | return $_appName.'-'.$_eventID.'-'.$GLOBALS['egw_info']['server']['install_id']; |
2259 | 2259 | } |
@@ -222,11 +222,20 @@ discard block |
||
222 | 222 | function __construct() |
223 | 223 | { |
224 | 224 | // log which CalDAVTester test is currently running, set as User-Agent header |
225 | - if (substr($_SERVER['HTTP_USER_AGENT'], 0, 14) == 'scripts/tests/') error_log('****** '.$_SERVER['HTTP_USER_AGENT']); |
|
225 | + if (substr($_SERVER['HTTP_USER_AGENT'], 0, 14) == 'scripts/tests/') |
|
226 | + { |
|
227 | + error_log('****** '.$_SERVER['HTTP_USER_AGENT']); |
|
228 | + } |
|
226 | 229 | |
227 | - if (!$this->debug) $this->debug = (int)$GLOBALS['egw_info']['user']['preferences']['groupdav']['debug_level']; |
|
230 | + if (!$this->debug) |
|
231 | + { |
|
232 | + $this->debug = (int)$GLOBALS['egw_info']['user']['preferences']['groupdav']['debug_level']; |
|
233 | + } |
|
228 | 234 | |
229 | - if ($this->debug > 2) error_log('groupdav: $_SERVER='.array2string($_SERVER)); |
|
235 | + if ($this->debug > 2) |
|
236 | + { |
|
237 | + error_log('groupdav: $_SERVER='.array2string($_SERVER)); |
|
238 | + } |
|
230 | 239 | |
231 | 240 | // setting our own exception handler, to be able to still log the requests |
232 | 241 | set_exception_handler(array(__CLASS__,'exception_handler')); |
@@ -254,7 +263,10 @@ discard block |
||
254 | 263 | $this->crrnd = true; // Older Apple Addressbook.app does not cope with namespace redundancy |
255 | 264 | break; |
256 | 265 | } |
257 | - if ($this->debug) error_log(__METHOD__."() HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]' --> '$agent' --> client_requires_href_as_url=$this->client_require_href_as_url, crrnd(client refuses redundand namespace declarations)=$this->crrnd"); |
|
266 | + if ($this->debug) |
|
267 | + { |
|
268 | + error_log(__METHOD__."() HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]' --> '$agent' --> client_requires_href_as_url=$this->client_require_href_as_url, crrnd(client refuses redundand namespace declarations)=$this->crrnd"); |
|
269 | + } |
|
258 | 270 | |
259 | 271 | // adding EGroupware version to X-Dav-Powered-By header eg. "EGroupware 1.8.001 CalDAV/CardDAV/GroupDAV server" |
260 | 272 | $this->dav_powered_by = str_replace('EGroupware','EGroupware '.$GLOBALS['egw_info']['server']['versions']['phpgwapi'], |
@@ -300,7 +312,10 @@ discard block |
||
300 | 312 | */ |
301 | 313 | function app_handler($app) |
302 | 314 | { |
303 | - if (isset($this->root[$app]['app'])) $app = $this->root[$app]['app']; |
|
315 | + if (isset($this->root[$app]['app'])) |
|
316 | + { |
|
317 | + $app = $this->root[$app]['app']; |
|
318 | + } |
|
304 | 319 | |
305 | 320 | return Handler::app_handler($app,$this); |
306 | 321 | } |
@@ -317,22 +332,34 @@ discard block |
||
317 | 332 | unset($allow); // not used, but required by function signature |
318 | 333 | |
319 | 334 | // locking support |
320 | - if (!in_array('2', $dav)) $dav[] = '2'; |
|
335 | + if (!in_array('2', $dav)) |
|
336 | + { |
|
337 | + $dav[] = '2'; |
|
338 | + } |
|
321 | 339 | |
322 | - if (preg_match('#/(calendar(-[^/]+)?|inbox|outbox)/#', $path)) // eg. /<username>/calendar-<otheruser>/ |
|
340 | + if (preg_match('#/(calendar(-[^/]+)?|inbox|outbox)/#', $path)) |
|
341 | + { |
|
342 | + // eg. /<username>/calendar-<otheruser>/ |
|
323 | 343 | { |
324 | 344 | $app = 'calendar'; |
325 | 345 | } |
326 | - elseif (preg_match('#/addressbook(-[^/]+)?/#', $path)) // eg. /<username>/addressbook-<otheruser>/ |
|
346 | + } |
|
347 | + elseif (preg_match('#/addressbook(-[^/]+)?/#', $path)) |
|
348 | + { |
|
349 | + // eg. /<username>/addressbook-<otheruser>/ |
|
327 | 350 | { |
328 | 351 | $app = 'addressbook'; |
329 | 352 | } |
353 | + } |
|
330 | 354 | // CalDAV and CardDAV |
331 | 355 | $dav[] = 'access-control'; |
332 | 356 | |
333 | - if ($app !== 'addressbook') // CalDAV |
|
357 | + if ($app !== 'addressbook') |
|
358 | + { |
|
359 | + // CalDAV |
|
334 | 360 | { |
335 | 361 | $dav[] = 'calendar-access'; |
362 | + } |
|
336 | 363 | $dav[] = 'calendar-auto-schedule'; |
337 | 364 | $dav[] = 'calendar-proxy'; |
338 | 365 | // required by iOS iCal to use principal-property-search to autocomplete participants (and locations) |
@@ -349,9 +376,13 @@ discard block |
||
349 | 376 | //$dav[] = 'calendarserver-sharing'; |
350 | 377 | //$dav[] = 'calendarserver-sharing-no-scheduling'; |
351 | 378 | } |
352 | - if ($app !== 'calendar') // CardDAV |
|
379 | + if ($app !== 'calendar') |
|
353 | 380 | { |
354 | - $dav[] = 'addressbook'; // CardDAV uses "addressbook" NOT "addressbook-access" |
|
381 | + // CardDAV |
|
382 | + { |
|
383 | + $dav[] = 'addressbook'; |
|
384 | + } |
|
385 | + // CardDAV uses "addressbook" NOT "addressbook-access" |
|
355 | 386 | } |
356 | 387 | //error_log(__METHOD__."('$path') --> app='$app' --> DAV: ".implode(', ', $dav)); |
357 | 388 | } |
@@ -365,7 +396,10 @@ discard block |
||
365 | 396 | */ |
366 | 397 | function PROPFIND(&$options, &$files, $method='PROPFIND') |
367 | 398 | { |
368 | - if ($this->debug) error_log(__CLASS__."::$method(".array2string($options).')'); |
|
399 | + if ($this->debug) |
|
400 | + { |
|
401 | + error_log(__CLASS__."::$method(".array2string($options).')'); |
|
402 | + } |
|
369 | 403 | |
370 | 404 | // make options (readonly) available to all class methods, eg. prop_requested |
371 | 405 | $this->propfind_options = $options; |
@@ -374,18 +408,27 @@ discard block |
||
374 | 408 | $id = $app = $user = $user_prefix = null; |
375 | 409 | if (!self::_parse_path($options['path'],$id,$app,$user,$user_prefix) && $app && !$user && $user !== 0) |
376 | 410 | { |
377 | - if ($this->debug > 1) error_log(__CLASS__."::$method: user='$user', app='$app', id='$id': 404 not found!"); |
|
411 | + if ($this->debug > 1) |
|
412 | + { |
|
413 | + error_log(__CLASS__."::$method: user='$user', app='$app', id='$id': 404 not found!"); |
|
414 | + } |
|
378 | 415 | return '404 Not Found'; |
379 | 416 | } |
380 | - if ($this->debug > 1) error_log(__CLASS__."::$method(path='$options[path]'): user='$user', user_prefix='$user_prefix', app='$app', id='$id'"); |
|
417 | + if ($this->debug > 1) |
|
418 | + { |
|
419 | + error_log(__CLASS__."::$method(path='$options[path]'): user='$user', user_prefix='$user_prefix', app='$app', id='$id'"); |
|
420 | + } |
|
381 | 421 | |
382 | 422 | $files = array('files' => array()); |
383 | 423 | $path = $user_prefix = $this->_slashify($user_prefix); |
384 | 424 | |
385 | - if (!$app) // user root folder containing apps |
|
425 | + if (!$app) |
|
426 | + { |
|
427 | + // user root folder containing apps |
|
386 | 428 | { |
387 | 429 | // add root with current users apps |
388 | 430 | $this->add_home($files, $path, $user, $options['depth']); |
431 | + } |
|
389 | 432 | |
390 | 433 | if ($path == '/') |
391 | 434 | { |
@@ -417,16 +460,22 @@ discard block |
||
417 | 460 | } |
418 | 461 | if ($app != 'principals' && !isset($GLOBALS['egw_info']['user']['apps'][$this->root[$app]['app'] ? $this->root[$app]['app'] : $app])) |
419 | 462 | { |
420 | - if ($this->debug) error_log(__CLASS__."::$method(path=$options[path]) 403 Forbidden: no app rights for '$app'"); |
|
463 | + if ($this->debug) |
|
464 | + { |
|
465 | + error_log(__CLASS__."::$method(path=$options[path]) 403 Forbidden: no app rights for '$app'"); |
|
466 | + } |
|
421 | 467 | return "403 Forbidden: no app rights for '$app'"; // no rights for the given app |
422 | 468 | } |
423 | 469 | if (($handler = self::app_handler($app))) |
424 | 470 | { |
425 | - if ($method != 'REPORT' && !$id) // no self URL for REPORT requests (only PROPFIND) or propfinds on an id |
|
471 | + if ($method != 'REPORT' && !$id) |
|
472 | + { |
|
473 | + // no self URL for REPORT requests (only PROPFIND) or propfinds on an id |
|
426 | 474 | { |
427 | 475 | // KAddressbook doubles the folder, if the self URL contains the GroupDAV/CalDAV resourcetypes |
428 | 476 | $files['files'][0] = $this->add_app($app,$app=='addressbook'&&$handler->get_agent()=='kde',$user, |
429 | 477 | $this->_slashify($options['path'])); |
478 | + } |
|
430 | 479 | |
431 | 480 | // Hack for iOS 5.0.1 addressbook to stop asking directory gateway permissions with depth != 0 |
432 | 481 | // values for depth are 0, 1, "infinit" or not set which has to be interpreted as "infinit" |
@@ -436,7 +485,11 @@ discard block |
||
436 | 485 | $this->log(__CLASS__."::$method(".array2string($options).') Enabling hack for iOS 5.0.1 addressbook: force Depth: 0 on PROPFIND for directory gateway!'); |
437 | 486 | return true; |
438 | 487 | } |
439 | - if (!$options['depth']) return true; // depth 0 --> show only the self url |
|
488 | + if (!$options['depth']) |
|
489 | + { |
|
490 | + return true; |
|
491 | + } |
|
492 | + // depth 0 --> show only the self url |
|
440 | 493 | } |
441 | 494 | return $handler->propfind($this->_slashify($options['path']),$options,$files,$user,$id); |
442 | 495 | } |
@@ -457,7 +510,10 @@ discard block |
||
457 | 510 | // resourcetype: collection |
458 | 511 | $props['resourcetype'][] = self::mkprop('collection',''); |
459 | 512 | |
460 | - if (!isset($props['getcontenttype'])) $props['getcontenttype'] = 'httpd/unix-directory'; |
|
513 | + if (!isset($props['getcontenttype'])) |
|
514 | + { |
|
515 | + $props['getcontenttype'] = 'httpd/unix-directory'; |
|
516 | + } |
|
461 | 517 | |
462 | 518 | return $this->add_resource($path, $props, $privileges, $supported_privileges); |
463 | 519 | } |
@@ -489,11 +545,17 @@ discard block |
||
489 | 545 | 'resourcetype' => '', |
490 | 546 | ) as $name => $default) |
491 | 547 | { |
492 | - if (!isset($props[$name])) $props[$name] = $default; |
|
548 | + if (!isset($props[$name])) |
|
549 | + { |
|
550 | + $props[$name] = $default; |
|
551 | + } |
|
493 | 552 | } |
494 | 553 | |
495 | 554 | // if requested add privileges |
496 | - if (is_null($supported_privileges)) $supported_privileges = $this->supported_privileges; |
|
555 | + if (is_null($supported_privileges)) |
|
556 | + { |
|
557 | + $supported_privileges = $this->supported_privileges; |
|
558 | + } |
|
497 | 559 | if ($this->prop_requested('current-user-privilege-set') === true) |
498 | 560 | { |
499 | 561 | foreach($privileges as $name) |
@@ -514,7 +576,10 @@ discard block |
||
514 | 576 | $props['owner'] = ''; |
515 | 577 | } |
516 | 578 | |
517 | - if ($this->debug > 1) error_log(__METHOD__."(path='$path', props=".array2string($props).')'); |
|
579 | + if ($this->debug > 1) |
|
580 | + { |
|
581 | + error_log(__METHOD__."(path='$path', props=".array2string($props).')'); |
|
582 | + } |
|
518 | 583 | |
519 | 584 | // convert simple associative properties to HTTP_WebDAV_Server ones |
520 | 585 | foreach($props as $name => &$prop) |
@@ -554,7 +619,10 @@ discard block |
||
554 | 619 | { |
555 | 620 | foreach($data as $name => $data) |
556 | 621 | { |
557 | - if ($name[0] == '*') continue; |
|
622 | + if ($name[0] == '*') |
|
623 | + { |
|
624 | + continue; |
|
625 | + } |
|
558 | 626 | if (is_array($data) && $data['*only*'] && strpos($path, $data['*only*']) === false) |
559 | 627 | { |
560 | 628 | continue; // wrong path |
@@ -668,8 +736,15 @@ discard block |
||
668 | 736 | { |
669 | 737 | foreach($this->root as $app => $data) |
670 | 738 | { |
671 | - if (!$GLOBALS['egw_info']['user']['apps'][$data['app'] ? $data['app'] : $app]) continue; // no rights for the given app |
|
672 | - if (!empty($data['user-only']) && ($path == '/' || $user < 0)) continue; |
|
739 | + if (!$GLOBALS['egw_info']['user']['apps'][$data['app'] ? $data['app'] : $app]) |
|
740 | + { |
|
741 | + continue; |
|
742 | + } |
|
743 | + // no rights for the given app |
|
744 | + if (!empty($data['user-only']) && ($path == '/' || $user < 0)) |
|
745 | + { |
|
746 | + continue; |
|
747 | + } |
|
673 | 748 | |
674 | 749 | $files['files'][] = $this->add_app($app,false,$user,$path.$app.'/'); |
675 | 750 | |
@@ -705,7 +780,10 @@ discard block |
||
705 | 780 | { |
706 | 781 | if (!isset($GLOBALS['egw_info']['user']['apps']['resources'])) |
707 | 782 | { |
708 | - if ($this->debug) error_log(__METHOD__."(path=$path) 403 Forbidden: no app rights for 'resources'"); |
|
783 | + if ($this->debug) |
|
784 | + { |
|
785 | + error_log(__METHOD__."(path=$path) 403 Forbidden: no app rights for 'resources'"); |
|
786 | + } |
|
709 | 787 | return "403 Forbidden: no app rights for 'resources'"; // no rights for the given app |
710 | 788 | } |
711 | 789 | list(,$what) = explode('/', $path); |
@@ -744,10 +822,13 @@ discard block |
||
744 | 822 | { |
745 | 823 | // currently only show shared calendars/addressbooks for current user and not in the root |
746 | 824 | if ($path == '/' || $user != $GLOBALS['egw_info']['user']['account_id'] || |
747 | - !isset($GLOBALS['egw_info']['user']['apps'][$app])) // also avoids principals, inbox and outbox |
|
825 | + !isset($GLOBALS['egw_info']['user']['apps'][$app])) |
|
826 | + { |
|
827 | + // also avoids principals, inbox and outbox |
|
748 | 828 | { |
749 | 829 | return true; |
750 | 830 | } |
831 | + } |
|
751 | 832 | $handler = $this->app_handler($app); |
752 | 833 | if (($shared = $handler->get_shared())) |
753 | 834 | { |
@@ -755,7 +836,10 @@ discard block |
||
755 | 836 | { |
756 | 837 | $file = $this->add_app($app,false,$id,$path.$owner.'/'); |
757 | 838 | // mark other users calendar as shared (iOS 5.0.1 AB does NOT display AB marked as shared!) |
758 | - if ($app == 'calendar') $file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared',''); |
|
839 | + if ($app == 'calendar') |
|
840 | + { |
|
841 | + $file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared',''); |
|
842 | + } |
|
759 | 843 | $files[] = $file; |
760 | 844 | } |
761 | 845 | } |
@@ -791,7 +875,10 @@ discard block |
||
791 | 875 | { |
792 | 876 | $name = $this->accounts->id2name($account,'account_fullname'); |
793 | 877 | } |
794 | - if (empty($name)) $name = '#'.$account; |
|
878 | + if (empty($name)) |
|
879 | + { |
|
880 | + $name = '#'.$account; |
|
881 | + } |
|
795 | 882 | } |
796 | 883 | return $name; |
797 | 884 | } |
@@ -807,7 +894,10 @@ discard block |
||
807 | 894 | */ |
808 | 895 | protected function add_app($app,$no_extra_types=false,$user=null,$path='/') |
809 | 896 | { |
810 | - if ($this->debug) error_log(__METHOD__."(app='$app', no_extra_types=$no_extra_types, user='$user', path='$path')"); |
|
897 | + if ($this->debug) |
|
898 | + { |
|
899 | + error_log(__METHOD__."(app='$app', no_extra_types=$no_extra_types, user='$user', path='$path')"); |
|
900 | + } |
|
811 | 901 | $user_preferences = $GLOBALS['egw_info']['user']['preferences']; |
812 | 902 | if (is_string($user) && $user[0] == 'r' && ($resource = Principals::read_resource(substr($user, 1)))) |
813 | 903 | { |
@@ -831,7 +921,10 @@ discard block |
||
831 | 921 | $account_lid = $GLOBALS['egw_info']['user']['account_lid']; |
832 | 922 | $principalType = 'users'; |
833 | 923 | } |
834 | - if (!isset($displayname)) $displayname = $this->account_name($user); |
|
924 | + if (!isset($displayname)) |
|
925 | + { |
|
926 | + $displayname = $this->account_name($user); |
|
927 | + } |
|
835 | 928 | |
836 | 929 | $props = array( |
837 | 930 | 'owner' => array(self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/')), |
@@ -864,10 +957,13 @@ discard block |
||
864 | 957 | |
865 | 958 | // rfc 5995 (Use POST to add members to WebDAV collections): we use collection path with add-member query param |
866 | 959 | // leaving it switched off, until further testing, because OS X iCal seem to ignore it and OS X Addressbook uses POST to full URL without ?add-member |
867 | - if ($app && !in_array($app,array('inbox','outbox','principals'))) // not on inbox, outbox or principals |
|
960 | + if ($app && !in_array($app,array('inbox','outbox','principals'))) |
|
961 | + { |
|
962 | + // not on inbox, outbox or principals |
|
868 | 963 | { |
869 | 964 | $props['add-member'][] = self::mkprop('href',$this->base_uri.$path.'?add-member'); |
870 | 965 | } |
966 | + } |
|
871 | 967 | |
872 | 968 | // add props modifyable via proppatch from client, eg. calendar-color, see self::$proppatch_props |
873 | 969 | $ns = null; |
@@ -961,7 +1057,10 @@ discard block |
||
961 | 1057 | */ |
962 | 1058 | function REPORT(&$options, &$files) |
963 | 1059 | { |
964 | - if ($this->debug > 1) error_log(__METHOD__.'('.array2string($options).')'); |
|
1060 | + if ($this->debug > 1) |
|
1061 | + { |
|
1062 | + error_log(__METHOD__.'('.array2string($options).')'); |
|
1063 | + } |
|
965 | 1064 | |
966 | 1065 | return $this->PROPFIND($options,$files,'REPORT'); |
967 | 1066 | } |
@@ -984,7 +1083,10 @@ discard block |
||
984 | 1083 | */ |
985 | 1084 | function GET(&$options) |
986 | 1085 | { |
987 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
|
1086 | + if ($this->debug) |
|
1087 | + { |
|
1088 | + error_log(__METHOD__.'('.array2string($options).')'); |
|
1089 | + } |
|
988 | 1090 | |
989 | 1091 | $id = $app = $user = null; |
990 | 1092 | if (!$this->_parse_path($options['path'],$id,$app,$user) || $app == 'principals') |
@@ -1220,7 +1322,10 @@ discard block |
||
1220 | 1322 | $_GET['add-member'] = ''; // otherwise we give no Location header |
1221 | 1323 | return $this->PUT($options); |
1222 | 1324 | } |
1223 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
|
1325 | + if ($this->debug) |
|
1326 | + { |
|
1327 | + error_log(__METHOD__.'('.array2string($options).')'); |
|
1328 | + } |
|
1224 | 1329 | |
1225 | 1330 | $id = $app = $user = null; |
1226 | 1331 | $this->_parse_path($options['path'],$id,$app,$user); |
@@ -1391,7 +1496,11 @@ discard block |
||
1391 | 1496 | error_log(__METHOD__."('$app', $id, ...) no rights to update attachments"); |
1392 | 1497 | return; // no rights --> nothing to do |
1393 | 1498 | } |
1394 | - if (!is_array($attach)) $attach = array(); // could be PEAR_Error if not set |
|
1499 | + if (!is_array($attach)) |
|
1500 | + { |
|
1501 | + $attach = array(); |
|
1502 | + } |
|
1503 | + // could be PEAR_Error if not set |
|
1395 | 1504 | |
1396 | 1505 | if ($delete_via_put) |
1397 | 1506 | { |
@@ -1436,7 +1545,11 @@ discard block |
||
1436 | 1545 | // reuse valid managed-id --> symlink attachment |
1437 | 1546 | if (Vfs::file_exists($link)) |
1438 | 1547 | { |
1439 | - if (Vfs::readlink($link) === $path) continue; // no need to recreate identical link |
|
1548 | + if (Vfs::readlink($link) === $path) |
|
1549 | + { |
|
1550 | + continue; |
|
1551 | + } |
|
1552 | + // no need to recreate identical link |
|
1440 | 1553 | Vfs::unlink($link); // symlink will fail, if $link exists |
1441 | 1554 | } |
1442 | 1555 | if (!Vfs::symlink($path, $link)) |
@@ -1476,7 +1589,11 @@ discard block |
||
1476 | 1589 | { |
1477 | 1590 | $filename = empty($_filename) ? 'attachment' : Vfs::basename($_filename); |
1478 | 1591 | |
1479 | - if (strpos($mime, ';')) list($mime) = explode(';', $mime); // in case it contains eg. charset info |
|
1592 | + if (strpos($mime, ';')) |
|
1593 | + { |
|
1594 | + list($mime) = explode(';', $mime); |
|
1595 | + } |
|
1596 | + // in case it contains eg. charset info |
|
1480 | 1597 | |
1481 | 1598 | $ext = !empty($mime) ? MimeMagic::mime2ext($mime) : ''; |
1482 | 1599 | |
@@ -1495,9 +1612,15 @@ discard block |
||
1495 | 1612 | for($i = 1; $i < 100; ++$i) |
1496 | 1613 | { |
1497 | 1614 | $path = Link::vfs_path($app, $id, $filename.($i > 1 ? '-'.$i : '').$ext, true); |
1498 | - if (!Vfs::stat($path)) break; |
|
1615 | + if (!Vfs::stat($path)) |
|
1616 | + { |
|
1617 | + break; |
|
1618 | + } |
|
1619 | + } |
|
1620 | + if ($i >= 100) |
|
1621 | + { |
|
1622 | + return null; |
|
1499 | 1623 | } |
1500 | - if ($i >= 100) return null; |
|
1501 | 1624 | |
1502 | 1625 | if (!Vfs::file_exists($dir = Vfs::dirname($path)) && !Vfs::mkdir($dir, 0777, STREAM_MKDIR_RECURSIVE)) |
1503 | 1626 | { |
@@ -1546,7 +1669,11 @@ discard block |
||
1546 | 1669 | // handle symlinks --> return target size and mime-type |
1547 | 1670 | if (($target = Vfs::readlink($path))) |
1548 | 1671 | { |
1549 | - if (!($stat = Vfs::stat($target))) continue; // broken or inaccessible symlink |
|
1672 | + if (!($stat = Vfs::stat($target))) |
|
1673 | + { |
|
1674 | + continue; |
|
1675 | + } |
|
1676 | + // broken or inaccessible symlink |
|
1550 | 1677 | |
1551 | 1678 | // check if target is in /apps, probably reused MANAGED-ID --> return it |
1552 | 1679 | if (substr($target, 0, 6) == '/apps/') |
@@ -1638,14 +1765,20 @@ discard block |
||
1638 | 1765 | */ |
1639 | 1766 | function PROPPATCH(&$options) |
1640 | 1767 | { |
1641 | - if ($this->debug) error_log(__METHOD__."(".array2string($options).')'); |
|
1768 | + if ($this->debug) |
|
1769 | + { |
|
1770 | + error_log(__METHOD__."(".array2string($options).')'); |
|
1771 | + } |
|
1642 | 1772 | |
1643 | 1773 | // parse path in form [/account_lid]/app[/more] |
1644 | 1774 | $id = $app = $user = $user_prefix = null; |
1645 | 1775 | self::_parse_path($options['path'],$id,$app,$user,$user_prefix); // allways returns false if eg. !$id |
1646 | 1776 | if ($app == 'principals' || $id || $options['path'] == '/') |
1647 | 1777 | { |
1648 | - if ($this->debug > 1) error_log(__METHOD__.": user='$user', app='$app', id='$id': 404 not found!"); |
|
1778 | + if ($this->debug > 1) |
|
1779 | + { |
|
1780 | + error_log(__METHOD__.": user='$user', app='$app', id='$id': 404 not found!"); |
|
1781 | + } |
|
1649 | 1782 | foreach($options['props'] as &$prop) |
1650 | 1783 | { |
1651 | 1784 | $prop['status'] = '403 Forbidden'; |
@@ -1670,11 +1803,14 @@ discard block |
||
1670 | 1803 | self::$proppatch_props[$prop['name']] == $prop['ns'] ? '' : ':'.$prop['ns']); |
1671 | 1804 | } |
1672 | 1805 | //error_log("preferences['user']['$app']['$name']=".array2string($GLOBALS['egw_info']['user']['preferences'][$app][$name]).($GLOBALS['egw_info']['user']['preferences'][$app][$name] !== $prop['val'] ? ' !== ':' === ')."prop['val']=".array2string($prop['val'])); |
1673 | - if ($GLOBALS['egw_info']['user']['preferences'][$app][$name] !== $prop['val']) // nothing to change otherwise |
|
1806 | + if ($GLOBALS['egw_info']['user']['preferences'][$app][$name] !== $prop['val']) |
|
1807 | + { |
|
1808 | + // nothing to change otherwise |
|
1674 | 1809 | { |
1675 | 1810 | if (isset($prop['val'])) |
1676 | 1811 | { |
1677 | 1812 | $GLOBALS['egw']->preferences->add($app, $name, $prop['val']); |
1813 | + } |
|
1678 | 1814 | } |
1679 | 1815 | else |
1680 | 1816 | { |
@@ -1726,7 +1862,10 @@ discard block |
||
1726 | 1862 | } |
1727 | 1863 | } |
1728 | 1864 | |
1729 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
|
1865 | + if ($this->debug) |
|
1866 | + { |
|
1867 | + error_log(__METHOD__.'('.array2string($options).')'); |
|
1868 | + } |
|
1730 | 1869 | |
1731 | 1870 | $id = $app = $user = $prefix = null; |
1732 | 1871 | if (!$this->_parse_path($options['path'],$id,$app,$user,$prefix)) |
@@ -1738,7 +1877,10 @@ discard block |
||
1738 | 1877 | $status = $handler->put($options,$id,$user,$prefix); |
1739 | 1878 | |
1740 | 1879 | // set default stati: true --> 204 No Content, false --> should be already handled |
1741 | - if (is_bool($status)) $status = $status ? '204 No Content' : '400 Something went wrong'; |
|
1880 | + if (is_bool($status)) |
|
1881 | + { |
|
1882 | + $status = $status ? '204 No Content' : '400 Something went wrong'; |
|
1883 | + } |
|
1742 | 1884 | |
1743 | 1885 | // check/handle Prefer: return-representation |
1744 | 1886 | if ($status[0] === '2' || $status === true) |
@@ -1762,7 +1904,10 @@ discard block |
||
1762 | 1904 | */ |
1763 | 1905 | function DELETE($options) |
1764 | 1906 | { |
1765 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
|
1907 | + if ($this->debug) |
|
1908 | + { |
|
1909 | + error_log(__METHOD__.'('.array2string($options).')'); |
|
1910 | + } |
|
1766 | 1911 | |
1767 | 1912 | $id = $app = $user = null; |
1768 | 1913 | if (!$this->_parse_path($options['path'],$id,$app,$user)) |
@@ -1773,7 +1918,10 @@ discard block |
||
1773 | 1918 | { |
1774 | 1919 | $status = $handler->delete($options,$id); |
1775 | 1920 | // set default stati: true --> 204 No Content, false --> should be already handled |
1776 | - if (is_bool($status)) $status = $status ? '204 No Content' : '400 Something went wrong'; |
|
1921 | + if (is_bool($status)) |
|
1922 | + { |
|
1923 | + $status = $status ? '204 No Content' : '400 Something went wrong'; |
|
1924 | + } |
|
1777 | 1925 | return $status; |
1778 | 1926 | } |
1779 | 1927 | return '501 Not Implemented'; |
@@ -1787,7 +1935,10 @@ discard block |
||
1787 | 1935 | */ |
1788 | 1936 | function MKCOL($options) |
1789 | 1937 | { |
1790 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
|
1938 | + if ($this->debug) |
|
1939 | + { |
|
1940 | + error_log(__METHOD__.'('.array2string($options).')'); |
|
1941 | + } |
|
1791 | 1942 | |
1792 | 1943 | return '501 Not Implemented'; |
1793 | 1944 | } |
@@ -1800,7 +1951,10 @@ discard block |
||
1800 | 1951 | */ |
1801 | 1952 | function MOVE($options) |
1802 | 1953 | { |
1803 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).')'); |
|
1954 | + if ($this->debug) |
|
1955 | + { |
|
1956 | + error_log(__METHOD__.'('.array2string($options).')'); |
|
1957 | + } |
|
1804 | 1958 | |
1805 | 1959 | return '501 Not Implemented'; |
1806 | 1960 | } |
@@ -1813,7 +1967,10 @@ discard block |
||
1813 | 1967 | */ |
1814 | 1968 | function COPY($options, $del=false) |
1815 | 1969 | { |
1816 | - if ($this->debug) error_log('self::'.($del ? 'MOVE' : 'COPY').'('.array2string($options).')'); |
|
1970 | + if ($this->debug) |
|
1971 | + { |
|
1972 | + error_log('self::'.($del ? 'MOVE' : 'COPY').'('.array2string($options).')'); |
|
1973 | + } |
|
1817 | 1974 | |
1818 | 1975 | return '501 Not Implemented'; |
1819 | 1976 | } |
@@ -1830,7 +1987,10 @@ discard block |
||
1830 | 1987 | self::_parse_path($options['path'],$id,$app,$user); |
1831 | 1988 | $path = Vfs::app_entry_lock_path($app,$id); |
1832 | 1989 | |
1833 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$path"); |
|
1990 | + if ($this->debug) |
|
1991 | + { |
|
1992 | + error_log(__METHOD__.'('.array2string($options).") path=$path"); |
|
1993 | + } |
|
1834 | 1994 | |
1835 | 1995 | // get the app handler, to check if the user has edit access to the entry (required to make locks) |
1836 | 1996 | $handler = self::app_handler($app); |
@@ -1845,10 +2005,13 @@ discard block |
||
1845 | 2005 | // dont know why, but HTTP_WebDAV_Server passes the owner in D:href tags, which get's passed unchanged to checkLock/PROPFIND |
1846 | 2006 | // that's wrong according to the standard and cadaver does not show it on discover --> strip_tags removes eventual tags |
1847 | 2007 | if (($ret = Vfs::lock($path,$options['locktoken'],$options['timeout'],strip_tags($options['owner']), |
1848 | - $options['scope'],$options['type'],isset($options['update']),false)) && !isset($options['update'])) // false = no ACL check |
|
2008 | + $options['scope'],$options['type'],isset($options['update']),false)) && !isset($options['update'])) |
|
2009 | + { |
|
2010 | + // false = no ACL check |
|
1849 | 2011 | { |
1850 | 2012 | return $ret ? '200 OK' : '409 Conflict'; |
1851 | 2013 | } |
2014 | + } |
|
1852 | 2015 | return $ret; |
1853 | 2016 | } |
1854 | 2017 | |
@@ -1864,7 +2027,10 @@ discard block |
||
1864 | 2027 | self::_parse_path($options['path'],$id,$app,$user); |
1865 | 2028 | $path = Vfs::app_entry_lock_path($app,$id); |
1866 | 2029 | |
1867 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$path"); |
|
2030 | + if ($this->debug) |
|
2031 | + { |
|
2032 | + error_log(__METHOD__.'('.array2string($options).") path=$path"); |
|
2033 | + } |
|
1868 | 2034 | return Vfs::unlock($path,$options['token']) ? '204 No Content' : '409 Conflict'; |
1869 | 2035 | } |
1870 | 2036 | |
@@ -1893,7 +2059,10 @@ discard block |
||
1893 | 2059 | $id = $app = $user = null; |
1894 | 2060 | self::_parse_path($options['path'],$id,$app,$user); |
1895 | 2061 | |
1896 | - if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$options[path]"); |
|
2062 | + if ($this->debug) |
|
2063 | + { |
|
2064 | + error_log(__METHOD__.'('.array2string($options).") path=$options[path]"); |
|
2065 | + } |
|
1897 | 2066 | |
1898 | 2067 | $options['errors'] = array(); |
1899 | 2068 | switch ($app) |
@@ -1956,7 +2125,10 @@ discard block |
||
1956 | 2125 | $user = array_shift($parts); |
1957 | 2126 | } |
1958 | 2127 | |
1959 | - if (!isset($app)) $app = array_shift($parts); |
|
2128 | + if (!isset($app)) |
|
2129 | + { |
|
2130 | + $app = array_shift($parts); |
|
2131 | + } |
|
1960 | 2132 | |
1961 | 2133 | // /addressbook-accounts/ |
1962 | 2134 | if (!$account_id && $app == 'addressbook-accounts') |
@@ -2047,7 +2219,10 @@ discard block |
||
2047 | 2219 | } |
2048 | 2220 | parent::ServeRequest(); |
2049 | 2221 | |
2050 | - if (self::$request_starttime) self::log_request(); |
|
2222 | + if (self::$request_starttime) |
|
2223 | + { |
|
2224 | + self::log_request(); |
|
2225 | + } |
|
2051 | 2226 | } |
2052 | 2227 | |
2053 | 2228 | /** |
@@ -2103,11 +2278,23 @@ discard block |
||
2103 | 2278 | { |
2104 | 2279 | $content .= $line."\n"; |
2105 | 2280 | } |
2106 | - if (($c = ob_get_flush())) $content .= "\n"; |
|
2107 | - if (self::$log_level !== 'f' && strlen($c) > 1536) $c = substr($c,0,1536)."\n*** LOG TRUNKATED\n"; |
|
2281 | + if (($c = ob_get_flush())) |
|
2282 | + { |
|
2283 | + $content .= "\n"; |
|
2284 | + } |
|
2285 | + if (self::$log_level !== 'f' && strlen($c) > 1536) |
|
2286 | + { |
|
2287 | + $c = substr($c,0,1536)."\n*** LOG TRUNKATED\n"; |
|
2288 | + } |
|
2108 | 2289 | $content .= $c; |
2109 | - if ($extra) $content .= $extra; |
|
2110 | - if ($this->to_log) $content .= "\n### ".implode("\n### ", $this->to_log)."\n"; |
|
2290 | + if ($extra) |
|
2291 | + { |
|
2292 | + $content .= $extra; |
|
2293 | + } |
|
2294 | + if ($this->to_log) |
|
2295 | + { |
|
2296 | + $content .= "\n### ".implode("\n### ", $this->to_log)."\n"; |
|
2297 | + } |
|
2111 | 2298 | $content .= $this->_http_status[0] == '4' && substr($this->_http_status,0,3) != '412' || |
2112 | 2299 | $this->_http_status[0] == '5' ? '###' : '***'; // mark failed requests with ###, instead of *** |
2113 | 2300 | $content .= sprintf(' %s --> "%s" took %5.3f s',$_SERVER['REQUEST_METHOD'].($_SERVER['REQUEST_METHOD']=='REPORT'?' '.$this->propfind_options['root']['name']:'').' '.$_SERVER['PATH_INFO'],$this->_http_status,microtime(true)-self::$request_starttime)."\n\n"; |
@@ -2165,8 +2352,14 @@ discard block |
||
2165 | 2352 | */ |
2166 | 2353 | protected static function add_prop(\XMLWriter $xml, $props) |
2167 | 2354 | { |
2168 | - if (is_string($props)) $props = self::mkprop($props, ''); |
|
2169 | - if (isset($props['name'])) $props = array($props); |
|
2355 | + if (is_string($props)) |
|
2356 | + { |
|
2357 | + $props = self::mkprop($props, ''); |
|
2358 | + } |
|
2359 | + if (isset($props['name'])) |
|
2360 | + { |
|
2361 | + $props = array($props); |
|
2362 | + } |
|
2170 | 2363 | |
2171 | 2364 | foreach($props as $prop) |
2172 | 2365 | { |
@@ -2253,7 +2446,10 @@ discard block |
||
2253 | 2446 | */ |
2254 | 2447 | static function generate_uid($_appName, $_eventID) |
2255 | 2448 | { |
2256 | - if(empty($_appName) || empty($_eventID)) return false; |
|
2449 | + if(empty($_appName) || empty($_eventID)) |
|
2450 | + { |
|
2451 | + return false; |
|
2452 | + } |
|
2257 | 2453 | |
2258 | 2454 | return $_appName.'-'.$_eventID.'-'.$GLOBALS['egw_info']['server']['install_id']; |
2259 | 2455 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @param string $path |
153 | 153 | * @param array $filter |
154 | - * @param array|boolean $start false=return all or array(start,num) |
|
154 | + * @param integer[] $start false=return all or array(start,num) |
|
155 | 155 | * @param int &$total |
156 | 156 | * @return array with "files" array with values for keys path and props |
157 | 157 | */ |
@@ -193,7 +193,6 @@ discard block |
||
193 | 193 | * Read an entry |
194 | 194 | * |
195 | 195 | * @param string|int $id |
196 | - * @param string $path =null implementation can use it, used in call from _common_get_put_delete |
|
197 | 196 | * @return array|boolean array with entry, false if no read rights, null if $id does not exist |
198 | 197 | */ |
199 | 198 | abstract function read($id /*,$path=null*/); |
@@ -238,7 +237,7 @@ discard block |
||
238 | 237 | * Get the etag for an entry, can be reimplemented for other algorithm or field names |
239 | 238 | * |
240 | 239 | * @param array|int $entry array with event or cal_id |
241 | - * @return string|boolean string with etag or false |
|
240 | + * @return false|string string with etag or false |
|
242 | 241 | */ |
243 | 242 | function get_etag($entry) |
244 | 243 | { |
@@ -423,7 +422,7 @@ discard block |
||
423 | 422 | /** |
424 | 423 | * Identify know GroupDAV agents by HTTP_USER_AGENT header |
425 | 424 | * |
426 | - * @return string|boolean agent name or false |
|
425 | + * @return string|false agent name or false |
|
427 | 426 | */ |
428 | 427 | static function get_agent() |
429 | 428 | { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param int $user account_id |
145 | 145 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
146 | 146 | */ |
147 | - abstract function propfind($path,&$options,&$files,$user); |
|
147 | + abstract function propfind($path, &$options, &$files, $user); |
|
148 | 148 | |
149 | 149 | /** |
150 | 150 | * Propfind callback, if interator is used |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * @param int &$total |
156 | 156 | * @return array with "files" array with values for keys path and props |
157 | 157 | */ |
158 | - function &propfind_callback($path, array $filter,$start,&$total) |
|
158 | + function &propfind_callback($path, array $filter, $start, &$total) |
|
159 | 159 | { |
160 | - unset($path, $filter, $start, $total); // not used, but required by function signature |
|
160 | + unset($path, $filter, $start, $total); // not used, but required by function signature |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param int $user =null account_id |
169 | 169 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
170 | 170 | */ |
171 | - abstract function get(&$options,$id,$user=null); |
|
171 | + abstract function get(&$options, $id, $user = null); |
|
172 | 172 | |
173 | 173 | /** |
174 | 174 | * Handle get request for an applications entry |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param int $user =null account_id of owner, default null |
179 | 179 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
180 | 180 | */ |
181 | - abstract function put(&$options,$id,$user=null); |
|
181 | + abstract function put(&$options, $id, $user = null); |
|
182 | 182 | |
183 | 183 | /** |
184 | 184 | * Handle get request for an applications entry |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param int $id |
188 | 188 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
189 | 189 | */ |
190 | - abstract function delete(&$options,$id); |
|
190 | + abstract function delete(&$options, $id); |
|
191 | 191 | |
192 | 192 | /** |
193 | 193 | * Read an entry |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @param array|int $entry entry-array or id |
217 | 217 | * @return boolean null if entry does not exist, false if no access, true if access permitted |
218 | 218 | */ |
219 | - abstract function check_access($acl,$entry); |
|
219 | + abstract function check_access($acl, $entry); |
|
220 | 220 | |
221 | 221 | /** |
222 | 222 | * Add extra properties for collections |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | * @param int $user =null account_id of owner of collection |
228 | 228 | * @return array |
229 | 229 | */ |
230 | - public function extra_properties(array $props, $displayname, $base_uri=null, $user=null) |
|
230 | + public function extra_properties(array $props, $displayname, $base_uri = null, $user = null) |
|
231 | 231 | { |
232 | - unset($displayname, $base_uri, $user); // not used, but required by function signature |
|
232 | + unset($displayname, $base_uri, $user); // not used, but required by function signature |
|
233 | 233 | |
234 | 234 | return $props; |
235 | 235 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | static function etag2value($etag) |
264 | 264 | { |
265 | - list(,$val) = explode(':',$etag,2); |
|
265 | + list(,$val) = explode(':', $etag, 2); |
|
266 | 266 | |
267 | 267 | return $val; |
268 | 268 | } |
@@ -280,18 +280,18 @@ discard block |
||
280 | 280 | * @param boolean $ignore_if_match =false if true, ignore If-Match precondition |
281 | 281 | * @return array|string entry on success, string with http-error-code on failure, null for PUT on an unknown id |
282 | 282 | */ |
283 | - function _common_get_put_delete($method,&$options,&$id,&$return_no_access=false,$ignore_if_match=false) |
|
283 | + function _common_get_put_delete($method, &$options, &$id, &$return_no_access = false, $ignore_if_match = false) |
|
284 | 284 | { |
285 | - if (self::$path_extension) $id = basename($id,self::$path_extension); |
|
285 | + if (self::$path_extension) $id = basename($id, self::$path_extension); |
|
286 | 286 | |
287 | 287 | if ($this->app != 'principals' && !$GLOBALS['egw_info']['user']['apps'][$this->app]) |
288 | 288 | { |
289 | 289 | if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden: no app rights for '$this->app'"); |
290 | - return '403 Forbidden'; // no app rights |
|
290 | + return '403 Forbidden'; // no app rights |
|
291 | 291 | } |
292 | 292 | $extra_acl = $this->method2acl[$method]; |
293 | 293 | if ($id && !($entry = $this->read($id, $options['path'])) && ($method != 'PUT' || $entry === false) || |
294 | - ($extra_acl != Api\Acl::READ && $this->check_access($extra_acl,$entry) === false)) |
|
294 | + ($extra_acl != Api\Acl::READ && $this->check_access($extra_acl, $entry) === false)) |
|
295 | 295 | { |
296 | 296 | if ($return_no_access && !is_null($entry)) |
297 | 297 | { |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | } |
301 | 301 | else |
302 | 302 | { |
303 | - if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null')); |
|
303 | + if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry === false ? 'false' : 'null')); |
|
304 | 304 | return !is_null($entry) ? '403 Forbidden' : '404 Not Found'; |
305 | 305 | } |
306 | 306 | } |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | if ($if_none_match[0] == '"') $if_none_match = substr($if_none_match, 1, -1); |
331 | 331 | |
332 | 332 | // if an IF_NONE_MATCH is given, check if we need to send a new export, or the current one is still up-to-date |
333 | - if (in_array($method, array('GET','HEAD')) && $etag === $if_none_match) |
|
333 | + if (in_array($method, array('GET', 'HEAD')) && $etag === $if_none_match) |
|
334 | 334 | { |
335 | 335 | if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified"); |
336 | 336 | return '304 Not Modified'; |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @param int $user =null account_id |
356 | 356 | * @return string|boolean http status of get or null if no representation was requested |
357 | 357 | */ |
358 | - public function check_return_representation($options, $id, $user=null) |
|
358 | + public function check_return_representation($options, $id, $user = null) |
|
359 | 359 | { |
360 | 360 | //error_log(__METHOD__."(, $id, $user) start ".function_backtrace()); |
361 | 361 | if (isset($_SERVER['HTTP_PREFER']) && in_array('return=representation', preg_split('/, ?/', $_SERVER['HTTP_PREFER']))) |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function update_tags($entry) |
396 | 396 | { |
397 | - unset($entry); // not used, but required by function signature |
|
397 | + unset($entry); // not used, but required by function signature |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | { |
410 | 410 | static $handler_cache = array(); |
411 | 411 | |
412 | - if (!array_key_exists($app,$handler_cache)) |
|
412 | + if (!array_key_exists($app, $handler_cache)) |
|
413 | 413 | { |
414 | 414 | $class = $app.'_groupdav'; |
415 | 415 | if (!class_exists($class) && !class_exists($class = __NAMESPACE__.'\\'.ucfirst($app))) return null; |
@@ -427,36 +427,36 @@ discard block |
||
427 | 427 | */ |
428 | 428 | static function get_agent() |
429 | 429 | { |
430 | - static $agent=null; |
|
430 | + static $agent = null; |
|
431 | 431 | |
432 | 432 | if (is_null($agent)) |
433 | 433 | { |
434 | 434 | $agent = false; |
435 | 435 | // identify the agent (GroupDAV client) from the HTTP_USER_AGENT header |
436 | 436 | $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); |
437 | - foreach(array( |
|
438 | - 'carddav-sync' => 'carddav-sync', // dmfs.org CardDAV client for Android: CardDAV-Sync (Android) (like iOS/5.0.1 (9A405) dataaccessd/1.0) gzip |
|
439 | - 'iphone' => 'iphone', // Apple iPhone iCal |
|
440 | - 'davkit' => 'davkit', // Apple iCal 10.6 |
|
441 | - 'coredav' => 'coredav', // Apple iCal 10.7 |
|
442 | - 'calendarstore' => 'calendarstore', // Apple iCal 5.0.1 under OS X 10.7.2 |
|
443 | - 'calendaragent/' => 'calendaragent', // Apple iCal OS X 10.8*: Mac OS X/10.8.2 (12C54) CalendarAgent/55 |
|
444 | - 'dataaccess' => 'dataaccess', // Apple addressbook iPhone |
|
445 | - 'cfnetwork' => 'cfnetwork', // Apple Addressbook 10.6/7 |
|
446 | - 'addressbook/' => 'cfnetwork', // Apple Addressbook OS X 10.8*: Mac OS X/10.8.2 (12C54) AddressBook/1167 |
|
447 | - 'bionicmessage.net' => 'funambol', // funambol GroupDAV connector from bionicmessage.net |
|
448 | - 'zideone' => 'zideone', // zideone outlook plugin |
|
449 | - 'lightning' => 'lightning', // Lighting (incl. SOGo connector for addressbook) |
|
450 | - 'webkit' => 'webkit', // Webkit Browser (also reports KHTML!) |
|
451 | - 'akonadi' => 'akonadi', // new KDE PIM framework (also reports KHTML!) |
|
452 | - 'khtml' => 'kde', // KDE clients |
|
437 | + foreach (array( |
|
438 | + 'carddav-sync' => 'carddav-sync', // dmfs.org CardDAV client for Android: CardDAV-Sync (Android) (like iOS/5.0.1 (9A405) dataaccessd/1.0) gzip |
|
439 | + 'iphone' => 'iphone', // Apple iPhone iCal |
|
440 | + 'davkit' => 'davkit', // Apple iCal 10.6 |
|
441 | + 'coredav' => 'coredav', // Apple iCal 10.7 |
|
442 | + 'calendarstore' => 'calendarstore', // Apple iCal 5.0.1 under OS X 10.7.2 |
|
443 | + 'calendaragent/' => 'calendaragent', // Apple iCal OS X 10.8*: Mac OS X/10.8.2 (12C54) CalendarAgent/55 |
|
444 | + 'dataaccess' => 'dataaccess', // Apple addressbook iPhone |
|
445 | + 'cfnetwork' => 'cfnetwork', // Apple Addressbook 10.6/7 |
|
446 | + 'addressbook/' => 'cfnetwork', // Apple Addressbook OS X 10.8*: Mac OS X/10.8.2 (12C54) AddressBook/1167 |
|
447 | + 'bionicmessage.net' => 'funambol', // funambol GroupDAV connector from bionicmessage.net |
|
448 | + 'zideone' => 'zideone', // zideone outlook plugin |
|
449 | + 'lightning' => 'lightning', // Lighting (incl. SOGo connector for addressbook) |
|
450 | + 'webkit' => 'webkit', // Webkit Browser (also reports KHTML!) |
|
451 | + 'akonadi' => 'akonadi', // new KDE PIM framework (also reports KHTML!) |
|
452 | + 'khtml' => 'kde', // KDE clients |
|
453 | 453 | 'neon' => 'neon', |
454 | - 'ical4ol' => 'ical4ol', // iCal4OL client |
|
455 | - 'evolution' => 'evolution', // Evolution |
|
456 | - 'thunderbird' => 'thunderbird', // SOGo connector for addressbook, no Lightning installed |
|
454 | + 'ical4ol' => 'ical4ol', // iCal4OL client |
|
455 | + 'evolution' => 'evolution', // Evolution |
|
456 | + 'thunderbird' => 'thunderbird', // SOGo connector for addressbook, no Lightning installed |
|
457 | 457 | ) as $pattern => $name) |
458 | 458 | { |
459 | - if (strpos($user_agent,$pattern) !== false) |
|
459 | + if (strpos($user_agent, $pattern) !== false) |
|
460 | 460 | { |
461 | 461 | $agent = $name; |
462 | 462 | break; |
@@ -512,35 +512,35 @@ discard block |
||
512 | 512 | * @param int $user =null owner of the collection, default current user |
513 | 513 | * @return array with privileges |
514 | 514 | */ |
515 | - public function current_user_privileges($path, $user=null) |
|
515 | + public function current_user_privileges($path, $user = null) |
|
516 | 516 | { |
517 | - unset($path); // not used, but required by function signature |
|
517 | + unset($path); // not used, but required by function signature |
|
518 | 518 | |
519 | - static $grants=null; |
|
519 | + static $grants = null; |
|
520 | 520 | if (is_null($grants)) |
521 | 521 | { |
522 | 522 | $grants = $this->get_grants(); |
523 | 523 | } |
524 | 524 | $priviledes = array('read-current-user-privilege-set' => 'read-current-user-privilege-set'); |
525 | 525 | |
526 | - if (is_null($user) || $grants[$user] & Api\Acl::READ) |
|
526 | + if (is_null($user) || $grants[$user]&Api\Acl::READ) |
|
527 | 527 | { |
528 | 528 | $priviledes['read'] = 'read'; |
529 | 529 | // allows on all calendars/addressbooks to write properties, as we store them on a per-user basis |
530 | 530 | // and only allow to modify explicit named properties in CalDAV, CardDAV or Calendarserver name-space |
531 | 531 | $priviledes['write-properties'] = 'write-properties'; |
532 | 532 | } |
533 | - if (is_null($user) || $grants[$user] & Api\Acl::ADD) |
|
533 | + if (is_null($user) || $grants[$user]&Api\Acl::ADD) |
|
534 | 534 | { |
535 | - $priviledes['bind'] = 'bind'; // PUT for new resources |
|
535 | + $priviledes['bind'] = 'bind'; // PUT for new resources |
|
536 | 536 | } |
537 | - if (is_null($user) || $grants[$user] & Api\Acl::EDIT) |
|
537 | + if (is_null($user) || $grants[$user]&Api\Acl::EDIT) |
|
538 | 538 | { |
539 | - $priviledes['write-content'] = 'write-content'; // otherwise iOS calendar does not allow to add events |
|
539 | + $priviledes['write-content'] = 'write-content'; // otherwise iOS calendar does not allow to add events |
|
540 | 540 | } |
541 | - if (is_null($user) || $grants[$user] & Api\Acl::DELETE) |
|
541 | + if (is_null($user) || $grants[$user]&Api\Acl::DELETE) |
|
542 | 542 | { |
543 | - $priviledes['unbind'] = 'unbind'; // DELETE |
|
543 | + $priviledes['unbind'] = 'unbind'; // DELETE |
|
544 | 544 | } |
545 | 545 | // copy/move of existing resources might require write-properties, thought we do not support an explicit PROPATCH |
546 | 546 | //error_log(__METHOD__."('$path', ".array2string($user).') returning '.array2string($priviledes).' '.function_backtrace()); |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | * @param boolean $path_attr_is_name =true true: path_attr is ca(l|rd)dav_name, false: id (GroupDAV needs Location header) |
568 | 568 | * @param string $etag =null etag, to not calculate it again (if != null) |
569 | 569 | */ |
570 | - function put_response_headers($entry, $path, $retval, $path_attr_is_name=true, $etag=null) |
|
570 | + function put_response_headers($entry, $path, $retval, $path_attr_is_name = true, $etag = null) |
|
571 | 571 | { |
572 | 572 | //error_log(__METHOD__."(".array2string($entry).", '$path', ".array2string($retval).", path_attr_is_name=$path_attr_is_name, etag=".array2string($etag).")"); |
573 | 573 | // we should not return an etag here, as EGroupware never stores ical/vcard byte-by-byte |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | */ |
611 | 611 | static function get_settings($hook_data) |
612 | 612 | { |
613 | - unset($hook_data); // not used, but required by function signature |
|
613 | + unset($hook_data); // not used, but required by function signature |
|
614 | 614 | |
615 | 615 | return array(); |
616 | 616 | } |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | { |
631 | 631 | $props['getetag'] = $this->get_etag($entry); |
632 | 632 | } |
633 | - foreach(array( |
|
633 | + foreach (array( |
|
634 | 634 | 'getcontenttype' => 'text/calendar', |
635 | 635 | 'getlastmodified' => $entry['modified'], |
636 | 636 | 'displayname' => $entry['title'], |
@@ -668,17 +668,17 @@ discard block |
||
668 | 668 | * @param boolean $full_uri =true |
669 | 669 | * @return string eg. https://domain.com/egroupware/groupdav.php |
670 | 670 | */ |
671 | - public function base_uri($full_uri=true) |
|
671 | + public function base_uri($full_uri = true) |
|
672 | 672 | { |
673 | - static $uri=null; |
|
674 | - static $path=null; |
|
673 | + static $uri = null; |
|
674 | + static $path = null; |
|
675 | 675 | |
676 | 676 | if (!isset($uri)) |
677 | 677 | { |
678 | 678 | $uri = $path = $this->caldav->base_uri; |
679 | 679 | if ($uri[0] == '/') |
680 | 680 | { |
681 | - $uri = ($_SERVER["HTTPS"] === "on" ? "https:" : "http:") .'//' . $_SERVER['HTTP_HOST'] . $uri; |
|
681 | + $uri = ($_SERVER["HTTPS"] === "on" ? "https:" : "http:").'//'.$_SERVER['HTTP_HOST'].$uri; |
|
682 | 682 | } |
683 | 683 | else |
684 | 684 | { |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | * @param int $user parameter necessary to call getctag, if no $token specified |
703 | 703 | * @return string |
704 | 704 | */ |
705 | - public function get_sync_collection_token($path, $user=null, $more_results=null) |
|
705 | + public function get_sync_collection_token($path, $user = null, $more_results = null) |
|
706 | 706 | { |
707 | 707 | //error_log(__METHOD__."('$path', $user, more_results=$more_results) this->sync_collection_token=".$this->sync_collection_token); |
708 | 708 | if ($more_results) |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | '; |
717 | 717 | if ($this->caldav->crrnd) |
718 | 718 | { |
719 | - $error = str_replace(array('<D:', '</D:'), array('<', '</'), $error); |
|
719 | + $error = str_replace(array('<D:', '</D:'), array('<', '</'), $error); |
|
720 | 720 | } |
721 | 721 | echo $error; |
722 | 722 | } |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | * @param int $token =null modification time, default call getctag($path, $user) to fetch it |
740 | 740 | * @return string |
741 | 741 | */ |
742 | - public function get_sync_token($path, $user, $token=null) |
|
742 | + public function get_sync_token($path, $user, $token = null) |
|
743 | 743 | { |
744 | 744 | if (!isset($token)) $token = $this->getctag($path, $user); |
745 | 745 |
@@ -123,7 +123,10 @@ discard block |
||
123 | 123 | function __construct($app, Api\CalDAV $caldav) |
124 | 124 | { |
125 | 125 | $this->app = $app; |
126 | - if (!is_null($caldav->debug)) $this->debug = $caldav->debug; |
|
126 | + if (!is_null($caldav->debug)) |
|
127 | + { |
|
128 | + $this->debug = $caldav->debug; |
|
129 | + } |
|
127 | 130 | $this->base_uri = $caldav->base_uri; |
128 | 131 | $this->caldav = $caldav; |
129 | 132 | |
@@ -282,11 +285,17 @@ discard block |
||
282 | 285 | */ |
283 | 286 | function _common_get_put_delete($method,&$options,&$id,&$return_no_access=false,$ignore_if_match=false) |
284 | 287 | { |
285 | - if (self::$path_extension) $id = basename($id,self::$path_extension); |
|
288 | + if (self::$path_extension) |
|
289 | + { |
|
290 | + $id = basename($id,self::$path_extension); |
|
291 | + } |
|
286 | 292 | |
287 | 293 | if ($this->app != 'principals' && !$GLOBALS['egw_info']['user']['apps'][$this->app]) |
288 | 294 | { |
289 | - if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden: no app rights for '$this->app'"); |
|
295 | + if ($this->debug) |
|
296 | + { |
|
297 | + error_log(__METHOD__."($method,,$id) 403 Forbidden: no app rights for '$this->app'"); |
|
298 | + } |
|
290 | 299 | return '403 Forbidden'; // no app rights |
291 | 300 | } |
292 | 301 | $extra_acl = $this->method2acl[$method]; |
@@ -295,12 +304,18 @@ discard block |
||
295 | 304 | { |
296 | 305 | if ($return_no_access && !is_null($entry)) |
297 | 306 | { |
298 | - if ($this->debug) error_log(__METHOD__."($method,,$id,$return_no_access) \$entry=".array2string($entry).", \$return_no_access set to false"); |
|
307 | + if ($this->debug) |
|
308 | + { |
|
309 | + error_log(__METHOD__."($method,,$id,$return_no_access) \$entry=".array2string($entry).", \$return_no_access set to false"); |
|
310 | + } |
|
299 | 311 | $return_no_access = false; |
300 | 312 | } |
301 | 313 | else |
302 | 314 | { |
303 | - if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null')); |
|
315 | + if ($this->debug) |
|
316 | + { |
|
317 | + error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null')); |
|
318 | + } |
|
304 | 319 | return !is_null($entry) ? '403 Forbidden' : '404 Not Found'; |
305 | 320 | } |
306 | 321 | } |
@@ -313,11 +328,17 @@ discard block |
||
313 | 328 | { |
314 | 329 | $this->http_if_match = $_SERVER['HTTP_IF_MATCH']; |
315 | 330 | // strip of quotes around etag, if they exist, that way we allow etag with and without quotes |
316 | - if ($this->http_if_match[0] == '"') $this->http_if_match = substr($this->http_if_match, 1, -1); |
|
331 | + if ($this->http_if_match[0] == '"') |
|
332 | + { |
|
333 | + $this->http_if_match = substr($this->http_if_match, 1, -1); |
|
334 | + } |
|
317 | 335 | |
318 | 336 | if ($this->http_if_match !== $etag) |
319 | 337 | { |
320 | - if ($this->debug) error_log(__METHOD__."($method,path=$options[path],$id) HTTP_IF_MATCH='$_SERVER[HTTP_IF_MATCH]', etag='$etag': 412 Precondition failed".array2string($entry)); |
|
338 | + if ($this->debug) |
|
339 | + { |
|
340 | + error_log(__METHOD__."($method,path=$options[path],$id) HTTP_IF_MATCH='$_SERVER[HTTP_IF_MATCH]', etag='$etag': 412 Precondition failed".array2string($entry)); |
|
341 | + } |
|
321 | 342 | // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) |
322 | 343 | $this->check_return_representation($options, $id); |
323 | 344 | return '412 Precondition Failed'; |
@@ -327,17 +348,26 @@ discard block |
||
327 | 348 | { |
328 | 349 | $if_none_match = $_SERVER['HTTP_IF_NONE_MATCH']; |
329 | 350 | // strip of quotes around etag, if they exist, that way we allow etag with and without quotes |
330 | - if ($if_none_match[0] == '"') $if_none_match = substr($if_none_match, 1, -1); |
|
351 | + if ($if_none_match[0] == '"') |
|
352 | + { |
|
353 | + $if_none_match = substr($if_none_match, 1, -1); |
|
354 | + } |
|
331 | 355 | |
332 | 356 | // if an IF_NONE_MATCH is given, check if we need to send a new export, or the current one is still up-to-date |
333 | 357 | if (in_array($method, array('GET','HEAD')) && $etag === $if_none_match) |
334 | 358 | { |
335 | - if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified"); |
|
359 | + if ($this->debug) |
|
360 | + { |
|
361 | + error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified"); |
|
362 | + } |
|
336 | 363 | return '304 Not Modified'; |
337 | 364 | } |
338 | 365 | if ($method == 'PUT' && ($if_none_match == '*' || $if_none_match == $etag)) |
339 | 366 | { |
340 | - if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 412 Precondition failed"); |
|
367 | + if ($this->debug) |
|
368 | + { |
|
369 | + error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 412 Precondition failed"); |
|
370 | + } |
|
341 | 371 | // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) |
342 | 372 | $this->check_return_representation($options, $id); |
343 | 373 | return '412 Precondition Failed'; |
@@ -376,7 +406,10 @@ discard block |
||
376 | 406 | |
377 | 407 | if (($ret = $this->get($options, $id ? $id : $this->new_id, $user)) && !empty($options['data'])) |
378 | 408 | { |
379 | - if (!$this->caldav->use_compression()) header('Content-Length: '.$this->caldav->bytes($options['data'])); |
|
409 | + if (!$this->caldav->use_compression()) |
|
410 | + { |
|
411 | + header('Content-Length: '.$this->caldav->bytes($options['data'])); |
|
412 | + } |
|
380 | 413 | header('Content-Type: '.$options['mimetype']); |
381 | 414 | echo $options['data']; |
382 | 415 | } |
@@ -412,7 +445,10 @@ discard block |
||
412 | 445 | if (!array_key_exists($app,$handler_cache)) |
413 | 446 | { |
414 | 447 | $class = $app.'_groupdav'; |
415 | - if (!class_exists($class) && !class_exists($class = __NAMESPACE__.'\\'.ucfirst($app))) return null; |
|
448 | + if (!class_exists($class) && !class_exists($class = __NAMESPACE__.'\\'.ucfirst($app))) |
|
449 | + { |
|
450 | + return null; |
|
451 | + } |
|
416 | 452 | |
417 | 453 | $handler_cache[$app] = new $class($app, $groupdav); |
418 | 454 | } |
@@ -474,7 +510,10 @@ discard block |
||
474 | 510 | $matches = null; |
475 | 511 | if (preg_match('/address%20book\/([0-9.]+)/', $user_agent, $matches)) |
476 | 512 | { |
477 | - if ((int)$matches[1] < 868) $agent .= '_old'; |
|
513 | + if ((int)$matches[1] < 868) |
|
514 | + { |
|
515 | + $agent .= '_old'; |
|
516 | + } |
|
478 | 517 | } |
479 | 518 | break; |
480 | 519 | case 'kde': |
@@ -575,7 +614,10 @@ discard block |
||
575 | 614 | // --> as all clients dislike not getting an ETag for a PUT, we sending it again even not storing byte-by-byte |
576 | 615 | //if (get_class($this) == 'addressbook_groupdav' && in_array(self::get_agent(),array('thunderbird','lightning'))) |
577 | 616 | { |
578 | - if (is_null($etag)) $etag = $this->get_etag($entry); |
|
617 | + if (is_null($etag)) |
|
618 | + { |
|
619 | + $etag = $this->get_etag($entry); |
|
620 | + } |
|
579 | 621 | header('ETag: "'.$etag.'"'); |
580 | 622 | } |
581 | 623 | |
@@ -741,7 +783,10 @@ discard block |
||
741 | 783 | */ |
742 | 784 | public function get_sync_token($path, $user, $token=null) |
743 | 785 | { |
744 | - if (!isset($token)) $token = $this->getctag($path, $user); |
|
786 | + if (!isset($token)) |
|
787 | + { |
|
788 | + $token = $this->getctag($path, $user); |
|
789 | + } |
|
745 | 790 | |
746 | 791 | // never return current time, as more modifications might happen due to second granularity --> return 1sec less |
747 | 792 | if ($token >= (int)$GLOBALS['egw_info']['flags']['page_start_time']) |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @param array &$options |
257 | 257 | * @param array &$files |
258 | 258 | * @param int $user account_id |
259 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
259 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
260 | 260 | */ |
261 | 261 | function expand_property_report($path,&$options,&$files,$user) |
262 | 262 | { |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | * Check if resource is a location |
1192 | 1192 | * |
1193 | 1193 | * @param array|int $resource |
1194 | - * @return boolean |
|
1194 | + * @return null|boolean |
|
1195 | 1195 | */ |
1196 | 1196 | public static function resource_is_location($resource) |
1197 | 1197 | { |
@@ -1470,7 +1470,6 @@ discard block |
||
1470 | 1470 | * Get proxy-groups for given user $account: users or groups who GRANT proxy rights to $account |
1471 | 1471 | * |
1472 | 1472 | * @param int $account who is the proxy |
1473 | - * @param string|array $app_proxys =null applications for which proxys should be added |
|
1474 | 1473 | * @return array with href props |
1475 | 1474 | */ |
1476 | 1475 | protected function get_resource_proxy_groups($account) |
@@ -1608,8 +1607,6 @@ discard block |
||
1608 | 1607 | /** |
1609 | 1608 | * Do propfind of /principals/ |
1610 | 1609 | * |
1611 | - * @param string $name name of group or empty |
|
1612 | - * @param string $rest name of rest of path behind group-name |
|
1613 | 1610 | * @param array $options |
1614 | 1611 | * @return array|string array with files or HTTP error code |
1615 | 1612 | */ |
@@ -1640,7 +1637,7 @@ discard block |
||
1640 | 1637 | * @param array &$options |
1641 | 1638 | * @param int $id |
1642 | 1639 | * @param int $user =null account_id |
1643 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1640 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1644 | 1641 | */ |
1645 | 1642 | function get(&$options,$id,$user=null) |
1646 | 1643 | { |
@@ -1655,7 +1652,7 @@ discard block |
||
1655 | 1652 | * @param array &$options |
1656 | 1653 | * @param int $id |
1657 | 1654 | * @param int $user =null account_id of owner, default null |
1658 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1655 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1659 | 1656 | */ |
1660 | 1657 | function put(&$options,$id,$user=null) |
1661 | 1658 | { |
@@ -1669,7 +1666,7 @@ discard block |
||
1669 | 1666 | * |
1670 | 1667 | * @param array &$options |
1671 | 1668 | * @param int $id |
1672 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1669 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1673 | 1670 | */ |
1674 | 1671 | function delete(&$options,$id) |
1675 | 1672 | { |
@@ -1681,7 +1678,7 @@ discard block |
||
1681 | 1678 | /** |
1682 | 1679 | * Read an entry |
1683 | 1680 | * |
1684 | - * @param string|int $id |
|
1681 | + * @param integer $id |
|
1685 | 1682 | * @return array/boolean array with entry, false if no read rights, null if $id does not exist |
1686 | 1683 | */ |
1687 | 1684 | function read($id) |
@@ -1696,7 +1693,7 @@ discard block |
||
1696 | 1693 | * |
1697 | 1694 | * @param int $acl Api\Acl::READ, Api\Acl::EDIT or Api\Acl::DELETE |
1698 | 1695 | * @param array|int $entry entry-array or id |
1699 | - * @return boolean null if entry does not exist, false if no access, true if access permitted |
|
1696 | + * @return null|boolean null if entry does not exist, false if no access, true if access permitted |
|
1700 | 1697 | */ |
1701 | 1698 | function check_access($acl,$entry) |
1702 | 1699 | { |
@@ -1739,7 +1736,7 @@ discard block |
||
1739 | 1736 | * |
1740 | 1737 | * @param string $path path of collection |
1741 | 1738 | * @param int $user =null owner of the collection, default current user |
1742 | - * @return array with privileges |
|
1739 | + * @return string[] with privileges |
|
1743 | 1740 | */ |
1744 | 1741 | public function current_user_privileges($path, $user=null) |
1745 | 1742 | { |
@@ -89,19 +89,18 @@ discard block |
||
89 | 89 | * @param array $reports =null |
90 | 90 | * @return array Api\CalDAV::mkprop('supported-report-set', ...) |
91 | 91 | */ |
92 | - protected function supported_report_set($path, array $reports=null) |
|
92 | + protected function supported_report_set($path, array $reports = null) |
|
93 | 93 | { |
94 | - unset($path); // not used, but required by function signature |
|
94 | + unset($path); // not used, but required by function signature |
|
95 | 95 | |
96 | 96 | if (is_null($reports)) $reports = $this->supported_reports; |
97 | 97 | |
98 | 98 | $supported = array(); |
99 | - foreach($reports as $name => $data) |
|
99 | + foreach ($reports as $name => $data) |
|
100 | 100 | { |
101 | - $supported[$name] = Api\CalDAV::mkprop('supported-report',array( |
|
102 | - Api\CalDAV::mkprop('report',array( |
|
103 | - !$data['ns'] ? Api\CalDAV::mkprop($name, '') : |
|
104 | - Api\CalDAV::mkprop($data['ns'], $name, ''))))); |
|
101 | + $supported[$name] = Api\CalDAV::mkprop('supported-report', array( |
|
102 | + Api\CalDAV::mkprop('report', array( |
|
103 | + !$data['ns'] ? Api\CalDAV::mkprop($name, '') : Api\CalDAV::mkprop($data['ns'], $name, ''))))); |
|
105 | 104 | } |
106 | 105 | return $supported; |
107 | 106 | } |
@@ -115,7 +114,7 @@ discard block |
||
115 | 114 | * @param int $user account_id |
116 | 115 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
117 | 116 | */ |
118 | - function propfind($path,&$options,&$files,$user) |
|
117 | + function propfind($path, &$options, &$files, $user) |
|
119 | 118 | { |
120 | 119 | if (($report = isset($_GET['report']) ? $_GET['report'] : $options['root']['name']) && $report != 'propfind') |
121 | 120 | { |
@@ -127,7 +126,7 @@ discard block |
||
127 | 126 | $this->caldav->log(__METHOD__."('$path', ".array2string($options).",, $user) not implemented report, returning 501 Not Implemented"); |
128 | 127 | return '501 Not Implemented'; |
129 | 128 | } |
130 | - list(,,$type,$name,$rest) = explode('/',$path,5); |
|
129 | + list(,, $type, $name, $rest) = explode('/', $path, 5); |
|
131 | 130 | // /principals/users/$name/ |
132 | 131 | // /users/$name/calendar-proxy-read/ |
133 | 132 | // /users/$name/calendar-proxy-write/ |
@@ -136,19 +135,19 @@ discard block |
||
136 | 135 | // /locations/$resource/ |
137 | 136 | // /__uids__/$uid/.../ |
138 | 137 | |
139 | - switch($type) |
|
138 | + switch ($type) |
|
140 | 139 | { |
141 | 140 | case 'users': |
142 | - $files['files'] = $this->propfind_users($name,$rest,$options); |
|
141 | + $files['files'] = $this->propfind_users($name, $rest, $options); |
|
143 | 142 | break; |
144 | 143 | case 'groups': |
145 | - $files['files'] = $this->propfind_groups($name,$rest,$options); |
|
144 | + $files['files'] = $this->propfind_groups($name, $rest, $options); |
|
146 | 145 | break; |
147 | 146 | case 'resources': |
148 | - $files['files'] = $this->propfind_resources($name,$rest,$options,false); |
|
147 | + $files['files'] = $this->propfind_resources($name, $rest, $options, false); |
|
149 | 148 | break; |
150 | 149 | case 'locations': |
151 | - $files['files'] = $this->propfind_resources($name,$rest,$options,true); |
|
150 | + $files['files'] = $this->propfind_resources($name, $rest, $options, true); |
|
152 | 151 | break; |
153 | 152 | /*case '__uids__': |
154 | 153 | $files['files'] = $this->propfind_uids($name,$rest,$options); |
@@ -258,11 +257,11 @@ discard block |
||
258 | 257 | * @param int $user account_id |
259 | 258 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
260 | 259 | */ |
261 | - function expand_property_report($path,&$options,&$files,$user) |
|
260 | + function expand_property_report($path, &$options, &$files, $user) |
|
262 | 261 | { |
263 | 262 | //error_log(__METHOD__."('$path', ".array2string($options).",, $user)"); |
264 | 263 | $requested_props = $options['other']; |
265 | - while(($requested_prop = array_shift($requested_props))) |
|
264 | + while (($requested_prop = array_shift($requested_props))) |
|
266 | 265 | { |
267 | 266 | if ($requested_prop['name'] != 'property' || $requested_prop['depth'] != 1) continue; |
268 | 267 | |
@@ -270,11 +269,11 @@ discard block |
||
270 | 269 | $prop_name = $requested_prop['attrs']['name']; |
271 | 270 | $prop_path = $path; |
272 | 271 | // calendarserver has some special property-names for expansion |
273 | - switch($prop_name) |
|
272 | + switch ($prop_name) |
|
274 | 273 | { |
275 | 274 | case 'calendar-proxy-read-for': |
276 | 275 | case 'calendar-proxy-write-for': |
277 | - $prop_path = $path . substr($prop_name, 0, -4).'/'; |
|
276 | + $prop_path = $path.substr($prop_name, 0, -4).'/'; |
|
278 | 277 | $prop_name = 'group-member-set'; |
279 | 278 | $prop_ns = Api\CalDAV::DAV; |
280 | 279 | break; |
@@ -294,14 +293,14 @@ discard block |
||
294 | 293 | 'xmlns' => $prop_ns, |
295 | 294 | )); |
296 | 295 | $prop_files = array(); |
297 | - $this->caldav->options = $options; // also modify global variable |
|
296 | + $this->caldav->options = $options; // also modify global variable |
|
298 | 297 | if (empty($prop_name) || $this->propfind($prop_path, $options, $prop_files, $user) !== true) |
299 | 298 | { |
300 | 299 | $this->caldav->log('### NO expand-property report for '.$requested_prop['attrs']['name']); |
301 | 300 | continue; |
302 | 301 | } |
303 | 302 | // find prop to expand |
304 | - foreach($prop_files['files'][0]['props'] as $expand_prop) |
|
303 | + foreach ($prop_files['files'][0]['props'] as $expand_prop) |
|
305 | 304 | { |
306 | 305 | if ($expand_prop['name'] === $prop_name) break; |
307 | 306 | } |
@@ -315,7 +314,7 @@ discard block |
||
315 | 314 | // requested properties of each href are in depth=2 properties |
316 | 315 | // set them as regular propfind properties to $options['props'] |
317 | 316 | $options2 = array('props' => 'all'); |
318 | - while(($prop = array_shift($requested_props)) && $prop['depth'] >= 2) |
|
317 | + while (($prop = array_shift($requested_props)) && $prop['depth'] >= 2) |
|
319 | 318 | { |
320 | 319 | if ($prop['name'] == 'property' && $prop['depth'] == 2) |
321 | 320 | { |
@@ -331,10 +330,10 @@ discard block |
||
331 | 330 | } |
332 | 331 | // put back evtl. read top-level property |
333 | 332 | if ($prop && $prop['depth'] == 1) array_unshift($requested_props, $prop); |
334 | - $this->caldav->options = $options2; // also modify global variable |
|
333 | + $this->caldav->options = $options2; // also modify global variable |
|
335 | 334 | |
336 | 335 | // run regular profind to get requested 2.-level properties for each href |
337 | - foreach($expand_prop['val'] as $key => &$prop_val) |
|
336 | + foreach ($expand_prop['val'] as $key => &$prop_val) |
|
338 | 337 | { |
339 | 338 | list(,$expand_path) = explode($this->caldav->base_uri, $prop_val['val']); |
340 | 339 | //error_log(__METHOD__."('$path', ..., $user) calling propfind('$expand_path', ".array2string($options2).', '.array2string($prop_val).", $user)"); |
@@ -429,23 +428,23 @@ discard block |
||
429 | 428 | * @param int $user account_id |
430 | 429 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
431 | 430 | */ |
432 | - function principal_property_search_report($path,&$options,&$files,$user) |
|
431 | + function principal_property_search_report($path, &$options, &$files, $user) |
|
433 | 432 | { |
434 | 433 | //error_log(__METHOD__."('$path', ".array2string($options).",, $user)"); |
435 | 434 | |
436 | 435 | // cant find the test attribute to root principal-property-search element in WebDAV rfc, but iPhones use it ... |
437 | - $anyof = !empty($options['root']['attrs']['test']) && $options['root']['attrs']['test'] == 'anyof'; // "allof" (default) or "anyof" |
|
436 | + $anyof = !empty($options['root']['attrs']['test']) && $options['root']['attrs']['test'] == 'anyof'; // "allof" (default) or "anyof" |
|
438 | 437 | |
439 | 438 | // parse property-search prop(s) contained in $options['other'] |
440 | - foreach($options['other'] as $n => $prop) |
|
439 | + foreach ($options['other'] as $n => $prop) |
|
441 | 440 | { |
442 | - switch($prop['name']) |
|
441 | + switch ($prop['name']) |
|
443 | 442 | { |
444 | 443 | case 'apply-to-principal-collection-set': // optinal prop to apply search on principal-collection-set == '/principals/' |
445 | 444 | $path = '/principals/'; |
446 | 445 | break; |
447 | 446 | case 'property-search': |
448 | - $property_search = $n; // should be 1 |
|
447 | + $property_search = $n; // should be 1 |
|
449 | 448 | break; |
450 | 449 | case 'prop': |
451 | 450 | if (isset($property_search)) |
@@ -475,7 +474,7 @@ discard block |
||
475 | 474 | return '400 Bad Request'; |
476 | 475 | } |
477 | 476 | // make sure search property is included in toplevel props (can be missing and defaults to property-search/prop's) |
478 | - foreach($search_props as $prop) |
|
477 | + foreach ($search_props as $prop) |
|
479 | 478 | { |
480 | 479 | if (!$this->caldav->prop_requested($prop['name'], $prop['xmlns'])) |
481 | 480 | { |
@@ -488,7 +487,7 @@ discard block |
||
488 | 487 | // but interprets returning all principals (all have a matching calendar-home-set) as NOT supporting CalDAV scheduling |
489 | 488 | // --> search only current user's principal |
490 | 489 | if ($prop['name'] == 'calendar-home-set' && stripos($_SERVER['HTTP_USER_AGENT'], 'Lightning') !== false && |
491 | - substr($search_props[0]['match'],-13) == '/groupdav.php') |
|
490 | + substr($search_props[0]['match'], -13) == '/groupdav.php') |
|
492 | 491 | { |
493 | 492 | $path = '/principals/users/'.$GLOBALS['egw_info']['user']['account_lid'].'/'; |
494 | 493 | $this->caldav->log('Enabling hack for Lightning prior 1.1.1 for searching calendar-home-set matching "/groupdav.php": limiting search to '.$path); |
@@ -497,7 +496,7 @@ discard block |
||
497 | 496 | // check type attribute to limit search on a certain tree |
498 | 497 | if (isset($options['root']['attrs']['type'])) |
499 | 498 | { |
500 | - switch($options['root']['attrs']['type']) |
|
499 | + switch ($options['root']['attrs']['type']) |
|
501 | 500 | { |
502 | 501 | case 'INDIVIDUAL': |
503 | 502 | $path = '/principals/users/'; |
@@ -524,7 +523,7 @@ discard block |
||
524 | 523 | return $ret; |
525 | 524 | } |
526 | 525 | // now filter out not matching "files" |
527 | - foreach($files['files'] as $n => $resource) |
|
526 | + foreach ($files['files'] as $n => $resource) |
|
528 | 527 | { |
529 | 528 | if (count(explode('/', $resource['path'])) < 5) // hack to only return principals, not the collections itself |
530 | 529 | { |
@@ -533,18 +532,18 @@ discard block |
||
533 | 532 | } |
534 | 533 | // match with $search_props |
535 | 534 | $matches = 0; |
536 | - foreach($search_props as $search_prop) |
|
535 | + foreach ($search_props as $search_prop) |
|
537 | 536 | { |
538 | 537 | // search resource for $search_prop |
539 | - foreach($resource['props'] as $prop) |
|
538 | + foreach ($resource['props'] as $prop) |
|
540 | 539 | { |
541 | 540 | if ($prop['name'] === $search_prop['name']) break; |
542 | 541 | } |
543 | 542 | if ($prop['name'] === $search_prop['name']) // search_prop NOT found |
544 | 543 | { |
545 | - foreach((array)$prop['val'] as $value) |
|
544 | + foreach ((array)$prop['val'] as $value) |
|
546 | 545 | { |
547 | - if (is_array($value)) $value = $value['val']; // eg. href prop |
|
546 | + if (is_array($value)) $value = $value['val']; // eg. href prop |
|
548 | 547 | if (self::match($value, $search_prop['match'], $search_prop['match-type']) !== false) // prop does match |
549 | 548 | { |
550 | 549 | ++$matches; |
@@ -556,7 +555,7 @@ discard block |
||
556 | 555 | if ($anyof && $matches || $matches == count($search_props)) |
557 | 556 | { |
558 | 557 | //error_log("$resource[path]: anyof=$anyof, $matches matches --> keep"); |
559 | - continue 2; // enough matches --> keep |
|
558 | + continue 2; // enough matches --> keep |
|
560 | 559 | } |
561 | 560 | } |
562 | 561 | //error_log("$resource[path]: anyof=$anyof, $matches matches --> skip"); |
@@ -574,9 +573,9 @@ discard block |
||
574 | 573 | * @param string $match criteria/sub-string |
575 | 574 | * @param string $match_type ='contains' 'starts-with', 'ends-with' or 'equals' |
576 | 575 | */ |
577 | - private static function match($value, $match, $match_type='contains') |
|
576 | + private static function match($value, $match, $match_type = 'contains') |
|
578 | 577 | { |
579 | - switch($match_type) |
|
578 | + switch ($match_type) |
|
580 | 579 | { |
581 | 580 | case 'equals': |
582 | 581 | return $value === $match; |
@@ -646,9 +645,9 @@ discard block |
||
646 | 645 | * @param int $user account_id |
647 | 646 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
648 | 647 | */ |
649 | - function principal_search_property_set_report($path,&$options,&$files,$user) |
|
648 | + function principal_search_property_set_report($path, &$options, &$files, $user) |
|
650 | 649 | { |
651 | - unset($path, $options, $files, $user); // not used, but required by function signature |
|
650 | + unset($path, $options, $files, $user); // not used, but required by function signature |
|
652 | 651 | |
653 | 652 | static $search_props = array( |
654 | 653 | // from iOS iCal |
@@ -670,7 +669,7 @@ discard block |
||
670 | 669 | $xml->startDocument('1.0', 'UTF-8'); |
671 | 670 | $xml->startElementNs(null, 'principal-search-property-set', 'DAV:'); |
672 | 671 | |
673 | - foreach($search_props as $name => $data) |
|
672 | + foreach ($search_props as $name => $data) |
|
674 | 673 | { |
675 | 674 | $xml->startElement('principal-search-property'); |
676 | 675 | $xml->startElement('prop'); |
@@ -682,16 +681,16 @@ discard block |
||
682 | 681 | { |
683 | 682 | $xml->writeElement($name); |
684 | 683 | } |
685 | - $xml->endElement(); // prop |
|
684 | + $xml->endElement(); // prop |
|
686 | 685 | |
687 | 686 | $xml->startElement('description'); |
688 | 687 | $xml->writeAttribute('xml:lang', 'en'); |
689 | 688 | $xml->text(is_array($data) ? $data['description'] : $data); |
690 | - $xml->endElement(); // description |
|
689 | + $xml->endElement(); // description |
|
691 | 690 | |
692 | - $xml->endElement(); // principal-search-property |
|
691 | + $xml->endElement(); // principal-search-property |
|
693 | 692 | } |
694 | - $xml->endElement(); // principal-search-property-set |
|
693 | + $xml->endElement(); // principal-search-property-set |
|
695 | 694 | $xml->endDocument(); |
696 | 695 | echo $xml->outputMemory(); |
697 | 696 | |
@@ -726,7 +725,7 @@ discard block |
||
726 | 725 | * @param int $user account_id |
727 | 726 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
728 | 727 | */ |
729 | - function acl_principal_prop_set_report($path,&$options,&$files,$user) |
|
728 | + function acl_principal_prop_set_report($path, &$options, &$files, $user) |
|
730 | 729 | { |
731 | 730 | //error_log(__METHOD__."('$path', ".array2string($options).",, $user)"); |
732 | 731 | |
@@ -745,13 +744,13 @@ discard block |
||
745 | 744 | return $ret; |
746 | 745 | } |
747 | 746 | // now filter out not matching "files" |
748 | - foreach($files['files'] as $n => $resource) |
|
747 | + foreach ($files['files'] as $n => $resource) |
|
749 | 748 | { |
750 | - foreach($resource['props']['resourcetype']['val'] as $prop) |
|
749 | + foreach ($resource['props']['resourcetype']['val'] as $prop) |
|
751 | 750 | { |
752 | 751 | if ($prop['name'] == 'principal') continue 2; |
753 | 752 | } |
754 | - unset($files['files'][$n]); // not a principal --> do not return |
|
753 | + unset($files['files'][$n]); // not a principal --> do not return |
|
755 | 754 | } |
756 | 755 | // we should not return it |
757 | 756 | unset($options['props']['resourcetype']); |
@@ -767,7 +766,7 @@ discard block |
||
767 | 766 | * @param array $options |
768 | 767 | * @return array|string array with files or HTTP error code |
769 | 768 | */ |
770 | - protected function propfind_users($name,$rest,array $options) |
|
769 | + protected function propfind_users($name, $rest, array $options) |
|
771 | 770 | { |
772 | 771 | //error_log(__METHOD__."($name,$rest,".array2string($options).')'); |
773 | 772 | if (empty($name)) |
@@ -786,7 +785,7 @@ discard block |
||
786 | 785 | else |
787 | 786 | { |
788 | 787 | // add all users (account_selection == groupmembers is handled by accounts->search()) |
789 | - foreach($this->accounts->search(array('type' => 'accounts','order' => 'account_lid')) as $account) |
|
788 | + foreach ($this->accounts->search(array('type' => 'accounts', 'order' => 'account_lid')) as $account) |
|
790 | 789 | { |
791 | 790 | $files[] = $this->add_account($account); |
792 | 791 | } |
@@ -795,18 +794,18 @@ discard block |
||
795 | 794 | } |
796 | 795 | else |
797 | 796 | { |
798 | - if (!($id = $this->accounts->name2id($name,'account_lid','u')) || |
|
797 | + if (!($id = $this->accounts->name2id($name, 'account_lid', 'u')) || |
|
799 | 798 | !($account = $this->accounts->read($id)) || |
800 | 799 | !$this->accounts->visible($name)) |
801 | 800 | { |
802 | 801 | $this->caldav->log(__METHOD__."('$name', ...) account '$name' NOT found OR not visible to you (check account-selection preference)!"); |
803 | 802 | return '404 Not Found'; |
804 | 803 | } |
805 | - while (substr($rest,-1) == '/') |
|
804 | + while (substr($rest, -1) == '/') |
|
806 | 805 | { |
807 | - $rest = substr($rest,0,-1); |
|
806 | + $rest = substr($rest, 0, -1); |
|
808 | 807 | } |
809 | - switch((string)$rest) |
|
808 | + switch ((string)$rest) |
|
810 | 809 | { |
811 | 810 | case '': |
812 | 811 | $files[] = $this->add_account($account); |
@@ -836,7 +835,7 @@ discard block |
||
836 | 835 | * @param array $options |
837 | 836 | * @return array|string array with files or HTTP error code |
838 | 837 | */ |
839 | - protected function propfind_groups($name,$rest,array $options) |
|
838 | + protected function propfind_groups($name, $rest, array $options) |
|
840 | 839 | { |
841 | 840 | //echo "<p>".__METHOD__."($name,$rest,".array2string($options).")</p>\n"; |
842 | 841 | if (empty($name)) |
@@ -848,11 +847,11 @@ discard block |
||
848 | 847 | if ($options['depth']) |
849 | 848 | { |
850 | 849 | // only show own groups, if account-selection is groupmembers or none |
851 | - $type = in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers','none')) ? |
|
850 | + $type = in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers', 'none')) ? |
|
852 | 851 | 'owngroups' : 'groups'; |
853 | 852 | |
854 | 853 | // add all groups or only membergroups |
855 | - foreach($this->accounts->search(array('type' => $type,'order' => 'account_lid')) as $account) |
|
854 | + foreach ($this->accounts->search(array('type' => $type, 'order' => 'account_lid')) as $account) |
|
856 | 855 | { |
857 | 856 | $files[] = $this->add_group($account); |
858 | 857 | } |
@@ -860,19 +859,19 @@ discard block |
||
860 | 859 | } |
861 | 860 | else |
862 | 861 | { |
863 | - if (!($id = $this->accounts->name2id($name,'account_lid','g')) || |
|
862 | + if (!($id = $this->accounts->name2id($name, 'account_lid', 'g')) || |
|
864 | 863 | !($account = $this->accounts->read($id)) || |
865 | 864 | // do NOT allow other groups, if account-selection is groupmembers or none |
866 | - in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers','none')) && |
|
867 | - !in_array($account['account_id'], $this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true))) |
|
865 | + in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers', 'none')) && |
|
866 | + !in_array($account['account_id'], $this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true))) |
|
868 | 867 | { |
869 | 868 | return '404 Not Found'; |
870 | 869 | } |
871 | - while (substr($rest,-1) == '/') |
|
870 | + while (substr($rest, -1) == '/') |
|
872 | 871 | { |
873 | - $rest = substr($rest,0,-1); |
|
872 | + $rest = substr($rest, 0, -1); |
|
874 | 873 | } |
875 | - switch((string)$rest) |
|
874 | + switch ((string)$rest) |
|
876 | 875 | { |
877 | 876 | case '': |
878 | 877 | $files[] = $this->add_group($account); |
@@ -903,10 +902,10 @@ discard block |
||
903 | 902 | { |
904 | 903 | $addressbooks = array(); |
905 | 904 | $ab_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set']; |
906 | - if (empty($ab_home_set)) $ab_home_set = 'P'; // personal addressbook |
|
905 | + if (empty($ab_home_set)) $ab_home_set = 'P'; // personal addressbook |
|
907 | 906 | $addressbook_home_set = explode(',', $ab_home_set); |
908 | 907 | // replace symbolic id's with real nummeric id's |
909 | - foreach(array( |
|
908 | + foreach (array( |
|
910 | 909 | 'P' => $GLOBALS['egw_info']['user']['account_id'], |
911 | 910 | 'G' => $GLOBALS['egw_info']['user']['account_primary_group'], |
912 | 911 | 'U' => '0', |
@@ -917,13 +916,13 @@ discard block |
||
917 | 916 | $addressbook_home_set[$key] = $id; |
918 | 917 | } |
919 | 918 | } |
920 | - if (in_array('O',$addressbook_home_set)) // "all in one" from groupdav.php/addressbook/ |
|
919 | + if (in_array('O', $addressbook_home_set)) // "all in one" from groupdav.php/addressbook/ |
|
921 | 920 | { |
922 | 921 | $addressbooks[] = '/'; |
923 | 922 | } |
924 | - foreach(array_keys($GLOBALS['egw']->contacts->get_addressbooks(Api\Acl::READ)) as $id) |
|
923 | + foreach (array_keys($GLOBALS['egw']->contacts->get_addressbooks(Api\Acl::READ)) as $id) |
|
925 | 924 | { |
926 | - if ((in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) && |
|
925 | + if ((in_array('A', $addressbook_home_set) || in_array((string)$id, $addressbook_home_set)) && |
|
927 | 926 | is_numeric($id) && ($owner = $this->accounts->id2name($id))) |
928 | 927 | { |
929 | 928 | $addressbooks[] = '/'.$owner.'/'; |
@@ -947,45 +946,45 @@ discard block |
||
947 | 946 | $calendars[] = Api\CalDAV::mkprop('href', |
948 | 947 | $this->base_uri.'/'.$account['account_lid'].'/'); |
949 | 948 | |
950 | - $displayname = Api\Translation::convert($account['account_fullname'], Api\Translation::charset(),'utf-8'); |
|
949 | + $displayname = Api\Translation::convert($account['account_fullname'], Api\Translation::charset(), 'utf-8'); |
|
951 | 950 | |
952 | 951 | return $this->add_principal('users/'.$account['account_lid'], array( |
953 | 952 | 'getetag' => $this->get_etag($account), |
954 | 953 | 'displayname' => $displayname, |
955 | 954 | // CalDAV |
956 | - 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-home-set',$calendars), |
|
955 | + 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-home-set', $calendars), |
|
957 | 956 | // CalDAV scheduling |
958 | - 'schedule-outbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'schedule-outbox-URL',array( |
|
959 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/outbox/'))), |
|
960 | - 'schedule-inbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'schedule-inbox-URL',array( |
|
961 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/inbox/'))), |
|
962 | - 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-address-set',array( |
|
963 | - Api\CalDAV::mkprop('href','mailto:'.$account['account_email']), |
|
964 | - Api\CalDAV::mkprop('href',$this->base_uri(true).'/principals/users/'.$account['account_lid'].'/'), |
|
965 | - Api\CalDAV::mkprop('href',$this->base_uri(false).'/principals/users/'.$account['account_lid'].'/'), |
|
966 | - Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
957 | + 'schedule-outbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'schedule-outbox-URL', array( |
|
958 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/outbox/'))), |
|
959 | + 'schedule-inbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'schedule-inbox-URL', array( |
|
960 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/inbox/'))), |
|
961 | + 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-address-set', array( |
|
962 | + Api\CalDAV::mkprop('href', 'mailto:'.$account['account_email']), |
|
963 | + Api\CalDAV::mkprop('href', $this->base_uri(true).'/principals/users/'.$account['account_lid'].'/'), |
|
964 | + Api\CalDAV::mkprop('href', $this->base_uri(false).'/principals/users/'.$account['account_lid'].'/'), |
|
965 | + Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
967 | 966 | )), |
968 | - 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-type','INDIVIDUAL'), |
|
967 | + 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-type', 'INDIVIDUAL'), |
|
969 | 968 | // Calendarserver |
970 | - 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'email-address-set',array( |
|
971 | - Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'email-address',$account['account_email']))), |
|
972 | - 'last-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'last-name',$account['account_lastname']), |
|
973 | - 'first-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'first-name',$account['account_firstname']), |
|
974 | - 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'record-type','users'), |
|
969 | + 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'email-address-set', array( |
|
970 | + Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'email-address', $account['account_email']))), |
|
971 | + 'last-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'last-name', $account['account_lastname']), |
|
972 | + 'first-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'first-name', $account['account_firstname']), |
|
973 | + 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'record-type', 'users'), |
|
975 | 974 | // WebDAV ACL and CalDAV proxy |
976 | 975 | 'group-membership' => $this->principal_set('group-membership', $this->accounts->memberships($account['account_id']), |
977 | - array('calendar', 'resources'), $account['account_id']), // add proxy-rights |
|
976 | + array('calendar', 'resources'), $account['account_id']), // add proxy-rights |
|
978 | 977 | 'alternate-URI-set' => array( |
979 | - Api\CalDAV::mkprop('href','mailto:'.$account['account_email'])), |
|
978 | + Api\CalDAV::mkprop('href', 'mailto:'.$account['account_email'])), |
|
980 | 979 | // CardDAV |
981 | - 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV,'addressbook-home-set',$addressbooks), |
|
982 | - 'principal-address' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV,'principal-address', |
|
980 | + 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'addressbook-home-set', $addressbooks), |
|
981 | + 'principal-address' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'principal-address', |
|
983 | 982 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] ? '' : array( |
984 | - Api\CalDAV::mkprop('href',$this->base_uri.'/addressbook-accounts/'.$account['person_id'].'.vcf'))), |
|
983 | + Api\CalDAV::mkprop('href', $this->base_uri.'/addressbook-accounts/'.$account['person_id'].'.vcf'))), |
|
985 | 984 | // CardDAV directory |
986 | - 'directory-gateway' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'directory-gateway',array( |
|
985 | + 'directory-gateway' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'directory-gateway', array( |
|
987 | 986 | Api\CalDAV::mkprop('href', $this->base_uri.'/addressbook/'))), |
988 | - 'resource-id' => array(Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
987 | + 'resource-id' => array(Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
989 | 988 | )); |
990 | 989 | } |
991 | 990 | |
@@ -997,7 +996,7 @@ discard block |
||
997 | 996 | * @param string $cn =null common name to be stored in case of an "e" uid |
998 | 997 | * @return int|string|boolean integer account_id, string calendar uid or false if not a supported uid |
999 | 998 | */ |
1000 | - static public function url2uid($url, $only_type=null, $cn=null) |
|
999 | + static public function url2uid($url, $only_type = null, $cn = null) |
|
1001 | 1000 | { |
1002 | 1001 | if (!$only_type) $only_type = array('users', 'groups', 'resources', 'locations', 'mailto'); |
1003 | 1002 | |
@@ -1011,17 +1010,17 @@ discard block |
||
1011 | 1010 | } |
1012 | 1011 | if (empty($rest)) return false; |
1013 | 1012 | |
1014 | - switch(strtolower($schema)) |
|
1013 | + switch (strtolower($schema)) |
|
1015 | 1014 | { |
1016 | 1015 | case 'http': |
1017 | 1016 | case 'https': |
1018 | 1017 | list(,$rest) = explode('/groupdav.php/principals/', $url); |
1019 | 1018 | list($type, $name) = explode('/', $rest); |
1020 | - switch($type) |
|
1019 | + switch ($type) |
|
1021 | 1020 | { |
1022 | 1021 | case 'users': |
1023 | 1022 | case 'groups': |
1024 | - $uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid', $type[0]); // u=users, g=groups |
|
1023 | + $uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid', $type[0]); // u=users, g=groups |
|
1025 | 1024 | break; |
1026 | 1025 | case 'resources': |
1027 | 1026 | case 'locations': |
@@ -1038,9 +1037,9 @@ discard block |
||
1038 | 1037 | } |
1039 | 1038 | // search contacts for email |
1040 | 1039 | if ((list($data) = $GLOBALS['egw']->contacts->search(array('email' => $rest, 'email_home' => $rest), |
1041 | - array('id','egw_addressbook.account_id as account_id','n_fn'), |
|
1040 | + array('id', 'egw_addressbook.account_id as account_id', 'n_fn'), |
|
1042 | 1041 | 'egw_addressbook.account_id IS NOT NULL DESC, n_fn IS NOT NULL DESC', |
1043 | - '','',false,'OR'))) |
|
1042 | + '', '', false, 'OR'))) |
|
1044 | 1043 | { |
1045 | 1044 | // found an addressbook entry |
1046 | 1045 | $uid = $data['account_id'] ? (int)$data['account_id'] : 'c'.$data['id']; |
@@ -1058,7 +1057,7 @@ discard block |
||
1058 | 1057 | list($type, $id, $install_id) = explode('-', $uid); |
1059 | 1058 | if ($type == 'accounts' && empty($id)) // groups have a negative id, eg. "urn:uuid:accounts--1-..." |
1060 | 1059 | { |
1061 | - list($type, , $id_abs, $install_id) = explode('-', $uid); |
|
1060 | + list($type,, $id_abs, $install_id) = explode('-', $uid); |
|
1062 | 1061 | $id = -$id_abs; |
1063 | 1062 | } |
1064 | 1063 | // own urn |
@@ -1071,9 +1070,9 @@ discard block |
||
1071 | 1070 | } |
1072 | 1071 | else |
1073 | 1072 | { |
1074 | - static $calendar_bo=null; |
|
1073 | + static $calendar_bo = null; |
|
1075 | 1074 | if (is_null($calendar_bo)) $calendar_bo = new calendar_bo(); |
1076 | - foreach($calendar_bo->resources as $letter => $info) |
|
1075 | + foreach ($calendar_bo->resources as $letter => $info) |
|
1077 | 1076 | { |
1078 | 1077 | if ($info['app'] == $type || $info['app'] == 'resources' && $type == 'location') |
1079 | 1078 | { |
@@ -1086,7 +1085,7 @@ discard block |
||
1086 | 1085 | break; |
1087 | 1086 | |
1088 | 1087 | default: |
1089 | - if (isset($GLOBALS['groupdav']) && is_a($GLOBALS['groupdav'],'groupdav')) |
|
1088 | + if (isset($GLOBALS['groupdav']) && is_a($GLOBALS['groupdav'], 'groupdav')) |
|
1090 | 1089 | { |
1091 | 1090 | $GLOBALS['groupdav']->log(__METHOD__."('$url') unsupported principal URL '$url'!"); |
1092 | 1091 | } |
@@ -1104,7 +1103,7 @@ discard block |
||
1104 | 1103 | */ |
1105 | 1104 | protected function add_group(array $account) |
1106 | 1105 | { |
1107 | - $displayname = Api\Translation::convert(lang('Group').' '.$account['account_lid'], Api\Translation::charset(), 'utf-8'); |
|
1106 | + $displayname = Api\Translation::convert(lang('Group').' '.$account['account_lid'], Api\Translation::charset(), 'utf-8'); |
|
1108 | 1107 | |
1109 | 1108 | // only return current user, if account-selection == 'none' |
1110 | 1109 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none') |
@@ -1119,19 +1118,19 @@ discard block |
||
1119 | 1118 | return $this->add_principal('groups/'.$account['account_lid'], array( |
1120 | 1119 | 'getetag' => $this->get_etag($account), |
1121 | 1120 | 'displayname' => $displayname, |
1122 | - 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-home-set',array( |
|
1123 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1124 | - 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV,'addressbook-home-set',array( |
|
1125 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1126 | - 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-address-set',array( |
|
1127 | - Api\CalDAV::mkprop('href',$this->base_uri(true).'/principals/groups/'.$account['account_lid'].'/'), |
|
1128 | - Api\CalDAV::mkprop('href',$this->base_uri(false).'/principals/groups/'.$account['account_lid'].'/'), |
|
1129 | - Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
1121 | + 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-home-set', array( |
|
1122 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1123 | + 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'addressbook-home-set', array( |
|
1124 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1125 | + 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-address-set', array( |
|
1126 | + Api\CalDAV::mkprop('href', $this->base_uri(true).'/principals/groups/'.$account['account_lid'].'/'), |
|
1127 | + Api\CalDAV::mkprop('href', $this->base_uri(false).'/principals/groups/'.$account['account_lid'].'/'), |
|
1128 | + Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
1130 | 1129 | )), |
1131 | - 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'record-type','groups'), |
|
1132 | - 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-type','GROUP'), |
|
1130 | + 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'record-type', 'groups'), |
|
1131 | + 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-type', 'GROUP'), |
|
1133 | 1132 | 'group-member-set' => $this->principal_set('group-member-set', $groupmembers), |
1134 | - 'resource-id' => array(Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
1133 | + 'resource-id' => array(Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
1135 | 1134 | )); |
1136 | 1135 | } |
1137 | 1136 | |
@@ -1142,7 +1141,7 @@ discard block |
||
1142 | 1141 | * @param boolean $is_location =null |
1143 | 1142 | * @return array with values for keys 'path' and 'props' |
1144 | 1143 | */ |
1145 | - protected function add_principal_resource(array $resource, $is_location=null) |
|
1144 | + protected function add_principal_resource(array $resource, $is_location = null) |
|
1146 | 1145 | { |
1147 | 1146 | $displayname = null; |
1148 | 1147 | $name = $this->resource2name($resource, $is_location, $displayname); |
@@ -1150,18 +1149,18 @@ discard block |
||
1150 | 1149 | return $this->add_principal($name, array( |
1151 | 1150 | 'getetag' => $this->get_resource_etag($resource), |
1152 | 1151 | 'displayname' => $displayname, |
1153 | - 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-address-set',array( |
|
1154 | - Api\CalDAV::mkprop('href',$this->base_uri(true).'/principals/'.$name.'/'), |
|
1155 | - Api\CalDAV::mkprop('href',$this->base_uri(false).'/principals/'.$name.'/'), |
|
1156 | - Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id'])), |
|
1152 | + 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-address-set', array( |
|
1153 | + Api\CalDAV::mkprop('href', $this->base_uri(true).'/principals/'.$name.'/'), |
|
1154 | + Api\CalDAV::mkprop('href', $this->base_uri(false).'/principals/'.$name.'/'), |
|
1155 | + Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id'])), |
|
1157 | 1156 | )), |
1158 | - 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'record-type',$is_location ? 'locations' : 'resources'), |
|
1159 | - 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-type',$is_location ? 'ROOM' : 'RESOURCE'), |
|
1160 | - 'resource-id' => array(Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id']))), |
|
1157 | + 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'record-type', $is_location ? 'locations' : 'resources'), |
|
1158 | + 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-type', $is_location ? 'ROOM' : 'RESOURCE'), |
|
1159 | + 'resource-id' => array(Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id']))), |
|
1161 | 1160 | // Calendarserver also reports empty email-address-set, thought iCal still does not show resources (only locations) |
1162 | - 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'email-address-set',''), |
|
1163 | - 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-home-set',array( |
|
1164 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$name.'/'))), |
|
1161 | + 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'email-address-set', ''), |
|
1162 | + 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-home-set', array( |
|
1163 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$name.'/'))), |
|
1165 | 1164 | )); |
1166 | 1165 | } |
1167 | 1166 | |
@@ -1173,7 +1172,7 @@ discard block |
||
1173 | 1172 | * @param string &$displayname=null on return displayname of resource |
1174 | 1173 | * @return string eg. "locations/123-some-room" or "resouces/345-some-device" |
1175 | 1174 | */ |
1176 | - public static function resource2name($resource, &$is_location=null, &$displayname=null) |
|
1175 | + public static function resource2name($resource, &$is_location = null, &$displayname = null) |
|
1177 | 1176 | { |
1178 | 1177 | if (!is_array($resource) && !($resource = self::read_resource($resource))) |
1179 | 1178 | { |
@@ -1181,10 +1180,10 @@ discard block |
||
1181 | 1180 | } |
1182 | 1181 | if (is_null($is_location)) $is_location = self::resource_is_location($resource); |
1183 | 1182 | |
1184 | - $displayname = Api\Translation::convert($resource['name'], Api\Translation::charset(), 'utf-8'); |
|
1183 | + $displayname = Api\Translation::convert($resource['name'], Api\Translation::charset(), 'utf-8'); |
|
1185 | 1184 | |
1186 | 1185 | return ($is_location ? 'locations/' : 'resources/').$resource['res_id'].'-'. |
1187 | - preg_replace('/[^a-z0-9]+/i','-', Api\Translation::to_ascii($resource['name'])); |
|
1186 | + preg_replace('/[^a-z0-9]+/i', '-', Api\Translation::to_ascii($resource['name'])); |
|
1188 | 1187 | } |
1189 | 1188 | |
1190 | 1189 | /** |
@@ -1195,7 +1194,7 @@ discard block |
||
1195 | 1194 | */ |
1196 | 1195 | public static function resource_is_location($resource) |
1197 | 1196 | { |
1198 | - static $location_cats=null; |
|
1197 | + static $location_cats = null; |
|
1199 | 1198 | if (is_null($location_cats)) |
1200 | 1199 | { |
1201 | 1200 | $config = Api\Config::read('resources'); |
@@ -1216,7 +1215,7 @@ discard block |
||
1216 | 1215 | */ |
1217 | 1216 | public static function read_resource($res_id) |
1218 | 1217 | { |
1219 | - static $cache=null; // some per-request caching |
|
1218 | + static $cache = null; // some per-request caching |
|
1220 | 1219 | |
1221 | 1220 | if (isset(self::$all_resources) && isset(self::$all_resources[$res_id])) |
1222 | 1221 | { |
@@ -1258,7 +1257,7 @@ discard block |
||
1258 | 1257 | * @param int $user =null account_if of user, or null for current user |
1259 | 1258 | * @return array of array with values for res_id, cat_id and name (no other values1) |
1260 | 1259 | */ |
1261 | - public static function get_resources($user=null) |
|
1260 | + public static function get_resources($user = null) |
|
1262 | 1261 | { |
1263 | 1262 | if (!isset(self::$all_resources)) |
1264 | 1263 | { |
@@ -1266,18 +1265,18 @@ discard block |
||
1266 | 1265 | |
1267 | 1266 | self::$all_resources = array(); |
1268 | 1267 | $query = array( |
1269 | - 'show_bookable' => true, // ignore non-bookable resources |
|
1268 | + 'show_bookable' => true, // ignore non-bookable resources |
|
1270 | 1269 | 'filter2' => -3, |
1271 | 1270 | 'start' => 0, |
1272 | - 'num_rows' => 10000, // return all aka first 10000 entries |
|
1271 | + 'num_rows' => 10000, // return all aka first 10000 entries |
|
1273 | 1272 | ); |
1274 | 1273 | $rows = $readonlys = null; |
1275 | 1274 | if (self::$resources->get_rows($query, $rows, $readonlys)) |
1276 | 1275 | { |
1277 | 1276 | //_debug_array($rows); |
1278 | - foreach($rows as $resource) |
|
1277 | + foreach ($rows as $resource) |
|
1279 | 1278 | { |
1280 | - self::$all_resources[$resource['res_id']] = array_intersect_key($resource, array('res_id'=>true,'cat_id'=>true,'name'=>true)); |
|
1279 | + self::$all_resources[$resource['res_id']] = array_intersect_key($resource, array('res_id'=>true, 'cat_id'=>true, 'name'=>true)); |
|
1281 | 1280 | } |
1282 | 1281 | } |
1283 | 1282 | } |
@@ -1293,7 +1292,7 @@ discard block |
||
1293 | 1292 | */ |
1294 | 1293 | protected function get_resource_rights() |
1295 | 1294 | { |
1296 | - static $grants=null; |
|
1295 | + static $grants = null; |
|
1297 | 1296 | |
1298 | 1297 | if (is_null($grants)) |
1299 | 1298 | { |
@@ -1326,19 +1325,19 @@ discard block |
||
1326 | 1325 | * @param string $principal_url =null include given principal url, relative to principal-collection-set, default $principal |
1327 | 1326 | * @return array with values for keys 'path' and 'props' |
1328 | 1327 | */ |
1329 | - protected function add_principal($principal, array $props = array(), $principal_url=null) |
|
1328 | + protected function add_principal($principal, array $props = array(), $principal_url = null) |
|
1330 | 1329 | { |
1331 | 1330 | $props['resourcetype'][] = Api\CalDAV::mkprop('principal', ''); |
1332 | 1331 | |
1333 | 1332 | // required props per WebDAV ACL |
1334 | - foreach(array('alternate-URI-set', 'group-membership') as $name) |
|
1333 | + foreach (array('alternate-URI-set', 'group-membership') as $name) |
|
1335 | 1334 | { |
1336 | - if (!isset($props[$name])) $props[$name] = Api\CalDAV::mkprop($name,''); |
|
1335 | + if (!isset($props[$name])) $props[$name] = Api\CalDAV::mkprop($name, ''); |
|
1337 | 1336 | } |
1338 | 1337 | if (!$principal_url) $principal_url = $principal; |
1339 | 1338 | |
1340 | 1339 | $props['principal-URL'] = array( |
1341 | - Api\CalDAV::mkprop('href',$this->base_uri.'/principals/'.$principal.'/')); |
|
1340 | + Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'.$principal.'/')); |
|
1342 | 1341 | |
1343 | 1342 | return $this->add_collection('/principals/'.$principal.'/', $props); |
1344 | 1343 | } |
@@ -1354,20 +1353,20 @@ discard block |
||
1354 | 1353 | * @param array $resource =null resource to use (to not query it multiple times from the database) |
1355 | 1354 | * @return array with values for 'path' and 'props' |
1356 | 1355 | */ |
1357 | - protected function add_proxys($principal, $type, array $proxys=array(), array $resource=null) |
|
1356 | + protected function add_proxys($principal, $type, array $proxys = array(), array $resource = null) |
|
1358 | 1357 | { |
1359 | 1358 | list($app,,$what) = explode('-', $type); |
1360 | 1359 | |
1361 | - if (true) $proxys = array(); // ignore parameter! |
|
1362 | - list($account_type,$account) = explode('/', $principal); |
|
1360 | + if (true) $proxys = array(); // ignore parameter! |
|
1361 | + list($account_type, $account) = explode('/', $principal); |
|
1363 | 1362 | |
1364 | - switch($account_type) |
|
1363 | + switch ($account_type) |
|
1365 | 1364 | { |
1366 | 1365 | case 'users': |
1367 | 1366 | case 'groups': |
1368 | 1367 | $account = $location = $this->accounts->name2id($account, 'account_lid', $account_type[0]); |
1369 | 1368 | $right = $what == 'write' ? Api\Acl::EDIT : Api\Acl::READ; |
1370 | - $mask = $what == 'write' ? Api\Acl::EDIT : Api\Acl::EDIT|Api\Acl::READ; // do NOT report write+read in read |
|
1369 | + $mask = $what == 'write' ? Api\Acl::EDIT : Api\Acl::EDIT|Api\Acl::READ; // do NOT report write+read in read |
|
1371 | 1370 | break; |
1372 | 1371 | |
1373 | 1372 | case 'locations': |
@@ -1379,18 +1378,18 @@ discard block |
||
1379 | 1378 | } |
1380 | 1379 | $location = 'L'.$resource['cat_id']; |
1381 | 1380 | $right = $what == 'write' ? EGW_ACL_DIRECT_BOOKING : EGW_ACL_CALREAD; |
1382 | - $mask = $what == 'write' ? EGW_ACL_DIRECT_BOOKING : EGW_ACL_DIRECT_BOOKING|EGW_ACL_CALREAD; // do NOT report write+read in read |
|
1381 | + $mask = $what == 'write' ? EGW_ACL_DIRECT_BOOKING : EGW_ACL_DIRECT_BOOKING|EGW_ACL_CALREAD; // do NOT report write+read in read |
|
1383 | 1382 | break; |
1384 | 1383 | } |
1385 | 1384 | static $principal2grants = array(); |
1386 | - $grants =& $principal2grants[$principal]; |
|
1385 | + $grants = & $principal2grants[$principal]; |
|
1387 | 1386 | if (!isset($grants)) |
1388 | 1387 | { |
1389 | - switch($app) |
|
1388 | + switch ($app) |
|
1390 | 1389 | { |
1391 | 1390 | case 'resources': |
1392 | 1391 | $res_grants = $this->get_resource_rights(); |
1393 | - $grants = (array)$res_grants[$location]; // returns array($location => $grants) |
|
1392 | + $grants = (array)$res_grants[$location]; // returns array($location => $grants) |
|
1394 | 1393 | break; |
1395 | 1394 | |
1396 | 1395 | case 'calendar': |
@@ -1400,9 +1399,9 @@ discard block |
||
1400 | 1399 | } |
1401 | 1400 | //echo "<p>type=$type --> app=$app, what=$what --> right=$right, mask=$mask, account=$account, location=$location --> grants=".array2string($grants)."</p>\n"; |
1402 | 1401 | } |
1403 | - foreach($grants as $account_id => $rights) |
|
1402 | + foreach ($grants as $account_id => $rights) |
|
1404 | 1403 | { |
1405 | - if ($account_id !== 'run' && $account_id != $account && ($rights & $mask) == $right && |
|
1404 | + if ($account_id !== 'run' && $account_id != $account && ($rights&$mask) == $right && |
|
1406 | 1405 | ($account_lid = $this->accounts->id2name($account_id))) |
1407 | 1406 | { |
1408 | 1407 | // ignore "broken" grants (eg. negative account_id for a user), as they lead to further errors (no members) |
@@ -1433,12 +1432,12 @@ discard block |
||
1433 | 1432 | * @param int $account who is the proxy |
1434 | 1433 | * @return array with href props |
1435 | 1434 | */ |
1436 | - protected function principal_set($prop, array $accounts=array(), $app_proxys=null, $account=null) |
|
1435 | + protected function principal_set($prop, array $accounts = array(), $app_proxys = null, $account = null) |
|
1437 | 1436 | { |
1438 | - unset($prop); // not used, but required by function signature |
|
1437 | + unset($prop); // not used, but required by function signature |
|
1439 | 1438 | |
1440 | 1439 | $set = array(); |
1441 | - foreach($accounts as $account_id => $account_lid) |
|
1440 | + foreach ($accounts as $account_id => $account_lid) |
|
1442 | 1441 | { |
1443 | 1442 | if ($this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
1444 | 1443 | { |
@@ -1447,11 +1446,11 @@ discard block |
||
1447 | 1446 | } |
1448 | 1447 | if ($app_proxys) |
1449 | 1448 | { |
1450 | - foreach((array)$app_proxys as $app) |
|
1449 | + foreach ((array)$app_proxys as $app) |
|
1451 | 1450 | { |
1452 | 1451 | if (!isset($GLOBALS['egw_info']['user']['apps'][$app])) continue; |
1453 | 1452 | |
1454 | - switch($app) |
|
1453 | + switch ($app) |
|
1455 | 1454 | { |
1456 | 1455 | case 'resources': |
1457 | 1456 | $proxy_groups = $this->get_resource_proxy_groups($account); |
@@ -1483,11 +1482,11 @@ discard block |
||
1483 | 1482 | // get location grants for $account (incl. his memberships) |
1484 | 1483 | $memberships = $GLOBALS['egw']->accounts->memberships($account, true); |
1485 | 1484 | $location_grants = array(); |
1486 | - foreach($all_location_grants as $location => $grants) |
|
1485 | + foreach ($all_location_grants as $location => $grants) |
|
1487 | 1486 | { |
1488 | - foreach($grants as $account_id => $rights) |
|
1487 | + foreach ($grants as $account_id => $rights) |
|
1489 | 1488 | { |
1490 | - if (($rights & (EGW_ACL_CALREAD|EGW_ACL_DIRECT_BOOKING)) && // we only care for these rights |
|
1489 | + if (($rights&(EGW_ACL_CALREAD|EGW_ACL_DIRECT_BOOKING)) && // we only care for these rights |
|
1491 | 1490 | ($account_id == $account || in_array($account_id, $memberships))) |
1492 | 1491 | { |
1493 | 1492 | if (!isset($location_grants[$location])) $location_grants[$location] = 0; |
@@ -1496,13 +1495,13 @@ discard block |
||
1496 | 1495 | } |
1497 | 1496 | } |
1498 | 1497 | // now add proxy-groups for all resources user has rights to |
1499 | - foreach($resources as $resource) |
|
1498 | + foreach ($resources as $resource) |
|
1500 | 1499 | { |
1501 | 1500 | $rights = $location_grants['L'.$resource['cat_id']]; |
1502 | 1501 | if (isset($rights)) |
1503 | 1502 | { |
1504 | 1503 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'.$this->resource2name($resource). |
1505 | - '/calendar-proxy-'.($rights & EGW_ACL_DIRECT_BOOKING ? 'write' : 'read').'/'); |
|
1504 | + '/calendar-proxy-'.($rights&EGW_ACL_DIRECT_BOOKING ? 'write' : 'read').'/'); |
|
1506 | 1505 | } |
1507 | 1506 | } |
1508 | 1507 | } |
@@ -1517,18 +1516,18 @@ discard block |
||
1517 | 1516 | * @param string|array $app ='calendar' applications for which proxys should be added |
1518 | 1517 | * @return array with href props |
1519 | 1518 | */ |
1520 | - protected function get_calendar_proxy_groups($account, $app='calendar') |
|
1519 | + protected function get_calendar_proxy_groups($account, $app = 'calendar') |
|
1521 | 1520 | { |
1522 | 1521 | $set = array(); |
1523 | - foreach($this->acl->get_grants($app, $app != 'addressbook', $account) as $account_id => $rights) |
|
1522 | + foreach ($this->acl->get_grants($app, $app != 'addressbook', $account) as $account_id => $rights) |
|
1524 | 1523 | { |
1525 | - if ($account_id != $account && ($rights & Api\Acl::READ) && |
|
1524 | + if ($account_id != $account && ($rights&Api\Acl::READ) && |
|
1526 | 1525 | ($account_lid = $this->accounts->id2name($account_id)) && |
1527 | 1526 | $this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
1528 | 1527 | { |
1529 | 1528 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'. |
1530 | 1529 | ($account_id < 0 ? 'groups/' : 'users/'). |
1531 | - $account_lid.'/'.$app.'-proxy-'.($rights & Api\Acl::EDIT ? 'write' : 'read').'/'); |
|
1530 | + $account_lid.'/'.$app.'-proxy-'.($rights&Api\Acl::EDIT ? 'write' : 'read').'/'); |
|
1532 | 1531 | } |
1533 | 1532 | } |
1534 | 1533 | return $set; |
@@ -1543,7 +1542,7 @@ discard block |
||
1543 | 1542 | * @param boolean $do_locations =false false: /principal/resources, true: /principals/locations |
1544 | 1543 | * @return array|string array with files or HTTP error code |
1545 | 1544 | */ |
1546 | - protected function propfind_resources($name,$rest,array $options,$do_locations=false) |
|
1545 | + protected function propfind_resources($name, $rest, array $options, $do_locations = false) |
|
1547 | 1546 | { |
1548 | 1547 | if (!isset($GLOBALS['egw_info']['user']['apps']['resources'])) |
1549 | 1548 | { |
@@ -1562,7 +1561,7 @@ discard block |
||
1562 | 1561 | if (($resources = $this->get_resources())) |
1563 | 1562 | { |
1564 | 1563 | //_debug_array($resources); |
1565 | - foreach($resources as $resource) |
|
1564 | + foreach ($resources as $resource) |
|
1566 | 1565 | { |
1567 | 1566 | if (($is_location = self::resource_is_location($resource)) == $do_locations) |
1568 | 1567 | { |
@@ -1579,11 +1578,11 @@ discard block |
||
1579 | 1578 | return '404 Not Found'; |
1580 | 1579 | } |
1581 | 1580 | $path = ($is_location ? 'locations/' : 'resources/').$name; |
1582 | - while (substr($rest,-1) == '/') |
|
1581 | + while (substr($rest, -1) == '/') |
|
1583 | 1582 | { |
1584 | - $rest = substr($rest,0,-1); |
|
1583 | + $rest = substr($rest, 0, -1); |
|
1585 | 1584 | } |
1586 | - switch((string)$rest) |
|
1585 | + switch ((string)$rest) |
|
1587 | 1586 | { |
1588 | 1587 | case '': |
1589 | 1588 | $files[] = $this->add_principal_resource($resource); |
@@ -1622,12 +1621,12 @@ discard block |
||
1622 | 1621 | if ($options['depth']) |
1623 | 1622 | { |
1624 | 1623 | if (is_numeric($options['depth'])) --$options['depth']; |
1625 | - $files = array_merge($files, $this->propfind_users('','',$options), |
|
1626 | - $this->propfind_groups('','',$options)); |
|
1624 | + $files = array_merge($files, $this->propfind_users('', '', $options), |
|
1625 | + $this->propfind_groups('', '', $options)); |
|
1627 | 1626 | if ($GLOBALS['egw_info']['user']['apps']['resources']) |
1628 | 1627 | { |
1629 | - $files = array_merge($files, $this->propfind_resources('','',$options,false), // resources |
|
1630 | - $this->propfind_resources('','',$options,true)); // locations |
|
1628 | + $files = array_merge($files, $this->propfind_resources('', '', $options, false), // resources |
|
1629 | + $this->propfind_resources('', '', $options, true)); // locations |
|
1631 | 1630 | } |
1632 | 1631 | //$files = array_merge($files,$this->propfind_uids('','',$options)); |
1633 | 1632 | } |
@@ -1642,9 +1641,9 @@ discard block |
||
1642 | 1641 | * @param int $user =null account_id |
1643 | 1642 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
1644 | 1643 | */ |
1645 | - function get(&$options,$id,$user=null) |
|
1644 | + function get(&$options, $id, $user = null) |
|
1646 | 1645 | { |
1647 | - unset($options, $id, $user); // not used, but required by function signature |
|
1646 | + unset($options, $id, $user); // not used, but required by function signature |
|
1648 | 1647 | |
1649 | 1648 | return false; |
1650 | 1649 | } |
@@ -1657,9 +1656,9 @@ discard block |
||
1657 | 1656 | * @param int $user =null account_id of owner, default null |
1658 | 1657 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
1659 | 1658 | */ |
1660 | - function put(&$options,$id,$user=null) |
|
1659 | + function put(&$options, $id, $user = null) |
|
1661 | 1660 | { |
1662 | - unset($options, $id, $user); // not used, but required by function signature |
|
1661 | + unset($options, $id, $user); // not used, but required by function signature |
|
1663 | 1662 | |
1664 | 1663 | return false; |
1665 | 1664 | } |
@@ -1671,9 +1670,9 @@ discard block |
||
1671 | 1670 | * @param int $id |
1672 | 1671 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
1673 | 1672 | */ |
1674 | - function delete(&$options,$id) |
|
1673 | + function delete(&$options, $id) |
|
1675 | 1674 | { |
1676 | - unset($options, $id); // not used, but required by function signature |
|
1675 | + unset($options, $id); // not used, but required by function signature |
|
1677 | 1676 | |
1678 | 1677 | return false; |
1679 | 1678 | } |
@@ -1686,7 +1685,7 @@ discard block |
||
1686 | 1685 | */ |
1687 | 1686 | function read($id) |
1688 | 1687 | { |
1689 | - unset($id); // not used, but required by function signature |
|
1688 | + unset($id); // not used, but required by function signature |
|
1690 | 1689 | |
1691 | 1690 | return false; |
1692 | 1691 | } |
@@ -1698,13 +1697,13 @@ discard block |
||
1698 | 1697 | * @param array|int $entry entry-array or id |
1699 | 1698 | * @return boolean null if entry does not exist, false if no access, true if access permitted |
1700 | 1699 | */ |
1701 | - function check_access($acl,$entry) |
|
1700 | + function check_access($acl, $entry) |
|
1702 | 1701 | { |
1703 | 1702 | if ($acl != Api\Acl::READ) |
1704 | 1703 | { |
1705 | 1704 | return false; |
1706 | 1705 | } |
1707 | - if (!is_array($entry) && !$this->accounts->name2id($entry,'account_lid','u')) |
|
1706 | + if (!is_array($entry) && !$this->accounts->name2id($entry, 'account_lid', 'u')) |
|
1708 | 1707 | { |
1709 | 1708 | return null; |
1710 | 1709 | } |
@@ -1741,9 +1740,9 @@ discard block |
||
1741 | 1740 | * @param int $user =null owner of the collection, default current user |
1742 | 1741 | * @return array with privileges |
1743 | 1742 | */ |
1744 | - public function current_user_privileges($path, $user=null) |
|
1743 | + public function current_user_privileges($path, $user = null) |
|
1745 | 1744 | { |
1746 | - unset($path, $user); // not used, but required by function signature |
|
1745 | + unset($path, $user); // not used, but required by function signature |
|
1747 | 1746 | |
1748 | 1747 | return array('read', 'read-current-user-privilege-set'); |
1749 | 1748 | } |
@@ -49,7 +49,10 @@ discard block |
||
49 | 49 | { |
50 | 50 | parent::__construct($app, $caldav); |
51 | 51 | |
52 | - if (!isset(self::$resources)) self::$resources = new resources_bo(); |
|
52 | + if (!isset(self::$resources)) |
|
53 | + { |
|
54 | + self::$resources = new resources_bo(); |
|
55 | + } |
|
53 | 56 | } |
54 | 57 | |
55 | 58 | /** |
@@ -93,7 +96,10 @@ discard block |
||
93 | 96 | { |
94 | 97 | unset($path); // not used, but required by function signature |
95 | 98 | |
96 | - if (is_null($reports)) $reports = $this->supported_reports; |
|
99 | + if (is_null($reports)) |
|
100 | + { |
|
101 | + $reports = $this->supported_reports; |
|
102 | + } |
|
97 | 103 | |
98 | 104 | $supported = array(); |
99 | 105 | foreach($reports as $name => $data) |
@@ -264,7 +270,10 @@ discard block |
||
264 | 270 | $requested_props = $options['other']; |
265 | 271 | while(($requested_prop = array_shift($requested_props))) |
266 | 272 | { |
267 | - if ($requested_prop['name'] != 'property' || $requested_prop['depth'] != 1) continue; |
|
273 | + if ($requested_prop['name'] != 'property' || $requested_prop['depth'] != 1) |
|
274 | + { |
|
275 | + continue; |
|
276 | + } |
|
268 | 277 | |
269 | 278 | $prop_ns = $requested_prop['attrs']['namespace']; |
270 | 279 | $prop_name = $requested_prop['attrs']['name']; |
@@ -303,7 +312,10 @@ discard block |
||
303 | 312 | // find prop to expand |
304 | 313 | foreach($prop_files['files'][0]['props'] as $expand_prop) |
305 | 314 | { |
306 | - if ($expand_prop['name'] === $prop_name) break; |
|
315 | + if ($expand_prop['name'] === $prop_name) |
|
316 | + { |
|
317 | + break; |
|
318 | + } |
|
307 | 319 | } |
308 | 320 | if ($expand_prop['name'] !== $prop_name || !is_array($expand_prop['val']) || |
309 | 321 | $expand_prop['val'] && $expand_prop['val'][0]['name'] !== 'href') |
@@ -319,10 +331,13 @@ discard block |
||
319 | 331 | { |
320 | 332 | if ($prop['name'] == 'property' && $prop['depth'] == 2) |
321 | 333 | { |
322 | - if (!is_array($options2['props'])) // is "all" initially |
|
334 | + if (!is_array($options2['props'])) |
|
335 | + { |
|
336 | + // is "all" initially |
|
323 | 337 | { |
324 | 338 | $options2['props'] = array(); |
325 | 339 | } |
340 | + } |
|
326 | 341 | $options2['props'][] = array( |
327 | 342 | 'name' => $prop['attrs']['name'], |
328 | 343 | 'xmlns' => isset($prop['attrs']['namespace']) ? $prop['attrs']['namespace'] : $prop['xmlns'], |
@@ -330,7 +345,10 @@ discard block |
||
330 | 345 | } |
331 | 346 | } |
332 | 347 | // put back evtl. read top-level property |
333 | - if ($prop && $prop['depth'] == 1) array_unshift($requested_props, $prop); |
|
348 | + if ($prop && $prop['depth'] == 1) |
|
349 | + { |
|
350 | + array_unshift($requested_props, $prop); |
|
351 | + } |
|
334 | 352 | $this->caldav->options = $options2; // also modify global variable |
335 | 353 | |
336 | 354 | // run regular profind to get requested 2.-level properties for each href |
@@ -526,9 +544,12 @@ discard block |
||
526 | 544 | // now filter out not matching "files" |
527 | 545 | foreach($files['files'] as $n => $resource) |
528 | 546 | { |
529 | - if (count(explode('/', $resource['path'])) < 5) // hack to only return principals, not the collections itself |
|
547 | + if (count(explode('/', $resource['path'])) < 5) |
|
548 | + { |
|
549 | + // hack to only return principals, not the collections itself |
|
530 | 550 | { |
531 | 551 | unset($files['files'][$n]); |
552 | + } |
|
532 | 553 | continue; |
533 | 554 | } |
534 | 555 | // match with $search_props |
@@ -538,16 +559,26 @@ discard block |
||
538 | 559 | // search resource for $search_prop |
539 | 560 | foreach($resource['props'] as $prop) |
540 | 561 | { |
541 | - if ($prop['name'] === $search_prop['name']) break; |
|
562 | + if ($prop['name'] === $search_prop['name']) |
|
563 | + { |
|
564 | + break; |
|
565 | + } |
|
542 | 566 | } |
543 | - if ($prop['name'] === $search_prop['name']) // search_prop NOT found |
|
567 | + if ($prop['name'] === $search_prop['name']) |
|
568 | + { |
|
569 | + // search_prop NOT found |
|
544 | 570 | { |
545 | 571 | foreach((array)$prop['val'] as $value) |
546 | 572 | { |
547 | - if (is_array($value)) $value = $value['val']; // eg. href prop |
|
548 | - if (self::match($value, $search_prop['match'], $search_prop['match-type']) !== false) // prop does match |
|
573 | + if (is_array($value)) $value = $value['val']; |
|
574 | + } |
|
575 | + // eg. href prop |
|
576 | + if (self::match($value, $search_prop['match'], $search_prop['match-type']) !== false) |
|
577 | + { |
|
578 | + // prop does match |
|
549 | 579 | { |
550 | 580 | ++$matches; |
581 | + } |
|
551 | 582 | //error_log("$matches: $resource[path]: $search_prop[name]=".array2string($prop['name'] !== $search_prop['name'] ? null : $prop['val'])." does match '$search_prop[match]'"); |
552 | 583 | break; |
553 | 584 | } |
@@ -749,7 +780,10 @@ discard block |
||
749 | 780 | { |
750 | 781 | foreach($resource['props']['resourcetype']['val'] as $prop) |
751 | 782 | { |
752 | - if ($prop['name'] == 'principal') continue 2; |
|
783 | + if ($prop['name'] == 'principal') |
|
784 | + { |
|
785 | + continue 2; |
|
786 | + } |
|
753 | 787 | } |
754 | 788 | unset($files['files'][$n]); // not a principal --> do not return |
755 | 789 | } |
@@ -903,7 +937,11 @@ discard block |
||
903 | 937 | { |
904 | 938 | $addressbooks = array(); |
905 | 939 | $ab_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set']; |
906 | - if (empty($ab_home_set)) $ab_home_set = 'P'; // personal addressbook |
|
940 | + if (empty($ab_home_set)) |
|
941 | + { |
|
942 | + $ab_home_set = 'P'; |
|
943 | + } |
|
944 | + // personal addressbook |
|
907 | 945 | $addressbook_home_set = explode(',', $ab_home_set); |
908 | 946 | // replace symbolic id's with real nummeric id's |
909 | 947 | foreach(array( |
@@ -917,10 +955,13 @@ discard block |
||
917 | 955 | $addressbook_home_set[$key] = $id; |
918 | 956 | } |
919 | 957 | } |
920 | - if (in_array('O',$addressbook_home_set)) // "all in one" from groupdav.php/addressbook/ |
|
958 | + if (in_array('O',$addressbook_home_set)) |
|
959 | + { |
|
960 | + // "all in one" from groupdav.php/addressbook/ |
|
921 | 961 | { |
922 | 962 | $addressbooks[] = '/'; |
923 | 963 | } |
964 | + } |
|
924 | 965 | foreach(array_keys($GLOBALS['egw']->contacts->get_addressbooks(Api\Acl::READ)) as $id) |
925 | 966 | { |
926 | 967 | if ((in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) && |
@@ -999,7 +1040,10 @@ discard block |
||
999 | 1040 | */ |
1000 | 1041 | static public function url2uid($url, $only_type=null, $cn=null) |
1001 | 1042 | { |
1002 | - if (!$only_type) $only_type = array('users', 'groups', 'resources', 'locations', 'mailto'); |
|
1043 | + if (!$only_type) |
|
1044 | + { |
|
1045 | + $only_type = array('users', 'groups', 'resources', 'locations', 'mailto'); |
|
1046 | + } |
|
1003 | 1047 | |
1004 | 1048 | if ($url[0] == '/') |
1005 | 1049 | { |
@@ -1009,7 +1053,10 @@ discard block |
||
1009 | 1053 | { |
1010 | 1054 | list($schema, $rest) = explode(':', $url, 2); |
1011 | 1055 | } |
1012 | - if (empty($rest)) return false; |
|
1056 | + if (empty($rest)) |
|
1057 | + { |
|
1058 | + return false; |
|
1059 | + } |
|
1013 | 1060 | |
1014 | 1061 | switch(strtolower($schema)) |
1015 | 1062 | { |
@@ -1056,9 +1103,12 @@ discard block |
||
1056 | 1103 | case 'urn': |
1057 | 1104 | list($urn_type, $uid) = explode(':', $rest, 2); |
1058 | 1105 | list($type, $id, $install_id) = explode('-', $uid); |
1059 | - if ($type == 'accounts' && empty($id)) // groups have a negative id, eg. "urn:uuid:accounts--1-..." |
|
1106 | + if ($type == 'accounts' && empty($id)) |
|
1107 | + { |
|
1108 | + // groups have a negative id, eg. "urn:uuid:accounts--1-..." |
|
1060 | 1109 | { |
1061 | 1110 | list($type, , $id_abs, $install_id) = explode('-', $uid); |
1111 | + } |
|
1062 | 1112 | $id = -$id_abs; |
1063 | 1113 | } |
1064 | 1114 | // own urn |
@@ -1072,7 +1122,10 @@ discard block |
||
1072 | 1122 | else |
1073 | 1123 | { |
1074 | 1124 | static $calendar_bo=null; |
1075 | - if (is_null($calendar_bo)) $calendar_bo = new calendar_bo(); |
|
1125 | + if (is_null($calendar_bo)) |
|
1126 | + { |
|
1127 | + $calendar_bo = new calendar_bo(); |
|
1128 | + } |
|
1076 | 1129 | foreach($calendar_bo->resources as $letter => $info) |
1077 | 1130 | { |
1078 | 1131 | if ($info['app'] == $type || $info['app'] == 'resources' && $type == 'location') |
@@ -1179,7 +1232,10 @@ discard block |
||
1179 | 1232 | { |
1180 | 1233 | return null; |
1181 | 1234 | } |
1182 | - if (is_null($is_location)) $is_location = self::resource_is_location($resource); |
|
1235 | + if (is_null($is_location)) |
|
1236 | + { |
|
1237 | + $is_location = self::resource_is_location($resource); |
|
1238 | + } |
|
1183 | 1239 | |
1184 | 1240 | $displayname = Api\Translation::convert($resource['name'], Api\Translation::charset(), 'utf-8'); |
1185 | 1241 | |
@@ -1225,7 +1281,10 @@ discard block |
||
1225 | 1281 | |
1226 | 1282 | if (!isset($cache[$res_id])) |
1227 | 1283 | { |
1228 | - if (!isset(self::$resources)) self::$resources = new resources_bo(); |
|
1284 | + if (!isset(self::$resources)) |
|
1285 | + { |
|
1286 | + self::$resources = new resources_bo(); |
|
1287 | + } |
|
1229 | 1288 | |
1230 | 1289 | if (!($cache[$res_id] = self::$resources->read($res_id))) |
1231 | 1290 | { |
@@ -1262,7 +1321,10 @@ discard block |
||
1262 | 1321 | { |
1263 | 1322 | if (!isset(self::$all_resources)) |
1264 | 1323 | { |
1265 | - if (!isset(self::$resources)) self::$resources = new resources_bo($user); |
|
1324 | + if (!isset(self::$resources)) |
|
1325 | + { |
|
1326 | + self::$resources = new resources_bo($user); |
|
1327 | + } |
|
1266 | 1328 | |
1267 | 1329 | self::$all_resources = array(); |
1268 | 1330 | $query = array( |
@@ -1333,9 +1395,15 @@ discard block |
||
1333 | 1395 | // required props per WebDAV ACL |
1334 | 1396 | foreach(array('alternate-URI-set', 'group-membership') as $name) |
1335 | 1397 | { |
1336 | - if (!isset($props[$name])) $props[$name] = Api\CalDAV::mkprop($name,''); |
|
1398 | + if (!isset($props[$name])) |
|
1399 | + { |
|
1400 | + $props[$name] = Api\CalDAV::mkprop($name,''); |
|
1401 | + } |
|
1402 | + } |
|
1403 | + if (!$principal_url) |
|
1404 | + { |
|
1405 | + $principal_url = $principal; |
|
1337 | 1406 | } |
1338 | - if (!$principal_url) $principal_url = $principal; |
|
1339 | 1407 | |
1340 | 1408 | $props['principal-URL'] = array( |
1341 | 1409 | Api\CalDAV::mkprop('href',$this->base_uri.'/principals/'.$principal.'/')); |
@@ -1358,7 +1426,11 @@ discard block |
||
1358 | 1426 | { |
1359 | 1427 | list($app,,$what) = explode('-', $type); |
1360 | 1428 | |
1361 | - if (true) $proxys = array(); // ignore parameter! |
|
1429 | + if (true) |
|
1430 | + { |
|
1431 | + $proxys = array(); |
|
1432 | + } |
|
1433 | + // ignore parameter! |
|
1362 | 1434 | list($account_type,$account) = explode('/', $principal); |
1363 | 1435 | |
1364 | 1436 | switch($account_type) |
@@ -1440,16 +1512,22 @@ discard block |
||
1440 | 1512 | $set = array(); |
1441 | 1513 | foreach($accounts as $account_id => $account_lid) |
1442 | 1514 | { |
1443 | - if ($this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
|
1515 | + if ($this->accounts->visible($account_lid)) |
|
1516 | + { |
|
1517 | + // only add visible accounts, gives error in iCal otherwise |
|
1444 | 1518 | { |
1445 | 1519 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'.($account_id < 0 ? 'groups/' : 'users/').$account_lid.'/'); |
1446 | 1520 | } |
1521 | + } |
|
1447 | 1522 | } |
1448 | 1523 | if ($app_proxys) |
1449 | 1524 | { |
1450 | 1525 | foreach((array)$app_proxys as $app) |
1451 | 1526 | { |
1452 | - if (!isset($GLOBALS['egw_info']['user']['apps'][$app])) continue; |
|
1527 | + if (!isset($GLOBALS['egw_info']['user']['apps'][$app])) |
|
1528 | + { |
|
1529 | + continue; |
|
1530 | + } |
|
1453 | 1531 | |
1454 | 1532 | switch($app) |
1455 | 1533 | { |
@@ -1490,7 +1568,10 @@ discard block |
||
1490 | 1568 | if (($rights & (EGW_ACL_CALREAD|EGW_ACL_DIRECT_BOOKING)) && // we only care for these rights |
1491 | 1569 | ($account_id == $account || in_array($account_id, $memberships))) |
1492 | 1570 | { |
1493 | - if (!isset($location_grants[$location])) $location_grants[$location] = 0; |
|
1571 | + if (!isset($location_grants[$location])) |
|
1572 | + { |
|
1573 | + $location_grants[$location] = 0; |
|
1574 | + } |
|
1494 | 1575 | $location_grants[$location] |= $rights; |
1495 | 1576 | } |
1496 | 1577 | } |
@@ -1524,12 +1605,15 @@ discard block |
||
1524 | 1605 | { |
1525 | 1606 | if ($account_id != $account && ($rights & Api\Acl::READ) && |
1526 | 1607 | ($account_lid = $this->accounts->id2name($account_id)) && |
1527 | - $this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
|
1608 | + $this->accounts->visible($account_lid)) |
|
1609 | + { |
|
1610 | + // only add visible accounts, gives error in iCal otherwise |
|
1528 | 1611 | { |
1529 | 1612 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'. |
1530 | 1613 | ($account_id < 0 ? 'groups/' : 'users/'). |
1531 | 1614 | $account_lid.'/'.$app.'-proxy-'.($rights & Api\Acl::EDIT ? 'write' : 'read').'/'); |
1532 | 1615 | } |
1616 | + } |
|
1533 | 1617 | } |
1534 | 1618 | return $set; |
1535 | 1619 | } |
@@ -1621,7 +1705,10 @@ discard block |
||
1621 | 1705 | |
1622 | 1706 | if ($options['depth']) |
1623 | 1707 | { |
1624 | - if (is_numeric($options['depth'])) --$options['depth']; |
|
1708 | + if (is_numeric($options['depth'])) |
|
1709 | + { |
|
1710 | + --$options['depth']; |
|
1711 | + } |
|
1625 | 1712 | $files = array_merge($files, $this->propfind_users('','',$options), |
1626 | 1713 | $this->propfind_groups('','',$options)); |
1627 | 1714 | if ($GLOBALS['egw_info']['user']['apps']['resources']) |
@@ -94,6 +94,7 @@ |
||
94 | 94 | * @param Handler $handler |
95 | 95 | * @param array $filter filter for propfind call |
96 | 96 | * @param array $files =array() extra files/responses to return too |
97 | + * @param string $path |
|
97 | 98 | */ |
98 | 99 | public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
99 | 100 | { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @var int |
73 | 73 | */ |
74 | - protected $start=0; |
|
74 | + protected $start = 0; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Number of entries queried from callback in one call |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param array $filter filter for propfind call |
96 | 96 | * @param array $files =array() extra files/responses to return too |
97 | 97 | */ |
98 | - public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
|
98 | + public function __construct(Handler $handler, $path, array $filter, array &$files = array()) |
|
99 | 99 | { |
100 | 100 | if ($this->debug) error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
101 | 101 | $this->path = $path; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $current = current($this->files); |
127 | 127 | |
128 | 128 | if ($this->debug) error_log(__METHOD__."() returning ".array2string($current['path'])); |
129 | - return $current['path']; // we return path as key |
|
129 | + return $current['path']; // we return path as key |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | // try query further files via propfind callback of handler and store result in $this->files |
149 | - $this->files = $this->handler->propfind_callback($this->path,$this->filter,array($this->start,self::CHUNK_SIZE)); |
|
149 | + $this->files = $this->handler->propfind_callback($this->path, $this->filter, array($this->start, self::CHUNK_SIZE)); |
|
150 | 150 | if (!is_array($this->files) || !($entries = count($this->files))) |
151 | 151 | { |
152 | 152 | if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
153 | - return false; // no further entries |
|
153 | + return false; // no further entries |
|
154 | 154 | } |
155 | 155 | $this->start += self::CHUNK_SIZE; |
156 | 156 | reset($this->files); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | $this->start = 0; |
171 | 171 | $this->files = $this->common_files; |
172 | - if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
172 | + if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
173 | 173 | reset($this->files); |
174 | 174 | } |
175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return boolean |
180 | 180 | */ |
181 | - public function valid () |
|
181 | + public function valid() |
|
182 | 182 | { |
183 | 183 | if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
184 | 184 | return current($this->files) !== false; |
@@ -97,7 +97,10 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
99 | 99 | { |
100 | - if ($this->debug) error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
|
100 | + if ($this->debug) |
|
101 | + { |
|
102 | + error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
|
103 | + } |
|
101 | 104 | $this->path = $path; |
102 | 105 | $this->handler = $handler; |
103 | 106 | $this->filter = $filter; |
@@ -112,7 +115,10 @@ discard block |
||
112 | 115 | */ |
113 | 116 | public function current() |
114 | 117 | { |
115 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files))); |
|
118 | + if ($this->debug) |
|
119 | + { |
|
120 | + error_log(__METHOD__."() returning ".array2string(current($this->files))); |
|
121 | + } |
|
116 | 122 | return current($this->files); |
117 | 123 | } |
118 | 124 | |
@@ -125,7 +131,10 @@ discard block |
||
125 | 131 | { |
126 | 132 | $current = current($this->files); |
127 | 133 | |
128 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string($current['path'])); |
|
134 | + if ($this->debug) |
|
135 | + { |
|
136 | + error_log(__METHOD__."() returning ".array2string($current['path'])); |
|
137 | + } |
|
129 | 138 | return $current['path']; // we return path as key |
130 | 139 | } |
131 | 140 | |
@@ -136,26 +145,38 @@ discard block |
||
136 | 145 | { |
137 | 146 | if (next($this->files) !== false) |
138 | 147 | { |
139 | - if ($this->debug) error_log(__METHOD__."() returning TRUE"); |
|
148 | + if ($this->debug) |
|
149 | + { |
|
150 | + error_log(__METHOD__."() returning TRUE"); |
|
151 | + } |
|
140 | 152 | return true; |
141 | 153 | } |
142 | 154 | // check if previous query gave less then CHUNK_SIZE entries --> we're done |
143 | 155 | if ($this->start && count($this->files) < self::CHUNK_SIZE) |
144 | 156 | { |
145 | - if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
157 | + if ($this->debug) |
|
158 | + { |
|
159 | + error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
160 | + } |
|
146 | 161 | return false; |
147 | 162 | } |
148 | 163 | // try query further files via propfind callback of handler and store result in $this->files |
149 | 164 | $this->files = $this->handler->propfind_callback($this->path,$this->filter,array($this->start,self::CHUNK_SIZE)); |
150 | 165 | if (!is_array($this->files) || !($entries = count($this->files))) |
151 | 166 | { |
152 | - if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
167 | + if ($this->debug) |
|
168 | + { |
|
169 | + error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
170 | + } |
|
153 | 171 | return false; // no further entries |
154 | 172 | } |
155 | 173 | $this->start += self::CHUNK_SIZE; |
156 | 174 | reset($this->files); |
157 | 175 | |
158 | - if ($this->debug) error_log(__METHOD__."() this->start=$this->start, entries=$entries, count(this->files)=".count($this->files)." returning ".array2string(current($this->files) !== false)); |
|
176 | + if ($this->debug) |
|
177 | + { |
|
178 | + error_log(__METHOD__."() this->start=$this->start, entries=$entries, count(this->files)=".count($this->files)." returning ".array2string(current($this->files) !== false)); |
|
179 | + } |
|
159 | 180 | |
160 | 181 | return current($this->files) !== false; |
161 | 182 | } |
@@ -165,11 +186,18 @@ discard block |
||
165 | 186 | */ |
166 | 187 | public function rewind() |
167 | 188 | { |
168 | - if ($this->debug) error_log(__METHOD__."()"); |
|
189 | + if ($this->debug) |
|
190 | + { |
|
191 | + error_log(__METHOD__."()"); |
|
192 | + } |
|
169 | 193 | |
170 | 194 | $this->start = 0; |
171 | 195 | $this->files = $this->common_files; |
172 | - if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
196 | + if (!$this->files) |
|
197 | + { |
|
198 | + $this->next(); |
|
199 | + } |
|
200 | + // otherwise valid will return false and nothing get returned |
|
173 | 201 | reset($this->files); |
174 | 202 | } |
175 | 203 | |
@@ -180,7 +208,10 @@ discard block |
||
180 | 208 | */ |
181 | 209 | public function valid () |
182 | 210 | { |
183 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
|
211 | + if ($this->debug) |
|
212 | + { |
|
213 | + error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
|
214 | + } |
|
184 | 215 | return current($this->files) !== false; |
185 | 216 | } |
186 | 217 | } |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | * return a sorted array populated with categories (main sorting criteria is hierachy!) |
323 | 323 | * |
324 | 324 | * @param int $start =0 see $limit |
325 | - * @param boolean|int $limit if true limited query to maxmatches rows (starting with $start) |
|
325 | + * @param boolean $limit if true limited query to maxmatches rows (starting with $start) |
|
326 | 326 | * @param string $query ='' query-pattern |
327 | 327 | * @param string $sort ='ASC' sort order, either defaults to 'ASC' |
328 | 328 | * @param string $order ='cat_name' order by |
329 | 329 | * @param boolean|string $globals includes the global egroupware categories or not, |
330 | 330 | * 'all_no_acl' to return global and all non-private user categories independent of ACL |
331 | - * @param array|int $parent_id =0 return only subcats of $parent_id(s) |
|
331 | + * @param integer $parent_id =0 return only subcats of $parent_id(s) |
|
332 | 332 | * @param boolean $unserialize_data =true return $cat['data'] as array (not serialized array) |
333 | 333 | * @return array with cats |
334 | 334 | */ |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @param mixed $category category as array or the category_id |
508 | 508 | * @param boolean $no_acl_check =false if true, grants are NOT checked, gives access to all non-private categories of all users |
509 | 509 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
510 | - * @return boolean true permission granted, false for permission denied, null for category does not exist |
|
510 | + * @return null|boolean true permission granted, false for permission denied, null for category does not exist |
|
511 | 511 | */ |
512 | 512 | public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
513 | 513 | { |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | * check_consistency4update - for edit |
676 | 676 | * |
677 | 677 | * @param array $values array with cat-data (it need to be complete, as everything get's written) |
678 | - * @return mixed string/boolean errorstring if consitency check failed / true if the consistency check did not fail |
|
678 | + * @return string|boolean string/boolean errorstring if consitency check failed / true if the consistency check did not fail |
|
679 | 679 | */ |
680 | 680 | function check_consistency4update($values) |
681 | 681 | { |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | * |
823 | 823 | * @param int|array $cat |
824 | 824 | * @param boolean $application_global =false true check for application global categories only (appname == 'phpgw') |
825 | - * @return boolean |
|
825 | + * @return null|boolean |
|
826 | 826 | */ |
827 | 827 | static function is_global($cat,$application_global=false) |
828 | 828 | { |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | * |
1031 | 1031 | * @param string appname |
1032 | 1032 | * |
1033 | - * @return Returns the URL, but you do not need to do anything with it. |
|
1033 | + * @return string the URL, but you do not need to do anything with it. |
|
1034 | 1034 | */ |
1035 | 1035 | public static function css($appname) |
1036 | 1036 | { |
@@ -1044,13 +1044,13 @@ |
||
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | /** |
1047 | - * Get the color of a category |
|
1048 | - * |
|
1049 | - * For multiple cats, the first with a color is used |
|
1050 | - * |
|
1051 | - * @param int|string $_cats multiple comma-separated cat_id's |
|
1052 | - * @return string |
|
1053 | - */ |
|
1047 | + * Get the color of a category |
|
1048 | + * |
|
1049 | + * For multiple cats, the first with a color is used |
|
1050 | + * |
|
1051 | + * @param int|string $_cats multiple comma-separated cat_id's |
|
1052 | + * @return string |
|
1053 | + */ |
|
1054 | 1054 | static function cats2color($_cats) |
1055 | 1055 | { |
1056 | 1056 | static $cat2color = array(); |
@@ -120,23 +120,23 @@ discard block |
||
120 | 120 | * @param int|string $accountid ='' account id or lid, default to current user |
121 | 121 | * @param string $app_name ='' app name defaults to current app |
122 | 122 | */ |
123 | - function __construct($accountid='',$app_name = '') |
|
123 | + function __construct($accountid = '', $app_name = '') |
|
124 | 124 | { |
125 | 125 | if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
126 | 126 | |
127 | 127 | if ($accountid === self::GLOBAL_ACCOUNT || |
128 | 128 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
129 | 129 | { |
130 | - $this->account_id = (int) $accountid; |
|
130 | + $this->account_id = (int)$accountid; |
|
131 | 131 | } |
132 | 132 | else |
133 | 133 | { |
134 | - $this->account_id = (int) get_account_id($accountid); |
|
134 | + $this->account_id = (int)get_account_id($accountid); |
|
135 | 135 | $this->global_owners = $this->account_id ? $GLOBALS['egw']->accounts->memberships($this->account_id, true) : array(); |
136 | 136 | $this->global_owners[] = self::GLOBAL_ACCOUNT; |
137 | 137 | } |
138 | - $this->app_name = $app_name; |
|
139 | - $this->db = $GLOBALS['egw']->db; |
|
138 | + $this->app_name = $app_name; |
|
139 | + $this->db = $GLOBALS['egw']->db; |
|
140 | 140 | |
141 | 141 | if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
142 | 142 | { |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | */ |
157 | 157 | function return_all_children($cat_id) |
158 | 158 | { |
159 | - $all_children = (array) $cat_id; |
|
159 | + $all_children = (array)$cat_id; |
|
160 | 160 | |
161 | - $children = $this->return_array('subs',0,False,'','','',True,$cat_id,-1,'id'); |
|
161 | + $children = $this->return_array('subs', 0, False, '', '', '', True, $cat_id, -1, 'id'); |
|
162 | 162 | if (is_array($children) && count($children)) |
163 | 163 | { |
164 | - $all_children = array_merge($all_children,$this->return_all_children($children)); |
|
164 | + $all_children = array_merge($all_children, $this->return_all_children($children)); |
|
165 | 165 | } |
166 | 166 | return $all_children; |
167 | 167 | } |
@@ -183,24 +183,24 @@ discard block |
||
183 | 183 | * @param array $filter =null array with column-name (without cat_-prefix) => value pairs (! negates the value) |
184 | 184 | * @return array of cat-arrays or $column values |
185 | 185 | */ |
186 | - function return_array($type='all', $start=0, $limit=true, $query='', $sort='ASC',$order='',$globals=false, $parent_id=null, $lastmod=-1, $column='', $filter=null) |
|
186 | + function return_array($type = 'all', $start = 0, $limit = true, $query = '', $sort = 'ASC', $order = '', $globals = false, $parent_id = null, $lastmod = -1, $column = '', $filter = null) |
|
187 | 187 | { |
188 | 188 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,globals=$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).") account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
189 | 189 | $cats = array(); |
190 | - foreach(self::$cache as $cat) |
|
190 | + foreach (self::$cache as $cat) |
|
191 | 191 | { |
192 | - if ($filter) foreach($filter as $col => $val) |
|
192 | + if ($filter) foreach ($filter as $col => $val) |
|
193 | 193 | { |
194 | 194 | if (!is_array($val) && $val[0] === '!') |
195 | 195 | { |
196 | 196 | // also match against trimmed database entry on name and description fields |
197 | 197 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
198 | 198 | { |
199 | - if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
|
199 | + if ($cat[$col] == substr($val, 1) || trim($cat[$col]) == substr($val, 1)) continue 2; |
|
200 | 200 | } |
201 | 201 | else |
202 | 202 | { |
203 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
203 | + if ($cat[$col] == substr($val, 1)) continue 2; |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | elseif (is_array($val)) |
@@ -208,11 +208,11 @@ discard block |
||
208 | 208 | // also match against trimmed database entry on name and description fields |
209 | 209 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
210 | 210 | { |
211 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
211 | + if (!in_array($cat[$col], $val) && !in_array(trim($cat[$col]), $val)) continue 2; |
|
212 | 212 | } |
213 | 213 | else |
214 | 214 | { |
215 | - if (!in_array($cat[$col],$val)) continue 2; |
|
215 | + if (!in_array($cat[$col], $val)) continue 2; |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | else |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | } |
230 | 230 | } |
231 | 231 | // check if certain parent required |
232 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
232 | + if ($parent_id && !in_array($cat['parent'], (array)$parent_id)) continue; |
|
233 | 233 | |
234 | 234 | // return global categories just if $globals is set |
235 | 235 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | } |
239 | 239 | |
240 | 240 | // check for read permission |
241 | - if(!$this->check_perms(Acl::READ, $cat, $globals === 'all_no_acl')) |
|
241 | + if (!$this->check_perms(Acl::READ, $cat, $globals === 'all_no_acl')) |
|
242 | 242 | { |
243 | 243 | continue; |
244 | 244 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | switch ($type) |
248 | 248 | { |
249 | 249 | case 'subs': |
250 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
250 | + if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
251 | 251 | break; |
252 | 252 | case 'mains': |
253 | 253 | if ($cat['parent']) continue 2; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | // check name and description for $query |
270 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
270 | + if ($query && stristr($cat['name'], $query) === false && stristr($cat['description'], $query) === false) continue; |
|
271 | 271 | |
272 | 272 | // check if last modified since |
273 | 273 | if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
@@ -284,37 +284,37 @@ discard block |
||
284 | 284 | if (!$sort) $sort = 'ASC'; |
285 | 285 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
286 | 286 | if ($this->total_records > 1 && !empty($order) && |
287 | - preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
|
287 | + preg_match('/^[a-zA-Z_(), ]+$/', $order) && preg_match('/^(ASC|DESC|asc|desc)$/', $sort)) |
|
288 | 288 | { |
289 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
290 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
289 | + if (strstr($order, 'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
290 | + if (substr($order, 0, 4) == 'cat_') $order = substr($order, 4); |
|
291 | 291 | $sign = strtoupper($sort) == 'DESC' ? -1 : 1; |
292 | 292 | usort($cats, function($a, $b) use ($order, $sign) |
293 | 293 | { |
294 | - if (in_array($order, array('name','description','appname','app_name'))) |
|
294 | + if (in_array($order, array('name', 'description', 'appname', 'app_name'))) |
|
295 | 295 | { |
296 | 296 | return $sign * strcasecmp($a[$order], $b[$order]); |
297 | 297 | } |
298 | - return $sign*(int)$a[$order] - $sign*(int)$b[$order]; |
|
298 | + return $sign * (int)$a[$order] - $sign * (int)$b[$order]; |
|
299 | 299 | }); |
300 | 300 | } |
301 | 301 | // limit the number of returned rows |
302 | 302 | if ($limit) |
303 | 303 | { |
304 | 304 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
305 | - $cats = array_slice($cats,(int)$start,$limit); |
|
305 | + $cats = array_slice($cats, (int)$start, $limit); |
|
306 | 306 | } |
307 | 307 | // return only a certain column (why not return is as value?) |
308 | 308 | if ($column) |
309 | 309 | { |
310 | - foreach($cats as $k => $cat) |
|
310 | + foreach ($cats as $k => $cat) |
|
311 | 311 | { |
312 | 312 | $cats[$k] = $cat[$column]; |
313 | 313 | } |
314 | 314 | } |
315 | 315 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).",$unserialize_data) account_id=$this->account_id, appname=$this->app_name = ".array2string($cats)); |
316 | 316 | |
317 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
317 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
318 | 318 | return $cats; |
319 | 319 | } |
320 | 320 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param boolean $unserialize_data =true return $cat['data'] as array (not serialized array) |
333 | 333 | * @return array with cats |
334 | 334 | */ |
335 | - function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
|
335 | + function return_sorted_array($start = 0, $limit = True, $query = '', $sort = 'ASC', $order = 'cat_name', $globals = False, $parent_id = 0, $unserialize_data = true, $filter = null) |
|
336 | 336 | { |
337 | 337 | if (!$sort) $sort = 'ASC'; |
338 | 338 | if (!$order) $order = 'cat_name'; |
@@ -342,27 +342,27 @@ discard block |
||
342 | 342 | $parents = $cats = array(); |
343 | 343 | |
344 | 344 | // Cast parent_id to array, but only if there is one |
345 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
346 | - if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
|
345 | + if ($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
346 | + if (!($cats = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parent_id, -1, '', $filter, $unserialize_data))) |
|
347 | 347 | { |
348 | 348 | $cats = array(); |
349 | 349 | } |
350 | - foreach($cats as $cat) |
|
350 | + foreach ($cats as $cat) |
|
351 | 351 | { |
352 | 352 | $parents[] = $cat['id']; |
353 | 353 | } |
354 | 354 | |
355 | - if($parent_id || !$cats) // Avoid wiping search results |
|
355 | + if ($parent_id || !$cats) // Avoid wiping search results |
|
356 | 356 | { |
357 | 357 | // Go find the children |
358 | 358 | while (count($parents)) |
359 | 359 | { |
360 | - if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
|
360 | + if (!($subs = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parents, -1, '', $filter, $unserialize_data))) |
|
361 | 361 | { |
362 | 362 | break; |
363 | 363 | } |
364 | 364 | $parents = $children = array(); |
365 | - foreach($subs as $cat) |
|
365 | + foreach ($subs as $cat) |
|
366 | 366 | { |
367 | 367 | $parents[] = $cat['id']; |
368 | 368 | $children[$cat['parent']][] = $cat; |
@@ -372,12 +372,12 @@ discard block |
||
372 | 372 | { |
373 | 373 | $cats2 = $cats; |
374 | 374 | $cats = array(); |
375 | - foreach($cats2 as $cat) |
|
375 | + foreach ($cats2 as $cat) |
|
376 | 376 | { |
377 | 377 | $cats[] = $cat; |
378 | 378 | if (isset($children[$cat['id']])) |
379 | 379 | { |
380 | - foreach($children[$cat['id']] as $child) |
|
380 | + foreach ($children[$cat['id']] as $child) |
|
381 | 381 | { |
382 | 382 | $cats[] = $child; |
383 | 383 | } |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | if ($limit) |
393 | 393 | { |
394 | 394 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
395 | - $cats = array_slice($cats,(int)$start,$limit); |
|
395 | + $cats = array_slice($cats, (int)$start, $limit); |
|
396 | 396 | } |
397 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
397 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
398 | 398 | return $cats; |
399 | 399 | } |
400 | 400 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | if (!isset(self::$cache[$id])) return false; |
416 | 416 | |
417 | 417 | $cat = self::$cache[$id]; |
418 | - $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
418 | + $cat['data'] = $cat['data'] ? ((($arr = json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
419 | 419 | $arr : $cat['data']) : array(); |
420 | 420 | |
421 | 421 | return $cat; |
@@ -433,31 +433,31 @@ discard block |
||
433 | 433 | { |
434 | 434 | if ((int)$values['parent'] > 0) |
435 | 435 | { |
436 | - $values['level'] = $this->id2name($values['parent'],'level')+1; |
|
437 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
436 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
437 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
438 | 438 | } |
439 | 439 | else |
440 | 440 | { |
441 | 441 | $values['level'] = 0; |
442 | 442 | } |
443 | - $this->db->insert(self::TABLE,$cat=array( |
|
443 | + $this->db->insert(self::TABLE, $cat = array( |
|
444 | 444 | 'cat_parent' => $values['parent'], |
445 | 445 | 'cat_owner' => isset($values['owner']) ? $values['owner'] : $this->account_id, |
446 | 446 | 'cat_access' => isset($values['access']) ? $values['access'] : 'public', |
447 | 447 | 'cat_appname' => $this->app_name, |
448 | 448 | 'cat_name' => $values['name'], |
449 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
449 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
450 | 450 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
451 | 451 | 'cat_main' => $values['main'], |
452 | 452 | 'cat_level' => $values['level'], |
453 | 453 | 'last_mod' => time(), |
454 | - ),(int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(),__LINE__,__FILE__); |
|
454 | + ), (int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(), __LINE__, __FILE__); |
|
455 | 455 | |
456 | - $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE,'cat_id'); |
|
456 | + $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE, 'cat_id'); |
|
457 | 457 | |
458 | 458 | if (!(int)$values['parent'] && $id != $values['main']) |
459 | 459 | { |
460 | - $this->db->update(self::TABLE,array('cat_main' => $id),array('cat_id' => $id),__LINE__,__FILE__); |
|
460 | + $this->db->update(self::TABLE, array('cat_main' => $id), array('cat_id' => $id), __LINE__, __FILE__); |
|
461 | 461 | $cat['cat_main'] = $id; |
462 | 462 | } |
463 | 463 | // update cache accordingly |
@@ -479,20 +479,20 @@ discard block |
||
479 | 479 | if (empty($cat_list)) return $cat_list; |
480 | 480 | if (is_array($cat_list)) |
481 | 481 | { |
482 | - $cat_list = implode(',',$cat_list); |
|
482 | + $cat_list = implode(',', $cat_list); |
|
483 | 483 | //error_log(__METHOD__.__LINE__.' string expected, array found for cat_list. Converted to:'.$cat_list); |
484 | 484 | } |
485 | - $cat_arr = explode(',',$cat_list); |
|
485 | + $cat_arr = explode(',', $cat_list); |
|
486 | 486 | if (!empty($cat_arr) && is_array($cat_arr) && count($cat_arr) > 0) |
487 | 487 | { |
488 | - foreach($cat_arr as $id=>$cat_id) |
|
488 | + foreach ($cat_arr as $id=>$cat_id) |
|
489 | 489 | { |
490 | 490 | if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) // allow reading all global cats |
491 | 491 | { |
492 | 492 | unset($cat_arr[$id]); |
493 | 493 | } |
494 | 494 | } |
495 | - $cat_list = implode(',',$cat_arr); |
|
495 | + $cat_list = implode(',', $cat_arr); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | return $cat_list; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
510 | 510 | * @return boolean true permission granted, false for permission denied, null for category does not exist |
511 | 511 | */ |
512 | - public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
|
512 | + public function check_perms($needed, $category, $no_acl_check = false, $allow_global_read = false) |
|
513 | 513 | { |
514 | 514 | if (!is_array($category) && !($category = self::read($category))) |
515 | 515 | { |
@@ -525,8 +525,8 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | // Read access to global categories |
528 | - if ($needed == Acl::READ && (($is_global=array_intersect(explode(',',$category['owner']),$this->global_owners)) || |
|
529 | - $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
528 | + if ($needed == Acl::READ && (($is_global = array_intersect(explode(',', $category['owner']), $this->global_owners)) || |
|
529 | + $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
530 | 530 | ($category['appname'] == self::GLOBAL_APPNAME || $category['appname'] == $this->app_name || |
531 | 531 | $is_global && $allow_global_read)) |
532 | 532 | { |
@@ -549,16 +549,16 @@ discard block |
||
549 | 549 | // Load the application grants |
550 | 550 | if ($category['appname'] == $this->app_name && is_null($this->grants)) |
551 | 551 | { |
552 | - $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name,true); |
|
552 | + $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name, true); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | // Check for ACL granted access, the self::GLOBAL_ACCOUNT user must not get access by ACL to keep old behaviour |
556 | 556 | $acl_grant = $this->account_id != self::GLOBAL_ACCOUNT && $category['appname'] == $this->app_name; |
557 | 557 | $owner_grant = false; |
558 | - foreach(explode(',',$category['owner']) as $owner) |
|
558 | + foreach (explode(',', $category['owner']) as $owner) |
|
559 | 559 | { |
560 | - $owner_grant = $owner_grant || (($this->grants[$owner] & $needed) && |
|
561 | - ($category['access'] == 'public' || ($this->grants[$owner] & Acl::PRIVAT))); |
|
560 | + $owner_grant = $owner_grant || (($this->grants[$owner]&$needed) && |
|
561 | + ($category['access'] == 'public' || ($this->grants[$owner]&Acl::PRIVAT))); |
|
562 | 562 | } |
563 | 563 | return $acl_grant && $owner_grant; |
564 | 564 | } |
@@ -575,35 +575,35 @@ discard block |
||
575 | 575 | //error_log(__METHOD__."(".array2string($cat_id).', drop_subs='.array2string($drop_subs).', modify_subs='.array2string($modify_subs).') '.function_backtrace()); |
576 | 576 | if ($modify_subs) |
577 | 577 | { |
578 | - $new_parent = $this->id2name($cat_id,'parent'); |
|
578 | + $new_parent = $this->id2name($cat_id, 'parent'); |
|
579 | 579 | |
580 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $cat_id) as $cat) |
|
580 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $cat_id) as $cat) |
|
581 | 581 | { |
582 | 582 | if ($cat['level'] == 1) |
583 | 583 | { |
584 | - $this->db->update(self::TABLE,array( |
|
584 | + $this->db->update(self::TABLE, array( |
|
585 | 585 | 'cat_level' => 0, |
586 | 586 | 'cat_parent' => 0, |
587 | 587 | 'cat_main' => $cat['id'], |
588 | - ),array( |
|
588 | + ), array( |
|
589 | 589 | 'cat_id' => $cat['id'], |
590 | 590 | 'cat_appname' => $this->app_name, |
591 | - ),__LINE__,__FILE__); |
|
591 | + ), __LINE__, __FILE__); |
|
592 | 592 | |
593 | 593 | $new_main = $cat['id']; |
594 | 594 | } |
595 | 595 | else |
596 | 596 | { |
597 | - $update = array('cat_level' => $cat['level']-1); |
|
597 | + $update = array('cat_level' => $cat['level'] - 1); |
|
598 | 598 | |
599 | 599 | if ($new_main) $update['cat_main'] = $new_main; |
600 | 600 | |
601 | 601 | if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
602 | 602 | |
603 | - $this->db->update(self::TABLE,$update,array( |
|
603 | + $this->db->update(self::TABLE, $update, array( |
|
604 | 604 | 'cat_id' => $cat['id'], |
605 | 605 | 'cat_appname' => $this->app_name, |
606 | - ),__LINE__,__FILE__); |
|
606 | + ), __LINE__, __FILE__); |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | } |
@@ -624,16 +624,16 @@ discard block |
||
624 | 624 | 'modify_subs' => $modify_subs, |
625 | 625 | 'location' => 'delete_category' |
626 | 626 | ); |
627 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
627 | + if ($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
628 | 628 | { |
629 | - Hooks::process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
629 | + Hooks::process($GLOBALS['hook_values'], False, True); // called for every app now, not only enabled ones) |
|
630 | 630 | } |
631 | 631 | else |
632 | 632 | { |
633 | - Hooks::single($GLOBALS['hook_values'], self::id2name($cat_id,'appname')); |
|
633 | + Hooks::single($GLOBALS['hook_values'], self::id2name($cat_id, 'appname')); |
|
634 | 634 | } |
635 | 635 | |
636 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
636 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
637 | 637 | |
638 | 638 | // update cache accordingly |
639 | 639 | self::invalidate_cache($modify_subs ? null : $where['cat_id']); |
@@ -649,17 +649,17 @@ discard block |
||
649 | 649 | */ |
650 | 650 | function adapt_level_in_subtree($values) |
651 | 651 | { |
652 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
652 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
653 | 653 | { |
654 | 654 | if ($cat['parent'] == $values['id']) |
655 | 655 | { |
656 | - $this->db->update(self::TABLE,array( |
|
657 | - 'cat_level' => $values['level']+1, |
|
656 | + $this->db->update(self::TABLE, array( |
|
657 | + 'cat_level' => $values['level'] + 1, |
|
658 | 658 | 'last_mod' => time(), |
659 | - ),array( |
|
659 | + ), array( |
|
660 | 660 | 'cat_id' => $cat['id'], |
661 | 661 | 'cat_appname' => $this->app_name, |
662 | - ),__LINE__,__FILE__); |
|
662 | + ), __LINE__, __FILE__); |
|
663 | 663 | $cat['level'] = $values['level'] + 1; |
664 | 664 | self::invalidate_cache($cat['id']); |
665 | 665 | $this->adapt_level_in_subtree($cat); |
@@ -680,14 +680,14 @@ discard block |
||
680 | 680 | function check_consistency4update($values) |
681 | 681 | { |
682 | 682 | // check if we try to move an element down its own subtree, which will fail |
683 | - foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
683 | + foreach ($this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
684 | 684 | { |
685 | 685 | if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
686 | 686 | } |
687 | 687 | // check if we try to be our own parent |
688 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
688 | + if ($values['parent'] == $values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
689 | 689 | // check if parent still exists |
690 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
690 | + if ((int)$values['parent'] > 0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
691 | 691 | return true; |
692 | 692 | } |
693 | 693 | |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | $ret = $this->check_consistency4update($values); |
707 | 707 | if ($ret !== true) throw new Exception\WrongUserinput($ret); |
708 | 708 | // everything seems in order -> proceed |
709 | - $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
|
709 | + $values['level'] = ($values['parent'] ? $this->id2name($values['parent'], 'level') + 1 : 0); |
|
710 | 710 | $this->adapt_level_in_subtree($values); |
711 | 711 | |
712 | 712 | return $this->add($values); |
@@ -720,8 +720,8 @@ discard block |
||
720 | 720 | if ($ret !== true) throw new Exception\WrongUserinput($ret); |
721 | 721 | |
722 | 722 | // everything seems in order -> proceed |
723 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
724 | - $values['level'] = $this->id2name($values['parent'],'level') + 1; |
|
723 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
724 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
725 | 725 | } |
726 | 726 | else |
727 | 727 | { |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | // adapt the level info in each child |
733 | 733 | $this->adapt_level_in_subtree($values); |
734 | 734 | } |
735 | - $this->db->update(self::TABLE,$cat=array( |
|
735 | + $this->db->update(self::TABLE, $cat = array( |
|
736 | 736 | 'cat_name' => $values['name'], |
737 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
737 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
738 | 738 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
739 | 739 | 'cat_parent' => $values['parent'], |
740 | 740 | 'cat_access' => $values['access'], |
@@ -742,10 +742,10 @@ discard block |
||
742 | 742 | 'cat_main' => $values['main'], |
743 | 743 | 'cat_level' => $values['level'], |
744 | 744 | 'last_mod' => time(), |
745 | - ),array( |
|
745 | + ), array( |
|
746 | 746 | 'cat_id' => $values['id'], |
747 | 747 | 'cat_appname' => $this->app_name, |
748 | - ),__LINE__,__FILE__); |
|
748 | + ), __LINE__, __FILE__); |
|
749 | 749 | |
750 | 750 | $cat['cat_id'] = $values['id']; |
751 | 751 | $cat['cat_appname'] = $this->app_name; |
@@ -769,9 +769,9 @@ discard block |
||
769 | 769 | * @param boolean|string $strip =false if true, strips 'X-' ($strip) from category names added by some SyncML clients |
770 | 770 | * @return int cat-id or 0 if not found |
771 | 771 | */ |
772 | - function name2id($cat_name, $strip=false) |
|
772 | + function name2id($cat_name, $strip = false) |
|
773 | 773 | { |
774 | - static $cache = array(); // a litle bit of caching |
|
774 | + static $cache = array(); // a litle bit of caching |
|
775 | 775 | |
776 | 776 | if (isset($cache[$cat_name])) return $cache[$cat_name]; |
777 | 777 | |
@@ -792,17 +792,17 @@ discard block |
||
792 | 792 | $cats[] = $stripped_cat_name; |
793 | 793 | } |
794 | 794 | |
795 | - if (!($cats = $this->return_array('all',0,false,'','','',true,null,-1,'',array( |
|
795 | + if (!($cats = $this->return_array('all', 0, false, '', '', '', true, null, -1, '', array( |
|
796 | 796 | 'name' => $cats, |
797 | 797 | 'appname' => array($this->app_name, self::GLOBAL_APPNAME), |
798 | 798 | )))) |
799 | 799 | { |
800 | - return 0; // cat not found, dont cache it, as it might be created in this request |
|
800 | + return 0; // cat not found, dont cache it, as it might be created in this request |
|
801 | 801 | } |
802 | 802 | if (count($cats) > 1) |
803 | 803 | { |
804 | 804 | // if more the one cat matches we weight them by: exact name match; own, global, other users cat; appplication cats |
805 | - foreach($cats as $k => $cat) |
|
805 | + foreach ($cats as $k => $cat) |
|
806 | 806 | { |
807 | 807 | $cats[$k]['weight'] = 100 * ($cat['name'] == $cat_name) + |
808 | 808 | 10 * ($cat['owner'] == $this->account_id ? 3 : ($cat['owner'] <= self::GLOBAL_ACCOUNT ? 2 : 1)) + |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | return $b['weight'] - $a['weight']; |
815 | 815 | }); |
816 | 816 | } |
817 | - return $cache[$cat['cat_name']] = (int) $cats[0]['id']; |
|
817 | + return $cache[$cat['cat_name']] = (int)$cats[0]['id']; |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
@@ -824,12 +824,12 @@ discard block |
||
824 | 824 | * @param boolean $application_global =false true check for application global categories only (appname == 'phpgw') |
825 | 825 | * @return boolean |
826 | 826 | */ |
827 | - static function is_global($cat,$application_global=false) |
|
827 | + static function is_global($cat, $application_global = false) |
|
828 | 828 | { |
829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
829 | + if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
830 | 830 | |
831 | 831 | $global_owner = false; |
832 | - foreach(explode(',',$cat['owner']) as $owner) |
|
832 | + foreach (explode(',', $cat['owner']) as $owner) |
|
833 | 833 | { |
834 | 834 | $global_owner = $global_owner || $owner <= self::GLOBAL_ACCOUNT; |
835 | 835 | } |
@@ -846,9 +846,9 @@ discard block |
||
846 | 846 | * @param string $item ='name' requested information, 'path' = / delimited path of category names (incl. parents) |
847 | 847 | * @return string information or '--' if not found or !$cat_id |
848 | 848 | */ |
849 | - static function id2name($cat_id=0, $item='name') |
|
849 | + static function id2name($cat_id = 0, $item = 'name') |
|
850 | 850 | { |
851 | - if(!$cat_id) return '--'; |
|
851 | + if (!$cat_id) return '--'; |
|
852 | 852 | if (!$item) $item = 'parent'; |
853 | 853 | |
854 | 854 | if (is_null(self::$cache)) self::init_cache(); |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | { |
859 | 859 | if ($cat['parent']) |
860 | 860 | { |
861 | - return self::id2name($cat['parent'],'path').' / '.$cat['name']; |
|
861 | + return self::id2name($cat['parent'], 'path').' / '.$cat['name']; |
|
862 | 862 | } |
863 | 863 | $item = 'name'; |
864 | 864 | } |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @param int $parent =0 category id of parent |
888 | 888 | * @return int/boolean cat_id or false if cat not exists |
889 | 889 | */ |
890 | - function exists($type,$cat_name = '',$cat_id = 0,$parent = 0) |
|
890 | + function exists($type, $cat_name = '', $cat_id = 0, $parent = 0) |
|
891 | 891 | { |
892 | 892 | if ($cat_name) |
893 | 893 | { |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | { |
899 | 899 | $filter['id'] = $cat_id; |
900 | 900 | } |
901 | - if (!($cats = $this->return_array($type,0,false,'','','',true,$parent,-1,'id',$filter))) |
|
901 | + if (!($cats = $this->return_array($type, 0, false, '', '', '', true, $parent, -1, 'id', $filter))) |
|
902 | 902 | { |
903 | 903 | $ret = false; |
904 | 904 | } |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | * @param int $to =0 new owner or 0 to delete the cats |
918 | 918 | * @param string $app ='' if given only cats matching $app are modifed/deleted |
919 | 919 | */ |
920 | - function change_owner($owner,$to=0,$app='') |
|
920 | + function change_owner($owner, $to = 0, $app = '') |
|
921 | 921 | { |
922 | 922 | $where = array('cat_owner' => $owner); |
923 | 923 | |
@@ -925,11 +925,11 @@ discard block |
||
925 | 925 | |
926 | 926 | if ((int)$to) |
927 | 927 | { |
928 | - $this->db->update(self::TABLE,array('cat_owner' => $to),$where,__LINE__,__FILE__); |
|
928 | + $this->db->update(self::TABLE, array('cat_owner' => $to), $where, __LINE__, __FILE__); |
|
929 | 929 | } |
930 | 930 | else |
931 | 931 | { |
932 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
932 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
933 | 933 | } |
934 | 934 | // update cache accordingly |
935 | 935 | self::invalidate_cache(); |
@@ -947,10 +947,10 @@ discard block |
||
947 | 947 | if (is_null(self::$cache)) |
948 | 948 | { |
949 | 949 | // check if we are already updated to global owner == 0, if not do it now |
950 | - if (!$GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',array('cat_owner'=>'0'),__LINE__,__FILE__)->fetchColumn()) |
|
950 | + if (!$GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', array('cat_owner'=>'0'), __LINE__, __FILE__)->fetchColumn()) |
|
951 | 951 | { |
952 | - $GLOBALS['egw']->db->update(self::TABLE,array('cat_owner'=>'0'),"(cat_owner='-1' OR cat_appname='phpgw')",__LINE__,__FILE__); |
|
953 | - $GLOBALS['egw']->db->insert(self::TABLE,array( |
|
952 | + $GLOBALS['egw']->db->update(self::TABLE, array('cat_owner'=>'0'), "(cat_owner='-1' OR cat_appname='phpgw')", __LINE__, __FILE__); |
|
953 | + $GLOBALS['egw']->db->insert(self::TABLE, array( |
|
954 | 954 | 'cat_main' => 0, |
955 | 955 | 'cat_parent' => 0, |
956 | 956 | 'cat_level' => 0, |
@@ -959,15 +959,15 @@ discard block |
||
959 | 959 | 'cat_name' => 'global=0', |
960 | 960 | 'cat_description' => 'global=0', |
961 | 961 | 'last_mod' => time(), |
962 | - ),false,__LINE__,__FILE__); |
|
962 | + ), false, __LINE__, __FILE__); |
|
963 | 963 | } |
964 | 964 | self::$cache = array(); |
965 | 965 | // read all cats (cant use $this->db!) |
966 | - foreach($GLOBALS['egw']->db->select(self::TABLE,'*',false,__LINE__,__FILE__, |
|
967 | - false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
966 | + foreach ($GLOBALS['egw']->db->select(self::TABLE, '*', false, __LINE__, __FILE__, |
|
967 | + false, 'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
968 | 968 | { |
969 | - $cat = Db::strip_array_keys($cat,'cat_'); |
|
970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
969 | + $cat = Db::strip_array_keys($cat, 'cat_'); |
|
970 | + if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
971 | 971 | $cat['app_name'] = $cat['appname']; |
972 | 972 | // backlink children to their parent |
973 | 973 | if ($cat['parent']) |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | if (isset(self::$cache[$cat['id']])) |
978 | 978 | { |
979 | 979 | $cat['children'] = self::$cache[$cat['id']]['children']; |
980 | - unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
980 | + unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
981 | 981 | } |
982 | 982 | self::$cache[$cat['id']] = $cat; |
983 | 983 | } |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | * |
995 | 995 | * @param int|array $cat concerned id(s) or array with cat-data or null for all cats |
996 | 996 | */ |
997 | - public static function invalidate_cache($cat=null) |
|
997 | + public static function invalidate_cache($cat = null) |
|
998 | 998 | { |
999 | 999 | //error_log(__METHOD__."(".array2string($cat).') '.function_backtrace()); |
1000 | 1000 | |
@@ -1006,12 +1006,12 @@ discard block |
||
1006 | 1006 | { |
1007 | 1007 | if (!is_array($cat) || isset($cat[0])) |
1008 | 1008 | { |
1009 | - foreach((array)$cat as $cat_id) |
|
1009 | + foreach ((array)$cat as $cat_id) |
|
1010 | 1010 | { |
1011 | 1011 | unset(self::$cache[$cat_id]); |
1012 | 1012 | } |
1013 | 1013 | } |
1014 | - elseif($cat['id']) |
|
1014 | + elseif ($cat['id']) |
|
1015 | 1015 | { |
1016 | 1016 | self::$cache[$cat['id']] = $cat; |
1017 | 1017 | } |
@@ -1034,8 +1034,8 @@ discard block |
||
1034 | 1034 | */ |
1035 | 1035 | public static function css($appname) |
1036 | 1036 | { |
1037 | - $cats = new Categories('',$appname); |
|
1038 | - $last_mod = $cats->return_array('all',0,1,'','DESC','last_mod', $appname == self::GLOBAL_APPNAME); |
|
1037 | + $cats = new Categories('', $appname); |
|
1038 | + $last_mod = $cats->return_array('all', 0, 1, '', 'DESC', 'last_mod', $appname == self::GLOBAL_APPNAME); |
|
1039 | 1039 | $time = count($last_mod) ? $last_mod[0]['last_mod'] : time(); |
1040 | 1040 | $path = '/api/categories.php?app='.$appname.'&'.$time; |
1041 | 1041 | Framework::includeCSS($path); |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | return $cat2color[$cats]; |
1066 | 1066 | } |
1067 | 1067 | |
1068 | - foreach(explode(',', $cats) as $cat) |
|
1068 | + foreach (explode(',', $cats) as $cat) |
|
1069 | 1069 | { |
1070 | 1070 | if (isset($cat2color[$cat])) |
1071 | 1071 | { |
@@ -1088,13 +1088,13 @@ discard block |
||
1088 | 1088 | * @param int $new_owner =null for users data can be transfered to new owner |
1089 | 1089 | * @return int number of deleted or modified categories |
1090 | 1090 | */ |
1091 | - public static function delete_account($account_id, $new_owner=null) |
|
1091 | + public static function delete_account($account_id, $new_owner = null) |
|
1092 | 1092 | { |
1093 | 1093 | if (is_null(self::$cache)) self::init_cache(); |
1094 | 1094 | |
1095 | 1095 | $deleted = 0; |
1096 | 1096 | $cat = null; |
1097 | - foreach(self::$cache as $cat_id => $data) |
|
1097 | + foreach (self::$cache as $cat_id => $data) |
|
1098 | 1098 | { |
1099 | 1099 | if ($data['owner'] && ($owners = explode(',', $data['owner'])) && ($owner_key = array_search($account_id, $owners)) !== false) |
1100 | 1100 | { |
@@ -1136,9 +1136,9 @@ discard block |
||
1136 | 1136 | |
1137 | 1137 | $checked = array(); |
1138 | 1138 | $deleted = 0; |
1139 | - foreach(self::$cache as $data) |
|
1139 | + foreach (self::$cache as $data) |
|
1140 | 1140 | { |
1141 | - foreach(explode(',', $data['owner']) as $owner) |
|
1141 | + foreach (explode(',', $data['owner']) as $owner) |
|
1142 | 1142 | { |
1143 | 1143 | if ($owner && !in_array($owner, $checked)) |
1144 | 1144 | { |
@@ -122,7 +122,10 @@ discard block |
||
122 | 122 | */ |
123 | 123 | function __construct($accountid='',$app_name = '') |
124 | 124 | { |
125 | - if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
125 | + if (!$app_name) |
|
126 | + { |
|
127 | + $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
128 | + } |
|
126 | 129 | |
127 | 130 | if ($accountid === self::GLOBAL_ACCOUNT || |
128 | 131 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
@@ -138,10 +141,13 @@ discard block |
||
138 | 141 | $this->app_name = $app_name; |
139 | 142 | $this->db = $GLOBALS['egw']->db; |
140 | 143 | |
141 | - if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
|
144 | + if (is_null(self::$cache)) |
|
145 | + { |
|
146 | + // should not be necessary, as cache is load and restored by egw object |
|
142 | 147 | { |
143 | 148 | self::init_cache(); |
144 | 149 | } |
150 | + } |
|
145 | 151 | if (is_null(self::$global_marker)) |
146 | 152 | { |
147 | 153 | // as et2 adds options with .text(), it can't be entities, but php knows no string literals with utf-8 |
@@ -189,7 +195,9 @@ discard block |
||
189 | 195 | $cats = array(); |
190 | 196 | foreach(self::$cache as $cat) |
191 | 197 | { |
192 | - if ($filter) foreach($filter as $col => $val) |
|
198 | + if ($filter) |
|
199 | + { |
|
200 | + foreach($filter as $col => $val) |
|
193 | 201 | { |
194 | 202 | if (!is_array($val) && $val[0] === '!') |
195 | 203 | { |
@@ -197,10 +205,14 @@ discard block |
||
197 | 205 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
198 | 206 | { |
199 | 207 | if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
208 | + } |
|
200 | 209 | } |
201 | 210 | else |
202 | 211 | { |
203 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
212 | + if ($cat[$col] == substr($val,1)) |
|
213 | + { |
|
214 | + continue 2; |
|
215 | + } |
|
204 | 216 | } |
205 | 217 | } |
206 | 218 | elseif (is_array($val)) |
@@ -208,11 +220,17 @@ discard block |
||
208 | 220 | // also match against trimmed database entry on name and description fields |
209 | 221 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
210 | 222 | { |
211 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
223 | + if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) |
|
224 | + { |
|
225 | + continue 2; |
|
226 | + } |
|
212 | 227 | } |
213 | 228 | else |
214 | 229 | { |
215 | - if (!in_array($cat[$col],$val)) continue 2; |
|
230 | + if (!in_array($cat[$col],$val)) |
|
231 | + { |
|
232 | + continue 2; |
|
233 | + } |
|
216 | 234 | } |
217 | 235 | } |
218 | 236 | else |
@@ -220,16 +238,25 @@ discard block |
||
220 | 238 | // also match against trimmed database entry on name and description fields |
221 | 239 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
222 | 240 | { |
223 | - if ($cat[$col] != $val && trim($cat[$col]) != $val) continue 2; |
|
241 | + if ($cat[$col] != $val && trim($cat[$col]) != $val) |
|
242 | + { |
|
243 | + continue 2; |
|
244 | + } |
|
224 | 245 | } |
225 | 246 | else |
226 | 247 | { |
227 | - if ($cat[$col] != $val) continue 2; |
|
248 | + if ($cat[$col] != $val) |
|
249 | + { |
|
250 | + continue 2; |
|
251 | + } |
|
228 | 252 | } |
229 | 253 | } |
230 | 254 | } |
231 | 255 | // check if certain parent required |
232 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
256 | + if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) |
|
257 | + { |
|
258 | + continue; |
|
259 | + } |
|
233 | 260 | |
234 | 261 | // return global categories just if $globals is set |
235 | 262 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -247,30 +274,55 @@ discard block |
||
247 | 274 | switch ($type) |
248 | 275 | { |
249 | 276 | case 'subs': |
250 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
277 | + if (!$cat['parent']) |
|
278 | + { |
|
279 | + continue 2; |
|
280 | + } |
|
281 | + // 2 for switch AND foreach! |
|
251 | 282 | break; |
252 | 283 | case 'mains': |
253 | - if ($cat['parent']) continue 2; |
|
284 | + if ($cat['parent']) |
|
285 | + { |
|
286 | + continue 2; |
|
287 | + } |
|
254 | 288 | break; |
255 | 289 | case 'appandmains': |
256 | - if ($cat['appname'] != $this->app_name || $cat['parent']) continue 2; |
|
290 | + if ($cat['appname'] != $this->app_name || $cat['parent']) |
|
291 | + { |
|
292 | + continue 2; |
|
293 | + } |
|
257 | 294 | break; |
258 | 295 | case 'appandsubs': |
259 | - if ($cat['appname'] != $this->app_name || !$cat['parent']) continue 2; |
|
296 | + if ($cat['appname'] != $this->app_name || !$cat['parent']) |
|
297 | + { |
|
298 | + continue 2; |
|
299 | + } |
|
260 | 300 | break; |
261 | 301 | case 'noglobal': |
262 | - if ($cat['appname'] == $this->app_name) continue 2; |
|
302 | + if ($cat['appname'] == $this->app_name) |
|
303 | + { |
|
304 | + continue 2; |
|
305 | + } |
|
263 | 306 | break; |
264 | 307 | case 'noglobalapp': |
265 | - if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) continue 2; |
|
308 | + if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) |
|
309 | + { |
|
310 | + continue 2; |
|
311 | + } |
|
266 | 312 | break; |
267 | 313 | } |
268 | 314 | |
269 | 315 | // check name and description for $query |
270 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
316 | + if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) |
|
317 | + { |
|
318 | + continue; |
|
319 | + } |
|
271 | 320 | |
272 | 321 | // check if last modified since |
273 | - if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
|
322 | + if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) |
|
323 | + { |
|
324 | + continue; |
|
325 | + } |
|
274 | 326 | |
275 | 327 | $cat['data'] = $cat['data'] ? json_php_unserialize($cat['data'], true) : array(); |
276 | 328 | |
@@ -281,13 +333,23 @@ discard block |
||
281 | 333 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=$parent_id,$lastmod,$column) account_id=$this->account_id, appname=$this->app_name = FALSE"); |
282 | 334 | return array(); |
283 | 335 | } |
284 | - if (!$sort) $sort = 'ASC'; |
|
336 | + if (!$sort) |
|
337 | + { |
|
338 | + $sort = 'ASC'; |
|
339 | + } |
|
285 | 340 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
286 | 341 | if ($this->total_records > 1 && !empty($order) && |
287 | 342 | preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
288 | 343 | { |
289 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
290 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
344 | + if (strstr($order,'cat_data') !== false) |
|
345 | + { |
|
346 | + $order = 'cat_data'; |
|
347 | + } |
|
348 | + // sitemgr orders by round(cat_data)! |
|
349 | + if (substr($order,0,4) == 'cat_') |
|
350 | + { |
|
351 | + $order = substr($order,4); |
|
352 | + } |
|
291 | 353 | $sign = strtoupper($sort) == 'DESC' ? -1 : 1; |
292 | 354 | usort($cats, function($a, $b) use ($order, $sign) |
293 | 355 | { |
@@ -301,7 +363,10 @@ discard block |
||
301 | 363 | // limit the number of returned rows |
302 | 364 | if ($limit) |
303 | 365 | { |
304 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
366 | + if (!is_int($limit)) |
|
367 | + { |
|
368 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
369 | + } |
|
305 | 370 | $cats = array_slice($cats,(int)$start,$limit); |
306 | 371 | } |
307 | 372 | // return only a certain column (why not return is as value?) |
@@ -334,15 +399,24 @@ discard block |
||
334 | 399 | */ |
335 | 400 | function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
336 | 401 | { |
337 | - if (!$sort) $sort = 'ASC'; |
|
338 | - if (!$order) $order = 'cat_name'; |
|
402 | + if (!$sort) |
|
403 | + { |
|
404 | + $sort = 'ASC'; |
|
405 | + } |
|
406 | + if (!$order) |
|
407 | + { |
|
408 | + $order = 'cat_name'; |
|
409 | + } |
|
339 | 410 | |
340 | 411 | //error_log(__METHOD__."($start,$limit,$query,$sort,$order,globals=$globals,parent=$parent_id,$unserialize_data) account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
341 | 412 | |
342 | 413 | $parents = $cats = array(); |
343 | 414 | |
344 | 415 | // Cast parent_id to array, but only if there is one |
345 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
416 | + if($parent_id !== false && $parent_id !== null) |
|
417 | + { |
|
418 | + $parent_id = (array)$parent_id; |
|
419 | + } |
|
346 | 420 | if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
347 | 421 | { |
348 | 422 | $cats = array(); |
@@ -352,7 +426,9 @@ discard block |
||
352 | 426 | $parents[] = $cat['id']; |
353 | 427 | } |
354 | 428 | |
355 | - if($parent_id || !$cats) // Avoid wiping search results |
|
429 | + if($parent_id || !$cats) |
|
430 | + { |
|
431 | + // Avoid wiping search results |
|
356 | 432 | { |
357 | 433 | // Go find the children |
358 | 434 | while (count($parents)) |
@@ -360,6 +436,7 @@ discard block |
||
360 | 436 | if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
361 | 437 | { |
362 | 438 | break; |
439 | + } |
|
363 | 440 | } |
364 | 441 | $parents = $children = array(); |
365 | 442 | foreach($subs as $cat) |
@@ -391,7 +468,10 @@ discard block |
||
391 | 468 | // limit the number of returned rows |
392 | 469 | if ($limit) |
393 | 470 | { |
394 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
471 | + if (!is_int($limit)) |
|
472 | + { |
|
473 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
474 | + } |
|
395 | 475 | $cats = array_slice($cats,(int)$start,$limit); |
396 | 476 | } |
397 | 477 | reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
@@ -410,9 +490,15 @@ discard block |
||
410 | 490 | */ |
411 | 491 | static function read($id) |
412 | 492 | { |
413 | - if (is_null(self::$cache)) self::init_cache(); |
|
493 | + if (is_null(self::$cache)) |
|
494 | + { |
|
495 | + self::init_cache(); |
|
496 | + } |
|
414 | 497 | |
415 | - if (!isset(self::$cache[$id])) return false; |
|
498 | + if (!isset(self::$cache[$id])) |
|
499 | + { |
|
500 | + return false; |
|
501 | + } |
|
416 | 502 | |
417 | 503 | $cat = self::$cache[$id]; |
418 | 504 | $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
@@ -475,8 +561,11 @@ discard block |
||
475 | 561 | * @return string truncated commaseparated list of category ids |
476 | 562 | */ |
477 | 563 | function check_list($needed, $cat_list) |
478 | - { |
|
479 | - if (empty($cat_list)) return $cat_list; |
|
564 | + { |
|
565 | + if (empty($cat_list)) |
|
566 | + { |
|
567 | + return $cat_list; |
|
568 | + } |
|
480 | 569 | if (is_array($cat_list)) |
481 | 570 | { |
482 | 571 | $cat_list = implode(',',$cat_list); |
@@ -487,10 +576,13 @@ discard block |
||
487 | 576 | { |
488 | 577 | foreach($cat_arr as $id=>$cat_id) |
489 | 578 | { |
490 | - if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) // allow reading all global cats |
|
579 | + if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) |
|
580 | + { |
|
581 | + // allow reading all global cats |
|
491 | 582 | { |
492 | 583 | unset($cat_arr[$id]); |
493 | 584 | } |
585 | + } |
|
494 | 586 | } |
495 | 587 | $cat_list = implode(',',$cat_arr); |
496 | 588 | } |
@@ -596,9 +688,15 @@ discard block |
||
596 | 688 | { |
597 | 689 | $update = array('cat_level' => $cat['level']-1); |
598 | 690 | |
599 | - if ($new_main) $update['cat_main'] = $new_main; |
|
691 | + if ($new_main) |
|
692 | + { |
|
693 | + $update['cat_main'] = $new_main; |
|
694 | + } |
|
600 | 695 | |
601 | - if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
|
696 | + if ($cat['parent'] == $cat_id) |
|
697 | + { |
|
698 | + $update['cat_parent'] = $new_parent; |
|
699 | + } |
|
602 | 700 | |
603 | 701 | $this->db->update(self::TABLE,$update,array( |
604 | 702 | 'cat_id' => $cat['id'], |
@@ -624,9 +722,13 @@ discard block |
||
624 | 722 | 'modify_subs' => $modify_subs, |
625 | 723 | 'location' => 'delete_category' |
626 | 724 | ); |
627 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
725 | + if($this->is_global($cat_id, true)) |
|
726 | + { |
|
727 | + // true = application global (otherwise eg. global addressbook categories call all apps) |
|
628 | 728 | { |
629 | - Hooks::process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
729 | + Hooks::process($GLOBALS['hook_values'],False,True); |
|
730 | + } |
|
731 | + // called for every app now, not only enabled ones) |
|
630 | 732 | } |
631 | 733 | else |
632 | 734 | { |
@@ -682,12 +784,22 @@ discard block |
||
682 | 784 | // check if we try to move an element down its own subtree, which will fail |
683 | 785 | foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
684 | 786 | { |
685 | - if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
787 | + if ($cat['id'] == $values['parent']) |
|
788 | + { |
|
789 | + return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
790 | + } |
|
686 | 791 | } |
687 | 792 | // check if we try to be our own parent |
688 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
793 | + if ($values['parent']==$values['id']) |
|
794 | + { |
|
795 | + return lang('Cannot set this cat as its own parent!'); |
|
796 | + } |
|
797 | + // deny to be our own parent |
|
689 | 798 | // check if parent still exists |
690 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
799 | + if ((int)$values['parent']>0 && !$this->read($values['parent'])) |
|
800 | + { |
|
801 | + return lang('Chosen parent category no longer exists'); |
|
802 | + } |
|
691 | 803 | return true; |
692 | 804 | } |
693 | 805 | |
@@ -704,7 +816,10 @@ discard block |
||
704 | 816 | if (isset($values['old_parent']) && (int)$values['old_parent'] != (int)$values['parent']) |
705 | 817 | { |
706 | 818 | $ret = $this->check_consistency4update($values); |
707 | - if ($ret !== true) throw new Exception\WrongUserinput($ret); |
|
819 | + if ($ret !== true) |
|
820 | + { |
|
821 | + throw new Exception\WrongUserinput($ret); |
|
822 | + } |
|
708 | 823 | // everything seems in order -> proceed |
709 | 824 | $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
710 | 825 | $this->adapt_level_in_subtree($values); |
@@ -717,7 +832,10 @@ discard block |
||
717 | 832 | if ($values['parent'] > 0) |
718 | 833 | { |
719 | 834 | $ret = $this->check_consistency4update($values); |
720 | - if ($ret !== true) throw new Exception\WrongUserinput($ret); |
|
835 | + if ($ret !== true) |
|
836 | + { |
|
837 | + throw new Exception\WrongUserinput($ret); |
|
838 | + } |
|
721 | 839 | |
722 | 840 | // everything seems in order -> proceed |
723 | 841 | $values['main'] = $this->id2name($values['parent'],'main'); |
@@ -773,7 +891,10 @@ discard block |
||
773 | 891 | { |
774 | 892 | static $cache = array(); // a litle bit of caching |
775 | 893 | |
776 | - if (isset($cache[$cat_name])) return $cache[$cat_name]; |
|
894 | + if (isset($cache[$cat_name])) |
|
895 | + { |
|
896 | + return $cache[$cat_name]; |
|
897 | + } |
|
777 | 898 | |
778 | 899 | if ($strip === true) |
779 | 900 | { |
@@ -826,7 +947,11 @@ discard block |
||
826 | 947 | */ |
827 | 948 | static function is_global($cat,$application_global=false) |
828 | 949 | { |
829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
950 | + if (!is_array($cat) && !($cat = self::read($cat))) |
|
951 | + { |
|
952 | + return null; |
|
953 | + } |
|
954 | + // cat not found |
|
830 | 955 | |
831 | 956 | $global_owner = false; |
832 | 957 | foreach(explode(',',$cat['owner']) as $owner) |
@@ -848,10 +973,19 @@ discard block |
||
848 | 973 | */ |
849 | 974 | static function id2name($cat_id=0, $item='name') |
850 | 975 | { |
851 | - if(!$cat_id) return '--'; |
|
852 | - if (!$item) $item = 'parent'; |
|
976 | + if(!$cat_id) |
|
977 | + { |
|
978 | + return '--'; |
|
979 | + } |
|
980 | + if (!$item) |
|
981 | + { |
|
982 | + $item = 'parent'; |
|
983 | + } |
|
853 | 984 | |
854 | - if (is_null(self::$cache)) self::init_cache(); |
|
985 | + if (is_null(self::$cache)) |
|
986 | + { |
|
987 | + self::init_cache(); |
|
988 | + } |
|
855 | 989 | |
856 | 990 | $cat = self::$cache[$cat_id]; |
857 | 991 | if ($item == 'path') |
@@ -892,7 +1026,10 @@ discard block |
||
892 | 1026 | if ($cat_name) |
893 | 1027 | { |
894 | 1028 | $filter['name'] = $cat_name; |
895 | - if ($cat_id) $filter['id'] = '!'.(int)$cat_id; |
|
1029 | + if ($cat_id) |
|
1030 | + { |
|
1031 | + $filter['id'] = '!'.(int)$cat_id; |
|
1032 | + } |
|
896 | 1033 | } |
897 | 1034 | elseif ($cat_id) |
898 | 1035 | { |
@@ -921,7 +1058,10 @@ discard block |
||
921 | 1058 | { |
922 | 1059 | $where = array('cat_owner' => $owner); |
923 | 1060 | |
924 | - if ($app) $where['cat_appname'] = $app; |
|
1061 | + if ($app) |
|
1062 | + { |
|
1063 | + $where['cat_appname'] = $app; |
|
1064 | + } |
|
925 | 1065 | |
926 | 1066 | if ((int)$to) |
927 | 1067 | { |
@@ -967,7 +1107,11 @@ discard block |
||
967 | 1107 | false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
968 | 1108 | { |
969 | 1109 | $cat = Db::strip_array_keys($cat,'cat_'); |
970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
1110 | + if ($cat['appname'] == '*update*') |
|
1111 | + { |
|
1112 | + continue; |
|
1113 | + } |
|
1114 | + // --> ignore update marker |
|
971 | 1115 | $cat['app_name'] = $cat['appname']; |
972 | 1116 | // backlink children to their parent |
973 | 1117 | if ($cat['parent']) |
@@ -1058,7 +1202,10 @@ discard block |
||
1058 | 1202 | // ACL check |
1059 | 1203 | $cats = $GLOBALS['egw']->categories->check_list(Acl::READ, $_cats); |
1060 | 1204 | |
1061 | - if (!$cats) return null; |
|
1205 | + if (!$cats) |
|
1206 | + { |
|
1207 | + return null; |
|
1208 | + } |
|
1062 | 1209 | |
1063 | 1210 | if (isset($cat2color[$cats])) |
1064 | 1211 | { |
@@ -1090,7 +1237,10 @@ discard block |
||
1090 | 1237 | */ |
1091 | 1238 | public static function delete_account($account_id, $new_owner=null) |
1092 | 1239 | { |
1093 | - if (is_null(self::$cache)) self::init_cache(); |
|
1240 | + if (is_null(self::$cache)) |
|
1241 | + { |
|
1242 | + self::init_cache(); |
|
1243 | + } |
|
1094 | 1244 | |
1095 | 1245 | $deleted = 0; |
1096 | 1246 | $cat = null; |
@@ -1110,7 +1260,10 @@ discard block |
||
1110 | 1260 | else |
1111 | 1261 | { |
1112 | 1262 | unset($owners[$owner_key]); |
1113 | - if ($new_owner && $account_id > 0) $owners[] = $new_owner; |
|
1263 | + if ($new_owner && $account_id > 0) |
|
1264 | + { |
|
1265 | + $owners[] = $new_owner; |
|
1266 | + } |
|
1114 | 1267 | $data['owner'] = implode(',', $owners); |
1115 | 1268 | // app_name have to match cat to update! |
1116 | 1269 | if (!isset($cat) || $cat->app_name != $data['appname']) |
@@ -1132,7 +1285,10 @@ discard block |
||
1132 | 1285 | */ |
1133 | 1286 | public static function delete_orphans() |
1134 | 1287 | { |
1135 | - if (is_null(self::$cache)) self::init_cache(); |
|
1288 | + if (is_null(self::$cache)) |
|
1289 | + { |
|
1290 | + self::init_cache(); |
|
1291 | + } |
|
1136 | 1292 | |
1137 | 1293 | $checked = array(); |
1138 | 1294 | $deleted = 0; |
@@ -194,7 +194,7 @@ |
||
194 | 194 | /** |
195 | 195 | * sets a single value in the repositry, you need to call save_repository after |
196 | 196 | * |
197 | - * @param $variable_name string name of the config |
|
197 | + * @param string $variable_name string name of the config |
|
198 | 198 | * @param $variable_data mixed the content |
199 | 199 | */ |
200 | 200 | function value($variable_name,$variable_data) |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | { |
87 | 87 | if (is_array($this->config_data)) |
88 | 88 | { |
89 | - foreach($this->config_data as $name => $value) |
|
89 | + foreach ($this->config_data as $name => $value) |
|
90 | 90 | { |
91 | 91 | self::save_value($name, $value, $this->appname, false); |
92 | 92 | } |
93 | - foreach(self::$configs[$this->appname] as $name => $value) |
|
93 | + foreach (self::$configs[$this->appname] as $name => $value) |
|
94 | 94 | { |
95 | 95 | if (!isset($this->config_data[$name])) // has been deleted |
96 | 96 | { |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
102 | + if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
103 | 103 | { |
104 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
104 | + $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
105 | 105 | } |
106 | 106 | self::$configs[$this->appname] = $this->config_data; |
107 | 107 | |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | * @throws Exception\WrongParameter if no $app parameter given for static call |
123 | 123 | * @return boolean|int true if no change, else number of affected rows |
124 | 124 | */ |
125 | - static function save_value($name, $value, $app, $update_cache=true) |
|
125 | + static function save_value($name, $value, $app, $update_cache = true) |
|
126 | 126 | { |
127 | - if (!$app && (!isset($this) || !is_a($this,__CLASS__))) |
|
127 | + if (!$app && (!isset($this) || !is_a($this, __CLASS__))) |
|
128 | 128 | { |
129 | 129 | throw new Exception\WrongParameter('$app parameter required for static call of Config::save_value($name,$value,$app)!'); |
130 | 130 | } |
131 | - if (!$app || isset($this) && is_a($this,__CLASS__) && $app == $this->appname) |
|
131 | + if (!$app || isset($this) && is_a($this, __CLASS__) && $app == $this->appname) |
|
132 | 132 | { |
133 | 133 | $app = $this->appname; |
134 | 134 | $this->config_data[$name] = $value; |
@@ -140,25 +140,25 @@ discard block |
||
140 | 140 | |
141 | 141 | if (isset(self::$configs[$app][$name]) && self::$configs[$app][$name] === $value) |
142 | 142 | { |
143 | - return True; // no change ==> exit |
|
143 | + return True; // no change ==> exit |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | if (!isset($value) || $value === '') |
147 | 147 | { |
148 | 148 | if (isset(self::$configs[$app])) unset(self::$configs[$app][$name]); |
149 | - self::$db->delete(self::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
|
149 | + self::$db->delete(self::TABLE, array('config_app'=>$app, 'config_name'=>$name), __LINE__, __FILE__); |
|
150 | 150 | } |
151 | 151 | else |
152 | 152 | { |
153 | 153 | self::$configs[$app][$name] = $value; |
154 | - if(is_array($value)) $value = json_encode($value); |
|
155 | - self::$db->insert(self::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
|
154 | + if (is_array($value)) $value = json_encode($value); |
|
155 | + self::$db->insert(self::TABLE, array('config_value'=>$value), array('config_app'=>$app, 'config_name'=>$name), __LINE__, __FILE__); |
|
156 | 156 | } |
157 | 157 | if ($update_cache) |
158 | 158 | { |
159 | - if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
159 | + if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
160 | 160 | { |
161 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
161 | + $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
162 | 162 | } |
163 | 163 | Cache::setInstance(__CLASS__, 'configs', self::$configs); |
164 | 164 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | { |
176 | 176 | self::init_static(); |
177 | 177 | } |
178 | - self::$db->delete(self::TABLE,array('config_app' => $this->appname),__LINE__,__FILE__); |
|
178 | + self::$db->delete(self::TABLE, array('config_app' => $this->appname), __LINE__, __FILE__); |
|
179 | 179 | |
180 | 180 | unset(self::$configs[$this->appname]); |
181 | 181 | Cache::setInstance(__CLASS__, 'configs', self::$configs); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param $variable_name string name of the config |
198 | 198 | * @param $variable_data mixed the content |
199 | 199 | */ |
200 | - function value($variable_name,$variable_data) |
|
200 | + function value($variable_name, $variable_data) |
|
201 | 201 | { |
202 | 202 | $this->config_data[$variable_name] = $variable_data; |
203 | 203 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @deprecated use Api\Storage\Customfields::get() |
229 | 229 | * @return array with customfields |
230 | 230 | */ |
231 | - static function get_customfields($app, $all_private_too=false, $only_type2=null) |
|
231 | + static function get_customfields($app, $all_private_too = false, $only_type2 = null) |
|
232 | 232 | { |
233 | 233 | //error_log(__METHOD__."('$app', $all_private_too, $only_type2) deprecated, use Storage\Customfields::get() in ". function_backtrace()); |
234 | 234 | return Storage\Customfields::get($app, $all_private_too, $only_type2); |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | { |
259 | 259 | static $white_list = array( |
260 | 260 | 'all' => array('customfields', 'types'), |
261 | - 'phpgwapi' => array('webserver_url','server_timezone','enforce_ssl','system_charset', |
|
262 | - 'checkfornewversion','checkappversions','email_address_format', // admin >> site config |
|
263 | - 'site_title','login_logo_file','login_logo_url','login_logo_title','favicon_file', |
|
264 | - 'markuntranslated','link_list_thumbnail','enabled_spellcheck','debug_minify', |
|
265 | - 'call_link','call_popup','geolocation_url', // addressbook |
|
266 | - 'hide_birthdays','calview_no_consolidate', 'egw_tutorial_disable','fw_mobile_app_list'), // calendar |
|
261 | + 'phpgwapi' => array('webserver_url', 'server_timezone', 'enforce_ssl', 'system_charset', |
|
262 | + 'checkfornewversion', 'checkappversions', 'email_address_format', // admin >> site config |
|
263 | + 'site_title', 'login_logo_file', 'login_logo_url', 'login_logo_title', 'favicon_file', |
|
264 | + 'markuntranslated', 'link_list_thumbnail', 'enabled_spellcheck', 'debug_minify', |
|
265 | + 'call_link', 'call_popup', 'geolocation_url', // addressbook |
|
266 | + 'hide_birthdays', 'calview_no_consolidate', 'egw_tutorial_disable', 'fw_mobile_app_list'), // calendar |
|
267 | 267 | 'projectmanager' => array('hours_per_workday', 'duration_units'), |
268 | 268 | 'manual' => array('manual_remote_egw_url'), |
269 | 269 | 'infolog' => array('status'), |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | self::init_static(); |
275 | 275 | } |
276 | 276 | $client_config = array(); |
277 | - foreach(self::$configs as $app => $config) |
|
277 | + foreach (self::$configs as $app => $config) |
|
278 | 278 | { |
279 | - foreach($config as $name => $value) |
|
279 | + foreach ($config as $name => $value) |
|
280 | 280 | { |
281 | 281 | if (strpos($name, 'pass') !== false) continue; |
282 | 282 | |
@@ -314,12 +314,12 @@ discard block |
||
314 | 314 | } |
315 | 315 | // handling of old PHP serialized config values |
316 | 316 | $data = php_safe_unserialize($str); |
317 | - if($data === false) |
|
317 | + if ($data === false) |
|
318 | 318 | { |
319 | 319 | // manually retrieve the string lengths of the serialized array if unserialize failed (iso / utf-8 conversation) |
320 | 320 | $data = php_safe_unserialize(preg_replace_callback('!s:(\d+):"(.*?)";!s', function($matches) |
321 | 321 | { |
322 | - return 's:'.mb_strlen($matches[2],'8bit').':"'.$matches[2].'";'; |
|
322 | + return 's:'.mb_strlen($matches[2], '8bit').':"'.$matches[2].'";'; |
|
323 | 323 | }, $str)); |
324 | 324 | } |
325 | 325 | // returning original string, if unserialize failed, eg. for "a:hello" |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | if (!(self::$configs = Cache::getInstance(__CLASS__, 'configs')) || !is_array(self::$configs['phpgwapi'])) |
345 | 345 | { |
346 | 346 | self::$configs = array(); |
347 | - foreach(self::$db->select(self::TABLE,'*',false,__LINE__,__FILE__) as $row) |
|
347 | + foreach (self::$db->select(self::TABLE, '*', false, __LINE__, __FILE__) as $row) |
|
348 | 348 | { |
349 | 349 | self::$configs[$row['config_app']][$row['config_name']] = self::unserialize($row['config_value']); |
350 | 350 | //error_log(__METHOD__."() configs[$row[config_app]][$row[config_name]]=".array2string(self::$configs[$row['config_app']][$row['config_name']])); |
@@ -92,16 +92,23 @@ discard block |
||
92 | 92 | } |
93 | 93 | foreach(self::$configs[$this->appname] as $name => $value) |
94 | 94 | { |
95 | - if (!isset($this->config_data[$name])) // has been deleted |
|
95 | + if (!isset($this->config_data[$name])) |
|
96 | + { |
|
97 | + // has been deleted |
|
96 | 98 | { |
97 | 99 | self::save_value($name, null, $this->appname, false); |
100 | + } |
|
98 | 101 | //self::$db->delete(self::TABLE,array('config_app'=>$this->appname,'config_name'=>$name),__LINE__,__FILE__); |
99 | 102 | } |
100 | 103 | } |
101 | 104 | |
102 | - if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
105 | + if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
106 | + { |
|
107 | + // egw object in setup is limited |
|
103 | 108 | { |
104 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
109 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
110 | + } |
|
111 | + // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
105 | 112 | } |
106 | 113 | self::$configs[$this->appname] = $this->config_data; |
107 | 114 | |
@@ -145,20 +152,30 @@ discard block |
||
145 | 152 | |
146 | 153 | if (!isset($value) || $value === '') |
147 | 154 | { |
148 | - if (isset(self::$configs[$app])) unset(self::$configs[$app][$name]); |
|
155 | + if (isset(self::$configs[$app])) |
|
156 | + { |
|
157 | + unset(self::$configs[$app][$name]); |
|
158 | + } |
|
149 | 159 | self::$db->delete(self::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
150 | 160 | } |
151 | 161 | else |
152 | 162 | { |
153 | 163 | self::$configs[$app][$name] = $value; |
154 | - if(is_array($value)) $value = json_encode($value); |
|
164 | + if(is_array($value)) |
|
165 | + { |
|
166 | + $value = json_encode($value); |
|
167 | + } |
|
155 | 168 | self::$db->insert(self::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
156 | 169 | } |
157 | 170 | if ($update_cache) |
158 | 171 | { |
159 | - if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
172 | + if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
173 | + { |
|
174 | + // egw object in setup is limited |
|
160 | 175 | { |
161 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
176 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
177 | + } |
|
178 | + // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
162 | 179 | } |
163 | 180 | Cache::setInstance(__CLASS__, 'configs', self::$configs); |
164 | 181 | } |
@@ -278,7 +295,10 @@ discard block |
||
278 | 295 | { |
279 | 296 | foreach($config as $name => $value) |
280 | 297 | { |
281 | - if (strpos($name, 'pass') !== false) continue; |
|
298 | + if (strpos($name, 'pass') !== false) |
|
299 | + { |
|
300 | + continue; |
|
301 | + } |
|
282 | 302 | |
283 | 303 | if (in_array($name, $white_list['all']) || isset($white_list[$app]) && in_array($name, $white_list[$app])) |
284 | 304 | { |
@@ -484,7 +484,6 @@ discard block |
||
484 | 484 | /** |
485 | 485 | * get selectbox options for the customfields |
486 | 486 | * |
487 | - * @param array $field =null |
|
488 | 487 | * @return array with options: |
489 | 488 | */ |
490 | 489 | public static function cf_options() |
@@ -536,7 +535,7 @@ discard block |
||
536 | 535 | * @param string $fileas_type '' or type of $this->fileas_types |
537 | 536 | * @param int $all =false update all contacts or only ones with empty values |
538 | 537 | * @param int &$errors=null on return number of errors |
539 | - * @return int|boolean number of contacts updated, false for wrong fileas type |
|
538 | + * @return string|null number of contacts updated, false for wrong fileas type |
|
540 | 539 | */ |
541 | 540 | function set_all_fileas($fileas_type,$all=false,&$errors=null,$ignore_acl=false) |
542 | 541 | { |
@@ -597,7 +596,7 @@ discard block |
||
597 | 596 | * remove unneeded carriage returns or set empty fields to NULL |
598 | 597 | * |
599 | 598 | * @param int &$errors=null on return number of errors |
600 | - * @return int|boolean number of contacts updated |
|
599 | + * @return integer number of contacts updated |
|
601 | 600 | */ |
602 | 601 | function set_all_cleanup(&$errors=null,$ignore_acl=false) |
603 | 602 | { |
@@ -1122,7 +1121,7 @@ discard block |
||
1122 | 1121 | * @param mixed $contact contact as array or the contact-id |
1123 | 1122 | * @param boolean $deny_account_delete =false if true never allow to delete accounts |
1124 | 1123 | * @param int $user =null for which user to check, default current user |
1125 | - * @return boolean true permission granted, false for permission denied, null for contact does not exist |
|
1124 | + * @return null|boolean true permission granted, false for permission denied, null for contact does not exist |
|
1126 | 1125 | */ |
1127 | 1126 | function check_perms($needed,$contact,$deny_account_delete=false,$user=null) |
1128 | 1127 | { |
@@ -1179,7 +1178,7 @@ discard block |
||
1179 | 1178 | * @param int $check Acl::READ for read and Acl::EDIT for write or delete access |
1180 | 1179 | * @param string $rel_path =null currently not used in InfoLog |
1181 | 1180 | * @param int $user =null for which user to check, default current user |
1182 | - * @return boolean true if access is granted or false otherwise |
|
1181 | + * @return null|boolean true if access is granted or false otherwise |
|
1183 | 1182 | */ |
1184 | 1183 | function file_access($id,$check,$rel_path=null,$user=null) |
1185 | 1184 | { |
@@ -2094,6 +2093,9 @@ discard block |
||
2094 | 2093 | return $cat_id_list; |
2095 | 2094 | } |
2096 | 2095 | |
2096 | + /** |
|
2097 | + * @param string $cat_id_list |
|
2098 | + */ |
|
2097 | 2099 | function get_categories($cat_id_list) |
2098 | 2100 | { |
2099 | 2101 | if (!is_object($this->categories)) |
@@ -145,19 +145,19 @@ discard block |
||
145 | 145 | var $categories; |
146 | 146 | |
147 | 147 | /** |
148 | - * Tracking changes |
|
149 | - * |
|
150 | - * @var Contacts\Tracking |
|
151 | - */ |
|
148 | + * Tracking changes |
|
149 | + * |
|
150 | + * @var Contacts\Tracking |
|
151 | + */ |
|
152 | 152 | protected $tracking; |
153 | 153 | |
154 | 154 | /** |
155 | - * Keep deleted addresses, or really delete them |
|
156 | - * Set in Admin -> Addressbook -> Site Configuration |
|
157 | - * ''=really delete, 'history'=keep, only admins delete, 'userpurge'=keep, users delete |
|
158 | - * |
|
159 | - * @var string |
|
160 | - */ |
|
155 | + * Keep deleted addresses, or really delete them |
|
156 | + * Set in Admin -> Addressbook -> Site Configuration |
|
157 | + * ''=really delete, 'history'=keep, only admins delete, 'userpurge'=keep, users delete |
|
158 | + * |
|
159 | + * @var string |
|
160 | + */ |
|
161 | 161 | protected $delete_history = ''; |
162 | 162 | |
163 | 163 | /** |
@@ -786,13 +786,13 @@ discard block |
||
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
789 | - * deletes contact in db |
|
790 | - * |
|
791 | - * @param mixed &$contact contact array with key id or (array of) id(s) |
|
792 | - * @param boolean $deny_account_delete =true if true never allow to delete accounts |
|
793 | - * @param int $check_etag =null |
|
794 | - * @return boolean|int true on success or false on failiure, 0 if etag does not match |
|
795 | - */ |
|
789 | + * deletes contact in db |
|
790 | + * |
|
791 | + * @param mixed &$contact contact array with key id or (array of) id(s) |
|
792 | + * @param boolean $deny_account_delete =true if true never allow to delete accounts |
|
793 | + * @param int $check_etag =null |
|
794 | + * @return boolean|int true on success or false on failiure, 0 if etag does not match |
|
795 | + */ |
|
796 | 796 | function delete($contact,$deny_account_delete=true,$check_etag=null) |
797 | 797 | { |
798 | 798 | if (is_array($contact) && isset($contact['id'])) |
@@ -844,12 +844,12 @@ discard block |
||
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
847 | - * saves contact to db |
|
848 | - * |
|
849 | - * @param array &$contact contact array from etemplate::exec |
|
850 | - * @param boolean $ignore_acl =false should the acl be checked or not |
|
851 | - * @return int/string/boolean id on success, false on failure, the error-message is in $this->error |
|
852 | - */ |
|
847 | + * saves contact to db |
|
848 | + * |
|
849 | + * @param array &$contact contact array from etemplate::exec |
|
850 | + * @param boolean $ignore_acl =false should the acl be checked or not |
|
851 | + * @return int/string/boolean id on success, false on failure, the error-message is in $this->error |
|
852 | + */ |
|
853 | 853 | function save(&$contact,$ignore_acl=false) |
854 | 854 | { |
855 | 855 | // remember if we add or update a entry |
@@ -1069,12 +1069,12 @@ discard block |
||
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | /** |
1072 | - * reads contacts matched by key and puts all cols in the data array |
|
1073 | - * |
|
1074 | - * @param int|string $contact_id |
|
1075 | - * @param boolean $ignore_acl =false true: no acl check |
|
1076 | - * @return array|boolean array with contact data, null if not found or false on no view perms |
|
1077 | - */ |
|
1072 | + * reads contacts matched by key and puts all cols in the data array |
|
1073 | + * |
|
1074 | + * @param int|string $contact_id |
|
1075 | + * @param boolean $ignore_acl =false true: no acl check |
|
1076 | + * @return array|boolean array with contact data, null if not found or false on no view perms |
|
1077 | + */ |
|
1078 | 1078 | function read($contact_id, $ignore_acl=false) |
1079 | 1079 | { |
1080 | 1080 | // get so_sql_cf to read private customfields too, if we ignore acl |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | namespace EGroupware\Api; |
18 | 18 | |
19 | -use calendar_bo; // to_do: do NOT require it, just use if there |
|
19 | +use calendar_bo; // to_do: do NOT require it, just use if there |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Business object for contacts |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @var array $timestamps timestamps |
33 | 33 | */ |
34 | - var $timestamps = array('modified','created'); |
|
34 | + var $timestamps = array('modified', 'created'); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @var array $fileas_types |
@@ -166,28 +166,28 @@ discard block |
||
166 | 166 | * @param string $contact_app ='addressbook' used for acl->get_grants() |
167 | 167 | * @param Db $db =null |
168 | 168 | */ |
169 | - function __construct($contact_app='addressbook',Db $db=null) |
|
169 | + function __construct($contact_app = 'addressbook', Db $db = null) |
|
170 | 170 | { |
171 | - parent::__construct($contact_app,$db); |
|
171 | + parent::__construct($contact_app, $db); |
|
172 | 172 | if ($this->log) |
173 | 173 | { |
174 | 174 | $this->logfile = $GLOBALS['egw_info']['server']['temp_dir'].'/log-addressbook_bo'; |
175 | - error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($contact_app)\n", 3 ,$this->logfile); |
|
175 | + error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($contact_app)\n", 3, $this->logfile); |
|
176 | 176 | } |
177 | 177 | |
178 | - $this->now_su = DateTime::to('now','ts'); |
|
178 | + $this->now_su = DateTime::to('now', 'ts'); |
|
179 | 179 | |
180 | - $this->prefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook']; |
|
180 | + $this->prefs = & $GLOBALS['egw_info']['user']['preferences']['addressbook']; |
|
181 | 181 | // get the default addressbook from the users prefs |
182 | 182 | $this->default_addressbook = $GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] ? |
183 | 183 | (int)$GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] : $this->user; |
184 | - $this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'],-1) == 'p'; |
|
184 | + $this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'], -1) == 'p'; |
|
185 | 185 | if ($this->default_addressbook > 0 && $this->default_addressbook != $this->user && |
186 | 186 | ($this->default_private || |
187 | 187 | $this->default_addressbook == (int)$GLOBALS['egw']->preferences->forced['addressbook']['add_default'] || |
188 | 188 | $this->default_addressbook == (int)$GLOBALS['egw']->preferences->default['addressbook']['add_default'])) |
189 | 189 | { |
190 | - $this->default_addressbook = $this->user; // admin set a default or forced pref for personal addressbook |
|
190 | + $this->default_addressbook = $this->user; // admin set a default or forced pref for personal addressbook |
|
191 | 191 | } |
192 | 192 | $this->private_addressbook = self::private_addressbook($this->contact_repository == 'sql', $this->prefs); |
193 | 193 | |
@@ -292,27 +292,27 @@ discard block |
||
292 | 292 | $this->own_account_acl = $GLOBALS['egw_info']['server']['own_account_acl']; |
293 | 293 | if (!is_array($this->own_account_acl)) $this->own_account_acl = json_php_unserialize($this->own_account_acl, true); |
294 | 294 | // we have only one acl (n_fn) for the whole name, as not all backends store every part in an own field |
295 | - if ($this->own_account_acl && in_array('n_fn',$this->own_account_acl)) |
|
295 | + if ($this->own_account_acl && in_array('n_fn', $this->own_account_acl)) |
|
296 | 296 | { |
297 | - $this->own_account_acl = array_merge($this->own_account_acl,array('n_prefix','n_given','n_middle','n_family','n_suffix')); |
|
297 | + $this->own_account_acl = array_merge($this->own_account_acl, array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix')); |
|
298 | 298 | } |
299 | 299 | if ($GLOBALS['egw_info']['server']['org_fileds_to_update']) |
300 | 300 | { |
301 | - $this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update']; |
|
301 | + $this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update']; |
|
302 | 302 | if (!is_array($this->org_fields)) $this->org_fields = unserialize($this->org_fields); |
303 | 303 | |
304 | 304 | // Set country code if country name is selected |
305 | - $supported_fields = $this->get_fields('supported',null,0); |
|
306 | - if(in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname',$this->org_fields)) |
|
305 | + $supported_fields = $this->get_fields('supported', null, 0); |
|
306 | + if (in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname', $this->org_fields)) |
|
307 | 307 | { |
308 | 308 | $this->org_fields[] = 'adr_one_countrycode'; |
309 | 309 | } |
310 | - if(in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname',$this->org_fields)) |
|
310 | + if (in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname', $this->org_fields)) |
|
311 | 311 | { |
312 | 312 | $this->org_fields[] = 'adr_two_countrycode'; |
313 | 313 | } |
314 | 314 | } |
315 | - $this->categories = new Categories($this->user,'addressbook'); |
|
315 | + $this->categories = new Categories($this->user, 'addressbook'); |
|
316 | 316 | |
317 | 317 | $this->delete_history = $GLOBALS['egw_info']['server']['history']; |
318 | 318 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @param array $prefs addressbook preferences |
327 | 327 | * @return boolean |
328 | 328 | */ |
329 | - public static function private_addressbook($contact_repository, array $prefs=null) |
|
329 | + public static function private_addressbook($contact_repository, array $prefs = null) |
|
330 | 330 | { |
331 | 331 | return $contact_repository == 'sql' && $prefs['private_addressbook']; |
332 | 332 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | * @param int $user =null account_id or null for current user |
341 | 341 | * @return array with owner => label pairs |
342 | 342 | */ |
343 | - function get_addressbooks($required=Acl::READ,$extra_label=null,$user=null) |
|
343 | + function get_addressbooks($required = Acl::READ, $extra_label = null, $user = null) |
|
344 | 344 | { |
345 | 345 | if (is_null($user)) |
346 | 346 | { |
@@ -359,11 +359,11 @@ discard block |
||
359 | 359 | if ($extra_label) $addressbooks[''] = $extra_label; |
360 | 360 | $addressbooks[$user] = lang('Personal'); |
361 | 361 | // add all group addressbooks the user has the necessary rights too |
362 | - foreach($grants as $uid => $rights) |
|
362 | + foreach ($grants as $uid => $rights) |
|
363 | 363 | { |
364 | - if (($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g') |
|
364 | + if (($rights&$required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g') |
|
365 | 365 | { |
366 | - $to_sort[$uid] = lang('Group %1',$GLOBALS['egw']->accounts->id2name($uid)); |
|
366 | + $to_sort[$uid] = lang('Group %1', $GLOBALS['egw']->accounts->id2name($uid)); |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | if ($to_sort) |
@@ -371,19 +371,19 @@ discard block |
||
371 | 371 | asort($to_sort); |
372 | 372 | $addressbooks += $to_sort; |
373 | 373 | } |
374 | - if ($required != Acl::ADD && // do NOT allow to set accounts as default addressbook (AB can add accounts) |
|
374 | + if ($required != Acl::ADD && // do NOT allow to set accounts as default addressbook (AB can add accounts) |
|
375 | 375 | !$preferences['addressbook']['hide_accounts'] && ( |
376 | - ($grants[0] & $required) == $required || |
|
376 | + ($grants[0]&$required) == $required || |
|
377 | 377 | $preferences['common']['account_selection'] == 'groupmembers' && |
378 | - $this->account_repository != 'ldap' && ($required & Acl::READ))) |
|
378 | + $this->account_repository != 'ldap' && ($required&Acl::READ))) |
|
379 | 379 | { |
380 | 380 | $addressbooks[0] = lang('Accounts'); |
381 | 381 | } |
382 | 382 | // add all other user addressbooks the user has the necessary rights too |
383 | 383 | $to_sort = array(); |
384 | - foreach($grants as $uid => $rights) |
|
384 | + foreach ($grants as $uid => $rights) |
|
385 | 385 | { |
386 | - if ($uid != $user && ($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u') |
|
386 | + if ($uid != $user && ($rights&$required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u') |
|
387 | 387 | { |
388 | 388 | $to_sort[$uid] = Accounts::username($uid); |
389 | 389 | } |
@@ -408,22 +408,22 @@ discard block |
||
408 | 408 | * @param boolean $isUpdate =false If true, reads the old record for any not set fields |
409 | 409 | * @return string |
410 | 410 | */ |
411 | - function fileas($contact,$type=null, $isUpdate=false) |
|
411 | + function fileas($contact, $type = null, $isUpdate = false) |
|
412 | 412 | { |
413 | 413 | if (is_null($type)) $type = $contact['fileas_type']; |
414 | 414 | if (!$type) $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0]; |
415 | 415 | |
416 | - if (strpos($type,'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact); |
|
416 | + if (strpos($type, 'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact); |
|
417 | 417 | |
418 | - if($isUpdate) |
|
418 | + if ($isUpdate) |
|
419 | 419 | { |
420 | - $fileas_fields = array('n_prefix','n_given','n_middle','n_family','n_suffix','n_fn','org_name','org_unit','adr_one_locality','bday'); |
|
420 | + $fileas_fields = array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix', 'n_fn', 'org_name', 'org_unit', 'adr_one_locality', 'bday'); |
|
421 | 421 | $old = null; |
422 | - foreach($fileas_fields as $field) |
|
422 | + foreach ($fileas_fields as $field) |
|
423 | 423 | { |
424 | - if(!isset($contact[$field])) |
|
424 | + if (!isset($contact[$field])) |
|
425 | 425 | { |
426 | - if(is_null($old)) $old = $this->read($contact['id']); |
|
426 | + if (is_null($old)) $old = $this->read($contact['id']); |
|
427 | 427 | $contact[$field] = $old[$field]; |
428 | 428 | } |
429 | 429 | } |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | } |
432 | 432 | |
433 | 433 | // removing empty delimiters, caused by empty contact fields |
434 | - $fileas = str_replace(array(', , : ',', : ',': , ',', , ',': : ',' ()'), |
|
435 | - array(': ',': ',': ',', ',': ',''), |
|
434 | + $fileas = str_replace(array(', , : ', ', : ', ': , ', ', , ', ': : ', ' ()'), |
|
435 | + array(': ', ': ', ': ', ', ', ': ', ''), |
|
436 | 436 | strtr($type, array( |
437 | 437 | 'n_prefix' => $contact['n_prefix'], |
438 | 438 | 'n_given' => $contact['n_given'], |
@@ -446,13 +446,13 @@ discard block |
||
446 | 446 | 'bday' => (int)$contact['bday'] ? DateTime::to($contact['bday'], true) : $contact['bday'], |
447 | 447 | ))); |
448 | 448 | |
449 | - while ($fileas[0] == ':' || $fileas[0] == ',') |
|
449 | + while ($fileas[0] == ':' || $fileas[0] == ',') |
|
450 | 450 | { |
451 | - $fileas = substr($fileas,2); |
|
451 | + $fileas = substr($fileas, 2); |
|
452 | 452 | } |
453 | - while (substr($fileas,-2) == ': ' || substr($fileas,-2) == ', ') |
|
453 | + while (substr($fileas, -2) == ': ' || substr($fileas, -2) == ', ') |
|
454 | 454 | { |
455 | - $fileas = substr($fileas,0,-2); |
|
455 | + $fileas = substr($fileas, 0, -2); |
|
456 | 456 | } |
457 | 457 | return $fileas; |
458 | 458 | } |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | * @param string $file_as =null file_as type, default null to read it from the contact, unknown/not set type default to the first one |
465 | 465 | * @return string |
466 | 466 | */ |
467 | - function fileas_type($contact,$file_as=null) |
|
467 | + function fileas_type($contact, $file_as = null) |
|
468 | 468 | { |
469 | 469 | if (is_null($file_as)) $file_as = $contact['n_fileas']; |
470 | 470 | |
471 | 471 | if ($file_as) |
472 | 472 | { |
473 | - foreach($this->fileas_types as $type) |
|
473 | + foreach ($this->fileas_types as $type) |
|
474 | 474 | { |
475 | - if ($this->fileas($contact,$type) == $file_as) |
|
475 | + if ($this->fileas($contact, $type) == $file_as) |
|
476 | 476 | { |
477 | 477 | return $type; |
478 | 478 | } |
@@ -489,10 +489,10 @@ discard block |
||
489 | 489 | */ |
490 | 490 | public static function cf_options() |
491 | 491 | { |
492 | - $cf_fields = Storage\Customfields::get('addressbook',TRUE); |
|
493 | - foreach ($cf_fields as $key => $value ) |
|
492 | + $cf_fields = Storage\Customfields::get('addressbook', TRUE); |
|
493 | + foreach ($cf_fields as $key => $value) |
|
494 | 494 | { |
495 | - $options[$key]= $value['label']; |
|
495 | + $options[$key] = $value['label']; |
|
496 | 496 | } |
497 | 497 | return $options; |
498 | 498 | } |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @param array $contact =null real content to use, default none |
504 | 504 | * @return array with options: fileas type => label pairs |
505 | 505 | */ |
506 | - function fileas_options($contact=null) |
|
506 | + function fileas_options($contact = null) |
|
507 | 507 | { |
508 | 508 | $labels = array( |
509 | 509 | 'n_prefix' => lang('prefix'), |
@@ -517,13 +517,13 @@ discard block |
||
517 | 517 | 'adr_one_locality' => lang('city'), |
518 | 518 | 'bday' => lang('Birthday'), |
519 | 519 | ); |
520 | - foreach(array_keys($labels) as $name) |
|
520 | + foreach (array_keys($labels) as $name) |
|
521 | 521 | { |
522 | 522 | if ($contact[$name]) $labels[$name] = $contact[$name]; |
523 | 523 | } |
524 | - foreach($this->fileas_types as $fileas_type) |
|
524 | + foreach ($this->fileas_types as $fileas_type) |
|
525 | 525 | { |
526 | - $options[$fileas_type] = $this->fileas($labels,$fileas_type); |
|
526 | + $options[$fileas_type] = $this->fileas($labels, $fileas_type); |
|
527 | 527 | } |
528 | 528 | return $options; |
529 | 529 | } |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | * @param int &$errors=null on return number of errors |
539 | 539 | * @return int|boolean number of contacts updated, false for wrong fileas type |
540 | 540 | */ |
541 | - function set_all_fileas($fileas_type,$all=false,&$errors=null,$ignore_acl=false) |
|
541 | + function set_all_fileas($fileas_type, $all = false, &$errors = null, $ignore_acl = false) |
|
542 | 542 | { |
543 | 543 | if ($fileas_type != '' && !in_array($fileas_type, $this->fileas_types)) |
544 | 544 | { |
@@ -546,17 +546,17 @@ discard block |
||
546 | 546 | } |
547 | 547 | if ($ignore_acl) |
548 | 548 | { |
549 | - unset($this->somain->grants); // to NOT limit search to contacts readable by current user |
|
549 | + unset($this->somain->grants); // to NOT limit search to contacts readable by current user |
|
550 | 550 | } |
551 | 551 | // to be able to work on huge contact repositories we read the contacts in chunks of 100 |
552 | - for($n = $updated = $errors = 0; ($contacts = parent::search($all ? array() : array( |
|
552 | + for ($n = $updated = $errors = 0; ($contacts = parent::search($all ? array() : array( |
|
553 | 553 | 'n_fileas IS NULL', |
554 | 554 | "n_fileas=''", |
555 | 555 | 'n_fn IS NULL', |
556 | 556 | "n_fn=''", |
557 | - ),false,'','','',false,'OR',array($n*100,100))); ++$n) |
|
557 | + ), false, '', '', '', false, 'OR', array($n * 100, 100))); ++$n) |
|
558 | 558 | { |
559 | - foreach($contacts as $contact) |
|
559 | + foreach ($contacts as $contact) |
|
560 | 560 | { |
561 | 561 | $old_fn = $contact['n_fn']; |
562 | 562 | $old_fileas = $contact['n_fileas']; |
@@ -564,19 +564,19 @@ discard block |
||
564 | 564 | // only update fileas if type is given AND (all should be updated or n_fileas is empty) |
565 | 565 | if ($fileas_type && ($all || empty($contact['n_fileas']))) |
566 | 566 | { |
567 | - $contact['n_fileas'] = $this->fileas($contact,$fileas_type); |
|
567 | + $contact['n_fileas'] = $this->fileas($contact, $fileas_type); |
|
568 | 568 | } |
569 | 569 | if ($old_fileas != $contact['n_fileas'] || $old_fn != $contact['n_fn']) |
570 | 570 | { |
571 | 571 | // only specify/write updated fields plus "keys" |
572 | - $contact = array_intersect_key($contact,array( |
|
572 | + $contact = array_intersect_key($contact, array( |
|
573 | 573 | 'id' => true, |
574 | 574 | 'owner' => true, |
575 | 575 | 'private' => true, |
576 | 576 | 'account_id' => true, |
577 | 577 | 'uid' => true, |
578 | - )+($old_fileas != $contact['n_fileas'] ? array('n_fileas' => true) : array())+($old_fn != $contact['n_fn'] ? array('n_fn' => true) : array())); |
|
579 | - if ($this->save($contact,$ignore_acl)) |
|
578 | + ) + ($old_fileas != $contact['n_fileas'] ? array('n_fileas' => true) : array()) + ($old_fn != $contact['n_fn'] ? array('n_fn' => true) : array())); |
|
579 | + if ($this->save($contact, $ignore_acl)) |
|
580 | 580 | { |
581 | 581 | $updated++; |
582 | 582 | } |
@@ -599,11 +599,11 @@ discard block |
||
599 | 599 | * @param int &$errors=null on return number of errors |
600 | 600 | * @return int|boolean number of contacts updated |
601 | 601 | */ |
602 | - function set_all_cleanup(&$errors=null,$ignore_acl=false) |
|
602 | + function set_all_cleanup(&$errors = null, $ignore_acl = false) |
|
603 | 603 | { |
604 | 604 | if ($ignore_acl) |
605 | 605 | { |
606 | - unset($this->somain->grants); // to NOT limit search to contacts readable by current user |
|
606 | + unset($this->somain->grants); // to NOT limit search to contacts readable by current user |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | // fields that must not be touched |
@@ -625,14 +625,14 @@ discard block |
||
625 | 625 | ); |
626 | 626 | |
627 | 627 | // to be able to work on huge contact repositories we read the contacts in chunks of 100 |
628 | - for($n = $updated = $errors = 0; ($contacts = parent::search(array(),false,'','','',false,'OR',array($n*100,100))); ++$n) |
|
628 | + for ($n = $updated = $errors = 0; ($contacts = parent::search(array(), false, '', '', '', false, 'OR', array($n * 100, 100))); ++$n) |
|
629 | 629 | { |
630 | - foreach($contacts as $contact) |
|
630 | + foreach ($contacts as $contact) |
|
631 | 631 | { |
632 | 632 | $fields_to_update = array(); |
633 | - foreach($contact as $field_name => $field_value) |
|
633 | + foreach ($contact as $field_name => $field_value) |
|
634 | 634 | { |
635 | - if($fields_exclude[$field_name] === true) continue; // dont touch specified field |
|
635 | + if ($fields_exclude[$field_name] === true) continue; // dont touch specified field |
|
636 | 636 | |
637 | 637 | if (is_string($field_value) && $field_name != 'pubkey' && $field_name != 'jpegphoto') |
638 | 638 | { |
@@ -642,9 +642,9 @@ discard block |
||
642 | 642 | $fields_to_update[$field_name] = $field_value = trim($field_value); |
643 | 643 | } |
644 | 644 | // check if field contains a carriage return - exclude notes |
645 | - if ($field_name != 'note' && strpos($field_value,"\x0D\x0A") !== false) |
|
645 | + if ($field_name != 'note' && strpos($field_value, "\x0D\x0A") !== false) |
|
646 | 646 | { |
647 | - $fields_to_update[$field_name] = $field_value = str_replace("\x0D\x0A"," ",$field_value); |
|
647 | + $fields_to_update[$field_name] = $field_value = str_replace("\x0D\x0A", " ", $field_value); |
|
648 | 648 | } |
649 | 649 | } |
650 | 650 | // check if a field contains an empty string |
@@ -654,13 +654,13 @@ discard block |
||
654 | 654 | } |
655 | 655 | // check for valid birthday date |
656 | 656 | if ($field_name == 'bday' && $field_value != null && |
657 | - !preg_match('/^(18|19|20|21|22)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/',$field_value)) |
|
657 | + !preg_match('/^(18|19|20|21|22)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $field_value)) |
|
658 | 658 | { |
659 | 659 | $fields_to_update[$field_name] = $field_value = null; |
660 | 660 | } |
661 | 661 | } |
662 | 662 | |
663 | - if(count($fields_to_update) > 0) |
|
663 | + if (count($fields_to_update) > 0) |
|
664 | 664 | { |
665 | 665 | $contact_to_save = array( |
666 | 666 | 'id' => $contact['id'], |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | 'account_id' => $contact['account_id'], |
670 | 670 | 'uid' => $contact['uid']) + $fields_to_update; |
671 | 671 | |
672 | - if ($this->save($contact_to_save,$ignore_acl)) |
|
672 | + if ($this->save($contact_to_save, $ignore_acl)) |
|
673 | 673 | { |
674 | 674 | $updated++; |
675 | 675 | } |
@@ -694,14 +694,14 @@ discard block |
||
694 | 694 | if (empty($contact['n_family']) && empty($contact['n_given'])) { |
695 | 695 | $cpart = array('org_name'); |
696 | 696 | } else { |
697 | - $cpart = array('n_prefix','n_given','n_middle','n_family','n_suffix'); |
|
697 | + $cpart = array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix'); |
|
698 | 698 | } |
699 | 699 | $parts = array(); |
700 | - foreach($cpart as $n) |
|
700 | + foreach ($cpart as $n) |
|
701 | 701 | { |
702 | 702 | if ($contact[$n]) $parts[] = $contact[$n]; |
703 | 703 | } |
704 | - return implode(' ',$parts); |
|
704 | + return implode(' ', $parts); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | /** |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | * |
716 | 716 | * @return array updated data |
717 | 717 | */ |
718 | - function db2data($data, $date_format='ts') |
|
718 | + function db2data($data, $date_format = 'ts') |
|
719 | 719 | { |
720 | 720 | static $fb_url = false; |
721 | 721 | |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | $data[$name] = DateTime::server2user($data[$name], $date_format); |
728 | 728 | } |
729 | 729 | } |
730 | - $data['photo'] = $this->photo_src($data['id'],$data['jpegphoto'],'',$data['etag']); |
|
730 | + $data['photo'] = $this->photo_src($data['id'], $data['jpegphoto'], '', $data['etag']); |
|
731 | 731 | |
732 | 732 | // set freebusy_uri for accounts |
733 | 733 | if (!$data['freebusy_uri'] && !$data['owner'] && $data['account_id'] && !is_object($GLOBALS['egw_setup'])) |
@@ -750,13 +750,13 @@ discard block |
||
750 | 750 | * @param string $etag =null etag to set in url to allow caching with Expires header |
751 | 751 | * @return string/array |
752 | 752 | */ |
753 | - function photo_src($id,$jpeg,$default='',$etag=null) |
|
753 | + function photo_src($id, $jpeg, $default = '', $etag = null) |
|
754 | 754 | { |
755 | 755 | //error_log(__METHOD__."($id, ..., etag=$etag) ". function_backtrace()); |
756 | 756 | return $jpeg ? array( |
757 | 757 | 'menuaction' => 'addressbook.addressbook_ui.photo', |
758 | 758 | 'contact_id' => $id, |
759 | - )+(isset($etag) ? array( |
|
759 | + ) + (isset($etag) ? array( |
|
760 | 760 | 'etag' => $etag, |
761 | 761 | ) : array()) : $default; |
762 | 762 | } |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | * |
773 | 773 | * @return array upated data |
774 | 774 | */ |
775 | - function data2db($data, $date_format='ts') |
|
775 | + function data2db($data, $date_format = 'ts') |
|
776 | 776 | { |
777 | 777 | // convert timestamps from user-time to server-time in the db |
778 | 778 | foreach ($this->timestamps as $name) |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | * @param int $check_etag =null |
794 | 794 | * @return boolean|int true on success or false on failiure, 0 if etag does not match |
795 | 795 | */ |
796 | - function delete($contact,$deny_account_delete=true,$check_etag=null) |
|
796 | + function delete($contact, $deny_account_delete = true, $check_etag = null) |
|
797 | 797 | { |
798 | 798 | if (is_array($contact) && isset($contact['id'])) |
799 | 799 | { |
@@ -803,12 +803,12 @@ discard block |
||
803 | 803 | { |
804 | 804 | $contact = array($contact); |
805 | 805 | } |
806 | - foreach($contact as $c) |
|
806 | + foreach ($contact as $c) |
|
807 | 807 | { |
808 | 808 | $id = is_array($c) ? $c['id'] : $c; |
809 | 809 | |
810 | 810 | $ok = false; |
811 | - if ($this->check_perms(Acl::DELETE,$c,$deny_account_delete)) |
|
811 | + if ($this->check_perms(Acl::DELETE, $c, $deny_account_delete)) |
|
812 | 812 | { |
813 | 813 | if (!($old = $this->read($id))) return false; |
814 | 814 | // check if we only mark contacts as deleted, or really delete them |
@@ -819,12 +819,12 @@ discard block |
||
819 | 819 | $delete = $old; |
820 | 820 | $delete['tid'] = self::DELETED_TYPE; |
821 | 821 | if ($check_etag) $delete['etag'] = $check_etag; |
822 | - if (($ok = $this->save($delete))) $ok = true; // we have to return true or false |
|
823 | - Link::unlink(0,'addressbook',$id,'','','',true); |
|
822 | + if (($ok = $this->save($delete))) $ok = true; // we have to return true or false |
|
823 | + Link::unlink(0, 'addressbook', $id, '', '', '', true); |
|
824 | 824 | } |
825 | - elseif (($ok = parent::delete($id,$check_etag))) |
|
825 | + elseif (($ok = parent::delete($id, $check_etag))) |
|
826 | 826 | { |
827 | - Link::unlink(0,'addressbook',$id); |
|
827 | + Link::unlink(0, 'addressbook', $id); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | // Don't notify of final purge |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | * @param boolean $ignore_acl =false should the acl be checked or not |
851 | 851 | * @return int/string/boolean id on success, false on failure, the error-message is in $this->error |
852 | 852 | */ |
853 | - function save(&$contact,$ignore_acl=false) |
|
853 | + function save(&$contact, $ignore_acl = false) |
|
854 | 854 | { |
855 | 855 | // remember if we add or update a entry |
856 | 856 | if (($isUpdate = $contact['id'])) |
@@ -859,11 +859,11 @@ discard block |
||
859 | 859 | { |
860 | 860 | if (($old = $this->read($contact['id']))) // --> try reading the old entry and set it from there |
861 | 861 | { |
862 | - if(!isset($contact['owner'])) |
|
862 | + if (!isset($contact['owner'])) |
|
863 | 863 | { |
864 | 864 | $contact['owner'] = $old['owner']; |
865 | 865 | } |
866 | - if(!isset($contact['private'])) |
|
866 | + if (!isset($contact['private'])) |
|
867 | 867 | { |
868 | 868 | $contact['private'] = $old['private']; |
869 | 869 | } |
@@ -895,7 +895,7 @@ discard block |
||
895 | 895 | { |
896 | 896 | $contact['private'] = 0; |
897 | 897 | } |
898 | - if(!$ignore_acl && !$this->check_perms($isUpdate ? Acl::EDIT : Acl::ADD,$contact)) |
|
898 | + if (!$ignore_acl && !$this->check_perms($isUpdate ? Acl::EDIT : Acl::ADD, $contact)) |
|
899 | 899 | { |
900 | 900 | $this->error = 'access denied'; |
901 | 901 | return false; |
@@ -908,15 +908,15 @@ discard block |
||
908 | 908 | // convert categories |
909 | 909 | if (is_array($contact['cat_id'])) |
910 | 910 | { |
911 | - $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
911 | + $contact['cat_id'] = implode(',', $contact['cat_id']); |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | // Update country codes |
915 | - foreach(array('adr_one_', 'adr_two_') as $c_prefix) { |
|
916 | - if($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] && |
|
915 | + foreach (array('adr_one_', 'adr_two_') as $c_prefix) { |
|
916 | + if ($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] && |
|
917 | 917 | $code = Country::country_code($contact[$c_prefix.'countryname'])) |
918 | 918 | { |
919 | - if(strlen($code) == 2) |
|
919 | + if (strlen($code) == 2) |
|
920 | 920 | { |
921 | 921 | $contact[$c_prefix.'countrycode'] = $code; |
922 | 922 | } |
@@ -925,7 +925,7 @@ discard block |
||
925 | 925 | $contact[$c_prefix.'countrycode'] = null; |
926 | 926 | } |
927 | 927 | } |
928 | - if($contact[$c_prefix.'countrycode'] != null) |
|
928 | + if ($contact[$c_prefix.'countrycode'] != null) |
|
929 | 929 | { |
930 | 930 | $contact[$c_prefix.'countryname'] = null; |
931 | 931 | } |
@@ -950,9 +950,9 @@ discard block |
||
950 | 950 | // (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc) |
951 | 951 | if (!$ignore_acl && !$contact['owner'] && !($this->is_admin($contact) || $this->allow_account_edit())) |
952 | 952 | { |
953 | - foreach(array_keys($contact) as $field) |
|
953 | + foreach (array_keys($contact) as $field) |
|
954 | 954 | { |
955 | - if (!in_array($field,$this->own_account_acl) && !in_array($field,array('id','owner','account_id','modified','modifier'))) |
|
955 | + if (!in_array($field, $this->own_account_acl) && !in_array($field, array('id', 'owner', 'account_id', 'modified', 'modifier'))) |
|
956 | 956 | { |
957 | 957 | // user is not allowed to change that |
958 | 958 | if ($old) |
@@ -973,12 +973,12 @@ discard block |
||
973 | 973 | { |
974 | 974 | if (isset($to_write['owner']) && !empty($to_write['owner'])) |
975 | 975 | { |
976 | - error_log(__METHOD__.__LINE__." Trying to change account to owner:". $to_write['owner'].' Account affected:'.array2string($old).' Data send:'.array2string($to_write)); |
|
976 | + error_log(__METHOD__.__LINE__." Trying to change account to owner:".$to_write['owner'].' Account affected:'.array2string($old).' Data send:'.array2string($to_write)); |
|
977 | 977 | unset($to_write['owner']); |
978 | 978 | } |
979 | 979 | } |
980 | 980 | |
981 | - if(!($this->error = parent::save($to_write))) |
|
981 | + if (!($this->error = parent::save($to_write))) |
|
982 | 982 | { |
983 | 983 | $contact['id'] = $to_write['id']; |
984 | 984 | $contact['uid'] = $to_write['uid']; |
@@ -992,27 +992,27 @@ discard block |
||
992 | 992 | $GLOBALS['egw']->accounts->cache_invalidate($contact['account_id']); |
993 | 993 | // call edit-accout hook, to let other apps know about changed account (names or email) |
994 | 994 | $GLOBALS['hook_values'] = $GLOBALS['egw']->accounts->read($contact['account_id']); |
995 | - Hooks::process($GLOBALS['hook_values']+array( |
|
995 | + Hooks::process($GLOBALS['hook_values'] + array( |
|
996 | 996 | 'location' => 'editaccount', |
997 | - ),False,True); // called for every app now, not only enabled ones) |
|
997 | + ), False, True); // called for every app now, not only enabled ones) |
|
998 | 998 | } |
999 | 999 | // notify interested apps about changes in the account-contact data |
1000 | 1000 | if (!$to_write['owner'] && $to_write['account_id'] && $isUpdate) |
1001 | 1001 | { |
1002 | 1002 | $to_write['location'] = 'editaccountcontact'; |
1003 | - Hooks::process($to_write,False,True); // called for every app now, not only enabled ones)); |
|
1003 | + Hooks::process($to_write, False, True); // called for every app now, not only enabled ones)); |
|
1004 | 1004 | } |
1005 | 1005 | // Notify linked apps about changes in the contact data |
1006 | - Link::notify_update('addressbook', $contact['id'], $contact); |
|
1006 | + Link::notify_update('addressbook', $contact['id'], $contact); |
|
1007 | 1007 | |
1008 | 1008 | // Check for restore of deleted contact, restore held links |
1009 | - if($old && $old['tid'] == self::DELETED_TYPE && $contact['tid'] != self::DELETED_TYPE) |
|
1009 | + if ($old && $old['tid'] == self::DELETED_TYPE && $contact['tid'] != self::DELETED_TYPE) |
|
1010 | 1010 | { |
1011 | 1011 | Link::restore('addressbook', $contact['id']); |
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | // Record change history for sql - doesn't work for LDAP accounts |
1015 | - if(!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql') |
|
1015 | + if (!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql') |
|
1016 | 1016 | { |
1017 | 1017 | $deleted = ($old['tid'] == self::DELETED_TYPE || $contact['tid'] == self::DELETED_TYPE); |
1018 | 1018 | if (!isset($this->tracking)) $this->tracking = new Contacts\Tracking($this); |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | * @param int $dst_w =240 max width to resize to |
1031 | 1031 | * @return string with resized jpeg photo, null on error |
1032 | 1032 | */ |
1033 | - public static function resize_photo($photo,$dst_w=240) |
|
1033 | + public static function resize_photo($photo, $dst_w = 240) |
|
1034 | 1034 | { |
1035 | 1035 | if (is_resource($photo)) |
1036 | 1036 | { |
@@ -1046,15 +1046,15 @@ discard block |
||
1046 | 1046 | //error_log(__METHOD__."() got image $src_w * $src_h, is_jpeg=".array2string(substr($photo,0,2) === "\377\330")); |
1047 | 1047 | |
1048 | 1048 | // if $photo is to width or not a jpeg image --> resize it |
1049 | - if ($src_w > $dst_w || cut_bytes($photo,0,2) !== "\377\330") |
|
1049 | + if ($src_w > $dst_w || cut_bytes($photo, 0, 2) !== "\377\330") |
|
1050 | 1050 | { |
1051 | 1051 | //error_log(__METHOD__."(,dst_w=$dst_w) src_w=$src_w, cut_bytes(photo,0,2)=".array2string(cut_bytes($photo,0,2)).' --> resizing'); |
1052 | 1052 | // scale the image to a width of 60 and a height according to the proportion of the source image |
1053 | - $resized = imagecreatetruecolor($dst_w,$dst_h = round($src_h * $dst_w / $src_w)); |
|
1054 | - imagecopyresized($resized,$image,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h); |
|
1053 | + $resized = imagecreatetruecolor($dst_w, $dst_h = round($src_h * $dst_w / $src_w)); |
|
1054 | + imagecopyresized($resized, $image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h); |
|
1055 | 1055 | |
1056 | 1056 | ob_start(); |
1057 | - imagejpeg($resized,null,90); |
|
1057 | + imagejpeg($resized, null, 90); |
|
1058 | 1058 | $photo = ob_get_contents(); |
1059 | 1059 | ob_end_clean(); |
1060 | 1060 | |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | * @param boolean $ignore_acl =false true: no acl check |
1076 | 1076 | * @return array|boolean array with contact data, null if not found or false on no view perms |
1077 | 1077 | */ |
1078 | - function read($contact_id, $ignore_acl=false) |
|
1078 | + function read($contact_id, $ignore_acl = false) |
|
1079 | 1079 | { |
1080 | 1080 | // get so_sql_cf to read private customfields too, if we ignore acl |
1081 | 1081 | if ($ignore_acl && is_a($this->somain, __CLASS__.'\\Sql')) |
@@ -1085,11 +1085,11 @@ discard block |
||
1085 | 1085 | } |
1086 | 1086 | if (!($data = parent::read($contact_id))) |
1087 | 1087 | { |
1088 | - $data = null; // not found |
|
1088 | + $data = null; // not found |
|
1089 | 1089 | } |
1090 | - elseif (!$ignore_acl && !$this->check_perms(Acl::READ,$data)) |
|
1090 | + elseif (!$ignore_acl && !$this->check_perms(Acl::READ, $data)) |
|
1091 | 1091 | { |
1092 | - $data = false; // no view perms |
|
1092 | + $data = false; // no view perms |
|
1093 | 1093 | } |
1094 | 1094 | else |
1095 | 1095 | { |
@@ -1097,10 +1097,10 @@ discard block |
||
1097 | 1097 | $data['fileas_type'] = $this->fileas_type($data); |
1098 | 1098 | |
1099 | 1099 | // Update country name from code |
1100 | - if($data['adr_one_countrycode'] != null) { |
|
1100 | + if ($data['adr_one_countrycode'] != null) { |
|
1101 | 1101 | $data['adr_one_countryname'] = Country::get_full_name($data['adr_one_countrycode'], true); |
1102 | 1102 | } |
1103 | - if($data['adr_two_countrycode'] != null) { |
|
1103 | + if ($data['adr_two_countrycode'] != null) { |
|
1104 | 1104 | $data['adr_two_countryname'] = Country::get_full_name($data['adr_two_countrycode'], true); |
1105 | 1105 | } |
1106 | 1106 | } |
@@ -1124,7 +1124,7 @@ discard block |
||
1124 | 1124 | * @param int $user =null for which user to check, default current user |
1125 | 1125 | * @return boolean true permission granted, false for permission denied, null for contact does not exist |
1126 | 1126 | */ |
1127 | - function check_perms($needed,$contact,$deny_account_delete=false,$user=null) |
|
1127 | + function check_perms($needed, $contact, $deny_account_delete = false, $user = null) |
|
1128 | 1128 | { |
1129 | 1129 | if (!$user) $user = $this->user; |
1130 | 1130 | if ($user == $this->user) |
@@ -1135,7 +1135,7 @@ discard block |
||
1135 | 1135 | else |
1136 | 1136 | { |
1137 | 1137 | $grants = $this->get_grants($user); |
1138 | - $memberships = $GLOBALS['egw']->accounts->memberships($user,true); |
|
1138 | + $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | if ((!is_array($contact) || !isset($contact['owner'])) && |
@@ -1161,12 +1161,12 @@ discard block |
||
1161 | 1161 | $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
1162 | 1162 | !isset($GLOBALS['egw_info']['user']['apps']['admin'])) |
1163 | 1163 | { |
1164 | - $access = !!array_intersect($memberships,$GLOBALS['egw']->accounts->memberships($contact['account_id'],true)); |
|
1164 | + $access = !!array_intersect($memberships, $GLOBALS['egw']->accounts->memberships($contact['account_id'], true)); |
|
1165 | 1165 | } |
1166 | 1166 | else |
1167 | 1167 | { |
1168 | - $access = ($grants[$owner] & $needed) && |
|
1169 | - (!$contact['private'] || ($grants[$owner] & Acl::PRIVAT) || in_array($owner,$memberships)); |
|
1168 | + $access = ($grants[$owner]&$needed) && |
|
1169 | + (!$contact['private'] || ($grants[$owner]&Acl::PRIVAT) || in_array($owner, $memberships)); |
|
1170 | 1170 | } |
1171 | 1171 | //error_log(__METHOD__."($needed,$contact[id],$deny_account_delete,$user) returning ".array2string($access)); |
1172 | 1172 | return $access; |
@@ -1181,11 +1181,11 @@ discard block |
||
1181 | 1181 | * @param int $user =null for which user to check, default current user |
1182 | 1182 | * @return boolean true if access is granted or false otherwise |
1183 | 1183 | */ |
1184 | - function file_access($id,$check,$rel_path=null,$user=null) |
|
1184 | + function file_access($id, $check, $rel_path = null, $user = null) |
|
1185 | 1185 | { |
1186 | - unset($rel_path); // not used, but required by function signature |
|
1186 | + unset($rel_path); // not used, but required by function signature |
|
1187 | 1187 | |
1188 | - return $this->check_perms($check,$id,false,$user); |
|
1188 | + return $this->check_perms($check, $id, false, $user); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | /** |
@@ -1197,18 +1197,18 @@ discard block |
||
1197 | 1197 | function read_org($org_id) |
1198 | 1198 | { |
1199 | 1199 | if (!$org_id) return false; |
1200 | - if (strpos($org_id,'*AND*')!== false) $org_id = str_replace('*AND*','&',$org_id); |
|
1200 | + if (strpos($org_id, '*AND*') !== false) $org_id = str_replace('*AND*', '&', $org_id); |
|
1201 | 1201 | $org = array(); |
1202 | - foreach(explode('|||',$org_id) as $part) |
|
1202 | + foreach (explode('|||', $org_id) as $part) |
|
1203 | 1203 | { |
1204 | - list($name,$value) = explode(':',$part,2); |
|
1204 | + list($name, $value) = explode(':', $part, 2); |
|
1205 | 1205 | $org[$name] = $value; |
1206 | 1206 | } |
1207 | - $csvs = array('cat_id'); // fields with comma-separated-values |
|
1207 | + $csvs = array('cat_id'); // fields with comma-separated-values |
|
1208 | 1208 | |
1209 | 1209 | // split regular fields and custom fields |
1210 | 1210 | $custom_fields = $regular_fields = array(); |
1211 | - foreach($this->org_fields as $name) |
|
1211 | + foreach ($this->org_fields as $name) |
|
1212 | 1212 | { |
1213 | 1213 | if ($name[0] != '#') |
1214 | 1214 | { |
@@ -1216,9 +1216,9 @@ discard block |
||
1216 | 1216 | } |
1217 | 1217 | else |
1218 | 1218 | { |
1219 | - $custom_fields[] = $name = substr($name,1); |
|
1219 | + $custom_fields[] = $name = substr($name, 1); |
|
1220 | 1220 | $regular_fields['id'] = 'id'; |
1221 | - if (substr($this->customfields[$name]['type'],0,6)=='select' && $this->customfields[$name]['rows'] || // multiselection |
|
1221 | + if (substr($this->customfields[$name]['type'], 0, 6) == 'select' && $this->customfields[$name]['rows'] || // multiselection |
|
1222 | 1222 | $this->customfields[$name]['type'] == 'radio') |
1223 | 1223 | { |
1224 | 1224 | $csvs[] = '#'.$name; |
@@ -1226,24 +1226,24 @@ discard block |
||
1226 | 1226 | } |
1227 | 1227 | } |
1228 | 1228 | // read the regular fields |
1229 | - $contacts = parent::search('',$regular_fields,'','','',false,'AND',false,$org); |
|
1229 | + $contacts = parent::search('', $regular_fields, '', '', '', false, 'AND', false, $org); |
|
1230 | 1230 | if (!$contacts) return false; |
1231 | 1231 | |
1232 | 1232 | // if we have custom fields, read and merge them in |
1233 | 1233 | if ($custom_fields) |
1234 | 1234 | { |
1235 | - foreach($contacts as $contact) |
|
1235 | + foreach ($contacts as $contact) |
|
1236 | 1236 | { |
1237 | 1237 | $ids[] = $contact['id']; |
1238 | 1238 | } |
1239 | - if (($cfs = $this->read_customfields($ids,$custom_fields))) |
|
1239 | + if (($cfs = $this->read_customfields($ids, $custom_fields))) |
|
1240 | 1240 | { |
1241 | 1241 | foreach ($contacts as &$contact) |
1242 | 1242 | { |
1243 | 1243 | $id = $contact['id']; |
1244 | 1244 | if (isset($cfs[$id])) |
1245 | 1245 | { |
1246 | - foreach($cfs[$id] as $name => $value) |
|
1246 | + foreach ($cfs[$id] as $name => $value) |
|
1247 | 1247 | { |
1248 | 1248 | $contact['#'.$name] = $value; |
1249 | 1249 | } |
@@ -1255,33 +1255,33 @@ discard block |
||
1255 | 1255 | |
1256 | 1256 | // create a statistic about the commonness of each fields values |
1257 | 1257 | $fields = array(); |
1258 | - foreach($contacts as $contact) |
|
1258 | + foreach ($contacts as $contact) |
|
1259 | 1259 | { |
1260 | - foreach($contact as $name => $value) |
|
1260 | + foreach ($contact as $name => $value) |
|
1261 | 1261 | { |
1262 | - if (!in_array($name,$csvs)) |
|
1262 | + if (!in_array($name, $csvs)) |
|
1263 | 1263 | { |
1264 | 1264 | $fields[$name][$value]++; |
1265 | 1265 | } |
1266 | 1266 | else |
1267 | 1267 | { |
1268 | 1268 | // for comma separated fields, we have to use each single value |
1269 | - foreach(explode(',',$value) as $val) |
|
1269 | + foreach (explode(',', $value) as $val) |
|
1270 | 1270 | { |
1271 | 1271 | $fields[$name][$val]++; |
1272 | 1272 | } |
1273 | 1273 | } |
1274 | 1274 | } |
1275 | 1275 | } |
1276 | - foreach($fields as $name => $values) |
|
1276 | + foreach ($fields as $name => $values) |
|
1277 | 1277 | { |
1278 | - if (!in_array($name,$this->org_fields)) continue; |
|
1278 | + if (!in_array($name, $this->org_fields)) continue; |
|
1279 | 1279 | |
1280 | - arsort($values,SORT_NUMERIC); |
|
1281 | - list($value,$num) = each($values); |
|
1282 | - if ($value && $num / (double) count($contacts) >= $this->org_common_factor) |
|
1280 | + arsort($values, SORT_NUMERIC); |
|
1281 | + list($value, $num) = each($values); |
|
1282 | + if ($value && $num / (double)count($contacts) >= $this->org_common_factor) |
|
1283 | 1283 | { |
1284 | - if (!in_array($name,$csvs)) |
|
1284 | + if (!in_array($name, $csvs)) |
|
1285 | 1285 | { |
1286 | 1286 | $org[$name] = $value; |
1287 | 1287 | } |
@@ -1290,12 +1290,12 @@ discard block |
||
1290 | 1290 | $org[$name] = array(); |
1291 | 1291 | foreach ($values as $value => $num) |
1292 | 1292 | { |
1293 | - if ($value && $num / (double) count($contacts) >= $this->org_common_factor) |
|
1293 | + if ($value && $num / (double)count($contacts) >= $this->org_common_factor) |
|
1294 | 1294 | { |
1295 | 1295 | $org[$name][] = $value; |
1296 | 1296 | } |
1297 | 1297 | } |
1298 | - $org[$name] = implode(',',$org[$name]); |
|
1298 | + $org[$name] = implode(',', $org[$name]); |
|
1299 | 1299 | } |
1300 | 1300 | } |
1301 | 1301 | } |
@@ -1309,10 +1309,10 @@ discard block |
||
1309 | 1309 | * @param array $fields field-name => value pairs |
1310 | 1310 | * @return array with contacts |
1311 | 1311 | */ |
1312 | - function org_similar($org_name,$fields) |
|
1312 | + function org_similar($org_name, $fields) |
|
1313 | 1313 | { |
1314 | 1314 | $criteria = array(); |
1315 | - foreach($this->org_fields as $name) |
|
1315 | + foreach ($this->org_fields as $name) |
|
1316 | 1316 | { |
1317 | 1317 | if (isset($fields[$name])) |
1318 | 1318 | { |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | } |
1327 | 1327 | } |
1328 | 1328 | } |
1329 | - return parent::search($criteria,false,'n_family,n_given','','',false,'OR',false,array('org_name'=>$org_name)); |
|
1329 | + return parent::search($criteria, false, 'n_family,n_given', '', '', false, 'OR', false, array('org_name'=>$org_name)); |
|
1330 | 1330 | } |
1331 | 1331 | |
1332 | 1332 | /** |
@@ -1337,10 +1337,10 @@ discard block |
||
1337 | 1337 | * @param boolean $only_org_fields =true check and return only org_fields, default true |
1338 | 1338 | * @return array with field-name => value from $from |
1339 | 1339 | */ |
1340 | - function changed_fields($from,$to,$only_org_fields=true) |
|
1340 | + function changed_fields($from, $to, $only_org_fields = true) |
|
1341 | 1341 | { |
1342 | 1342 | // we only care about countryname, if contrycode is empty |
1343 | - foreach(array( |
|
1343 | + foreach (array( |
|
1344 | 1344 | 'adr_one_countryname' => 'adr_one_countrycode', |
1345 | 1345 | 'adr_two_countryname' => 'adr_one_countrycode', |
1346 | 1346 | ) as $name => $code) |
@@ -1349,13 +1349,13 @@ discard block |
||
1349 | 1349 | if (!empty($to[$code])) $to[$name] = ''; |
1350 | 1350 | } |
1351 | 1351 | $changed = array(); |
1352 | - foreach($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name) |
|
1352 | + foreach ($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name) |
|
1353 | 1353 | { |
1354 | - if (in_array($name,array('modified','modifier'))) // never count these |
|
1354 | + if (in_array($name, array('modified', 'modifier'))) // never count these |
|
1355 | 1355 | { |
1356 | 1356 | continue; |
1357 | 1357 | } |
1358 | - if ((string) $from[$name] != (string) $to[$name]) |
|
1358 | + if ((string)$from[$name] != (string)$to[$name]) |
|
1359 | 1359 | { |
1360 | 1360 | $changed[$name] = $from[$name]; |
1361 | 1361 | } |
@@ -1372,35 +1372,35 @@ discard block |
||
1372 | 1372 | * @param array $members =null org-members to change, default null --> function queries them itself |
1373 | 1373 | * @return array/boolean (changed-members,changed-fields,failed-members) or false if no org_fields changed or no (other) members matching that fields |
1374 | 1374 | */ |
1375 | - function change_org($org_name,$from,$to,$members=null) |
|
1375 | + function change_org($org_name, $from, $to, $members = null) |
|
1376 | 1376 | { |
1377 | - if (!($changed = $this->changed_fields($from,$to,true))) return false; |
|
1377 | + if (!($changed = $this->changed_fields($from, $to, true))) return false; |
|
1378 | 1378 | |
1379 | 1379 | if (is_null($members) || !is_array($members)) |
1380 | 1380 | { |
1381 | - $members = $this->org_similar($org_name,$changed); |
|
1381 | + $members = $this->org_similar($org_name, $changed); |
|
1382 | 1382 | } |
1383 | 1383 | if (!$members) return false; |
1384 | 1384 | |
1385 | 1385 | $ids = array(); |
1386 | - foreach($members as $member) |
|
1386 | + foreach ($members as $member) |
|
1387 | 1387 | { |
1388 | 1388 | $ids[] = $member['id']; |
1389 | 1389 | } |
1390 | 1390 | $customfields = $this->read_customfields($ids); |
1391 | 1391 | |
1392 | 1392 | $changed_members = $changed_fields = $failed_members = 0; |
1393 | - foreach($members as $member) |
|
1393 | + foreach ($members as $member) |
|
1394 | 1394 | { |
1395 | 1395 | if (isset($customfields[$member['id']])) |
1396 | 1396 | { |
1397 | - foreach(array_keys($this->customfields) as $name) |
|
1397 | + foreach (array_keys($this->customfields) as $name) |
|
1398 | 1398 | { |
1399 | 1399 | $member['#'.$name] = $customfields[$member['id']][$name]; |
1400 | 1400 | } |
1401 | 1401 | } |
1402 | 1402 | $fields = 0; |
1403 | - foreach($changed as $name => $value) |
|
1403 | + foreach ($changed as $name => $value) |
|
1404 | 1404 | { |
1405 | 1405 | if ((string)$value == (string)$member[$name]) |
1406 | 1406 | { |
@@ -1410,7 +1410,7 @@ discard block |
||
1410 | 1410 | } |
1411 | 1411 | if ($fields) |
1412 | 1412 | { |
1413 | - if (!$this->check_perms(Acl::EDIT,$member) || !$this->save($member)) |
|
1413 | + if (!$this->check_perms(Acl::EDIT, $member) || !$this->save($member)) |
|
1414 | 1414 | { |
1415 | 1415 | ++$failed_members; |
1416 | 1416 | } |
@@ -1421,7 +1421,7 @@ discard block |
||
1421 | 1421 | } |
1422 | 1422 | } |
1423 | 1423 | } |
1424 | - return array($changed_members,$changed_fields,$failed_members); |
|
1424 | + return array($changed_members, $changed_fields, $failed_members); |
|
1425 | 1425 | } |
1426 | 1426 | |
1427 | 1427 | /** |
@@ -1448,12 +1448,12 @@ discard block |
||
1448 | 1448 | if ($contact['n_fileas']) return $contact['n_fileas']; |
1449 | 1449 | $type = null; |
1450 | 1450 | } |
1451 | - $title = $this->fileas($contact,$type); |
|
1451 | + $title = $this->fileas($contact, $type); |
|
1452 | 1452 | if ($this->prefs['link_title_cf'] && $contact['#'.$this->prefs['link_title_cf']]) |
1453 | 1453 | { |
1454 | - $title .= ' ' . $contact['#'.$this->prefs['link_title_cf']]; |
|
1454 | + $title .= ' '.$contact['#'.$this->prefs['link_title_cf']]; |
|
1455 | 1455 | } |
1456 | - return $title ; |
|
1456 | + return $title; |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 | /** |
@@ -1467,21 +1467,21 @@ discard block |
||
1467 | 1467 | function link_titles(array $ids) |
1468 | 1468 | { |
1469 | 1469 | $titles = array(); |
1470 | - if (($contacts =& $this->search(array('contact_id' => $ids),false))) |
|
1470 | + if (($contacts = & $this->search(array('contact_id' => $ids), false))) |
|
1471 | 1471 | { |
1472 | 1472 | $ids = array(); |
1473 | - foreach($contacts as $contact) |
|
1473 | + foreach ($contacts as $contact) |
|
1474 | 1474 | { |
1475 | 1475 | $ids[] = $contact['id']; |
1476 | 1476 | } |
1477 | 1477 | $cfs = $this->read_customfields($ids); |
1478 | - foreach($contacts as $contact) |
|
1478 | + foreach ($contacts as $contact) |
|
1479 | 1479 | { |
1480 | - $titles[$contact['id']] = $this->link_title($contact+(array)$cfs[$contact['id']]); |
|
1480 | + $titles[$contact['id']] = $this->link_title($contact + (array)$cfs[$contact['id']]); |
|
1481 | 1481 | } |
1482 | 1482 | } |
1483 | 1483 | // we assume all not returned contacts are not readable for the user (as we report all deleted contacts to egw_link) |
1484 | - foreach($ids as $id) |
|
1484 | + foreach ($ids as $id) |
|
1485 | 1485 | { |
1486 | 1486 | if (!isset($titles[$id])) |
1487 | 1487 | { |
@@ -1508,23 +1508,23 @@ discard block |
||
1508 | 1508 | { |
1509 | 1509 | $criteria = is_array($pattern) ? $pattern['search'] : $pattern; |
1510 | 1510 | } |
1511 | - if($options['start'] || $options['num_rows']) |
|
1511 | + if ($options['start'] || $options['num_rows']) |
|
1512 | 1512 | { |
1513 | 1513 | $limit = array($options['start'], $options['num_rows']); |
1514 | 1514 | } |
1515 | 1515 | $filter = (array)$options['filter']; |
1516 | 1516 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $filter['account_id'] = null; |
1517 | - if (($contacts =& parent::search($criteria,false,'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR', $limit, $filter))) |
|
1517 | + if (($contacts = & parent::search($criteria, false, 'org_name,n_family,n_given,cat_id,contact_email', '', '%', false, 'OR', $limit, $filter))) |
|
1518 | 1518 | { |
1519 | 1519 | $ids = array(); |
1520 | - foreach($contacts as $contact) |
|
1520 | + foreach ($contacts as $contact) |
|
1521 | 1521 | { |
1522 | 1522 | $ids[] = $contact['id']; |
1523 | 1523 | } |
1524 | 1524 | $cfs = $this->read_customfields($ids); |
1525 | - foreach($contacts as $contact) |
|
1525 | + foreach ($contacts as $contact) |
|
1526 | 1526 | { |
1527 | - $result[$contact['id']] = $this->link_title($contact+(array)$cfs[$contact['id']]); |
|
1527 | + $result[$contact['id']] = $this->link_title($contact + (array)$cfs[$contact['id']]); |
|
1528 | 1528 | // make sure to return a correctly quoted rfc822 address, if requested |
1529 | 1529 | if ($options['type'] === 'email') |
1530 | 1530 | { |
@@ -1565,7 +1565,7 @@ discard block |
||
1565 | 1565 | // let link query know, to append email to list |
1566 | 1566 | $options['type'] = 'email'; |
1567 | 1567 | |
1568 | - return $this->link_query($pattern,$options); |
|
1568 | + return $this->link_query($pattern, $options); |
|
1569 | 1569 | } |
1570 | 1570 | |
1571 | 1571 | /** |
@@ -1579,7 +1579,7 @@ discard block |
||
1579 | 1579 | if (!$ids) return null; |
1580 | 1580 | |
1581 | 1581 | $data = array(); |
1582 | - foreach(!is_array($ids) ? array($ids) : $ids as $id) |
|
1582 | + foreach (!is_array($ids) ? array($ids) : $ids as $id) |
|
1583 | 1583 | { |
1584 | 1584 | if (!($contact = $this->read($id))) continue; |
1585 | 1585 | |
@@ -1601,12 +1601,12 @@ discard block |
||
1601 | 1601 | * @param boolean $extra_title =true if true, use a short date only title and put the full title as extra_title (tooltip) |
1602 | 1602 | * @return array |
1603 | 1603 | */ |
1604 | - function read_calendar($ids,$extra_title=true) |
|
1604 | + function read_calendar($ids, $extra_title = true) |
|
1605 | 1605 | { |
1606 | 1606 | if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return array(); |
1607 | 1607 | |
1608 | 1608 | $uids = array(); |
1609 | - foreach($ids as $id) |
|
1609 | + foreach ($ids as $id) |
|
1610 | 1610 | { |
1611 | 1611 | if (is_numeric($id)) $uids[] = 'c'.$id; |
1612 | 1612 | } |
@@ -1621,15 +1621,15 @@ discard block |
||
1621 | 1621 | |
1622 | 1622 | //_debug_array($events); |
1623 | 1623 | $calendars = array(); |
1624 | - foreach($events as $event) |
|
1624 | + foreach ($events as $event) |
|
1625 | 1625 | { |
1626 | - foreach($event['participants'] as $uid => $status) |
|
1626 | + foreach ($event['participants'] as $uid => $status) |
|
1627 | 1627 | { |
1628 | 1628 | if ($uid[0] != 'c' || ($status == 'R' && !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])) |
1629 | 1629 | { |
1630 | 1630 | continue; |
1631 | 1631 | } |
1632 | - $id = (int)substr($uid,1); |
|
1632 | + $id = (int)substr($uid, 1); |
|
1633 | 1633 | |
1634 | 1634 | if ($event['start'] < $this->now_su) // past event --> check for last event |
1635 | 1635 | { |
@@ -1641,13 +1641,13 @@ discard block |
||
1641 | 1641 | 'app' => 'calendar', |
1642 | 1642 | 'title' => $bocal->link_title($event), |
1643 | 1643 | 'extra_args' => array( |
1644 | - 'date' => date('Ymd',$event['start']), |
|
1644 | + 'date' => date('Ymd', $event['start']), |
|
1645 | 1645 | ), |
1646 | 1646 | ); |
1647 | 1647 | if ($extra_title) |
1648 | 1648 | { |
1649 | 1649 | $link['extra_title'] = $link['title']; |
1650 | - $link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']); |
|
1650 | + $link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $event['start']); |
|
1651 | 1651 | } |
1652 | 1652 | $calendars[$id]['last_link'] = $link; |
1653 | 1653 | } |
@@ -1662,13 +1662,13 @@ discard block |
||
1662 | 1662 | 'app' => 'calendar', |
1663 | 1663 | 'title' => $bocal->link_title($event), |
1664 | 1664 | 'extra_args' => array( |
1665 | - 'date' => date('Ymd',$event['start']), |
|
1665 | + 'date' => date('Ymd', $event['start']), |
|
1666 | 1666 | ), |
1667 | 1667 | ); |
1668 | 1668 | if ($extra_title) |
1669 | 1669 | { |
1670 | 1670 | $link['extra_title'] = $link['title']; |
1671 | - $link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']); |
|
1671 | + $link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $event['start']); |
|
1672 | 1672 | } |
1673 | 1673 | $calendars[$id]['next_link'] = $link; |
1674 | 1674 | } |
@@ -1697,7 +1697,7 @@ discard block |
||
1697 | 1697 | { |
1698 | 1698 | // get all cats if you want to drop sub cats |
1699 | 1699 | $drop_subs = ($data['drop_subs'] && !$data['modify_subs']); |
1700 | - if($drop_subs) |
|
1700 | + if ($drop_subs) |
|
1701 | 1701 | { |
1702 | 1702 | $cats = new Categories('', 'addressbook'); |
1703 | 1703 | $cat_ids = $cats->return_all_children($data['cat_id']); |
@@ -1708,14 +1708,14 @@ discard block |
||
1708 | 1708 | } |
1709 | 1709 | |
1710 | 1710 | // Get addresses that use the category |
1711 | - @set_time_limit( 0 ); |
|
1712 | - foreach($cat_ids as $cat_id) |
|
1711 | + @set_time_limit(0); |
|
1712 | + foreach ($cat_ids as $cat_id) |
|
1713 | 1713 | { |
1714 | 1714 | if (($ids = $this->search(array('cat_id' => $cat_id), false))) |
1715 | 1715 | { |
1716 | - foreach($ids as &$info) |
|
1716 | + foreach ($ids as &$info) |
|
1717 | 1717 | { |
1718 | - $info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), $cat_ids)); |
|
1718 | + $info['cat_id'] = implode(',', array_diff(explode(',', $info['cat_id']), $cat_ids)); |
|
1719 | 1719 | $this->save($info); |
1720 | 1720 | } |
1721 | 1721 | } |
@@ -1737,14 +1737,14 @@ discard block |
||
1737 | 1737 | $account = null; |
1738 | 1738 | $custom_fields = Storage\Customfields::get('addressbook', true); |
1739 | 1739 | $custom_field_list = $this->read_customfields($ids); |
1740 | - foreach(parent::search(array('id'=>$ids),false) as $contact) // $this->search calls the extended search from ui! |
|
1740 | + foreach (parent::search(array('id'=>$ids), false) as $contact) // $this->search calls the extended search from ui! |
|
1741 | 1741 | { |
1742 | 1742 | if ($contact['account_id']) |
1743 | 1743 | { |
1744 | 1744 | if (!is_null($account)) |
1745 | 1745 | { |
1746 | 1746 | echo $this->error = 'Can not merge more then one account!'; |
1747 | - return false; // we dont deal with two accounts! |
|
1747 | + return false; // we dont deal with two accounts! |
|
1748 | 1748 | } |
1749 | 1749 | $account = $contact; |
1750 | 1750 | continue; |
@@ -1752,7 +1752,7 @@ discard block |
||
1752 | 1752 | // Add in custom fields |
1753 | 1753 | if (is_array($custom_field_list[$contact['id']])) $contact = array_merge($contact, $custom_field_list[$contact['id']]); |
1754 | 1754 | |
1755 | - $pos = array_search($contact['id'],$ids); |
|
1755 | + $pos = array_search($contact['id'], $ids); |
|
1756 | 1756 | $contacts[$pos] = $contact; |
1757 | 1757 | } |
1758 | 1758 | if (!is_null($account)) // we found an account, so we merge the contacts into it |
@@ -1765,38 +1765,38 @@ discard block |
||
1765 | 1765 | $target = $contacts[0]; |
1766 | 1766 | unset($contacts[0]); |
1767 | 1767 | } |
1768 | - if (!$this->check_perms(Acl::EDIT,$target)) |
|
1768 | + if (!$this->check_perms(Acl::EDIT, $target)) |
|
1769 | 1769 | { |
1770 | 1770 | echo $this->error = 'No edit permission for the target contact!'; |
1771 | 1771 | return 0; |
1772 | 1772 | } |
1773 | - foreach($contacts as $contact) |
|
1773 | + foreach ($contacts as $contact) |
|
1774 | 1774 | { |
1775 | - foreach($contact as $name => $value) |
|
1775 | + foreach ($contact as $name => $value) |
|
1776 | 1776 | { |
1777 | 1777 | if (!$value) continue; |
1778 | 1778 | |
1779 | - switch($name) |
|
1779 | + switch ($name) |
|
1780 | 1780 | { |
1781 | 1781 | case 'id': |
1782 | 1782 | case 'tid': |
1783 | 1783 | case 'owner': |
1784 | 1784 | case 'private': |
1785 | 1785 | case 'etag'; |
1786 | - break; // ignored |
|
1786 | + break; // ignored |
|
1787 | 1787 | |
1788 | 1788 | case 'cat_id': // cats are all merged together |
1789 | - if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array(); |
|
1790 | - $target['cat_id'] = array_unique(array_merge($target['cat_id'],is_array($value)?$value:explode(',',$value))); |
|
1789 | + if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',', $target['cat_id']) : array(); |
|
1790 | + $target['cat_id'] = array_unique(array_merge($target['cat_id'], is_array($value) ? $value : explode(',', $value))); |
|
1791 | 1791 | break; |
1792 | 1792 | |
1793 | 1793 | default: |
1794 | 1794 | // Multi-select custom fields can also be merged |
1795 | - if($name[0] == '#') { |
|
1795 | + if ($name[0] == '#') { |
|
1796 | 1796 | $c_name = substr($name, 1); |
1797 | - if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) { |
|
1798 | - if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',',$target[$name]) : array(); |
|
1799 | - $target[$name] = implode(',',array_unique(array_merge($target[$name],is_array($value)?$value:explode(',',$value)))); |
|
1797 | + if ($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) { |
|
1798 | + if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',', $target[$name]) : array(); |
|
1799 | + $target[$name] = implode(',', array_unique(array_merge($target[$name], is_array($value) ? $value : explode(',', $value)))); |
|
1800 | 1800 | } |
1801 | 1801 | } |
1802 | 1802 | if (!$target[$name]) $target[$name] = $value; |
@@ -1807,29 +1807,29 @@ discard block |
||
1807 | 1807 | if (!$this->save($target)) return 0; |
1808 | 1808 | |
1809 | 1809 | $success = 1; |
1810 | - foreach($contacts as $contact) |
|
1810 | + foreach ($contacts as $contact) |
|
1811 | 1811 | { |
1812 | - if (!$this->check_perms(Acl::DELETE,$contact)) |
|
1812 | + if (!$this->check_perms(Acl::DELETE, $contact)) |
|
1813 | 1813 | { |
1814 | 1814 | continue; |
1815 | 1815 | } |
1816 | - foreach(Link::get_links('addressbook',$contact['id']) as $data) |
|
1816 | + foreach (Link::get_links('addressbook', $contact['id']) as $data) |
|
1817 | 1817 | { |
1818 | 1818 | //_debug_array(array('function'=>__METHOD__,'line'=>__LINE__,'app'=>'addressbook','id'=>$contact['id'],'data:'=>$data,'target'=>$target['id'])); |
1819 | 1819 | // info_from and info_link_id (main link) |
1820 | - $newlinkID = Link::link('addressbook',$target['id'],$data['app'],$data['id'],$data['remark'],$target['owner']); |
|
1820 | + $newlinkID = Link::link('addressbook', $target['id'], $data['app'], $data['id'], $data['remark'], $target['owner']); |
|
1821 | 1821 | //_debug_array(array('newLinkID'=>$newlinkID)); |
1822 | 1822 | if ($newlinkID) |
1823 | 1823 | { |
1824 | 1824 | // update egw_infolog set info_link_id=$newlinkID where info_id=$data['id'] and info_link_id=$data['link_id'] |
1825 | - if ($data['app']=='infolog') |
|
1825 | + if ($data['app'] == 'infolog') |
|
1826 | 1826 | { |
1827 | - $this->db->update('egw_infolog',array( |
|
1827 | + $this->db->update('egw_infolog', array( |
|
1828 | 1828 | 'info_link_id' => $newlinkID |
1829 | - ),array( |
|
1829 | + ), array( |
|
1830 | 1830 | 'info_id' => $data['id'], |
1831 | 1831 | 'info_link_id' => $data['link_id'] |
1832 | - ),__LINE__,__FILE__,'infolog'); |
|
1832 | + ), __LINE__, __FILE__, 'infolog'); |
|
1833 | 1833 | } |
1834 | 1834 | unset($newlinkID); |
1835 | 1835 | } |
@@ -1854,14 +1854,14 @@ discard block |
||
1854 | 1854 | * @param int $owner =null |
1855 | 1855 | * @return boolean |
1856 | 1856 | */ |
1857 | - function check_list($list,$required,$owner=null) |
|
1857 | + function check_list($list, $required, $owner = null) |
|
1858 | 1858 | { |
1859 | 1859 | if ($list && ($list_data = $this->read_list($list))) |
1860 | 1860 | { |
1861 | 1861 | $owner = $list_data['list_owner']; |
1862 | 1862 | } |
1863 | 1863 | //error_log(__METHOD__."($list, $required, $owner) grants[$owner]=".$this->grants[$owner]." returning ".array2string(!!($this->grants[$owner] & $required))); |
1864 | - return !!($this->grants[$owner] & $required); |
|
1864 | + return !!($this->grants[$owner]&$required); |
|
1865 | 1865 | } |
1866 | 1866 | |
1867 | 1867 | /** |
@@ -1873,17 +1873,17 @@ discard block |
||
1873 | 1873 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
1874 | 1874 | * @return int|boolean integer list_id or false on error |
1875 | 1875 | */ |
1876 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
1876 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
1877 | 1877 | { |
1878 | - if (!$this->check_list(null,Acl::ADD|Acl::EDIT,$owner)) return false; |
|
1878 | + if (!$this->check_list(null, Acl::ADD|Acl::EDIT, $owner)) return false; |
|
1879 | 1879 | |
1880 | 1880 | try { |
1881 | - $ret = parent::add_list($keys,$owner,$contacts,$data); |
|
1881 | + $ret = parent::add_list($keys, $owner, $contacts, $data); |
|
1882 | 1882 | if ($ret) unset(self::$list_cache[$ret]); |
1883 | 1883 | } |
1884 | 1884 | // catch sql error, as creating same name&owner list gives a sql error doublicate key |
1885 | - catch(Api\Db\Exception\InvalidSql $e) { |
|
1886 | - unset($e); // not used |
|
1885 | + catch (Api\Db\Exception\InvalidSql $e) { |
|
1886 | + unset($e); // not used |
|
1887 | 1887 | return false; |
1888 | 1888 | } |
1889 | 1889 | return $ret; |
@@ -1897,13 +1897,13 @@ discard block |
||
1897 | 1897 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
1898 | 1898 | * @return false on error |
1899 | 1899 | */ |
1900 | - function add2list($contact,$list,array $existing=null) |
|
1900 | + function add2list($contact, $list, array $existing = null) |
|
1901 | 1901 | { |
1902 | - if (!$this->check_list($list,Acl::EDIT)) return false; |
|
1902 | + if (!$this->check_list($list, Acl::EDIT)) return false; |
|
1903 | 1903 | |
1904 | 1904 | unset(self::$list_cache[$list]); |
1905 | 1905 | |
1906 | - return parent::add2list($contact,$list,$existing); |
|
1906 | + return parent::add2list($contact, $list, $existing); |
|
1907 | 1907 | } |
1908 | 1908 | |
1909 | 1909 | /** |
@@ -1913,9 +1913,9 @@ discard block |
||
1913 | 1913 | * @param int $list list-id |
1914 | 1914 | * @return false on error |
1915 | 1915 | */ |
1916 | - function remove_from_list($contact,$list=null) |
|
1916 | + function remove_from_list($contact, $list = null) |
|
1917 | 1917 | { |
1918 | - if ($list && !$this->check_list($list,Acl::EDIT)) return false; |
|
1918 | + if ($list && !$this->check_list($list, Acl::EDIT)) return false; |
|
1919 | 1919 | |
1920 | 1920 | if ($list) |
1921 | 1921 | { |
@@ -1926,7 +1926,7 @@ discard block |
||
1926 | 1926 | self::$list_cache = array(); |
1927 | 1927 | } |
1928 | 1928 | |
1929 | - return parent::remove_from_list($contact,$list); |
|
1929 | + return parent::remove_from_list($contact, $list); |
|
1930 | 1930 | } |
1931 | 1931 | |
1932 | 1932 | /** |
@@ -1937,9 +1937,9 @@ discard block |
||
1937 | 1937 | */ |
1938 | 1938 | function delete_list($list) |
1939 | 1939 | { |
1940 | - if (!$this->check_list($list,Acl::DELETE)) return false; |
|
1940 | + if (!$this->check_list($list, Acl::DELETE)) return false; |
|
1941 | 1941 | |
1942 | - foreach((array)$list as $l) |
|
1942 | + foreach ((array)$list as $l) |
|
1943 | 1943 | { |
1944 | 1944 | unset(self::$list_cache[$l]); |
1945 | 1945 | } |
@@ -1975,7 +1975,7 @@ discard block |
||
1975 | 1975 | { |
1976 | 1976 | $code = Country::country_code($country); |
1977 | 1977 | |
1978 | - switch($code) |
|
1978 | + switch ($code) |
|
1979 | 1979 | { |
1980 | 1980 | case 'AU': |
1981 | 1981 | case 'CA': |
@@ -2039,12 +2039,12 @@ discard block |
||
2039 | 2039 | * by the ones the user normally does not see due to category permissions - used to preserve categories |
2040 | 2040 | * @return array category ids (found, added and preserved categories) |
2041 | 2041 | */ |
2042 | - function find_or_add_categories($catname_list, $contact_id=null) |
|
2042 | + function find_or_add_categories($catname_list, $contact_id = null) |
|
2043 | 2043 | { |
2044 | 2044 | if ($contact_id && $contact_id > 0 && ($old_contact = $this->read($contact_id))) |
2045 | 2045 | { |
2046 | 2046 | // preserve categories without users read access |
2047 | - $old_categories = explode(',',$old_contact['cat_id']); |
|
2047 | + $old_categories = explode(',', $old_contact['cat_id']); |
|
2048 | 2048 | $old_cats_preserve = array(); |
2049 | 2049 | if (is_array($old_categories) && count($old_categories) > 0) |
2050 | 2050 | { |
@@ -2098,15 +2098,15 @@ discard block |
||
2098 | 2098 | { |
2099 | 2099 | if (!is_object($this->categories)) |
2100 | 2100 | { |
2101 | - $this->categories = new Categories($this->user,'addressbook'); |
|
2101 | + $this->categories = new Categories($this->user, 'addressbook'); |
|
2102 | 2102 | } |
2103 | 2103 | |
2104 | 2104 | if (!is_array($cat_id_list)) |
2105 | 2105 | { |
2106 | - $cat_id_list = explode(',',$cat_id_list); |
|
2106 | + $cat_id_list = explode(',', $cat_id_list); |
|
2107 | 2107 | } |
2108 | 2108 | $cat_list = array(); |
2109 | - foreach($cat_id_list as $cat_id) |
|
2109 | + foreach ($cat_id_list as $cat_id) |
|
2110 | 2110 | { |
2111 | 2111 | if ($cat_id && $this->categories->check_perms(Acl::READ, $cat_id) && |
2112 | 2112 | ($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--') |
@@ -2138,14 +2138,14 @@ discard block |
||
2138 | 2138 | * @param boolean $relax =false if asked to relax, we only match against some key fields |
2139 | 2139 | * @return array od matching contact_ids |
2140 | 2140 | */ |
2141 | - function find_contact($contact, $relax=false) |
|
2141 | + function find_contact($contact, $relax = false) |
|
2142 | 2142 | { |
2143 | 2143 | $empty_addr_one = $empty_addr_two = true; |
2144 | 2144 | |
2145 | 2145 | if ($this->log) |
2146 | 2146 | { |
2147 | 2147 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2148 | - . '('. ($relax ? 'RELAX': 'EXACT') . ')[ContactData]:' |
|
2148 | + . '('.($relax ? 'RELAX' : 'EXACT').')[ContactData]:' |
|
2149 | 2149 | . array2string($contact) |
2150 | 2150 | . "\n", 3, $this->logfile); |
2151 | 2151 | } |
@@ -2156,7 +2156,7 @@ discard block |
||
2156 | 2156 | if ($this->log) |
2157 | 2157 | { |
2158 | 2158 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2159 | - . '()[ContactID]: ' . $contact['id'] |
|
2159 | + . '()[ContactID]: '.$contact['id'] |
|
2160 | 2160 | . "\n", 3, $this->logfile); |
2161 | 2161 | } |
2162 | 2162 | // We only do a simple consistency check |
@@ -2174,11 +2174,11 @@ discard block |
||
2174 | 2174 | if ($this->log) |
2175 | 2175 | { |
2176 | 2176 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2177 | - . '()[ContactUID]: ' . $contact['uid'] |
|
2177 | + . '()[ContactUID]: '.$contact['uid'] |
|
2178 | 2178 | . "\n", 3, $this->logfile); |
2179 | 2179 | } |
2180 | 2180 | // Try the given UID first |
2181 | - $criteria = array ('contact_uid' => $contact['uid']); |
|
2181 | + $criteria = array('contact_uid' => $contact['uid']); |
|
2182 | 2182 | if (($foundContacts = parent::search($criteria))) |
2183 | 2183 | { |
2184 | 2184 | foreach ($foundContacts as $egwContact) |
@@ -2261,7 +2261,7 @@ discard block |
||
2261 | 2261 | { |
2262 | 2262 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2263 | 2263 | . '()[Addressbook FIND Step 1]: ' |
2264 | - . 'CRITERIA = ' . array2string($criteria) |
|
2264 | + . 'CRITERIA = '.array2string($criteria) |
|
2265 | 2265 | . "\n", 3, $this->logfile); |
2266 | 2266 | } |
2267 | 2267 | |
@@ -2290,7 +2290,7 @@ discard block |
||
2290 | 2290 | { |
2291 | 2291 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2292 | 2292 | . '()[Addressbook FIND Step 2]: ' |
2293 | - . 'CRITERIA = ' . array2string($criteria) |
|
2293 | + . 'CRITERIA = '.array2string($criteria) |
|
2294 | 2294 | . "\n", 3, $this->logfile); |
2295 | 2295 | } |
2296 | 2296 | |
@@ -2314,7 +2314,7 @@ discard block |
||
2314 | 2314 | { |
2315 | 2315 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2316 | 2316 | . '()[Addressbook FIND Step 3]: ' |
2317 | - . 'CRITERIA = ' . array2string($criteria) |
|
2317 | + . 'CRITERIA = '.array2string($criteria) |
|
2318 | 2318 | . "\n", 3, $this->logfile); |
2319 | 2319 | } |
2320 | 2320 | |
@@ -2340,7 +2340,7 @@ discard block |
||
2340 | 2340 | { |
2341 | 2341 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2342 | 2342 | . '()[Addressbook FIND Step 4]: ' |
2343 | - . 'CRITERIA = ' . array2string($criteria) |
|
2343 | + . 'CRITERIA = '.array2string($criteria) |
|
2344 | 2344 | . "\n", 3, $this->logfile); |
2345 | 2345 | } |
2346 | 2346 | if (($foundContacts = parent::search($criteria, true, '', '', '', true))) |
@@ -2354,7 +2354,7 @@ discard block |
||
2354 | 2354 | if ($this->log) |
2355 | 2355 | { |
2356 | 2356 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ |
2357 | - . '()[FOUND]: ' . array2string($matchingContacts) |
|
2357 | + . '()[FOUND]: '.array2string($matchingContacts) |
|
2358 | 2358 | . "\n", 3, $this->logfile); |
2359 | 2359 | } |
2360 | 2360 | return $matchingContacts; |
@@ -2371,9 +2371,9 @@ discard block |
||
2371 | 2371 | * @param int|array $owner =null 0=accounts, null=all addressbooks or integer account_id of user or group |
2372 | 2372 | * @return string |
2373 | 2373 | */ |
2374 | - public function get_ctag($owner=null) |
|
2374 | + public function get_ctag($owner = null) |
|
2375 | 2375 | { |
2376 | - $filter = array('tid' => null); // tid=null --> use all entries incl. deleted (tid='D') |
|
2376 | + $filter = array('tid' => null); // tid=null --> use all entries incl. deleted (tid='D') |
|
2377 | 2377 | // show addressbook of a single user? |
2378 | 2378 | if (!is_null($owner)) $filter['owner'] = $owner; |
2379 | 2379 | |
@@ -2382,11 +2382,11 @@ discard block |
||
2382 | 2382 | { |
2383 | 2383 | $filter['account_id'] = null; |
2384 | 2384 | } |
2385 | - $result = $this->search(array(),'contact_modified','contact_modified DESC','','',false,'AND',array(0,1),$filter); |
|
2385 | + $result = $this->search(array(), 'contact_modified', 'contact_modified DESC', '', '', false, 'AND', array(0, 1), $filter); |
|
2386 | 2386 | |
2387 | 2387 | if (!$result || !isset($result[0]['modified'])) |
2388 | 2388 | { |
2389 | - $ctag = 'empty'; // ctag for empty addressbook |
|
2389 | + $ctag = 'empty'; // ctag for empty addressbook |
|
2390 | 2390 | } |
2391 | 2391 | else |
2392 | 2392 | { |
@@ -290,7 +290,10 @@ discard block |
||
290 | 290 | ); |
291 | 291 | //_debug_array($this->contact_fields); |
292 | 292 | $this->own_account_acl = $GLOBALS['egw_info']['server']['own_account_acl']; |
293 | - if (!is_array($this->own_account_acl)) $this->own_account_acl = json_php_unserialize($this->own_account_acl, true); |
|
293 | + if (!is_array($this->own_account_acl)) |
|
294 | + { |
|
295 | + $this->own_account_acl = json_php_unserialize($this->own_account_acl, true); |
|
296 | + } |
|
294 | 297 | // we have only one acl (n_fn) for the whole name, as not all backends store every part in an own field |
295 | 298 | if ($this->own_account_acl && in_array('n_fn',$this->own_account_acl)) |
296 | 299 | { |
@@ -299,7 +302,10 @@ discard block |
||
299 | 302 | if ($GLOBALS['egw_info']['server']['org_fileds_to_update']) |
300 | 303 | { |
301 | 304 | $this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update']; |
302 | - if (!is_array($this->org_fields)) $this->org_fields = unserialize($this->org_fields); |
|
305 | + if (!is_array($this->org_fields)) |
|
306 | + { |
|
307 | + $this->org_fields = unserialize($this->org_fields); |
|
308 | + } |
|
303 | 309 | |
304 | 310 | // Set country code if country name is selected |
305 | 311 | $supported_fields = $this->get_fields('supported',null,0); |
@@ -356,7 +362,10 @@ discard block |
||
356 | 362 | } |
357 | 363 | |
358 | 364 | $addressbooks = $to_sort = array(); |
359 | - if ($extra_label) $addressbooks[''] = $extra_label; |
|
365 | + if ($extra_label) |
|
366 | + { |
|
367 | + $addressbooks[''] = $extra_label; |
|
368 | + } |
|
360 | 369 | $addressbooks[$user] = lang('Personal'); |
361 | 370 | // add all group addressbooks the user has the necessary rights too |
362 | 371 | foreach($grants as $uid => $rights) |
@@ -410,10 +419,19 @@ discard block |
||
410 | 419 | */ |
411 | 420 | function fileas($contact,$type=null, $isUpdate=false) |
412 | 421 | { |
413 | - if (is_null($type)) $type = $contact['fileas_type']; |
|
414 | - if (!$type) $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0]; |
|
422 | + if (is_null($type)) |
|
423 | + { |
|
424 | + $type = $contact['fileas_type']; |
|
425 | + } |
|
426 | + if (!$type) |
|
427 | + { |
|
428 | + $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0]; |
|
429 | + } |
|
415 | 430 | |
416 | - if (strpos($type,'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact); |
|
431 | + if (strpos($type,'n_fn') !== false) |
|
432 | + { |
|
433 | + $contact['n_fn'] = $this->fullname($contact); |
|
434 | + } |
|
417 | 435 | |
418 | 436 | if($isUpdate) |
419 | 437 | { |
@@ -423,7 +441,10 @@ discard block |
||
423 | 441 | { |
424 | 442 | if(!isset($contact[$field])) |
425 | 443 | { |
426 | - if(is_null($old)) $old = $this->read($contact['id']); |
|
444 | + if(is_null($old)) |
|
445 | + { |
|
446 | + $old = $this->read($contact['id']); |
|
447 | + } |
|
427 | 448 | $contact[$field] = $old[$field]; |
428 | 449 | } |
429 | 450 | } |
@@ -466,7 +487,10 @@ discard block |
||
466 | 487 | */ |
467 | 488 | function fileas_type($contact,$file_as=null) |
468 | 489 | { |
469 | - if (is_null($file_as)) $file_as = $contact['n_fileas']; |
|
490 | + if (is_null($file_as)) |
|
491 | + { |
|
492 | + $file_as = $contact['n_fileas']; |
|
493 | + } |
|
470 | 494 | |
471 | 495 | if ($file_as) |
472 | 496 | { |
@@ -519,7 +543,10 @@ discard block |
||
519 | 543 | ); |
520 | 544 | foreach(array_keys($labels) as $name) |
521 | 545 | { |
522 | - if ($contact[$name]) $labels[$name] = $contact[$name]; |
|
546 | + if ($contact[$name]) |
|
547 | + { |
|
548 | + $labels[$name] = $contact[$name]; |
|
549 | + } |
|
523 | 550 | } |
524 | 551 | foreach($this->fileas_types as $fileas_type) |
525 | 552 | { |
@@ -632,7 +659,11 @@ discard block |
||
632 | 659 | $fields_to_update = array(); |
633 | 660 | foreach($contact as $field_name => $field_value) |
634 | 661 | { |
635 | - if($fields_exclude[$field_name] === true) continue; // dont touch specified field |
|
662 | + if($fields_exclude[$field_name] === true) |
|
663 | + { |
|
664 | + continue; |
|
665 | + } |
|
666 | + // dont touch specified field |
|
636 | 667 | |
637 | 668 | if (is_string($field_value) && $field_name != 'pubkey' && $field_name != 'jpegphoto') |
638 | 669 | { |
@@ -691,15 +722,21 @@ discard block |
||
691 | 722 | */ |
692 | 723 | function fullname($contact) |
693 | 724 | { |
694 | - if (empty($contact['n_family']) && empty($contact['n_given'])) { |
|
725 | + if (empty($contact['n_family']) && empty($contact['n_given'])) |
|
726 | + { |
|
695 | 727 | $cpart = array('org_name'); |
696 | - } else { |
|
728 | + } |
|
729 | + else |
|
730 | + { |
|
697 | 731 | $cpart = array('n_prefix','n_given','n_middle','n_family','n_suffix'); |
698 | 732 | } |
699 | 733 | $parts = array(); |
700 | 734 | foreach($cpart as $n) |
701 | 735 | { |
702 | - if ($contact[$n]) $parts[] = $contact[$n]; |
|
736 | + if ($contact[$n]) |
|
737 | + { |
|
738 | + $parts[] = $contact[$n]; |
|
739 | + } |
|
703 | 740 | } |
704 | 741 | return implode(' ',$parts); |
705 | 742 | } |
@@ -810,7 +847,10 @@ discard block |
||
810 | 847 | $ok = false; |
811 | 848 | if ($this->check_perms(Acl::DELETE,$c,$deny_account_delete)) |
812 | 849 | { |
813 | - if (!($old = $this->read($id))) return false; |
|
850 | + if (!($old = $this->read($id))) |
|
851 | + { |
|
852 | + return false; |
|
853 | + } |
|
814 | 854 | // check if we only mark contacts as deleted, or really delete them |
815 | 855 | // already marked as deleted item and accounts are always really deleted |
816 | 856 | // we cant mark accounts as deleted, as no such thing exists for accounts! |
@@ -818,8 +858,15 @@ discard block |
||
818 | 858 | { |
819 | 859 | $delete = $old; |
820 | 860 | $delete['tid'] = self::DELETED_TYPE; |
821 | - if ($check_etag) $delete['etag'] = $check_etag; |
|
822 | - if (($ok = $this->save($delete))) $ok = true; // we have to return true or false |
|
861 | + if ($check_etag) |
|
862 | + { |
|
863 | + $delete['etag'] = $check_etag; |
|
864 | + } |
|
865 | + if (($ok = $this->save($delete))) |
|
866 | + { |
|
867 | + $ok = true; |
|
868 | + } |
|
869 | + // we have to return true or false |
|
823 | 870 | Link::unlink(0,'addressbook',$id,'','','',true); |
824 | 871 | } |
825 | 872 | elseif (($ok = parent::delete($id,$check_etag))) |
@@ -830,7 +877,10 @@ discard block |
||
830 | 877 | // Don't notify of final purge |
831 | 878 | if ($ok && $old['tid'] != self::DELETED_TYPE) |
832 | 879 | { |
833 | - if (!isset($this->tracking)) $this->tracking = new Contacts\Tracking($this); |
|
880 | + if (!isset($this->tracking)) |
|
881 | + { |
|
882 | + $this->tracking = new Contacts\Tracking($this); |
|
883 | + } |
|
834 | 884 | $this->tracking->track(array('id' => $id), array('id' => $id), null, true); |
835 | 885 | } |
836 | 886 | } |
@@ -855,13 +905,16 @@ discard block |
||
855 | 905 | // remember if we add or update a entry |
856 | 906 | if (($isUpdate = $contact['id'])) |
857 | 907 | { |
858 | - if (!isset($contact['owner']) || !isset($contact['private'])) // owner/private not set on update, eg. SyncML |
|
908 | + if (!isset($contact['owner']) || !isset($contact['private'])) |
|
909 | + { |
|
910 | + // owner/private not set on update, eg. SyncML |
|
859 | 911 | { |
860 | 912 | if (($old = $this->read($contact['id']))) // --> try reading the old entry and set it from there |
861 | 913 | { |
862 | 914 | if(!isset($contact['owner'])) |
863 | 915 | { |
864 | 916 | $contact['owner'] = $old['owner']; |
917 | + } |
|
865 | 918 | } |
866 | 919 | if(!isset($contact['private'])) |
867 | 920 | { |
@@ -877,18 +930,33 @@ discard block |
||
877 | 930 | else |
878 | 931 | { |
879 | 932 | // if no owner/addressbook set use the setting of the add_default prefs (if set, otherwise the users personal addressbook) |
880 | - if (!isset($contact['owner'])) $contact['owner'] = $this->default_addressbook; |
|
881 | - if (!isset($contact['private'])) $contact['private'] = (int)$this->default_private; |
|
933 | + if (!isset($contact['owner'])) |
|
934 | + { |
|
935 | + $contact['owner'] = $this->default_addressbook; |
|
936 | + } |
|
937 | + if (!isset($contact['private'])) |
|
938 | + { |
|
939 | + $contact['private'] = (int)$this->default_private; |
|
940 | + } |
|
882 | 941 | // do NOT allow to create new accounts via addressbook, they are broken without an account_id |
883 | 942 | if (!$contact['owner'] && empty($contact['account_id'])) |
884 | 943 | { |
885 | 944 | $contact['owner'] = $this->default_addressbook ? $this->default_addressbook : $this->user; |
886 | 945 | } |
887 | 946 | // allow admins to import contacts with creator / created date set |
888 | - if (!$contact['creator'] || !$this->is_admin($contact)) $contact['creator'] = $this->user; |
|
889 | - if (!$contact['created'] || !$this->is_admin($contact)) $contact['created'] = $this->now_su; |
|
947 | + if (!$contact['creator'] || !$this->is_admin($contact)) |
|
948 | + { |
|
949 | + $contact['creator'] = $this->user; |
|
950 | + } |
|
951 | + if (!$contact['created'] || !$this->is_admin($contact)) |
|
952 | + { |
|
953 | + $contact['created'] = $this->now_su; |
|
954 | + } |
|
890 | 955 | |
891 | - if (!$contact['tid']) $contact['tid'] = 'n'; |
|
956 | + if (!$contact['tid']) |
|
957 | + { |
|
958 | + $contact['tid'] = 'n'; |
|
959 | + } |
|
892 | 960 | } |
893 | 961 | // ensure accounts and group addressbooks are never private! |
894 | 962 | if ($contact['owner'] <= 0) |
@@ -912,7 +980,8 @@ discard block |
||
912 | 980 | } |
913 | 981 | |
914 | 982 | // Update country codes |
915 | - foreach(array('adr_one_', 'adr_two_') as $c_prefix) { |
|
983 | + foreach(array('adr_one_', 'adr_two_') as $c_prefix) |
|
984 | + { |
|
916 | 985 | if($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] && |
917 | 986 | $code = Country::country_code($contact[$c_prefix.'countryname'])) |
918 | 987 | { |
@@ -939,7 +1008,10 @@ discard block |
||
939 | 1008 | { |
940 | 1009 | $contact['n_fn'] = $this->fullname($contact); |
941 | 1010 | } |
942 | - if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact, null, false); |
|
1011 | + if (isset($contact['org_name'])) |
|
1012 | + { |
|
1013 | + $contact['n_fileas'] = $this->fileas($contact, null, false); |
|
1014 | + } |
|
943 | 1015 | |
944 | 1016 | // Get old record for tracking changes |
945 | 1017 | if (!isset($old) && $isUpdate) |
@@ -1015,7 +1087,10 @@ discard block |
||
1015 | 1087 | if(!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql') |
1016 | 1088 | { |
1017 | 1089 | $deleted = ($old['tid'] == self::DELETED_TYPE || $contact['tid'] == self::DELETED_TYPE); |
1018 | - if (!isset($this->tracking)) $this->tracking = new Contacts\Tracking($this); |
|
1090 | + if (!isset($this->tracking)) |
|
1091 | + { |
|
1092 | + $this->tracking = new Contacts\Tracking($this); |
|
1093 | + } |
|
1019 | 1094 | $this->tracking->track($to_write, $old ? $old : null, null, $deleted); |
1020 | 1095 | } |
1021 | 1096 | } |
@@ -1097,10 +1172,12 @@ discard block |
||
1097 | 1172 | $data['fileas_type'] = $this->fileas_type($data); |
1098 | 1173 | |
1099 | 1174 | // Update country name from code |
1100 | - if($data['adr_one_countrycode'] != null) { |
|
1175 | + if($data['adr_one_countrycode'] != null) |
|
1176 | + { |
|
1101 | 1177 | $data['adr_one_countryname'] = Country::get_full_name($data['adr_one_countrycode'], true); |
1102 | 1178 | } |
1103 | - if($data['adr_two_countrycode'] != null) { |
|
1179 | + if($data['adr_two_countrycode'] != null) |
|
1180 | + { |
|
1104 | 1181 | $data['adr_two_countryname'] = Country::get_full_name($data['adr_two_countrycode'], true); |
1105 | 1182 | } |
1106 | 1183 | } |
@@ -1126,7 +1203,10 @@ discard block |
||
1126 | 1203 | */ |
1127 | 1204 | function check_perms($needed,$contact,$deny_account_delete=false,$user=null) |
1128 | 1205 | { |
1129 | - if (!$user) $user = $this->user; |
|
1206 | + if (!$user) |
|
1207 | + { |
|
1208 | + $user = $this->user; |
|
1209 | + } |
|
1130 | 1210 | if ($user == $this->user) |
1131 | 1211 | { |
1132 | 1212 | $grants = $this->grants; |
@@ -1196,8 +1276,14 @@ discard block |
||
1196 | 1276 | */ |
1197 | 1277 | function read_org($org_id) |
1198 | 1278 | { |
1199 | - if (!$org_id) return false; |
|
1200 | - if (strpos($org_id,'*AND*')!== false) $org_id = str_replace('*AND*','&',$org_id); |
|
1279 | + if (!$org_id) |
|
1280 | + { |
|
1281 | + return false; |
|
1282 | + } |
|
1283 | + if (strpos($org_id,'*AND*')!== false) |
|
1284 | + { |
|
1285 | + $org_id = str_replace('*AND*','&',$org_id); |
|
1286 | + } |
|
1201 | 1287 | $org = array(); |
1202 | 1288 | foreach(explode('|||',$org_id) as $part) |
1203 | 1289 | { |
@@ -1227,7 +1313,10 @@ discard block |
||
1227 | 1313 | } |
1228 | 1314 | // read the regular fields |
1229 | 1315 | $contacts = parent::search('',$regular_fields,'','','',false,'AND',false,$org); |
1230 | - if (!$contacts) return false; |
|
1316 | + if (!$contacts) |
|
1317 | + { |
|
1318 | + return false; |
|
1319 | + } |
|
1231 | 1320 | |
1232 | 1321 | // if we have custom fields, read and merge them in |
1233 | 1322 | if ($custom_fields) |
@@ -1275,7 +1364,10 @@ discard block |
||
1275 | 1364 | } |
1276 | 1365 | foreach($fields as $name => $values) |
1277 | 1366 | { |
1278 | - if (!in_array($name,$this->org_fields)) continue; |
|
1367 | + if (!in_array($name,$this->org_fields)) |
|
1368 | + { |
|
1369 | + continue; |
|
1370 | + } |
|
1279 | 1371 | |
1280 | 1372 | arsort($values,SORT_NUMERIC); |
1281 | 1373 | list($value,$num) = each($values); |
@@ -1345,16 +1437,25 @@ discard block |
||
1345 | 1437 | 'adr_two_countryname' => 'adr_one_countrycode', |
1346 | 1438 | ) as $name => $code) |
1347 | 1439 | { |
1348 | - if (!empty($from[$code])) $from[$name] = ''; |
|
1349 | - if (!empty($to[$code])) $to[$name] = ''; |
|
1440 | + if (!empty($from[$code])) |
|
1441 | + { |
|
1442 | + $from[$name] = ''; |
|
1443 | + } |
|
1444 | + if (!empty($to[$code])) |
|
1445 | + { |
|
1446 | + $to[$name] = ''; |
|
1447 | + } |
|
1350 | 1448 | } |
1351 | 1449 | $changed = array(); |
1352 | 1450 | foreach($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name) |
1353 | 1451 | { |
1354 | - if (in_array($name,array('modified','modifier'))) // never count these |
|
1452 | + if (in_array($name,array('modified','modifier'))) |
|
1453 | + { |
|
1454 | + // never count these |
|
1355 | 1455 | { |
1356 | 1456 | continue; |
1357 | 1457 | } |
1458 | + } |
|
1358 | 1459 | if ((string) $from[$name] != (string) $to[$name]) |
1359 | 1460 | { |
1360 | 1461 | $changed[$name] = $from[$name]; |
@@ -1374,13 +1475,19 @@ discard block |
||
1374 | 1475 | */ |
1375 | 1476 | function change_org($org_name,$from,$to,$members=null) |
1376 | 1477 | { |
1377 | - if (!($changed = $this->changed_fields($from,$to,true))) return false; |
|
1478 | + if (!($changed = $this->changed_fields($from,$to,true))) |
|
1479 | + { |
|
1480 | + return false; |
|
1481 | + } |
|
1378 | 1482 | |
1379 | 1483 | if (is_null($members) || !is_array($members)) |
1380 | 1484 | { |
1381 | 1485 | $members = $this->org_similar($org_name,$changed); |
1382 | 1486 | } |
1383 | - if (!$members) return false; |
|
1487 | + if (!$members) |
|
1488 | + { |
|
1489 | + return false; |
|
1490 | + } |
|
1384 | 1491 | |
1385 | 1492 | $ids = array(); |
1386 | 1493 | foreach($members as $member) |
@@ -1445,7 +1552,10 @@ discard block |
||
1445 | 1552 | $type = $this->prefs['link_title']; |
1446 | 1553 | if (!$type || $type === 'n_fileas') |
1447 | 1554 | { |
1448 | - if ($contact['n_fileas']) return $contact['n_fileas']; |
|
1555 | + if ($contact['n_fileas']) |
|
1556 | + { |
|
1557 | + return $contact['n_fileas']; |
|
1558 | + } |
|
1449 | 1559 | $type = null; |
1450 | 1560 | } |
1451 | 1561 | $title = $this->fileas($contact,$type); |
@@ -1513,7 +1623,10 @@ discard block |
||
1513 | 1623 | $limit = array($options['start'], $options['num_rows']); |
1514 | 1624 | } |
1515 | 1625 | $filter = (array)$options['filter']; |
1516 | - if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $filter['account_id'] = null; |
|
1626 | + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) |
|
1627 | + { |
|
1628 | + $filter['account_id'] = null; |
|
1629 | + } |
|
1517 | 1630 | if (($contacts =& parent::search($criteria,false,'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR', $limit, $filter))) |
1518 | 1631 | { |
1519 | 1632 | $ids = array(); |
@@ -1576,12 +1689,18 @@ discard block |
||
1576 | 1689 | */ |
1577 | 1690 | function calendar_info($ids) |
1578 | 1691 | { |
1579 | - if (!$ids) return null; |
|
1692 | + if (!$ids) |
|
1693 | + { |
|
1694 | + return null; |
|
1695 | + } |
|
1580 | 1696 | |
1581 | 1697 | $data = array(); |
1582 | 1698 | foreach(!is_array($ids) ? array($ids) : $ids as $id) |
1583 | 1699 | { |
1584 | - if (!($contact = $this->read($id))) continue; |
|
1700 | + if (!($contact = $this->read($id))) |
|
1701 | + { |
|
1702 | + continue; |
|
1703 | + } |
|
1585 | 1704 | |
1586 | 1705 | $data[] = array( |
1587 | 1706 | 'res_id' => $id, |
@@ -1603,21 +1722,33 @@ discard block |
||
1603 | 1722 | */ |
1604 | 1723 | function read_calendar($ids,$extra_title=true) |
1605 | 1724 | { |
1606 | - if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return array(); |
|
1725 | + if (!$GLOBALS['egw_info']['user']['apps']['calendar']) |
|
1726 | + { |
|
1727 | + return array(); |
|
1728 | + } |
|
1607 | 1729 | |
1608 | 1730 | $uids = array(); |
1609 | 1731 | foreach($ids as $id) |
1610 | 1732 | { |
1611 | - if (is_numeric($id)) $uids[] = 'c'.$id; |
|
1733 | + if (is_numeric($id)) |
|
1734 | + { |
|
1735 | + $uids[] = 'c'.$id; |
|
1736 | + } |
|
1737 | + } |
|
1738 | + if (!$uids) |
|
1739 | + { |
|
1740 | + return array(); |
|
1612 | 1741 | } |
1613 | - if (!$uids) return array(); |
|
1614 | 1742 | |
1615 | 1743 | $bocal = new calendar_bo(); |
1616 | 1744 | $events = $bocal->search(array( |
1617 | 1745 | 'users' => $uids, |
1618 | 1746 | 'enum_recuring' => true, |
1619 | 1747 | )); |
1620 | - if (!$events) return array(); |
|
1748 | + if (!$events) |
|
1749 | + { |
|
1750 | + return array(); |
|
1751 | + } |
|
1621 | 1752 | |
1622 | 1753 | //_debug_array($events); |
1623 | 1754 | $calendars = array(); |
@@ -1631,11 +1762,14 @@ discard block |
||
1631 | 1762 | } |
1632 | 1763 | $id = (int)substr($uid,1); |
1633 | 1764 | |
1634 | - if ($event['start'] < $this->now_su) // past event --> check for last event |
|
1765 | + if ($event['start'] < $this->now_su) |
|
1766 | + { |
|
1767 | + // past event --> check for last event |
|
1635 | 1768 | { |
1636 | 1769 | if (!isset($calendars[$id]['last_event']) || $event['start'] > $calendars[$id]['last_event']) |
1637 | 1770 | { |
1638 | 1771 | $calendars[$id]['last_event'] = $event['start']; |
1772 | + } |
|
1639 | 1773 | $link = array( |
1640 | 1774 | 'id' => $event['id'], |
1641 | 1775 | 'app' => 'calendar', |
@@ -1737,27 +1871,36 @@ discard block |
||
1737 | 1871 | $account = null; |
1738 | 1872 | $custom_fields = Storage\Customfields::get('addressbook', true); |
1739 | 1873 | $custom_field_list = $this->read_customfields($ids); |
1740 | - foreach(parent::search(array('id'=>$ids),false) as $contact) // $this->search calls the extended search from ui! |
|
1874 | + foreach(parent::search(array('id'=>$ids),false) as $contact) |
|
1875 | + { |
|
1876 | + // $this->search calls the extended search from ui! |
|
1741 | 1877 | { |
1742 | 1878 | if ($contact['account_id']) |
1743 | 1879 | { |
1744 | 1880 | if (!is_null($account)) |
1745 | 1881 | { |
1746 | 1882 | echo $this->error = 'Can not merge more then one account!'; |
1883 | + } |
|
1747 | 1884 | return false; // we dont deal with two accounts! |
1748 | 1885 | } |
1749 | 1886 | $account = $contact; |
1750 | 1887 | continue; |
1751 | 1888 | } |
1752 | 1889 | // Add in custom fields |
1753 | - if (is_array($custom_field_list[$contact['id']])) $contact = array_merge($contact, $custom_field_list[$contact['id']]); |
|
1890 | + if (is_array($custom_field_list[$contact['id']])) |
|
1891 | + { |
|
1892 | + $contact = array_merge($contact, $custom_field_list[$contact['id']]); |
|
1893 | + } |
|
1754 | 1894 | |
1755 | 1895 | $pos = array_search($contact['id'],$ids); |
1756 | 1896 | $contacts[$pos] = $contact; |
1757 | 1897 | } |
1758 | - if (!is_null($account)) // we found an account, so we merge the contacts into it |
|
1898 | + if (!is_null($account)) |
|
1899 | + { |
|
1900 | + // we found an account, so we merge the contacts into it |
|
1759 | 1901 | { |
1760 | 1902 | $target = $account; |
1903 | + } |
|
1761 | 1904 | unset($account); |
1762 | 1905 | } |
1763 | 1906 | else // we found no account, so we merge all but the first into the first |
@@ -1774,7 +1917,10 @@ discard block |
||
1774 | 1917 | { |
1775 | 1918 | foreach($contact as $name => $value) |
1776 | 1919 | { |
1777 | - if (!$value) continue; |
|
1920 | + if (!$value) |
|
1921 | + { |
|
1922 | + continue; |
|
1923 | + } |
|
1778 | 1924 | |
1779 | 1925 | switch($name) |
1780 | 1926 | { |
@@ -1786,25 +1932,39 @@ discard block |
||
1786 | 1932 | break; // ignored |
1787 | 1933 | |
1788 | 1934 | case 'cat_id': // cats are all merged together |
1789 | - if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array(); |
|
1935 | + if (!is_array($target['cat_id'])) |
|
1936 | + { |
|
1937 | + $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array(); |
|
1938 | + } |
|
1790 | 1939 | $target['cat_id'] = array_unique(array_merge($target['cat_id'],is_array($value)?$value:explode(',',$value))); |
1791 | 1940 | break; |
1792 | 1941 | |
1793 | 1942 | default: |
1794 | 1943 | // Multi-select custom fields can also be merged |
1795 | - if($name[0] == '#') { |
|
1944 | + if($name[0] == '#') |
|
1945 | + { |
|
1796 | 1946 | $c_name = substr($name, 1); |
1797 | - if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) { |
|
1798 | - if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',',$target[$name]) : array(); |
|
1947 | + if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) |
|
1948 | + { |
|
1949 | + if (!is_array($target[$name])) |
|
1950 | + { |
|
1951 | + $target[$name] = $target[$name] ? explode(',',$target[$name]) : array(); |
|
1952 | + } |
|
1799 | 1953 | $target[$name] = implode(',',array_unique(array_merge($target[$name],is_array($value)?$value:explode(',',$value)))); |
1800 | 1954 | } |
1801 | 1955 | } |
1802 | - if (!$target[$name]) $target[$name] = $value; |
|
1956 | + if (!$target[$name]) |
|
1957 | + { |
|
1958 | + $target[$name] = $value; |
|
1959 | + } |
|
1803 | 1960 | break; |
1804 | 1961 | } |
1805 | 1962 | } |
1806 | 1963 | } |
1807 | - if (!$this->save($target)) return 0; |
|
1964 | + if (!$this->save($target)) |
|
1965 | + { |
|
1966 | + return 0; |
|
1967 | + } |
|
1808 | 1968 | |
1809 | 1969 | $success = 1; |
1810 | 1970 | foreach($contacts as $contact) |
@@ -1834,7 +1994,10 @@ discard block |
||
1834 | 1994 | unset($newlinkID); |
1835 | 1995 | } |
1836 | 1996 | } |
1837 | - if ($this->delete($contact['id'])) $success++; |
|
1997 | + if ($this->delete($contact['id'])) |
|
1998 | + { |
|
1999 | + $success++; |
|
2000 | + } |
|
1838 | 2001 | } |
1839 | 2002 | return $success; |
1840 | 2003 | } |
@@ -1875,11 +2038,17 @@ discard block |
||
1875 | 2038 | */ |
1876 | 2039 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
1877 | 2040 | { |
1878 | - if (!$this->check_list(null,Acl::ADD|Acl::EDIT,$owner)) return false; |
|
2041 | + if (!$this->check_list(null,Acl::ADD|Acl::EDIT,$owner)) |
|
2042 | + { |
|
2043 | + return false; |
|
2044 | + } |
|
1879 | 2045 | |
1880 | 2046 | try { |
1881 | 2047 | $ret = parent::add_list($keys,$owner,$contacts,$data); |
1882 | - if ($ret) unset(self::$list_cache[$ret]); |
|
2048 | + if ($ret) |
|
2049 | + { |
|
2050 | + unset(self::$list_cache[$ret]); |
|
2051 | + } |
|
1883 | 2052 | } |
1884 | 2053 | // catch sql error, as creating same name&owner list gives a sql error doublicate key |
1885 | 2054 | catch(Api\Db\Exception\InvalidSql $e) { |
@@ -1899,7 +2068,10 @@ discard block |
||
1899 | 2068 | */ |
1900 | 2069 | function add2list($contact,$list,array $existing=null) |
1901 | 2070 | { |
1902 | - if (!$this->check_list($list,Acl::EDIT)) return false; |
|
2071 | + if (!$this->check_list($list,Acl::EDIT)) |
|
2072 | + { |
|
2073 | + return false; |
|
2074 | + } |
|
1903 | 2075 | |
1904 | 2076 | unset(self::$list_cache[$list]); |
1905 | 2077 | |
@@ -1915,7 +2087,10 @@ discard block |
||
1915 | 2087 | */ |
1916 | 2088 | function remove_from_list($contact,$list=null) |
1917 | 2089 | { |
1918 | - if ($list && !$this->check_list($list,Acl::EDIT)) return false; |
|
2090 | + if ($list && !$this->check_list($list,Acl::EDIT)) |
|
2091 | + { |
|
2092 | + return false; |
|
2093 | + } |
|
1919 | 2094 | |
1920 | 2095 | if ($list) |
1921 | 2096 | { |
@@ -1937,7 +2112,10 @@ discard block |
||
1937 | 2112 | */ |
1938 | 2113 | function delete_list($list) |
1939 | 2114 | { |
1940 | - if (!$this->check_list($list,Acl::DELETE)) return false; |
|
2115 | + if (!$this->check_list($list,Acl::DELETE)) |
|
2116 | + { |
|
2117 | + return false; |
|
2118 | + } |
|
1941 | 2119 | |
1942 | 2120 | foreach((array)$list as $l) |
1943 | 2121 | { |
@@ -1955,7 +2133,10 @@ discard block |
||
1955 | 2133 | */ |
1956 | 2134 | function read_list($list) |
1957 | 2135 | { |
1958 | - if (isset(self::$list_cache[$list])) return self::$list_cache[$list]; |
|
2136 | + if (isset(self::$list_cache[$list])) |
|
2137 | + { |
|
2138 | + return self::$list_cache[$list]; |
|
2139 | + } |
|
1959 | 2140 | |
1960 | 2141 | return self::$list_cache[$list] = parent::read_list($list); |
1961 | 2142 | } |
@@ -2210,7 +2391,10 @@ discard block |
||
2210 | 2391 | |
2211 | 2392 | foreach ($columns_to_search as $field) |
2212 | 2393 | { |
2213 | - if ($relax && in_array($field, $tolerance_fields)) continue; |
|
2394 | + if ($relax && in_array($field, $tolerance_fields)) |
|
2395 | + { |
|
2396 | + continue; |
|
2397 | + } |
|
2214 | 2398 | |
2215 | 2399 | if (empty($contact[$field])) |
2216 | 2400 | { |
@@ -2275,7 +2459,10 @@ discard block |
||
2275 | 2459 | } |
2276 | 2460 | |
2277 | 2461 | // No need for more searches for relaxed matching |
2278 | - if ($relax || count($matchingContacts)) return $matchingContacts; |
|
2462 | + if ($relax || count($matchingContacts)) |
|
2463 | + { |
|
2464 | + return $matchingContacts; |
|
2465 | + } |
|
2279 | 2466 | |
2280 | 2467 | |
2281 | 2468 | if (!$empty_addr_one && $empty_addr_two) |
@@ -2328,7 +2515,8 @@ discard block |
||
2328 | 2515 | } |
2329 | 2516 | } |
2330 | 2517 | elseif (!$empty_addr_one && !$empty_addr_two) |
2331 | - { // try again after address swap |
|
2518 | + { |
|
2519 | +// try again after address swap |
|
2332 | 2520 | |
2333 | 2521 | foreach ($addr_one_fields as $key => $field) |
2334 | 2522 | { |
@@ -2375,7 +2563,10 @@ discard block |
||
2375 | 2563 | { |
2376 | 2564 | $filter = array('tid' => null); // tid=null --> use all entries incl. deleted (tid='D') |
2377 | 2565 | // show addressbook of a single user? |
2378 | - if (!is_null($owner)) $filter['owner'] = $owner; |
|
2566 | + if (!is_null($owner)) |
|
2567 | + { |
|
2568 | + $filter['owner'] = $owner; |
|
2569 | + } |
|
2379 | 2570 | |
2380 | 2571 | // should we hide the accounts addressbook |
2381 | 2572 | if (!$owner && $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) |
@@ -1500,7 +1500,7 @@ discard block |
||
1500 | 1500 | * @param array $options Array of options for the search |
1501 | 1501 | * @return array with id - title pairs of the matching entries |
1502 | 1502 | */ |
1503 | - function link_query($pattern, Array &$options = array()) |
|
1503 | + function link_query($pattern, array &$options = array()) |
|
1504 | 1504 | { |
1505 | 1505 | $result = $criteria = array(); |
1506 | 1506 | $limit = false; |
@@ -1553,7 +1553,7 @@ discard block |
||
1553 | 1553 | * @param array $options |
1554 | 1554 | * @return Ambigous <multitype:, string, multitype:Ambigous <multitype:, string> string > |
1555 | 1555 | */ |
1556 | - function link_query_email($pattern, Array &$options = array()) |
|
1556 | + function link_query_email($pattern, array &$options = array()) |
|
1557 | 1557 | { |
1558 | 1558 | if (isset($options['filter']) && !is_array($options['filter'])) |
1559 | 1559 | { |
@@ -213,7 +213,6 @@ |
||
213 | 213 | /** |
214 | 214 | * Remove attributes we are not allowed to update |
215 | 215 | * |
216 | - * @param array $attributes |
|
217 | 216 | */ |
218 | 217 | function sanitize_update(array &$ldapContact) |
219 | 218 | { |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email'); |
36 | 36 | */ |
37 | 37 | var $search_attributes = array( |
38 | - 'n_family','n_middle','n_given','org_name','org_unit', |
|
39 | - 'adr_one_location','note','email','samaccountname', |
|
38 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
39 | + 'adr_one_location', 'note', 'email', 'samaccountname', |
|
40 | 40 | ); |
41 | 41 | |
42 | 42 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @var string |
52 | 52 | */ |
53 | - var $dn_attribute='cn'; |
|
53 | + var $dn_attribute = 'cn'; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!) |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server'] |
83 | 83 | * @param resource $ds =null ldap connection to use |
84 | 84 | */ |
85 | - function __construct(array $ldap_config=null, $ds=null) |
|
85 | + function __construct(array $ldap_config = null, $ds = null) |
|
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) parent::__construct(); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 88 | |
89 | - $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
89 | + $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
90 | 90 | |
91 | 91 | if ($ldap_config) |
92 | 92 | { |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | else |
96 | 96 | { |
97 | - $this->ldap_config =& $GLOBALS['egw_info']['server']; |
|
97 | + $this->ldap_config = & $GLOBALS['egw_info']['server']; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $this->accounts_ads = $GLOBALS['egw']->accounts->backend; |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | 'account_id' => 'objectsid', |
120 | 120 | 'id' => 'objectguid', |
121 | 121 | 'uid' => 'objectguid', |
122 | - 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | - 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
122 | + 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | + 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
124 | 124 | )); |
125 | 125 | unset($this->schema2egw['user']['n_fileas']); |
126 | 126 | unset($this->schema2egw['inetorgperson']); |
127 | 127 | |
128 | - foreach($this->schema2egw as $attributes) |
|
128 | + foreach ($this->schema2egw as $attributes) |
|
129 | 129 | { |
130 | - $this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); |
|
130 | + $this->all_attributes = array_merge($this->all_attributes, array_values($attributes)); |
|
131 | 131 | } |
132 | 132 | $this->all_attributes = array_values(array_unique($this->all_attributes)); |
133 | 133 | |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param boolean $admin =false true (re-)connect with admin not user credentials, eg. to modify accounts |
141 | 141 | */ |
142 | - function connect($admin=false) |
|
142 | + function connect($admin = false) |
|
143 | 143 | { |
144 | - unset($admin); // not used, but required by function signature |
|
144 | + unset($admin); // not used, but required by function signature |
|
145 | 145 | |
146 | 146 | $this->ds = $this->accounts_ads->ldap_connection(); |
147 | 147 | } |
@@ -174,15 +174,14 @@ discard block |
||
174 | 174 | function read($_contact_id) |
175 | 175 | { |
176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
177 | - !is_array($_contact_id) && substr($_contact_id,0,8) == 'account:') |
|
177 | + !is_array($_contact_id) && substr($_contact_id, 0, 8) == 'account:') |
|
178 | 178 | { |
179 | - $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id,8)); |
|
179 | + $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id, 8)); |
|
180 | 180 | $_contact_id = $GLOBALS['egw']->accounts->id2name($account_id, 'person_id'); |
181 | 181 | } |
182 | - $contact_id = !is_array($_contact_id) ? $_contact_id : |
|
183 | - (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
182 | + $contact_id = !is_array($_contact_id) ? $_contact_id : (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
184 | 183 | |
185 | - $rows = $this->_searchLDAP($this->allContactsDN, $filter=$this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
184 | + $rows = $this->_searchLDAP($this->allContactsDN, $filter = $this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
186 | 185 | //error_log(__METHOD__."('$contact_id') _searchLDAP($this->allContactsDN, '$filter',...)=".array2string($rows)); |
187 | 186 | return $rows ? $rows[0] : false; |
188 | 187 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * while it uses select-account for owner in historylog (containing all users). |
34 | 34 | * |
35 | 35 | * @param string $cname |
36 | - */ |
|
36 | + */ |
|
37 | 37 | public function beforeSendToClient($cname) |
38 | 38 | { |
39 | 39 | $form_name = self::form_name($cname, $this->id); |
@@ -84,7 +84,11 @@ discard block |
||
84 | 84 | */ |
85 | 85 | function __construct(array $ldap_config=null, $ds=null) |
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) |
|
88 | + { |
|
89 | + parent::__construct (); |
|
90 | + } |
|
91 | + // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 92 | |
89 | 93 | $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
90 | 94 | |
@@ -202,10 +206,16 @@ discard block |
||
202 | 206 | $contact['id'] = $contact['uid'] = $this->accounts_ads->objectguid2str($data['objectguid']); |
203 | 207 | |
204 | 208 | // ignore system accounts |
205 | - if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) return false; |
|
209 | + if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) |
|
210 | + { |
|
211 | + return false; |
|
212 | + } |
|
206 | 213 | |
207 | 214 | // ignore deactivated or expired accounts |
208 | - if (!$this->accounts_ads->user_active($data)) return false; |
|
215 | + if (!$this->accounts_ads->user_active($data)) |
|
216 | + { |
|
217 | + return false; |
|
218 | + } |
|
209 | 219 | |
210 | 220 | $this->_inetorgperson2egw($contact, $data, 'displayname'); |
211 | 221 | } |
@@ -425,7 +425,6 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * Remove attributes we are not allowed to update |
427 | 427 | * |
428 | - * @param array $attributes |
|
429 | 428 | */ |
430 | 429 | function sanitize_update(array &$ldapContact) |
431 | 430 | { |
@@ -703,14 +702,14 @@ discard block |
||
703 | 702 | * |
704 | 703 | * '*' and '?' are replaced with sql-wildcards '%' and '_' |
705 | 704 | * |
706 | - * @param array|string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) |
|
705 | + * @param boolean $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) |
|
707 | 706 | * @param boolean|string $only_keys =true True returns only keys, False returns all cols. comma seperated list of keys to return |
708 | 707 | * @param string $order_by ='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) |
709 | - * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
708 | + * @param string $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
710 | 709 | * @param string $wildcard ='' appended befor and after each criteria |
711 | 710 | * @param boolean $empty =false False=empty criteria are ignored in query, True=empty have to be empty in row |
712 | 711 | * @param string $op ='AND' defaults to 'AND', can be set to 'OR' too, then criteria's are OR'ed together |
713 | - * @param mixed $start =false if != false, return only maxmatch rows begining with start, or array($start,$num) |
|
712 | + * @param boolean $start =false if != false, return only maxmatch rows begining with start, or array($start,$num) |
|
714 | 713 | * @param array $filter =null if set (!=null) col-data pairs, to be and-ed (!) into the query without wildcards |
715 | 714 | * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
716 | 715 | * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
@@ -41,33 +41,33 @@ discard block |
||
41 | 41 | var $contacts_id='id'; |
42 | 42 | |
43 | 43 | /** |
44 | - * @var string $accountName holds the accountname of the current user |
|
45 | - */ |
|
44 | + * @var string $accountName holds the accountname of the current user |
|
45 | + */ |
|
46 | 46 | var $accountName; |
47 | 47 | |
48 | 48 | /** |
49 | - * @var object $ldapServerInfo holds the information about the current used ldap server |
|
50 | - */ |
|
49 | + * @var object $ldapServerInfo holds the information about the current used ldap server |
|
50 | + */ |
|
51 | 51 | var $ldapServerInfo; |
52 | 52 | |
53 | 53 | /** |
54 | - * @var int $ldapLimit how many rows to fetch from ldap server |
|
55 | - */ |
|
54 | + * @var int $ldapLimit how many rows to fetch from ldap server |
|
55 | + */ |
|
56 | 56 | var $ldapLimit = 2000; |
57 | 57 | |
58 | 58 | /** |
59 | - * @var string $personalContactsDN holds the base DN for the personal addressbooks |
|
60 | - */ |
|
59 | + * @var string $personalContactsDN holds the base DN for the personal addressbooks |
|
60 | + */ |
|
61 | 61 | var $personalContactsDN; |
62 | 62 | |
63 | 63 | /** |
64 | - * @var string $sharedContactsDN holds the base DN for the shared addressbooks |
|
65 | - */ |
|
64 | + * @var string $sharedContactsDN holds the base DN for the shared addressbooks |
|
65 | + */ |
|
66 | 66 | var $sharedContactsDN; |
67 | 67 | |
68 | 68 | /** |
69 | - * @var string $accountContactsDN holds the base DN for accounts addressbook |
|
70 | - */ |
|
69 | + * @var string $accountContactsDN holds the base DN for accounts addressbook |
|
70 | + */ |
|
71 | 71 | var $accountContactsDN; |
72 | 72 | |
73 | 73 | /** |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | var $accountsFilter = '(objectclass=posixaccount)'; |
78 | 78 | |
79 | 79 | /** |
80 | - * @var string $allContactsDN holds the base DN of all addressbook |
|
81 | - */ |
|
80 | + * @var string $allContactsDN holds the base DN of all addressbook |
|
81 | + */ |
|
82 | 82 | var $allContactsDN; |
83 | 83 | |
84 | 84 | /** |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | var $never_change_dn = false; |
97 | 97 | |
98 | 98 | /** |
99 | - * @var int $total holds the total count of found rows |
|
100 | - */ |
|
99 | + * @var int $total holds the total count of found rows |
|
100 | + */ |
|
101 | 101 | var $total; |
102 | 102 | |
103 | 103 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * |
404 | 404 | * @param string|array $contact_id contact_id or array with values for id or account_id |
405 | 405 | * @return array/boolean data if row could be retrived else False |
406 | - */ |
|
406 | + */ |
|
407 | 407 | function read($contact_id) |
408 | 408 | { |
409 | 409 | if (is_array($contact_id) && isset($contact_id['account_id']) || |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @var string |
40 | 40 | */ |
41 | - var $contacts_id='id'; |
|
41 | + var $contacts_id = 'id'; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @var string $accountName holds the accountname of the current user |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @var string |
88 | 88 | */ |
89 | - var $dn_attribute='uid'; |
|
89 | + var $dn_attribute = 'uid'; |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!) |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email'); |
114 | 114 | */ |
115 | 115 | var $search_attributes = array( |
116 | - 'n_family','n_middle','n_given','org_name','org_unit', |
|
117 | - 'adr_one_location','adr_two_location','note', |
|
118 | - 'email','mozillasecondemail','uidnumber', |
|
116 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
117 | + 'adr_one_location', 'adr_two_location', 'note', |
|
118 | + 'email', 'mozillasecondemail', 'uidnumber', |
|
119 | 119 | ); |
120 | 120 | |
121 | 121 | /** |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | #postOfficeBox |
172 | 172 | 'mozillaabpersonalpha' => array( |
173 | 173 | 'adr_one_street2' => 'mozillaworkstreet2', |
174 | - 'adr_one_countryname' => 'c', // 2 letter country code |
|
175 | - 'adr_one_countrycode' => 'c', // 2 letter country code |
|
174 | + 'adr_one_countryname' => 'c', // 2 letter country code |
|
175 | + 'adr_one_countrycode' => 'c', // 2 letter country code |
|
176 | 176 | 'adr_two_street' => 'mozillahomestreet', |
177 | 177 | 'adr_two_street2' => 'mozillahomestreet2', |
178 | 178 | 'adr_two_locality' => 'mozillahomelocalityname', |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | // similar to the newer mozillaAbPerson, but uses mozillaPostalAddress2 instead of mozillaStreet2 |
187 | 187 | 'mozillaorgperson' => array( |
188 | 188 | 'adr_one_street2' => 'mozillapostaladdress2', |
189 | - 'adr_one_countrycode' => 'c', // 2 letter country code |
|
190 | - 'adr_one_countryname' => 'co', // human readable country name, must be after 'c' to take precedence on read! |
|
189 | + 'adr_one_countrycode' => 'c', // 2 letter country code |
|
190 | + 'adr_one_countryname' => 'co', // human readable country name, must be after 'c' to take precedence on read! |
|
191 | 191 | 'adr_two_street' => 'mozillahomestreet', |
192 | 192 | 'adr_two_street2' => 'mozillahomepostaladdress2', |
193 | 193 | 'adr_two_locality' => 'mozillahomelocalityname', |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | 'note' => 'note', |
214 | 214 | 'tel_car' => 'carphone', |
215 | 215 | 'tel_prefer' => 'primaryphone', |
216 | - 'cat_id' => 'category', // special handling in _egw2evolutionperson method |
|
216 | + 'cat_id' => 'category', // special handling in _egw2evolutionperson method |
|
217 | 217 | 'role' => 'businessrole', |
218 | 218 | 'tel_assistent' => 'assistantphone', |
219 | 219 | 'assistent' => 'assistantname', |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | 'freebusy_uri' => 'freeBusyuri', |
223 | 223 | 'calendar_uri' => 'calendaruri', |
224 | 224 | 'tel_other' => 'otherphone', |
225 | - 'tel_cell_private' => 'callbackphone', // not the best choice, but better then nothing |
|
225 | + 'tel_cell_private' => 'callbackphone', // not the best choice, but better then nothing |
|
226 | 226 | ), |
227 | 227 | // additional schema can be added here, including special functions |
228 | 228 | |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server'] |
271 | 271 | * @param resource $ds =null ldap connection to use |
272 | 272 | */ |
273 | - function __construct(array $ldap_config=null, $ds=null) |
|
273 | + function __construct(array $ldap_config = null, $ds = null) |
|
274 | 274 | { |
275 | 275 | //$this->db_data_cols = $this->stock_contact_fields + $this->non_contact_fields; |
276 | - $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
276 | + $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
277 | 277 | |
278 | 278 | if ($ldap_config) |
279 | 279 | { |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | } |
282 | 282 | else |
283 | 283 | { |
284 | - $this->ldap_config =& $GLOBALS['egw_info']['server']; |
|
284 | + $this->ldap_config = & $GLOBALS['egw_info']['server']; |
|
285 | 285 | } |
286 | 286 | $this->accountContactsDN = $this->ldap_config['ldap_context']; |
287 | - $this->allContactsDN = $this->ldap_config['ldap_contact_context']; |
|
288 | - $this->personalContactsDN = 'ou=personal,ou=contacts,'. $this->allContactsDN; |
|
289 | - $this->sharedContactsDN = 'ou=shared,ou=contacts,'. $this->allContactsDN; |
|
287 | + $this->allContactsDN = $this->ldap_config['ldap_contact_context']; |
|
288 | + $this->personalContactsDN = 'ou=personal,ou=contacts,'.$this->allContactsDN; |
|
289 | + $this->sharedContactsDN = 'ou=shared,ou=contacts,'.$this->allContactsDN; |
|
290 | 290 | |
291 | 291 | if ($ds) |
292 | 292 | { |
@@ -298,9 +298,9 @@ discard block |
||
298 | 298 | } |
299 | 299 | $this->ldapServerInfo = $GLOBALS['egw']->ldap->getLDAPServerInfo($this->ldap_config['ldap_contact_host']); |
300 | 300 | |
301 | - foreach($this->schema2egw as $attributes) |
|
301 | + foreach ($this->schema2egw as $attributes) |
|
302 | 302 | { |
303 | - $this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); |
|
303 | + $this->all_attributes = array_merge($this->all_attributes, array_values($attributes)); |
|
304 | 304 | } |
305 | 305 | $this->all_attributes = array_values(array_unique($this->all_attributes)); |
306 | 306 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $this->ds = Api\Ldap::factory(); |
328 | 328 | } |
329 | 329 | // if ldap is NOT the contact repository, we only do accounts and need to use the account-data |
330 | - elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') // not (ldap or sql-ldap) |
|
330 | + elseif (substr($GLOBALS['egw_info']['server']['contact_repository'], -4) != 'ldap') // not (ldap or sql-ldap) |
|
331 | 331 | { |
332 | 332 | $this->ldap_config['ldap_contact_host'] = $this->ldap_config['ldap_host']; |
333 | 333 | $this->allContactsDN = $this->ldap_config['ldap_context']; |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | function supported_fields() |
352 | 352 | { |
353 | 353 | $fields = array( |
354 | - 'id','tid','owner', |
|
355 | - 'n_middle','n_prefix','n_suffix', // stored in the cn |
|
356 | - 'created','modified', // automatic timestamps |
|
357 | - 'creator','modifier', // automatic for non accounts |
|
358 | - 'private', // true for personal addressbooks, false otherwise |
|
354 | + 'id', 'tid', 'owner', |
|
355 | + 'n_middle', 'n_prefix', 'n_suffix', // stored in the cn |
|
356 | + 'created', 'modified', // automatic timestamps |
|
357 | + 'creator', 'modifier', // automatic for non accounts |
|
358 | + 'private', // true for personal addressbooks, false otherwise |
|
359 | 359 | ); |
360 | - foreach($this->schema2egw as $objectclass => $mapping) |
|
360 | + foreach ($this->schema2egw as $objectclass => $mapping) |
|
361 | 361 | { |
362 | - if($this->ldapServerInfo->supportsObjectClass($objectclass)) |
|
362 | + if ($this->ldapServerInfo->supportsObjectClass($objectclass)) |
|
363 | 363 | { |
364 | - $fields = array_merge($fields,array_keys($mapping)); |
|
364 | + $fields = array_merge($fields, array_keys($mapping)); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | return array_values(array_unique($fields)); |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | return $this->id_filter(is_array($ids) ? array_shift($ids) : $ids); |
392 | 392 | } |
393 | 393 | $filter = array(); |
394 | - foreach($ids as $id) |
|
394 | + foreach ($ids as $id) |
|
395 | 395 | { |
396 | 396 | $filter[] = $this->id_filter($id); |
397 | 397 | } |
@@ -407,9 +407,9 @@ discard block |
||
407 | 407 | function read($contact_id) |
408 | 408 | { |
409 | 409 | if (is_array($contact_id) && isset($contact_id['account_id']) || |
410 | - !is_array($contact_id) && substr($contact_id,0,8) == 'account:') |
|
410 | + !is_array($contact_id) && substr($contact_id, 0, 8) == 'account:') |
|
411 | 411 | { |
412 | - $filter = 'uidNumber='.(int)(is_array($contact_id) ? $contact_id['account_id'] : substr($contact_id,8)); |
|
412 | + $filter = 'uidNumber='.(int)(is_array($contact_id) ? $contact_id['account_id'] : substr($contact_id, 8)); |
|
413 | 413 | } |
414 | 414 | else |
415 | 415 | { |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | // never allow to change the uidNumber (account_id) on update, as it could be misused by eg. xmlrpc or syncml |
433 | 433 | unset($ldapContact['uidnumber']); |
434 | 434 | |
435 | - unset($ldapContact['entryuuid']); // not allowed to modify that, no need either |
|
435 | + unset($ldapContact['entryuuid']); // not allowed to modify that, no need either |
|
436 | 436 | |
437 | 437 | unset($ldapContact['objectClass']); |
438 | 438 | } |
@@ -443,28 +443,28 @@ discard block |
||
443 | 443 | * @param array $keys if given $keys are copied to data before saveing => allows a save as |
444 | 444 | * @return int 0 on success and errno != 0 else |
445 | 445 | */ |
446 | - function save($keys=null) |
|
446 | + function save($keys = null) |
|
447 | 447 | { |
448 | 448 | //error_log(__METHOD__."(".array2string($keys).") this->data=".array2string($this->data)); |
449 | - if(is_array($keys)) |
|
449 | + if (is_array($keys)) |
|
450 | 450 | { |
451 | - $this->data = is_array($this->data) ? array_merge($this->data,$keys) : $keys; |
|
451 | + $this->data = is_array($this->data) ? array_merge($this->data, $keys) : $keys; |
|
452 | 452 | } |
453 | 453 | |
454 | - $data =& $this->data; |
|
454 | + $data = & $this->data; |
|
455 | 455 | $isUpdate = false; |
456 | 456 | $ldapContact = array(); |
457 | 457 | |
458 | 458 | // generate addressbook dn |
459 | - if((int)$data['owner']) |
|
459 | + if ((int)$data['owner']) |
|
460 | 460 | { |
461 | 461 | // group address book |
462 | - if(!($cn = strtolower($GLOBALS['egw']->accounts->id2name((int)$data['owner'])))) |
|
462 | + if (!($cn = strtolower($GLOBALS['egw']->accounts->id2name((int)$data['owner'])))) |
|
463 | 463 | { |
464 | 464 | error_log('Unknown owner'); |
465 | 465 | return true; |
466 | 466 | } |
467 | - $baseDN = 'cn='. $cn .','.($data['owner'] < 0 ? $this->sharedContactsDN : $this->personalContactsDN); |
|
467 | + $baseDN = 'cn='.$cn.','.($data['owner'] < 0 ? $this->sharedContactsDN : $this->personalContactsDN); |
|
468 | 468 | } |
469 | 469 | // only an admin or the user itself is allowed to change the data of an account |
470 | 470 | elseif ($data['account_id'] && ($GLOBALS['egw_info']['user']['apps']['admin'] || |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | { |
473 | 473 | // account |
474 | 474 | $baseDN = $this->accountContactsDN; |
475 | - $cn = false; |
|
475 | + $cn = false; |
|
476 | 476 | // we need an admin connection |
477 | 477 | $this->connect(true); |
478 | 478 | |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | else |
486 | 486 | { |
487 | 487 | error_log("Permission denied, to write: data[owner]=$data[owner], data[account_id]=$data[account_id], account_id=".$GLOBALS['egw_info']['user']['account_id']); |
488 | - return lang('Permission denied !!!'); // only admin or the user itself is allowd to write accounts! |
|
488 | + return lang('Permission denied !!!'); // only admin or the user itself is allowd to write accounts! |
|
489 | 489 | } |
490 | 490 | // check if $baseDN exists. If not create it |
491 | 491 | if (($err = $this->_check_create_dn($baseDN))) |
@@ -494,55 +494,54 @@ discard block |
||
494 | 494 | } |
495 | 495 | // check the existing objectclasses of an entry, none = array() for new ones |
496 | 496 | $oldObjectclasses = array(); |
497 | - $attributes = array('dn','cn','objectClass',$this->dn_attribute,'mail'); |
|
497 | + $attributes = array('dn', 'cn', 'objectClass', $this->dn_attribute, 'mail'); |
|
498 | 498 | |
499 | 499 | $contactUID = $this->data[$this->contacts_id]; |
500 | 500 | if (!empty($contactUID) && |
501 | - ($result = ldap_search($this->ds, $base=$this->allContactsDN, $this->id_filter($contactUID), $attributes)) && |
|
501 | + ($result = ldap_search($this->ds, $base = $this->allContactsDN, $this->id_filter($contactUID), $attributes)) && |
|
502 | 502 | ($oldContactInfo = ldap_get_entries($this->ds, $result)) && $oldContactInfo['count']) |
503 | 503 | { |
504 | 504 | unset($oldContactInfo[0]['objectclass']['count']); |
505 | - foreach($oldContactInfo[0]['objectclass'] as $objectclass) |
|
505 | + foreach ($oldContactInfo[0]['objectclass'] as $objectclass) |
|
506 | 506 | { |
507 | - $oldObjectclasses[] = strtolower($objectclass); |
|
507 | + $oldObjectclasses[] = strtolower($objectclass); |
|
508 | 508 | } |
509 | 509 | $isUpdate = true; |
510 | 510 | } |
511 | 511 | |
512 | - if(empty($contactUID)) |
|
512 | + if (empty($contactUID)) |
|
513 | 513 | { |
514 | 514 | $ldapContact[$this->dn_attribute] = $this->data[$this->contacts_id] = $contactUID = md5(Api\Auth::randomstring(15)); |
515 | 515 | } |
516 | 516 | //error_log(__METHOD__."() contactUID='$contactUID', isUpdate=".array2string($isUpdate).", oldContactInfo=".array2string($oldContactInfo)); |
517 | 517 | // add for all supported objectclasses the objectclass and it's attributes |
518 | - foreach($this->schema2egw as $objectclass => $mapping) |
|
518 | + foreach ($this->schema2egw as $objectclass => $mapping) |
|
519 | 519 | { |
520 | - if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue; |
|
520 | + if (!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue; |
|
521 | 521 | |
522 | - if($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses)) |
|
522 | + if ($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses)) |
|
523 | 523 | { |
524 | 524 | $ldapContact['objectClass'][] = $objectclass; |
525 | 525 | } |
526 | 526 | if (isset($this->required_subs[$objectclass])) |
527 | 527 | { |
528 | - foreach($this->required_subs[$objectclass] as $sub) |
|
528 | + foreach ($this->required_subs[$objectclass] as $sub) |
|
529 | 529 | { |
530 | - if(!in_array($sub, $oldObjectclasses)) |
|
530 | + if (!in_array($sub, $oldObjectclasses)) |
|
531 | 531 | { |
532 | 532 | $ldapContact['objectClass'][] = $sub; |
533 | 533 | } |
534 | 534 | } |
535 | 535 | } |
536 | - foreach($mapping as $egwFieldName => $ldapFieldName) |
|
536 | + foreach ($mapping as $egwFieldName => $ldapFieldName) |
|
537 | 537 | { |
538 | 538 | if (is_int($egwFieldName)) continue; |
539 | - if(!empty($data[$egwFieldName])) |
|
539 | + if (!empty($data[$egwFieldName])) |
|
540 | 540 | { |
541 | 541 | // dont convert the (binary) jpegPhoto! |
542 | - $ldapContact[$ldapFieldName] = $ldapFieldName == 'jpegphoto' ? $data[$egwFieldName] : |
|
543 | - Api\Translation::convert(trim($data[$egwFieldName]),$this->charset,'utf-8'); |
|
542 | + $ldapContact[$ldapFieldName] = $ldapFieldName == 'jpegphoto' ? $data[$egwFieldName] : Api\Translation::convert(trim($data[$egwFieldName]), $this->charset, 'utf-8'); |
|
544 | 543 | } |
545 | - elseif($isUpdate && isset($data[$egwFieldName])) |
|
544 | + elseif ($isUpdate && isset($data[$egwFieldName])) |
|
546 | 545 | { |
547 | 546 | $ldapContact[$ldapFieldName] = array(); |
548 | 547 | } |
@@ -550,9 +549,9 @@ discard block |
||
550 | 549 | } |
551 | 550 | // handling of special attributes, like cat_id in evolutionPerson |
552 | 551 | $egw2objectclass = '_egw2'.$objectclass; |
553 | - if (method_exists($this,$egw2objectclass)) |
|
552 | + if (method_exists($this, $egw2objectclass)) |
|
554 | 553 | { |
555 | - $this->$egw2objectclass($ldapContact,$data,$isUpdate); |
|
554 | + $this->$egw2objectclass($ldapContact, $data, $isUpdate); |
|
556 | 555 | } |
557 | 556 | } |
558 | 557 | if ($isUpdate) |
@@ -570,11 +569,11 @@ discard block |
||
570 | 569 | $needRecreation = false; |
571 | 570 | |
572 | 571 | // add missing objectclasses |
573 | - if($ldapContact['objectClass'] && ($missing=array_diff($ldapContact['objectClass'],$oldObjectclasses))) |
|
572 | + if ($ldapContact['objectClass'] && ($missing = array_diff($ldapContact['objectClass'], $oldObjectclasses))) |
|
574 | 573 | { |
575 | 574 | if (!@ldap_mod_add($this->ds, $dn, array('objectClass' => $ldapContact['objectClass']))) |
576 | 575 | { |
577 | - if(in_array(ldap_errno($this->ds),array(69,20))) |
|
576 | + if (in_array(ldap_errno($this->ds), array(69, 20))) |
|
578 | 577 | { |
579 | 578 | // need to modify structural objectclass |
580 | 579 | $needRecreation = true; |
@@ -583,15 +582,15 @@ discard block |
||
583 | 582 | else |
584 | 583 | { |
585 | 584 | //echo "<p>ldap_mod_add($this->ds,'$dn',array(objectClass =>".print_r($ldapContact['objectClass'],true)."))</p>\n"; |
586 | - error_log(__METHOD__.'() '.__LINE__.' update of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .')'); |
|
585 | + error_log(__METHOD__.'() '.__LINE__.' update of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).')'); |
|
587 | 586 | return $this->_error(__LINE__); |
588 | 587 | } |
589 | 588 | } |
590 | 589 | } |
591 | 590 | |
592 | 591 | // check if we need to rename the DN or need to recreate the contact |
593 | - $newRDN = $this->dn_attribute.'='. $ldapContact[$this->dn_attribute]; |
|
594 | - $newDN = $newRDN .','. $baseDN; |
|
592 | + $newRDN = $this->dn_attribute.'='.$ldapContact[$this->dn_attribute]; |
|
593 | + $newDN = $newRDN.','.$baseDN; |
|
595 | 594 | if ($needRecreation) |
596 | 595 | { |
597 | 596 | $result = ldap_read($this->ds, $dn, 'objectclass=*'); |
@@ -602,20 +601,20 @@ discard block |
||
602 | 601 | $newContact = $oldContact; |
603 | 602 | $newContact[$this->dn_attribute] = $ldapContact[$this->dn_attribute]; |
604 | 603 | |
605 | - if(is_array($ldapContact['objectClass']) && count($ldapContact['objectClass']) > 0) |
|
604 | + if (is_array($ldapContact['objectClass']) && count($ldapContact['objectClass']) > 0) |
|
606 | 605 | { |
607 | - $newContact['objectclass'] = array_unique(array_map('strtolower', // objectclasses my have different case |
|
606 | + $newContact['objectclass'] = array_unique(array_map('strtolower', // objectclasses my have different case |
|
608 | 607 | array_merge($newContact['objectclass'], $ldapContact['objectClass']))); |
609 | 608 | } |
610 | 609 | |
611 | - if(!ldap_delete($this->ds, $dn)) |
|
610 | + if (!ldap_delete($this->ds, $dn)) |
|
612 | 611 | { |
613 | - error_log(__METHOD__.'() '.__LINE__.' delete of old '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .')'); |
|
612 | + error_log(__METHOD__.'() '.__LINE__.' delete of old '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).')'); |
|
614 | 613 | return $this->_error(__LINE__); |
615 | 614 | } |
616 | - if(!@ldap_add($this->ds, $newDN, $newContact)) |
|
615 | + if (!@ldap_add($this->ds, $newDN, $newContact)) |
|
617 | 616 | { |
618 | - error_log(__METHOD__.'() '.__LINE__.' re-create contact as '. $newDN .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') newContact='.array2string($newContact)); |
|
617 | + error_log(__METHOD__.'() '.__LINE__.' re-create contact as '.$newDN.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') newContact='.array2string($newContact)); |
|
619 | 618 | // if adding with new objectclass or dn fails, re-add deleted contact |
620 | 619 | @ldap_add($this->ds, $dn, $oldContact); |
621 | 620 | return $this->_error(__LINE__); |
@@ -644,22 +643,22 @@ discard block |
||
644 | 643 | |
645 | 644 | if (!@ldap_modify($this->ds, $dn, $ldapContact)) |
646 | 645 | { |
647 | - error_log(__METHOD__.'() '.__LINE__.' update of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') ldapContact='.array2string($ldapContact)); |
|
646 | + error_log(__METHOD__.'() '.__LINE__.' update of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') ldapContact='.array2string($ldapContact)); |
|
648 | 647 | return $this->_error(__LINE__); |
649 | 648 | } |
650 | 649 | } |
651 | 650 | else |
652 | 651 | { |
653 | - $dn = $this->dn_attribute.'='. $ldapContact[$this->dn_attribute] .','. $baseDN; |
|
654 | - unset($ldapContact['entryuuid']); // trying to write it, gives an error |
|
652 | + $dn = $this->dn_attribute.'='.$ldapContact[$this->dn_attribute].','.$baseDN; |
|
653 | + unset($ldapContact['entryuuid']); // trying to write it, gives an error |
|
655 | 654 | |
656 | 655 | if (!@ldap_add($this->ds, $dn, $ldapContact)) |
657 | 656 | { |
658 | - error_log(__METHOD__.'() '.__LINE__.' add of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') ldapContact='.array2string($ldapContact)); |
|
657 | + error_log(__METHOD__.'() '.__LINE__.' add of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') ldapContact='.array2string($ldapContact)); |
|
659 | 658 | return $this->_error(__LINE__); |
660 | 659 | } |
661 | 660 | } |
662 | - return 0; // Ok, no error |
|
661 | + return 0; // Ok, no error |
|
663 | 662 | } |
664 | 663 | |
665 | 664 | /** |
@@ -668,28 +667,28 @@ discard block |
||
668 | 667 | * @param array $keys if given array with col => value pairs to characterise the rows to delete |
669 | 668 | * @return int affected rows, should be 1 if ok, 0 if an error |
670 | 669 | */ |
671 | - function delete($keys=null) |
|
670 | + function delete($keys = null) |
|
672 | 671 | { |
673 | 672 | // single entry |
674 | - if($keys[$this->contacts_id]) $keys = array( 0 => $keys); |
|
673 | + if ($keys[$this->contacts_id]) $keys = array(0 => $keys); |
|
675 | 674 | |
676 | - if(!is_array($keys)) |
|
675 | + if (!is_array($keys)) |
|
677 | 676 | { |
678 | - $keys = array( $keys); |
|
677 | + $keys = array($keys); |
|
679 | 678 | } |
680 | 679 | |
681 | 680 | $ret = 0; |
682 | 681 | |
683 | 682 | $attributes = array('dn'); |
684 | 683 | |
685 | - foreach($keys as $entry) |
|
684 | + foreach ($keys as $entry) |
|
686 | 685 | { |
687 | 686 | $entry = Api\Ldap::quote(is_array($entry) ? $entry['id'] : $entry); |
688 | - if(($result = ldap_search($this->ds, $this->allContactsDN, |
|
687 | + if (($result = ldap_search($this->ds, $this->allContactsDN, |
|
689 | 688 | "(|(entryUUID=$entry)(uid=$entry))", $attributes))) |
690 | 689 | { |
691 | 690 | $contactInfo = ldap_get_entries($this->ds, $result); |
692 | - if(@ldap_delete($this->ds, $contactInfo[0]['dn'])) |
|
691 | + if (@ldap_delete($this->ds, $contactInfo[0]['dn'])) |
|
693 | 692 | { |
694 | 693 | $ret++; |
695 | 694 | } |
@@ -717,10 +716,10 @@ discard block |
||
717 | 716 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
718 | 717 | * @return array of matching rows (the row is an array of the cols) or False |
719 | 718 | */ |
720 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) |
|
719 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false) |
|
721 | 720 | { |
722 | 721 | //error_log(__METHOD__."(".array2string($criteria).", ".array2string($only_keys).", '$order_by', ".array2string($extra_cols).", '$wildcard', '$empty', '$op', ".array2string($start).", ".array2string($filter).")"); |
723 | - unset($only_keys, $extra_cols, $empty, $join, $need_full_no_count); // not used, but required by function signature |
|
722 | + unset($only_keys, $extra_cols, $empty, $join, $need_full_no_count); // not used, but required by function signature |
|
724 | 723 | |
725 | 724 | if (is_array($filter['owner'])) |
726 | 725 | { |
@@ -742,7 +741,7 @@ discard block |
||
742 | 741 | 'created' => 'createtimestamp', |
743 | 742 | 'modified' => 'modifytimestamp', |
744 | 743 | ); |
745 | - foreach($filter as $key => $value) |
|
744 | + foreach ($filter as $key => $value) |
|
746 | 745 | { |
747 | 746 | $matches = null; |
748 | 747 | if (is_int($key) && preg_match('/^(contact_)?(modified|created)([<=>]+)([0-9]+)$/', $value, $matches)) |
@@ -758,11 +757,11 @@ discard block |
||
758 | 757 | } |
759 | 758 | } |
760 | 759 | |
761 | - if((int)$filter['owner']) |
|
760 | + if ((int)$filter['owner']) |
|
762 | 761 | { |
763 | 762 | if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) return false; |
764 | 763 | |
765 | - $searchDN = 'cn='. Api\Ldap::quote(strtolower($accountName)) .','; |
|
764 | + $searchDN = 'cn='.Api\Ldap::quote(strtolower($accountName)).','; |
|
766 | 765 | |
767 | 766 | if ($filter['owner'] < 0) |
768 | 767 | { |
@@ -786,7 +785,7 @@ discard block |
||
786 | 785 | $addressbookType = self::ACCOUNTS; |
787 | 786 | } |
788 | 787 | // create the search filter |
789 | - switch($addressbookType) |
|
788 | + switch ($addressbookType) |
|
790 | 789 | { |
791 | 790 | case self::ACCOUNTS: |
792 | 791 | $objectFilter = $this->accountsFilter; |
@@ -801,28 +800,28 @@ discard block |
||
801 | 800 | // shadowExpire>= does NOT work, as shadow schema only specifies integerMatch and not integerOrderingMatch :-( |
802 | 801 | |
803 | 802 | $searchFilter = ''; |
804 | - if(is_array($criteria) && count($criteria) > 0) |
|
803 | + if (is_array($criteria) && count($criteria) > 0) |
|
805 | 804 | { |
806 | 805 | $wildcard = $wildcard === '%' ? '*' : ''; |
807 | 806 | $searchFilter = ''; |
808 | - foreach($criteria as $egwSearchKey => $searchValue) |
|
807 | + foreach ($criteria as $egwSearchKey => $searchValue) |
|
809 | 808 | { |
810 | - if (in_array($egwSearchKey, array('id','contact_id'))) |
|
809 | + if (in_array($egwSearchKey, array('id', 'contact_id'))) |
|
811 | 810 | { |
812 | 811 | $searchFilter .= $this->ids_filter($searchValue); |
813 | 812 | continue; |
814 | 813 | } |
815 | - foreach($this->schema2egw as $mapping) |
|
814 | + foreach ($this->schema2egw as $mapping) |
|
816 | 815 | { |
817 | - if(($ldapSearchKey = $mapping[$egwSearchKey])) |
|
816 | + if (($ldapSearchKey = $mapping[$egwSearchKey])) |
|
818 | 817 | { |
819 | - $searchString = Api\Translation::convert($searchValue,$this->charset,'utf-8'); |
|
818 | + $searchString = Api\Translation::convert($searchValue, $this->charset, 'utf-8'); |
|
820 | 819 | $searchFilter .= '('.$ldapSearchKey.'='.$wildcard.Api\Ldap::quote($searchString).$wildcard.')'; |
821 | 820 | break; |
822 | 821 | } |
823 | 822 | } |
824 | 823 | } |
825 | - if($op == 'AND') |
|
824 | + if ($op == 'AND') |
|
826 | 825 | { |
827 | 826 | $searchFilter = "(&$searchFilter)"; |
828 | 827 | } |
@@ -841,9 +840,9 @@ discard block |
||
841 | 840 | // only return certain owners --> unset not matching ones |
842 | 841 | if ($owner_filter) |
843 | 842 | { |
844 | - foreach($rows as $k => $row) |
|
843 | + foreach ($rows as $k => $row) |
|
845 | 844 | { |
846 | - if (!in_array($row['owner'],$owner_filter)) |
|
845 | + if (!in_array($row['owner'], $owner_filter)) |
|
847 | 846 | { |
848 | 847 | unset($rows[$k]); |
849 | 848 | --$this->total; |
@@ -854,36 +853,36 @@ discard block |
||
854 | 853 | { |
855 | 854 | $order = array(); |
856 | 855 | $sort = 'ASC'; |
857 | - foreach(explode(',',$order_by) as $o) |
|
856 | + foreach (explode(',', $order_by) as $o) |
|
858 | 857 | { |
859 | - if (substr($o,0,8) == 'contact_') $o = substr($o,8); |
|
860 | - if (substr($o,-4) == ' ASC') |
|
858 | + if (substr($o, 0, 8) == 'contact_') $o = substr($o, 8); |
|
859 | + if (substr($o, -4) == ' ASC') |
|
861 | 860 | { |
862 | 861 | $sort = 'ASC'; |
863 | - $order[] = substr($o,0,-4); |
|
862 | + $order[] = substr($o, 0, -4); |
|
864 | 863 | } |
865 | - elseif (substr($o,-5) == ' DESC') |
|
864 | + elseif (substr($o, -5) == ' DESC') |
|
866 | 865 | { |
867 | 866 | $sort = 'DESC'; |
868 | - $order[] = substr($o,0,-5); |
|
867 | + $order[] = substr($o, 0, -5); |
|
869 | 868 | } |
870 | 869 | elseif ($o) |
871 | 870 | { |
872 | 871 | $order[] = $o; |
873 | 872 | } |
874 | 873 | } |
875 | - $rows = ExecMethod2('phpgwapi.arrayfunctions.arfsort',$rows,$order,$sort); |
|
874 | + $rows = ExecMethod2('phpgwapi.arrayfunctions.arfsort', $rows, $order, $sort); |
|
876 | 875 | } |
877 | 876 | // if requested ($start !== false) return only limited resultset |
878 | 877 | if (is_array($start)) |
879 | 878 | { |
880 | - list($start,$offset) = $start; |
|
879 | + list($start, $offset) = $start; |
|
881 | 880 | } |
882 | - if(is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
881 | + if (is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
883 | 882 | { |
884 | 883 | return array_slice($rows, $start, $offset); |
885 | 884 | } |
886 | - elseif(is_numeric($start)) |
|
885 | + elseif (is_numeric($start)) |
|
887 | 886 | { |
888 | 887 | return array_slice($rows, $start, $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']); |
889 | 888 | } |
@@ -901,11 +900,11 @@ discard block |
||
901 | 900 | if (!is_array($filter)) return ''; |
902 | 901 | |
903 | 902 | $filters = ''; |
904 | - foreach($filter as $key => $value) |
|
903 | + foreach ($filter as $key => $value) |
|
905 | 904 | { |
906 | 905 | if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
907 | 906 | |
908 | - switch((string) $key) |
|
907 | + switch ((string)$key) |
|
909 | 908 | { |
910 | 909 | case 'owner': // already handled |
911 | 910 | case 'tid': // ignored |
@@ -928,7 +927,7 @@ discard block |
||
928 | 927 | { |
929 | 928 | $filters .= '(!(category=*))'; |
930 | 929 | } |
931 | - elseif((int)$value) |
|
930 | + elseif ((int)$value) |
|
932 | 931 | { |
933 | 932 | if (!is_object($GLOBALS['egw']->categories)) |
934 | 933 | { |
@@ -936,10 +935,10 @@ discard block |
||
936 | 935 | } |
937 | 936 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
938 | 937 | if (count($cats) > 1) $filters .= '(|'; |
939 | - foreach($cats as $cat) |
|
938 | + foreach ($cats as $cat) |
|
940 | 939 | { |
941 | 940 | $catName = Api\Translation::convert( |
942 | - $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
|
941 | + $GLOBALS['egw']->categories->id2name($cat), $this->charset, 'utf-8'); |
|
943 | 942 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
944 | 943 | } |
945 | 944 | if (count($cats) > 1) $filters .= ')'; |
@@ -948,7 +947,7 @@ discard block |
||
948 | 947 | |
949 | 948 | case 'carddav_name': |
950 | 949 | if (!is_array($value)) $value = array($value); |
951 | - foreach($value as &$v) |
|
950 | + foreach ($value as &$v) |
|
952 | 951 | { |
953 | 952 | $v = basename($v, '.vcf'); |
954 | 953 | } |
@@ -962,28 +961,27 @@ discard block |
||
962 | 961 | $matches = null; |
963 | 962 | if (!is_int($key)) |
964 | 963 | { |
965 | - foreach($this->schema2egw as $mapping) |
|
964 | + foreach ($this->schema2egw as $mapping) |
|
966 | 965 | { |
967 | 966 | if (isset($mapping[$key])) |
968 | 967 | { |
969 | 968 | // todo: value = "!''" |
970 | - $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : |
|
971 | - Api\Ldap::quote(Api\Translation::convert($value,$this->charset,'utf-8'))).')'; |
|
969 | + $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : Api\Ldap::quote(Api\Translation::convert($value, $this->charset, 'utf-8'))).')'; |
|
972 | 970 | break; |
973 | 971 | } |
974 | 972 | } |
975 | 973 | } |
976 | 974 | // filter for letter-search |
977 | - elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
|
975 | + elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/", $value, $matches)) |
|
978 | 976 | { |
979 | - list(,$name,$value) = $matches; |
|
980 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
981 | - foreach($this->schema2egw as $mapping) |
|
977 | + list(,$name, $value) = $matches; |
|
978 | + if (strpos($name, '.') !== false) list(,$name) = explode('.', $name); |
|
979 | + foreach ($this->schema2egw as $mapping) |
|
982 | 980 | { |
983 | 981 | if (isset($mapping[$name])) |
984 | 982 | { |
985 | 983 | $filters .= '('.$mapping[$name].'='.Api\Ldap::quote( |
986 | - Api\Translation::convert($value,$this->charset,'utf-8')).'*)'; |
|
984 | + Api\Translation::convert($value, $this->charset, 'utf-8')).'*)'; |
|
987 | 985 | break; |
988 | 986 | } |
989 | 987 | } |
@@ -1007,7 +1005,7 @@ discard block |
||
1007 | 1005 | * @param array $_skipPlugins =null schema-plugins to skip |
1008 | 1006 | * @return array/boolean with eGW contacts or false on error |
1009 | 1007 | */ |
1010 | - function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null) |
|
1008 | + function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins = null) |
|
1011 | 1009 | { |
1012 | 1010 | $this->total = 0; |
1013 | 1011 | |
@@ -1020,7 +1018,7 @@ discard block |
||
1020 | 1018 | |
1021 | 1019 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype)"); |
1022 | 1020 | |
1023 | - if($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1021 | + if ($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1024 | 1022 | { |
1025 | 1023 | $result = ldap_search($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1026 | 1024 | } |
@@ -1028,36 +1026,36 @@ discard block |
||
1028 | 1026 | { |
1029 | 1027 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1030 | 1028 | } |
1031 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1029 | + if (!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1032 | 1030 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1033 | 1031 | |
1034 | 1032 | $this->total = $entries['count']; |
1035 | - foreach($entries as $i => $entry) |
|
1033 | + foreach ($entries as $i => $entry) |
|
1036 | 1034 | { |
1037 | - if (!is_int($i)) continue; // eg. count |
|
1035 | + if (!is_int($i)) continue; // eg. count |
|
1038 | 1036 | |
1039 | 1037 | $contact = array( |
1040 | 1038 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
1041 | - 'tid' => 'n', // the type id for the addressbook |
|
1039 | + 'tid' => 'n', // the type id for the addressbook |
|
1042 | 1040 | ); |
1043 | - foreach($entry['objectclass'] as $ii => $objectclass) |
|
1041 | + foreach ($entry['objectclass'] as $ii => $objectclass) |
|
1044 | 1042 | { |
1045 | 1043 | $objectclass = strtolower($objectclass); |
1046 | 1044 | if (!is_int($ii) || !isset($this->schema2egw[$objectclass])) |
1047 | 1045 | { |
1048 | - continue; // eg. count or unsupported objectclass |
|
1046 | + continue; // eg. count or unsupported objectclass |
|
1049 | 1047 | } |
1050 | - foreach($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1048 | + foreach ($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1051 | 1049 | { |
1052 | - if(!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1050 | + if (!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1053 | 1051 | { |
1054 | - $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0],'utf-8'); |
|
1052 | + $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0], 'utf-8'); |
|
1055 | 1053 | } |
1056 | 1054 | } |
1057 | 1055 | $objectclass2egw = '_'.$objectclass.'2egw'; |
1058 | - if (!in_array($objectclass2egw, (array)$_skipPlugins) &&method_exists($this,$objectclass2egw)) |
|
1056 | + if (!in_array($objectclass2egw, (array)$_skipPlugins) && method_exists($this, $objectclass2egw)) |
|
1059 | 1057 | { |
1060 | - if (($ret=$this->$objectclass2egw($contact,$entry)) === false) |
|
1058 | + if (($ret = $this->$objectclass2egw($contact, $entry)) === false) |
|
1061 | 1059 | { |
1062 | 1060 | --$this->total; |
1063 | 1061 | continue 2; |
@@ -1067,20 +1065,20 @@ discard block |
||
1067 | 1065 | // read binary jpegphoto only for one result == call by read |
1068 | 1066 | if ($this->total == 1 && isset($entry['jpegphoto'][0])) |
1069 | 1067 | { |
1070 | - $bin = ldap_get_values_len($this->ds,ldap_first_entry($this->ds,$result),'jpegphoto'); |
|
1068 | + $bin = ldap_get_values_len($this->ds, ldap_first_entry($this->ds, $result), 'jpegphoto'); |
|
1071 | 1069 | $contact['jpegphoto'] = $bin[0]; |
1072 | 1070 | } |
1073 | 1071 | $matches = null; |
1074 | - if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1072 | + if (preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1075 | 1073 | { |
1076 | 1074 | // personal addressbook |
1077 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','u'); |
|
1075 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'u'); |
|
1078 | 1076 | $contact['private'] = 0; |
1079 | 1077 | } |
1080 | - elseif(preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1078 | + elseif (preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1081 | 1079 | { |
1082 | 1080 | // group addressbook |
1083 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','g'); |
|
1081 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g'); |
|
1084 | 1082 | $contact['private'] = 0; |
1085 | 1083 | } |
1086 | 1084 | else |
@@ -1089,12 +1087,12 @@ discard block |
||
1089 | 1087 | $contact['owner'] = 0; |
1090 | 1088 | $contact['private'] = 0; |
1091 | 1089 | } |
1092 | - foreach(array( |
|
1090 | + foreach (array( |
|
1093 | 1091 | 'createtimestamp' => 'created', |
1094 | 1092 | 'modifytimestamp' => 'modified', |
1095 | 1093 | ) as $ldapFieldName => $egwFieldName) |
1096 | 1094 | { |
1097 | - if(!empty($entry[$ldapFieldName][0])) |
|
1095 | + if (!empty($entry[$ldapFieldName][0])) |
|
1098 | 1096 | { |
1099 | 1097 | $contact[$egwFieldName] = $this->_ldap2ts($entry[$ldapFieldName][0]); |
1100 | 1098 | } |
@@ -1113,8 +1111,8 @@ discard block |
||
1113 | 1111 | */ |
1114 | 1112 | static function _ldap2ts($date) |
1115 | 1113 | { |
1116 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
1117 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
1114 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
1115 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
1118 | 1116 | } |
1119 | 1117 | |
1120 | 1118 | /** |
@@ -1137,22 +1135,22 @@ discard block |
||
1137 | 1135 | function _check_create_dn($baseDN) |
1138 | 1136 | { |
1139 | 1137 | // check if $baseDN exists. If not create new one |
1140 | - if(@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1138 | + if (@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1141 | 1139 | { |
1142 | 1140 | return false; |
1143 | 1141 | } |
1144 | 1142 | //error_log(__METHOD__."('$baseDN') !ldap_read({$this->ds}, '$baseDN', 'objectclass=*') ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds).get_class($this)); |
1145 | - if(ldap_errno($this->ds) != 32 || substr($baseDN,0,3) != 'cn=') |
|
1143 | + if (ldap_errno($this->ds) != 32 || substr($baseDN, 0, 3) != 'cn=') |
|
1146 | 1144 | { |
1147 | 1145 | error_log(__METHOD__."('$baseDN') baseDN does NOT exist and we cant/wont create it! ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds)); |
1148 | - return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1146 | + return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1149 | 1147 | } |
1150 | 1148 | // create a admin connection to add the needed DN |
1151 | 1149 | $adminLDAP = new ldap; |
1152 | 1150 | $adminDS = $adminLDAP->ldapConnect(); |
1153 | 1151 | |
1154 | - list(,$ou) = explode(',',$baseDN); |
|
1155 | - foreach(array( |
|
1152 | + list(,$ou) = explode(',', $baseDN); |
|
1153 | + foreach (array( |
|
1156 | 1154 | 'ou=contacts,'.$this->allContactsDN, |
1157 | 1155 | $ou.',ou=contacts,'.$this->allContactsDN, |
1158 | 1156 | $baseDN, |
@@ -1161,16 +1159,16 @@ discard block |
||
1161 | 1159 | if (!@ldap_read($this->ds, $dn, 'objectclass=*') && ldap_errno($this->ds) == 32) |
1162 | 1160 | { |
1163 | 1161 | // entry does not exist, lets try to create it |
1164 | - list($top) = explode(',',$dn); |
|
1165 | - list($var,$val) = explode('=',$top); |
|
1162 | + list($top) = explode(',', $dn); |
|
1163 | + list($var, $val) = explode('=', $top); |
|
1166 | 1164 | $data = array( |
1167 | 1165 | 'objectClass' => $var == 'cn' ? 'organizationalRole' : 'organizationalUnit', |
1168 | 1166 | $var => $val, |
1169 | 1167 | ); |
1170 | - if(!@ldap_add($adminDS, $dn, $data)) |
|
1168 | + if (!@ldap_add($adminDS, $dn, $data)) |
|
1171 | 1169 | { |
1172 | 1170 | //echo "<p>ldap_add($adminDS,'$dn',".print_r($data,true).")</p>\n"; |
1173 | - $err = lang("Can't create dn %1",$dn).': '.$this->_error(__LINE__,$adminDS); |
|
1171 | + $err = lang("Can't create dn %1", $dn).': '.$this->_error(__LINE__, $adminDS); |
|
1174 | 1172 | $adminLDAP->ldapDisconnect(); |
1175 | 1173 | return $err; |
1176 | 1174 | } |
@@ -1187,7 +1185,7 @@ discard block |
||
1187 | 1185 | * @param int $line |
1188 | 1186 | * @return string |
1189 | 1187 | */ |
1190 | - function _error($line,$ds=null) |
|
1188 | + function _error($line, $ds = null) |
|
1191 | 1189 | { |
1192 | 1190 | return ldap_error($ds ? $ds : $this->ds).': '.__CLASS__.': '.$line; |
1193 | 1191 | } |
@@ -1202,27 +1200,27 @@ discard block |
||
1202 | 1200 | * @param array $data eGW contact data |
1203 | 1201 | * @param boolean $isUpdate |
1204 | 1202 | */ |
1205 | - function _egw2evolutionperson(&$ldapContact,$data,$isUpdate) |
|
1203 | + function _egw2evolutionperson(&$ldapContact, $data, $isUpdate) |
|
1206 | 1204 | { |
1207 | - if(!empty($data['cat_id'])) |
|
1205 | + if (!empty($data['cat_id'])) |
|
1208 | 1206 | { |
1209 | 1207 | $ldapContact['category'] = array(); |
1210 | - foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id']) as $cat) |
|
1208 | + foreach (is_array($data['cat_id']) ? $data['cat_id'] : explode(',', $data['cat_id']) as $cat) |
|
1211 | 1209 | { |
1212 | 1210 | $ldapContact['category'][] = Api\Translation::convert( |
1213 | - Api\Categories::id2name($cat),$this->charset,'utf-8'); |
|
1211 | + Api\Categories::id2name($cat), $this->charset, 'utf-8'); |
|
1214 | 1212 | } |
1215 | 1213 | } |
1216 | - foreach(array( |
|
1217 | - 'postaladdress' => $data['adr_one_street'] .'$'. $data['adr_one_locality'] .', '. $data['adr_one_region'] .'$'. $data['adr_one_postalcode'] .'$$'. $data['adr_one_countryname'], |
|
1218 | - 'homepostaladdress' => $data['adr_two_street'] .'$'. $data['adr_two_locality'] .', '. $data['adr_two_region'] .'$'. $data['adr_two_postalcode'] .'$$'. $data['adr_two_countryname'], |
|
1214 | + foreach (array( |
|
1215 | + 'postaladdress' => $data['adr_one_street'].'$'.$data['adr_one_locality'].', '.$data['adr_one_region'].'$'.$data['adr_one_postalcode'].'$$'.$data['adr_one_countryname'], |
|
1216 | + 'homepostaladdress' => $data['adr_two_street'].'$'.$data['adr_two_locality'].', '.$data['adr_two_region'].'$'.$data['adr_two_postalcode'].'$$'.$data['adr_two_countryname'], |
|
1219 | 1217 | ) as $attr => $value) |
1220 | 1218 | { |
1221 | - if($value != '$, $$$') |
|
1219 | + if ($value != '$, $$$') |
|
1222 | 1220 | { |
1223 | - $ldapContact[$attr] = Api\Translation::convert($value,$this->charset,'utf-8'); |
|
1221 | + $ldapContact[$attr] = Api\Translation::convert($value, $this->charset, 'utf-8'); |
|
1224 | 1222 | } |
1225 | - elseif($isUpdate) |
|
1223 | + elseif ($isUpdate) |
|
1226 | 1224 | { |
1227 | 1225 | $ldapContact[$attr] = array(); |
1228 | 1226 | } |
@@ -1232,7 +1230,7 @@ discard block |
||
1232 | 1230 | { |
1233 | 1231 | $ldapContact['primaryphone'] = $data[$data['tel_prefer']]; |
1234 | 1232 | } |
1235 | - elseif($isUpdate) |
|
1233 | + elseif ($isUpdate) |
|
1236 | 1234 | { |
1237 | 1235 | $ldapContact['primaryphone'] = array(); |
1238 | 1236 | } |
@@ -1247,23 +1245,23 @@ discard block |
||
1247 | 1245 | * @param array &$contact already copied fields according to the mapping |
1248 | 1246 | * @param array $data eGW contact data |
1249 | 1247 | */ |
1250 | - function _evolutionperson2egw(&$contact,$data) |
|
1248 | + function _evolutionperson2egw(&$contact, $data) |
|
1251 | 1249 | { |
1252 | 1250 | if ($data['category'] && is_array($data['category'])) |
1253 | 1251 | { |
1254 | 1252 | $contact['cat_id'] = array(); |
1255 | - foreach($data['category'] as $iii => $cat) |
|
1253 | + foreach ($data['category'] as $iii => $cat) |
|
1256 | 1254 | { |
1257 | 1255 | if (!is_int($iii)) continue; |
1258 | 1256 | |
1259 | 1257 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1260 | 1258 | } |
1261 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1259 | + if ($contact['cat_id']) $contact['cat_id'] = implode(',', $contact['cat_id']); |
|
1262 | 1260 | } |
1263 | 1261 | if ($data['primaryphone']) |
1264 | 1262 | { |
1265 | - unset($contact['tel_prefer']); // to not find itself |
|
1266 | - $contact['tel_prefer'] = array_search($data['primaryphone'][0],$contact); |
|
1263 | + unset($contact['tel_prefer']); // to not find itself |
|
1264 | + $contact['tel_prefer'] = array_search($data['primaryphone'][0], $contact); |
|
1267 | 1265 | } |
1268 | 1266 | } |
1269 | 1267 | |
@@ -1276,10 +1274,10 @@ discard block |
||
1276 | 1274 | * @param array &$contact already copied fields according to the mapping |
1277 | 1275 | * @param array $data eGW contact data |
1278 | 1276 | */ |
1279 | - function _inetorgperson2egw(&$contact, $data, $cn='cn') |
|
1277 | + function _inetorgperson2egw(&$contact, $data, $cn = 'cn') |
|
1280 | 1278 | { |
1281 | 1279 | $matches = null; |
1282 | - if(empty($data['givenname'][0])) |
|
1280 | + if (empty($data['givenname'][0])) |
|
1283 | 1281 | { |
1284 | 1282 | $parts = explode($data['sn'][0], $data[$cn][0]); |
1285 | 1283 | $contact['n_prefix'] = trim($parts[0]); |
@@ -1287,8 +1285,8 @@ discard block |
||
1287 | 1285 | } |
1288 | 1286 | // iOS addressbook either use "givenname surname" or "surname givenname" depending on contact preference display-order |
1289 | 1287 | // in full name, so we need to check for both when trying to parse prefix, middle name and suffix form full name |
1290 | - elseif (preg_match($preg='/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1291 | - preg_match($preg='/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1288 | + elseif (preg_match($preg = '/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1289 | + preg_match($preg = '/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1292 | 1290 | { |
1293 | 1291 | list(,$contact['n_prefix'], $contact['n_middle'], $contact['n_suffix']) = $matches; |
1294 | 1292 | //error_log(__METHOD__."() preg_match('$preg', '{$data[$cn][0]}') = ".array2string($matches)); |
@@ -1309,11 +1307,11 @@ discard block |
||
1309 | 1307 | * @param array &$contact already copied fields according to the mapping |
1310 | 1308 | * @param array $data eGW contact data |
1311 | 1309 | */ |
1312 | - function _posixaccount2egw(&$contact,$data) |
|
1310 | + function _posixaccount2egw(&$contact, $data) |
|
1313 | 1311 | { |
1314 | - unset($contact); // not used, but required by function signature |
|
1315 | - static $shadowExpireNow=null; |
|
1316 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1312 | + unset($contact); // not used, but required by function signature |
|
1313 | + static $shadowExpireNow = null; |
|
1314 | + if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time() - date('Z')) / 86400); |
|
1317 | 1315 | |
1318 | 1316 | // exclude expired or deactivated accounts |
1319 | 1317 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1331,11 +1329,11 @@ discard block |
||
1331 | 1329 | * @param array &$contact already copied fields according to the mapping |
1332 | 1330 | * @param array $data eGW contact data |
1333 | 1331 | */ |
1334 | - function _mozillaabpersonalpha2egw(&$contact,$data) |
|
1332 | + function _mozillaabpersonalpha2egw(&$contact, $data) |
|
1335 | 1333 | { |
1336 | 1334 | if ($data['c']) |
1337 | 1335 | { |
1338 | - $contact['adr_one_countryname'] = ExecMethod('phpgwapi.country.get_full_name',$data['c'][0]); |
|
1336 | + $contact['adr_one_countryname'] = ExecMethod('phpgwapi.country.get_full_name', $data['c'][0]); |
|
1339 | 1337 | } |
1340 | 1338 | } |
1341 | 1339 | |
@@ -1349,7 +1347,7 @@ discard block |
||
1349 | 1347 | * @param array $data eGW contact data |
1350 | 1348 | * @param boolean $isUpdate |
1351 | 1349 | */ |
1352 | - function _egw2mozillaabpersonalpha(&$ldapContact,$data,$isUpdate) |
|
1350 | + function _egw2mozillaabpersonalpha(&$ldapContact, $data, $isUpdate) |
|
1353 | 1351 | { |
1354 | 1352 | if ($data['adr_one_countrycode']) |
1355 | 1353 | { |
@@ -1357,7 +1355,7 @@ discard block |
||
1357 | 1355 | } |
1358 | 1356 | elseif ($data['adr_one_countryname']) |
1359 | 1357 | { |
1360 | - $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
|
1358 | + $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code', $data['adr_one_countryname']); |
|
1361 | 1359 | if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
1362 | 1360 | { |
1363 | 1361 | $ldapContact['c'] = array(); // should return error... |
@@ -1378,9 +1376,9 @@ discard block |
||
1378 | 1376 | * @param array &$contact already copied fields according to the mapping |
1379 | 1377 | * @param array $data eGW contact data |
1380 | 1378 | */ |
1381 | - function _mozillaorgperson2egw(&$contact,$data) |
|
1379 | + function _mozillaorgperson2egw(&$contact, $data) |
|
1382 | 1380 | { |
1383 | - unset($contact, $data); // not used, but required by function signature |
|
1381 | + unset($contact, $data); // not used, but required by function signature |
|
1384 | 1382 | // no special handling necessary, as it supports two distinct attributes: c, cn |
1385 | 1383 | } |
1386 | 1384 | |
@@ -1394,7 +1392,7 @@ discard block |
||
1394 | 1392 | * @param array $data eGW contact data |
1395 | 1393 | * @param boolean $isUpdate |
1396 | 1394 | */ |
1397 | - function _egw2mozillaorgperson(&$ldapContact,$data,$isUpdate) |
|
1395 | + function _egw2mozillaorgperson(&$ldapContact, $data, $isUpdate) |
|
1398 | 1396 | { |
1399 | 1397 | if ($data['adr_one_countrycode']) |
1400 | 1398 | { |
@@ -1403,7 +1401,7 @@ discard block |
||
1403 | 1401 | } |
1404 | 1402 | elseif ($data['adr_one_countryname']) |
1405 | 1403 | { |
1406 | - $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
|
1404 | + $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code', $data['adr_one_countryname']); |
|
1407 | 1405 | if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
1408 | 1406 | { |
1409 | 1407 | $ldapContact['c'] = array(); // should return error... |
@@ -1422,7 +1420,7 @@ discard block |
||
1422 | 1420 | * @param int $account_id account-id of the old owner |
1423 | 1421 | * @param int $new_owner account-id of the new owner |
1424 | 1422 | */ |
1425 | - function change_owner($account_id,$new_owner) |
|
1423 | + function change_owner($account_id, $new_owner) |
|
1426 | 1424 | { |
1427 | 1425 | error_log(__METHOD__."($account_id,$new_owner) not yet implemented"); |
1428 | 1426 | } |
@@ -327,9 +327,12 @@ discard block |
||
327 | 327 | $this->ds = Api\Ldap::factory(); |
328 | 328 | } |
329 | 329 | // if ldap is NOT the contact repository, we only do accounts and need to use the account-data |
330 | - elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') // not (ldap or sql-ldap) |
|
330 | + elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') |
|
331 | + { |
|
332 | + // not (ldap or sql-ldap) |
|
331 | 333 | { |
332 | 334 | $this->ldap_config['ldap_contact_host'] = $this->ldap_config['ldap_host']; |
335 | + } |
|
333 | 336 | $this->allContactsDN = $this->ldap_config['ldap_context']; |
334 | 337 | $this->ds = Api\Ldap::factory(); |
335 | 338 | } |
@@ -413,7 +416,10 @@ discard block |
||
413 | 416 | } |
414 | 417 | else |
415 | 418 | { |
416 | - if (is_array($contact_id)) $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid']; |
|
419 | + if (is_array($contact_id)) |
|
420 | + { |
|
421 | + $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid']; |
|
422 | + } |
|
417 | 423 | $filter = $this->id_filter($contact_id); |
418 | 424 | } |
419 | 425 | $rows = $this->_searchLDAP($this->allContactsDN, |
@@ -517,7 +523,10 @@ discard block |
||
517 | 523 | // add for all supported objectclasses the objectclass and it's attributes |
518 | 524 | foreach($this->schema2egw as $objectclass => $mapping) |
519 | 525 | { |
520 | - if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue; |
|
526 | + if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) |
|
527 | + { |
|
528 | + continue; |
|
529 | + } |
|
521 | 530 | |
522 | 531 | if($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses)) |
523 | 532 | { |
@@ -535,7 +544,10 @@ discard block |
||
535 | 544 | } |
536 | 545 | foreach($mapping as $egwFieldName => $ldapFieldName) |
537 | 546 | { |
538 | - if (is_int($egwFieldName)) continue; |
|
547 | + if (is_int($egwFieldName)) |
|
548 | + { |
|
549 | + continue; |
|
550 | + } |
|
539 | 551 | if(!empty($data[$egwFieldName])) |
540 | 552 | { |
541 | 553 | // dont convert the (binary) jpegPhoto! |
@@ -671,7 +683,10 @@ discard block |
||
671 | 683 | function delete($keys=null) |
672 | 684 | { |
673 | 685 | // single entry |
674 | - if($keys[$this->contacts_id]) $keys = array( 0 => $keys); |
|
686 | + if($keys[$this->contacts_id]) |
|
687 | + { |
|
688 | + $keys = array( 0 => $keys); |
|
689 | + } |
|
675 | 690 | |
676 | 691 | if(!is_array($keys)) |
677 | 692 | { |
@@ -760,7 +775,10 @@ discard block |
||
760 | 775 | |
761 | 776 | if((int)$filter['owner']) |
762 | 777 | { |
763 | - if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) return false; |
|
778 | + if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) |
|
779 | + { |
|
780 | + return false; |
|
781 | + } |
|
764 | 782 | |
765 | 783 | $searchDN = 'cn='. Api\Ldap::quote(strtolower($accountName)) .','; |
766 | 784 | |
@@ -856,7 +874,10 @@ discard block |
||
856 | 874 | $sort = 'ASC'; |
857 | 875 | foreach(explode(',',$order_by) as $o) |
858 | 876 | { |
859 | - if (substr($o,0,8) == 'contact_') $o = substr($o,8); |
|
877 | + if (substr($o,0,8) == 'contact_') |
|
878 | + { |
|
879 | + $o = substr($o,8); |
|
880 | + } |
|
860 | 881 | if (substr($o,-4) == ' ASC') |
861 | 882 | { |
862 | 883 | $sort = 'ASC'; |
@@ -898,12 +919,18 @@ discard block |
||
898 | 919 | */ |
899 | 920 | function _colFilter($filter) |
900 | 921 | { |
901 | - if (!is_array($filter)) return ''; |
|
922 | + if (!is_array($filter)) |
|
923 | + { |
|
924 | + return ''; |
|
925 | + } |
|
902 | 926 | |
903 | 927 | $filters = ''; |
904 | 928 | foreach($filter as $key => $value) |
905 | 929 | { |
906 | - if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
|
930 | + if ($key != 'cat_id' && $key != 'account_id' && !$value) |
|
931 | + { |
|
932 | + continue; |
|
933 | + } |
|
907 | 934 | |
908 | 935 | switch((string) $key) |
909 | 936 | { |
@@ -935,19 +962,28 @@ discard block |
||
935 | 962 | $GLOBALS['egw']->categories = new Api\Categories(); |
936 | 963 | } |
937 | 964 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
938 | - if (count($cats) > 1) $filters .= '(|'; |
|
965 | + if (count($cats) > 1) |
|
966 | + { |
|
967 | + $filters .= '(|'; |
|
968 | + } |
|
939 | 969 | foreach($cats as $cat) |
940 | 970 | { |
941 | 971 | $catName = Api\Translation::convert( |
942 | 972 | $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
943 | 973 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
944 | 974 | } |
945 | - if (count($cats) > 1) $filters .= ')'; |
|
975 | + if (count($cats) > 1) |
|
976 | + { |
|
977 | + $filters .= ')'; |
|
978 | + } |
|
946 | 979 | } |
947 | 980 | break; |
948 | 981 | |
949 | 982 | case 'carddav_name': |
950 | - if (!is_array($value)) $value = array($value); |
|
983 | + if (!is_array($value)) |
|
984 | + { |
|
985 | + $value = array($value); |
|
986 | + } |
|
951 | 987 | foreach($value as &$v) |
952 | 988 | { |
953 | 989 | $v = basename($v, '.vcf'); |
@@ -977,7 +1013,10 @@ discard block |
||
977 | 1013 | elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
978 | 1014 | { |
979 | 1015 | list(,$name,$value) = $matches; |
980 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
1016 | + if (strpos($name,'.') !== false) |
|
1017 | + { |
|
1018 | + list(,$name) = explode('.',$name); |
|
1019 | + } |
|
981 | 1020 | foreach($this->schema2egw as $mapping) |
982 | 1021 | { |
983 | 1022 | if (isset($mapping[$name])) |
@@ -1028,13 +1067,20 @@ discard block |
||
1028 | 1067 | { |
1029 | 1068 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1030 | 1069 | } |
1031 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1070 | + if(!$result || !$entries = ldap_get_entries($this->ds, $result)) |
|
1071 | + { |
|
1072 | + return array(); |
|
1073 | + } |
|
1032 | 1074 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1033 | 1075 | |
1034 | 1076 | $this->total = $entries['count']; |
1035 | 1077 | foreach($entries as $i => $entry) |
1036 | 1078 | { |
1037 | - if (!is_int($i)) continue; // eg. count |
|
1079 | + if (!is_int($i)) |
|
1080 | + { |
|
1081 | + continue; |
|
1082 | + } |
|
1083 | + // eg. count |
|
1038 | 1084 | |
1039 | 1085 | $contact = array( |
1040 | 1086 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
@@ -1254,11 +1300,17 @@ discard block |
||
1254 | 1300 | $contact['cat_id'] = array(); |
1255 | 1301 | foreach($data['category'] as $iii => $cat) |
1256 | 1302 | { |
1257 | - if (!is_int($iii)) continue; |
|
1303 | + if (!is_int($iii)) |
|
1304 | + { |
|
1305 | + continue; |
|
1306 | + } |
|
1258 | 1307 | |
1259 | 1308 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1260 | 1309 | } |
1261 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1310 | + if ($contact['cat_id']) |
|
1311 | + { |
|
1312 | + $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1313 | + } |
|
1262 | 1314 | } |
1263 | 1315 | if ($data['primaryphone']) |
1264 | 1316 | { |
@@ -1313,7 +1365,10 @@ discard block |
||
1313 | 1365 | { |
1314 | 1366 | unset($contact); // not used, but required by function signature |
1315 | 1367 | static $shadowExpireNow=null; |
1316 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1368 | + if (!isset($shadowExpireNow)) |
|
1369 | + { |
|
1370 | + $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1371 | + } |
|
1317 | 1372 | |
1318 | 1373 | // exclude expired or deactivated accounts |
1319 | 1374 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1358,9 +1413,13 @@ discard block |
||
1358 | 1413 | elseif ($data['adr_one_countryname']) |
1359 | 1414 | { |
1360 | 1415 | $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
1361 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1416 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1417 | + { |
|
1418 | + // Bad countryname when "custom" selected! |
|
1362 | 1419 | { |
1363 | - $ldapContact['c'] = array(); // should return error... |
|
1420 | + $ldapContact['c'] = array(); |
|
1421 | + } |
|
1422 | + // should return error... |
|
1364 | 1423 | } |
1365 | 1424 | } |
1366 | 1425 | elseif ($isUpdate) |
@@ -1399,14 +1458,21 @@ discard block |
||
1399 | 1458 | if ($data['adr_one_countrycode']) |
1400 | 1459 | { |
1401 | 1460 | $ldapContact['c'] = $data['adr_one_countrycode']; |
1402 | - if ($isUpdate) $ldapContact['co'] = array(); |
|
1461 | + if ($isUpdate) |
|
1462 | + { |
|
1463 | + $ldapContact['co'] = array(); |
|
1464 | + } |
|
1403 | 1465 | } |
1404 | 1466 | elseif ($data['adr_one_countryname']) |
1405 | 1467 | { |
1406 | 1468 | $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
1407 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1469 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1408 | 1470 | { |
1409 | - $ldapContact['c'] = array(); // should return error... |
|
1471 | + // Bad countryname when "custom" selected! |
|
1472 | + { |
|
1473 | + $ldapContact['c'] = array(); |
|
1474 | + } |
|
1475 | + // should return error... |
|
1410 | 1476 | } |
1411 | 1477 | } |
1412 | 1478 | elseif ($isUpdate) |