@@ -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(); |
@@ -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; |
@@ -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 | { |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | { |
159 | 159 | $all_children = array_map('intval', (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 | { |
@@ -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 | { |
@@ -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 | { |
@@ -170,7 +170,7 @@ |
||
170 | 170 | * |
171 | 171 | * @param string/array $_contact_id contact_id or array with values for id or account_id |
172 | 172 | * @return array/boolean data if row could be retrived else False |
173 | - */ |
|
173 | + */ |
|
174 | 174 | function read($_contact_id) |
175 | 175 | { |
176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
@@ -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 | } |
@@ -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_locality','adr_two_locality','note', |
|
118 | - 'email','mozillasecondemail','uidnumber', |
|
116 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
117 | + 'adr_one_locality', 'adr_two_locality', '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,18 +853,18 @@ 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 | { |
@@ -874,9 +873,9 @@ discard block |
||
874 | 873 | } |
875 | 874 | usort($rows, function($a, $b) use ($order, $sort) |
876 | 875 | { |
877 | - foreach($order as $f) |
|
876 | + foreach ($order as $f) |
|
878 | 877 | { |
879 | - if($sort == 'ASC') |
|
878 | + if ($sort == 'ASC') |
|
880 | 879 | { |
881 | 880 | $strc = strcmp($a[$f], $b[$f]); |
882 | 881 | } |
@@ -892,13 +891,13 @@ discard block |
||
892 | 891 | // if requested ($start !== false) return only limited resultset |
893 | 892 | if (is_array($start)) |
894 | 893 | { |
895 | - list($start,$offset) = $start; |
|
894 | + list($start, $offset) = $start; |
|
896 | 895 | } |
897 | - if(is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
896 | + if (is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
898 | 897 | { |
899 | 898 | return array_slice($rows, $start, $offset); |
900 | 899 | } |
901 | - elseif(is_numeric($start)) |
|
900 | + elseif (is_numeric($start)) |
|
902 | 901 | { |
903 | 902 | return array_slice($rows, $start, $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']); |
904 | 903 | } |
@@ -916,11 +915,11 @@ discard block |
||
916 | 915 | if (!is_array($filter)) return ''; |
917 | 916 | |
918 | 917 | $filters = ''; |
919 | - foreach($filter as $key => $value) |
|
918 | + foreach ($filter as $key => $value) |
|
920 | 919 | { |
921 | 920 | if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
922 | 921 | |
923 | - switch((string) $key) |
|
922 | + switch ((string)$key) |
|
924 | 923 | { |
925 | 924 | case 'owner': // already handled |
926 | 925 | case 'tid': // ignored |
@@ -934,7 +933,7 @@ discard block |
||
934 | 933 | elseif ($value) |
935 | 934 | { |
936 | 935 | if (is_array($value)) $filters .= '(|'; |
937 | - foreach((array)$value as $value) |
|
936 | + foreach ((array)$value as $value) |
|
938 | 937 | { |
939 | 938 | $filters .= '(uidNumber='.(int)$value.')'; |
940 | 939 | } |
@@ -947,7 +946,7 @@ discard block |
||
947 | 946 | { |
948 | 947 | $filters .= '(!(category=*))'; |
949 | 948 | } |
950 | - elseif((int)$value) |
|
949 | + elseif ((int)$value) |
|
951 | 950 | { |
952 | 951 | if (!is_object($GLOBALS['egw']->categories)) |
953 | 952 | { |
@@ -955,10 +954,10 @@ discard block |
||
955 | 954 | } |
956 | 955 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
957 | 956 | if (count($cats) > 1) $filters .= '(|'; |
958 | - foreach($cats as $cat) |
|
957 | + foreach ($cats as $cat) |
|
959 | 958 | { |
960 | 959 | $catName = Api\Translation::convert( |
961 | - $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
|
960 | + $GLOBALS['egw']->categories->id2name($cat), $this->charset, 'utf-8'); |
|
962 | 961 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
963 | 962 | } |
964 | 963 | if (count($cats) > 1) $filters .= ')'; |
@@ -967,7 +966,7 @@ discard block |
||
967 | 966 | |
968 | 967 | case 'carddav_name': |
969 | 968 | if (!is_array($value)) $value = array($value); |
970 | - foreach($value as &$v) |
|
969 | + foreach ($value as &$v) |
|
971 | 970 | { |
972 | 971 | $v = basename($v, '.vcf'); |
973 | 972 | } |
@@ -985,28 +984,27 @@ discard block |
||
985 | 984 | $matches = null; |
986 | 985 | if (!is_int($key)) |
987 | 986 | { |
988 | - foreach($this->schema2egw as $mapping) |
|
987 | + foreach ($this->schema2egw as $mapping) |
|
989 | 988 | { |
990 | 989 | if (isset($mapping[$key])) |
991 | 990 | { |
992 | 991 | // todo: value = "!''" |
993 | - $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : |
|
994 | - Api\Ldap::quote(Api\Translation::convert($value,$this->charset,'utf-8'))).')'; |
|
992 | + $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : Api\Ldap::quote(Api\Translation::convert($value, $this->charset, 'utf-8'))).')'; |
|
995 | 993 | break; |
996 | 994 | } |
997 | 995 | } |
998 | 996 | } |
999 | 997 | // filter for letter-search |
1000 | - elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
|
998 | + elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/", $value, $matches)) |
|
1001 | 999 | { |
1002 | - list(,$name,$value) = $matches; |
|
1003 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
1004 | - foreach($this->schema2egw as $mapping) |
|
1000 | + list(,$name, $value) = $matches; |
|
1001 | + if (strpos($name, '.') !== false) list(,$name) = explode('.', $name); |
|
1002 | + foreach ($this->schema2egw as $mapping) |
|
1005 | 1003 | { |
1006 | 1004 | if (isset($mapping[$name])) |
1007 | 1005 | { |
1008 | 1006 | $filters .= '('.$mapping[$name].'='.Api\Ldap::quote( |
1009 | - Api\Translation::convert($value,$this->charset,'utf-8')).'*)'; |
|
1007 | + Api\Translation::convert($value, $this->charset, 'utf-8')).'*)'; |
|
1010 | 1008 | break; |
1011 | 1009 | } |
1012 | 1010 | } |
@@ -1030,7 +1028,7 @@ discard block |
||
1030 | 1028 | { |
1031 | 1029 | $filter .= '(|'; |
1032 | 1030 | // unfortunately we have no group-membership attribute in LDAP, like in AD |
1033 | - foreach($GLOBALS['egw']->accounts->members($gid, true) as $account_id) |
|
1031 | + foreach ($GLOBALS['egw']->accounts->members($gid, true) as $account_id) |
|
1034 | 1032 | { |
1035 | 1033 | $filter .= '(uidNumber='.(int)$account_id.')'; |
1036 | 1034 | } |
@@ -1052,7 +1050,7 @@ discard block |
||
1052 | 1050 | * @param array $_skipPlugins =null schema-plugins to skip |
1053 | 1051 | * @return array/boolean with eGW contacts or false on error |
1054 | 1052 | */ |
1055 | - function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null) |
|
1053 | + function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins = null) |
|
1056 | 1054 | { |
1057 | 1055 | $this->total = 0; |
1058 | 1056 | |
@@ -1065,7 +1063,7 @@ discard block |
||
1065 | 1063 | |
1066 | 1064 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype)"); |
1067 | 1065 | |
1068 | - if($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1066 | + if ($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1069 | 1067 | { |
1070 | 1068 | $result = ldap_search($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1071 | 1069 | } |
@@ -1073,36 +1071,36 @@ discard block |
||
1073 | 1071 | { |
1074 | 1072 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1075 | 1073 | } |
1076 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1074 | + if (!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1077 | 1075 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1078 | 1076 | |
1079 | 1077 | $this->total = $entries['count']; |
1080 | - foreach($entries as $i => $entry) |
|
1078 | + foreach ($entries as $i => $entry) |
|
1081 | 1079 | { |
1082 | - if (!is_int($i)) continue; // eg. count |
|
1080 | + if (!is_int($i)) continue; // eg. count |
|
1083 | 1081 | |
1084 | 1082 | $contact = array( |
1085 | 1083 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
1086 | - 'tid' => 'n', // the type id for the addressbook |
|
1084 | + 'tid' => 'n', // the type id for the addressbook |
|
1087 | 1085 | ); |
1088 | - foreach($entry['objectclass'] as $ii => $objectclass) |
|
1086 | + foreach ($entry['objectclass'] as $ii => $objectclass) |
|
1089 | 1087 | { |
1090 | 1088 | $objectclass = strtolower($objectclass); |
1091 | 1089 | if (!is_int($ii) || !isset($this->schema2egw[$objectclass])) |
1092 | 1090 | { |
1093 | - continue; // eg. count or unsupported objectclass |
|
1091 | + continue; // eg. count or unsupported objectclass |
|
1094 | 1092 | } |
1095 | - foreach($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1093 | + foreach ($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1096 | 1094 | { |
1097 | - if(!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1095 | + if (!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1098 | 1096 | { |
1099 | - $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0],'utf-8'); |
|
1097 | + $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0], 'utf-8'); |
|
1100 | 1098 | } |
1101 | 1099 | } |
1102 | 1100 | $objectclass2egw = '_'.$objectclass.'2egw'; |
1103 | - if (!in_array($objectclass2egw, (array)$_skipPlugins) &&method_exists($this,$objectclass2egw)) |
|
1101 | + if (!in_array($objectclass2egw, (array)$_skipPlugins) && method_exists($this, $objectclass2egw)) |
|
1104 | 1102 | { |
1105 | - if (($ret=$this->$objectclass2egw($contact,$entry)) === false) |
|
1103 | + if (($ret = $this->$objectclass2egw($contact, $entry)) === false) |
|
1106 | 1104 | { |
1107 | 1105 | --$this->total; |
1108 | 1106 | continue 2; |
@@ -1112,20 +1110,20 @@ discard block |
||
1112 | 1110 | // read binary jpegphoto only for one result == call by read |
1113 | 1111 | if ($this->total == 1 && isset($entry['jpegphoto'][0])) |
1114 | 1112 | { |
1115 | - $bin = ldap_get_values_len($this->ds,ldap_first_entry($this->ds,$result),'jpegphoto'); |
|
1113 | + $bin = ldap_get_values_len($this->ds, ldap_first_entry($this->ds, $result), 'jpegphoto'); |
|
1116 | 1114 | $contact['jpegphoto'] = $bin[0]; |
1117 | 1115 | } |
1118 | 1116 | $matches = null; |
1119 | - if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1117 | + if (preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1120 | 1118 | { |
1121 | 1119 | // personal addressbook |
1122 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','u'); |
|
1120 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'u'); |
|
1123 | 1121 | $contact['private'] = 0; |
1124 | 1122 | } |
1125 | - elseif(preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1123 | + elseif (preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1126 | 1124 | { |
1127 | 1125 | // group addressbook |
1128 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','g'); |
|
1126 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g'); |
|
1129 | 1127 | $contact['private'] = 0; |
1130 | 1128 | } |
1131 | 1129 | else |
@@ -1134,12 +1132,12 @@ discard block |
||
1134 | 1132 | $contact['owner'] = 0; |
1135 | 1133 | $contact['private'] = 0; |
1136 | 1134 | } |
1137 | - foreach(array( |
|
1135 | + foreach (array( |
|
1138 | 1136 | 'createtimestamp' => 'created', |
1139 | 1137 | 'modifytimestamp' => 'modified', |
1140 | 1138 | ) as $ldapFieldName => $egwFieldName) |
1141 | 1139 | { |
1142 | - if(!empty($entry[$ldapFieldName][0])) |
|
1140 | + if (!empty($entry[$ldapFieldName][0])) |
|
1143 | 1141 | { |
1144 | 1142 | $contact[$egwFieldName] = $this->_ldap2ts($entry[$ldapFieldName][0]); |
1145 | 1143 | } |
@@ -1158,8 +1156,8 @@ discard block |
||
1158 | 1156 | */ |
1159 | 1157 | static function _ldap2ts($date) |
1160 | 1158 | { |
1161 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
1162 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
1159 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
1160 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
1163 | 1161 | } |
1164 | 1162 | |
1165 | 1163 | /** |
@@ -1182,22 +1180,22 @@ discard block |
||
1182 | 1180 | function _check_create_dn($baseDN) |
1183 | 1181 | { |
1184 | 1182 | // check if $baseDN exists. If not create new one |
1185 | - if(@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1183 | + if (@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1186 | 1184 | { |
1187 | 1185 | return false; |
1188 | 1186 | } |
1189 | 1187 | //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)); |
1190 | - if(ldap_errno($this->ds) != 32 || substr($baseDN,0,3) != 'cn=') |
|
1188 | + if (ldap_errno($this->ds) != 32 || substr($baseDN, 0, 3) != 'cn=') |
|
1191 | 1189 | { |
1192 | 1190 | 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)); |
1193 | - return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1191 | + return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1194 | 1192 | } |
1195 | 1193 | // create a admin connection to add the needed DN |
1196 | 1194 | $adminLDAP = new ldap; |
1197 | 1195 | $adminDS = $adminLDAP->ldapConnect(); |
1198 | 1196 | |
1199 | - list(,$ou) = explode(',',$baseDN); |
|
1200 | - foreach(array( |
|
1197 | + list(,$ou) = explode(',', $baseDN); |
|
1198 | + foreach (array( |
|
1201 | 1199 | 'ou=contacts,'.$this->allContactsDN, |
1202 | 1200 | $ou.',ou=contacts,'.$this->allContactsDN, |
1203 | 1201 | $baseDN, |
@@ -1206,16 +1204,16 @@ discard block |
||
1206 | 1204 | if (!@ldap_read($this->ds, $dn, 'objectclass=*') && ldap_errno($this->ds) == 32) |
1207 | 1205 | { |
1208 | 1206 | // entry does not exist, lets try to create it |
1209 | - list($top) = explode(',',$dn); |
|
1210 | - list($var,$val) = explode('=',$top); |
|
1207 | + list($top) = explode(',', $dn); |
|
1208 | + list($var, $val) = explode('=', $top); |
|
1211 | 1209 | $data = array( |
1212 | 1210 | 'objectClass' => $var == 'cn' ? 'organizationalRole' : 'organizationalUnit', |
1213 | 1211 | $var => $val, |
1214 | 1212 | ); |
1215 | - if(!@ldap_add($adminDS, $dn, $data)) |
|
1213 | + if (!@ldap_add($adminDS, $dn, $data)) |
|
1216 | 1214 | { |
1217 | 1215 | //echo "<p>ldap_add($adminDS,'$dn',".print_r($data,true).")</p>\n"; |
1218 | - $err = lang("Can't create dn %1",$dn).': '.$this->_error(__LINE__,$adminDS); |
|
1216 | + $err = lang("Can't create dn %1", $dn).': '.$this->_error(__LINE__, $adminDS); |
|
1219 | 1217 | $adminLDAP->ldapDisconnect(); |
1220 | 1218 | return $err; |
1221 | 1219 | } |
@@ -1232,7 +1230,7 @@ discard block |
||
1232 | 1230 | * @param int $line |
1233 | 1231 | * @return string |
1234 | 1232 | */ |
1235 | - function _error($line,$ds=null) |
|
1233 | + function _error($line, $ds = null) |
|
1236 | 1234 | { |
1237 | 1235 | return ldap_error($ds ? $ds : $this->ds).': '.__CLASS__.': '.$line; |
1238 | 1236 | } |
@@ -1247,27 +1245,27 @@ discard block |
||
1247 | 1245 | * @param array $data eGW contact data |
1248 | 1246 | * @param boolean $isUpdate |
1249 | 1247 | */ |
1250 | - function _egw2evolutionperson(&$ldapContact,$data,$isUpdate) |
|
1248 | + function _egw2evolutionperson(&$ldapContact, $data, $isUpdate) |
|
1251 | 1249 | { |
1252 | - if(!empty($data['cat_id'])) |
|
1250 | + if (!empty($data['cat_id'])) |
|
1253 | 1251 | { |
1254 | 1252 | $ldapContact['category'] = array(); |
1255 | - foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id']) as $cat) |
|
1253 | + foreach (is_array($data['cat_id']) ? $data['cat_id'] : explode(',', $data['cat_id']) as $cat) |
|
1256 | 1254 | { |
1257 | 1255 | $ldapContact['category'][] = Api\Translation::convert( |
1258 | - Api\Categories::id2name($cat),$this->charset,'utf-8'); |
|
1256 | + Api\Categories::id2name($cat), $this->charset, 'utf-8'); |
|
1259 | 1257 | } |
1260 | 1258 | } |
1261 | - foreach(array( |
|
1262 | - 'postaladdress' => $data['adr_one_street'] .'$'. $data['adr_one_locality'] .', '. $data['adr_one_region'] .'$'. $data['adr_one_postalcode'] .'$$'. $data['adr_one_countryname'], |
|
1263 | - 'homepostaladdress' => $data['adr_two_street'] .'$'. $data['adr_two_locality'] .', '. $data['adr_two_region'] .'$'. $data['adr_two_postalcode'] .'$$'. $data['adr_two_countryname'], |
|
1259 | + foreach (array( |
|
1260 | + 'postaladdress' => $data['adr_one_street'].'$'.$data['adr_one_locality'].', '.$data['adr_one_region'].'$'.$data['adr_one_postalcode'].'$$'.$data['adr_one_countryname'], |
|
1261 | + 'homepostaladdress' => $data['adr_two_street'].'$'.$data['adr_two_locality'].', '.$data['adr_two_region'].'$'.$data['adr_two_postalcode'].'$$'.$data['adr_two_countryname'], |
|
1264 | 1262 | ) as $attr => $value) |
1265 | 1263 | { |
1266 | - if($value != '$, $$$') |
|
1264 | + if ($value != '$, $$$') |
|
1267 | 1265 | { |
1268 | - $ldapContact[$attr] = Api\Translation::convert($value,$this->charset,'utf-8'); |
|
1266 | + $ldapContact[$attr] = Api\Translation::convert($value, $this->charset, 'utf-8'); |
|
1269 | 1267 | } |
1270 | - elseif($isUpdate) |
|
1268 | + elseif ($isUpdate) |
|
1271 | 1269 | { |
1272 | 1270 | $ldapContact[$attr] = array(); |
1273 | 1271 | } |
@@ -1277,7 +1275,7 @@ discard block |
||
1277 | 1275 | { |
1278 | 1276 | $ldapContact['primaryphone'] = $data[$data['tel_prefer']]; |
1279 | 1277 | } |
1280 | - elseif($isUpdate) |
|
1278 | + elseif ($isUpdate) |
|
1281 | 1279 | { |
1282 | 1280 | $ldapContact['primaryphone'] = array(); |
1283 | 1281 | } |
@@ -1292,23 +1290,23 @@ discard block |
||
1292 | 1290 | * @param array &$contact already copied fields according to the mapping |
1293 | 1291 | * @param array $data eGW contact data |
1294 | 1292 | */ |
1295 | - function _evolutionperson2egw(&$contact,$data) |
|
1293 | + function _evolutionperson2egw(&$contact, $data) |
|
1296 | 1294 | { |
1297 | 1295 | if ($data['category'] && is_array($data['category'])) |
1298 | 1296 | { |
1299 | 1297 | $contact['cat_id'] = array(); |
1300 | - foreach($data['category'] as $iii => $cat) |
|
1298 | + foreach ($data['category'] as $iii => $cat) |
|
1301 | 1299 | { |
1302 | 1300 | if (!is_int($iii)) continue; |
1303 | 1301 | |
1304 | 1302 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1305 | 1303 | } |
1306 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1304 | + if ($contact['cat_id']) $contact['cat_id'] = implode(',', $contact['cat_id']); |
|
1307 | 1305 | } |
1308 | 1306 | if ($data['primaryphone']) |
1309 | 1307 | { |
1310 | - unset($contact['tel_prefer']); // to not find itself |
|
1311 | - $contact['tel_prefer'] = array_search($data['primaryphone'][0],$contact); |
|
1308 | + unset($contact['tel_prefer']); // to not find itself |
|
1309 | + $contact['tel_prefer'] = array_search($data['primaryphone'][0], $contact); |
|
1312 | 1310 | } |
1313 | 1311 | } |
1314 | 1312 | |
@@ -1321,10 +1319,10 @@ discard block |
||
1321 | 1319 | * @param array &$contact already copied fields according to the mapping |
1322 | 1320 | * @param array $data eGW contact data |
1323 | 1321 | */ |
1324 | - function _inetorgperson2egw(&$contact, $data, $cn='cn') |
|
1322 | + function _inetorgperson2egw(&$contact, $data, $cn = 'cn') |
|
1325 | 1323 | { |
1326 | 1324 | $matches = null; |
1327 | - if(empty($data['givenname'][0])) |
|
1325 | + if (empty($data['givenname'][0])) |
|
1328 | 1326 | { |
1329 | 1327 | $parts = explode($data['sn'][0], $data[$cn][0]); |
1330 | 1328 | $contact['n_prefix'] = trim($parts[0]); |
@@ -1332,8 +1330,8 @@ discard block |
||
1332 | 1330 | } |
1333 | 1331 | // iOS addressbook either use "givenname surname" or "surname givenname" depending on contact preference display-order |
1334 | 1332 | // in full name, so we need to check for both when trying to parse prefix, middle name and suffix form full name |
1335 | - elseif (preg_match($preg='/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1336 | - preg_match($preg='/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1333 | + elseif (preg_match($preg = '/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1334 | + preg_match($preg = '/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1337 | 1335 | { |
1338 | 1336 | list(,$contact['n_prefix'], $contact['n_middle'], $contact['n_suffix']) = $matches; |
1339 | 1337 | //error_log(__METHOD__."() preg_match('$preg', '{$data[$cn][0]}') = ".array2string($matches)); |
@@ -1354,11 +1352,11 @@ discard block |
||
1354 | 1352 | * @param array &$contact already copied fields according to the mapping |
1355 | 1353 | * @param array $data eGW contact data |
1356 | 1354 | */ |
1357 | - function _posixaccount2egw(&$contact,$data) |
|
1355 | + function _posixaccount2egw(&$contact, $data) |
|
1358 | 1356 | { |
1359 | - unset($contact); // not used, but required by function signature |
|
1360 | - static $shadowExpireNow=null; |
|
1361 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1357 | + unset($contact); // not used, but required by function signature |
|
1358 | + static $shadowExpireNow = null; |
|
1359 | + if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time() - date('Z')) / 86400); |
|
1362 | 1360 | |
1363 | 1361 | // exclude expired or deactivated accounts |
1364 | 1362 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1376,7 +1374,7 @@ discard block |
||
1376 | 1374 | * @param array &$contact already copied fields according to the mapping |
1377 | 1375 | * @param array $data eGW contact data |
1378 | 1376 | */ |
1379 | - function _mozillaabpersonalpha2egw(&$contact,$data) |
|
1377 | + function _mozillaabpersonalpha2egw(&$contact, $data) |
|
1380 | 1378 | { |
1381 | 1379 | if ($data['c']) |
1382 | 1380 | { |
@@ -1394,7 +1392,7 @@ discard block |
||
1394 | 1392 | * @param array $data eGW contact data |
1395 | 1393 | * @param boolean $isUpdate |
1396 | 1394 | */ |
1397 | - function _egw2mozillaabpersonalpha(&$ldapContact,$data,$isUpdate) |
|
1395 | + function _egw2mozillaabpersonalpha(&$ldapContact, $data, $isUpdate) |
|
1398 | 1396 | { |
1399 | 1397 | if ($data['adr_one_countrycode']) |
1400 | 1398 | { |
@@ -1423,9 +1421,9 @@ discard block |
||
1423 | 1421 | * @param array &$contact already copied fields according to the mapping |
1424 | 1422 | * @param array $data eGW contact data |
1425 | 1423 | */ |
1426 | - function _mozillaorgperson2egw(&$contact,$data) |
|
1424 | + function _mozillaorgperson2egw(&$contact, $data) |
|
1427 | 1425 | { |
1428 | - unset($contact, $data); // not used, but required by function signature |
|
1426 | + unset($contact, $data); // not used, but required by function signature |
|
1429 | 1427 | // no special handling necessary, as it supports two distinct attributes: c, cn |
1430 | 1428 | } |
1431 | 1429 | |
@@ -1439,7 +1437,7 @@ discard block |
||
1439 | 1437 | * @param array $data eGW contact data |
1440 | 1438 | * @param boolean $isUpdate |
1441 | 1439 | */ |
1442 | - function _egw2mozillaorgperson(&$ldapContact,$data,$isUpdate) |
|
1440 | + function _egw2mozillaorgperson(&$ldapContact, $data, $isUpdate) |
|
1443 | 1441 | { |
1444 | 1442 | if ($data['adr_one_countrycode']) |
1445 | 1443 | { |
@@ -1467,7 +1465,7 @@ discard block |
||
1467 | 1465 | * @param int $account_id account-id of the old owner |
1468 | 1466 | * @param int $new_owner account-id of the new owner |
1469 | 1467 | */ |
1470 | - function change_owner($account_id,$new_owner) |
|
1468 | + function change_owner($account_id, $new_owner) |
|
1471 | 1469 | { |
1472 | 1470 | error_log(__METHOD__."($account_id,$new_owner) not yet implemented"); |
1473 | 1471 | } |
@@ -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'; |
@@ -884,7 +905,10 @@ discard block |
||
884 | 905 | { |
885 | 906 | $strc = strcmp($b[$f], $a[$f]); |
886 | 907 | } |
887 | - if ($strc) return $strc; |
|
908 | + if ($strc) |
|
909 | + { |
|
910 | + return $strc; |
|
911 | + } |
|
888 | 912 | } |
889 | 913 | return 0; |
890 | 914 | }); |
@@ -913,12 +937,18 @@ discard block |
||
913 | 937 | */ |
914 | 938 | function _colFilter($filter) |
915 | 939 | { |
916 | - if (!is_array($filter)) return ''; |
|
940 | + if (!is_array($filter)) |
|
941 | + { |
|
942 | + return ''; |
|
943 | + } |
|
917 | 944 | |
918 | 945 | $filters = ''; |
919 | 946 | foreach($filter as $key => $value) |
920 | 947 | { |
921 | - if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
|
948 | + if ($key != 'cat_id' && $key != 'account_id' && !$value) |
|
949 | + { |
|
950 | + continue; |
|
951 | + } |
|
922 | 952 | |
923 | 953 | switch((string) $key) |
924 | 954 | { |
@@ -933,12 +963,18 @@ discard block |
||
933 | 963 | } |
934 | 964 | elseif ($value) |
935 | 965 | { |
936 | - if (is_array($value)) $filters .= '(|'; |
|
966 | + if (is_array($value)) |
|
967 | + { |
|
968 | + $filters .= '(|'; |
|
969 | + } |
|
937 | 970 | foreach((array)$value as $value) |
938 | 971 | { |
939 | 972 | $filters .= '(uidNumber='.(int)$value.')'; |
940 | 973 | } |
941 | - if (is_array($value)) $filters .= ')'; |
|
974 | + if (is_array($value)) |
|
975 | + { |
|
976 | + $filters .= ')'; |
|
977 | + } |
|
942 | 978 | } |
943 | 979 | break; |
944 | 980 | |
@@ -954,19 +990,28 @@ discard block |
||
954 | 990 | $GLOBALS['egw']->categories = new Api\Categories(); |
955 | 991 | } |
956 | 992 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
957 | - if (count($cats) > 1) $filters .= '(|'; |
|
993 | + if (count($cats) > 1) |
|
994 | + { |
|
995 | + $filters .= '(|'; |
|
996 | + } |
|
958 | 997 | foreach($cats as $cat) |
959 | 998 | { |
960 | 999 | $catName = Api\Translation::convert( |
961 | 1000 | $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
962 | 1001 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
963 | 1002 | } |
964 | - if (count($cats) > 1) $filters .= ')'; |
|
1003 | + if (count($cats) > 1) |
|
1004 | + { |
|
1005 | + $filters .= ')'; |
|
1006 | + } |
|
965 | 1007 | } |
966 | 1008 | break; |
967 | 1009 | |
968 | 1010 | case 'carddav_name': |
969 | - if (!is_array($value)) $value = array($value); |
|
1011 | + if (!is_array($value)) |
|
1012 | + { |
|
1013 | + $value = array($value); |
|
1014 | + } |
|
970 | 1015 | foreach($value as &$v) |
971 | 1016 | { |
972 | 1017 | $v = basename($v, '.vcf'); |
@@ -1000,7 +1045,10 @@ discard block |
||
1000 | 1045 | elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
1001 | 1046 | { |
1002 | 1047 | list(,$name,$value) = $matches; |
1003 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
1048 | + if (strpos($name,'.') !== false) |
|
1049 | + { |
|
1050 | + list(,$name) = explode('.',$name); |
|
1051 | + } |
|
1004 | 1052 | foreach($this->schema2egw as $mapping) |
1005 | 1053 | { |
1006 | 1054 | if (isset($mapping[$name])) |
@@ -1073,13 +1121,20 @@ discard block |
||
1073 | 1121 | { |
1074 | 1122 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1075 | 1123 | } |
1076 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1124 | + if(!$result || !$entries = ldap_get_entries($this->ds, $result)) |
|
1125 | + { |
|
1126 | + return array(); |
|
1127 | + } |
|
1077 | 1128 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1078 | 1129 | |
1079 | 1130 | $this->total = $entries['count']; |
1080 | 1131 | foreach($entries as $i => $entry) |
1081 | 1132 | { |
1082 | - if (!is_int($i)) continue; // eg. count |
|
1133 | + if (!is_int($i)) |
|
1134 | + { |
|
1135 | + continue; |
|
1136 | + } |
|
1137 | + // eg. count |
|
1083 | 1138 | |
1084 | 1139 | $contact = array( |
1085 | 1140 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
@@ -1299,11 +1354,17 @@ discard block |
||
1299 | 1354 | $contact['cat_id'] = array(); |
1300 | 1355 | foreach($data['category'] as $iii => $cat) |
1301 | 1356 | { |
1302 | - if (!is_int($iii)) continue; |
|
1357 | + if (!is_int($iii)) |
|
1358 | + { |
|
1359 | + continue; |
|
1360 | + } |
|
1303 | 1361 | |
1304 | 1362 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1305 | 1363 | } |
1306 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1364 | + if ($contact['cat_id']) |
|
1365 | + { |
|
1366 | + $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1367 | + } |
|
1307 | 1368 | } |
1308 | 1369 | if ($data['primaryphone']) |
1309 | 1370 | { |
@@ -1358,7 +1419,10 @@ discard block |
||
1358 | 1419 | { |
1359 | 1420 | unset($contact); // not used, but required by function signature |
1360 | 1421 | static $shadowExpireNow=null; |
1361 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1422 | + if (!isset($shadowExpireNow)) |
|
1423 | + { |
|
1424 | + $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1425 | + } |
|
1362 | 1426 | |
1363 | 1427 | // exclude expired or deactivated accounts |
1364 | 1428 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1403,9 +1467,13 @@ discard block |
||
1403 | 1467 | elseif ($data['adr_one_countryname']) |
1404 | 1468 | { |
1405 | 1469 | $ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']); |
1406 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1470 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1407 | 1471 | { |
1408 | - $ldapContact['c'] = array(); // should return error... |
|
1472 | + // Bad countryname when "custom" selected! |
|
1473 | + { |
|
1474 | + $ldapContact['c'] = array(); |
|
1475 | + } |
|
1476 | + // should return error... |
|
1409 | 1477 | } |
1410 | 1478 | } |
1411 | 1479 | elseif ($isUpdate) |
@@ -1444,14 +1512,21 @@ discard block |
||
1444 | 1512 | if ($data['adr_one_countrycode']) |
1445 | 1513 | { |
1446 | 1514 | $ldapContact['c'] = $data['adr_one_countrycode']; |
1447 | - if ($isUpdate) $ldapContact['co'] = array(); |
|
1515 | + if ($isUpdate) |
|
1516 | + { |
|
1517 | + $ldapContact['co'] = array(); |
|
1518 | + } |
|
1448 | 1519 | } |
1449 | 1520 | elseif ($data['adr_one_countryname']) |
1450 | 1521 | { |
1451 | 1522 | $ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']); |
1452 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1523 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1524 | + { |
|
1525 | + // Bad countryname when "custom" selected! |
|
1453 | 1526 | { |
1454 | - $ldapContact['c'] = array(); // should return error... |
|
1527 | + $ldapContact['c'] = array(); |
|
1528 | + } |
|
1529 | + // should return error... |
|
1455 | 1530 | } |
1456 | 1531 | } |
1457 | 1532 | elseif ($isUpdate) |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * For a union-query you call search for each query with $start=='UNION' and one more with only $order_by and $start set to run the union-query. |
251 | 251 | * |
252 | 252 | * @param array|string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) |
253 | - * @param boolean|string|array $only_keys =true True returns only keys, False returns all cols. or |
|
253 | + * @param boolean|string $only_keys =true True returns only keys, False returns all cols. or |
|
254 | 254 | * comma seperated list or array of columns to return |
255 | 255 | * @param string $order_by ='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) |
256 | 256 | * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * or whole where array: column-name => value(s) pairs |
509 | 509 | * @param string $uid_column ='list_owner' column-name or null to use $uids as where array |
510 | 510 | * @param string $member_attr =null null: no members, 'contact_uid', 'contact_id', 'caldav_name' return members as that attribute |
511 | - * @param boolean|int|array $limit_in_ab =false if true only return members from the same owners addressbook, |
|
511 | + * @param boolean $limit_in_ab =false if true only return members from the same owners addressbook, |
|
512 | 512 | * if int|array only return members from the given owners addressbook(s) |
513 | 513 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
514 | 514 | */ |
@@ -858,9 +858,9 @@ |
||
858 | 858 | } |
859 | 859 | |
860 | 860 | /** |
861 | - * Deletes custom field data |
|
862 | - * Implemented to deal with LDAP backend, which saves CFs in SQL, but the account record is in LDAP |
|
863 | - */ |
|
861 | + * Deletes custom field data |
|
862 | + * Implemented to deal with LDAP backend, which saves CFs in SQL, but the account record is in LDAP |
|
863 | + */ |
|
864 | 864 | function delete_customfields($data) |
865 | 865 | { |
866 | 866 | $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
@@ -543,7 +543,7 @@ |
||
543 | 543 | foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
544 | 544 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
545 | 545 | __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
546 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
546 | + '',false,0,"join $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
547 | 547 | { |
548 | 548 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
549 | 549 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @var string |
46 | 46 | */ |
47 | - var $contacts_id='id'; |
|
47 | + var $contacts_id = 'id'; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * Name of the table for distribution lists |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param Api\Db $db =null |
69 | 69 | */ |
70 | - function __construct(Api\Db $db=null) |
|
70 | + function __construct(Api\Db $db = null) |
|
71 | 71 | { |
72 | 72 | parent::__construct('api', 'egw_addressbook', self::EXTRA_TABLE, |
73 | 73 | 'contact_', '_name', '_value', '_id', $db); |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
115 | 115 | $advanced_search = false; |
116 | 116 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
117 | - $wildcard ='%'; |
|
118 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
117 | + $wildcard = '%'; |
|
118 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
119 | 119 | |
120 | 120 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
121 | 121 | if ($filter['cat_id']) |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | // we have no private grants in addressbook at the moment, they have then to be added here too |
134 | 134 | if ($param['owner']) |
135 | 135 | { |
136 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
136 | + if (!$this->grants[(int)$filter['owner']]) return false; // we have no access to that addressbook |
|
137 | 137 | |
138 | 138 | $filter['owner'] = $param['owner']; |
139 | 139 | $filter['private'] = 0; |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | { |
143 | 143 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
144 | 144 | { |
145 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
145 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
146 | 146 | } |
147 | 147 | $filter[] = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
148 | 148 | " OR contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
149 | - implode(',',array_keys($this->grants))."))"; |
|
149 | + implode(',', array_keys($this->grants))."))"; |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | if ($param['searchletter']) |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | } |
156 | 156 | else |
157 | 157 | { |
158 | - $filter[] = "org_name != ''";// AND org_name IS NOT NULL"; |
|
158 | + $filter[] = "org_name != ''"; // AND org_name IS NOT NULL"; |
|
159 | 159 | } |
160 | 160 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
161 | 161 | |
162 | - list(,$by) = explode(',',$param['org_view']); |
|
162 | + list(,$by) = explode(',', $param['org_view']); |
|
163 | 163 | if (!$by) |
164 | 164 | { |
165 | 165 | $extra = array( |
@@ -172,50 +172,49 @@ discard block |
||
172 | 172 | else // by adr_one_location or org_unit |
173 | 173 | { |
174 | 174 | // org total for more then one $by |
175 | - $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : |
|
176 | - "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
177 | - parent::search($param['search'],array('org_name'), |
|
175 | + $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
176 | + parent::search($param['search'], array('org_name'), |
|
178 | 177 | "GROUP BY org_name HAVING $by_expr > 1 ORDER BY org_name $sort", array( |
179 | 178 | "NULL AS $by", |
180 | 179 | '1 AS is_main', |
181 | 180 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
182 | 181 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
183 | 182 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
184 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter); |
|
183 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter); |
|
185 | 184 | // org by location |
186 | - parent::search($param['search'],array('org_name'), |
|
185 | + parent::search($param['search'], array('org_name'), |
|
187 | 186 | "GROUP BY org_name,$by ORDER BY org_name $sort,$by $sort", array( |
188 | 187 | "CASE WHEN $by IS NULL THEN '' ELSE $by END AS $by", |
189 | 188 | '0 AS is_main', |
190 | 189 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
191 | 190 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
192 | 191 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
193 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter); |
|
192 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter); |
|
194 | 193 | $append = "ORDER BY org_name $sort,is_main DESC,$by $sort"; |
195 | 194 | } |
196 | - $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
|
197 | - array($param['start'],$param['num_rows']),$filter); |
|
195 | + $rows = parent::search($param['search'], array('org_name'), $append, $extra, $wildcard, false, $op/*'OR'*/, |
|
196 | + array($param['start'], $param['num_rows']), $filter); |
|
198 | 197 | |
199 | 198 | if (!$rows) return false; |
200 | 199 | |
201 | 200 | // query the values for *_count == 1, to display them instead |
202 | 201 | $filter['org_name'] = $orgs = array(); |
203 | - foreach($rows as $row) |
|
202 | + foreach ($rows as $row) |
|
204 | 203 | { |
205 | 204 | if ($row['org_unit_count'] == 1 || $row['adr_one_locality_count'] == 1) |
206 | 205 | { |
207 | - $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
206 | + $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
208 | 207 | } |
209 | - $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count']==1 ? $row[$by] : '|||') : ''); |
|
208 | + $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count'] == 1 ? $row[$by] : '|||') : ''); |
|
210 | 209 | $orgs[$org_key] = $row; |
211 | 210 | } |
212 | 211 | unset($rows); |
213 | 212 | |
214 | 213 | if (count($filter['org_name'])) |
215 | 214 | { |
216 | - foreach((array) parent::search(null, array('org_name','org_unit','adr_one_locality'), |
|
215 | + foreach ((array)parent::search(null, array('org_name', 'org_unit', 'adr_one_locality'), |
|
217 | 216 | 'GROUP BY org_name,org_unit,adr_one_locality', |
218 | - '',$wildcard,false,$op/*'AND'*/,false,$filter) as $row) |
|
217 | + '', $wildcard, false, $op/*'AND'*/, false, $filter) as $row) |
|
219 | 218 | { |
220 | 219 | $org_key = $row['org_name'].($by ? '|||'.$row[$by] : ''); |
221 | 220 | if ($orgs[$org_key]['org_unit_count'] == 1) |
@@ -265,9 +264,9 @@ discard block |
||
265 | 264 | * @param boolean $ignore_acl =false true: no acl check |
266 | 265 | * @return boolean/array of matching rows (the row is an array of the cols) or False |
267 | 266 | */ |
268 | - 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, $ignore_acl=false) |
|
267 | + 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, $ignore_acl = false) |
|
269 | 268 | { |
270 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
269 | + if ((int)$this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
271 | 270 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
272 | 271 | |
273 | 272 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -283,10 +282,10 @@ discard block |
||
283 | 282 | { |
284 | 283 | if ($filter['cat_id'][0] == '!') |
285 | 284 | { |
286 | - $filter['cat_id'] = substr($filter['cat_id'],1); |
|
285 | + $filter['cat_id'] = substr($filter['cat_id'], 1); |
|
287 | 286 | $not = 'NOT'; |
288 | 287 | } |
289 | - $filter[] = $this->_cat_filter($filter['cat_id'],$not); |
|
288 | + $filter[] = $this->_cat_filter($filter['cat_id'], $not); |
|
290 | 289 | unset($filter['cat_id']); |
291 | 290 | } |
292 | 291 | |
@@ -296,17 +295,17 @@ discard block |
||
296 | 295 | { |
297 | 296 | // add read ACL for groupmembers (they have no |
298 | 297 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
299 | - (!isset($filter['owner']) || in_array('0',(array)$filter['owner']))) |
|
298 | + (!isset($filter['owner']) || in_array('0', (array)$filter['owner']))) |
|
300 | 299 | { |
301 | 300 | $groupmembers = array(); |
302 | - foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $group_id) |
|
301 | + foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $group_id) |
|
303 | 302 | { |
304 | - if (($members = $GLOBALS['egw']->accounts->members($group_id,true))) |
|
303 | + if (($members = $GLOBALS['egw']->accounts->members($group_id, true))) |
|
305 | 304 | { |
306 | - $groupmembers = array_merge($groupmembers,$members); |
|
305 | + $groupmembers = array_merge($groupmembers, $members); |
|
307 | 306 | } |
308 | 307 | } |
309 | - $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.',array( |
|
308 | + $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.', array( |
|
310 | 309 | 'account_id' => array_unique($groupmembers), |
311 | 310 | )); |
312 | 311 | } |
@@ -314,34 +313,34 @@ discard block |
||
314 | 313 | if (isset($filter['owner'])) |
315 | 314 | { |
316 | 315 | // no grants for selected owner/addressbook |
317 | - if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
|
316 | + if (!($filter['owner'] = array_intersect((array)$filter['owner'], array_keys($this->grants)))) |
|
318 | 317 | { |
319 | 318 | if (!isset($groupmember_sql)) return false; |
320 | - $filter[] = substr($groupmember_sql,4); |
|
319 | + $filter[] = substr($groupmember_sql, 4); |
|
321 | 320 | unset($filter['owner']); |
322 | 321 | } |
323 | 322 | // for an owner filter, which does NOT include current user, filter out private entries |
324 | - elseif (!in_array($GLOBALS['egw_info']['user']['account_id'],$filter['owner'])) |
|
323 | + elseif (!in_array($GLOBALS['egw_info']['user']['account_id'], $filter['owner'])) |
|
325 | 324 | { |
326 | 325 | $filter['private'] = 0; |
327 | 326 | } |
328 | 327 | // if multiple addressbooks (incl. current owner) are searched, we need full acl filter |
329 | - elseif(count($filter['owner']) > 1) |
|
328 | + elseif (count($filter['owner']) > 1) |
|
330 | 329 | { |
331 | 330 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
332 | 331 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
333 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
332 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
334 | 333 | } |
335 | 334 | } |
336 | 335 | else // search all addressbooks, incl. accounts |
337 | 336 | { |
338 | 337 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
339 | 338 | { |
340 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
339 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
341 | 340 | } |
342 | 341 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
343 | 342 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
344 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
343 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
345 | 344 | } |
346 | 345 | } |
347 | 346 | if (isset($filter['list'])) |
@@ -351,21 +350,21 @@ discard block |
||
351 | 350 | unset($filter['list']); |
352 | 351 | } |
353 | 352 | // add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin) |
354 | - if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' && |
|
355 | - strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter)) |
|
353 | + if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository, 0, 3) == 'sql' && |
|
354 | + strpos($join, $GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id', $filter)) |
|
356 | 355 | { |
357 | 356 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
358 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
357 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
359 | 358 | } |
360 | 359 | if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
361 | 360 | { |
362 | - switch(gettype($only_keys)) |
|
361 | + switch (gettype($only_keys)) |
|
363 | 362 | { |
364 | 363 | case 'boolean': |
365 | 364 | // Correctly handled by parent class |
366 | 365 | break; |
367 | 366 | case 'string': |
368 | - $only_keys = explode(',',$only_keys); |
|
367 | + $only_keys = explode(',', $only_keys); |
|
369 | 368 | // fall through |
370 | 369 | } |
371 | 370 | // postgres requires that expressions in order by appear in the columns of a distinct select |
@@ -373,14 +372,14 @@ discard block |
||
373 | 372 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
374 | 373 | $order_by, $all_matches, PREG_SET_ORDER)) |
375 | 374 | { |
376 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
377 | - foreach($all_matches as $matches) |
|
375 | + if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',', $extra_cols) : array(); |
|
376 | + foreach ($all_matches as $matches) |
|
378 | 377 | { |
379 | 378 | $table = ''; |
380 | 379 | $column = $matches[1]; |
381 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
380 | + if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
382 | 381 | if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
383 | - if (strpos($column,'.') === false) |
|
382 | + if (strpos($column, '.') === false) |
|
384 | 383 | { |
385 | 384 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
386 | 385 | if (isset($this->db_cols[$column])) |
@@ -396,34 +395,34 @@ discard block |
||
396 | 395 | //_debug_array($matches); |
397 | 396 | if (!empty($order_by) && $table) // postgres requires explizit order by |
398 | 397 | { |
399 | - $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
|
398 | + $order_by = str_replace($matches[0], $table.$column.' '.$matches[2].' '.$matches[3].$matches[4], $order_by); |
|
400 | 399 | } |
401 | 400 | } |
402 | 401 | //_debug_array($order_by); _debug_array($extra_cols); |
403 | 402 | } |
404 | 403 | |
405 | 404 | // Understand search by date with wildcard (????.10.??) according to user date preference |
406 | - if(is_string($criteria) && strpos($criteria, '?') !== false) |
|
405 | + if (is_string($criteria) && strpos($criteria, '?') !== false) |
|
407 | 406 | { |
408 | 407 | // First, check for a 'date', with wildcards, in the user's format |
409 | - $date_regex = str_replace('Q','d', |
|
410 | - str_replace(array('Y','m','d','.','-'), |
|
411 | - array('(?P<Y>(?:\?|\Q){4})','(?P<m>(?:\?|\Q){2})','(?P<d>(?:\?|\Q){2})','\.','\-'), |
|
408 | + $date_regex = str_replace('Q', 'd', |
|
409 | + str_replace(array('Y', 'm', 'd', '.', '-'), |
|
410 | + array('(?P<Y>(?:\?|\Q){4})', '(?P<m>(?:\?|\Q){2})', '(?P<d>(?:\?|\Q){2})', '\.', '\-'), |
|
412 | 411 | $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); |
413 | 412 | |
414 | - if(preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
413 | + if (preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
415 | 414 | { |
416 | - foreach($matches[0] as $m_id => $match) |
|
415 | + foreach ($matches[0] as $m_id => $match) |
|
417 | 416 | { |
418 | 417 | // Birthday is Y-m-d |
419 | - $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*",$criteria); |
|
418 | + $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*", $criteria); |
|
420 | 419 | } |
421 | 420 | } |
422 | 421 | } |
423 | 422 | } |
424 | - $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
423 | + $rows = & parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
425 | 424 | |
426 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
425 | + if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
427 | 426 | |
428 | 427 | return $rows; |
429 | 428 | } |
@@ -435,18 +434,18 @@ discard block |
||
435 | 434 | * @param int|array $cat_id |
436 | 435 | * @return string sql to filter by given cat |
437 | 436 | */ |
438 | - function _cat_filter($cat_id, $not='') |
|
437 | + function _cat_filter($cat_id, $not = '') |
|
439 | 438 | { |
440 | 439 | if (!is_object($GLOBALS['egw']->categories)) |
441 | 440 | { |
442 | 441 | $GLOBALS['egw']->categories = new Api\Categories; |
443 | 442 | } |
444 | - foreach($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
443 | + foreach ($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
445 | 444 | { |
446 | - $cat_filter[] = $this->db->concat("','",cat_id,"','")." $not LIKE '%,$cat,%'"; |
|
445 | + $cat_filter[] = $this->db->concat("','", cat_id, "','")." $not LIKE '%,$cat,%'"; |
|
447 | 446 | } |
448 | - $cfilter = '('.implode(' OR ',$cat_filter).')'; |
|
449 | - if(!empty($not)) |
|
447 | + $cfilter = '('.implode(' OR ', $cat_filter).')'; |
|
448 | + if (!empty($not)) |
|
450 | 449 | { |
451 | 450 | $cfilter = "( $cfilter OR cat_id IS NULL )"; |
452 | 451 | } |
@@ -463,9 +462,9 @@ discard block |
||
463 | 462 | function _cat_search($cats) |
464 | 463 | { |
465 | 464 | $cat_filter = array(); |
466 | - foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
|
465 | + foreach (is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',', $cats)) as $cat) |
|
467 | 466 | { |
468 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
467 | + if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','", cat_id, "','")." LIKE '%,$cat,%'"; |
|
469 | 468 | } |
470 | 469 | return $cat_filter; |
471 | 470 | } |
@@ -476,32 +475,32 @@ discard block |
||
476 | 475 | * @param int $account_id account-id of the old owner |
477 | 476 | * @param int $new_owner account-id of the new owner |
478 | 477 | */ |
479 | - function change_owner($account_id,$new_owner) |
|
478 | + function change_owner($account_id, $new_owner) |
|
480 | 479 | { |
481 | 480 | if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
482 | 481 | { |
483 | 482 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
484 | 483 | } |
485 | 484 | // contacts |
486 | - $this->db->update($this->table_name,array( |
|
485 | + $this->db->update($this->table_name, array( |
|
487 | 486 | 'contact_owner' => $new_owner, |
488 | - ),array( |
|
487 | + ), array( |
|
489 | 488 | 'contact_owner' => $account_id, |
490 | - ),__LINE__,__FILE__); |
|
489 | + ), __LINE__, __FILE__); |
|
491 | 490 | |
492 | 491 | // cfs |
493 | 492 | $this->db->update(self::EXTRA_TABLE, array( |
494 | 493 | 'contact_owner' => $new_owner |
495 | - ),array( |
|
494 | + ), array( |
|
496 | 495 | 'contact_owner' => $account_id |
497 | 496 | ), __LINE__, __FILE__); |
498 | 497 | |
499 | 498 | // lists |
500 | 499 | $this->db->update($this->lists_table, array( |
501 | 500 | 'list_owner' => $new_owner, |
502 | - ),array( |
|
501 | + ), array( |
|
503 | 502 | 'list_owner' => $account_id, |
504 | - ),__LINE__,__FILE__); |
|
503 | + ), __LINE__, __FILE__); |
|
505 | 504 | } |
506 | 505 | |
507 | 506 | /** |
@@ -515,21 +514,21 @@ discard block |
||
515 | 514 | * if int|array only return members from the given owners addressbook(s) |
516 | 515 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
517 | 516 | */ |
518 | - function get_lists($uids,$uid_column='list_owner',$member_attr=null,$limit_in_ab=false) |
|
517 | + function get_lists($uids, $uid_column = 'list_owner', $member_attr = null, $limit_in_ab = false) |
|
519 | 518 | { |
520 | 519 | if (is_array($uids) && array_key_exists('list_id', $uids)) |
521 | 520 | { |
522 | - $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.',array('list_id' => $uids['list_id'])); |
|
521 | + $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.', array('list_id' => $uids['list_id'])); |
|
523 | 522 | unset($uids['list_id']); |
524 | 523 | } |
525 | 524 | $lists = array(); |
526 | - foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
|
527 | - false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
525 | + foreach ($this->db->select($this->lists_table, '*', $uid_column ? array($uid_column=>$uids) : $uids, __LINE__, __FILE__, |
|
526 | + false, 'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
528 | 527 | { |
529 | 528 | if ($member_attr) $row['members'] = array(); |
530 | 529 | $lists[$row['list_id']] = $row; |
531 | 530 | } |
532 | - if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
|
531 | + if ($lists && $member_attr && in_array($member_attr, array('contact_id', 'contact_uid', 'caldav_name'))) |
|
533 | 532 | { |
534 | 533 | if ($limit_in_ab) |
535 | 534 | { |
@@ -543,10 +542,9 @@ discard block |
||
543 | 542 | $in_ab_join .= "list_owner=$this->table_name.contact_owner"; |
544 | 543 | } |
545 | 544 | } |
546 | - foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
545 | + foreach ($this->db->select($this->ab2list_table, "$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
547 | 546 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
548 | - __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
|
549 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
547 | + __LINE__, __FILE__, false, $member_attr == 'contact_id' ? '' : '', false, 0, "JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
550 | 548 | { |
551 | 549 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
552 | 550 | } |
@@ -564,7 +562,7 @@ discard block |
||
564 | 562 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
565 | 563 | * @return int|boolean integer list_id or false on error |
566 | 564 | */ |
567 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
565 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
568 | 566 | { |
569 | 567 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
570 | 568 | if (!$keys && !$data || !(int)$owner) return false; |
@@ -578,7 +576,7 @@ discard block |
||
578 | 576 | { |
579 | 577 | $data['list_owner'] = $owner; |
580 | 578 | } |
581 | - if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys,__LINE__,__FILE__)->fetchColumn())) |
|
579 | + if (!$keys || !($list_id = $this->db->select($this->lists_table, 'list_id', $keys, __LINE__, __FILE__)->fetchColumn())) |
|
582 | 580 | { |
583 | 581 | $data['list_created'] = time(); |
584 | 582 | $data['list_creator'] = $GLOBALS['egw_info']['user']['account_id']; |
@@ -591,9 +589,9 @@ discard block |
||
591 | 589 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
592 | 590 | if (!$data['list_id']) unset($data['list_id']); |
593 | 591 | |
594 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
592 | + if (!$this->db->insert($this->lists_table, $data, $keys, __LINE__, __FILE__)) return false; |
|
595 | 593 | |
596 | - if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
|
594 | + if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table, 'list_id')) && |
|
597 | 595 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
598 | 596 | { |
599 | 597 | $update = array(); |
@@ -605,9 +603,9 @@ discard block |
||
605 | 603 | { |
606 | 604 | $update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf'; |
607 | 605 | } |
608 | - $this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__); |
|
606 | + $this->db->update($this->lists_table, $update, array('list_id'=>$list_id), __LINE__, __FILE__); |
|
609 | 607 | |
610 | - $this->add2list($list_id,$contacts,array()); |
|
608 | + $this->add2list($list_id, $contacts, array()); |
|
611 | 609 | } |
612 | 610 | if ($keys) $data += $keys; |
613 | 611 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
@@ -622,39 +620,39 @@ discard block |
||
622 | 620 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
623 | 621 | * @return false on error |
624 | 622 | */ |
625 | - function add2list($contact,$list,array $existing=null) |
|
623 | + function add2list($contact, $list, array $existing = null) |
|
626 | 624 | { |
627 | 625 | if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
628 | 626 | |
629 | 627 | if (!is_array($existing)) |
630 | 628 | { |
631 | 629 | $existing = array(); |
632 | - foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row) |
|
630 | + foreach ($this->db->select($this->ab2list_table, 'contact_id', array('list_id'=>$list), __LINE__, __FILE__) as $row) |
|
633 | 631 | { |
634 | 632 | $existing[] = $row['contact_id']; |
635 | 633 | } |
636 | 634 | } |
637 | - if (!($to_add = array_diff((array)$contact,$existing))) |
|
635 | + if (!($to_add = array_diff((array)$contact, $existing))) |
|
638 | 636 | { |
639 | - return true; // no need to insert it, would give sql error |
|
637 | + return true; // no need to insert it, would give sql error |
|
640 | 638 | } |
641 | - foreach($to_add as $contact) |
|
639 | + foreach ($to_add as $contact) |
|
642 | 640 | { |
643 | - $this->db->insert($this->ab2list_table,array( |
|
641 | + $this->db->insert($this->ab2list_table, array( |
|
644 | 642 | 'contact_id' => $contact, |
645 | 643 | 'list_id' => $list, |
646 | 644 | 'list_added' => time(), |
647 | 645 | 'list_added_by' => $GLOBALS['egw_info']['user']['account_id'], |
648 | - ),array(),__LINE__,__FILE__); |
|
646 | + ), array(), __LINE__, __FILE__); |
|
649 | 647 | } |
650 | 648 | // update etag |
651 | - return $this->db->update($this->lists_table,array( |
|
649 | + return $this->db->update($this->lists_table, array( |
|
652 | 650 | 'list_etag=list_etag+1', |
653 | 651 | 'list_modified' => time(), |
654 | 652 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
655 | - ),array( |
|
653 | + ), array( |
|
656 | 654 | 'list_id' => $list, |
657 | - ),__LINE__,__FILE__); |
|
655 | + ), __LINE__, __FILE__); |
|
658 | 656 | } |
659 | 657 | |
660 | 658 | /** |
@@ -664,7 +662,7 @@ discard block |
||
664 | 662 | * @param int $list =null list-id or null to remove from all lists |
665 | 663 | * @return false on error |
666 | 664 | */ |
667 | - function remove_from_list($contact,$list=null) |
|
665 | + function remove_from_list($contact, $list = null) |
|
668 | 666 | { |
669 | 667 | if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
670 | 668 | |
@@ -678,24 +676,24 @@ discard block |
||
678 | 676 | else |
679 | 677 | { |
680 | 678 | $list = array(); |
681 | - foreach($this->db->select($this->ab2list_table,'list_id',$where,__LINE__,__FILE__) as $row) |
|
679 | + foreach ($this->db->select($this->ab2list_table, 'list_id', $where, __LINE__, __FILE__) as $row) |
|
682 | 680 | { |
683 | 681 | $list[] = $row['list_id']; |
684 | 682 | } |
685 | 683 | } |
686 | - if (!$this->db->delete($this->ab2list_table,$where,__LINE__,__FILE__)) |
|
684 | + if (!$this->db->delete($this->ab2list_table, $where, __LINE__, __FILE__)) |
|
687 | 685 | { |
688 | 686 | return false; |
689 | 687 | } |
690 | - foreach((array)$list as $list_id) |
|
688 | + foreach ((array)$list as $list_id) |
|
691 | 689 | { |
692 | - $this->db->update($this->lists_table,array( |
|
690 | + $this->db->update($this->lists_table, array( |
|
693 | 691 | 'list_etag=list_etag+1', |
694 | 692 | 'list_modified' => time(), |
695 | 693 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
696 | - ),array( |
|
694 | + ), array( |
|
697 | 695 | 'list_id' => $list_id, |
698 | - ),__LINE__,__FILE__); |
|
696 | + ), __LINE__, __FILE__); |
|
699 | 697 | } |
700 | 698 | return true; |
701 | 699 | } |
@@ -708,9 +706,9 @@ discard block |
||
708 | 706 | */ |
709 | 707 | function delete_list($list) |
710 | 708 | { |
711 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
709 | + if (!$this->db->delete($this->lists_table, array('list_id' => $list), __LINE__, __FILE__)) return false; |
|
712 | 710 | |
713 | - $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
|
711 | + $this->db->delete($this->ab2list_table, array('list_id' => $list), __LINE__, __FILE__); |
|
714 | 712 | |
715 | 713 | return $this->db->affected_rows(); |
716 | 714 | } |
@@ -721,12 +719,12 @@ discard block |
||
721 | 719 | * @param int|array $owner =null null for all lists user has access too |
722 | 720 | * @return int |
723 | 721 | */ |
724 | - function lists_ctag($owner=null) |
|
722 | + function lists_ctag($owner = null) |
|
725 | 723 | { |
726 | 724 | if (is_null($owner)) $owner = array_keys($this->grants); |
727 | 725 | |
728 | - if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
|
729 | - __LINE__,__FILE__)->fetchColumn())) |
|
726 | + if (!($modified = $this->db->select($this->lists_table, 'MAX(list_modified)', array('list_owner'=>$owner), |
|
727 | + __LINE__, __FILE__)->fetchColumn())) |
|
730 | 728 | { |
731 | 729 | return 0; |
732 | 730 | } |
@@ -741,7 +739,7 @@ discard block |
||
741 | 739 | * @param string $join |
742 | 740 | * @return array|boolean |
743 | 741 | */ |
744 | - function read($keys,$extra_cols='',$join='') |
|
742 | + function read($keys, $extra_cols = '', $join = '') |
|
745 | 743 | { |
746 | 744 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
747 | 745 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -754,11 +752,11 @@ discard block |
||
754 | 752 | $keys = array('uid' => $keys); |
755 | 753 | } |
756 | 754 | try { |
757 | - $contact = parent::read($keys,$extra_cols,$join); |
|
755 | + $contact = parent::read($keys, $extra_cols, $join); |
|
758 | 756 | } |
759 | 757 | // catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267) |
760 | 758 | // caused by non-ascii chars compared with ascii field uid |
761 | - catch(Api\Db\Exception $e) { |
|
759 | + catch (Api\Db\Exception $e) { |
|
762 | 760 | _egw_log_exception($e); |
763 | 761 | return false; |
764 | 762 | } |
@@ -766,7 +764,7 @@ discard block |
||
766 | 764 | // enforce a minium uid strength |
767 | 765 | if (is_array($contact) && (!isset($contact['uid']) |
768 | 766 | || strlen($contact['uid']) < $minimum_uid_length)) { |
769 | - parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
|
767 | + parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook', $contact['id']))); |
|
770 | 768 | } |
771 | 769 | return $contact; |
772 | 770 | } |
@@ -780,7 +778,7 @@ discard block |
||
780 | 778 | */ |
781 | 779 | function save($keys = NULL, $extra_where = NULL) |
782 | 780 | { |
783 | - unset($extra_where); // not used, but required by function signature |
|
781 | + unset($extra_where); // not used, but required by function signature |
|
784 | 782 | |
785 | 783 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
786 | 784 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -796,9 +794,9 @@ discard block |
||
796 | 794 | { |
797 | 795 | $etag = $this->data['etag']; |
798 | 796 | unset($this->data['etag']); |
799 | - if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
|
797 | + if (!($err = parent::save(array('contact_etag=contact_etag+1'), array('contact_etag' => $etag)))) |
|
800 | 798 | { |
801 | - $this->data['etag'] = $etag+1; |
|
799 | + $this->data['etag'] = $etag + 1; |
|
802 | 800 | } |
803 | 801 | else |
804 | 802 | { |
@@ -818,7 +816,7 @@ discard block |
||
818 | 816 | // enforce a minium uid strength |
819 | 817 | if (!isset($this->data['uid']) || strlen($this->data['uid']) < $minimum_uid_length) |
820 | 818 | { |
821 | - $update['uid'] = Api\CalDAV::generate_uid('addressbook',$this->data['id']); |
|
819 | + $update['uid'] = Api\CalDAV::generate_uid('addressbook', $this->data['id']); |
|
822 | 820 | //echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>"; |
823 | 821 | } |
824 | 822 | // set carddav_name, if not given by caller |
@@ -844,7 +842,7 @@ discard block |
||
844 | 842 | { |
845 | 843 | if (!$list) return false; |
846 | 844 | |
847 | - return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
|
845 | + return $this->db->select($this->lists_table, '*', array('list_id'=>$list), __LINE__, __FILE__)->fetch(); |
|
848 | 846 | } |
849 | 847 | |
850 | 848 | /** |
@@ -855,9 +853,9 @@ discard block |
||
855 | 853 | * @param array $extra_cols =array() extra-data to be saved |
856 | 854 | * @return bool false on success, errornumber on failure |
857 | 855 | */ |
858 | - function save_customfields($data, array $extra_cols=array()) |
|
856 | + function save_customfields($data, array $extra_cols = array()) |
|
859 | 857 | { |
860 | - return parent::save_customfields($data, array('contact_owner' => $data['owner'])+$extra_cols); |
|
858 | + return parent::save_customfields($data, array('contact_owner' => $data['owner']) + $extra_cols); |
|
861 | 859 | } |
862 | 860 | |
863 | 861 | /** |
@@ -866,6 +864,6 @@ discard block |
||
866 | 864 | */ |
867 | 865 | function delete_customfields($data) |
868 | 866 | { |
869 | - $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
|
867 | + $this->db->delete($this->extra_table, $data, __LINE__, __FILE__); |
|
870 | 868 | } |
871 | 869 | } |
@@ -111,11 +111,20 @@ discard block |
||
111 | 111 | { |
112 | 112 | $filter = is_array($param['col_filter']) ? $param['col_filter'] : array(); |
113 | 113 | $op = 'OR'; |
114 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
114 | + if (isset($param['op']) && !empty($param['op'])) |
|
115 | + { |
|
116 | + $op = $param['op']; |
|
117 | + } |
|
115 | 118 | $advanced_search = false; |
116 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
119 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
120 | + { |
|
121 | + $advanced_search = true; |
|
122 | + } |
|
117 | 123 | $wildcard ='%'; |
118 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
124 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
125 | + { |
|
126 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
127 | + } |
|
119 | 128 | |
120 | 129 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
121 | 130 | if ($filter['cat_id']) |
@@ -133,7 +142,11 @@ discard block |
||
133 | 142 | // we have no private grants in addressbook at the moment, they have then to be added here too |
134 | 143 | if ($param['owner']) |
135 | 144 | { |
136 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
145 | + if (!$this->grants[(int) $filter['owner']]) |
|
146 | + { |
|
147 | + return false; |
|
148 | + } |
|
149 | + // we have no access to that addressbook |
|
137 | 150 | |
138 | 151 | $filter['owner'] = $param['owner']; |
139 | 152 | $filter['private'] = 0; |
@@ -196,7 +209,10 @@ discard block |
||
196 | 209 | $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
197 | 210 | array($param['start'],$param['num_rows']),$filter); |
198 | 211 | |
199 | - if (!$rows) return false; |
|
212 | + if (!$rows) |
|
213 | + { |
|
214 | + return false; |
|
215 | + } |
|
200 | 216 | |
201 | 217 | // query the values for *_count == 1, to display them instead |
202 | 218 | $filter['org_name'] = $orgs = array(); |
@@ -267,7 +283,10 @@ discard block |
||
267 | 283 | */ |
268 | 284 | 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, $ignore_acl=false) |
269 | 285 | { |
270 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
286 | + if ((int) $this->debug >= 4) |
|
287 | + { |
|
288 | + echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
289 | + } |
|
271 | 290 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
272 | 291 | |
273 | 292 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -316,7 +335,10 @@ discard block |
||
316 | 335 | // no grants for selected owner/addressbook |
317 | 336 | if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
318 | 337 | { |
319 | - if (!isset($groupmember_sql)) return false; |
|
338 | + if (!isset($groupmember_sql)) |
|
339 | + { |
|
340 | + return false; |
|
341 | + } |
|
320 | 342 | $filter[] = substr($groupmember_sql,4); |
321 | 343 | unset($filter['owner']); |
322 | 344 | } |
@@ -365,13 +387,16 @@ discard block |
||
365 | 387 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
366 | 388 | $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
367 | 389 | } |
368 | - if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
|
390 | + if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) |
|
391 | + { |
|
392 | + // search also adds a join for custom fields! |
|
369 | 393 | { |
370 | 394 | switch(gettype($only_keys)) |
371 | 395 | { |
372 | 396 | case 'boolean': |
373 | 397 | // Correctly handled by parent class |
374 | 398 | break; |
399 | + } |
|
375 | 400 | case 'string': |
376 | 401 | $only_keys = explode(',',$only_keys); |
377 | 402 | // fall through |
@@ -381,13 +406,23 @@ discard block |
||
381 | 406 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
382 | 407 | $order_by, $all_matches, PREG_SET_ORDER)) |
383 | 408 | { |
384 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
409 | + if (!is_array($extra_cols)) |
|
410 | + { |
|
411 | + $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
412 | + } |
|
385 | 413 | foreach($all_matches as $matches) |
386 | 414 | { |
387 | 415 | $table = ''; |
388 | 416 | $column = $matches[1]; |
389 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
390 | - if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
|
417 | + if ($column[0] == '#') |
|
418 | + { |
|
419 | + continue; |
|
420 | + } |
|
421 | + // order by custom field is handeled in so_sql_cf anyway |
|
422 | + if (($key = array_search($column, $this->db_cols)) !== false) |
|
423 | + { |
|
424 | + $column = $key; |
|
425 | + } |
|
391 | 426 | if (strpos($column,'.') === false) |
392 | 427 | { |
393 | 428 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
@@ -402,10 +437,13 @@ discard block |
||
402 | 437 | } |
403 | 438 | $extra_cols[] = $table.$column.' '.$matches[2]; |
404 | 439 | //_debug_array($matches); |
405 | - if (!empty($order_by) && $table) // postgres requires explizit order by |
|
440 | + if (!empty($order_by) && $table) |
|
441 | + { |
|
442 | + // postgres requires explizit order by |
|
406 | 443 | { |
407 | 444 | $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
408 | 445 | } |
446 | + } |
|
409 | 447 | } |
410 | 448 | //_debug_array($order_by); _debug_array($extra_cols); |
411 | 449 | } |
@@ -431,7 +469,11 @@ discard block |
||
431 | 469 | } |
432 | 470 | $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
433 | 471 | |
434 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
472 | + if ($start === false) |
|
473 | + { |
|
474 | + $this->total = is_array($rows) ? count($rows) : 0; |
|
475 | + } |
|
476 | + // so_sql sets total only for $start !== false! |
|
435 | 477 | |
436 | 478 | return $rows; |
437 | 479 | } |
@@ -473,7 +515,10 @@ discard block |
||
473 | 515 | $cat_filter = array(); |
474 | 516 | foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
475 | 517 | { |
476 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
518 | + if (is_numeric($cat)) |
|
519 | + { |
|
520 | + $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
521 | + } |
|
477 | 522 | } |
478 | 523 | return $cat_filter; |
479 | 524 | } |
@@ -486,10 +531,13 @@ discard block |
||
486 | 531 | */ |
487 | 532 | function change_owner($account_id,$new_owner) |
488 | 533 | { |
489 | - if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
|
534 | + if (!$new_owner) |
|
535 | + { |
|
536 | + // otherwise we would create an account (contact_owner==0) |
|
490 | 537 | { |
491 | 538 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
492 | 539 | } |
540 | + } |
|
493 | 541 | // contacts |
494 | 542 | $this->db->update($this->table_name,array( |
495 | 543 | 'contact_owner' => $new_owner, |
@@ -534,7 +582,10 @@ discard block |
||
534 | 582 | foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
535 | 583 | false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
536 | 584 | { |
537 | - if ($member_attr) $row['members'] = array(); |
|
585 | + if ($member_attr) |
|
586 | + { |
|
587 | + $row['members'] = array(); |
|
588 | + } |
|
538 | 589 | $lists[$row['list_id']] = $row; |
539 | 590 | } |
540 | 591 | if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
@@ -597,9 +648,15 @@ discard block |
||
597 | 648 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
598 | 649 | { |
599 | 650 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
600 | - if (!$keys && !$data || !(int)$owner) return false; |
|
651 | + if (!$keys && !$data || !(int)$owner) |
|
652 | + { |
|
653 | + return false; |
|
654 | + } |
|
601 | 655 | |
602 | - if ($keys && !is_array($keys)) $keys = array('list_name' => $keys); |
|
656 | + if ($keys && !is_array($keys)) |
|
657 | + { |
|
658 | + $keys = array('list_name' => $keys); |
|
659 | + } |
|
603 | 660 | if ($keys) |
604 | 661 | { |
605 | 662 | $keys['list_owner'] = $owner; |
@@ -619,9 +676,15 @@ discard block |
||
619 | 676 | } |
620 | 677 | $data['list_modified'] = time(); |
621 | 678 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
622 | - if (!$data['list_id']) unset($data['list_id']); |
|
679 | + if (!$data['list_id']) |
|
680 | + { |
|
681 | + unset($data['list_id']); |
|
682 | + } |
|
623 | 683 | |
624 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
684 | + if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) |
|
685 | + { |
|
686 | + return false; |
|
687 | + } |
|
625 | 688 | |
626 | 689 | if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
627 | 690 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
@@ -639,7 +702,10 @@ discard block |
||
639 | 702 | |
640 | 703 | $this->add2list($list_id,$contacts,array()); |
641 | 704 | } |
642 | - if ($keys) $data += $keys; |
|
705 | + if ($keys) |
|
706 | + { |
|
707 | + $data += $keys; |
|
708 | + } |
|
643 | 709 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
644 | 710 | return $list_id; |
645 | 711 | } |
@@ -654,7 +720,10 @@ discard block |
||
654 | 720 | */ |
655 | 721 | function add2list($contact,$list,array $existing=null) |
656 | 722 | { |
657 | - if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
|
723 | + if (!(int)$list || !is_array($contact) && !(int)$contact) |
|
724 | + { |
|
725 | + return false; |
|
726 | + } |
|
658 | 727 | |
659 | 728 | if (!is_array($existing)) |
660 | 729 | { |
@@ -696,7 +765,10 @@ discard block |
||
696 | 765 | */ |
697 | 766 | function remove_from_list($contact,$list=null) |
698 | 767 | { |
699 | - if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
|
768 | + if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) |
|
769 | + { |
|
770 | + return false; |
|
771 | + } |
|
700 | 772 | |
701 | 773 | $where = array( |
702 | 774 | 'contact_id' => $contact, |
@@ -738,7 +810,10 @@ discard block |
||
738 | 810 | */ |
739 | 811 | function delete_list($list) |
740 | 812 | { |
741 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
813 | + if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) |
|
814 | + { |
|
815 | + return false; |
|
816 | + } |
|
742 | 817 | |
743 | 818 | $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
744 | 819 | |
@@ -753,7 +828,10 @@ discard block |
||
753 | 828 | */ |
754 | 829 | function lists_ctag($owner=null) |
755 | 830 | { |
756 | - if (is_null($owner)) $owner = array_keys($this->grants); |
|
831 | + if (is_null($owner)) |
|
832 | + { |
|
833 | + $owner = array_keys($this->grants); |
|
834 | + } |
|
757 | 835 | |
758 | 836 | if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
759 | 837 | __LINE__,__FILE__)->fetchColumn())) |
@@ -773,9 +851,12 @@ discard block |
||
773 | 851 | */ |
774 | 852 | function read($keys,$extra_cols='',$join='') |
775 | 853 | { |
776 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
854 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
855 | + { |
|
777 | 856 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
778 | - } else { |
|
857 | + } |
|
858 | + else |
|
859 | + { |
|
779 | 860 | $minimum_uid_length = 8; |
780 | 861 | } |
781 | 862 | |
@@ -795,7 +876,8 @@ discard block |
||
795 | 876 | |
796 | 877 | // enforce a minium uid strength |
797 | 878 | if (is_array($contact) && (!isset($contact['uid']) |
798 | - || strlen($contact['uid']) < $minimum_uid_length)) { |
|
879 | + || strlen($contact['uid']) < $minimum_uid_length)) |
|
880 | + { |
|
799 | 881 | parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
800 | 882 | } |
801 | 883 | return $contact; |
@@ -812,19 +894,28 @@ discard block |
||
812 | 894 | { |
813 | 895 | unset($extra_where); // not used, but required by function signature |
814 | 896 | |
815 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
897 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
898 | + { |
|
816 | 899 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
817 | - } else { |
|
900 | + } |
|
901 | + else |
|
902 | + { |
|
818 | 903 | $minimum_uid_length = 8; |
819 | 904 | } |
820 | 905 | |
821 | - if (is_array($keys) && count($keys)) $this->data_merge($keys); |
|
906 | + if (is_array($keys) && count($keys)) |
|
907 | + { |
|
908 | + $this->data_merge($keys); |
|
909 | + } |
|
822 | 910 | |
823 | 911 | $new_entry = !$this->data['id']; |
824 | 912 | |
825 | - if (isset($this->data['etag'])) // do we have an etag in the data to write |
|
913 | + if (isset($this->data['etag'])) |
|
914 | + { |
|
915 | + // do we have an etag in the data to write |
|
826 | 916 | { |
827 | 917 | $etag = $this->data['etag']; |
918 | + } |
|
828 | 919 | unset($this->data['etag']); |
829 | 920 | if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
830 | 921 | { |
@@ -872,7 +963,10 @@ discard block |
||
872 | 963 | */ |
873 | 964 | function read_list($list) |
874 | 965 | { |
875 | - if (!$list) return false; |
|
966 | + if (!$list) |
|
967 | + { |
|
968 | + return false; |
|
969 | + } |
|
876 | 970 | |
877 | 971 | return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
878 | 972 | } |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | * @param array|string $criteria array of key and data cols, OR string to search over all standard search fields |
593 | 593 | * @param boolean|string $only_keys =true True returns only keys, False returns all cols. comma seperated list of keys to return |
594 | 594 | * @param string $order_by ='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) |
595 | - * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
595 | + * @param string $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
596 | 596 | * @param string $wildcard ='' appended befor and after each criteria |
597 | 597 | * @param boolean $empty =false False=empty criteria are ignored in query, True=empty have to be empty in row |
598 | 598 | * @param string $op ='AND' defaults to 'AND', can be set to 'OR' too, then criteria's are OR'ed together |
@@ -814,8 +814,6 @@ discard block |
||
814 | 814 | * delete / move all contacts of an addressbook |
815 | 815 | * |
816 | 816 | * @param array $data |
817 | - * @param int $data['account_id'] owner to change |
|
818 | - * @param int $data['new_owner'] new owner or 0 for delete |
|
819 | 817 | */ |
820 | 818 | function deleteaccount($data) |
821 | 819 | { |
@@ -44,23 +44,23 @@ discard block |
||
44 | 44 | var $extra_table = 'egw_addressbook_extra'; |
45 | 45 | |
46 | 46 | /** |
47 | - * @var string |
|
48 | - */ |
|
47 | + * @var string |
|
48 | + */ |
|
49 | 49 | var $extra_id = 'contact_id'; |
50 | 50 | |
51 | 51 | /** |
52 | - * @var string |
|
53 | - */ |
|
52 | + * @var string |
|
53 | + */ |
|
54 | 54 | var $extra_owner = 'contact_owner'; |
55 | 55 | |
56 | 56 | /** |
57 | - * @var string |
|
58 | - */ |
|
57 | + * @var string |
|
58 | + */ |
|
59 | 59 | var $extra_key = 'contact_name'; |
60 | 60 | |
61 | 61 | /** |
62 | - * @var string |
|
63 | - */ |
|
62 | + * @var string |
|
63 | + */ |
|
64 | 64 | var $extra_value = 'contact_value'; |
65 | 65 | |
66 | 66 | /** |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | var $distributionlist_view ='(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
72 | 72 | var $distributionlist_tabledef = array(); |
73 | 73 | /** |
74 | - * @var string |
|
75 | - */ |
|
74 | + * @var string |
|
75 | + */ |
|
76 | 76 | var $distri_id = 'contact_id'; |
77 | 77 | |
78 | 78 | /** |
79 | - * @var string |
|
80 | - */ |
|
79 | + * @var string |
|
80 | + */ |
|
81 | 81 | var $distri_owner = 'list_owner'; |
82 | 82 | |
83 | 83 | /** |
84 | - * @var string |
|
85 | - */ |
|
84 | + * @var string |
|
85 | + */ |
|
86 | 86 | var $distri_key = 'list_id'; |
87 | 87 | |
88 | 88 | /** |
89 | - * @var string |
|
90 | - */ |
|
89 | + * @var string |
|
90 | + */ |
|
91 | 91 | var $distri_value = 'list_name'; |
92 | 92 | |
93 | 93 | /** |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | var $content_types = array(); |
161 | 161 | |
162 | 162 | /** |
163 | - * Special content type to indicate a deleted addressbook |
|
164 | - * |
|
165 | - * @var String; |
|
166 | - */ |
|
163 | + * Special content type to indicate a deleted addressbook |
|
164 | + * |
|
165 | + * @var String; |
|
166 | + */ |
|
167 | 167 | const DELETED_TYPE = 'D'; |
168 | 168 | |
169 | 169 | /** |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | $this->distributionlist_tabledef = array('fd' => array( |
269 | 269 | $this->distri_id => $tda2list['fd'][$this->distri_id], |
270 | 270 | $this->distri_owner => $tdlists['fd'][$this->distri_owner], |
271 | - $this->distri_key => $tdlists['fd'][$this->distri_key], |
|
271 | + $this->distri_key => $tdlists['fd'][$this->distri_key], |
|
272 | 272 | $this->distri_value => $tdlists['fd'][$this->distri_value], |
273 | 273 | ), 'pk' => array(), 'fk' => array(), 'ix' => array(), 'uc' => array(), |
274 | 274 | ); |
@@ -469,12 +469,12 @@ discard block |
||
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
472 | - * deletes contact entry including custom fields |
|
473 | - * |
|
474 | - * @param mixed $contact array with id or just the id |
|
475 | - * @param int $check_etag =null |
|
476 | - * @return boolean|int true on success or false on failiure, 0 if etag does not match |
|
477 | - */ |
|
472 | + * deletes contact entry including custom fields |
|
473 | + * |
|
474 | + * @param mixed $contact array with id or just the id |
|
475 | + * @param int $check_etag =null |
|
476 | + * @return boolean|int true on success or false on failiure, 0 if etag does not match |
|
477 | + */ |
|
478 | 478 | function delete($contact,$check_etag=null) |
479 | 479 | { |
480 | 480 | if (is_array($contact)) $contact = $contact['id']; |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
513 | - * saves contact data including custom fields |
|
514 | - * |
|
515 | - * @param array &$contact contact data from etemplate::exec |
|
516 | - * @return bool false on success, errornumber on failure |
|
517 | - */ |
|
513 | + * saves contact data including custom fields |
|
514 | + * |
|
515 | + * @param array &$contact contact data from etemplate::exec |
|
516 | + * @return bool false on success, errornumber on failure |
|
517 | + */ |
|
518 | 518 | function save(&$contact) |
519 | 519 | { |
520 | 520 | // save mainfields |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * |
567 | 567 | * @param int|string $contact_id contact_id or 'a'.account_id |
568 | 568 | * @return array|boolean data if row could be retrived else False |
569 | - */ |
|
569 | + */ |
|
570 | 570 | function read($contact_id) |
571 | 571 | { |
572 | 572 | if (!is_array($contact_id) && substr($contact_id,0,8) == 'account:') |
@@ -796,10 +796,10 @@ discard block |
||
796 | 796 | } |
797 | 797 | |
798 | 798 | /** |
799 | - * gets all contact fields from database |
|
800 | - * |
|
801 | - * @return array of (internal) field-names |
|
802 | - */ |
|
799 | + * gets all contact fields from database |
|
800 | + * |
|
801 | + * @return array of (internal) field-names |
|
802 | + */ |
|
803 | 803 | function get_contact_columns() |
804 | 804 | { |
805 | 805 | $fields = $this->get_fields('all'); |
@@ -239,10 +239,13 @@ discard block |
||
239 | 239 | |
240 | 240 | // remove some columns, absolutly not necessary to search in sql |
241 | 241 | $this->columns_to_search = array_diff(array_values($this->somain->db_cols),$this->sql_cols_not_to_search); |
242 | - if ($this->customfields) // add custom fields, if configured |
|
242 | + if ($this->customfields) |
|
243 | + { |
|
244 | + // add custom fields, if configured |
|
243 | 245 | { |
244 | 246 | $this->columns_to_search[] = Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE; |
245 | 247 | } |
248 | + } |
|
246 | 249 | } |
247 | 250 | if ($this->user) |
248 | 251 | { |
@@ -319,7 +322,10 @@ discard block |
||
319 | 322 | */ |
320 | 323 | function get_grants($user, $contact_app='addressbook', $preferences=null) |
321 | 324 | { |
322 | - if (!isset($preferences)) $preferences = $GLOBALS['egw_info']['user']['preferences']; |
|
325 | + if (!isset($preferences)) |
|
326 | + { |
|
327 | + $preferences = $GLOBALS['egw_info']['user']['preferences']; |
|
328 | + } |
|
323 | 329 | |
324 | 330 | if ($user) |
325 | 331 | { |
@@ -347,12 +353,25 @@ discard block |
||
347 | 353 | $grants[0] = Api\Acl::READ; |
348 | 354 | } |
349 | 355 | // add account grants for admins (only for current user!) |
350 | - if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL! |
|
356 | + if ($user == $this->user && $this->is_admin()) |
|
357 | + { |
|
358 | + // admin rights can be limited by ACL! |
|
351 | 359 | { |
352 | - $grants[0] = Api\Acl::READ; // admins always have read-access |
|
353 | - if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= Api\Acl::EDIT; |
|
354 | - if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) $grants[0] |= Api\Acl::ADD; |
|
355 | - if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) $grants[0] |= Api\Acl::DELETE; |
|
360 | + $grants[0] = Api\Acl::READ; |
|
361 | + } |
|
362 | + // admins always have read-access |
|
363 | + if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) |
|
364 | + { |
|
365 | + $grants[0] |= Api\Acl::EDIT; |
|
366 | + } |
|
367 | + if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) |
|
368 | + { |
|
369 | + $grants[0] |= Api\Acl::ADD; |
|
370 | + } |
|
371 | + if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) |
|
372 | + { |
|
373 | + $grants[0] |= Api\Acl::DELETE; |
|
374 | + } |
|
356 | 375 | } |
357 | 376 | // allow certain groups to edit contact-data of accounts |
358 | 377 | if (self::allow_account_edit($user)) |
@@ -422,12 +441,22 @@ discard block |
||
422 | 441 | } |
423 | 442 | foreach($ids as $key => $id) |
424 | 443 | { |
425 | - if (!is_numeric($id)) unset($ids[$key]); |
|
444 | + if (!is_numeric($id)) |
|
445 | + { |
|
446 | + unset($ids[$key]); |
|
447 | + } |
|
448 | + } |
|
449 | + if (!$ids) |
|
450 | + { |
|
451 | + return array(); |
|
426 | 452 | } |
427 | - if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
453 | + // nothing to do, eg. all these contacts are in ldap |
|
428 | 454 | $fields = array(); |
429 | 455 | $filter[$this->distri_id]=$ids; |
430 | - if (count($dl_allowed)) $filter[$this->distri_key]=$dl_allowed; |
|
456 | + if (count($dl_allowed)) |
|
457 | + { |
|
458 | + $filter[$this->distri_key]=$dl_allowed; |
|
459 | + } |
|
431 | 460 | $distri_view = str_replace(') d_view',' and '.$this->distri_id.' in ('.implode(',',$ids).')) d_view',$this->distributionlist_view); |
432 | 461 | #_debug_array($this->distributionlist_tabledef); |
433 | 462 | foreach($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
@@ -477,10 +506,16 @@ discard block |
||
477 | 506 | */ |
478 | 507 | function delete($contact,$check_etag=null) |
479 | 508 | { |
480 | - if (is_array($contact)) $contact = $contact['id']; |
|
509 | + if (is_array($contact)) |
|
510 | + { |
|
511 | + $contact = $contact['id']; |
|
512 | + } |
|
481 | 513 | |
482 | 514 | $where = array('id' => $contact); |
483 | - if ($check_etag) $where['etag'] = $check_etag; |
|
515 | + if ($check_etag) |
|
516 | + { |
|
517 | + $where['etag'] = $check_etag; |
|
518 | + } |
|
484 | 519 | |
485 | 520 | // delete mainfields |
486 | 521 | if ($this->somain->delete($where)) |
@@ -556,7 +591,10 @@ discard block |
||
556 | 591 | } |
557 | 592 | } |
558 | 593 | } |
559 | - if($error_nr) return $error_nr; |
|
594 | + if($error_nr) |
|
595 | + { |
|
596 | + return $error_nr; |
|
597 | + } |
|
560 | 598 | |
561 | 599 | return false; // no error |
562 | 600 | } |
@@ -580,7 +618,10 @@ discard block |
||
580 | 618 | return $contact; |
581 | 619 | } |
582 | 620 | $dl_list=$this->read_distributionlist(array($contact['id'])); |
583 | - if (count($dl_list)) $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
621 | + if (count($dl_list)) |
|
622 | + { |
|
623 | + $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
624 | + } |
|
584 | 625 | return $this->db2data($contact); |
585 | 626 | } |
586 | 627 | |
@@ -614,7 +655,10 @@ discard block |
||
614 | 655 | unset($filter['adr_one_countrycode']); |
615 | 656 | } |
616 | 657 | // Hide deleted items unless type is specifically deleted |
617 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
658 | + if(!is_array($filter)) |
|
659 | + { |
|
660 | + $filter = $filter ? (array) $filter : array(); |
|
661 | + } |
|
618 | 662 | |
619 | 663 | if (isset($filter['cols_to_search'])) |
620 | 664 | { |
@@ -625,10 +669,13 @@ discard block |
||
625 | 669 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
626 | 670 | if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
627 | 671 | { |
628 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
672 | + if ($join && strpos($join,'RIGHT JOIN') !== false) |
|
673 | + { |
|
674 | + // used eg. to search for groups |
|
629 | 675 | { |
630 | 676 | $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
631 | 677 | } |
678 | + } |
|
632 | 679 | else |
633 | 680 | { |
634 | 681 | $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
@@ -676,7 +723,10 @@ discard block |
||
676 | 723 | unset($cols[$key]); |
677 | 724 | } |
678 | 725 | } |
679 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
726 | + if ($col=='contact_id') |
|
727 | + { |
|
728 | + $col='egw_addressbook.contact_id'; |
|
729 | + } |
|
680 | 730 | } |
681 | 731 | |
682 | 732 | $backend->columns_to_search = $cols; |
@@ -751,7 +801,11 @@ discard block |
||
751 | 801 | { |
752 | 802 | foreach($this->columns_to_search as $col) |
753 | 803 | { |
754 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
804 | + if ($col != 'contact_value') |
|
805 | + { |
|
806 | + $param['search'][$col] = $search; |
|
807 | + } |
|
808 | + // we dont search the customfields |
|
755 | 809 | } |
756 | 810 | } |
757 | 811 | } |
@@ -771,11 +825,17 @@ discard block |
||
771 | 825 | $rows = $this->somain->organisations($param); |
772 | 826 | $this->total = $this->somain->total; |
773 | 827 | |
774 | - if (!$rows) return array(); |
|
828 | + if (!$rows) |
|
829 | + { |
|
830 | + return array(); |
|
831 | + } |
|
775 | 832 | |
776 | 833 | foreach($rows as $n => $row) |
777 | 834 | { |
778 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
835 | + if (strpos($row['org_name'],'&')!==false) |
|
836 | + { |
|
837 | + $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
838 | + } |
|
779 | 839 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
780 | 840 | foreach(array( |
781 | 841 | 'org_unit' => lang('departments'), |
@@ -788,7 +848,10 @@ discard block |
||
788 | 848 | } |
789 | 849 | else |
790 | 850 | { |
791 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
851 | + if (strpos($row[$by],'&')!==false) |
|
852 | + { |
|
853 | + $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
854 | + } |
|
792 | 855 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
793 | 856 | } |
794 | 857 | } |
@@ -848,7 +911,10 @@ discard block |
||
848 | 911 | */ |
849 | 912 | function get_backend($keys=null,$owner=null) |
850 | 913 | { |
851 | - if ($owner === '') $owner = null; |
|
914 | + if ($owner === '') |
|
915 | + { |
|
916 | + $owner = null; |
|
917 | + } |
|
852 | 918 | |
853 | 919 | $contact_id = !is_array($keys) ? $keys : |
854 | 920 | (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
@@ -912,7 +978,10 @@ discard block |
||
912 | 978 | $ds = $GLOBALS['egw']->ldap->ldapConnect(); |
913 | 979 | $ldap_contacts = new Ldap(null, $ds); |
914 | 980 | |
915 | - if (!is_array($type)) $type = explode(',', $type); |
|
981 | + if (!is_array($type)) |
|
982 | + { |
|
983 | + $type = explode(',', $type); |
|
984 | + } |
|
916 | 985 | |
917 | 986 | $start = $n = 0; |
918 | 987 | $num = 100; |
@@ -928,7 +997,10 @@ discard block |
||
928 | 997 | { |
929 | 998 | foreach($contacts as $contact) |
930 | 999 | { |
931 | - if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
1000 | + if ($contact['account_id']) |
|
1001 | + { |
|
1002 | + $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
1003 | + } |
|
932 | 1004 | |
933 | 1005 | $ldap_contacts->data = $contact; |
934 | 1006 | $n++; |
@@ -956,10 +1028,13 @@ discard block |
||
956 | 1028 | false, $filter) as $contact) |
957 | 1029 | { |
958 | 1030 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
959 | - if ($contact['jpegphoto']) // photo is NOT read by LDAP backend on search, need to do an extra read |
|
1031 | + if ($contact['jpegphoto']) |
|
1032 | + { |
|
1033 | + // photo is NOT read by LDAP backend on search, need to do an extra read |
|
960 | 1034 | { |
961 | 1035 | $contact = $ldap_contacts->read($contact['id']); |
962 | 1036 | } |
1037 | + } |
|
963 | 1038 | $old_contact_id = $contact['id']; |
964 | 1039 | unset($contact['id']); // ldap uid/account_lid |
965 | 1040 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
@@ -1020,7 +1095,10 @@ discard block |
||
1020 | 1095 | foreach($this->grants as $uid => $rights) |
1021 | 1096 | { |
1022 | 1097 | // only requests groups / list in accounts addressbook for read |
1023 | - if (!$uid && $required != Api\Acl::READ) continue; |
|
1098 | + if (!$uid && $required != Api\Acl::READ) |
|
1099 | + { |
|
1100 | + continue; |
|
1101 | + } |
|
1024 | 1102 | |
1025 | 1103 | if (($rights & $required) == $required) |
1026 | 1104 | { |
@@ -1060,7 +1138,10 @@ discard block |
||
1060 | 1138 | function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
1061 | 1139 | { |
1062 | 1140 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1063 | - if (!method_exists($backend, 'get_lists')) return false; |
|
1141 | + if (!method_exists($backend, 'get_lists')) |
|
1142 | + { |
|
1143 | + return false; |
|
1144 | + } |
|
1064 | 1145 | |
1065 | 1146 | return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
1066 | 1147 | } |
@@ -1077,7 +1158,10 @@ discard block |
||
1077 | 1158 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
1078 | 1159 | { |
1079 | 1160 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1080 | - if (!method_exists($backend, 'add_list')) return false; |
|
1161 | + if (!method_exists($backend, 'add_list')) |
|
1162 | + { |
|
1163 | + return false; |
|
1164 | + } |
|
1081 | 1165 | |
1082 | 1166 | return $backend->add_list($keys,$owner,$contacts,$data); |
1083 | 1167 | } |
@@ -1092,7 +1176,10 @@ discard block |
||
1092 | 1176 | */ |
1093 | 1177 | function add2list($contact,$list,array $existing=null) |
1094 | 1178 | { |
1095 | - if (!method_exists($this->somain,'add2list')) return false; |
|
1179 | + if (!method_exists($this->somain,'add2list')) |
|
1180 | + { |
|
1181 | + return false; |
|
1182 | + } |
|
1096 | 1183 | |
1097 | 1184 | return $this->somain->add2list($contact,$list,$existing); |
1098 | 1185 | } |
@@ -1106,7 +1193,10 @@ discard block |
||
1106 | 1193 | */ |
1107 | 1194 | function remove_from_list($contact,$list=null) |
1108 | 1195 | { |
1109 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
1196 | + if (!method_exists($this->somain,'remove_from_list')) |
|
1197 | + { |
|
1198 | + return false; |
|
1199 | + } |
|
1110 | 1200 | |
1111 | 1201 | return $this->somain->remove_from_list($contact,$list); |
1112 | 1202 | } |
@@ -1119,7 +1209,10 @@ discard block |
||
1119 | 1209 | */ |
1120 | 1210 | function delete_list($list) |
1121 | 1211 | { |
1122 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
1212 | + if (!method_exists($this->somain,'delete_list')) |
|
1213 | + { |
|
1214 | + return false; |
|
1215 | + } |
|
1123 | 1216 | |
1124 | 1217 | return $this->somain->delete_list($list); |
1125 | 1218 | } |
@@ -1132,7 +1225,10 @@ discard block |
||
1132 | 1225 | */ |
1133 | 1226 | function read_list($list) |
1134 | 1227 | { |
1135 | - if (!method_exists($this->somain,'read_list')) return false; |
|
1228 | + if (!method_exists($this->somain,'read_list')) |
|
1229 | + { |
|
1230 | + return false; |
|
1231 | + } |
|
1136 | 1232 | |
1137 | 1233 | return $this->somain->read_list($list); |
1138 | 1234 | } |
@@ -1158,7 +1254,10 @@ discard block |
||
1158 | 1254 | */ |
1159 | 1255 | function lists_ctag($owner=null) |
1160 | 1256 | { |
1161 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
1257 | + if (!method_exists($this->somain,'lists_ctag')) |
|
1258 | + { |
|
1259 | + return 0; |
|
1260 | + } |
|
1162 | 1261 | |
1163 | 1262 | return $this->somain->lists_ctag($owner); |
1164 | 1263 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @var string |
70 | 70 | */ |
71 | - var $distributionlist_view ='(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
|
71 | + var $distributionlist_view = '(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
|
72 | 72 | var $distributionlist_tabledef = array(); |
73 | 73 | /** |
74 | 74 | * @var string |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | * In SQL we can search all columns, though a view make on real sense |
123 | 123 | */ |
124 | 124 | var $sql_cols_not_to_search = array( |
125 | - 'jpegphoto','owner','tid','private','cat_id','etag', |
|
126 | - 'modified','modifier','creator','created','tz','account_id', |
|
127 | - 'uid','carddav_name','freebusy_uri','calendar_uri', |
|
128 | - 'geo','pubkey', |
|
125 | + 'jpegphoto', 'owner', 'tid', 'private', 'cat_id', 'etag', |
|
126 | + 'modified', 'modifier', 'creator', 'created', 'tz', 'account_id', |
|
127 | + 'uid', 'carddav_name', 'freebusy_uri', 'calendar_uri', |
|
128 | + 'geo', 'pubkey', |
|
129 | 129 | ); |
130 | 130 | /** |
131 | 131 | * columns to search, if we search for a single pattern |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | * @param string $contact_app ='addressbook' used for acl->get_grants() |
206 | 206 | * @param Api\Db $db =null |
207 | 207 | */ |
208 | - function __construct($contact_app='addressbook',Api\Db $db=null) |
|
208 | + function __construct($contact_app = 'addressbook', Api\Db $db = null) |
|
209 | 209 | { |
210 | - $this->db = is_null($db) ? $GLOBALS['egw']->db : $db; |
|
210 | + $this->db = is_null($db) ? $GLOBALS['egw']->db : $db; |
|
211 | 211 | |
212 | 212 | $this->user = $GLOBALS['egw_info']['user']['account_id']; |
213 | - $this->memberships = $GLOBALS['egw']->accounts->memberships($this->user,true); |
|
213 | + $this->memberships = $GLOBALS['egw']->accounts->memberships($this->user, true); |
|
214 | 214 | |
215 | 215 | // account backend used |
216 | 216 | if ($GLOBALS['egw_info']['server']['account_repository']) |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | } |
224 | 224 | $this->customfields = Api\Storage\Customfields::get('addressbook'); |
225 | 225 | // contacts backend (contacts in LDAP require accounts in LDAP!) |
226 | - if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
226 | + if ($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
227 | 227 | { |
228 | 228 | $this->contact_repository = 'ldap'; |
229 | 229 | $this->somain = new Ldap(); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $this->somain = new Sql($db); |
239 | 239 | |
240 | 240 | // remove some columns, absolutly not necessary to search in sql |
241 | - $this->columns_to_search = array_diff(array_values($this->somain->db_cols),$this->sql_cols_not_to_search); |
|
241 | + $this->columns_to_search = array_diff(array_values($this->somain->db_cols), $this->sql_cols_not_to_search); |
|
242 | 242 | if ($this->customfields) // add custom fields, if configured |
243 | 243 | { |
244 | 244 | $this->columns_to_search[] = Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE; |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | } |
247 | 247 | if ($this->user) |
248 | 248 | { |
249 | - $this->grants = $this->get_grants($this->user,$contact_app); |
|
249 | + $this->grants = $this->get_grants($this->user, $contact_app); |
|
250 | 250 | } |
251 | 251 | if ($this->account_repository != 'sql' && $this->contact_repository == 'sql') |
252 | 252 | { |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | } |
264 | 264 | if ($this->contact_repository == 'sql' || $this->contact_repository == 'sql-ldap') |
265 | 265 | { |
266 | - $tda2list = $this->db->get_table_definitions('api','egw_addressbook2list'); |
|
267 | - $tdlists = $this->db->get_table_definitions('api','egw_addressbook_lists'); |
|
266 | + $tda2list = $this->db->get_table_definitions('api', 'egw_addressbook2list'); |
|
267 | + $tdlists = $this->db->get_table_definitions('api', 'egw_addressbook_lists'); |
|
268 | 268 | $this->distributionlist_tabledef = array('fd' => array( |
269 | 269 | $this->distri_id => $tda2list['fd'][$this->distri_id], |
270 | 270 | $this->distri_owner => $tdlists['fd'][$this->distri_owner], |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | ); |
275 | 275 | } |
276 | 276 | // ToDo: it should be the other way arround, the backend should set the grants it uses |
277 | - $this->somain->grants =& $this->grants; |
|
277 | + $this->somain->grants = & $this->grants; |
|
278 | 278 | |
279 | - if($this->somain instanceof Sql) |
|
279 | + if ($this->somain instanceof Sql) |
|
280 | 280 | { |
281 | - $this->soextra =& $this->somain; |
|
281 | + $this->soextra = & $this->somain; |
|
282 | 282 | } |
283 | 283 | else |
284 | 284 | { |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | |
299 | 299 | // Add in deleted type, if holding deleted contacts |
300 | 300 | $config = Api\Config::read('phpgwapi'); |
301 | - if($config['history']) |
|
301 | + if ($config['history']) |
|
302 | 302 | { |
303 | 303 | $this->content_types[self::DELETED_TYPE] = array( |
304 | 304 | 'name' => lang('Deleted'), |
@@ -317,18 +317,18 @@ discard block |
||
317 | 317 | * @param string $contact_app ='addressbook' |
318 | 318 | * @return array |
319 | 319 | */ |
320 | - function get_grants($user, $contact_app='addressbook', $preferences=null) |
|
320 | + function get_grants($user, $contact_app = 'addressbook', $preferences = null) |
|
321 | 321 | { |
322 | 322 | if (!isset($preferences)) $preferences = $GLOBALS['egw_info']['user']['preferences']; |
323 | 323 | |
324 | 324 | if ($user) |
325 | 325 | { |
326 | 326 | // contacts backend (contacts in LDAP require accounts in LDAP!) |
327 | - if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
327 | + if ($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
328 | 328 | { |
329 | 329 | // static grants from ldap: all rights for the own personal addressbook and the group ones of the meberships |
330 | 330 | $grants = array($user => ~0); |
331 | - foreach($GLOBALS['egw']->accounts->memberships($user,true) as $gid) |
|
331 | + foreach ($GLOBALS['egw']->accounts->memberships($user, true) as $gid) |
|
332 | 332 | { |
333 | 333 | $grants[$gid] = ~0; |
334 | 334 | } |
@@ -337,22 +337,22 @@ discard block |
||
337 | 337 | { |
338 | 338 | // group grants are now grants for the group addressbook and NOT grants for all its members, |
339 | 339 | // therefor the param false! |
340 | - $grants = $GLOBALS['egw']->acl->get_grants($contact_app,false,$user); |
|
340 | + $grants = $GLOBALS['egw']->acl->get_grants($contact_app, false, $user); |
|
341 | 341 | } |
342 | 342 | // add grants for accounts: if account_selection not in ('none','groupmembers'): everyone has read access, |
343 | 343 | // if he has not set the hide_accounts preference |
344 | 344 | // ToDo: be more specific for 'groupmembers', they should be able to see the groupmembers |
345 | - if (!in_array($preferences['common']['account_selection'], array('none','groupmembers'))) |
|
345 | + if (!in_array($preferences['common']['account_selection'], array('none', 'groupmembers'))) |
|
346 | 346 | { |
347 | 347 | $grants[0] = Api\Acl::READ; |
348 | 348 | } |
349 | 349 | // add account grants for admins (only for current user!) |
350 | 350 | if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL! |
351 | 351 | { |
352 | - $grants[0] = Api\Acl::READ; // admins always have read-access |
|
353 | - if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= Api\Acl::EDIT; |
|
354 | - if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) $grants[0] |= Api\Acl::ADD; |
|
355 | - if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) $grants[0] |= Api\Acl::DELETE; |
|
352 | + $grants[0] = Api\Acl::READ; // admins always have read-access |
|
353 | + if (!$GLOBALS['egw']->acl->check('account_access', 16, 'admin')) $grants[0] |= Api\Acl::EDIT; |
|
354 | + if (!$GLOBALS['egw']->acl->check('account_access', 4, 'admin')) $grants[0] |= Api\Acl::ADD; |
|
355 | + if (!$GLOBALS['egw']->acl->check('account_access', 32, 'admin')) $grants[0] |= Api\Acl::DELETE; |
|
356 | 356 | } |
357 | 357 | // allow certain groups to edit contact-data of accounts |
358 | 358 | if (self::allow_account_edit($user)) |
@@ -376,11 +376,11 @@ discard block |
||
376 | 376 | * @param array $contact =null for future use, where admins might not be admins for all accounts |
377 | 377 | * @return boolean |
378 | 378 | */ |
379 | - function is_admin($contact=null) |
|
379 | + function is_admin($contact = null) |
|
380 | 380 | { |
381 | - unset($contact); // not (yet) used |
|
381 | + unset($contact); // not (yet) used |
|
382 | 382 | |
383 | - return isset($GLOBALS['egw_info']['user']['apps']['admin']) && !$GLOBALS['egw']->acl->check('account_access',16,'admin'); |
|
383 | + return isset($GLOBALS['egw_info']['user']['apps']['admin']) && !$GLOBALS['egw']->acl->check('account_access', 16, 'admin'); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * @param int $user =null default $this->user |
390 | 390 | * @return boolean |
391 | 391 | */ |
392 | - function allow_account_edit($user=null) |
|
392 | + function allow_account_edit($user = null) |
|
393 | 393 | { |
394 | 394 | return $GLOBALS['egw_info']['server']['allow_account_edit'] && |
395 | 395 | array_intersect($GLOBALS['egw_info']['server']['allow_account_edit'], |
@@ -403,9 +403,9 @@ discard block |
||
403 | 403 | * @param array $field_names =null custom fields to read, default all |
404 | 404 | * @return array id => name => value |
405 | 405 | */ |
406 | - function read_customfields($ids,$field_names=null) |
|
406 | + function read_customfields($ids, $field_names = null) |
|
407 | 407 | { |
408 | - return $this->soextra->read_customfields($ids,$field_names); |
|
408 | + return $this->soextra->read_customfields($ids, $field_names); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -414,26 +414,26 @@ discard block |
||
414 | 414 | * @param int|array $ids |
415 | 415 | * @return array id => name => value |
416 | 416 | */ |
417 | - function read_distributionlist($ids, $dl_allowed=array()) |
|
417 | + function read_distributionlist($ids, $dl_allowed = array()) |
|
418 | 418 | { |
419 | 419 | if ($this->contact_repository == 'ldap') |
420 | 420 | { |
421 | - return array(); // ldap does not support distributionlists |
|
421 | + return array(); // ldap does not support distributionlists |
|
422 | 422 | } |
423 | - foreach($ids as $key => $id) |
|
423 | + foreach ($ids as $key => $id) |
|
424 | 424 | { |
425 | 425 | if (!is_numeric($id)) unset($ids[$key]); |
426 | 426 | } |
427 | - if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
427 | + if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
428 | 428 | $fields = array(); |
429 | - $filter[$this->distri_id]=$ids; |
|
430 | - if (count($dl_allowed)) $filter[$this->distri_key]=$dl_allowed; |
|
431 | - $distri_view = str_replace(') d_view',' and '.$this->distri_id.' in ('.implode(',',$ids).')) d_view',$this->distributionlist_view); |
|
429 | + $filter[$this->distri_id] = $ids; |
|
430 | + if (count($dl_allowed)) $filter[$this->distri_key] = $dl_allowed; |
|
431 | + $distri_view = str_replace(') d_view', ' and '.$this->distri_id.' in ('.implode(',', $ids).')) d_view', $this->distributionlist_view); |
|
432 | 432 | #_debug_array($this->distributionlist_tabledef); |
433 | - foreach($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
|
433 | + foreach ($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
|
434 | 434 | false, 'ORDER BY '.$this->distri_id, false, 0, '', $this->distributionlist_tabledef) as $row) |
435 | 435 | { |
436 | - if ((isset($row[$this->distri_id])&&strlen($row[$this->distri_value])>0)) |
|
436 | + if ((isset($row[$this->distri_id]) && strlen($row[$this->distri_value]) > 0)) |
|
437 | 437 | { |
438 | 438 | $fields[$row[$this->distri_id]][$row[$this->distri_key]] = $row[$this->distri_value].' ('. |
439 | 439 | Api\Accounts::username($row[$this->distri_owner]).')'; |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | * @param int $check_etag =null |
476 | 476 | * @return boolean|int true on success or false on failiure, 0 if etag does not match |
477 | 477 | */ |
478 | - function delete($contact,$check_etag=null) |
|
478 | + function delete($contact, $check_etag = null) |
|
479 | 479 | { |
480 | 480 | if (is_array($contact)) $contact = $contact['id']; |
481 | 481 | |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | if ($this->somain->delete($where)) |
487 | 487 | { |
488 | 488 | // delete customfields, can return 0 if there are no customfields |
489 | - if(!($this->somain instanceof Sql)) |
|
489 | + if (!($this->somain instanceof Sql)) |
|
490 | 490 | { |
491 | 491 | $this->soextra->delete_customfields(array($this->extra_id => $contact)); |
492 | 492 | } |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | } |
507 | 507 | return true; |
508 | 508 | } |
509 | - return $check_etag ? 0 : false; // if etag given, we return 0 on failure, thought it could also mean the whole contact does not exist |
|
509 | + return $check_etag ? 0 : false; // if etag given, we return 0 on failure, thought it could also mean the whole contact does not exist |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -556,9 +556,9 @@ discard block |
||
556 | 556 | } |
557 | 557 | } |
558 | 558 | } |
559 | - if($error_nr) return $error_nr; |
|
559 | + if ($error_nr) return $error_nr; |
|
560 | 560 | |
561 | - return false; // no error |
|
561 | + return false; // no error |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | /** |
@@ -569,18 +569,18 @@ discard block |
||
569 | 569 | */ |
570 | 570 | function read($contact_id) |
571 | 571 | { |
572 | - if (!is_array($contact_id) && substr($contact_id,0,8) == 'account:') |
|
572 | + if (!is_array($contact_id) && substr($contact_id, 0, 8) == 'account:') |
|
573 | 573 | { |
574 | - $contact_id = array('account_id' => (int) substr($contact_id,8)); |
|
574 | + $contact_id = array('account_id' => (int)substr($contact_id, 8)); |
|
575 | 575 | } |
576 | 576 | // read main data |
577 | - $backend =& $this->get_backend($contact_id); |
|
577 | + $backend = & $this->get_backend($contact_id); |
|
578 | 578 | if (!($contact = $backend->read($contact_id))) |
579 | 579 | { |
580 | 580 | return $contact; |
581 | 581 | } |
582 | - $dl_list=$this->read_distributionlist(array($contact['id'])); |
|
583 | - if (count($dl_list)) $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
582 | + $dl_list = $this->read_distributionlist(array($contact['id'])); |
|
583 | + if (count($dl_list)) $contact['distrib_lists'] = implode("\n", $dl_list[$contact['id']]); |
|
584 | 584 | return $this->db2data($contact); |
585 | 585 | } |
586 | 586 | |
@@ -603,18 +603,18 @@ discard block |
||
603 | 603 | * @param boolean $ignore_acl =false true: no acl check |
604 | 604 | * @return array of matching rows (the row is an array of the cols) or False |
605 | 605 | */ |
606 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='', $ignore_acl=false) |
|
606 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $ignore_acl = false) |
|
607 | 607 | { |
608 | 608 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',".array2string($start).','.array2string($filter,true).",'$join')"); |
609 | 609 | |
610 | 610 | // Handle 'None' country option |
611 | - if(is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
611 | + if (is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
612 | 612 | { |
613 | 613 | $filter[] = 'adr_one_countrycode IS NULL'; |
614 | 614 | unset($filter['adr_one_countrycode']); |
615 | 615 | } |
616 | 616 | // Hide deleted items unless type is specifically deleted |
617 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
617 | + if (!is_array($filter)) $filter = $filter ? (array)$filter : array(); |
|
618 | 618 | |
619 | 619 | if (isset($filter['cols_to_search'])) |
620 | 620 | { |
@@ -623,22 +623,22 @@ discard block |
||
623 | 623 | } |
624 | 624 | |
625 | 625 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
626 | - if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
626 | + if (!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
627 | 627 | { |
628 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
628 | + if ($join && strpos($join, 'RIGHT JOIN') !== false) // used eg. to search for groups |
|
629 | 629 | { |
630 | - $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
|
630 | + $filter[] = '(contact_tid != \''.self::DELETED_TYPE.'\' OR contact_tid IS NULL)'; |
|
631 | 631 | } |
632 | 632 | else |
633 | 633 | { |
634 | - $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
634 | + $filter[] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
635 | 635 | } |
636 | 636 | } |
637 | - elseif(is_null($filter['tid'])) |
|
637 | + elseif (is_null($filter['tid'])) |
|
638 | 638 | { |
639 | - unset($filter['tid']); // return all entries incl. deleted |
|
639 | + unset($filter['tid']); // return all entries incl. deleted |
|
640 | 640 | } |
641 | - $backend = $this->get_backend(null,$filter['owner']); |
|
641 | + $backend = $this->get_backend(null, $filter['owner']); |
|
642 | 642 | // single string to search for --> create so_sql conformant search criterial for the standard search columns |
643 | 643 | if ($criteria && !is_array($criteria)) |
644 | 644 | { |
@@ -659,34 +659,34 @@ discard block |
||
659 | 659 | { |
660 | 660 | $cols = $this->account_cols_to_search; |
661 | 661 | } |
662 | - if($backend instanceof Sql) |
|
662 | + if ($backend instanceof Sql) |
|
663 | 663 | { |
664 | 664 | // Keep a string, let the parent handle it |
665 | 665 | $criteria = $search; |
666 | 666 | |
667 | - foreach($cols as $key => &$col) |
|
667 | + foreach ($cols as $key => &$col) |
|
668 | 668 | { |
669 | - if($col != Sql::EXTRA_VALUE && |
|
669 | + if ($col != Sql::EXTRA_VALUE && |
|
670 | 670 | $col != Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE && |
671 | 671 | !array_key_exists($col, $backend->db_cols)) |
672 | 672 | { |
673 | - if(!($col = array_search($col, $backend->db_cols))) |
|
673 | + if (!($col = array_search($col, $backend->db_cols))) |
|
674 | 674 | { |
675 | 675 | // Can't search this column, it will error if we try |
676 | 676 | unset($cols[$key]); |
677 | 677 | } |
678 | 678 | } |
679 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
679 | + if ($col == 'contact_id') $col = 'egw_addressbook.contact_id'; |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | $backend->columns_to_search = $cols; |
683 | 683 | } |
684 | 684 | else |
685 | 685 | { |
686 | - foreach($cols as $col) |
|
686 | + foreach ($cols as $col) |
|
687 | 687 | { |
688 | 688 | // remove from LDAP backend not understood use-AND-syntax |
689 | - $criteria[$col] = str_replace(' +',' ',$search); |
|
689 | + $criteria[$col] = str_replace(' +', ' ', $search); |
|
690 | 690 | } |
691 | 691 | } |
692 | 692 | } |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | |
711 | 711 | if ($rows) |
712 | 712 | { |
713 | - foreach($rows as $n => $row) |
|
713 | + foreach ($rows as $n => $row) |
|
714 | 714 | { |
715 | 715 | $rows[$n] = $this->db2data($row); |
716 | 716 | } |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | */ |
734 | 734 | function organisations($param) |
735 | 735 | { |
736 | - if (!method_exists($this->somain,'organisations')) |
|
736 | + if (!method_exists($this->somain, 'organisations')) |
|
737 | 737 | { |
738 | 738 | $this->total = 0; |
739 | 739 | return false; |
@@ -742,16 +742,16 @@ discard block |
||
742 | 742 | { |
743 | 743 | $search = $param['search']; |
744 | 744 | $param['search'] = array(); |
745 | - if($this->somain instanceof Sql) |
|
745 | + if ($this->somain instanceof Sql) |
|
746 | 746 | { |
747 | 747 | // Keep the string, let the parent deal with it |
748 | 748 | $param['search'] = $search; |
749 | 749 | } |
750 | 750 | else |
751 | 751 | { |
752 | - foreach($this->columns_to_search as $col) |
|
752 | + foreach ($this->columns_to_search as $col) |
|
753 | 753 | { |
754 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
754 | + if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
755 | 755 | } |
756 | 756 | } |
757 | 757 | } |
@@ -759,13 +759,13 @@ discard block |
||
759 | 759 | { |
760 | 760 | $param['search'] = $this->data2db($param['search']); |
761 | 761 | } |
762 | - if(!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
762 | + if (!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
763 | 763 | { |
764 | - $param['col_filter'][] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
764 | + $param['col_filter'][] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
765 | 765 | } |
766 | - elseif(is_null($param['col_filter']['tid'])) |
|
766 | + elseif (is_null($param['col_filter']['tid'])) |
|
767 | 767 | { |
768 | - unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
768 | + unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | $rows = $this->somain->organisations($param); |
@@ -773,11 +773,11 @@ discard block |
||
773 | 773 | |
774 | 774 | if (!$rows) return array(); |
775 | 775 | |
776 | - foreach($rows as $n => $row) |
|
776 | + foreach ($rows as $n => $row) |
|
777 | 777 | { |
778 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
778 | + if (strpos($row['org_name'], '&') !== false) $row['org_name'] = str_replace('&', '*AND*', $row['org_name']); |
|
779 | 779 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
780 | - foreach(array( |
|
780 | + foreach (array( |
|
781 | 781 | 'org_unit' => lang('departments'), |
782 | 782 | 'adr_one_locality' => lang('locations'), |
783 | 783 | ) as $by => $by_label) |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | } |
789 | 789 | else |
790 | 790 | { |
791 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
791 | + if (strpos($row[$by], '&') !== false) $row[$by] = str_replace('&', '*AND*', $row[$by]); |
|
792 | 792 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
793 | 793 | } |
794 | 794 | } |
@@ -821,11 +821,11 @@ discard block |
||
821 | 821 | function deleteaccount($data) |
822 | 822 | { |
823 | 823 | $account_id = $data['account_id']; |
824 | - $new_owner = $data['new_owner']; |
|
824 | + $new_owner = $data['new_owner']; |
|
825 | 825 | |
826 | 826 | if (!$new_owner) |
827 | 827 | { |
828 | - $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
828 | + $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
829 | 829 | |
830 | 830 | if (method_exists($this->somain, 'get_lists') && |
831 | 831 | ($lists = $this->somain->get_lists($account_id))) |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | } |
836 | 836 | else |
837 | 837 | { |
838 | - $this->somain->change_owner($account_id,$new_owner); |
|
838 | + $this->somain->change_owner($account_id, $new_owner); |
|
839 | 839 | } |
840 | 840 | } |
841 | 841 | |
@@ -846,16 +846,15 @@ discard block |
||
846 | 846 | * @param int $owner =null account_id of owner or 0 for accounts |
847 | 847 | * @return Sql |
848 | 848 | */ |
849 | - function get_backend($keys=null,$owner=null) |
|
849 | + function get_backend($keys = null, $owner = null) |
|
850 | 850 | { |
851 | 851 | if ($owner === '') $owner = null; |
852 | 852 | |
853 | - $contact_id = !is_array($keys) ? $keys : |
|
854 | - (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
853 | + $contact_id = !is_array($keys) ? $keys : (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
855 | 854 | |
856 | 855 | if ($this->contact_repository != $this->account_repository && is_object($this->so_accounts) && |
857 | 856 | (!is_null($owner) && !$owner || is_array($keys) && $keys['account_id'] || !is_null($contact_id) && |
858 | - ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id) )|| |
|
857 | + ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id)) || |
|
859 | 858 | $this->contact_repository == 'ldap' && is_numeric($contact_id)))) |
860 | 859 | { |
861 | 860 | return $this->so_accounts; |
@@ -871,28 +870,28 @@ discard block |
||
871 | 870 | * @param int $owner =null account_id of owner or 0 for accounts |
872 | 871 | * @return array with eGW contact field names |
873 | 872 | */ |
874 | - function get_fields($type='all',$contact_id=null,$owner=null) |
|
873 | + function get_fields($type = 'all', $contact_id = null, $owner = null) |
|
875 | 874 | { |
876 | - $def = $this->db->get_table_definitions('api','egw_addressbook'); |
|
875 | + $def = $this->db->get_table_definitions('api', 'egw_addressbook'); |
|
877 | 876 | |
878 | 877 | $all_fields = array(); |
879 | - foreach(array_keys($def['fd']) as $field) |
|
878 | + foreach (array_keys($def['fd']) as $field) |
|
880 | 879 | { |
881 | - $all_fields[] = substr($field,0,8) == 'contact_' ? substr($field,8) : $field; |
|
880 | + $all_fields[] = substr($field, 0, 8) == 'contact_' ? substr($field, 8) : $field; |
|
882 | 881 | } |
883 | 882 | if ($type == 'all') |
884 | 883 | { |
885 | 884 | return $all_fields; |
886 | 885 | } |
887 | - $backend =& $this->get_backend($contact_id,$owner); |
|
886 | + $backend = & $this->get_backend($contact_id, $owner); |
|
888 | 887 | |
889 | - $supported_fields = method_exists($backend,supported_fields) ? $backend->supported_fields() : $all_fields; |
|
888 | + $supported_fields = method_exists($backend, supported_fields) ? $backend->supported_fields() : $all_fields; |
|
890 | 889 | |
891 | 890 | if ($type == 'supported') |
892 | 891 | { |
893 | 892 | return $supported_fields; |
894 | 893 | } |
895 | - return array_diff($all_fields,$supported_fields); |
|
894 | + return array_diff($all_fields, $supported_fields); |
|
896 | 895 | } |
897 | 896 | |
898 | 897 | /** |
@@ -920,13 +919,12 @@ discard block |
||
920 | 919 | // direction SQL --> LDAP, either only accounts, or only contacts or both |
921 | 920 | if (($do = array_intersect($type, array('contacts', 'accounts')))) |
922 | 921 | { |
923 | - $filter = count($do) == 2 ? null : |
|
924 | - array($do[0] == 'contacts' ? 'contact_owner != 0' : 'contact_owner = 0'); |
|
922 | + $filter = count($do) == 2 ? null : array($do[0] == 'contacts' ? 'contact_owner != 0' : 'contact_owner = 0'); |
|
925 | 923 | |
926 | - while (($contacts = $sql_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
927 | - array($start,$num),$filter))) |
|
924 | + while (($contacts = $sql_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
925 | + array($start, $num), $filter))) |
|
928 | 926 | { |
929 | - foreach($contacts as $contact) |
|
927 | + foreach ($contacts as $contact) |
|
930 | 928 | { |
931 | 929 | if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
932 | 930 | |
@@ -947,12 +945,12 @@ discard block |
||
947 | 945 | } |
948 | 946 | } |
949 | 947 | // direction LDAP --> SQL: either "sql" (contacts and accounts) or "accounts-back" (only accounts) |
950 | - if (($do = array_intersect(array('accounts-back','sql'), $type))) |
|
948 | + if (($do = array_intersect(array('accounts-back', 'sql'), $type))) |
|
951 | 949 | { |
952 | 950 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)); |
953 | 951 | $filter = in_array('sql', $do) ? null : array('owner' => 0); |
954 | 952 | |
955 | - foreach($ldap_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
953 | + foreach ($ldap_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
956 | 954 | false, $filter) as $contact) |
957 | 955 | { |
958 | 956 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
@@ -961,7 +959,7 @@ discard block |
||
961 | 959 | $contact = $ldap_contacts->read($contact['id']); |
962 | 960 | } |
963 | 961 | $old_contact_id = $contact['id']; |
964 | - unset($contact['id']); // ldap uid/account_lid |
|
962 | + unset($contact['id']); // ldap uid/account_lid |
|
965 | 963 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
966 | 964 | { |
967 | 965 | $contact['id'] = $old['id']; |
@@ -973,24 +971,24 @@ discard block |
||
973 | 971 | { |
974 | 972 | echo '<p style="margin: 0px;">'.$n.': '.$contact['n_fn']. |
975 | 973 | ($contact['org_name'] ? ' ('.$contact['org_name'].')' : '')." --> SQL (". |
976 | - ($contact['owner']?lang('User'):lang('Contact')).")<br>\n"; |
|
974 | + ($contact['owner'] ? lang('User') : lang('Contact')).")<br>\n"; |
|
977 | 975 | |
978 | 976 | $new_contact_id = $sql_contacts->data['id']; |
979 | - echo " " . $old_contact_id . " --> " . $new_contact_id . " / "; |
|
977 | + echo " ".$old_contact_id." --> ".$new_contact_id." / "; |
|
980 | 978 | |
981 | - $tq = $this->db->update('egw_links',array( |
|
979 | + $tq = $this->db->update('egw_links', array( |
|
982 | 980 | 'link_id1' => $new_contact_id, |
983 | - ),array( |
|
981 | + ), array( |
|
984 | 982 | 'link_app1' => 'addressbook', |
985 | 983 | 'link_id1' => $old_contact_id |
986 | - ),__LINE__,__FILE__); |
|
984 | + ), __LINE__, __FILE__); |
|
987 | 985 | |
988 | - $tq = $this->db->update('egw_links',array( |
|
986 | + $tq = $this->db->update('egw_links', array( |
|
989 | 987 | 'link_id2' => $new_contact_id, |
990 | - ),array( |
|
988 | + ), array( |
|
991 | 989 | 'link_app2' => 'addressbook', |
992 | 990 | 'link_id2' => $old_contact_id |
993 | - ),__LINE__,__FILE__); |
|
991 | + ), __LINE__, __FILE__); |
|
994 | 992 | echo "</p>\n"; |
995 | 993 | } |
996 | 994 | else |
@@ -1010,25 +1008,25 @@ discard block |
||
1010 | 1008 | * @param string $extra_labels =null first labels if given (already translated) |
1011 | 1009 | * @return array with id => label pairs or false if backend does not support lists |
1012 | 1010 | */ |
1013 | - function get_lists($required=Api\Acl::READ,$extra_labels=null) |
|
1011 | + function get_lists($required = Api\Acl::READ, $extra_labels = null) |
|
1014 | 1012 | { |
1015 | 1013 | $lists = is_array($extra_labels) ? $extra_labels : array(); |
1016 | 1014 | |
1017 | - if (method_exists($this->somain,'get_lists')) |
|
1015 | + if (method_exists($this->somain, 'get_lists')) |
|
1018 | 1016 | { |
1019 | 1017 | $uids = array(); |
1020 | - foreach($this->grants as $uid => $rights) |
|
1018 | + foreach ($this->grants as $uid => $rights) |
|
1021 | 1019 | { |
1022 | 1020 | // only requests groups / list in accounts addressbook for read |
1023 | 1021 | if (!$uid && $required != Api\Acl::READ) continue; |
1024 | 1022 | |
1025 | - if (($rights & $required) == $required) |
|
1023 | + if (($rights&$required) == $required) |
|
1026 | 1024 | { |
1027 | 1025 | $uids[] = $uid; |
1028 | 1026 | } |
1029 | 1027 | } |
1030 | 1028 | |
1031 | - foreach($this->somain->get_lists($uids) as $list_id => $data) |
|
1029 | + foreach ($this->somain->get_lists($uids) as $list_id => $data) |
|
1032 | 1030 | { |
1033 | 1031 | $lists[$list_id] = $data['list_name']; |
1034 | 1032 | if ($data['list_owner'] != $this->user) |
@@ -1041,7 +1039,7 @@ discard block |
||
1041 | 1039 | // add groups for all backends, if accounts addressbook is not hidden |
1042 | 1040 | if (empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'])) |
1043 | 1041 | { |
1044 | - foreach($GLOBALS['egw']->accounts->search(array( |
|
1042 | + foreach ($GLOBALS['egw']->accounts->search(array( |
|
1045 | 1043 | 'type' => 'groups' |
1046 | 1044 | )) as $account_id => $group) |
1047 | 1045 | { |
@@ -1060,12 +1058,12 @@ discard block |
||
1060 | 1058 | * @param boolean $limit_in_ab =false if true only return members from the same owners addressbook |
1061 | 1059 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
1062 | 1060 | */ |
1063 | - function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
|
1061 | + function read_lists($keys, $member_attr = null, $limit_in_ab = false) |
|
1064 | 1062 | { |
1065 | 1063 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1066 | 1064 | if (!method_exists($backend, 'get_lists')) return false; |
1067 | 1065 | |
1068 | - return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
|
1066 | + return $backend->get_lists($keys, null, $member_attr, $limit_in_ab); |
|
1069 | 1067 | } |
1070 | 1068 | |
1071 | 1069 | /** |
@@ -1077,12 +1075,12 @@ discard block |
||
1077 | 1075 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
1078 | 1076 | * @return int|boolean integer list_id or false on error |
1079 | 1077 | */ |
1080 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
1078 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
1081 | 1079 | { |
1082 | 1080 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1083 | 1081 | if (!method_exists($backend, 'add_list')) return false; |
1084 | 1082 | |
1085 | - return $backend->add_list($keys,$owner,$contacts,$data); |
|
1083 | + return $backend->add_list($keys, $owner, $contacts, $data); |
|
1086 | 1084 | } |
1087 | 1085 | |
1088 | 1086 | /** |
@@ -1093,11 +1091,11 @@ discard block |
||
1093 | 1091 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
1094 | 1092 | * @return false on error |
1095 | 1093 | */ |
1096 | - function add2list($contact,$list,array $existing=null) |
|
1094 | + function add2list($contact, $list, array $existing = null) |
|
1097 | 1095 | { |
1098 | - if (!method_exists($this->somain,'add2list')) return false; |
|
1096 | + if (!method_exists($this->somain, 'add2list')) return false; |
|
1099 | 1097 | |
1100 | - return $this->somain->add2list($contact,$list,$existing); |
|
1098 | + return $this->somain->add2list($contact, $list, $existing); |
|
1101 | 1099 | } |
1102 | 1100 | |
1103 | 1101 | /** |
@@ -1107,11 +1105,11 @@ discard block |
||
1107 | 1105 | * @param int $list =null list-id or null to remove from all lists |
1108 | 1106 | * @return false on error |
1109 | 1107 | */ |
1110 | - function remove_from_list($contact,$list=null) |
|
1108 | + function remove_from_list($contact, $list = null) |
|
1111 | 1109 | { |
1112 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
1110 | + if (!method_exists($this->somain, 'remove_from_list')) return false; |
|
1113 | 1111 | |
1114 | - return $this->somain->remove_from_list($contact,$list); |
|
1112 | + return $this->somain->remove_from_list($contact, $list); |
|
1115 | 1113 | } |
1116 | 1114 | |
1117 | 1115 | /** |
@@ -1122,7 +1120,7 @@ discard block |
||
1122 | 1120 | */ |
1123 | 1121 | function delete_list($list) |
1124 | 1122 | { |
1125 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
1123 | + if (!method_exists($this->somain, 'delete_list')) return false; |
|
1126 | 1124 | |
1127 | 1125 | return $this->somain->delete_list($list); |
1128 | 1126 | } |
@@ -1135,7 +1133,7 @@ discard block |
||
1135 | 1133 | */ |
1136 | 1134 | function read_list($list) |
1137 | 1135 | { |
1138 | - if (!method_exists($this->somain,'read_list')) return false; |
|
1136 | + if (!method_exists($this->somain, 'read_list')) return false; |
|
1139 | 1137 | |
1140 | 1138 | return $this->somain->read_list($list); |
1141 | 1139 | } |
@@ -1146,11 +1144,11 @@ discard block |
||
1146 | 1144 | * @param int|string $owner ='' addressbook (eg. 0 = accounts), default '' = "all" addressbook (uses the main backend) |
1147 | 1145 | * @return boolean |
1148 | 1146 | */ |
1149 | - function lists_available($owner='') |
|
1147 | + function lists_available($owner = '') |
|
1150 | 1148 | { |
1151 | - $backend =& $this->get_backend(null,$owner); |
|
1149 | + $backend = & $this->get_backend(null, $owner); |
|
1152 | 1150 | |
1153 | - return method_exists($backend,'read_list'); |
|
1151 | + return method_exists($backend, 'read_list'); |
|
1154 | 1152 | } |
1155 | 1153 | |
1156 | 1154 | /** |
@@ -1159,9 +1157,9 @@ discard block |
||
1159 | 1157 | * @param int|array $owner =null null for all lists user has access too |
1160 | 1158 | * @return int |
1161 | 1159 | */ |
1162 | - function lists_ctag($owner=null) |
|
1160 | + function lists_ctag($owner = null) |
|
1163 | 1161 | { |
1164 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
1162 | + if (!method_exists($this->somain, 'lists_ctag')) return 0; |
|
1165 | 1163 | |
1166 | 1164 | return $this->somain->lists_ctag($owner); |
1167 | 1165 | } |
@@ -91,6 +91,7 @@ discard block |
||
91 | 91 | * array with values for keys('year','month','day') or 'full' plus 'hour','minute' and optional 'second' |
92 | 92 | * @param DateTimeZone $tz =null timezone, default user time (PHP DateTime default to server time!) |
93 | 93 | * @param string &$type=null on return type of $time (optional) |
94 | + * @param string $type |
|
94 | 95 | * @throws Exception if $time can NOT be parsed |
95 | 96 | */ |
96 | 97 | public function __construct($time='now',DateTimeZone $tz=null,&$type=null) |
@@ -573,7 +574,7 @@ discard block |
||
573 | 574 | * - return UTC and oceans at the end |
574 | 575 | * - if (user lang is a european language), move Europe to top |
575 | 576 | * |
576 | - * @return array continent|ocean => array(tz-name => tz-label incl. current time) |
|
577 | + * @return string continent|ocean => array(tz-name => tz-label incl. current time) |
|
577 | 578 | */ |
578 | 579 | public static function getTimezones() |
579 | 580 | { |
@@ -95,7 +95,11 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function __construct($time='now',DateTimeZone $tz=null,&$type=null) |
97 | 97 | { |
98 | - if (is_null($tz)) $tz = self::$user_timezone; // default user timezone |
|
98 | + if (is_null($tz)) |
|
99 | + { |
|
100 | + $tz = self::$user_timezone; |
|
101 | + } |
|
102 | + // default user timezone |
|
99 | 103 | |
100 | 104 | switch(($type = gettype($time))) |
101 | 105 | { |
@@ -108,7 +112,11 @@ discard block |
||
108 | 112 | if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000))) |
109 | 113 | { |
110 | 114 | $t_str = $time; |
111 | - if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date |
|
115 | + if (is_numeric($time) && strlen($time) == 8) |
|
116 | + { |
|
117 | + $t_str .= 'T000000'; |
|
118 | + } |
|
119 | + // 'Ymd' string used in calendar to represent a date |
|
112 | 120 | // $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself |
113 | 121 | try { |
114 | 122 | parent::__construct($t_str,$tz); |
@@ -116,7 +124,10 @@ discard block |
||
116 | 124 | } |
117 | 125 | catch(Exception $e) { |
118 | 126 | // if string is nummeric, ignore the exception and treat string as timestamp |
119 | - if (!is_numeric($time)) throw $e; |
|
127 | + if (!is_numeric($time)) |
|
128 | + { |
|
129 | + throw $e; |
|
130 | + } |
|
120 | 131 | } |
121 | 132 | } |
122 | 133 | $type = 'integer'; |
@@ -137,7 +148,9 @@ discard block |
||
137 | 148 | |
138 | 149 | case 'array': |
139 | 150 | parent::__construct('now',$tz); |
140 | - if (isset($time['Y'])) // array format used in eTemplate |
|
151 | + if (isset($time['Y'])) |
|
152 | + { |
|
153 | + // array format used in eTemplate |
|
141 | 154 | { |
142 | 155 | $time = array( |
143 | 156 | 'year' => $time['Y'], |
@@ -148,13 +161,17 @@ discard block |
||
148 | 161 | 'second' => $time['s'], |
149 | 162 | ); |
150 | 163 | } |
164 | + } |
|
151 | 165 | if (!empty($time['full']) && empty($time['year'])) |
152 | 166 | { |
153 | 167 | $time['year'] = (int)substr($time['full'],0,4); |
154 | 168 | $time['month'] = (int)substr($time['full'],4,2); |
155 | 169 | $time['day'] = (int)substr($time['full'],6,2); |
156 | 170 | } |
157 | - if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
171 | + if (isset($time['year'])) |
|
172 | + { |
|
173 | + $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
174 | + } |
|
158 | 175 | $this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']); |
159 | 176 | break; |
160 | 177 | |
@@ -178,7 +195,10 @@ discard block |
||
178 | 195 | */ |
179 | 196 | public function add($interval) |
180 | 197 | { |
181 | - if (is_string($interval)) $interval = DateInterval::createFromDateString($interval); |
|
198 | + if (is_string($interval)) |
|
199 | + { |
|
200 | + $interval = DateInterval::createFromDateString($interval); |
|
201 | + } |
|
182 | 202 | |
183 | 203 | parent::add($interval); |
184 | 204 | } |
@@ -202,7 +222,10 @@ discard block |
||
202 | 222 | $wstart = -($wday ? $wday-1 : 6); |
203 | 223 | break; |
204 | 224 | } |
205 | - if ($wstart) $this->add($wstart.'days'); |
|
225 | + if ($wstart) |
|
226 | + { |
|
227 | + $this->add($wstart.'days'); |
|
228 | + } |
|
206 | 229 | } |
207 | 230 | |
208 | 231 | /** |
@@ -263,15 +286,27 @@ discard block |
||
263 | 286 | } |
264 | 287 | elseif ($sday || $eday) |
265 | 288 | { |
266 | - if ($sday) $start->add($sday.'days'); |
|
267 | - if ($eday) $end->add($eday.'days'); |
|
289 | + if ($sday) |
|
290 | + { |
|
291 | + $start->add($sday.'days'); |
|
292 | + } |
|
293 | + if ($eday) |
|
294 | + { |
|
295 | + $end->add($eday.'days'); |
|
296 | + } |
|
268 | 297 | } |
269 | 298 | elseif ($sweek || $eweek) |
270 | 299 | { |
271 | 300 | $start->setWeekstart(); |
272 | - if ($sweek) $start->add($sweek.'weeks'); |
|
301 | + if ($sweek) |
|
302 | + { |
|
303 | + $start->add($sweek.'weeks'); |
|
304 | + } |
|
273 | 305 | $end->setWeekstart(); |
274 | - if ($eweek) $end->add($eweek.'weeks'); |
|
306 | + if ($eweek) |
|
307 | + { |
|
308 | + $end->add($eweek.'weeks'); |
|
309 | + } |
|
275 | 310 | } |
276 | 311 | } |
277 | 312 | // convert start + end from user to servertime for the filter |
@@ -416,7 +451,10 @@ discard block |
||
416 | 451 | } |
417 | 452 | $time->setUser(); |
418 | 453 | |
419 | - if (is_null($type)) $type = $typeof; |
|
454 | + if (is_null($type)) |
|
455 | + { |
|
456 | + $type = $typeof; |
|
457 | + } |
|
420 | 458 | |
421 | 459 | //echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n"; |
422 | 460 | return $time->format($type); |
@@ -446,7 +484,10 @@ discard block |
||
446 | 484 | } |
447 | 485 | $time->setServer(); |
448 | 486 | |
449 | - if (is_null($type)) $type = $typeof; |
|
487 | + if (is_null($type)) |
|
488 | + { |
|
489 | + $type = $typeof; |
|
490 | + } |
|
450 | 491 | |
451 | 492 | //echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n"; |
452 | 493 | return $time->format($type); |
@@ -489,7 +530,10 @@ discard block |
||
489 | 530 | public static function setUserPrefs($tz,$dateformat='',$timeformat='') |
490 | 531 | { |
491 | 532 | //echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n"; |
492 | - if (!empty($dateformat)) self::$user_dateformat = $dateformat; |
|
533 | + if (!empty($dateformat)) |
|
534 | + { |
|
535 | + self::$user_dateformat = $dateformat; |
|
536 | + } |
|
493 | 537 | |
494 | 538 | switch($timeformat) |
495 | 539 | { |
@@ -527,7 +571,10 @@ discard block |
||
527 | 571 | */ |
528 | 572 | public static function tz_offset_s($time='now') |
529 | 573 | { |
530 | - if (!($time instanceof DateTime)) $time = new DateTime($time); |
|
574 | + if (!($time instanceof DateTime)) |
|
575 | + { |
|
576 | + $time = new DateTime($time); |
|
577 | + } |
|
531 | 578 | |
532 | 579 | return self::$user_timezone->getOffset($time) - self::$server_timezone->getOffset($time); |
533 | 580 | } |
@@ -635,9 +682,17 @@ discard block |
||
635 | 682 | ); |
636 | 683 | foreach(DateTimeZone::listIdentifiers() as $name) |
637 | 684 | { |
638 | - if (in_array($name,$no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
685 | + if (in_array($name,$no_vtimezone)) |
|
686 | + { |
|
687 | + continue; |
|
688 | + } |
|
689 | + // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
639 | 690 | list($continent) = explode('/',$name,2); |
640 | - if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
691 | + if (!isset($tzs[$continent])) |
|
692 | + { |
|
693 | + continue; |
|
694 | + } |
|
695 | + // old depricated timezones |
|
641 | 696 | $datetime = new DateTime('now',new DateTimeZone($name)); |
642 | 697 | $tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)." ".$datetime->format(); |
643 | 698 | unset($datetime); |
@@ -676,10 +731,13 @@ discard block |
||
676 | 731 | { |
677 | 732 | $user_tzs = array_merge(array($tz),$user_tzs); |
678 | 733 | } |
679 | - if (!$user_tzs) // if we have no user timezones, eg. user set no pref --> use server default |
|
734 | + if (!$user_tzs) |
|
735 | + { |
|
736 | + // if we have no user timezones, eg. user set no pref --> use server default |
|
680 | 737 | { |
681 | 738 | $user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']); |
682 | 739 | } |
740 | + } |
|
683 | 741 | if ($extra && !in_array($extra,$user_tzs)) |
684 | 742 | { |
685 | 743 | $user_tzs = array_merge(array($extra),$user_tzs); |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | * @param string &$type=null on return type of $time (optional) |
94 | 94 | * @throws Exception if $time can NOT be parsed |
95 | 95 | */ |
96 | - public function __construct($time='now',DateTimeZone $tz=null,&$type=null) |
|
96 | + public function __construct($time = 'now', DateTimeZone $tz = null, &$type = null) |
|
97 | 97 | { |
98 | - if (is_null($tz)) $tz = self::$user_timezone; // default user timezone |
|
98 | + if (is_null($tz)) $tz = self::$user_timezone; // default user timezone |
|
99 | 99 | |
100 | - switch(($type = gettype($time))) |
|
100 | + switch (($type = gettype($time))) |
|
101 | 101 | { |
102 | 102 | case 'NULL': |
103 | 103 | case 'boolean': // depricated use in calendar for 'now' |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000))) |
109 | 109 | { |
110 | 110 | $t_str = $time; |
111 | - if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date |
|
111 | + if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date |
|
112 | 112 | // $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself |
113 | 113 | try { |
114 | - parent::__construct($t_str,$tz); |
|
114 | + parent::__construct($t_str, $tz); |
|
115 | 115 | break; |
116 | 116 | } |
117 | - catch(Exception $e) { |
|
117 | + catch (Exception $e) { |
|
118 | 118 | // if string is nummeric, ignore the exception and treat string as timestamp |
119 | 119 | if (!is_numeric($time)) throw $e; |
120 | 120 | } |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | } |
132 | 132 | else*/ |
133 | 133 | { |
134 | - parent::__construct(date('Y-m-d H:i:s',$time),$tz); |
|
134 | + parent::__construct(date('Y-m-d H:i:s', $time), $tz); |
|
135 | 135 | } |
136 | 136 | break; |
137 | 137 | |
138 | 138 | case 'array': |
139 | - parent::__construct('now',$tz); |
|
139 | + parent::__construct('now', $tz); |
|
140 | 140 | if (isset($time['Y'])) // array format used in eTemplate |
141 | 141 | { |
142 | 142 | $time = array( |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | } |
151 | 151 | if (!empty($time['full']) && empty($time['year'])) |
152 | 152 | { |
153 | - $time['year'] = (int)substr($time['full'],0,4); |
|
154 | - $time['month'] = (int)substr($time['full'],4,2); |
|
155 | - $time['day'] = (int)substr($time['full'],6,2); |
|
153 | + $time['year'] = (int)substr($time['full'], 0, 4); |
|
154 | + $time['month'] = (int)substr($time['full'], 4, 2); |
|
155 | + $time['day'] = (int)substr($time['full'], 6, 2); |
|
156 | 156 | } |
157 | - if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
158 | - $this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']); |
|
157 | + if (isset($time['year'])) $this->setDate((int)$time['year'], (int)$time['month'], isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
158 | + $this->setTime((int)$time['hour'], (int)$time['minute'], (int)$time['second']); |
|
159 | 159 | break; |
160 | 160 | |
161 | 161 | case 'object': |
162 | 162 | if ($time instanceof \DateTime) |
163 | 163 | { |
164 | - parent::__construct($time->format('Y-m-d H:i:s'),$time->getTimezone()); |
|
164 | + parent::__construct($time->format('Y-m-d H:i:s'), $time->getTimezone()); |
|
165 | 165 | $this->setTimezone($tz); |
166 | 166 | break; |
167 | 167 | } |
@@ -188,18 +188,18 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function setWeekstart() |
190 | 190 | { |
191 | - $wday = (int) $this->format('w'); // 0=sun, ..., 6=sat |
|
192 | - switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
191 | + $wday = (int)$this->format('w'); // 0=sun, ..., 6=sat |
|
192 | + switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
193 | 193 | { |
194 | 194 | case 'Sunday': |
195 | 195 | $wstart = -$wday; |
196 | 196 | break; |
197 | 197 | case 'Saturday': |
198 | - $wstart = -(6-$wday); |
|
198 | + $wstart = -(6 - $wday); |
|
199 | 199 | break; |
200 | 200 | case 'Moday': |
201 | 201 | default: |
202 | - $wstart = -($wday ? $wday-1 : 6); |
|
202 | + $wstart = -($wday ? $wday - 1 : 6); |
|
203 | 203 | break; |
204 | 204 | } |
205 | 205 | if ($wstart) $this->add($wstart.'days'); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param array $filters $name => list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) pairs with offsets |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public static function sql_filter($name, &$start, &$end, $column, array $filters=array()) |
|
218 | + public static function sql_filter($name, &$start, &$end, $column, array $filters = array()) |
|
219 | 219 | { |
220 | 220 | if ($name == 'custom' && $start) |
221 | 221 | { |
@@ -240,26 +240,26 @@ discard block |
||
240 | 240 | $end = new DateTime('now'); |
241 | 241 | $end->setTime(0, 0, 0); |
242 | 242 | |
243 | - $year = (int) $start->format('Y'); |
|
244 | - $month = (int) $start->format('m'); |
|
243 | + $year = (int)$start->format('Y'); |
|
244 | + $month = (int)$start->format('m'); |
|
245 | 245 | |
246 | - list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $filters[$name]; |
|
246 | + list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $filters[$name]; |
|
247 | 247 | |
248 | 248 | // Handle quarters |
249 | - if(stripos($name, 'quarter') !== false) |
|
249 | + if (stripos($name, 'quarter') !== false) |
|
250 | 250 | { |
251 | - $start->setDate($year, ((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1); |
|
252 | - $end->setDate($year, ((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1); |
|
251 | + $start->setDate($year, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1); |
|
252 | + $end->setDate($year, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1); |
|
253 | 253 | } |
254 | 254 | elseif ($syear || $eyear) |
255 | 255 | { |
256 | - $start->setDate($year+$syear, 1, 1); |
|
257 | - $end->setDate($year+$eyear, 1, 1); |
|
256 | + $start->setDate($year + $syear, 1, 1); |
|
257 | + $end->setDate($year + $eyear, 1, 1); |
|
258 | 258 | } |
259 | 259 | elseif ($smonth || $emonth) |
260 | 260 | { |
261 | - $start->setDate($year, $month+$smonth, 1); |
|
262 | - $end->setDate($year, $month+$emonth, 1); |
|
261 | + $start->setDate($year, $month + $smonth, 1); |
|
262 | + $end->setDate($year, $month + $emonth, 1); |
|
263 | 263 | } |
264 | 264 | elseif ($sday || $eday) |
265 | 265 | { |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | } |
277 | 277 | // convert start + end from user to servertime for the filter |
278 | 278 | $sql = '('.DateTime::user2server($start, 'ts').' <= '.$column; |
279 | - if($end) |
|
279 | + if ($end) |
|
280 | 280 | { |
281 | - $sql .=' AND '.$column.' < '.DateTime::user2server($end, 'ts'); |
|
281 | + $sql .= ' AND '.$column.' < '.DateTime::user2server($end, 'ts'); |
|
282 | 282 | |
283 | 283 | // returned timestamps: $end is an inclusive date, eg. for today it's equal to start! |
284 | 284 | $end->add('-1day'); |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | * true = date only, false = time only as in user prefs, '' = date+time as in user prefs |
321 | 321 | * @return int|string|array|datetime see $type |
322 | 322 | */ |
323 | - public function format($type='') |
|
323 | + public function format($type = '') |
|
324 | 324 | { |
325 | - switch((string)$type) |
|
325 | + switch ((string)$type) |
|
326 | 326 | { |
327 | 327 | case '': // empty string: date and time as in user prefs |
328 | 328 | //case '': // boolean false: time as in user prefs |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | case 'integer': |
348 | 348 | case 'ts': |
349 | 349 | // ToDo: Check if PHP5.3 getTimestamp does the same, or always returns UTC timestamp |
350 | - return mktime(parent::format('H'),parent::format('i'),parent::format('s'),parent::format('m'),parent::format('d'),parent::format('Y')); |
|
350 | + return mktime(parent::format('H'), parent::format('i'), parent::format('s'), parent::format('m'), parent::format('d'), parent::format('Y')); |
|
351 | 351 | |
352 | 352 | case 'object': |
353 | 353 | case 'datetime': |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | 'second' => (int)parent::format('s'), |
366 | 366 | 'full' => parent::format('Ymd'), |
367 | 367 | ); |
368 | - $arr['raw'] = mktime($arr['hour'],$arr['minute'],$arr['second'],$arr['month'],$arr['day'],$arr['year']); |
|
368 | + $arr['raw'] = mktime($arr['hour'], $arr['minute'], $arr['second'], $arr['month'], $arr['day'], $arr['year']); |
|
369 | 369 | return $arr; |
370 | 370 | |
371 | 371 | case 'date_array': // array with short keys used by date: Y, m, d, H, i, s (used in eTemplate) |
@@ -399,19 +399,19 @@ discard block |
||
399 | 399 | * @param string $type =null type or return-value, default (null) same as $time |
400 | 400 | * @return int|string|array|datetime null if time could not be parsed |
401 | 401 | */ |
402 | - public static function server2user($time,$type=null) |
|
402 | + public static function server2user($time, $type = null) |
|
403 | 403 | { |
404 | - $typeof='DateTime'; |
|
404 | + $typeof = 'DateTime'; |
|
405 | 405 | if (!($time instanceof DateTime)) |
406 | 406 | { |
407 | 407 | try |
408 | 408 | { |
409 | 409 | $time = new DateTime($time, self::$server_timezone, $typeof); |
410 | 410 | } |
411 | - catch(Exception $e) |
|
411 | + catch (Exception $e) |
|
412 | 412 | { |
413 | 413 | unset($e); |
414 | - return null; // time could not be parsed |
|
414 | + return null; // time could not be parsed |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | $time->setUser(); |
@@ -429,19 +429,19 @@ discard block |
||
429 | 429 | * @param string $type =null type or return-value, default (null) same as $time |
430 | 430 | * @return int|string|array|datetime null if time could not be parsed |
431 | 431 | */ |
432 | - public static function user2server($time,$type=null) |
|
432 | + public static function user2server($time, $type = null) |
|
433 | 433 | { |
434 | - $typeof='DateTime'; |
|
434 | + $typeof = 'DateTime'; |
|
435 | 435 | if (!($time instanceof DateTime)) |
436 | 436 | { |
437 | 437 | try |
438 | 438 | { |
439 | - $time = new DateTime($time,self::$user_timezone,$typeof); |
|
439 | + $time = new DateTime($time, self::$user_timezone, $typeof); |
|
440 | 440 | } |
441 | - catch(Exception $e) |
|
441 | + catch (Exception $e) |
|
442 | 442 | { |
443 | 443 | unset($e); |
444 | - return null; // time could not be parsed |
|
444 | + return null; // time could not be parsed |
|
445 | 445 | } |
446 | 446 | } |
447 | 447 | $time->setServer(); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | * true = date only, false = time only as in user prefs, '' = date+time as in user prefs |
462 | 462 | * @return int|string|array|datetime see $type, null if time could not be parsed |
463 | 463 | */ |
464 | - public static function to($time='now',$type='') |
|
464 | + public static function to($time = 'now', $type = '') |
|
465 | 465 | { |
466 | 466 | if (!($time instanceof DateTime)) |
467 | 467 | { |
@@ -469,10 +469,10 @@ discard block |
||
469 | 469 | { |
470 | 470 | $time = new DateTime($time); |
471 | 471 | } |
472 | - catch(\Exception $e) |
|
472 | + catch (\Exception $e) |
|
473 | 473 | { |
474 | 474 | unset($e); |
475 | - return null; // time could not be parsed |
|
475 | + return null; // time could not be parsed |
|
476 | 476 | } |
477 | 477 | } |
478 | 478 | return $time->format($type); |
@@ -486,12 +486,12 @@ discard block |
||
486 | 486 | * @param string|int $timeformat ='' integer 12, 24, or format string eg. 'H:i' |
487 | 487 | * @return DateTimeZone |
488 | 488 | */ |
489 | - public static function setUserPrefs($tz,$dateformat='',$timeformat='') |
|
489 | + public static function setUserPrefs($tz, $dateformat = '', $timeformat = '') |
|
490 | 490 | { |
491 | 491 | //echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n"; |
492 | 492 | if (!empty($dateformat)) self::$user_dateformat = $dateformat; |
493 | 493 | |
494 | - switch($timeformat) |
|
494 | + switch ($timeformat) |
|
495 | 495 | { |
496 | 496 | case '': |
497 | 497 | break; |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | try { |
509 | 509 | self::$user_timezone = new DateTimeZone($tz); |
510 | 510 | } |
511 | - catch(\Exception $e) |
|
511 | + catch (\Exception $e) |
|
512 | 512 | { |
513 | 513 | unset($e); |
514 | 514 | // silently use server timezone, as we have no means to report the wrong timezone to the user from this class |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | * @param int|string|DateTime $time ='now' |
526 | 526 | * @return int difference in seconds between user and server time (for the given time!) |
527 | 527 | */ |
528 | - public static function tz_offset_s($time='now') |
|
528 | + public static function tz_offset_s($time = 'now') |
|
529 | 529 | { |
530 | 530 | if (!($time instanceof DateTime)) $time = new DateTime($time); |
531 | 531 | |
@@ -546,17 +546,17 @@ discard block |
||
546 | 546 | try { |
547 | 547 | self::$server_timezone = new DateTimeZone($GLOBALS['egw_info']['server']['server_timezone']); |
548 | 548 | } |
549 | - catch(\Exception $e) |
|
549 | + catch (\Exception $e) |
|
550 | 550 | { |
551 | 551 | try { |
552 | 552 | self::$server_timezone = new DateTimeZone(date_default_timezone_get()); |
553 | 553 | } |
554 | - catch(\Exception $e) |
|
554 | + catch (\Exception $e) |
|
555 | 555 | { |
556 | 556 | self::$server_timezone = new DateTimeZone('Europe/Berlin'); |
557 | 557 | } |
558 | 558 | error_log(__METHOD__."() invalid server_timezone='{$GLOBALS['egw_info']['server']['server_timezone']}' setting now '".self::$server_timezone->getName()."'!"); |
559 | - Config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(),'phpgwapi'); |
|
559 | + Config::save_value('server_timezone', $GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(), 'phpgwapi'); |
|
560 | 560 | } |
561 | 561 | if (!isset($GLOBALS['egw_info']['user']['preferences']['common']['tz'])) |
562 | 562 | { |
@@ -579,15 +579,15 @@ discard block |
||
579 | 579 | { |
580 | 580 | // prepare list of timezones from php, ignoring depricated ones and sort as follows |
581 | 581 | $tzs = array( |
582 | - 'Africa' => array(), // Contients |
|
582 | + 'Africa' => array(), // Contients |
|
583 | 583 | 'America' => array(), |
584 | 584 | 'Asia' => array(), |
585 | 585 | 'Australia' => array(), |
586 | 586 | 'Europe' => array(), |
587 | - 'Atlantic' => array(), // Oceans |
|
587 | + 'Atlantic' => array(), // Oceans |
|
588 | 588 | 'Pacific' => array(), |
589 | 589 | 'Indian' => array(), |
590 | - 'Antarctica' => array(), // Poles |
|
590 | + 'Antarctica' => array(), // Poles |
|
591 | 591 | 'Arctic' => array(), |
592 | 592 | 'UTC' => array('UTC' => 'UTC'), |
593 | 593 | ); |
@@ -633,27 +633,27 @@ discard block |
||
633 | 633 | 'Australia/Yancowinna', |
634 | 634 | 'Pacific/Samoa', |
635 | 635 | ); |
636 | - foreach(DateTimeZone::listIdentifiers() as $name) |
|
636 | + foreach (DateTimeZone::listIdentifiers() as $name) |
|
637 | 637 | { |
638 | - if (in_array($name,$no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
639 | - list($continent) = explode('/',$name,2); |
|
640 | - if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
641 | - $datetime = new DateTime('now',new DateTimeZone($name)); |
|
642 | - $tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)." ".$datetime->format(); |
|
638 | + if (in_array($name, $no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
639 | + list($continent) = explode('/', $name, 2); |
|
640 | + if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
641 | + $datetime = new DateTime('now', new DateTimeZone($name)); |
|
642 | + $tzs[$continent][$name] = str_replace(array('_', '/'), array(' ', ' / '), $name)." ".$datetime->format(); |
|
643 | 643 | unset($datetime); |
644 | 644 | } |
645 | - foreach($tzs as $continent => &$data) |
|
645 | + foreach ($tzs as $continent => &$data) |
|
646 | 646 | { |
647 | - natcasesort($data); // sort cities |
|
647 | + natcasesort($data); // sort cities |
|
648 | 648 | } |
649 | 649 | unset($data); |
650 | 650 | |
651 | 651 | // if user lang or installed langs contain a european language --> move Europe to top of tz list |
652 | 652 | $langs = class_exists('EGroupware\\Api\\Translation') ? Translation::get_installed_langs() : array(); |
653 | - if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang'])+array_keys($langs), |
|
654 | - array('de','fr','it','nl','bg','ca','cs','da','el','es-es','et','eu','fi','hr','hu','lt','no','pl','pt','sk','sl','sv','tr','uk'))) |
|
653 | + if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang']) + array_keys($langs), |
|
654 | + array('de', 'fr', 'it', 'nl', 'bg', 'ca', 'cs', 'da', 'el', 'es-es', 'et', 'eu', 'fi', 'hr', 'hu', 'lt', 'no', 'pl', 'pt', 'sk', 'sl', 'sv', 'tr', 'uk'))) |
|
655 | 655 | { |
656 | - $tzs = array_merge(array('Europe' => $tzs['Europe']),$tzs); |
|
656 | + $tzs = array_merge(array('Europe' => $tzs['Europe']), $tzs); |
|
657 | 657 | } |
658 | 658 | return $tzs; |
659 | 659 | } |
@@ -664,30 +664,30 @@ discard block |
||
664 | 664 | * @param string $extra extra timezone to add, if not already included in user timezones |
665 | 665 | * @return array tzid => label |
666 | 666 | */ |
667 | - public static function getUserTimezones($extra=null) |
|
667 | + public static function getUserTimezones($extra = null) |
|
668 | 668 | { |
669 | 669 | $tz = $GLOBALS['egw_info']['user']['preferences']['common']['tz']; |
670 | - $user_tzs = explode(',',$GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']); |
|
670 | + $user_tzs = explode(',', $GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']); |
|
671 | 671 | if (count($user_tzs) <= 1) |
672 | 672 | { |
673 | 673 | $user_tzs = $tz ? array($tz) : array(); |
674 | 674 | } |
675 | - if ($tz && !in_array($tz,$user_tzs)) |
|
675 | + if ($tz && !in_array($tz, $user_tzs)) |
|
676 | 676 | { |
677 | - $user_tzs = array_merge(array($tz),$user_tzs); |
|
677 | + $user_tzs = array_merge(array($tz), $user_tzs); |
|
678 | 678 | } |
679 | 679 | if (!$user_tzs) // if we have no user timezones, eg. user set no pref --> use server default |
680 | 680 | { |
681 | 681 | $user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']); |
682 | 682 | } |
683 | - if ($extra && !in_array($extra,$user_tzs)) |
|
683 | + if ($extra && !in_array($extra, $user_tzs)) |
|
684 | 684 | { |
685 | - $user_tzs = array_merge(array($extra),$user_tzs); |
|
685 | + $user_tzs = array_merge(array($extra), $user_tzs); |
|
686 | 686 | } |
687 | - $ret_user_tzs = array_combine($user_tzs,$user_tzs); |
|
688 | - foreach($ret_user_tzs as &$label) |
|
687 | + $ret_user_tzs = array_combine($user_tzs, $user_tzs); |
|
688 | + foreach ($ret_user_tzs as &$label) |
|
689 | 689 | { |
690 | - $label = str_replace(array('_','/'),array(' ',' / '),$label); |
|
690 | + $label = str_replace(array('_', '/'), array(' ', ' / '), $label); |
|
691 | 691 | } |
692 | 692 | return $ret_user_tzs; |
693 | 693 | } |