@@ -213,7 +213,6 @@ |
||
213 | 213 | /** |
214 | 214 | * Remove attributes we are not allowed to update |
215 | 215 | * |
216 | - * @param array $attributes |
|
217 | 216 | */ |
218 | 217 | function sanitize_update(array &$ldapContact) |
219 | 218 | { |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email'); |
36 | 36 | */ |
37 | 37 | var $search_attributes = array( |
38 | - 'n_family','n_middle','n_given','org_name','org_unit', |
|
39 | - 'adr_one_location','note','email','samaccountname', |
|
38 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
39 | + 'adr_one_location', 'note', 'email', 'samaccountname', |
|
40 | 40 | ); |
41 | 41 | |
42 | 42 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @var string |
52 | 52 | */ |
53 | - var $dn_attribute='cn'; |
|
53 | + var $dn_attribute = 'cn'; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!) |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server'] |
83 | 83 | * @param resource $ds =null ldap connection to use |
84 | 84 | */ |
85 | - function __construct(array $ldap_config=null, $ds=null) |
|
85 | + function __construct(array $ldap_config = null, $ds = null) |
|
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) parent::__construct(); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 88 | |
89 | - $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
89 | + $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
90 | 90 | |
91 | 91 | if ($ldap_config) |
92 | 92 | { |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | else |
96 | 96 | { |
97 | - $this->ldap_config =& $GLOBALS['egw_info']['server']; |
|
97 | + $this->ldap_config = & $GLOBALS['egw_info']['server']; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $this->accounts_ads = $GLOBALS['egw']->accounts->backend; |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | 'account_id' => 'objectsid', |
120 | 120 | 'id' => 'objectguid', |
121 | 121 | 'uid' => 'objectguid', |
122 | - 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | - 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
122 | + 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | + 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
124 | 124 | )); |
125 | 125 | unset($this->schema2egw['user']['n_fileas']); |
126 | 126 | unset($this->schema2egw['inetorgperson']); |
127 | 127 | |
128 | - foreach($this->schema2egw as $attributes) |
|
128 | + foreach ($this->schema2egw as $attributes) |
|
129 | 129 | { |
130 | - $this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); |
|
130 | + $this->all_attributes = array_merge($this->all_attributes, array_values($attributes)); |
|
131 | 131 | } |
132 | 132 | $this->all_attributes = array_values(array_unique($this->all_attributes)); |
133 | 133 | |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param boolean $admin =false true (re-)connect with admin not user credentials, eg. to modify accounts |
141 | 141 | */ |
142 | - function connect($admin=false) |
|
142 | + function connect($admin = false) |
|
143 | 143 | { |
144 | - unset($admin); // not used, but required by function signature |
|
144 | + unset($admin); // not used, but required by function signature |
|
145 | 145 | |
146 | 146 | $this->ds = $this->accounts_ads->ldap_connection(); |
147 | 147 | } |
@@ -174,15 +174,14 @@ discard block |
||
174 | 174 | function read($_contact_id) |
175 | 175 | { |
176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
177 | - !is_array($_contact_id) && substr($_contact_id,0,8) == 'account:') |
|
177 | + !is_array($_contact_id) && substr($_contact_id, 0, 8) == 'account:') |
|
178 | 178 | { |
179 | - $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id,8)); |
|
179 | + $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id, 8)); |
|
180 | 180 | $_contact_id = $GLOBALS['egw']->accounts->id2name($account_id, 'person_id'); |
181 | 181 | } |
182 | - $contact_id = !is_array($_contact_id) ? $_contact_id : |
|
183 | - (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
182 | + $contact_id = !is_array($_contact_id) ? $_contact_id : (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
184 | 183 | |
185 | - $rows = $this->_searchLDAP($this->allContactsDN, $filter=$this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
184 | + $rows = $this->_searchLDAP($this->allContactsDN, $filter = $this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
186 | 185 | //error_log(__METHOD__."('$contact_id') _searchLDAP($this->allContactsDN, '$filter',...)=".array2string($rows)); |
187 | 186 | return $rows ? $rows[0] : false; |
188 | 187 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * while it uses select-account for owner in historylog (containing all users). |
34 | 34 | * |
35 | 35 | * @param string $cname |
36 | - */ |
|
36 | + */ |
|
37 | 37 | public function beforeSendToClient($cname) |
38 | 38 | { |
39 | 39 | $form_name = self::form_name($cname, $this->id); |
@@ -84,7 +84,11 @@ discard block |
||
84 | 84 | */ |
85 | 85 | function __construct(array $ldap_config=null, $ds=null) |
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) |
|
88 | + { |
|
89 | + parent::__construct (); |
|
90 | + } |
|
91 | + // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 92 | |
89 | 93 | $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
90 | 94 | |
@@ -202,10 +206,16 @@ discard block |
||
202 | 206 | $contact['id'] = $contact['uid'] = $this->accounts_ads->objectguid2str($data['objectguid']); |
203 | 207 | |
204 | 208 | // ignore system accounts |
205 | - if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) return false; |
|
209 | + if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) |
|
210 | + { |
|
211 | + return false; |
|
212 | + } |
|
206 | 213 | |
207 | 214 | // ignore deactivated or expired accounts |
208 | - if (!$this->accounts_ads->user_active($data)) return false; |
|
215 | + if (!$this->accounts_ads->user_active($data)) |
|
216 | + { |
|
217 | + return false; |
|
218 | + } |
|
209 | 219 | |
210 | 220 | $this->_inetorgperson2egw($contact, $data, 'displayname'); |
211 | 221 | } |
@@ -425,7 +425,6 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * Remove attributes we are not allowed to update |
427 | 427 | * |
428 | - * @param array $attributes |
|
429 | 428 | */ |
430 | 429 | function sanitize_update(array &$ldapContact) |
431 | 430 | { |
@@ -703,14 +702,14 @@ discard block |
||
703 | 702 | * |
704 | 703 | * '*' and '?' are replaced with sql-wildcards '%' and '_' |
705 | 704 | * |
706 | - * @param array|string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) |
|
705 | + * @param boolean $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) |
|
707 | 706 | * @param boolean|string $only_keys =true True returns only keys, False returns all cols. comma seperated list of keys to return |
708 | 707 | * @param string $order_by ='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) |
709 | - * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
708 | + * @param string $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
710 | 709 | * @param string $wildcard ='' appended befor and after each criteria |
711 | 710 | * @param boolean $empty =false False=empty criteria are ignored in query, True=empty have to be empty in row |
712 | 711 | * @param string $op ='AND' defaults to 'AND', can be set to 'OR' too, then criteria's are OR'ed together |
713 | - * @param mixed $start =false if != false, return only maxmatch rows begining with start, or array($start,$num) |
|
712 | + * @param boolean $start =false if != false, return only maxmatch rows begining with start, or array($start,$num) |
|
714 | 713 | * @param array $filter =null if set (!=null) col-data pairs, to be and-ed (!) into the query without wildcards |
715 | 714 | * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
716 | 715 | * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
@@ -41,33 +41,33 @@ discard block |
||
41 | 41 | var $contacts_id='id'; |
42 | 42 | |
43 | 43 | /** |
44 | - * @var string $accountName holds the accountname of the current user |
|
45 | - */ |
|
44 | + * @var string $accountName holds the accountname of the current user |
|
45 | + */ |
|
46 | 46 | var $accountName; |
47 | 47 | |
48 | 48 | /** |
49 | - * @var object $ldapServerInfo holds the information about the current used ldap server |
|
50 | - */ |
|
49 | + * @var object $ldapServerInfo holds the information about the current used ldap server |
|
50 | + */ |
|
51 | 51 | var $ldapServerInfo; |
52 | 52 | |
53 | 53 | /** |
54 | - * @var int $ldapLimit how many rows to fetch from ldap server |
|
55 | - */ |
|
54 | + * @var int $ldapLimit how many rows to fetch from ldap server |
|
55 | + */ |
|
56 | 56 | var $ldapLimit = 2000; |
57 | 57 | |
58 | 58 | /** |
59 | - * @var string $personalContactsDN holds the base DN for the personal addressbooks |
|
60 | - */ |
|
59 | + * @var string $personalContactsDN holds the base DN for the personal addressbooks |
|
60 | + */ |
|
61 | 61 | var $personalContactsDN; |
62 | 62 | |
63 | 63 | /** |
64 | - * @var string $sharedContactsDN holds the base DN for the shared addressbooks |
|
65 | - */ |
|
64 | + * @var string $sharedContactsDN holds the base DN for the shared addressbooks |
|
65 | + */ |
|
66 | 66 | var $sharedContactsDN; |
67 | 67 | |
68 | 68 | /** |
69 | - * @var string $accountContactsDN holds the base DN for accounts addressbook |
|
70 | - */ |
|
69 | + * @var string $accountContactsDN holds the base DN for accounts addressbook |
|
70 | + */ |
|
71 | 71 | var $accountContactsDN; |
72 | 72 | |
73 | 73 | /** |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | var $accountsFilter = '(objectclass=posixaccount)'; |
78 | 78 | |
79 | 79 | /** |
80 | - * @var string $allContactsDN holds the base DN of all addressbook |
|
81 | - */ |
|
80 | + * @var string $allContactsDN holds the base DN of all addressbook |
|
81 | + */ |
|
82 | 82 | var $allContactsDN; |
83 | 83 | |
84 | 84 | /** |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | var $never_change_dn = false; |
97 | 97 | |
98 | 98 | /** |
99 | - * @var int $total holds the total count of found rows |
|
100 | - */ |
|
99 | + * @var int $total holds the total count of found rows |
|
100 | + */ |
|
101 | 101 | var $total; |
102 | 102 | |
103 | 103 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * |
404 | 404 | * @param string|array $contact_id contact_id or array with values for id or account_id |
405 | 405 | * @return array/boolean data if row could be retrived else False |
406 | - */ |
|
406 | + */ |
|
407 | 407 | function read($contact_id) |
408 | 408 | { |
409 | 409 | if (is_array($contact_id) && isset($contact_id['account_id']) || |
@@ -327,9 +327,12 @@ discard block |
||
327 | 327 | $this->ds = Api\Ldap::factory(); |
328 | 328 | } |
329 | 329 | // if ldap is NOT the contact repository, we only do accounts and need to use the account-data |
330 | - elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') // not (ldap or sql-ldap) |
|
330 | + elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap') |
|
331 | + { |
|
332 | + // not (ldap or sql-ldap) |
|
331 | 333 | { |
332 | 334 | $this->ldap_config['ldap_contact_host'] = $this->ldap_config['ldap_host']; |
335 | + } |
|
333 | 336 | $this->allContactsDN = $this->ldap_config['ldap_context']; |
334 | 337 | $this->ds = Api\Ldap::factory(); |
335 | 338 | } |
@@ -413,7 +416,10 @@ discard block |
||
413 | 416 | } |
414 | 417 | else |
415 | 418 | { |
416 | - if (is_array($contact_id)) $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid']; |
|
419 | + if (is_array($contact_id)) |
|
420 | + { |
|
421 | + $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid']; |
|
422 | + } |
|
417 | 423 | $filter = $this->id_filter($contact_id); |
418 | 424 | } |
419 | 425 | $rows = $this->_searchLDAP($this->allContactsDN, |
@@ -517,7 +523,10 @@ discard block |
||
517 | 523 | // add for all supported objectclasses the objectclass and it's attributes |
518 | 524 | foreach($this->schema2egw as $objectclass => $mapping) |
519 | 525 | { |
520 | - if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue; |
|
526 | + if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) |
|
527 | + { |
|
528 | + continue; |
|
529 | + } |
|
521 | 530 | |
522 | 531 | if($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses)) |
523 | 532 | { |
@@ -535,7 +544,10 @@ discard block |
||
535 | 544 | } |
536 | 545 | foreach($mapping as $egwFieldName => $ldapFieldName) |
537 | 546 | { |
538 | - if (is_int($egwFieldName)) continue; |
|
547 | + if (is_int($egwFieldName)) |
|
548 | + { |
|
549 | + continue; |
|
550 | + } |
|
539 | 551 | if(!empty($data[$egwFieldName])) |
540 | 552 | { |
541 | 553 | // dont convert the (binary) jpegPhoto! |
@@ -671,7 +683,10 @@ discard block |
||
671 | 683 | function delete($keys=null) |
672 | 684 | { |
673 | 685 | // single entry |
674 | - if($keys[$this->contacts_id]) $keys = array( 0 => $keys); |
|
686 | + if($keys[$this->contacts_id]) |
|
687 | + { |
|
688 | + $keys = array( 0 => $keys); |
|
689 | + } |
|
675 | 690 | |
676 | 691 | if(!is_array($keys)) |
677 | 692 | { |
@@ -760,7 +775,10 @@ discard block |
||
760 | 775 | |
761 | 776 | if((int)$filter['owner']) |
762 | 777 | { |
763 | - if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) return false; |
|
778 | + if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) |
|
779 | + { |
|
780 | + return false; |
|
781 | + } |
|
764 | 782 | |
765 | 783 | $searchDN = 'cn='. Api\Ldap::quote(strtolower($accountName)) .','; |
766 | 784 | |
@@ -856,7 +874,10 @@ discard block |
||
856 | 874 | $sort = 'ASC'; |
857 | 875 | foreach(explode(',',$order_by) as $o) |
858 | 876 | { |
859 | - if (substr($o,0,8) == 'contact_') $o = substr($o,8); |
|
877 | + if (substr($o,0,8) == 'contact_') |
|
878 | + { |
|
879 | + $o = substr($o,8); |
|
880 | + } |
|
860 | 881 | if (substr($o,-4) == ' ASC') |
861 | 882 | { |
862 | 883 | $sort = 'ASC'; |
@@ -898,12 +919,18 @@ discard block |
||
898 | 919 | */ |
899 | 920 | function _colFilter($filter) |
900 | 921 | { |
901 | - if (!is_array($filter)) return ''; |
|
922 | + if (!is_array($filter)) |
|
923 | + { |
|
924 | + return ''; |
|
925 | + } |
|
902 | 926 | |
903 | 927 | $filters = ''; |
904 | 928 | foreach($filter as $key => $value) |
905 | 929 | { |
906 | - if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
|
930 | + if ($key != 'cat_id' && $key != 'account_id' && !$value) |
|
931 | + { |
|
932 | + continue; |
|
933 | + } |
|
907 | 934 | |
908 | 935 | switch((string) $key) |
909 | 936 | { |
@@ -935,19 +962,28 @@ discard block |
||
935 | 962 | $GLOBALS['egw']->categories = new Api\Categories(); |
936 | 963 | } |
937 | 964 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
938 | - if (count($cats) > 1) $filters .= '(|'; |
|
965 | + if (count($cats) > 1) |
|
966 | + { |
|
967 | + $filters .= '(|'; |
|
968 | + } |
|
939 | 969 | foreach($cats as $cat) |
940 | 970 | { |
941 | 971 | $catName = Api\Translation::convert( |
942 | 972 | $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
943 | 973 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
944 | 974 | } |
945 | - if (count($cats) > 1) $filters .= ')'; |
|
975 | + if (count($cats) > 1) |
|
976 | + { |
|
977 | + $filters .= ')'; |
|
978 | + } |
|
946 | 979 | } |
947 | 980 | break; |
948 | 981 | |
949 | 982 | case 'carddav_name': |
950 | - if (!is_array($value)) $value = array($value); |
|
983 | + if (!is_array($value)) |
|
984 | + { |
|
985 | + $value = array($value); |
|
986 | + } |
|
951 | 987 | foreach($value as &$v) |
952 | 988 | { |
953 | 989 | $v = basename($v, '.vcf'); |
@@ -977,7 +1013,10 @@ discard block |
||
977 | 1013 | elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
978 | 1014 | { |
979 | 1015 | list(,$name,$value) = $matches; |
980 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
1016 | + if (strpos($name,'.') !== false) |
|
1017 | + { |
|
1018 | + list(,$name) = explode('.',$name); |
|
1019 | + } |
|
981 | 1020 | foreach($this->schema2egw as $mapping) |
982 | 1021 | { |
983 | 1022 | if (isset($mapping[$name])) |
@@ -1028,13 +1067,20 @@ discard block |
||
1028 | 1067 | { |
1029 | 1068 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1030 | 1069 | } |
1031 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1070 | + if(!$result || !$entries = ldap_get_entries($this->ds, $result)) |
|
1071 | + { |
|
1072 | + return array(); |
|
1073 | + } |
|
1032 | 1074 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1033 | 1075 | |
1034 | 1076 | $this->total = $entries['count']; |
1035 | 1077 | foreach($entries as $i => $entry) |
1036 | 1078 | { |
1037 | - if (!is_int($i)) continue; // eg. count |
|
1079 | + if (!is_int($i)) |
|
1080 | + { |
|
1081 | + continue; |
|
1082 | + } |
|
1083 | + // eg. count |
|
1038 | 1084 | |
1039 | 1085 | $contact = array( |
1040 | 1086 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
@@ -1254,11 +1300,17 @@ discard block |
||
1254 | 1300 | $contact['cat_id'] = array(); |
1255 | 1301 | foreach($data['category'] as $iii => $cat) |
1256 | 1302 | { |
1257 | - if (!is_int($iii)) continue; |
|
1303 | + if (!is_int($iii)) |
|
1304 | + { |
|
1305 | + continue; |
|
1306 | + } |
|
1258 | 1307 | |
1259 | 1308 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1260 | 1309 | } |
1261 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1310 | + if ($contact['cat_id']) |
|
1311 | + { |
|
1312 | + $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1313 | + } |
|
1262 | 1314 | } |
1263 | 1315 | if ($data['primaryphone']) |
1264 | 1316 | { |
@@ -1313,7 +1365,10 @@ discard block |
||
1313 | 1365 | { |
1314 | 1366 | unset($contact); // not used, but required by function signature |
1315 | 1367 | static $shadowExpireNow=null; |
1316 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1368 | + if (!isset($shadowExpireNow)) |
|
1369 | + { |
|
1370 | + $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1371 | + } |
|
1317 | 1372 | |
1318 | 1373 | // exclude expired or deactivated accounts |
1319 | 1374 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1358,9 +1413,13 @@ discard block |
||
1358 | 1413 | elseif ($data['adr_one_countryname']) |
1359 | 1414 | { |
1360 | 1415 | $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
1361 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1416 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1417 | + { |
|
1418 | + // Bad countryname when "custom" selected! |
|
1362 | 1419 | { |
1363 | - $ldapContact['c'] = array(); // should return error... |
|
1420 | + $ldapContact['c'] = array(); |
|
1421 | + } |
|
1422 | + // should return error... |
|
1364 | 1423 | } |
1365 | 1424 | } |
1366 | 1425 | elseif ($isUpdate) |
@@ -1399,14 +1458,21 @@ discard block |
||
1399 | 1458 | if ($data['adr_one_countrycode']) |
1400 | 1459 | { |
1401 | 1460 | $ldapContact['c'] = $data['adr_one_countrycode']; |
1402 | - if ($isUpdate) $ldapContact['co'] = array(); |
|
1461 | + if ($isUpdate) |
|
1462 | + { |
|
1463 | + $ldapContact['co'] = array(); |
|
1464 | + } |
|
1403 | 1465 | } |
1404 | 1466 | elseif ($data['adr_one_countryname']) |
1405 | 1467 | { |
1406 | 1468 | $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
1407 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
1469 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
1408 | 1470 | { |
1409 | - $ldapContact['c'] = array(); // should return error... |
|
1471 | + // Bad countryname when "custom" selected! |
|
1472 | + { |
|
1473 | + $ldapContact['c'] = array(); |
|
1474 | + } |
|
1475 | + // should return error... |
|
1410 | 1476 | } |
1411 | 1477 | } |
1412 | 1478 | elseif ($isUpdate) |
@@ -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,36 +853,36 @@ discard block |
||
854 | 853 | { |
855 | 854 | $order = array(); |
856 | 855 | $sort = 'ASC'; |
857 | - foreach(explode(',',$order_by) as $o) |
|
856 | + foreach (explode(',', $order_by) as $o) |
|
858 | 857 | { |
859 | - if (substr($o,0,8) == 'contact_') $o = substr($o,8); |
|
860 | - if (substr($o,-4) == ' ASC') |
|
858 | + if (substr($o, 0, 8) == 'contact_') $o = substr($o, 8); |
|
859 | + if (substr($o, -4) == ' ASC') |
|
861 | 860 | { |
862 | 861 | $sort = 'ASC'; |
863 | - $order[] = substr($o,0,-4); |
|
862 | + $order[] = substr($o, 0, -4); |
|
864 | 863 | } |
865 | - elseif (substr($o,-5) == ' DESC') |
|
864 | + elseif (substr($o, -5) == ' DESC') |
|
866 | 865 | { |
867 | 866 | $sort = 'DESC'; |
868 | - $order[] = substr($o,0,-5); |
|
867 | + $order[] = substr($o, 0, -5); |
|
869 | 868 | } |
870 | 869 | elseif ($o) |
871 | 870 | { |
872 | 871 | $order[] = $o; |
873 | 872 | } |
874 | 873 | } |
875 | - $rows = ExecMethod2('phpgwapi.arrayfunctions.arfsort',$rows,$order,$sort); |
|
874 | + $rows = ExecMethod2('phpgwapi.arrayfunctions.arfsort', $rows, $order, $sort); |
|
876 | 875 | } |
877 | 876 | // if requested ($start !== false) return only limited resultset |
878 | 877 | if (is_array($start)) |
879 | 878 | { |
880 | - list($start,$offset) = $start; |
|
879 | + list($start, $offset) = $start; |
|
881 | 880 | } |
882 | - if(is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
881 | + if (is_numeric($start) && is_numeric($offset) && $offset >= 0) |
|
883 | 882 | { |
884 | 883 | return array_slice($rows, $start, $offset); |
885 | 884 | } |
886 | - elseif(is_numeric($start)) |
|
885 | + elseif (is_numeric($start)) |
|
887 | 886 | { |
888 | 887 | return array_slice($rows, $start, $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']); |
889 | 888 | } |
@@ -901,11 +900,11 @@ discard block |
||
901 | 900 | if (!is_array($filter)) return ''; |
902 | 901 | |
903 | 902 | $filters = ''; |
904 | - foreach($filter as $key => $value) |
|
903 | + foreach ($filter as $key => $value) |
|
905 | 904 | { |
906 | 905 | if ($key != 'cat_id' && $key != 'account_id' && !$value) continue; |
907 | 906 | |
908 | - switch((string) $key) |
|
907 | + switch ((string)$key) |
|
909 | 908 | { |
910 | 909 | case 'owner': // already handled |
911 | 910 | case 'tid': // ignored |
@@ -928,7 +927,7 @@ discard block |
||
928 | 927 | { |
929 | 928 | $filters .= '(!(category=*))'; |
930 | 929 | } |
931 | - elseif((int)$value) |
|
930 | + elseif ((int)$value) |
|
932 | 931 | { |
933 | 932 | if (!is_object($GLOBALS['egw']->categories)) |
934 | 933 | { |
@@ -936,10 +935,10 @@ discard block |
||
936 | 935 | } |
937 | 936 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
938 | 937 | if (count($cats) > 1) $filters .= '(|'; |
939 | - foreach($cats as $cat) |
|
938 | + foreach ($cats as $cat) |
|
940 | 939 | { |
941 | 940 | $catName = Api\Translation::convert( |
942 | - $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
|
941 | + $GLOBALS['egw']->categories->id2name($cat), $this->charset, 'utf-8'); |
|
943 | 942 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
944 | 943 | } |
945 | 944 | if (count($cats) > 1) $filters .= ')'; |
@@ -948,7 +947,7 @@ discard block |
||
948 | 947 | |
949 | 948 | case 'carddav_name': |
950 | 949 | if (!is_array($value)) $value = array($value); |
951 | - foreach($value as &$v) |
|
950 | + foreach ($value as &$v) |
|
952 | 951 | { |
953 | 952 | $v = basename($v, '.vcf'); |
954 | 953 | } |
@@ -962,28 +961,27 @@ discard block |
||
962 | 961 | $matches = null; |
963 | 962 | if (!is_int($key)) |
964 | 963 | { |
965 | - foreach($this->schema2egw as $mapping) |
|
964 | + foreach ($this->schema2egw as $mapping) |
|
966 | 965 | { |
967 | 966 | if (isset($mapping[$key])) |
968 | 967 | { |
969 | 968 | // todo: value = "!''" |
970 | - $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : |
|
971 | - Api\Ldap::quote(Api\Translation::convert($value,$this->charset,'utf-8'))).')'; |
|
969 | + $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : Api\Ldap::quote(Api\Translation::convert($value, $this->charset, 'utf-8'))).')'; |
|
972 | 970 | break; |
973 | 971 | } |
974 | 972 | } |
975 | 973 | } |
976 | 974 | // filter for letter-search |
977 | - elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
|
975 | + elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/", $value, $matches)) |
|
978 | 976 | { |
979 | - list(,$name,$value) = $matches; |
|
980 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
981 | - foreach($this->schema2egw as $mapping) |
|
977 | + list(,$name, $value) = $matches; |
|
978 | + if (strpos($name, '.') !== false) list(,$name) = explode('.', $name); |
|
979 | + foreach ($this->schema2egw as $mapping) |
|
982 | 980 | { |
983 | 981 | if (isset($mapping[$name])) |
984 | 982 | { |
985 | 983 | $filters .= '('.$mapping[$name].'='.Api\Ldap::quote( |
986 | - Api\Translation::convert($value,$this->charset,'utf-8')).'*)'; |
|
984 | + Api\Translation::convert($value, $this->charset, 'utf-8')).'*)'; |
|
987 | 985 | break; |
988 | 986 | } |
989 | 987 | } |
@@ -1007,7 +1005,7 @@ discard block |
||
1007 | 1005 | * @param array $_skipPlugins =null schema-plugins to skip |
1008 | 1006 | * @return array/boolean with eGW contacts or false on error |
1009 | 1007 | */ |
1010 | - function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null) |
|
1008 | + function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins = null) |
|
1011 | 1009 | { |
1012 | 1010 | $this->total = 0; |
1013 | 1011 | |
@@ -1020,7 +1018,7 @@ discard block |
||
1020 | 1018 | |
1021 | 1019 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype)"); |
1022 | 1020 | |
1023 | - if($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1021 | + if ($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
1024 | 1022 | { |
1025 | 1023 | $result = ldap_search($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1026 | 1024 | } |
@@ -1028,36 +1026,36 @@ discard block |
||
1028 | 1026 | { |
1029 | 1027 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
1030 | 1028 | } |
1031 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1029 | + if (!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
1032 | 1030 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
1033 | 1031 | |
1034 | 1032 | $this->total = $entries['count']; |
1035 | - foreach($entries as $i => $entry) |
|
1033 | + foreach ($entries as $i => $entry) |
|
1036 | 1034 | { |
1037 | - if (!is_int($i)) continue; // eg. count |
|
1035 | + if (!is_int($i)) continue; // eg. count |
|
1038 | 1036 | |
1039 | 1037 | $contact = array( |
1040 | 1038 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
1041 | - 'tid' => 'n', // the type id for the addressbook |
|
1039 | + 'tid' => 'n', // the type id for the addressbook |
|
1042 | 1040 | ); |
1043 | - foreach($entry['objectclass'] as $ii => $objectclass) |
|
1041 | + foreach ($entry['objectclass'] as $ii => $objectclass) |
|
1044 | 1042 | { |
1045 | 1043 | $objectclass = strtolower($objectclass); |
1046 | 1044 | if (!is_int($ii) || !isset($this->schema2egw[$objectclass])) |
1047 | 1045 | { |
1048 | - continue; // eg. count or unsupported objectclass |
|
1046 | + continue; // eg. count or unsupported objectclass |
|
1049 | 1047 | } |
1050 | - foreach($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1048 | + foreach ($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
1051 | 1049 | { |
1052 | - if(!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1050 | + if (!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
1053 | 1051 | { |
1054 | - $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0],'utf-8'); |
|
1052 | + $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0], 'utf-8'); |
|
1055 | 1053 | } |
1056 | 1054 | } |
1057 | 1055 | $objectclass2egw = '_'.$objectclass.'2egw'; |
1058 | - if (!in_array($objectclass2egw, (array)$_skipPlugins) &&method_exists($this,$objectclass2egw)) |
|
1056 | + if (!in_array($objectclass2egw, (array)$_skipPlugins) && method_exists($this, $objectclass2egw)) |
|
1059 | 1057 | { |
1060 | - if (($ret=$this->$objectclass2egw($contact,$entry)) === false) |
|
1058 | + if (($ret = $this->$objectclass2egw($contact, $entry)) === false) |
|
1061 | 1059 | { |
1062 | 1060 | --$this->total; |
1063 | 1061 | continue 2; |
@@ -1067,20 +1065,20 @@ discard block |
||
1067 | 1065 | // read binary jpegphoto only for one result == call by read |
1068 | 1066 | if ($this->total == 1 && isset($entry['jpegphoto'][0])) |
1069 | 1067 | { |
1070 | - $bin = ldap_get_values_len($this->ds,ldap_first_entry($this->ds,$result),'jpegphoto'); |
|
1068 | + $bin = ldap_get_values_len($this->ds, ldap_first_entry($this->ds, $result), 'jpegphoto'); |
|
1071 | 1069 | $contact['jpegphoto'] = $bin[0]; |
1072 | 1070 | } |
1073 | 1071 | $matches = null; |
1074 | - if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1072 | + if (preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1075 | 1073 | { |
1076 | 1074 | // personal addressbook |
1077 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','u'); |
|
1075 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'u'); |
|
1078 | 1076 | $contact['private'] = 0; |
1079 | 1077 | } |
1080 | - elseif(preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
1078 | + elseif (preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
1081 | 1079 | { |
1082 | 1080 | // group addressbook |
1083 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','g'); |
|
1081 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g'); |
|
1084 | 1082 | $contact['private'] = 0; |
1085 | 1083 | } |
1086 | 1084 | else |
@@ -1089,12 +1087,12 @@ discard block |
||
1089 | 1087 | $contact['owner'] = 0; |
1090 | 1088 | $contact['private'] = 0; |
1091 | 1089 | } |
1092 | - foreach(array( |
|
1090 | + foreach (array( |
|
1093 | 1091 | 'createtimestamp' => 'created', |
1094 | 1092 | 'modifytimestamp' => 'modified', |
1095 | 1093 | ) as $ldapFieldName => $egwFieldName) |
1096 | 1094 | { |
1097 | - if(!empty($entry[$ldapFieldName][0])) |
|
1095 | + if (!empty($entry[$ldapFieldName][0])) |
|
1098 | 1096 | { |
1099 | 1097 | $contact[$egwFieldName] = $this->_ldap2ts($entry[$ldapFieldName][0]); |
1100 | 1098 | } |
@@ -1113,8 +1111,8 @@ discard block |
||
1113 | 1111 | */ |
1114 | 1112 | static function _ldap2ts($date) |
1115 | 1113 | { |
1116 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
1117 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
1114 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
1115 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
1118 | 1116 | } |
1119 | 1117 | |
1120 | 1118 | /** |
@@ -1137,22 +1135,22 @@ discard block |
||
1137 | 1135 | function _check_create_dn($baseDN) |
1138 | 1136 | { |
1139 | 1137 | // check if $baseDN exists. If not create new one |
1140 | - if(@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1138 | + if (@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
1141 | 1139 | { |
1142 | 1140 | return false; |
1143 | 1141 | } |
1144 | 1142 | //error_log(__METHOD__."('$baseDN') !ldap_read({$this->ds}, '$baseDN', 'objectclass=*') ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds).get_class($this)); |
1145 | - if(ldap_errno($this->ds) != 32 || substr($baseDN,0,3) != 'cn=') |
|
1143 | + if (ldap_errno($this->ds) != 32 || substr($baseDN, 0, 3) != 'cn=') |
|
1146 | 1144 | { |
1147 | 1145 | error_log(__METHOD__."('$baseDN') baseDN does NOT exist and we cant/wont create it! ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds)); |
1148 | - return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1146 | + return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
1149 | 1147 | } |
1150 | 1148 | // create a admin connection to add the needed DN |
1151 | 1149 | $adminLDAP = new ldap; |
1152 | 1150 | $adminDS = $adminLDAP->ldapConnect(); |
1153 | 1151 | |
1154 | - list(,$ou) = explode(',',$baseDN); |
|
1155 | - foreach(array( |
|
1152 | + list(,$ou) = explode(',', $baseDN); |
|
1153 | + foreach (array( |
|
1156 | 1154 | 'ou=contacts,'.$this->allContactsDN, |
1157 | 1155 | $ou.',ou=contacts,'.$this->allContactsDN, |
1158 | 1156 | $baseDN, |
@@ -1161,16 +1159,16 @@ discard block |
||
1161 | 1159 | if (!@ldap_read($this->ds, $dn, 'objectclass=*') && ldap_errno($this->ds) == 32) |
1162 | 1160 | { |
1163 | 1161 | // entry does not exist, lets try to create it |
1164 | - list($top) = explode(',',$dn); |
|
1165 | - list($var,$val) = explode('=',$top); |
|
1162 | + list($top) = explode(',', $dn); |
|
1163 | + list($var, $val) = explode('=', $top); |
|
1166 | 1164 | $data = array( |
1167 | 1165 | 'objectClass' => $var == 'cn' ? 'organizationalRole' : 'organizationalUnit', |
1168 | 1166 | $var => $val, |
1169 | 1167 | ); |
1170 | - if(!@ldap_add($adminDS, $dn, $data)) |
|
1168 | + if (!@ldap_add($adminDS, $dn, $data)) |
|
1171 | 1169 | { |
1172 | 1170 | //echo "<p>ldap_add($adminDS,'$dn',".print_r($data,true).")</p>\n"; |
1173 | - $err = lang("Can't create dn %1",$dn).': '.$this->_error(__LINE__,$adminDS); |
|
1171 | + $err = lang("Can't create dn %1", $dn).': '.$this->_error(__LINE__, $adminDS); |
|
1174 | 1172 | $adminLDAP->ldapDisconnect(); |
1175 | 1173 | return $err; |
1176 | 1174 | } |
@@ -1187,7 +1185,7 @@ discard block |
||
1187 | 1185 | * @param int $line |
1188 | 1186 | * @return string |
1189 | 1187 | */ |
1190 | - function _error($line,$ds=null) |
|
1188 | + function _error($line, $ds = null) |
|
1191 | 1189 | { |
1192 | 1190 | return ldap_error($ds ? $ds : $this->ds).': '.__CLASS__.': '.$line; |
1193 | 1191 | } |
@@ -1202,27 +1200,27 @@ discard block |
||
1202 | 1200 | * @param array $data eGW contact data |
1203 | 1201 | * @param boolean $isUpdate |
1204 | 1202 | */ |
1205 | - function _egw2evolutionperson(&$ldapContact,$data,$isUpdate) |
|
1203 | + function _egw2evolutionperson(&$ldapContact, $data, $isUpdate) |
|
1206 | 1204 | { |
1207 | - if(!empty($data['cat_id'])) |
|
1205 | + if (!empty($data['cat_id'])) |
|
1208 | 1206 | { |
1209 | 1207 | $ldapContact['category'] = array(); |
1210 | - foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id']) as $cat) |
|
1208 | + foreach (is_array($data['cat_id']) ? $data['cat_id'] : explode(',', $data['cat_id']) as $cat) |
|
1211 | 1209 | { |
1212 | 1210 | $ldapContact['category'][] = Api\Translation::convert( |
1213 | - Api\Categories::id2name($cat),$this->charset,'utf-8'); |
|
1211 | + Api\Categories::id2name($cat), $this->charset, 'utf-8'); |
|
1214 | 1212 | } |
1215 | 1213 | } |
1216 | - foreach(array( |
|
1217 | - 'postaladdress' => $data['adr_one_street'] .'$'. $data['adr_one_locality'] .', '. $data['adr_one_region'] .'$'. $data['adr_one_postalcode'] .'$$'. $data['adr_one_countryname'], |
|
1218 | - 'homepostaladdress' => $data['adr_two_street'] .'$'. $data['adr_two_locality'] .', '. $data['adr_two_region'] .'$'. $data['adr_two_postalcode'] .'$$'. $data['adr_two_countryname'], |
|
1214 | + foreach (array( |
|
1215 | + 'postaladdress' => $data['adr_one_street'].'$'.$data['adr_one_locality'].', '.$data['adr_one_region'].'$'.$data['adr_one_postalcode'].'$$'.$data['adr_one_countryname'], |
|
1216 | + 'homepostaladdress' => $data['adr_two_street'].'$'.$data['adr_two_locality'].', '.$data['adr_two_region'].'$'.$data['adr_two_postalcode'].'$$'.$data['adr_two_countryname'], |
|
1219 | 1217 | ) as $attr => $value) |
1220 | 1218 | { |
1221 | - if($value != '$, $$$') |
|
1219 | + if ($value != '$, $$$') |
|
1222 | 1220 | { |
1223 | - $ldapContact[$attr] = Api\Translation::convert($value,$this->charset,'utf-8'); |
|
1221 | + $ldapContact[$attr] = Api\Translation::convert($value, $this->charset, 'utf-8'); |
|
1224 | 1222 | } |
1225 | - elseif($isUpdate) |
|
1223 | + elseif ($isUpdate) |
|
1226 | 1224 | { |
1227 | 1225 | $ldapContact[$attr] = array(); |
1228 | 1226 | } |
@@ -1232,7 +1230,7 @@ discard block |
||
1232 | 1230 | { |
1233 | 1231 | $ldapContact['primaryphone'] = $data[$data['tel_prefer']]; |
1234 | 1232 | } |
1235 | - elseif($isUpdate) |
|
1233 | + elseif ($isUpdate) |
|
1236 | 1234 | { |
1237 | 1235 | $ldapContact['primaryphone'] = array(); |
1238 | 1236 | } |
@@ -1247,23 +1245,23 @@ discard block |
||
1247 | 1245 | * @param array &$contact already copied fields according to the mapping |
1248 | 1246 | * @param array $data eGW contact data |
1249 | 1247 | */ |
1250 | - function _evolutionperson2egw(&$contact,$data) |
|
1248 | + function _evolutionperson2egw(&$contact, $data) |
|
1251 | 1249 | { |
1252 | 1250 | if ($data['category'] && is_array($data['category'])) |
1253 | 1251 | { |
1254 | 1252 | $contact['cat_id'] = array(); |
1255 | - foreach($data['category'] as $iii => $cat) |
|
1253 | + foreach ($data['category'] as $iii => $cat) |
|
1256 | 1254 | { |
1257 | 1255 | if (!is_int($iii)) continue; |
1258 | 1256 | |
1259 | 1257 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
1260 | 1258 | } |
1261 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
1259 | + if ($contact['cat_id']) $contact['cat_id'] = implode(',', $contact['cat_id']); |
|
1262 | 1260 | } |
1263 | 1261 | if ($data['primaryphone']) |
1264 | 1262 | { |
1265 | - unset($contact['tel_prefer']); // to not find itself |
|
1266 | - $contact['tel_prefer'] = array_search($data['primaryphone'][0],$contact); |
|
1263 | + unset($contact['tel_prefer']); // to not find itself |
|
1264 | + $contact['tel_prefer'] = array_search($data['primaryphone'][0], $contact); |
|
1267 | 1265 | } |
1268 | 1266 | } |
1269 | 1267 | |
@@ -1276,10 +1274,10 @@ discard block |
||
1276 | 1274 | * @param array &$contact already copied fields according to the mapping |
1277 | 1275 | * @param array $data eGW contact data |
1278 | 1276 | */ |
1279 | - function _inetorgperson2egw(&$contact, $data, $cn='cn') |
|
1277 | + function _inetorgperson2egw(&$contact, $data, $cn = 'cn') |
|
1280 | 1278 | { |
1281 | 1279 | $matches = null; |
1282 | - if(empty($data['givenname'][0])) |
|
1280 | + if (empty($data['givenname'][0])) |
|
1283 | 1281 | { |
1284 | 1282 | $parts = explode($data['sn'][0], $data[$cn][0]); |
1285 | 1283 | $contact['n_prefix'] = trim($parts[0]); |
@@ -1287,8 +1285,8 @@ discard block |
||
1287 | 1285 | } |
1288 | 1286 | // iOS addressbook either use "givenname surname" or "surname givenname" depending on contact preference display-order |
1289 | 1287 | // in full name, so we need to check for both when trying to parse prefix, middle name and suffix form full name |
1290 | - elseif (preg_match($preg='/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1291 | - preg_match($preg='/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1288 | + elseif (preg_match($preg = '/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
1289 | + preg_match($preg = '/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
1292 | 1290 | { |
1293 | 1291 | list(,$contact['n_prefix'], $contact['n_middle'], $contact['n_suffix']) = $matches; |
1294 | 1292 | //error_log(__METHOD__."() preg_match('$preg', '{$data[$cn][0]}') = ".array2string($matches)); |
@@ -1309,11 +1307,11 @@ discard block |
||
1309 | 1307 | * @param array &$contact already copied fields according to the mapping |
1310 | 1308 | * @param array $data eGW contact data |
1311 | 1309 | */ |
1312 | - function _posixaccount2egw(&$contact,$data) |
|
1310 | + function _posixaccount2egw(&$contact, $data) |
|
1313 | 1311 | { |
1314 | - unset($contact); // not used, but required by function signature |
|
1315 | - static $shadowExpireNow=null; |
|
1316 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
1312 | + unset($contact); // not used, but required by function signature |
|
1313 | + static $shadowExpireNow = null; |
|
1314 | + if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time() - date('Z')) / 86400); |
|
1317 | 1315 | |
1318 | 1316 | // exclude expired or deactivated accounts |
1319 | 1317 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1331,11 +1329,11 @@ discard block |
||
1331 | 1329 | * @param array &$contact already copied fields according to the mapping |
1332 | 1330 | * @param array $data eGW contact data |
1333 | 1331 | */ |
1334 | - function _mozillaabpersonalpha2egw(&$contact,$data) |
|
1332 | + function _mozillaabpersonalpha2egw(&$contact, $data) |
|
1335 | 1333 | { |
1336 | 1334 | if ($data['c']) |
1337 | 1335 | { |
1338 | - $contact['adr_one_countryname'] = ExecMethod('phpgwapi.country.get_full_name',$data['c'][0]); |
|
1336 | + $contact['adr_one_countryname'] = ExecMethod('phpgwapi.country.get_full_name', $data['c'][0]); |
|
1339 | 1337 | } |
1340 | 1338 | } |
1341 | 1339 | |
@@ -1349,7 +1347,7 @@ discard block |
||
1349 | 1347 | * @param array $data eGW contact data |
1350 | 1348 | * @param boolean $isUpdate |
1351 | 1349 | */ |
1352 | - function _egw2mozillaabpersonalpha(&$ldapContact,$data,$isUpdate) |
|
1350 | + function _egw2mozillaabpersonalpha(&$ldapContact, $data, $isUpdate) |
|
1353 | 1351 | { |
1354 | 1352 | if ($data['adr_one_countrycode']) |
1355 | 1353 | { |
@@ -1357,7 +1355,7 @@ discard block |
||
1357 | 1355 | } |
1358 | 1356 | elseif ($data['adr_one_countryname']) |
1359 | 1357 | { |
1360 | - $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
|
1358 | + $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code', $data['adr_one_countryname']); |
|
1361 | 1359 | if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
1362 | 1360 | { |
1363 | 1361 | $ldapContact['c'] = array(); // should return error... |
@@ -1378,9 +1376,9 @@ discard block |
||
1378 | 1376 | * @param array &$contact already copied fields according to the mapping |
1379 | 1377 | * @param array $data eGW contact data |
1380 | 1378 | */ |
1381 | - function _mozillaorgperson2egw(&$contact,$data) |
|
1379 | + function _mozillaorgperson2egw(&$contact, $data) |
|
1382 | 1380 | { |
1383 | - unset($contact, $data); // not used, but required by function signature |
|
1381 | + unset($contact, $data); // not used, but required by function signature |
|
1384 | 1382 | // no special handling necessary, as it supports two distinct attributes: c, cn |
1385 | 1383 | } |
1386 | 1384 | |
@@ -1394,7 +1392,7 @@ discard block |
||
1394 | 1392 | * @param array $data eGW contact data |
1395 | 1393 | * @param boolean $isUpdate |
1396 | 1394 | */ |
1397 | - function _egw2mozillaorgperson(&$ldapContact,$data,$isUpdate) |
|
1395 | + function _egw2mozillaorgperson(&$ldapContact, $data, $isUpdate) |
|
1398 | 1396 | { |
1399 | 1397 | if ($data['adr_one_countrycode']) |
1400 | 1398 | { |
@@ -1403,7 +1401,7 @@ discard block |
||
1403 | 1401 | } |
1404 | 1402 | elseif ($data['adr_one_countryname']) |
1405 | 1403 | { |
1406 | - $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code',$data['adr_one_countryname']); |
|
1404 | + $ldapContact['c'] = ExecMethod('phpgwapi.country.country_code', $data['adr_one_countryname']); |
|
1407 | 1405 | if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
1408 | 1406 | { |
1409 | 1407 | $ldapContact['c'] = array(); // should return error... |
@@ -1422,7 +1420,7 @@ discard block |
||
1422 | 1420 | * @param int $account_id account-id of the old owner |
1423 | 1421 | * @param int $new_owner account-id of the new owner |
1424 | 1422 | */ |
1425 | - function change_owner($account_id,$new_owner) |
|
1423 | + function change_owner($account_id, $new_owner) |
|
1426 | 1424 | { |
1427 | 1425 | error_log(__METHOD__."($account_id,$new_owner) not yet implemented"); |
1428 | 1426 | } |
@@ -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__); |
@@ -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 ((int)$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(); |
@@ -266,7 +282,10 @@ discard block |
||
266 | 282 | */ |
267 | 283 | 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) |
268 | 284 | { |
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"; |
|
285 | + if ((int) $this->debug >= 4) |
|
286 | + { |
|
287 | + echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
288 | + } |
|
270 | 289 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
271 | 290 | |
272 | 291 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -314,7 +333,10 @@ discard block |
||
314 | 333 | // no grants for selected owner/addressbook |
315 | 334 | if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
316 | 335 | { |
317 | - if (!isset($groupmember_sql)) return false; |
|
336 | + if (!isset($groupmember_sql)) |
|
337 | + { |
|
338 | + return false; |
|
339 | + } |
|
318 | 340 | $filter[] = substr($groupmember_sql,4); |
319 | 341 | unset($filter['owner']); |
320 | 342 | } |
@@ -354,13 +376,16 @@ discard block |
||
354 | 376 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
355 | 377 | $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
356 | 378 | } |
357 | - if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
|
379 | + if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) |
|
380 | + { |
|
381 | + // search also adds a join for custom fields! |
|
358 | 382 | { |
359 | 383 | switch(gettype($only_keys)) |
360 | 384 | { |
361 | 385 | case 'boolean': |
362 | 386 | // Correctly handled by parent class |
363 | 387 | break; |
388 | + } |
|
364 | 389 | case 'string': |
365 | 390 | $only_keys = explode(',',$only_keys); |
366 | 391 | // fall through |
@@ -370,13 +395,23 @@ discard block |
||
370 | 395 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
371 | 396 | $order_by, $all_matches, PREG_SET_ORDER)) |
372 | 397 | { |
373 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
398 | + if (!is_array($extra_cols)) |
|
399 | + { |
|
400 | + $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
401 | + } |
|
374 | 402 | foreach($all_matches as $matches) |
375 | 403 | { |
376 | 404 | $table = ''; |
377 | 405 | $column = $matches[1]; |
378 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
379 | - if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
|
406 | + if ($column[0] == '#') |
|
407 | + { |
|
408 | + continue; |
|
409 | + } |
|
410 | + // order by custom field is handeled in so_sql_cf anyway |
|
411 | + if (($key = array_search($column, $this->db_cols)) !== false) |
|
412 | + { |
|
413 | + $column = $key; |
|
414 | + } |
|
380 | 415 | if (strpos($column,'.') === false) |
381 | 416 | { |
382 | 417 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
@@ -391,10 +426,13 @@ discard block |
||
391 | 426 | } |
392 | 427 | $extra_cols[] = $table.$column.' '.$matches[2]; |
393 | 428 | //_debug_array($matches); |
394 | - if (!empty($order_by) && $table) // postgres requires explizit order by |
|
429 | + if (!empty($order_by) && $table) |
|
430 | + { |
|
431 | + // postgres requires explizit order by |
|
395 | 432 | { |
396 | 433 | $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
397 | 434 | } |
435 | + } |
|
398 | 436 | } |
399 | 437 | //_debug_array($order_by); _debug_array($extra_cols); |
400 | 438 | } |
@@ -420,7 +458,11 @@ discard block |
||
420 | 458 | } |
421 | 459 | $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
422 | 460 | |
423 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
461 | + if ($start === false) |
|
462 | + { |
|
463 | + $this->total = is_array($rows) ? count($rows) : 0; |
|
464 | + } |
|
465 | + // so_sql sets total only for $start !== false! |
|
424 | 466 | |
425 | 467 | return $rows; |
426 | 468 | } |
@@ -462,7 +504,10 @@ discard block |
||
462 | 504 | $cat_filter = array(); |
463 | 505 | foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
464 | 506 | { |
465 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
507 | + if (is_numeric($cat)) |
|
508 | + { |
|
509 | + $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
510 | + } |
|
466 | 511 | } |
467 | 512 | return $cat_filter; |
468 | 513 | } |
@@ -475,10 +520,13 @@ discard block |
||
475 | 520 | */ |
476 | 521 | function change_owner($account_id,$new_owner) |
477 | 522 | { |
478 | - if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
|
523 | + if (!$new_owner) |
|
524 | + { |
|
525 | + // otherwise we would create an account (contact_owner==0) |
|
479 | 526 | { |
480 | 527 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
481 | 528 | } |
529 | + } |
|
482 | 530 | // contacts |
483 | 531 | $this->db->update($this->table_name,array( |
484 | 532 | 'contact_owner' => $new_owner, |
@@ -523,7 +571,10 @@ discard block |
||
523 | 571 | foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
524 | 572 | false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
525 | 573 | { |
526 | - if ($member_attr) $row['members'] = array(); |
|
574 | + if ($member_attr) |
|
575 | + { |
|
576 | + $row['members'] = array(); |
|
577 | + } |
|
527 | 578 | $lists[$row['list_id']] = $row; |
528 | 579 | } |
529 | 580 | if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
@@ -564,9 +615,15 @@ discard block |
||
564 | 615 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
565 | 616 | { |
566 | 617 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
567 | - if (!$keys && !$data || !(int)$owner) return false; |
|
618 | + if (!$keys && !$data || !(int)$owner) |
|
619 | + { |
|
620 | + return false; |
|
621 | + } |
|
568 | 622 | |
569 | - if ($keys && !is_array($keys)) $keys = array('list_name' => $keys); |
|
623 | + if ($keys && !is_array($keys)) |
|
624 | + { |
|
625 | + $keys = array('list_name' => $keys); |
|
626 | + } |
|
570 | 627 | if ($keys) |
571 | 628 | { |
572 | 629 | $keys['list_owner'] = $owner; |
@@ -586,9 +643,15 @@ discard block |
||
586 | 643 | } |
587 | 644 | $data['list_modified'] = time(); |
588 | 645 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
589 | - if (!$data['list_id']) unset($data['list_id']); |
|
646 | + if (!$data['list_id']) |
|
647 | + { |
|
648 | + unset($data['list_id']); |
|
649 | + } |
|
590 | 650 | |
591 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
651 | + if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) |
|
652 | + { |
|
653 | + return false; |
|
654 | + } |
|
592 | 655 | |
593 | 656 | if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
594 | 657 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
@@ -606,7 +669,10 @@ discard block |
||
606 | 669 | |
607 | 670 | $this->add2list($list_id,$contacts,array()); |
608 | 671 | } |
609 | - if ($keys) $data += $keys; |
|
672 | + if ($keys) |
|
673 | + { |
|
674 | + $data += $keys; |
|
675 | + } |
|
610 | 676 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
611 | 677 | return $list_id; |
612 | 678 | } |
@@ -621,7 +687,10 @@ discard block |
||
621 | 687 | */ |
622 | 688 | function add2list($contact,$list,array $existing=null) |
623 | 689 | { |
624 | - if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
|
690 | + if (!(int)$list || !is_array($contact) && !(int)$contact) |
|
691 | + { |
|
692 | + return false; |
|
693 | + } |
|
625 | 694 | |
626 | 695 | if (!is_array($existing)) |
627 | 696 | { |
@@ -663,7 +732,10 @@ discard block |
||
663 | 732 | */ |
664 | 733 | function remove_from_list($contact,$list=null) |
665 | 734 | { |
666 | - if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
|
735 | + if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) |
|
736 | + { |
|
737 | + return false; |
|
738 | + } |
|
667 | 739 | |
668 | 740 | $where = array( |
669 | 741 | 'contact_id' => $contact, |
@@ -705,7 +777,10 @@ discard block |
||
705 | 777 | */ |
706 | 778 | function delete_list($list) |
707 | 779 | { |
708 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
780 | + if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) |
|
781 | + { |
|
782 | + return false; |
|
783 | + } |
|
709 | 784 | |
710 | 785 | $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
711 | 786 | |
@@ -720,7 +795,10 @@ discard block |
||
720 | 795 | */ |
721 | 796 | function lists_ctag($owner=null) |
722 | 797 | { |
723 | - if (is_null($owner)) $owner = array_keys($this->grants); |
|
798 | + if (is_null($owner)) |
|
799 | + { |
|
800 | + $owner = array_keys($this->grants); |
|
801 | + } |
|
724 | 802 | |
725 | 803 | if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
726 | 804 | __LINE__,__FILE__)->fetchColumn())) |
@@ -740,9 +818,12 @@ discard block |
||
740 | 818 | */ |
741 | 819 | function read($keys,$extra_cols='',$join='') |
742 | 820 | { |
743 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
821 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
822 | + { |
|
744 | 823 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
745 | - } else { |
|
824 | + } |
|
825 | + else |
|
826 | + { |
|
746 | 827 | $minimum_uid_length = 8; |
747 | 828 | } |
748 | 829 | |
@@ -762,7 +843,8 @@ discard block |
||
762 | 843 | |
763 | 844 | // enforce a minium uid strength |
764 | 845 | if (is_array($contact) && (!isset($contact['uid']) |
765 | - || strlen($contact['uid']) < $minimum_uid_length)) { |
|
846 | + || strlen($contact['uid']) < $minimum_uid_length)) |
|
847 | + { |
|
766 | 848 | parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
767 | 849 | } |
768 | 850 | return $contact; |
@@ -779,19 +861,28 @@ discard block |
||
779 | 861 | { |
780 | 862 | unset($extra_where); // not used, but required by function signature |
781 | 863 | |
782 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
864 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
865 | + { |
|
783 | 866 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
784 | - } else { |
|
867 | + } |
|
868 | + else |
|
869 | + { |
|
785 | 870 | $minimum_uid_length = 8; |
786 | 871 | } |
787 | 872 | |
788 | - if (is_array($keys) && count($keys)) $this->data_merge($keys); |
|
873 | + if (is_array($keys) && count($keys)) |
|
874 | + { |
|
875 | + $this->data_merge($keys); |
|
876 | + } |
|
789 | 877 | |
790 | 878 | $new_entry = !$this->data['id']; |
791 | 879 | |
792 | - if (isset($this->data['etag'])) // do we have an etag in the data to write |
|
880 | + if (isset($this->data['etag'])) |
|
881 | + { |
|
882 | + // do we have an etag in the data to write |
|
793 | 883 | { |
794 | 884 | $etag = $this->data['etag']; |
885 | + } |
|
795 | 886 | unset($this->data['etag']); |
796 | 887 | if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
797 | 888 | { |
@@ -839,7 +930,10 @@ discard block |
||
839 | 930 | */ |
840 | 931 | function read_list($list) |
841 | 932 | { |
842 | - if (!$list) return false; |
|
933 | + if (!$list) |
|
934 | + { |
|
935 | + return false; |
|
936 | + } |
|
843 | 937 | |
844 | 938 | return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
845 | 939 | } |
@@ -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) |
@@ -264,9 +263,9 @@ discard block |
||
264 | 263 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
265 | 264 | * @return boolean/array of matching rows (the row is an array of the cols) or False |
266 | 265 | */ |
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) |
|
266 | + 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) |
|
268 | 267 | { |
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"; |
|
268 | + 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"; |
|
270 | 269 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
271 | 270 | |
272 | 271 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -282,10 +281,10 @@ discard block |
||
282 | 281 | { |
283 | 282 | if ($filter['cat_id'][0] == '!') |
284 | 283 | { |
285 | - $filter['cat_id'] = substr($filter['cat_id'],1); |
|
284 | + $filter['cat_id'] = substr($filter['cat_id'], 1); |
|
286 | 285 | $not = 'NOT'; |
287 | 286 | } |
288 | - $filter[] = $this->_cat_filter($filter['cat_id'],$not); |
|
287 | + $filter[] = $this->_cat_filter($filter['cat_id'], $not); |
|
289 | 288 | unset($filter['cat_id']); |
290 | 289 | } |
291 | 290 | |
@@ -294,17 +293,17 @@ discard block |
||
294 | 293 | { |
295 | 294 | // add read ACL for groupmembers (they have no |
296 | 295 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
297 | - (!isset($filter['owner']) || in_array('0',(array)$filter['owner']))) |
|
296 | + (!isset($filter['owner']) || in_array('0', (array)$filter['owner']))) |
|
298 | 297 | { |
299 | 298 | $groupmembers = array(); |
300 | - foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $group_id) |
|
299 | + foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $group_id) |
|
301 | 300 | { |
302 | - if (($members = $GLOBALS['egw']->accounts->members($group_id,true))) |
|
301 | + if (($members = $GLOBALS['egw']->accounts->members($group_id, true))) |
|
303 | 302 | { |
304 | - $groupmembers = array_merge($groupmembers,$members); |
|
303 | + $groupmembers = array_merge($groupmembers, $members); |
|
305 | 304 | } |
306 | 305 | } |
307 | - $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.',array( |
|
306 | + $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.', array( |
|
308 | 307 | 'account_id' => array_unique($groupmembers), |
309 | 308 | )); |
310 | 309 | } |
@@ -312,34 +311,34 @@ discard block |
||
312 | 311 | if (isset($filter['owner'])) |
313 | 312 | { |
314 | 313 | // no grants for selected owner/addressbook |
315 | - if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
|
314 | + if (!($filter['owner'] = array_intersect((array)$filter['owner'], array_keys($this->grants)))) |
|
316 | 315 | { |
317 | 316 | if (!isset($groupmember_sql)) return false; |
318 | - $filter[] = substr($groupmember_sql,4); |
|
317 | + $filter[] = substr($groupmember_sql, 4); |
|
319 | 318 | unset($filter['owner']); |
320 | 319 | } |
321 | 320 | // for an owner filter, which does NOT include current user, filter out private entries |
322 | - elseif (!in_array($GLOBALS['egw_info']['user']['account_id'],$filter['owner'])) |
|
321 | + elseif (!in_array($GLOBALS['egw_info']['user']['account_id'], $filter['owner'])) |
|
323 | 322 | { |
324 | 323 | $filter['private'] = 0; |
325 | 324 | } |
326 | 325 | // if multiple addressbooks (incl. current owner) are searched, we need full acl filter |
327 | - elseif(count($filter['owner']) > 1) |
|
326 | + elseif (count($filter['owner']) > 1) |
|
328 | 327 | { |
329 | 328 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
330 | 329 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
331 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
330 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
332 | 331 | } |
333 | 332 | } |
334 | 333 | else // search all addressbooks, incl. accounts |
335 | 334 | { |
336 | 335 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
337 | 336 | { |
338 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
337 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
339 | 338 | } |
340 | 339 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
341 | 340 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
342 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
341 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
343 | 342 | } |
344 | 343 | } |
345 | 344 | if (isset($filter['list'])) |
@@ -349,21 +348,21 @@ discard block |
||
349 | 348 | unset($filter['list']); |
350 | 349 | } |
351 | 350 | // 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) |
352 | - if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' && |
|
353 | - strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter)) |
|
351 | + if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository, 0, 3) == 'sql' && |
|
352 | + strpos($join, $GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id', $filter)) |
|
354 | 353 | { |
355 | 354 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
356 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
355 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
357 | 356 | } |
358 | 357 | if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
359 | 358 | { |
360 | - switch(gettype($only_keys)) |
|
359 | + switch (gettype($only_keys)) |
|
361 | 360 | { |
362 | 361 | case 'boolean': |
363 | 362 | // Correctly handled by parent class |
364 | 363 | break; |
365 | 364 | case 'string': |
366 | - $only_keys = explode(',',$only_keys); |
|
365 | + $only_keys = explode(',', $only_keys); |
|
367 | 366 | // fall through |
368 | 367 | } |
369 | 368 | // postgres requires that expressions in order by appear in the columns of a distinct select |
@@ -371,14 +370,14 @@ discard block |
||
371 | 370 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
372 | 371 | $order_by, $all_matches, PREG_SET_ORDER)) |
373 | 372 | { |
374 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
375 | - foreach($all_matches as $matches) |
|
373 | + if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',', $extra_cols) : array(); |
|
374 | + foreach ($all_matches as $matches) |
|
376 | 375 | { |
377 | 376 | $table = ''; |
378 | 377 | $column = $matches[1]; |
379 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
378 | + if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
380 | 379 | if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
381 | - if (strpos($column,'.') === false) |
|
380 | + if (strpos($column, '.') === false) |
|
382 | 381 | { |
383 | 382 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
384 | 383 | if (isset($this->db_cols[$column])) |
@@ -394,34 +393,34 @@ discard block |
||
394 | 393 | //_debug_array($matches); |
395 | 394 | if (!empty($order_by) && $table) // postgres requires explizit order by |
396 | 395 | { |
397 | - $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
|
396 | + $order_by = str_replace($matches[0], $table.$column.' '.$matches[2].' '.$matches[3].$matches[4], $order_by); |
|
398 | 397 | } |
399 | 398 | } |
400 | 399 | //_debug_array($order_by); _debug_array($extra_cols); |
401 | 400 | } |
402 | 401 | |
403 | 402 | // Understand search by date with wildcard (????.10.??) according to user date preference |
404 | - if(is_string($criteria) && strpos($criteria, '?') !== false) |
|
403 | + if (is_string($criteria) && strpos($criteria, '?') !== false) |
|
405 | 404 | { |
406 | 405 | // First, check for a 'date', with wildcards, in the user's format |
407 | - $date_regex = str_replace('Q','d', |
|
408 | - str_replace(array('Y','m','d','.','-'), |
|
409 | - array('(?P<Y>(?:\?|\Q){4})','(?P<m>(?:\?|\Q){2})','(?P<d>(?:\?|\Q){2})','\.','\-'), |
|
406 | + $date_regex = str_replace('Q', 'd', |
|
407 | + str_replace(array('Y', 'm', 'd', '.', '-'), |
|
408 | + array('(?P<Y>(?:\?|\Q){4})', '(?P<m>(?:\?|\Q){2})', '(?P<d>(?:\?|\Q){2})', '\.', '\-'), |
|
410 | 409 | $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); |
411 | 410 | |
412 | - if(preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
411 | + if (preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
413 | 412 | { |
414 | - foreach($matches[0] as $m_id => $match) |
|
413 | + foreach ($matches[0] as $m_id => $match) |
|
415 | 414 | { |
416 | 415 | // Birthday is Y-m-d |
417 | - $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*",$criteria); |
|
416 | + $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*", $criteria); |
|
418 | 417 | } |
419 | 418 | } |
420 | 419 | } |
421 | 420 | } |
422 | - $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
421 | + $rows = & parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
423 | 422 | |
424 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
423 | + if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
425 | 424 | |
426 | 425 | return $rows; |
427 | 426 | } |
@@ -433,18 +432,18 @@ discard block |
||
433 | 432 | * @param int|array $cat_id |
434 | 433 | * @return string sql to filter by given cat |
435 | 434 | */ |
436 | - function _cat_filter($cat_id, $not='') |
|
435 | + function _cat_filter($cat_id, $not = '') |
|
437 | 436 | { |
438 | 437 | if (!is_object($GLOBALS['egw']->categories)) |
439 | 438 | { |
440 | 439 | $GLOBALS['egw']->categories = new Api\Categories; |
441 | 440 | } |
442 | - foreach($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
441 | + foreach ($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
443 | 442 | { |
444 | - $cat_filter[] = $this->db->concat("','",cat_id,"','")." $not LIKE '%,$cat,%'"; |
|
443 | + $cat_filter[] = $this->db->concat("','", cat_id, "','")." $not LIKE '%,$cat,%'"; |
|
445 | 444 | } |
446 | - $cfilter = '('.implode(' OR ',$cat_filter).')'; |
|
447 | - if(!empty($not)) |
|
445 | + $cfilter = '('.implode(' OR ', $cat_filter).')'; |
|
446 | + if (!empty($not)) |
|
448 | 447 | { |
449 | 448 | $cfilter = "( $cfilter OR cat_id IS NULL )"; |
450 | 449 | } |
@@ -461,9 +460,9 @@ discard block |
||
461 | 460 | function _cat_search($cats) |
462 | 461 | { |
463 | 462 | $cat_filter = array(); |
464 | - foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
|
463 | + foreach (is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',', $cats)) as $cat) |
|
465 | 464 | { |
466 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
465 | + if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','", cat_id, "','")." LIKE '%,$cat,%'"; |
|
467 | 466 | } |
468 | 467 | return $cat_filter; |
469 | 468 | } |
@@ -474,32 +473,32 @@ discard block |
||
474 | 473 | * @param int $account_id account-id of the old owner |
475 | 474 | * @param int $new_owner account-id of the new owner |
476 | 475 | */ |
477 | - function change_owner($account_id,$new_owner) |
|
476 | + function change_owner($account_id, $new_owner) |
|
478 | 477 | { |
479 | 478 | if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
480 | 479 | { |
481 | 480 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
482 | 481 | } |
483 | 482 | // contacts |
484 | - $this->db->update($this->table_name,array( |
|
483 | + $this->db->update($this->table_name, array( |
|
485 | 484 | 'contact_owner' => $new_owner, |
486 | - ),array( |
|
485 | + ), array( |
|
487 | 486 | 'contact_owner' => $account_id, |
488 | - ),__LINE__,__FILE__); |
|
487 | + ), __LINE__, __FILE__); |
|
489 | 488 | |
490 | 489 | // cfs |
491 | 490 | $this->db->update(self::EXTRA_TABLE, array( |
492 | 491 | 'contact_owner' => $new_owner |
493 | - ),array( |
|
492 | + ), array( |
|
494 | 493 | 'contact_owner' => $account_id |
495 | 494 | ), __LINE__, __FILE__); |
496 | 495 | |
497 | 496 | // lists |
498 | 497 | $this->db->update($this->lists_table, array( |
499 | 498 | 'list_owner' => $new_owner, |
500 | - ),array( |
|
499 | + ), array( |
|
501 | 500 | 'list_owner' => $account_id, |
502 | - ),__LINE__,__FILE__); |
|
501 | + ), __LINE__, __FILE__); |
|
503 | 502 | } |
504 | 503 | |
505 | 504 | /** |
@@ -513,21 +512,21 @@ discard block |
||
513 | 512 | * if int|array only return members from the given owners addressbook(s) |
514 | 513 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
515 | 514 | */ |
516 | - function get_lists($uids,$uid_column='list_owner',$member_attr=null,$limit_in_ab=false) |
|
515 | + function get_lists($uids, $uid_column = 'list_owner', $member_attr = null, $limit_in_ab = false) |
|
517 | 516 | { |
518 | 517 | if (is_array($uids) && array_key_exists('list_id', $uids)) |
519 | 518 | { |
520 | - $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.',array('list_id' => $uids['list_id'])); |
|
519 | + $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.', array('list_id' => $uids['list_id'])); |
|
521 | 520 | unset($uids['list_id']); |
522 | 521 | } |
523 | 522 | $lists = array(); |
524 | - foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
|
525 | - false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
523 | + foreach ($this->db->select($this->lists_table, '*', $uid_column ? array($uid_column=>$uids) : $uids, __LINE__, __FILE__, |
|
524 | + false, 'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
526 | 525 | { |
527 | 526 | if ($member_attr) $row['members'] = array(); |
528 | 527 | $lists[$row['list_id']] = $row; |
529 | 528 | } |
530 | - if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
|
529 | + if ($lists && $member_attr && in_array($member_attr, array('contact_id', 'contact_uid', 'caldav_name'))) |
|
531 | 530 | { |
532 | 531 | if ($limit_in_ab) |
533 | 532 | { |
@@ -541,10 +540,9 @@ discard block |
||
541 | 540 | $in_ab_join .= "list_owner=$this->table_name.contact_owner"; |
542 | 541 | } |
543 | 542 | } |
544 | - foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
543 | + foreach ($this->db->select($this->ab2list_table, "$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
545 | 544 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
546 | - __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
|
547 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
545 | + __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) |
|
548 | 546 | { |
549 | 547 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
550 | 548 | } |
@@ -562,7 +560,7 @@ discard block |
||
562 | 560 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
563 | 561 | * @return int|boolean integer list_id or false on error |
564 | 562 | */ |
565 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
563 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
566 | 564 | { |
567 | 565 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
568 | 566 | if (!$keys && !$data || !(int)$owner) return false; |
@@ -576,7 +574,7 @@ discard block |
||
576 | 574 | { |
577 | 575 | $data['list_owner'] = $owner; |
578 | 576 | } |
579 | - if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys,__LINE__,__FILE__)->fetchColumn())) |
|
577 | + if (!$keys || !($list_id = $this->db->select($this->lists_table, 'list_id', $keys, __LINE__, __FILE__)->fetchColumn())) |
|
580 | 578 | { |
581 | 579 | $data['list_created'] = time(); |
582 | 580 | $data['list_creator'] = $GLOBALS['egw_info']['user']['account_id']; |
@@ -589,9 +587,9 @@ discard block |
||
589 | 587 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
590 | 588 | if (!$data['list_id']) unset($data['list_id']); |
591 | 589 | |
592 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
590 | + if (!$this->db->insert($this->lists_table, $data, $keys, __LINE__, __FILE__)) return false; |
|
593 | 591 | |
594 | - if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
|
592 | + if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table, 'list_id')) && |
|
595 | 593 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
596 | 594 | { |
597 | 595 | $update = array(); |
@@ -603,9 +601,9 @@ discard block |
||
603 | 601 | { |
604 | 602 | $update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf'; |
605 | 603 | } |
606 | - $this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__); |
|
604 | + $this->db->update($this->lists_table, $update, array('list_id'=>$list_id), __LINE__, __FILE__); |
|
607 | 605 | |
608 | - $this->add2list($list_id,$contacts,array()); |
|
606 | + $this->add2list($list_id, $contacts, array()); |
|
609 | 607 | } |
610 | 608 | if ($keys) $data += $keys; |
611 | 609 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
@@ -620,39 +618,39 @@ discard block |
||
620 | 618 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
621 | 619 | * @return false on error |
622 | 620 | */ |
623 | - function add2list($contact,$list,array $existing=null) |
|
621 | + function add2list($contact, $list, array $existing = null) |
|
624 | 622 | { |
625 | 623 | if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
626 | 624 | |
627 | 625 | if (!is_array($existing)) |
628 | 626 | { |
629 | 627 | $existing = array(); |
630 | - foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row) |
|
628 | + foreach ($this->db->select($this->ab2list_table, 'contact_id', array('list_id'=>$list), __LINE__, __FILE__) as $row) |
|
631 | 629 | { |
632 | 630 | $existing[] = $row['contact_id']; |
633 | 631 | } |
634 | 632 | } |
635 | - if (!($to_add = array_diff((array)$contact,$existing))) |
|
633 | + if (!($to_add = array_diff((array)$contact, $existing))) |
|
636 | 634 | { |
637 | - return true; // no need to insert it, would give sql error |
|
635 | + return true; // no need to insert it, would give sql error |
|
638 | 636 | } |
639 | - foreach($to_add as $contact) |
|
637 | + foreach ($to_add as $contact) |
|
640 | 638 | { |
641 | - $this->db->insert($this->ab2list_table,array( |
|
639 | + $this->db->insert($this->ab2list_table, array( |
|
642 | 640 | 'contact_id' => $contact, |
643 | 641 | 'list_id' => $list, |
644 | 642 | 'list_added' => time(), |
645 | 643 | 'list_added_by' => $GLOBALS['egw_info']['user']['account_id'], |
646 | - ),array(),__LINE__,__FILE__); |
|
644 | + ), array(), __LINE__, __FILE__); |
|
647 | 645 | } |
648 | 646 | // update etag |
649 | - return $this->db->update($this->lists_table,array( |
|
647 | + return $this->db->update($this->lists_table, array( |
|
650 | 648 | 'list_etag=list_etag+1', |
651 | 649 | 'list_modified' => time(), |
652 | 650 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
653 | - ),array( |
|
651 | + ), array( |
|
654 | 652 | 'list_id' => $list, |
655 | - ),__LINE__,__FILE__); |
|
653 | + ), __LINE__, __FILE__); |
|
656 | 654 | } |
657 | 655 | |
658 | 656 | /** |
@@ -662,7 +660,7 @@ discard block |
||
662 | 660 | * @param int $list =null list-id or null to remove from all lists |
663 | 661 | * @return false on error |
664 | 662 | */ |
665 | - function remove_from_list($contact,$list=null) |
|
663 | + function remove_from_list($contact, $list = null) |
|
666 | 664 | { |
667 | 665 | if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
668 | 666 | |
@@ -676,24 +674,24 @@ discard block |
||
676 | 674 | else |
677 | 675 | { |
678 | 676 | $list = array(); |
679 | - foreach($this->db->select($this->ab2list_table,'list_id',$where,__LINE__,__FILE__) as $row) |
|
677 | + foreach ($this->db->select($this->ab2list_table, 'list_id', $where, __LINE__, __FILE__) as $row) |
|
680 | 678 | { |
681 | 679 | $list[] = $row['list_id']; |
682 | 680 | } |
683 | 681 | } |
684 | - if (!$this->db->delete($this->ab2list_table,$where,__LINE__,__FILE__)) |
|
682 | + if (!$this->db->delete($this->ab2list_table, $where, __LINE__, __FILE__)) |
|
685 | 683 | { |
686 | 684 | return false; |
687 | 685 | } |
688 | - foreach((array)$list as $list_id) |
|
686 | + foreach ((array)$list as $list_id) |
|
689 | 687 | { |
690 | - $this->db->update($this->lists_table,array( |
|
688 | + $this->db->update($this->lists_table, array( |
|
691 | 689 | 'list_etag=list_etag+1', |
692 | 690 | 'list_modified' => time(), |
693 | 691 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
694 | - ),array( |
|
692 | + ), array( |
|
695 | 693 | 'list_id' => $list_id, |
696 | - ),__LINE__,__FILE__); |
|
694 | + ), __LINE__, __FILE__); |
|
697 | 695 | } |
698 | 696 | return true; |
699 | 697 | } |
@@ -706,9 +704,9 @@ discard block |
||
706 | 704 | */ |
707 | 705 | function delete_list($list) |
708 | 706 | { |
709 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
707 | + if (!$this->db->delete($this->lists_table, array('list_id' => $list), __LINE__, __FILE__)) return false; |
|
710 | 708 | |
711 | - $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
|
709 | + $this->db->delete($this->ab2list_table, array('list_id' => $list), __LINE__, __FILE__); |
|
712 | 710 | |
713 | 711 | return $this->db->affected_rows(); |
714 | 712 | } |
@@ -719,12 +717,12 @@ discard block |
||
719 | 717 | * @param int|array $owner =null null for all lists user has access too |
720 | 718 | * @return int |
721 | 719 | */ |
722 | - function lists_ctag($owner=null) |
|
720 | + function lists_ctag($owner = null) |
|
723 | 721 | { |
724 | 722 | if (is_null($owner)) $owner = array_keys($this->grants); |
725 | 723 | |
726 | - if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
|
727 | - __LINE__,__FILE__)->fetchColumn())) |
|
724 | + if (!($modified = $this->db->select($this->lists_table, 'MAX(list_modified)', array('list_owner'=>$owner), |
|
725 | + __LINE__, __FILE__)->fetchColumn())) |
|
728 | 726 | { |
729 | 727 | return 0; |
730 | 728 | } |
@@ -739,7 +737,7 @@ discard block |
||
739 | 737 | * @param string $join |
740 | 738 | * @return array|boolean |
741 | 739 | */ |
742 | - function read($keys,$extra_cols='',$join='') |
|
740 | + function read($keys, $extra_cols = '', $join = '') |
|
743 | 741 | { |
744 | 742 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
745 | 743 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -752,11 +750,11 @@ discard block |
||
752 | 750 | $keys = array('uid' => $keys); |
753 | 751 | } |
754 | 752 | try { |
755 | - $contact = parent::read($keys,$extra_cols,$join); |
|
753 | + $contact = parent::read($keys, $extra_cols, $join); |
|
756 | 754 | } |
757 | 755 | // catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267) |
758 | 756 | // caused by non-ascii chars compared with ascii field uid |
759 | - catch(Api\Db\Exception $e) { |
|
757 | + catch (Api\Db\Exception $e) { |
|
760 | 758 | _egw_log_exception($e); |
761 | 759 | return false; |
762 | 760 | } |
@@ -764,7 +762,7 @@ discard block |
||
764 | 762 | // enforce a minium uid strength |
765 | 763 | if (is_array($contact) && (!isset($contact['uid']) |
766 | 764 | || strlen($contact['uid']) < $minimum_uid_length)) { |
767 | - parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
|
765 | + parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook', $contact['id']))); |
|
768 | 766 | } |
769 | 767 | return $contact; |
770 | 768 | } |
@@ -778,7 +776,7 @@ discard block |
||
778 | 776 | */ |
779 | 777 | function save($keys = NULL, $extra_where = NULL) |
780 | 778 | { |
781 | - unset($extra_where); // not used, but required by function signature |
|
779 | + unset($extra_where); // not used, but required by function signature |
|
782 | 780 | |
783 | 781 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
784 | 782 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -794,9 +792,9 @@ discard block |
||
794 | 792 | { |
795 | 793 | $etag = $this->data['etag']; |
796 | 794 | unset($this->data['etag']); |
797 | - if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
|
795 | + if (!($err = parent::save(array('contact_etag=contact_etag+1'), array('contact_etag' => $etag)))) |
|
798 | 796 | { |
799 | - $this->data['etag'] = $etag+1; |
|
797 | + $this->data['etag'] = $etag + 1; |
|
800 | 798 | } |
801 | 799 | else |
802 | 800 | { |
@@ -816,7 +814,7 @@ discard block |
||
816 | 814 | // enforce a minium uid strength |
817 | 815 | if (!isset($this->data['uid']) || strlen($this->data['uid']) < $minimum_uid_length) |
818 | 816 | { |
819 | - $update['uid'] = Api\CalDAV::generate_uid('addressbook',$this->data['id']); |
|
817 | + $update['uid'] = Api\CalDAV::generate_uid('addressbook', $this->data['id']); |
|
820 | 818 | //echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>"; |
821 | 819 | } |
822 | 820 | // set carddav_name, if not given by caller |
@@ -842,7 +840,7 @@ discard block |
||
842 | 840 | { |
843 | 841 | if (!$list) return false; |
844 | 842 | |
845 | - return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
|
843 | + return $this->db->select($this->lists_table, '*', array('list_id'=>$list), __LINE__, __FILE__)->fetch(); |
|
846 | 844 | } |
847 | 845 | |
848 | 846 | /** |
@@ -853,9 +851,9 @@ discard block |
||
853 | 851 | * @param array $extra_cols =array() extra-data to be saved |
854 | 852 | * @return bool false on success, errornumber on failure |
855 | 853 | */ |
856 | - function save_customfields($data, array $extra_cols=array()) |
|
854 | + function save_customfields($data, array $extra_cols = array()) |
|
857 | 855 | { |
858 | - return parent::save_customfields($data, array('contact_owner' => $data['owner'])+$extra_cols); |
|
856 | + return parent::save_customfields($data, array('contact_owner' => $data['owner']) + $extra_cols); |
|
859 | 857 | } |
860 | 858 | |
861 | 859 | /** |
@@ -864,6 +862,6 @@ discard block |
||
864 | 862 | */ |
865 | 863 | function delete_customfields($data) |
866 | 864 | { |
867 | - $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
|
865 | + $this->db->delete($this->extra_table, $data, __LINE__, __FILE__); |
|
868 | 866 | } |
869 | 867 | } |
@@ -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 | + } |
|
426 | 448 | } |
427 | - if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
449 | + if (!$ids) |
|
450 | + { |
|
451 | + return array(); |
|
452 | + } |
|
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 | |
@@ -613,7 +654,10 @@ discard block |
||
613 | 654 | unset($filter['adr_one_countrycode']); |
614 | 655 | } |
615 | 656 | // Hide deleted items unless type is specifically deleted |
616 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
657 | + if(!is_array($filter)) |
|
658 | + { |
|
659 | + $filter = $filter ? (array) $filter : array(); |
|
660 | + } |
|
617 | 661 | |
618 | 662 | if (isset($filter['cols_to_search'])) |
619 | 663 | { |
@@ -624,10 +668,13 @@ discard block |
||
624 | 668 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
625 | 669 | if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
626 | 670 | { |
627 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
671 | + if ($join && strpos($join,'RIGHT JOIN') !== false) |
|
672 | + { |
|
673 | + // used eg. to search for groups |
|
628 | 674 | { |
629 | 675 | $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
630 | 676 | } |
677 | + } |
|
631 | 678 | else |
632 | 679 | { |
633 | 680 | $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
@@ -675,7 +722,10 @@ discard block |
||
675 | 722 | unset($cols[$key]); |
676 | 723 | } |
677 | 724 | } |
678 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
725 | + if ($col=='contact_id') |
|
726 | + { |
|
727 | + $col='egw_addressbook.contact_id'; |
|
728 | + } |
|
679 | 729 | } |
680 | 730 | |
681 | 731 | $backend->columns_to_search = $cols; |
@@ -750,7 +800,11 @@ discard block |
||
750 | 800 | { |
751 | 801 | foreach($this->columns_to_search as $col) |
752 | 802 | { |
753 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
803 | + if ($col != 'contact_value') |
|
804 | + { |
|
805 | + $param['search'][$col] = $search; |
|
806 | + } |
|
807 | + // we dont search the customfields |
|
754 | 808 | } |
755 | 809 | } |
756 | 810 | } |
@@ -770,11 +824,17 @@ discard block |
||
770 | 824 | $rows = $this->somain->organisations($param); |
771 | 825 | $this->total = $this->somain->total; |
772 | 826 | |
773 | - if (!$rows) return array(); |
|
827 | + if (!$rows) |
|
828 | + { |
|
829 | + return array(); |
|
830 | + } |
|
774 | 831 | |
775 | 832 | foreach($rows as $n => $row) |
776 | 833 | { |
777 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
834 | + if (strpos($row['org_name'],'&')!==false) |
|
835 | + { |
|
836 | + $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
837 | + } |
|
778 | 838 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
779 | 839 | foreach(array( |
780 | 840 | 'org_unit' => lang('departments'), |
@@ -787,7 +847,10 @@ discard block |
||
787 | 847 | } |
788 | 848 | else |
789 | 849 | { |
790 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
850 | + if (strpos($row[$by],'&')!==false) |
|
851 | + { |
|
852 | + $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
853 | + } |
|
791 | 854 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
792 | 855 | } |
793 | 856 | } |
@@ -847,7 +910,10 @@ discard block |
||
847 | 910 | */ |
848 | 911 | function get_backend($keys=null,$owner=null) |
849 | 912 | { |
850 | - if ($owner === '') $owner = null; |
|
913 | + if ($owner === '') |
|
914 | + { |
|
915 | + $owner = null; |
|
916 | + } |
|
851 | 917 | |
852 | 918 | $contact_id = !is_array($keys) ? $keys : |
853 | 919 | (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
@@ -911,7 +977,10 @@ discard block |
||
911 | 977 | $ds = $GLOBALS['egw']->ldap->ldapConnect(); |
912 | 978 | $ldap_contacts = new Ldap(null, $ds); |
913 | 979 | |
914 | - if (!is_array($type)) $type = explode(',', $type); |
|
980 | + if (!is_array($type)) |
|
981 | + { |
|
982 | + $type = explode(',', $type); |
|
983 | + } |
|
915 | 984 | |
916 | 985 | $start = $n = 0; |
917 | 986 | $num = 100; |
@@ -927,7 +996,10 @@ discard block |
||
927 | 996 | { |
928 | 997 | foreach($contacts as $contact) |
929 | 998 | { |
930 | - if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
999 | + if ($contact['account_id']) |
|
1000 | + { |
|
1001 | + $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
1002 | + } |
|
931 | 1003 | |
932 | 1004 | $ldap_contacts->data = $contact; |
933 | 1005 | $n++; |
@@ -955,10 +1027,13 @@ discard block |
||
955 | 1027 | false, $filter) as $contact) |
956 | 1028 | { |
957 | 1029 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
958 | - if ($contact['jpegphoto']) // photo is NOT read by LDAP backend on search, need to do an extra read |
|
1030 | + if ($contact['jpegphoto']) |
|
1031 | + { |
|
1032 | + // photo is NOT read by LDAP backend on search, need to do an extra read |
|
959 | 1033 | { |
960 | 1034 | $contact = $ldap_contacts->read($contact['id']); |
961 | 1035 | } |
1036 | + } |
|
962 | 1037 | unset($contact['id']); // ldap uid/account_lid |
963 | 1038 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
964 | 1039 | { |
@@ -992,7 +1067,10 @@ discard block |
||
992 | 1067 | */ |
993 | 1068 | function get_lists($required=Api\Acl::READ,$extra_labels=null) |
994 | 1069 | { |
995 | - if (!method_exists($this->somain,'get_lists')) return false; |
|
1070 | + if (!method_exists($this->somain,'get_lists')) |
|
1071 | + { |
|
1072 | + return false; |
|
1073 | + } |
|
996 | 1074 | |
997 | 1075 | $uids = array(); |
998 | 1076 | foreach($this->grants as $uid => $rights) |
@@ -1026,7 +1104,10 @@ discard block |
||
1026 | 1104 | function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
1027 | 1105 | { |
1028 | 1106 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1029 | - if (!method_exists($backend, 'get_lists')) return false; |
|
1107 | + if (!method_exists($backend, 'get_lists')) |
|
1108 | + { |
|
1109 | + return false; |
|
1110 | + } |
|
1030 | 1111 | |
1031 | 1112 | return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
1032 | 1113 | } |
@@ -1043,7 +1124,10 @@ discard block |
||
1043 | 1124 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
1044 | 1125 | { |
1045 | 1126 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1046 | - if (!method_exists($backend, 'add_list')) return false; |
|
1127 | + if (!method_exists($backend, 'add_list')) |
|
1128 | + { |
|
1129 | + return false; |
|
1130 | + } |
|
1047 | 1131 | |
1048 | 1132 | return $backend->add_list($keys,$owner,$contacts,$data); |
1049 | 1133 | } |
@@ -1058,7 +1142,10 @@ discard block |
||
1058 | 1142 | */ |
1059 | 1143 | function add2list($contact,$list,array $existing=null) |
1060 | 1144 | { |
1061 | - if (!method_exists($this->somain,'add2list')) return false; |
|
1145 | + if (!method_exists($this->somain,'add2list')) |
|
1146 | + { |
|
1147 | + return false; |
|
1148 | + } |
|
1062 | 1149 | |
1063 | 1150 | return $this->somain->add2list($contact,$list,$existing); |
1064 | 1151 | } |
@@ -1072,7 +1159,10 @@ discard block |
||
1072 | 1159 | */ |
1073 | 1160 | function remove_from_list($contact,$list=null) |
1074 | 1161 | { |
1075 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
1162 | + if (!method_exists($this->somain,'remove_from_list')) |
|
1163 | + { |
|
1164 | + return false; |
|
1165 | + } |
|
1076 | 1166 | |
1077 | 1167 | return $this->somain->remove_from_list($contact,$list); |
1078 | 1168 | } |
@@ -1085,7 +1175,10 @@ discard block |
||
1085 | 1175 | */ |
1086 | 1176 | function delete_list($list) |
1087 | 1177 | { |
1088 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
1178 | + if (!method_exists($this->somain,'delete_list')) |
|
1179 | + { |
|
1180 | + return false; |
|
1181 | + } |
|
1089 | 1182 | |
1090 | 1183 | return $this->somain->delete_list($list); |
1091 | 1184 | } |
@@ -1098,7 +1191,10 @@ discard block |
||
1098 | 1191 | */ |
1099 | 1192 | function read_list($list) |
1100 | 1193 | { |
1101 | - if (!method_exists($this->somain,'read_list')) return false; |
|
1194 | + if (!method_exists($this->somain,'read_list')) |
|
1195 | + { |
|
1196 | + return false; |
|
1197 | + } |
|
1102 | 1198 | |
1103 | 1199 | return $this->somain->read_list($list); |
1104 | 1200 | } |
@@ -1124,7 +1220,10 @@ discard block |
||
1124 | 1220 | */ |
1125 | 1221 | function lists_ctag($owner=null) |
1126 | 1222 | { |
1127 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
1223 | + if (!method_exists($this->somain,'lists_ctag')) |
|
1224 | + { |
|
1225 | + return 0; |
|
1226 | + } |
|
1128 | 1227 | |
1129 | 1228 | return $this->somain->lists_ctag($owner); |
1130 | 1229 | } |
@@ -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 | |
@@ -602,18 +602,18 @@ discard block |
||
602 | 602 | * @param string $join ='' sql to do a join (only used by sql backend!), eg. " RIGHT JOIN egw_accounts USING(account_id)" |
603 | 603 | * @return array of matching rows (the row is an array of the cols) or False |
604 | 604 | */ |
605 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='') |
|
605 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '') |
|
606 | 606 | { |
607 | 607 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',".array2string($start).','.array2string($filter,true).",'$join')"); |
608 | 608 | |
609 | 609 | // Handle 'None' country option |
610 | - if(is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
610 | + if (is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
611 | 611 | { |
612 | 612 | $filter[] = 'adr_one_countrycode IS NULL'; |
613 | 613 | unset($filter['adr_one_countrycode']); |
614 | 614 | } |
615 | 615 | // Hide deleted items unless type is specifically deleted |
616 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
616 | + if (!is_array($filter)) $filter = $filter ? (array)$filter : array(); |
|
617 | 617 | |
618 | 618 | if (isset($filter['cols_to_search'])) |
619 | 619 | { |
@@ -622,22 +622,22 @@ discard block |
||
622 | 622 | } |
623 | 623 | |
624 | 624 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
625 | - if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
625 | + if (!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
626 | 626 | { |
627 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
627 | + if ($join && strpos($join, 'RIGHT JOIN') !== false) // used eg. to search for groups |
|
628 | 628 | { |
629 | - $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
|
629 | + $filter[] = '(contact_tid != \''.self::DELETED_TYPE.'\' OR contact_tid IS NULL)'; |
|
630 | 630 | } |
631 | 631 | else |
632 | 632 | { |
633 | - $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
633 | + $filter[] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
634 | 634 | } |
635 | 635 | } |
636 | - elseif(is_null($filter['tid'])) |
|
636 | + elseif (is_null($filter['tid'])) |
|
637 | 637 | { |
638 | - unset($filter['tid']); // return all entries incl. deleted |
|
638 | + unset($filter['tid']); // return all entries incl. deleted |
|
639 | 639 | } |
640 | - $backend = $this->get_backend(null,$filter['owner']); |
|
640 | + $backend = $this->get_backend(null, $filter['owner']); |
|
641 | 641 | // single string to search for --> create so_sql conformant search criterial for the standard search columns |
642 | 642 | if ($criteria && !is_array($criteria)) |
643 | 643 | { |
@@ -658,34 +658,34 @@ discard block |
||
658 | 658 | { |
659 | 659 | $cols = $this->account_cols_to_search; |
660 | 660 | } |
661 | - if($backend instanceof Sql) |
|
661 | + if ($backend instanceof Sql) |
|
662 | 662 | { |
663 | 663 | // Keep a string, let the parent handle it |
664 | 664 | $criteria = $search; |
665 | 665 | |
666 | - foreach($cols as $key => &$col) |
|
666 | + foreach ($cols as $key => &$col) |
|
667 | 667 | { |
668 | - if($col != Sql::EXTRA_VALUE && |
|
668 | + if ($col != Sql::EXTRA_VALUE && |
|
669 | 669 | $col != Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE && |
670 | 670 | !array_key_exists($col, $backend->db_cols)) |
671 | 671 | { |
672 | - if(!($col = array_search($col, $backend->db_cols))) |
|
672 | + if (!($col = array_search($col, $backend->db_cols))) |
|
673 | 673 | { |
674 | 674 | // Can't search this column, it will error if we try |
675 | 675 | unset($cols[$key]); |
676 | 676 | } |
677 | 677 | } |
678 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
678 | + if ($col == 'contact_id') $col = 'egw_addressbook.contact_id'; |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | $backend->columns_to_search = $cols; |
682 | 682 | } |
683 | 683 | else |
684 | 684 | { |
685 | - foreach($cols as $col) |
|
685 | + foreach ($cols as $col) |
|
686 | 686 | { |
687 | 687 | // remove from LDAP backend not understood use-AND-syntax |
688 | - $criteria[$col] = str_replace(' +',' ',$search); |
|
688 | + $criteria[$col] = str_replace(' +', ' ', $search); |
|
689 | 689 | } |
690 | 690 | } |
691 | 691 | } |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | |
710 | 710 | if ($rows) |
711 | 711 | { |
712 | - foreach($rows as $n => $row) |
|
712 | + foreach ($rows as $n => $row) |
|
713 | 713 | { |
714 | 714 | $rows[$n] = $this->db2data($row); |
715 | 715 | } |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | */ |
733 | 733 | function organisations($param) |
734 | 734 | { |
735 | - if (!method_exists($this->somain,'organisations')) |
|
735 | + if (!method_exists($this->somain, 'organisations')) |
|
736 | 736 | { |
737 | 737 | $this->total = 0; |
738 | 738 | return false; |
@@ -741,16 +741,16 @@ discard block |
||
741 | 741 | { |
742 | 742 | $search = $param['search']; |
743 | 743 | $param['search'] = array(); |
744 | - if($this->somain instanceof Sql) |
|
744 | + if ($this->somain instanceof Sql) |
|
745 | 745 | { |
746 | 746 | // Keep the string, let the parent deal with it |
747 | 747 | $param['search'] = $search; |
748 | 748 | } |
749 | 749 | else |
750 | 750 | { |
751 | - foreach($this->columns_to_search as $col) |
|
751 | + foreach ($this->columns_to_search as $col) |
|
752 | 752 | { |
753 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
753 | + if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
754 | 754 | } |
755 | 755 | } |
756 | 756 | } |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | { |
759 | 759 | $param['search'] = $this->data2db($param['search']); |
760 | 760 | } |
761 | - if(!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
761 | + if (!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
762 | 762 | { |
763 | - $param['col_filter'][] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
763 | + $param['col_filter'][] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
764 | 764 | } |
765 | - elseif(is_null($param['col_filter']['tid'])) |
|
765 | + elseif (is_null($param['col_filter']['tid'])) |
|
766 | 766 | { |
767 | - unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
767 | + unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | $rows = $this->somain->organisations($param); |
@@ -772,11 +772,11 @@ discard block |
||
772 | 772 | |
773 | 773 | if (!$rows) return array(); |
774 | 774 | |
775 | - foreach($rows as $n => $row) |
|
775 | + foreach ($rows as $n => $row) |
|
776 | 776 | { |
777 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
777 | + if (strpos($row['org_name'], '&') !== false) $row['org_name'] = str_replace('&', '*AND*', $row['org_name']); |
|
778 | 778 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
779 | - foreach(array( |
|
779 | + foreach (array( |
|
780 | 780 | 'org_unit' => lang('departments'), |
781 | 781 | 'adr_one_locality' => lang('locations'), |
782 | 782 | ) as $by => $by_label) |
@@ -787,7 +787,7 @@ discard block |
||
787 | 787 | } |
788 | 788 | else |
789 | 789 | { |
790 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
790 | + if (strpos($row[$by], '&') !== false) $row[$by] = str_replace('&', '*AND*', $row[$by]); |
|
791 | 791 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
792 | 792 | } |
793 | 793 | } |
@@ -820,11 +820,11 @@ discard block |
||
820 | 820 | function deleteaccount($data) |
821 | 821 | { |
822 | 822 | $account_id = $data['account_id']; |
823 | - $new_owner = $data['new_owner']; |
|
823 | + $new_owner = $data['new_owner']; |
|
824 | 824 | |
825 | 825 | if (!$new_owner) |
826 | 826 | { |
827 | - $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
827 | + $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
828 | 828 | |
829 | 829 | if (method_exists($this->somain, 'get_lists') && |
830 | 830 | ($lists = $this->somain->get_lists($account_id))) |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | } |
835 | 835 | else |
836 | 836 | { |
837 | - $this->somain->change_owner($account_id,$new_owner); |
|
837 | + $this->somain->change_owner($account_id, $new_owner); |
|
838 | 838 | } |
839 | 839 | } |
840 | 840 | |
@@ -845,16 +845,15 @@ discard block |
||
845 | 845 | * @param int $owner =null account_id of owner or 0 for accounts |
846 | 846 | * @return Sql |
847 | 847 | */ |
848 | - function get_backend($keys=null,$owner=null) |
|
848 | + function get_backend($keys = null, $owner = null) |
|
849 | 849 | { |
850 | 850 | if ($owner === '') $owner = null; |
851 | 851 | |
852 | - $contact_id = !is_array($keys) ? $keys : |
|
853 | - (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
852 | + $contact_id = !is_array($keys) ? $keys : (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
854 | 853 | |
855 | 854 | if ($this->contact_repository != $this->account_repository && is_object($this->so_accounts) && |
856 | 855 | (!is_null($owner) && !$owner || is_array($keys) && $keys['account_id'] || !is_null($contact_id) && |
857 | - ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id) )|| |
|
856 | + ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id)) || |
|
858 | 857 | $this->contact_repository == 'ldap' && is_numeric($contact_id)))) |
859 | 858 | { |
860 | 859 | return $this->so_accounts; |
@@ -870,28 +869,28 @@ discard block |
||
870 | 869 | * @param int $owner =null account_id of owner or 0 for accounts |
871 | 870 | * @return array with eGW contact field names |
872 | 871 | */ |
873 | - function get_fields($type='all',$contact_id=null,$owner=null) |
|
872 | + function get_fields($type = 'all', $contact_id = null, $owner = null) |
|
874 | 873 | { |
875 | - $def = $this->db->get_table_definitions('api','egw_addressbook'); |
|
874 | + $def = $this->db->get_table_definitions('api', 'egw_addressbook'); |
|
876 | 875 | |
877 | 876 | $all_fields = array(); |
878 | - foreach(array_keys($def['fd']) as $field) |
|
877 | + foreach (array_keys($def['fd']) as $field) |
|
879 | 878 | { |
880 | - $all_fields[] = substr($field,0,8) == 'contact_' ? substr($field,8) : $field; |
|
879 | + $all_fields[] = substr($field, 0, 8) == 'contact_' ? substr($field, 8) : $field; |
|
881 | 880 | } |
882 | 881 | if ($type == 'all') |
883 | 882 | { |
884 | 883 | return $all_fields; |
885 | 884 | } |
886 | - $backend =& $this->get_backend($contact_id,$owner); |
|
885 | + $backend = & $this->get_backend($contact_id, $owner); |
|
887 | 886 | |
888 | - $supported_fields = method_exists($backend,supported_fields) ? $backend->supported_fields() : $all_fields; |
|
887 | + $supported_fields = method_exists($backend, supported_fields) ? $backend->supported_fields() : $all_fields; |
|
889 | 888 | |
890 | 889 | if ($type == 'supported') |
891 | 890 | { |
892 | 891 | return $supported_fields; |
893 | 892 | } |
894 | - return array_diff($all_fields,$supported_fields); |
|
893 | + return array_diff($all_fields, $supported_fields); |
|
895 | 894 | } |
896 | 895 | |
897 | 896 | /** |
@@ -919,13 +918,12 @@ discard block |
||
919 | 918 | // direction SQL --> LDAP, either only accounts, or only contacts or both |
920 | 919 | if (($do = array_intersect($type, array('contacts', 'accounts')))) |
921 | 920 | { |
922 | - $filter = count($do) == 2 ? null : |
|
923 | - array($do[0] == 'contacts' ? 'contact_owner != 0' : 'contact_owner = 0'); |
|
921 | + $filter = count($do) == 2 ? null : array($do[0] == 'contacts' ? 'contact_owner != 0' : 'contact_owner = 0'); |
|
924 | 922 | |
925 | - while (($contacts = $sql_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
926 | - array($start,$num),$filter))) |
|
923 | + while (($contacts = $sql_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
924 | + array($start, $num), $filter))) |
|
927 | 925 | { |
928 | - foreach($contacts as $contact) |
|
926 | + foreach ($contacts as $contact) |
|
929 | 927 | { |
930 | 928 | if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
931 | 929 | |
@@ -946,12 +944,12 @@ discard block |
||
946 | 944 | } |
947 | 945 | } |
948 | 946 | // direction LDAP --> SQL: either "sql" (contacts and accounts) or "accounts-back" (only accounts) |
949 | - if (($do = array_intersect(array('accounts-back','sql'), $type))) |
|
947 | + if (($do = array_intersect(array('accounts-back', 'sql'), $type))) |
|
950 | 948 | { |
951 | 949 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)); |
952 | 950 | $filter = in_array('sql', $do) ? null : array('owner' => 0); |
953 | 951 | |
954 | - foreach($ldap_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
952 | + foreach ($ldap_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
955 | 953 | false, $filter) as $contact) |
956 | 954 | { |
957 | 955 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
@@ -960,7 +958,7 @@ discard block |
||
960 | 958 | $contact = $ldap_contacts->read($contact['id']); |
961 | 959 | } |
962 | 960 | $old_contact_id = $contact['id']; |
963 | - unset($contact['id']); // ldap uid/account_lid |
|
961 | + unset($contact['id']); // ldap uid/account_lid |
|
964 | 962 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
965 | 963 | { |
966 | 964 | $contact['id'] = $old['id']; |
@@ -972,24 +970,24 @@ discard block |
||
972 | 970 | { |
973 | 971 | echo '<p style="margin: 0px;">'.$n.': '.$contact['n_fn']. |
974 | 972 | ($contact['org_name'] ? ' ('.$contact['org_name'].')' : '')." --> SQL (". |
975 | - ($contact['owner']?lang('User'):lang('Contact')).")<br>\n"; |
|
973 | + ($contact['owner'] ? lang('User') : lang('Contact')).")<br>\n"; |
|
976 | 974 | |
977 | 975 | $new_contact_id = $sql_contacts->data['id']; |
978 | - echo " " . $old_contact_id . " --> " . $new_contact_id . " / "; |
|
976 | + echo " ".$old_contact_id." --> ".$new_contact_id." / "; |
|
979 | 977 | |
980 | - $tq = $this->db->update('egw_links',array( |
|
978 | + $tq = $this->db->update('egw_links', array( |
|
981 | 979 | 'link_id1' => $new_contact_id, |
982 | - ),array( |
|
980 | + ), array( |
|
983 | 981 | 'link_app1' => 'addressbook', |
984 | 982 | 'link_id1' => $old_contact_id |
985 | - ),__LINE__,__FILE__); |
|
983 | + ), __LINE__, __FILE__); |
|
986 | 984 | |
987 | - $tq = $this->db->update('egw_links',array( |
|
985 | + $tq = $this->db->update('egw_links', array( |
|
988 | 986 | 'link_id2' => $new_contact_id, |
989 | - ),array( |
|
987 | + ), array( |
|
990 | 988 | 'link_app2' => 'addressbook', |
991 | 989 | 'link_id2' => $old_contact_id |
992 | - ),__LINE__,__FILE__); |
|
990 | + ), __LINE__, __FILE__); |
|
993 | 991 | echo "</p>\n"; |
994 | 992 | } |
995 | 993 | else |
@@ -1009,21 +1007,21 @@ discard block |
||
1009 | 1007 | * @param string $extra_labels =null first labels if given (already translated) |
1010 | 1008 | * @return array with id => label pairs or false if backend does not support lists |
1011 | 1009 | */ |
1012 | - function get_lists($required=Api\Acl::READ,$extra_labels=null) |
|
1010 | + function get_lists($required = Api\Acl::READ, $extra_labels = null) |
|
1013 | 1011 | { |
1014 | - if (!method_exists($this->somain,'get_lists')) return false; |
|
1012 | + if (!method_exists($this->somain, 'get_lists')) return false; |
|
1015 | 1013 | |
1016 | 1014 | $uids = array(); |
1017 | - foreach($this->grants as $uid => $rights) |
|
1015 | + foreach ($this->grants as $uid => $rights) |
|
1018 | 1016 | { |
1019 | - if (($rights & $required) == $required) |
|
1017 | + if (($rights&$required) == $required) |
|
1020 | 1018 | { |
1021 | 1019 | $uids[] = $uid; |
1022 | 1020 | } |
1023 | 1021 | } |
1024 | 1022 | $lists = is_array($extra_labels) ? $extra_labels : array(); |
1025 | 1023 | |
1026 | - foreach($this->somain->get_lists($uids) as $list_id => $data) |
|
1024 | + foreach ($this->somain->get_lists($uids) as $list_id => $data) |
|
1027 | 1025 | { |
1028 | 1026 | $lists[$list_id] = $data['list_name']; |
1029 | 1027 | if ($data['list_owner'] != $this->user) |
@@ -1042,12 +1040,12 @@ discard block |
||
1042 | 1040 | * @param boolean $limit_in_ab =false if true only return members from the same owners addressbook |
1043 | 1041 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
1044 | 1042 | */ |
1045 | - function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
|
1043 | + function read_lists($keys, $member_attr = null, $limit_in_ab = false) |
|
1046 | 1044 | { |
1047 | 1045 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1048 | 1046 | if (!method_exists($backend, 'get_lists')) return false; |
1049 | 1047 | |
1050 | - return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
|
1048 | + return $backend->get_lists($keys, null, $member_attr, $limit_in_ab); |
|
1051 | 1049 | } |
1052 | 1050 | |
1053 | 1051 | /** |
@@ -1059,12 +1057,12 @@ discard block |
||
1059 | 1057 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
1060 | 1058 | * @return int|boolean integer list_id or false on error |
1061 | 1059 | */ |
1062 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
1060 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
1063 | 1061 | { |
1064 | 1062 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1065 | 1063 | if (!method_exists($backend, 'add_list')) return false; |
1066 | 1064 | |
1067 | - return $backend->add_list($keys,$owner,$contacts,$data); |
|
1065 | + return $backend->add_list($keys, $owner, $contacts, $data); |
|
1068 | 1066 | } |
1069 | 1067 | |
1070 | 1068 | /** |
@@ -1075,11 +1073,11 @@ discard block |
||
1075 | 1073 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
1076 | 1074 | * @return false on error |
1077 | 1075 | */ |
1078 | - function add2list($contact,$list,array $existing=null) |
|
1076 | + function add2list($contact, $list, array $existing = null) |
|
1079 | 1077 | { |
1080 | - if (!method_exists($this->somain,'add2list')) return false; |
|
1078 | + if (!method_exists($this->somain, 'add2list')) return false; |
|
1081 | 1079 | |
1082 | - return $this->somain->add2list($contact,$list,$existing); |
|
1080 | + return $this->somain->add2list($contact, $list, $existing); |
|
1083 | 1081 | } |
1084 | 1082 | |
1085 | 1083 | /** |
@@ -1089,11 +1087,11 @@ discard block |
||
1089 | 1087 | * @param int $list =null list-id or null to remove from all lists |
1090 | 1088 | * @return false on error |
1091 | 1089 | */ |
1092 | - function remove_from_list($contact,$list=null) |
|
1090 | + function remove_from_list($contact, $list = null) |
|
1093 | 1091 | { |
1094 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
1092 | + if (!method_exists($this->somain, 'remove_from_list')) return false; |
|
1095 | 1093 | |
1096 | - return $this->somain->remove_from_list($contact,$list); |
|
1094 | + return $this->somain->remove_from_list($contact, $list); |
|
1097 | 1095 | } |
1098 | 1096 | |
1099 | 1097 | /** |
@@ -1104,7 +1102,7 @@ discard block |
||
1104 | 1102 | */ |
1105 | 1103 | function delete_list($list) |
1106 | 1104 | { |
1107 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
1105 | + if (!method_exists($this->somain, 'delete_list')) return false; |
|
1108 | 1106 | |
1109 | 1107 | return $this->somain->delete_list($list); |
1110 | 1108 | } |
@@ -1117,7 +1115,7 @@ discard block |
||
1117 | 1115 | */ |
1118 | 1116 | function read_list($list) |
1119 | 1117 | { |
1120 | - if (!method_exists($this->somain,'read_list')) return false; |
|
1118 | + if (!method_exists($this->somain, 'read_list')) return false; |
|
1121 | 1119 | |
1122 | 1120 | return $this->somain->read_list($list); |
1123 | 1121 | } |
@@ -1128,11 +1126,11 @@ discard block |
||
1128 | 1126 | * @param int|string $owner ='' addressbook (eg. 0 = accounts), default '' = "all" addressbook (uses the main backend) |
1129 | 1127 | * @return boolean |
1130 | 1128 | */ |
1131 | - function lists_available($owner='') |
|
1129 | + function lists_available($owner = '') |
|
1132 | 1130 | { |
1133 | - $backend =& $this->get_backend(null,$owner); |
|
1131 | + $backend = & $this->get_backend(null, $owner); |
|
1134 | 1132 | |
1135 | - return method_exists($backend,'read_list'); |
|
1133 | + return method_exists($backend, 'read_list'); |
|
1136 | 1134 | } |
1137 | 1135 | |
1138 | 1136 | /** |
@@ -1141,9 +1139,9 @@ discard block |
||
1141 | 1139 | * @param int|array $owner =null null for all lists user has access too |
1142 | 1140 | * @return int |
1143 | 1141 | */ |
1144 | - function lists_ctag($owner=null) |
|
1142 | + function lists_ctag($owner = null) |
|
1145 | 1143 | { |
1146 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
1144 | + if (!method_exists($this->somain, 'lists_ctag')) return 0; |
|
1147 | 1145 | |
1148 | 1146 | return $this->somain->lists_ctag($owner); |
1149 | 1147 | } |
@@ -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 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * require_once(EGW_INCLUDE_ROOT.'/api/src/Db.php'); |
372 | 372 | * EGroupware\Api\Db::$health_check = array('EGroupware\Api\Db', 'galera_cluster_health'); |
373 | 373 | * |
374 | - * @param Api\Db $db already connected Api\Db instance to check |
|
374 | + * @param Db $db already connected Api\Db instance to check |
|
375 | 375 | * @throws Db\Exception\Connection if node should NOT be used |
376 | 376 | */ |
377 | 377 | static function galera_cluster_health(Db $db) |
@@ -1077,7 +1077,6 @@ discard block |
||
1077 | 1077 | * |
1078 | 1078 | * Example: $db->concat($db->quote('Hallo '),'username') would return |
1079 | 1079 | * for mysql "concat('Hallo ',username)" or "'Hallo ' || username" for postgres |
1080 | - * @param string $str1 already quoted stringliteral or column-name, variable number of arguments |
|
1081 | 1080 | * @return string to be used in a query |
1082 | 1081 | */ |
1083 | 1082 | function concat(/*$str1, ...*/) |
@@ -1097,7 +1096,7 @@ discard block |
||
1097 | 1096 | * @param string $expr column-name or expression optional prefixed with "DISTINCT" |
1098 | 1097 | * @param string $order_by ='' optional order |
1099 | 1098 | * @param string $separator =',' optional separator, default is comma |
1100 | - * @return string|boolean false if not supported by dbms |
|
1099 | + * @return false|string false if not supported by dbms |
|
1101 | 1100 | */ |
1102 | 1101 | function group_concat($expr, $order_by='', $separator=',') |
1103 | 1102 | { |
@@ -1430,7 +1429,7 @@ discard block |
||
1430 | 1429 | * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
1431 | 1430 | * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
1432 | 1431 | * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
1433 | - * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1432 | + * @param boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1434 | 1433 | * typicaly used to form a WHERE-clause from the primary keys. |
1435 | 1434 | * If set to True, only columns from the colum_definitons are written. |
1436 | 1435 | * @param array|boolean $column_definitions this can be set to the column-definitions-array |
@@ -1910,13 +1909,6 @@ discard block |
||
1910 | 1909 | * gives "(name='test\'ed' AND lang='en') OR 'owner' IN (0,4,5,6,10)" if name,lang are strings and owner is an integer |
1911 | 1910 | * |
1912 | 1911 | * @param string|array $table_def table-name or definition array |
1913 | - * @param mixed $args variable number of arguments of the following types: |
|
1914 | - * string: get's as is into the result |
|
1915 | - * array: column-name / value pairs: the value gets quoted according to the type of the column and prefixed |
|
1916 | - * with column-name=, multiple pairs are AND'ed together, see db::column_data_implode |
|
1917 | - * bool: If False or is_null($arg): the next 2 (!) arguments gets ignored |
|
1918 | - * |
|
1919 | - * Please note: As the function has a variable number of arguments, you CAN NOT add further parameters !!! |
|
1920 | 1912 | * |
1921 | 1913 | * @return string the expression generated from the arguments |
1922 | 1914 | */ |
@@ -2054,7 +2046,7 @@ discard block |
||
2054 | 2046 | * Strip eg. a prefix from the keys of an array |
2055 | 2047 | * |
2056 | 2048 | * @param array $arr |
2057 | - * @param string|array $strip |
|
2049 | + * @param string $strip |
|
2058 | 2050 | * @return array |
2059 | 2051 | */ |
2060 | 2052 | static function strip_array_keys($arr,$strip) |
@@ -67,43 +67,43 @@ discard block |
||
67 | 67 | */ |
68 | 68 | const FETCH_BOTH = ADODB_FETCH_BOTH; |
69 | 69 | /** |
70 | - * @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types |
|
71 | - */ |
|
70 | + * @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types |
|
71 | + */ |
|
72 | 72 | var $Type = ''; |
73 | 73 | |
74 | 74 | /** |
75 | - * @var string $type database type as defined in the header.inc.php, eg. mysqlt |
|
76 | - */ |
|
75 | + * @var string $type database type as defined in the header.inc.php, eg. mysqlt |
|
76 | + */ |
|
77 | 77 | var $setupType = ''; |
78 | 78 | |
79 | 79 | /** |
80 | - * @var string $Host database host to connect to |
|
81 | - */ |
|
80 | + * @var string $Host database host to connect to |
|
81 | + */ |
|
82 | 82 | var $Host = ''; |
83 | 83 | |
84 | 84 | /** |
85 | - * @var string $Port port number of database to connect to |
|
86 | - */ |
|
85 | + * @var string $Port port number of database to connect to |
|
86 | + */ |
|
87 | 87 | var $Port = ''; |
88 | 88 | |
89 | 89 | /** |
90 | - * @var string $Database name of database to use |
|
91 | - */ |
|
90 | + * @var string $Database name of database to use |
|
91 | + */ |
|
92 | 92 | var $Database = ''; |
93 | 93 | |
94 | 94 | /** |
95 | - * @var string $User name of database user |
|
96 | - */ |
|
95 | + * @var string $User name of database user |
|
96 | + */ |
|
97 | 97 | var $User = ''; |
98 | 98 | |
99 | 99 | /** |
100 | - * @var string $Password password for database user |
|
101 | - */ |
|
100 | + * @var string $Password password for database user |
|
101 | + */ |
|
102 | 102 | var $Password = ''; |
103 | 103 | |
104 | 104 | /** |
105 | - * @var int $Debug enable debuging - 0 no, 1 yes |
|
106 | - */ |
|
105 | + * @var int $Debug enable debuging - 0 no, 1 yes |
|
106 | + */ |
|
107 | 107 | var $Debug = 0; |
108 | 108 | |
109 | 109 | /** |
@@ -114,23 +114,23 @@ discard block |
||
114 | 114 | var $log_updates = false; |
115 | 115 | |
116 | 116 | /** |
117 | - * @var array $Record current record |
|
118 | - */ |
|
117 | + * @var array $Record current record |
|
118 | + */ |
|
119 | 119 | var $Record = array(); |
120 | 120 | |
121 | 121 | /** |
122 | - * @var int row number for current record |
|
123 | - */ |
|
122 | + * @var int row number for current record |
|
123 | + */ |
|
124 | 124 | var $Row; |
125 | 125 | |
126 | 126 | /** |
127 | - * @var int $Errno internal rdms error number for last error |
|
128 | - */ |
|
127 | + * @var int $Errno internal rdms error number for last error |
|
128 | + */ |
|
129 | 129 | var $Errno = 0; |
130 | 130 | |
131 | 131 | /** |
132 | - * @var string descriptive text from last error |
|
133 | - */ |
|
132 | + * @var string descriptive text from last error |
|
133 | + */ |
|
134 | 134 | var $Error = ''; |
135 | 135 | |
136 | 136 | /** |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * @param string $query query to be executed (optional) |
|
274 | - */ |
|
273 | + * @param string $query query to be executed (optional) |
|
274 | + */ |
|
275 | 275 | |
276 | 276 | function db($query = '') |
277 | 277 | { |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | - * @return int current connection id |
|
283 | - */ |
|
282 | + * @return int current connection id |
|
283 | + */ |
|
284 | 284 | function link_id() |
285 | 285 | { |
286 | 286 | return $this->Link_ID; |
@@ -652,8 +652,8 @@ discard block |
||
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
655 | - * Close a connection to a database |
|
656 | - */ |
|
655 | + * Close a connection to a database |
|
656 | + */ |
|
657 | 657 | function disconnect() |
658 | 658 | { |
659 | 659 | if (!$this->privat_Link_ID) |
@@ -667,11 +667,11 @@ discard block |
||
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
670 | - * Convert a unix timestamp to a rdms specific timestamp |
|
671 | - * |
|
672 | - * @param int unix timestamp |
|
673 | - * @return string rdms specific timestamp |
|
674 | - */ |
|
670 | + * Convert a unix timestamp to a rdms specific timestamp |
|
671 | + * |
|
672 | + * @param int unix timestamp |
|
673 | + * @return string rdms specific timestamp |
|
674 | + */ |
|
675 | 675 | function to_timestamp($epoch) |
676 | 676 | { |
677 | 677 | if (!$this->Link_ID && !$this->connect()) |
@@ -683,11 +683,11 @@ discard block |
||
683 | 683 | } |
684 | 684 | |
685 | 685 | /** |
686 | - * Convert a rdms specific timestamp to a unix timestamp |
|
687 | - * |
|
688 | - * @param string rdms specific timestamp |
|
689 | - * @return int unix timestamp |
|
690 | - */ |
|
686 | + * Convert a rdms specific timestamp to a unix timestamp |
|
687 | + * |
|
688 | + * @param string rdms specific timestamp |
|
689 | + * @return int unix timestamp |
|
690 | + */ |
|
691 | 691 | function from_timestamp($timestamp) |
692 | 692 | { |
693 | 693 | if (!$this->Link_ID && !$this->connect()) |
@@ -709,19 +709,19 @@ discard block |
||
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
712 | - * Execute a query |
|
713 | - * |
|
714 | - * @param string $Query_String the query to be executed |
|
715 | - * @param int $line the line method was called from - use __LINE__ |
|
716 | - * @param string $file the file method was called from - use __FILE__ |
|
717 | - * @param int $offset row to start from, default 0 |
|
718 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
719 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
720 | - * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
721 | - * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
722 | - * @return ADORecordSet or false, if the query fails |
|
723 | - * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
724 | - */ |
|
712 | + * Execute a query |
|
713 | + * |
|
714 | + * @param string $Query_String the query to be executed |
|
715 | + * @param int $line the line method was called from - use __LINE__ |
|
716 | + * @param string $file the file method was called from - use __FILE__ |
|
717 | + * @param int $offset row to start from, default 0 |
|
718 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
719 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
720 | + * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
721 | + * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
722 | + * @return ADORecordSet or false, if the query fails |
|
723 | + * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
724 | + */ |
|
725 | 725 | function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
726 | 726 | { |
727 | 727 | unset($line, $file); // not used anymore |
@@ -786,26 +786,26 @@ discard block |
||
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
789 | - * Execute a query with limited result set |
|
790 | - * |
|
791 | - * @param string $Query_String the query to be executed |
|
792 | - * @param int $offset row to start from, default 0 |
|
793 | - * @param int $line the line method was called from - use __LINE__ |
|
794 | - * @param string $file the file method was called from - use __FILE__ |
|
795 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
796 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
797 | - * @return ADORecordSet or false, if the query fails |
|
798 | - */ |
|
789 | + * Execute a query with limited result set |
|
790 | + * |
|
791 | + * @param string $Query_String the query to be executed |
|
792 | + * @param int $offset row to start from, default 0 |
|
793 | + * @param int $line the line method was called from - use __LINE__ |
|
794 | + * @param string $file the file method was called from - use __FILE__ |
|
795 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
796 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
797 | + * @return ADORecordSet or false, if the query fails |
|
798 | + */ |
|
799 | 799 | function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
800 | 800 | { |
801 | 801 | return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
802 | 802 | } |
803 | 803 | |
804 | 804 | /** |
805 | - * Begin Transaction |
|
806 | - * |
|
807 | - * @return int/boolean current transaction-id, of false if no connection |
|
808 | - */ |
|
805 | + * Begin Transaction |
|
806 | + * |
|
807 | + * @return int/boolean current transaction-id, of false if no connection |
|
808 | + */ |
|
809 | 809 | function transaction_begin() |
810 | 810 | { |
811 | 811 | if (!$this->Link_ID && !$this->connect()) |
@@ -817,10 +817,10 @@ discard block |
||
817 | 817 | } |
818 | 818 | |
819 | 819 | /** |
820 | - * Complete the transaction |
|
821 | - * |
|
822 | - * @return bool True if sucessful, False if fails |
|
823 | - */ |
|
820 | + * Complete the transaction |
|
821 | + * |
|
822 | + * @return bool True if sucessful, False if fails |
|
823 | + */ |
|
824 | 824 | function transaction_commit() |
825 | 825 | { |
826 | 826 | if (!$this->Link_ID && !$this->connect()) |
@@ -832,10 +832,10 @@ discard block |
||
832 | 832 | } |
833 | 833 | |
834 | 834 | /** |
835 | - * Rollback the current transaction |
|
836 | - * |
|
837 | - * @return bool True if sucessful, False if fails |
|
838 | - */ |
|
835 | + * Rollback the current transaction |
|
836 | + * |
|
837 | + * @return bool True if sucessful, False if fails |
|
838 | + */ |
|
839 | 839 | function transaction_abort() |
840 | 840 | { |
841 | 841 | if (!$this->Link_ID && !$this->connect()) |
@@ -847,12 +847,12 @@ discard block |
||
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
850 | - * Find the primary key of the last insertion on the current db connection |
|
851 | - * |
|
852 | - * @param string $table name of table the insert was performed on |
|
853 | - * @param string $field the autoincrement primary key of the table |
|
854 | - * @return int the id, -1 if fails |
|
855 | - */ |
|
850 | + * Find the primary key of the last insertion on the current db connection |
|
851 | + * |
|
852 | + * @param string $table name of table the insert was performed on |
|
853 | + * @param string $field the autoincrement primary key of the table |
|
854 | + * @return int the id, -1 if fails |
|
855 | + */ |
|
856 | 856 | function get_last_insert_id($table, $field) |
857 | 857 | { |
858 | 858 | if (!$this->Link_ID && !$this->connect()) |
@@ -875,10 +875,10 @@ discard block |
||
875 | 875 | } |
876 | 876 | |
877 | 877 | /** |
878 | - * Get the number of rows affected by last update or delete |
|
879 | - * |
|
880 | - * @return int number of rows |
|
881 | - */ |
|
878 | + * Get the number of rows affected by last update or delete |
|
879 | + * |
|
880 | + * @return int number of rows |
|
881 | + */ |
|
882 | 882 | function affected_rows() |
883 | 883 | { |
884 | 884 | if ($this->log_updates) return 0; |
@@ -891,14 +891,14 @@ discard block |
||
891 | 891 | } |
892 | 892 | |
893 | 893 | /** |
894 | - * Get description of a table |
|
895 | - * |
|
896 | - * Beside the column-name all other data depends on the db-type !!! |
|
897 | - * |
|
898 | - * @param string $table name of table to describe |
|
899 | - * @param bool $full optional, default False summary information, True full information |
|
900 | - * @return array table meta data |
|
901 | - */ |
|
894 | + * Get description of a table |
|
895 | + * |
|
896 | + * Beside the column-name all other data depends on the db-type !!! |
|
897 | + * |
|
898 | + * @param string $table name of table to describe |
|
899 | + * @param bool $full optional, default False summary information, True full information |
|
900 | + * @return array table meta data |
|
901 | + */ |
|
902 | 902 | function metadata($table='',$full=false) |
903 | 903 | { |
904 | 904 | if (!$this->Link_ID && !$this->connect()) |
@@ -980,10 +980,10 @@ discard block |
||
980 | 980 | } |
981 | 981 | |
982 | 982 | /** |
983 | - * Return a list of indexes in current database |
|
984 | - * |
|
985 | - * @return array list of indexes |
|
986 | - */ |
|
983 | + * Return a list of indexes in current database |
|
984 | + * |
|
985 | + * @return array list of indexes |
|
986 | + */ |
|
987 | 987 | function index_names() |
988 | 988 | { |
989 | 989 | $indices = array(); |
@@ -1004,10 +1004,10 @@ discard block |
||
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | /** |
1007 | - * Returns an array containing column names that are the primary keys of $tablename. |
|
1008 | - * |
|
1009 | - * @return array of columns |
|
1010 | - */ |
|
1007 | + * Returns an array containing column names that are the primary keys of $tablename. |
|
1008 | + * |
|
1009 | + * @return array of columns |
|
1010 | + */ |
|
1011 | 1011 | function pkey_columns($tablename) |
1012 | 1012 | { |
1013 | 1013 | if (!$this->Link_ID && !$this->connect()) |
@@ -1018,13 +1018,13 @@ discard block |
||
1018 | 1018 | } |
1019 | 1019 | |
1020 | 1020 | /** |
1021 | - * Create a new database |
|
1022 | - * |
|
1023 | - * @param string $adminname name of database administrator user (optional) |
|
1024 | - * @param string $adminpasswd password for the database administrator user (optional) |
|
1025 | - * @param string $charset default charset for the database |
|
1026 | - * @param string $grant_host ='localhost' host/ip of the webserver |
|
1027 | - */ |
|
1021 | + * Create a new database |
|
1022 | + * |
|
1023 | + * @param string $adminname name of database administrator user (optional) |
|
1024 | + * @param string $adminpasswd password for the database administrator user (optional) |
|
1025 | + * @param string $charset default charset for the database |
|
1026 | + * @param string $grant_host ='localhost' host/ip of the webserver |
|
1027 | + */ |
|
1028 | 1028 | function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
1029 | 1029 | { |
1030 | 1030 | $currentUser = $this->User; |
@@ -1280,12 +1280,12 @@ discard block |
||
1280 | 1280 | } |
1281 | 1281 | |
1282 | 1282 | /** |
1283 | - * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
1284 | - * |
|
1285 | - * This is mostly copy & paste from adodb's datadict class |
|
1286 | - * @param string $_name |
|
1287 | - * @return string quoted string |
|
1288 | - */ |
|
1283 | + * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
1284 | + * |
|
1285 | + * This is mostly copy & paste from adodb's datadict class |
|
1286 | + * @param string $_name |
|
1287 | + * @return string quoted string |
|
1288 | + */ |
|
1289 | 1289 | function name_quote($_name = NULL) |
1290 | 1290 | { |
1291 | 1291 | if (!is_string($_name)) |
@@ -1324,19 +1324,19 @@ discard block |
||
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | /** |
1327 | - * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
1328 | - * |
|
1329 | - * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
1330 | - * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
1331 | - * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
1332 | - * |
|
1333 | - * @param mixed $value the value to be escaped |
|
1334 | - * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
1335 | - * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
1336 | - * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
1337 | - * @param string $glue =',' used to glue array values together for the string type |
|
1338 | - * @return string escaped sting |
|
1339 | - */ |
|
1327 | + * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
1328 | + * |
|
1329 | + * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
1330 | + * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
1331 | + * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
1332 | + * |
|
1333 | + * @param mixed $value the value to be escaped |
|
1334 | + * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
1335 | + * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
1336 | + * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
1337 | + * @param string $glue =',' used to glue array values together for the string type |
|
1338 | + * @return string escaped sting |
|
1339 | + */ |
|
1340 | 1340 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
1341 | 1341 | { |
1342 | 1342 | if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
@@ -1417,27 +1417,27 @@ discard block |
||
1417 | 1417 | } |
1418 | 1418 | |
1419 | 1419 | /** |
1420 | - * Implodes an array of column-value pairs for the use in sql-querys. |
|
1421 | - * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
1422 | - * |
|
1423 | - * @author RalfBecker<at>outdoor-training.de |
|
1424 | - * |
|
1425 | - * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
1426 | - * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
1427 | - * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
1428 | - * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
1429 | - * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
1430 | - * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
1431 | - * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
1432 | - * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
1433 | - * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1434 | - * typicaly used to form a WHERE-clause from the primary keys. |
|
1435 | - * If set to True, only columns from the colum_definitons are written. |
|
1436 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1437 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1438 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1439 | - * @return string SQL |
|
1440 | - */ |
|
1420 | + * Implodes an array of column-value pairs for the use in sql-querys. |
|
1421 | + * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
1422 | + * |
|
1423 | + * @author RalfBecker<at>outdoor-training.de |
|
1424 | + * |
|
1425 | + * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
1426 | + * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
1427 | + * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
1428 | + * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
1429 | + * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
1430 | + * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
1431 | + * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
1432 | + * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
1433 | + * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1434 | + * typicaly used to form a WHERE-clause from the primary keys. |
|
1435 | + * If set to True, only columns from the colum_definitons are written. |
|
1436 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1437 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1438 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1439 | + * @return string SQL |
|
1440 | + */ |
|
1441 | 1441 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
1442 | 1442 | { |
1443 | 1443 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
@@ -1523,14 +1523,14 @@ discard block |
||
1523 | 1523 | } |
1524 | 1524 | |
1525 | 1525 | /** |
1526 | - * Sets the default column-definitions for use with column_data_implode() |
|
1527 | - * |
|
1528 | - * @author RalfBecker<at>outdoor-training.de |
|
1529 | - * |
|
1530 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1531 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1532 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1533 | - */ |
|
1526 | + * Sets the default column-definitions for use with column_data_implode() |
|
1527 | + * |
|
1528 | + * @author RalfBecker<at>outdoor-training.de |
|
1529 | + * |
|
1530 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1531 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1532 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1533 | + */ |
|
1534 | 1534 | function set_column_definitions($column_definitions=False) |
1535 | 1535 | { |
1536 | 1536 | $this->column_definitions=$column_definitions; |
@@ -1570,17 +1570,17 @@ discard block |
||
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | /** |
1573 | - * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
1574 | - * |
|
1575 | - * The already read table-definitions are shared between all db-instances via a static var. |
|
1576 | - * |
|
1577 | - * @author RalfBecker<at>outdoor-training.de |
|
1578 | - * |
|
1579 | - * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
1580 | - * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
1581 | - * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
1582 | - * @return mixed array with table-defintions or False if file not found |
|
1583 | - */ |
|
1573 | + * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
1574 | + * |
|
1575 | + * The already read table-definitions are shared between all db-instances via a static var. |
|
1576 | + * |
|
1577 | + * @author RalfBecker<at>outdoor-training.de |
|
1578 | + * |
|
1579 | + * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
1580 | + * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
1581 | + * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
1582 | + * @return mixed array with table-defintions or False if file not found |
|
1583 | + */ |
|
1584 | 1584 | function get_table_definitions($app=False,$table=False) |
1585 | 1585 | { |
1586 | 1586 | // ease the transition to api |
@@ -1676,21 +1676,21 @@ discard block |
||
1676 | 1676 | } |
1677 | 1677 | |
1678 | 1678 | /** |
1679 | - * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
1680 | - * |
|
1681 | - * @author RalfBecker<at>outdoor-training.de |
|
1682 | - * |
|
1683 | - * @param string $table name of the table |
|
1684 | - * @param array $data with column-name / value pairs |
|
1685 | - * @param mixed $where string with where clause or array with column-name / values pairs to check if a row with that keys already exists, or false for an unconditional insert |
|
1686 | - * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
1687 | - * @param int $line line-number to pass to query |
|
1688 | - * @param string $file file-name to pass to query |
|
1689 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1690 | - * @param bool $use_prepared_statement use a prepared statement |
|
1691 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1692 | - * @return ADORecordSet or false, if the query fails |
|
1693 | - */ |
|
1679 | + * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
1680 | + * |
|
1681 | + * @author RalfBecker<at>outdoor-training.de |
|
1682 | + * |
|
1683 | + * @param string $table name of the table |
|
1684 | + * @param array $data with column-name / value pairs |
|
1685 | + * @param mixed $where string with where clause or array with column-name / values pairs to check if a row with that keys already exists, or false for an unconditional insert |
|
1686 | + * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
1687 | + * @param int $line line-number to pass to query |
|
1688 | + * @param string $file file-name to pass to query |
|
1689 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1690 | + * @param bool $use_prepared_statement use a prepared statement |
|
1691 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1692 | + * @return ADORecordSet or false, if the query fails |
|
1693 | + */ |
|
1694 | 1694 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1695 | 1695 | { |
1696 | 1696 | if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
@@ -1786,20 +1786,20 @@ discard block |
||
1786 | 1786 | } |
1787 | 1787 | |
1788 | 1788 | /** |
1789 | - * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
1790 | - * |
|
1791 | - * @author RalfBecker<at>outdoor-training.de |
|
1792 | - * |
|
1793 | - * @param string $table name of the table |
|
1794 | - * @param array $data with column-name / value pairs |
|
1795 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
1796 | - * @param int $line line-number to pass to query |
|
1797 | - * @param string $file file-name to pass to query |
|
1798 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1799 | - * @param bool $use_prepared_statement use a prepared statement |
|
1800 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1801 | - * @return ADORecordSet or false, if the query fails |
|
1802 | - */ |
|
1789 | + * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
1790 | + * |
|
1791 | + * @author RalfBecker<at>outdoor-training.de |
|
1792 | + * |
|
1793 | + * @param string $table name of the table |
|
1794 | + * @param array $data with column-name / value pairs |
|
1795 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
1796 | + * @param int $line line-number to pass to query |
|
1797 | + * @param string $file file-name to pass to query |
|
1798 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1799 | + * @param bool $use_prepared_statement use a prepared statement |
|
1800 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1801 | + * @return ADORecordSet or false, if the query fails |
|
1802 | + */ |
|
1803 | 1803 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1804 | 1804 | { |
1805 | 1805 | if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
@@ -1876,18 +1876,18 @@ discard block |
||
1876 | 1876 | } |
1877 | 1877 | |
1878 | 1878 | /** |
1879 | - * Deletes one or more rows in table, all data is quoted according to it's type |
|
1880 | - * |
|
1881 | - * @author RalfBecker<at>outdoor-training.de |
|
1882 | - * |
|
1883 | - * @param string $table name of the table |
|
1884 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
1885 | - * @param int $line line-number to pass to query |
|
1886 | - * @param string $file file-name to pass to query |
|
1887 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1888 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1889 | - * @return ADORecordSet or false, if the query fails |
|
1890 | - */ |
|
1879 | + * Deletes one or more rows in table, all data is quoted according to it's type |
|
1880 | + * |
|
1881 | + * @author RalfBecker<at>outdoor-training.de |
|
1882 | + * |
|
1883 | + * @param string $table name of the table |
|
1884 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
1885 | + * @param int $line line-number to pass to query |
|
1886 | + * @param string $file file-name to pass to query |
|
1887 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1888 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1889 | + * @return ADORecordSet or false, if the query fails |
|
1890 | + */ |
|
1891 | 1891 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
1892 | 1892 | { |
1893 | 1893 | if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
@@ -1953,25 +1953,25 @@ discard block |
||
1953 | 1953 | } |
1954 | 1954 | |
1955 | 1955 | /** |
1956 | - * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
1957 | - * |
|
1958 | - * @author RalfBecker<at>outdoor-training.de |
|
1959 | - * |
|
1960 | - * @param string $table name of the table |
|
1961 | - * @param array|string $cols string or array of column-names / select-expressions |
|
1962 | - * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
1963 | - * @param int $line line-number to pass to query |
|
1964 | - * @param string $file file-name to pass to query |
|
1965 | - * @param int|bool $offset offset for a limited query or False (default) |
|
1966 | - * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
1967 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1968 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
1969 | - * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
1970 | - * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
1971 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1972 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
1973 | - * @return ADORecordSet or false, if the query fails |
|
1974 | - */ |
|
1956 | + * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
1957 | + * |
|
1958 | + * @author RalfBecker<at>outdoor-training.de |
|
1959 | + * |
|
1960 | + * @param string $table name of the table |
|
1961 | + * @param array|string $cols string or array of column-names / select-expressions |
|
1962 | + * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
1963 | + * @param int $line line-number to pass to query |
|
1964 | + * @param string $file file-name to pass to query |
|
1965 | + * @param int|bool $offset offset for a limited query or False (default) |
|
1966 | + * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
1967 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1968 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
1969 | + * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
1970 | + * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
1971 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1972 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
1973 | + * @return ADORecordSet or false, if the query fails |
|
1974 | + */ |
|
1975 | 1975 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
1976 | 1976 | { |
1977 | 1977 | if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
@@ -2006,20 +2006,20 @@ discard block |
||
2006 | 2006 | } |
2007 | 2007 | |
2008 | 2008 | /** |
2009 | - * Does a union over multiple selects |
|
2010 | - * |
|
2011 | - * @author RalfBecker<at>outdoor-training.de |
|
2012 | - * |
|
2013 | - * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
2014 | - * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
2015 | - * @param int $line line-number to pass to query |
|
2016 | - * @param string $file file-name to pass to query |
|
2017 | - * @param string $order_by ORDER BY statement for the union |
|
2018 | - * @param int|bool $offset offset for a limited query or False (default) |
|
2019 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2020 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2021 | - * @return ADORecordSet or false, if the query fails |
|
2022 | - */ |
|
2009 | + * Does a union over multiple selects |
|
2010 | + * |
|
2011 | + * @author RalfBecker<at>outdoor-training.de |
|
2012 | + * |
|
2013 | + * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
2014 | + * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
2015 | + * @param int $line line-number to pass to query |
|
2016 | + * @param string $file file-name to pass to query |
|
2017 | + * @param string $order_by ORDER BY statement for the union |
|
2018 | + * @param int|bool $offset offset for a limited query or False (default) |
|
2019 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2020 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2021 | + * @return ADORecordSet or false, if the query fails |
|
2022 | + */ |
|
2023 | 2023 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
2024 | 2024 | { |
2025 | 2025 | if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
@@ -383,7 +383,10 @@ discard block |
||
383 | 383 | if ($state['wsrep_local_state_comment'] == 'Synced' || |
384 | 384 | // if we have only 2 nodes (2. one starting), we can only use the donor |
385 | 385 | $state['wsrep_local_state_comment'] == 'Donor/Desynced' && |
386 | - $state['wsrep_cluster_size'] == 2) return; |
|
386 | + $state['wsrep_cluster_size'] == 2) |
|
387 | + { |
|
388 | + return; |
|
389 | + } |
|
387 | 390 | |
388 | 391 | throw new Db\Exception\Connection('Node is NOT Synced! '.array2string($state)); |
389 | 392 | } |
@@ -402,7 +405,10 @@ discard block |
||
402 | 405 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
403 | 406 | $num_hosts = count($hosts); |
404 | 407 | $n =& Cache::getSession(__CLASS__, $this->Host); |
405 | - if (!isset($n)) $n = 0; |
|
408 | + if (!isset($n)) |
|
409 | + { |
|
410 | + $n = 0; |
|
411 | + } |
|
406 | 412 | |
407 | 413 | if ($next && ++$n >= $num_hosts+2) |
408 | 414 | { |
@@ -432,7 +438,10 @@ discard block |
||
432 | 438 | foreach(array('Database','User','Password','Port','Type') as $name) |
433 | 439 | { |
434 | 440 | $$name = $this->$name; |
435 | - if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
|
441 | + if (${$name}[0] == '@' && $name != 'Password') |
|
442 | + { |
|
443 | + $$name = getenv(substr($$name, 1)); |
|
444 | + } |
|
436 | 445 | } |
437 | 446 | $this->setupType = $php_extension = $Type; |
438 | 447 | |
@@ -451,7 +460,10 @@ discard block |
||
451 | 460 | $Type = 'mssql'; |
452 | 461 | // fall through |
453 | 462 | case 'mssql': |
454 | - if ($Port) $Host .= ','.$Port; |
|
463 | + if ($Port) |
|
464 | + { |
|
465 | + $Host .= ','.$Port; |
|
466 | + } |
|
455 | 467 | break; |
456 | 468 | |
457 | 469 | case 'odbc_oracle': |
@@ -486,7 +498,10 @@ discard block |
||
486 | 498 | $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
487 | 499 | // fall through |
488 | 500 | default: |
489 | - if ($Port) $Host .= ':'.$Port; |
|
501 | + if ($Port) |
|
502 | + { |
|
503 | + $Host .= ':'.$Port; |
|
504 | + } |
|
490 | 505 | break; |
491 | 506 | } |
492 | 507 | if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
@@ -501,10 +516,13 @@ discard block |
||
501 | 516 | { |
502 | 517 | throw new Db\Exception\Connection("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!"); |
503 | 518 | } |
504 | - if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
|
519 | + if (!isset($GLOBALS['egw']->ADOdb)) |
|
520 | + { |
|
521 | + // use the global object to store the connection |
|
505 | 522 | { |
506 | 523 | $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
507 | 524 | } |
525 | + } |
|
508 | 526 | else |
509 | 527 | { |
510 | 528 | $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
@@ -600,7 +618,11 @@ discard block |
||
600 | 618 | */ |
601 | 619 | function __sleep() |
602 | 620 | { |
603 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
621 | + if (!empty($this->setupType)) |
|
622 | + { |
|
623 | + $this->Type = $this->setupType; |
|
624 | + } |
|
625 | + // restore Type eg. to mysqli |
|
604 | 626 | |
605 | 627 | $vars = get_object_vars($this); |
606 | 628 | unset($vars['Link_ID']); |
@@ -663,7 +685,10 @@ discard block |
||
663 | 685 | unset($this->Link_ID); |
664 | 686 | $this->Link_ID = 0; |
665 | 687 | |
666 | - if (!empty($this->setupType)) $this->Type = $this->setupType; |
|
688 | + if (!empty($this->setupType)) |
|
689 | + { |
|
690 | + $this->Type = $this->setupType; |
|
691 | + } |
|
667 | 692 | } |
668 | 693 | |
669 | 694 | /** |
@@ -772,16 +797,22 @@ discard block |
||
772 | 797 | } |
773 | 798 | if (!$rs) |
774 | 799 | { |
775 | - if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) // Server has gone away |
|
800 | + if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) |
|
801 | + { |
|
802 | + // Server has gone away |
|
776 | 803 | { |
777 | 804 | $this->disconnect(); |
805 | + } |
|
778 | 806 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
779 | 807 | } |
780 | 808 | throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
781 | 809 | "\n$this->Error ($this->Errno)". |
782 | 810 | ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
783 | 811 | } |
784 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
812 | + elseif(empty($rs->sql)) |
|
813 | + { |
|
814 | + $rs->sql = $Query_String; |
|
815 | + } |
|
785 | 816 | return $rs; |
786 | 817 | } |
787 | 818 | |
@@ -865,9 +896,12 @@ discard block |
||
865 | 896 | } |
866 | 897 | $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
867 | 898 | |
868 | - if ($id === False) // function not supported |
|
899 | + if ($id === False) |
|
900 | + { |
|
901 | + // function not supported |
|
869 | 902 | { |
870 | 903 | echo "<p>db::get_last_insert_id(table='$table',field='$field') not yet implemented for db-type '$this->Type' OR no insert operation before</p>\n"; |
904 | + } |
|
871 | 905 | echo '<p>'.function_backtrace()."</p>\n"; |
872 | 906 | return -1; |
873 | 907 | } |
@@ -881,7 +915,10 @@ discard block |
||
881 | 915 | */ |
882 | 916 | function affected_rows() |
883 | 917 | { |
884 | - if ($this->log_updates) return 0; |
|
918 | + if ($this->log_updates) |
|
919 | + { |
|
920 | + return 0; |
|
921 | + } |
|
885 | 922 | |
886 | 923 | if (!$this->Link_ID && !$this->connect()) |
887 | 924 | { |
@@ -915,9 +952,18 @@ discard block |
||
915 | 952 | { |
916 | 953 | // for backwards compatibilty (depreciated) |
917 | 954 | $flags = null; |
918 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
919 | - if($column->primary_key) $flags .= "primary_key "; |
|
920 | - if($column->binary) $flags .= "binary "; |
|
955 | + if($column->auto_increment) |
|
956 | + { |
|
957 | + $flags .= "auto_increment "; |
|
958 | + } |
|
959 | + if($column->primary_key) |
|
960 | + { |
|
961 | + $flags .= "primary_key "; |
|
962 | + } |
|
963 | + if($column->binary) |
|
964 | + { |
|
965 | + $flags .= "binary "; |
|
966 | + } |
|
921 | 967 | |
922 | 968 | $metadata[$i] = array( |
923 | 969 | 'table' => $table, |
@@ -954,7 +1000,10 @@ discard block |
||
954 | 1000 | */ |
955 | 1001 | function table_names($just_name=false) |
956 | 1002 | { |
957 | - if (!$this->Link_ID) $this->connect(); |
|
1003 | + if (!$this->Link_ID) |
|
1004 | + { |
|
1005 | + $this->connect(); |
|
1006 | + } |
|
958 | 1007 | if (!$this->Link_ID) |
959 | 1008 | { |
960 | 1009 | return False; |
@@ -1105,8 +1154,14 @@ discard block |
||
1105 | 1154 | { |
1106 | 1155 | case 'mysql': |
1107 | 1156 | $sql = 'GROUP_CONCAT('.$expr; |
1108 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
1109 | - if ($separator != ',') $sql .= ' SEPARATOR '.$this->quote($separator); |
|
1157 | + if ($order_by) |
|
1158 | + { |
|
1159 | + $sql .= ' ORDER BY '.$order_by; |
|
1160 | + } |
|
1161 | + if ($separator != ',') |
|
1162 | + { |
|
1163 | + $sql .= ' SEPARATOR '.$this->quote($separator); |
|
1164 | + } |
|
1110 | 1165 | $sql .= ')'; |
1111 | 1166 | break; |
1112 | 1167 | |
@@ -1116,7 +1171,10 @@ discard block |
||
1116 | 1171 | return false; |
1117 | 1172 | } |
1118 | 1173 | $sql = 'ARRAY_TO_STRING(ARRAY_AGG('.$expr; |
1119 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
1174 | + if ($order_by) |
|
1175 | + { |
|
1176 | + $sql .= ' ORDER BY '.$order_by; |
|
1177 | + } |
|
1120 | 1178 | $sql .= '), '.$this->quote($separator).')'; |
1121 | 1179 | break; |
1122 | 1180 | |
@@ -1339,12 +1397,18 @@ discard block |
||
1339 | 1397 | */ |
1340 | 1398 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
1341 | 1399 | { |
1342 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1400 | + if ($this->Debug) |
|
1401 | + { |
|
1402 | + echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1403 | + } |
|
1343 | 1404 | |
1344 | - if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
|
1405 | + if (!$not_null && is_null($value)) |
|
1406 | + { |
|
1407 | + // writing unset php-variables and those set to NULL now as SQL NULL |
|
1345 | 1408 | { |
1346 | 1409 | return 'NULL'; |
1347 | 1410 | } |
1411 | + } |
|
1348 | 1412 | switch($type) |
1349 | 1413 | { |
1350 | 1414 | case 'int': |
@@ -1359,10 +1423,13 @@ discard block |
||
1359 | 1423 | // There for we have to keep it as float by using round instead the int cast. |
1360 | 1424 | return is_float($value) ? round($value) : (int) $value; |
1361 | 1425 | case 'bool': |
1362 | - if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
|
1426 | + if ($this->Type == 'mysql') |
|
1427 | + { |
|
1428 | + // maybe it's not longer necessary with mysql5 |
|
1363 | 1429 | { |
1364 | 1430 | return $value ? 1 : 0; |
1365 | 1431 | } |
1432 | + } |
|
1366 | 1433 | return $value ? 'true' : 'false'; |
1367 | 1434 | case 'float': |
1368 | 1435 | case 'decimal': |
@@ -1410,7 +1477,10 @@ discard block |
||
1410 | 1477 | } |
1411 | 1478 | // casting boolean explicitly to string, as ADODB_postgres64::qstr() has an unwanted special handling |
1412 | 1479 | // for boolean types, causing it to return "true" or "false" and not a quoted string like "'1'"! |
1413 | - if (is_bool($value)) $value = (string)$value; |
|
1480 | + if (is_bool($value)) |
|
1481 | + { |
|
1482 | + $value = (string)$value; |
|
1483 | + } |
|
1414 | 1484 | |
1415 | 1485 | // need to cast to string, as ADOdb 5.20 would return NULL instead of '' for NULL, causing us to write that into NOT NULL columns |
1416 | 1486 | return $this->Link_ID->qstr((string)$value); |
@@ -1440,15 +1510,21 @@ discard block |
||
1440 | 1510 | */ |
1441 | 1511 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
1442 | 1512 | { |
1443 | - if (!is_array($array)) // this allows to give an SQL-string for delete or update |
|
1513 | + if (!is_array($array)) |
|
1514 | + { |
|
1515 | + // this allows to give an SQL-string for delete or update |
|
1444 | 1516 | { |
1445 | 1517 | return $array; |
1446 | 1518 | } |
1519 | + } |
|
1447 | 1520 | if (!$column_definitions) |
1448 | 1521 | { |
1449 | 1522 | $column_definitions = $this->column_definitions; |
1450 | 1523 | } |
1451 | - if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
1524 | + if ($this->Debug) |
|
1525 | + { |
|
1526 | + echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
1527 | + } |
|
1452 | 1528 | |
1453 | 1529 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
1454 | 1530 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
@@ -1465,7 +1541,10 @@ discard block |
||
1465 | 1541 | // fix "table.column" expressions, to not trigger exception, if column alone would work |
1466 | 1542 | if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key])) |
1467 | 1543 | { |
1468 | - if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
|
1544 | + if (strpos($key, '.') !== false) |
|
1545 | + { |
|
1546 | + list(, $col) = explode('.', $key); |
|
1547 | + } |
|
1469 | 1548 | if (!isset($column_definitions[$col])) |
1470 | 1549 | { |
1471 | 1550 | throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>"); |
@@ -1505,7 +1584,11 @@ discard block |
||
1505 | 1584 | } |
1506 | 1585 | elseif (is_int($key) && $use_key===True) |
1507 | 1586 | { |
1508 | - if (empty($data)) continue; // would give SQL error |
|
1587 | + if (empty($data)) |
|
1588 | + { |
|
1589 | + continue; |
|
1590 | + } |
|
1591 | + // would give SQL error |
|
1509 | 1592 | $values[] = $data; |
1510 | 1593 | } |
1511 | 1594 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
@@ -1559,7 +1642,10 @@ discard block |
||
1559 | 1642 | function set_app($app) |
1560 | 1643 | { |
1561 | 1644 | // ease the transition to api |
1562 | - if ($app == 'phpgwapi') $app = 'api'; |
|
1645 | + if ($app == 'phpgwapi') |
|
1646 | + { |
|
1647 | + $app = 'api'; |
|
1648 | + } |
|
1563 | 1649 | |
1564 | 1650 | if ($this === $GLOBALS['egw']->db && $app != self::API_APPNAME) |
1565 | 1651 | { |
@@ -1584,7 +1670,10 @@ discard block |
||
1584 | 1670 | function get_table_definitions($app=False,$table=False) |
1585 | 1671 | { |
1586 | 1672 | // ease the transition to api |
1587 | - if ($app === 'phpgwapi') $app = 'api'; |
|
1673 | + if ($app === 'phpgwapi') |
|
1674 | + { |
|
1675 | + $app = 'api'; |
|
1676 | + } |
|
1588 | 1677 | |
1589 | 1678 | static $all_app_data = array(); |
1590 | 1679 | if ($app === true && $table) |
@@ -1642,10 +1731,16 @@ discard block |
||
1642 | 1731 | } |
1643 | 1732 | if ($table && (!$app_data || !isset($app_data[$table]))) |
1644 | 1733 | { |
1645 | - if ($this->Debug) echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
1734 | + if ($this->Debug) |
|
1735 | + { |
|
1736 | + echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
1737 | + } |
|
1646 | 1738 | return False; |
1647 | 1739 | } |
1648 | - if ($this->Debug) echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
1740 | + if ($this->Debug) |
|
1741 | + { |
|
1742 | + echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
1743 | + } |
|
1649 | 1744 | return $table ? $app_data[$table] : $app_data; |
1650 | 1745 | } |
1651 | 1746 | |
@@ -1670,7 +1765,10 @@ discard block |
||
1670 | 1765 | $table_def = $db->get_table_definitions($app,$table); |
1671 | 1766 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
1672 | 1767 | } |
1673 | - if ($cached_columns === false) return null; |
|
1768 | + if ($cached_columns === false) |
|
1769 | + { |
|
1770 | + return null; |
|
1771 | + } |
|
1674 | 1772 | |
1675 | 1773 | return is_null($attribute) ? $cached_columns[$column] : $cached_columns[$column][$attribute]; |
1676 | 1774 | } |
@@ -1693,9 +1791,15 @@ discard block |
||
1693 | 1791 | */ |
1694 | 1792 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1695 | 1793 | { |
1696 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1794 | + if ($this->Debug) |
|
1795 | + { |
|
1796 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1797 | + } |
|
1697 | 1798 | |
1698 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1799 | + if (!$table_def) |
|
1800 | + { |
|
1801 | + $table_def = $this->get_table_definitions($app,$table); |
|
1802 | + } |
|
1699 | 1803 | |
1700 | 1804 | $sql_append = ''; |
1701 | 1805 | $cmd = 'INSERT'; |
@@ -1737,9 +1841,12 @@ discard block |
||
1737 | 1841 | $table = self::$tablealiases[$table]; |
1738 | 1842 | } |
1739 | 1843 | $inputarr = false; |
1740 | - if (isset($data[0]) && is_array($data[0])) // multiple data rows |
|
1844 | + if (isset($data[0]) && is_array($data[0])) |
|
1845 | + { |
|
1846 | + // multiple data rows |
|
1741 | 1847 | { |
1742 | 1848 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
1849 | + } |
|
1743 | 1850 | |
1744 | 1851 | $sql = "$cmd INTO $table "; |
1745 | 1852 | foreach($data as $k => $d) |
@@ -1755,15 +1862,22 @@ discard block |
||
1755 | 1862 | } |
1756 | 1863 | $sql .= $sql_append; |
1757 | 1864 | } |
1758 | - elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
1865 | + elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
1759 | 1866 | { |
1760 | - $this->Link_ID->Param(false); // reset param-counter |
|
1867 | + // eg. MaxDB |
|
1868 | + { |
|
1869 | + $this->Link_ID->Param(false); |
|
1870 | + } |
|
1871 | + // reset param-counter |
|
1761 | 1872 | $cols = array_keys($data); |
1762 | 1873 | foreach($cols as $k => $col) |
1763 | 1874 | { |
1764 | - if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
|
1875 | + if (!isset($table_def['fd'][$col])) |
|
1876 | + { |
|
1877 | + // ignore columns not in this table |
|
1765 | 1878 | { |
1766 | 1879 | unset($cols[$k]); |
1880 | + } |
|
1767 | 1881 | continue; |
1768 | 1882 | } |
1769 | 1883 | $params[] = $this->Link_ID->Param($col); |
@@ -1781,7 +1895,10 @@ discard block |
||
1781 | 1895 | { |
1782 | 1896 | $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
1783 | 1897 | } |
1784 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1898 | + if ($this->Debug) |
|
1899 | + { |
|
1900 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1901 | + } |
|
1785 | 1902 | return $this->query($sql,$line,$file,0,-1,$inputarr); |
1786 | 1903 | } |
1787 | 1904 | |
@@ -1802,8 +1919,14 @@ discard block |
||
1802 | 1919 | */ |
1803 | 1920 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1804 | 1921 | { |
1805 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
1806 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1922 | + if ($this->Debug) |
|
1923 | + { |
|
1924 | + echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
1925 | + } |
|
1926 | + if (!$table_def) |
|
1927 | + { |
|
1928 | + $table_def = $this->get_table_definitions($app,$table); |
|
1929 | + } |
|
1807 | 1930 | |
1808 | 1931 | $blobs2update = array(); |
1809 | 1932 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1812,7 +1935,10 @@ discard block |
||
1812 | 1935 | { |
1813 | 1936 | case 'sapdb': |
1814 | 1937 | case 'maxdb': |
1815 | - if ($use_prepared_statement) break; |
|
1938 | + if ($use_prepared_statement) |
|
1939 | + { |
|
1940 | + break; |
|
1941 | + } |
|
1816 | 1942 | // check if data contains any LONG columns |
1817 | 1943 | foreach($data as $col => $val) |
1818 | 1944 | { |
@@ -1837,12 +1963,20 @@ discard block |
||
1837 | 1963 | if (count($data)) |
1838 | 1964 | { |
1839 | 1965 | $inputarr = false; |
1840 | - if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
1966 | + if ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
1967 | + { |
|
1968 | + // eg. MaxDB |
|
1841 | 1969 | { |
1842 | - $this->Link_ID->Param(false); // reset param-counter |
|
1970 | + $this->Link_ID->Param(false); |
|
1971 | + } |
|
1972 | + // reset param-counter |
|
1843 | 1973 | foreach($data as $col => $val) |
1844 | 1974 | { |
1845 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
1975 | + if (!isset($table_def['fd'][$col])) |
|
1976 | + { |
|
1977 | + continue; |
|
1978 | + } |
|
1979 | + // ignore columns not in this table |
|
1846 | 1980 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
1847 | 1981 | } |
1848 | 1982 | $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
@@ -1860,7 +1994,10 @@ discard block |
||
1860 | 1994 | $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
1861 | 1995 | } |
1862 | 1996 | $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
1863 | - if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
1997 | + if ($this->Debug) |
|
1998 | + { |
|
1999 | + echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
2000 | + } |
|
1864 | 2001 | } |
1865 | 2002 | // if we have any blobs to update, we do so now |
1866 | 2003 | if (($ret || !count($data)) && count($blobs2update)) |
@@ -1868,8 +2005,14 @@ discard block |
||
1868 | 2005 | foreach($blobs2update as $col => $val) |
1869 | 2006 | { |
1870 | 2007 | $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
1871 | - if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
1872 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
2008 | + if ($this->Debug) |
|
2009 | + { |
|
2010 | + echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
2011 | + } |
|
2012 | + if (!$ret) |
|
2013 | + { |
|
2014 | + throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
2015 | + } |
|
1873 | 2016 | } |
1874 | 2017 | } |
1875 | 2018 | return $ret; |
@@ -1890,7 +2033,10 @@ discard block |
||
1890 | 2033 | */ |
1891 | 2034 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
1892 | 2035 | { |
1893 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2036 | + if (!$table_def) |
|
2037 | + { |
|
2038 | + $table_def = $this->get_table_definitions($app,$table); |
|
2039 | + } |
|
1894 | 2040 | |
1895 | 2041 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
1896 | 2042 | { |
@@ -1922,19 +2068,29 @@ discard block |
||
1922 | 2068 | */ |
1923 | 2069 | function expression($table_def/*,$args, ...*/) |
1924 | 2070 | { |
1925 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
2071 | + if (!is_array($table_def)) |
|
2072 | + { |
|
2073 | + $table_def = $this->get_table_definitions(true,$table_def); |
|
2074 | + } |
|
1926 | 2075 | $sql = ''; |
1927 | 2076 | $ignore_next = 0; |
1928 | 2077 | foreach(func_get_args() as $n => $arg) |
1929 | 2078 | { |
1930 | - if ($n < 1) continue; // table-name |
|
2079 | + if ($n < 1) |
|
2080 | + { |
|
2081 | + continue; |
|
2082 | + } |
|
2083 | + // table-name |
|
1931 | 2084 | |
1932 | 2085 | if ($ignore_next) |
1933 | 2086 | { |
1934 | 2087 | --$ignore_next; |
1935 | 2088 | continue; |
1936 | 2089 | } |
1937 | - if (is_null($arg)) $arg = False; |
|
2090 | + if (is_null($arg)) |
|
2091 | + { |
|
2092 | + $arg = False; |
|
2093 | + } |
|
1938 | 2094 | |
1939 | 2095 | switch(gettype($arg)) |
1940 | 2096 | { |
@@ -1974,9 +2130,15 @@ discard block |
||
1974 | 2130 | */ |
1975 | 2131 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
1976 | 2132 | { |
1977 | - if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
2133 | + if ($this->Debug) |
|
2134 | + { |
|
2135 | + echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
2136 | + } |
|
1978 | 2137 | |
1979 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2138 | + if (!$table_def) |
|
2139 | + { |
|
2140 | + $table_def = $this->get_table_definitions($app,$table); |
|
2141 | + } |
|
1980 | 2142 | if (is_array($cols)) |
1981 | 2143 | { |
1982 | 2144 | $cols = implode(',',$cols); |
@@ -1992,16 +2154,28 @@ discard block |
||
1992 | 2154 | $sql = "SELECT $cols FROM $table $join"; |
1993 | 2155 | |
1994 | 2156 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
1995 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2157 | + if ($where) |
|
2158 | + { |
|
2159 | + $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2160 | + } |
|
1996 | 2161 | |
1997 | - if ($append) $sql .= ' '.$append; |
|
2162 | + if ($append) |
|
2163 | + { |
|
2164 | + $sql .= ' '.$append; |
|
2165 | + } |
|
1998 | 2166 | |
1999 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
2167 | + if ($this->Debug) |
|
2168 | + { |
|
2169 | + echo "<p>sql='$sql'</p>"; |
|
2170 | + } |
|
2000 | 2171 | |
2001 | - if ($line === false && $file === false) // call by union, to return the sql rather then run the query |
|
2172 | + if ($line === false && $file === false) |
|
2173 | + { |
|
2174 | + // call by union, to return the sql rather then run the query |
|
2002 | 2175 | { |
2003 | 2176 | return $sql; |
2004 | 2177 | } |
2178 | + } |
|
2005 | 2179 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
2006 | 2180 | } |
2007 | 2181 | |
@@ -2022,7 +2196,10 @@ discard block |
||
2022 | 2196 | */ |
2023 | 2197 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
2024 | 2198 | { |
2025 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2199 | + if ($this->Debug) |
|
2200 | + { |
|
2201 | + echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2202 | + } |
|
2026 | 2203 | |
2027 | 2204 | $union = array(); |
2028 | 2205 | foreach($selects as $select) |
@@ -2043,9 +2220,15 @@ discard block |
||
2043 | 2220 | } |
2044 | 2221 | $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
2045 | 2222 | |
2046 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2223 | + if ($order_by) |
|
2224 | + { |
|
2225 | + $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2226 | + } |
|
2047 | 2227 | |
2048 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
2228 | + if ($this->Debug) |
|
2229 | + { |
|
2230 | + echo "<p>sql='$sql'</p>"; |
|
2231 | + } |
|
2049 | 2232 | |
2050 | 2233 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
2051 | 2234 | } |
@@ -1845,7 +1845,7 @@ discard block |
||
1845 | 1845 | if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
1846 | 1846 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
1847 | 1847 | } |
1848 | - $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
1848 | + $sql = "update $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
1849 | 1849 | // check if we already prepared that statement |
1850 | 1850 | if (!isset($this->prepared_sql[$sql])) |
1851 | 1851 | { |
@@ -1856,7 +1856,7 @@ discard block |
||
1856 | 1856 | } |
1857 | 1857 | else |
1858 | 1858 | { |
1859 | - $sql = "UPDATE $table SET ". |
|
1859 | + $sql = "update $table SET ". |
|
1860 | 1860 | $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
1861 | 1861 | } |
1862 | 1862 | $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
@@ -1989,7 +1989,7 @@ discard block |
||
1989 | 1989 | { |
1990 | 1990 | $table = self::$tablealiases[$table]; |
1991 | 1991 | } |
1992 | - $sql = "SELECT $cols FROM $table $join"; |
|
1992 | + $sql = "select $cols FROM $table $join"; |
|
1993 | 1993 | |
1994 | 1994 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
1995 | 1995 | if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | namespace EGroupware\Api; |
15 | 15 | |
16 | -if(empty($GLOBALS['egw_info']['server']['db_type'])) |
|
16 | +if (empty($GLOBALS['egw_info']['server']['db_type'])) |
|
17 | 17 | { |
18 | 18 | $GLOBALS['egw_info']['server']['db_type'] = 'mysql'; |
19 | 19 | } |
@@ -69,22 +69,22 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types |
71 | 71 | */ |
72 | - var $Type = ''; |
|
72 | + var $Type = ''; |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @var string $type database type as defined in the header.inc.php, eg. mysqlt |
76 | 76 | */ |
77 | - var $setupType = ''; |
|
77 | + var $setupType = ''; |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @var string $Host database host to connect to |
81 | 81 | */ |
82 | - var $Host = ''; |
|
82 | + var $Host = ''; |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @var string $Port port number of database to connect to |
86 | 86 | */ |
87 | - var $Port = ''; |
|
87 | + var $Port = ''; |
|
88 | 88 | |
89 | 89 | /** |
90 | 90 | * @var string $Database name of database to use |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | /** |
95 | 95 | * @var string $User name of database user |
96 | 96 | */ |
97 | - var $User = ''; |
|
97 | + var $User = ''; |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @var string $Password password for database user |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * @var int $Debug enable debuging - 0 no, 1 yes |
106 | 106 | */ |
107 | - var $Debug = 0; |
|
107 | + var $Debug = 0; |
|
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Log update querys to error_log, do not run them |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | /** |
117 | 117 | * @var array $Record current record |
118 | 118 | */ |
119 | - var $Record = array(); |
|
119 | + var $Record = array(); |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * @var int row number for current record |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * @var int $Errno internal rdms error number for last error |
128 | 128 | */ |
129 | - var $Errno = 0; |
|
129 | + var $Errno = 0; |
|
130 | 130 | |
131 | 131 | /** |
132 | 132 | * @var string descriptive text from last error |
133 | 133 | */ |
134 | - var $Error = ''; |
|
134 | + var $Error = ''; |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * eGW's own query log, independent of the db-type, eg. /tmp/query.log |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @var ADOConnection |
153 | 153 | */ |
154 | - var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
154 | + var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Can be used to transparently convert tablenames, eg. 'mytable' => 'otherdb.othertable' |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | /** |
188 | 188 | * db is able to use DISTINCT on text or blob columns |
189 | 189 | */ |
190 | - const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
190 | + const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
191 | 191 | /** |
192 | 192 | * DB is able to use LIKE on text columns |
193 | 193 | */ |
194 | - const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
194 | + const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
195 | 195 | /** |
196 | 196 | * DB allows ORDER on text columns |
197 | 197 | * |
@@ -243,18 +243,18 @@ discard block |
||
243 | 243 | self::CAPABILITY_CAST_AS_VARCHAR => 'CAST(%s AS varchar)', |
244 | 244 | ); |
245 | 245 | |
246 | - var $prepared_sql = array(); // sql is the index |
|
246 | + var $prepared_sql = array(); // sql is the index |
|
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Constructor |
250 | 250 | * |
251 | 251 | * @param array $db_data =null values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type' |
252 | 252 | */ |
253 | - function __construct(array $db_data=null) |
|
253 | + function __construct(array $db_data = null) |
|
254 | 254 | { |
255 | 255 | if (!is_null($db_data)) |
256 | 256 | { |
257 | - foreach(array( |
|
257 | + foreach (array( |
|
258 | 258 | 'Database' => 'db_name', |
259 | 259 | 'Host' => 'db_host', |
260 | 260 | 'Port' => 'db_port', |
@@ -307,15 +307,15 @@ discard block |
||
307 | 307 | } |
308 | 308 | if (!is_null($Host) && $Host) |
309 | 309 | { |
310 | - $this->Host = $Host; |
|
310 | + $this->Host = $Host; |
|
311 | 311 | } |
312 | 312 | if (!is_null($Port) && $Port) |
313 | 313 | { |
314 | - $this->Port = $Port; |
|
314 | + $this->Port = $Port; |
|
315 | 315 | } |
316 | 316 | if (!is_null($User) && $User) |
317 | 317 | { |
318 | - $this->User = $User; |
|
318 | + $this->User = $User; |
|
319 | 319 | } |
320 | 320 | if (!is_null($Password) && $Password) |
321 | 321 | { |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | // on connection failure re-try with an other host |
333 | 333 | // remembering in session which host we used last time |
334 | 334 | $use_host_from_session = true; |
335 | - while(($host = $this->get_host(!$use_host_from_session))) |
|
335 | + while (($host = $this->get_host(!$use_host_from_session))) |
|
336 | 336 | { |
337 | 337 | try { |
338 | 338 | //error_log(__METHOD__."() this->Host(s)=$this->Host, n=$n --> host=$host"); |
@@ -346,11 +346,11 @@ discard block |
||
346 | 346 | //error_log(__METHOD__."() host=$host, new_connection=$new_connection, this->Type=$this->Type, this->Host=$this->Host, wsrep_local_state=".array2string($state)); |
347 | 347 | return $this->Link_ID; |
348 | 348 | } |
349 | - catch(Db\Exception\Connection $e) { |
|
349 | + catch (Db\Exception\Connection $e) { |
|
350 | 350 | //_egw_log_exception($e); |
351 | - $this->disconnect(); // force a new connect |
|
352 | - $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
353 | - $use_host_from_session = false; // re-try with next host from list |
|
351 | + $this->disconnect(); // force a new connect |
|
352 | + $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
353 | + $use_host_from_session = false; // re-try with next host from list |
|
354 | 354 | } |
355 | 355 | } |
356 | 356 | if (!isset($e)) |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | { |
402 | 402 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
403 | 403 | $num_hosts = count($hosts); |
404 | - $n =& Cache::getSession(__CLASS__, $this->Host); |
|
404 | + $n = & Cache::getSession(__CLASS__, $this->Host); |
|
405 | 405 | if (!isset($n)) $n = 0; |
406 | 406 | |
407 | - if ($next && ++$n >= $num_hosts+2) |
|
407 | + if ($next && ++$n >= $num_hosts + 2) |
|
408 | 408 | { |
409 | - $n = 0; // start search again with default on next request |
|
409 | + $n = 0; // start search again with default on next request |
|
410 | 410 | $ret = false; |
411 | 411 | } |
412 | 412 | else |
@@ -429,21 +429,21 @@ discard block |
||
429 | 429 | if (!$this->Link_ID) |
430 | 430 | { |
431 | 431 | $Database = $User = $Password = $Port = $Type = ''; |
432 | - foreach(array('Database','User','Password','Port','Type') as $name) |
|
432 | + foreach (array('Database', 'User', 'Password', 'Port', 'Type') as $name) |
|
433 | 433 | { |
434 | 434 | $$name = $this->$name; |
435 | 435 | if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
436 | 436 | } |
437 | 437 | $this->setupType = $php_extension = $Type; |
438 | 438 | |
439 | - switch($Type) // convert to ADO db-type-names |
|
439 | + switch ($Type) // convert to ADO db-type-names |
|
440 | 440 | { |
441 | 441 | case 'pgsql': |
442 | 442 | $Type = 'postgres'; // name in ADOdb |
443 | 443 | // create our own pgsql connection-string, to allow unix domain soccets if !$Host |
444 | 444 | $Host = "dbname=$Database".($Host ? " host=$Host".($Port ? " port=$Port" : '') : ''). |
445 | 445 | " user=$User".($Password ? " password='".addslashes($Password)."'" : ''); |
446 | - $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
446 | + $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
447 | 447 | break; |
448 | 448 | |
449 | 449 | case 'odbc_mssql': |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | $Type = 'maxdb'; |
467 | 467 | // fall through |
468 | 468 | case 'maxdb': |
469 | - $Type ='sapdb'; // name in ADOdb |
|
469 | + $Type = 'sapdb'; // name in ADOdb |
|
470 | 470 | $php_extension = 'odbc'; |
471 | 471 | break; |
472 | 472 | |
@@ -479,18 +479,18 @@ discard block |
||
479 | 479 | } |
480 | 480 | else |
481 | 481 | { |
482 | - $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
482 | + $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
483 | 483 | } |
484 | 484 | // fall through |
485 | 485 | case 'mysqli': |
486 | - $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
486 | + $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
487 | 487 | // fall through |
488 | 488 | default: |
489 | 489 | if ($Port) $Host .= ':'.$Port; |
490 | 490 | break; |
491 | 491 | } |
492 | - if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
493 | - (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
492 | + if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
493 | + (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
494 | 494 | ($this->Type != $GLOBALS['egw']->db->Type || |
495 | 495 | $this->Database != $GLOBALS['egw']->db->Database || |
496 | 496 | $this->User != $GLOBALS['egw']->db->User || |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | } |
504 | 504 | if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
505 | 505 | { |
506 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
506 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
507 | 507 | } |
508 | 508 | else |
509 | 509 | { |
510 | - $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
510 | + $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
511 | 511 | } |
512 | 512 | $this->Link_ID = ADONewConnection($Type); |
513 | 513 | if (!$this->Link_ID) |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database))) |
524 | 524 | { |
525 | 525 | $this->ServerInfo = $this->Link_ID->ServerInfo(); |
526 | - $this->set_capabilities($Type,$this->ServerInfo['version']); |
|
526 | + $this->set_capabilities($Type, $this->ServerInfo['version']); |
|
527 | 527 | |
528 | 528 | // switch off MySQL 5.7+ ONLY_FULL_GROUP_BY sql_mode |
529 | 529 | if (substr($this->Type, 0, 5) == 'mysql' && $this->ServerInfo['version'] >= 5.7 && $this->ServerInfo['version'] < 10.0) |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | } |
534 | 534 | if (!$Ok) |
535 | 535 | { |
536 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
536 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
537 | 537 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); |
538 | 538 | } |
539 | 539 | if ($this->Debug) |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | // this is the format ADOdb expects |
550 | 550 | $this->Link_ID->Execute('SET DATEFORMAT ymd'); |
551 | 551 | // sets the limit to the maximum |
552 | - ini_set('mssql.textlimit',2147483647); |
|
553 | - ini_set('mssql.sizelimit',2147483647); |
|
552 | + ini_set('mssql.textlimit', 2147483647); |
|
553 | + ini_set('mssql.sizelimit', 2147483647); |
|
554 | 554 | } |
555 | 555 | // set our default charset |
556 | 556 | $this->Link_ID->SetCharSet($this->Type == 'mysql' ? 'utf8' : 'utf-8'); |
@@ -559,12 +559,12 @@ discard block |
||
559 | 559 | } |
560 | 560 | else |
561 | 561 | { |
562 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
562 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
563 | 563 | } |
564 | 564 | } |
565 | 565 | if (!$this->Link_ID->isConnected() && !$this->Link_ID->Connect()) |
566 | 566 | { |
567 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
567 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
568 | 568 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) reconnect failed."); |
569 | 569 | } |
570 | 570 | // fix due to caching and reusing of connection not correctly set $this->Type == 'mysql' |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | } |
576 | 576 | if ($new_connection) |
577 | 577 | { |
578 | - foreach(get_included_files() as $file) |
|
578 | + foreach (get_included_files() as $file) |
|
579 | 579 | { |
580 | - if (strpos($file,'adodb') !== false && !in_array($file,(array)$_SESSION['egw_required_files'])) |
|
580 | + if (strpos($file, 'adodb') !== false && !in_array($file, (array)$_SESSION['egw_required_files'])) |
|
581 | 581 | { |
582 | 582 | $_SESSION['egw_required_files'][] = $file; |
583 | 583 | //error_log(__METHOD__."() egw_required_files[] = $file"); |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | */ |
594 | 594 | function __wakeup() |
595 | 595 | { |
596 | - $this->connect(); // we need to re-connect |
|
596 | + $this->connect(); // we need to re-connect |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | */ |
607 | 607 | function __sleep() |
608 | 608 | { |
609 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
609 | + if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
610 | 610 | |
611 | 611 | $vars = get_object_vars($this); |
612 | 612 | unset($vars['Link_ID']); |
@@ -620,23 +620,23 @@ discard block |
||
620 | 620 | * @param string $adodb_driver mysql, postgres, mssql, sapdb, oci8 |
621 | 621 | * @param string $db_version version-number of connected db-server, as reported by ServerInfo |
622 | 622 | */ |
623 | - function set_capabilities($adodb_driver,$db_version) |
|
623 | + function set_capabilities($adodb_driver, $db_version) |
|
624 | 624 | { |
625 | - switch($adodb_driver) |
|
625 | + switch ($adodb_driver) |
|
626 | 626 | { |
627 | 627 | case 'mysql': |
628 | 628 | case 'mysqlt': |
629 | 629 | case 'mysqli': |
630 | - $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float) $db_version >= 4.1; |
|
631 | - $this->capabilities[self::CAPABILITY_UNION] = (float) $db_version >= 4.0; |
|
630 | + $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float)$db_version >= 4.1; |
|
631 | + $this->capabilities[self::CAPABILITY_UNION] = (float)$db_version >= 4.0; |
|
632 | 632 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'preserv'; |
633 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 4.1; |
|
633 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 4.1; |
|
634 | 634 | $this->capabilities[self::CAPABILITY_CAST_AS_VARCHAR] = 'CAST(%s AS char)'; |
635 | 635 | break; |
636 | 636 | |
637 | 637 | case 'postgres': |
638 | 638 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'lower'; |
639 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 7.4; |
|
639 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 7.4; |
|
640 | 640 | $this->capabilities[self::CAPABILITY_OUTER_JOIN] = true; |
641 | 641 | $this->capabilities[self::CAPABILITY_CASE_INSENSITIV_LIKE] = '::text ILIKE'; |
642 | 642 | $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR] = true; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | return False; |
686 | 686 | } |
687 | 687 | // the substring is needed as the string is already in quotes |
688 | - return substr($this->Link_ID->DBTimeStamp($epoch),1,-1); |
|
688 | + return substr($this->Link_ID->DBTimeStamp($epoch), 1, -1); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public static function from_bool($val) |
713 | 713 | { |
714 | - return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
714 | + return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -728,9 +728,9 @@ discard block |
||
728 | 728 | * @return ADORecordSet or false, if the query fails |
729 | 729 | * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
730 | 730 | */ |
731 | - function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
|
731 | + function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true) |
|
732 | 732 | { |
733 | - unset($line, $file); // not used anymore |
|
733 | + unset($line, $file); // not used anymore |
|
734 | 734 | |
735 | 735 | if ($Query_String == '') |
736 | 736 | { |
@@ -756,23 +756,23 @@ discard block |
||
756 | 756 | } |
757 | 757 | if ($num_rows > 0) |
758 | 758 | { |
759 | - $rs = $this->Link_ID->SelectLimit($Query_String,$num_rows,(int)$offset,$inputarr); |
|
759 | + $rs = $this->Link_ID->SelectLimit($Query_String, $num_rows, (int)$offset, $inputarr); |
|
760 | 760 | } |
761 | 761 | else |
762 | 762 | { |
763 | - $rs = $this->Link_ID->Execute($Query_String,$inputarr); |
|
763 | + $rs = $this->Link_ID->Execute($Query_String, $inputarr); |
|
764 | 764 | } |
765 | 765 | $this->Row = 0; |
766 | 766 | $this->Errno = $this->Link_ID->ErrorNo(); |
767 | 767 | $this->Error = $this->Link_ID->ErrorMsg(); |
768 | 768 | |
769 | - if ($this->query_log && ($f = @fopen($this->query_log,'a+'))) |
|
769 | + if ($this->query_log && ($f = @fopen($this->query_log, 'a+'))) |
|
770 | 770 | { |
771 | - fwrite($f,'['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
772 | - fwrite($f,date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr,true) : '')."\n"); |
|
771 | + fwrite($f, '['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
772 | + fwrite($f, date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr, true) : '')."\n"); |
|
773 | 773 | if (!$rs) |
774 | 774 | { |
775 | - fwrite($f,"*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
775 | + fwrite($f, "*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
776 | 776 | } |
777 | 777 | fclose($f); |
778 | 778 | } |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | $this->disconnect(); |
784 | 784 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
785 | 785 | } |
786 | - throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
|
786 | + throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String) ? $Query_String[0] : $Query_String). |
|
787 | 787 | "\n$this->Error ($this->Errno)". |
788 | - ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
|
788 | + ($inputarr ? "\nParameters: '".implode("','", $inputarr)."'" : ''), $this->Errno); |
|
789 | 789 | } |
790 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
790 | + elseif (empty($rs->sql)) $rs->sql = $Query_String; |
|
791 | 791 | return $rs; |
792 | 792 | } |
793 | 793 | |
@@ -802,9 +802,9 @@ discard block |
||
802 | 802 | * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
803 | 803 | * @return ADORecordSet or false, if the query fails |
804 | 804 | */ |
805 | - function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
|
805 | + function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '', $inputarr = false) |
|
806 | 806 | { |
807 | - return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
|
807 | + return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | /** |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | * @param string $where ='true' where clause to use, eg: "WHERE row=12". Defaults to lock whole table. |
863 | 863 | * @param string $col ='1 as adodbignore' |
864 | 864 | */ |
865 | - function row_lock($table, $where='true', $col='1 as adodbignore') |
|
865 | + function row_lock($table, $where = 'true', $col = '1 as adodbignore') |
|
866 | 866 | { |
867 | 867 | if (!$this->Link_ID && !$this->connect()) |
868 | 868 | { |
@@ -933,7 +933,7 @@ discard block |
||
933 | 933 | { |
934 | 934 | $table = self::$tablealiases[$table]; |
935 | 935 | } |
936 | - $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
936 | + $id = $this->Link_ID->PO_Insert_ID($table, $field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
937 | 937 | |
938 | 938 | if ($id === False) // function not supported |
939 | 939 | { |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | * @param bool $full optional, default False summary information, True full information |
970 | 970 | * @return array table meta data |
971 | 971 | */ |
972 | - function metadata($table='',$full=false) |
|
972 | + function metadata($table = '', $full = false) |
|
973 | 973 | { |
974 | 974 | if (!$this->Link_ID && !$this->connect()) |
975 | 975 | { |
@@ -981,13 +981,13 @@ discard block |
||
981 | 981 | |
982 | 982 | $metadata = array(); |
983 | 983 | $i = 0; |
984 | - foreach($columns as $column) |
|
984 | + foreach ($columns as $column) |
|
985 | 985 | { |
986 | 986 | // for backwards compatibilty (depreciated) |
987 | 987 | $flags = null; |
988 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
989 | - if($column->primary_key) $flags .= "primary_key "; |
|
990 | - if($column->binary) $flags .= "binary "; |
|
988 | + if ($column->auto_increment) $flags .= "auto_increment "; |
|
989 | + if ($column->primary_key) $flags .= "primary_key "; |
|
990 | + if ($column->binary) $flags .= "binary "; |
|
991 | 991 | |
992 | 992 | $metadata[$i] = array( |
993 | 993 | 'table' => $table, |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | * @param boolean $just_name =false true return array of table-names, false return old format |
1023 | 1023 | * @return array list of the tables |
1024 | 1024 | */ |
1025 | - function table_names($just_name=false) |
|
1025 | + function table_names($just_name = false) |
|
1026 | 1026 | { |
1027 | 1027 | if (!$this->Link_ID) $this->connect(); |
1028 | 1028 | if (!$this->Link_ID) |
@@ -1033,7 +1033,7 @@ discard block |
||
1033 | 1033 | $tables = $this->Link_ID->MetaTables('TABLES'); |
1034 | 1034 | if (is_array($tables)) |
1035 | 1035 | { |
1036 | - foreach($tables as $table) |
|
1036 | + foreach ($tables as $table) |
|
1037 | 1037 | { |
1038 | 1038 | if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') |
1039 | 1039 | { |
@@ -1062,7 +1062,7 @@ discard block |
||
1062 | 1062 | echo "<p>db::index_names() not yet implemented for db-type '$this->Type'</p>\n"; |
1063 | 1063 | return $indices; |
1064 | 1064 | } |
1065 | - foreach($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
1065 | + foreach ($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
1066 | 1066 | { |
1067 | 1067 | $indices[] = array( |
1068 | 1068 | 'index_name' => $row[0], |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | * @param string $charset default charset for the database |
1096 | 1096 | * @param string $grant_host ='localhost' host/ip of the webserver |
1097 | 1097 | */ |
1098 | - function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
|
1098 | + function create_database($adminname = '', $adminpasswd = '', $charset = '', $grant_host = 'localhost') |
|
1099 | 1099 | { |
1100 | 1100 | $currentUser = $this->User; |
1101 | 1101 | $currentPassword = $this->Password; |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | case 'mysqli': |
1120 | 1120 | case 'mysqlt': |
1121 | 1121 | $create = "CREATE DATABASE `$currentDatabase`"; |
1122 | - if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float) $this->ServerInfo['version'] >= 4.1) |
|
1122 | + if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float)$this->ServerInfo['version'] >= 4.1) |
|
1123 | 1123 | { |
1124 | 1124 | $create .= ' DEFAULT CHARACTER SET '.$this->Link_ID->charset2mysql[$charset].';'; |
1125 | 1125 | } |
@@ -1130,9 +1130,9 @@ discard block |
||
1130 | 1130 | throw new Exception\WrongParameter(__METHOD__."(user=$adminname, \$pw) not yet implemented for DB-type '$this->Type'"); |
1131 | 1131 | } |
1132 | 1132 | //error_log(__METHOD__."() this->Type=$this->Type: sqls=".array2string($sqls)); |
1133 | - foreach($sqls as $sql) |
|
1133 | + foreach ($sqls as $sql) |
|
1134 | 1134 | { |
1135 | - $this->query($sql,__LINE__,__FILE__); |
|
1135 | + $this->query($sql, __LINE__, __FILE__); |
|
1136 | 1136 | } |
1137 | 1137 | $this->disconnect(); |
1138 | 1138 | |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | { |
1159 | 1159 | return False; |
1160 | 1160 | } |
1161 | - return call_user_func_array(array(&$this->Link_ID,'concat'),$args); |
|
1161 | + return call_user_func_array(array(&$this->Link_ID, 'concat'), $args); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | /** |
@@ -1169,9 +1169,9 @@ discard block |
||
1169 | 1169 | * @param string $separator =',' optional separator, default is comma |
1170 | 1170 | * @return string|boolean false if not supported by dbms |
1171 | 1171 | */ |
1172 | - function group_concat($expr, $order_by='', $separator=',') |
|
1172 | + function group_concat($expr, $order_by = '', $separator = ',') |
|
1173 | 1173 | { |
1174 | - switch($this->Type) |
|
1174 | + switch ($this->Type) |
|
1175 | 1175 | { |
1176 | 1176 | case 'mysql': |
1177 | 1177 | $sql = 'GROUP_CONCAT('.$expr; |
@@ -1205,7 +1205,7 @@ discard block |
||
1205 | 1205 | */ |
1206 | 1206 | function strpos($str, $substr) |
1207 | 1207 | { |
1208 | - switch($this->Type) |
|
1208 | + switch ($this->Type) |
|
1209 | 1209 | { |
1210 | 1210 | case 'mysql': |
1211 | 1211 | return "LOCATE($substr,$str)"; |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | */ |
1226 | 1226 | function unix_timestamp($expr) |
1227 | 1227 | { |
1228 | - switch($this->Type) |
|
1228 | + switch ($this->Type) |
|
1229 | 1229 | { |
1230 | 1230 | case 'mysql': |
1231 | 1231 | return "UNIX_TIMESTAMP($expr)"; |
@@ -1246,7 +1246,7 @@ discard block |
||
1246 | 1246 | */ |
1247 | 1247 | function from_unixtime($expr) |
1248 | 1248 | { |
1249 | - switch($this->Type) |
|
1249 | + switch ($this->Type) |
|
1250 | 1250 | { |
1251 | 1251 | case 'mysql': |
1252 | 1252 | return "FROM_UNIXTIME($expr)"; |
@@ -1255,7 +1255,7 @@ discard block |
||
1255 | 1255 | return "(TIMESTAMP WITH TIME ZONE 'epoch' + ($expr) * INTERVAL '1 sec')"; |
1256 | 1256 | |
1257 | 1257 | case 'mssql': // we use date(,0) as we store server-time |
1258 | - return "DATEADD(second,($expr),'".date('Y-m-d H:i:s',0)."')"; |
|
1258 | + return "DATEADD(second,($expr),'".date('Y-m-d H:i:s', 0)."')"; |
|
1259 | 1259 | } |
1260 | 1260 | return false; |
1261 | 1261 | } |
@@ -1269,30 +1269,30 @@ discard block |
||
1269 | 1269 | * @param string $format format specifier like '%Y-%m-%d %H:%i:%s' or '%V%X' ('%v%x') weeknumber & year with Sunday (Monday) as first day |
1270 | 1270 | * @return string SQL expression of type timestamp |
1271 | 1271 | */ |
1272 | - function date_format($expr,$format) |
|
1272 | + function date_format($expr, $format) |
|
1273 | 1273 | { |
1274 | - switch($this->Type) |
|
1274 | + switch ($this->Type) |
|
1275 | 1275 | { |
1276 | 1276 | case 'mysql': |
1277 | 1277 | return "DATE_FORMAT($expr,'$format')"; |
1278 | 1278 | |
1279 | 1279 | case 'pgsql': |
1280 | 1280 | $format = str_replace( |
1281 | - array('%Y', '%y','%m','%d','%H', '%h','%i','%s','%V','%v','%X', '%x'), |
|
1282 | - array('YYYY','YY','MM','DD','HH24','HH','MI','SS','IW','IW','YYYY','YYYY'), |
|
1281 | + array('%Y', '%y', '%m', '%d', '%H', '%h', '%i', '%s', '%V', '%v', '%X', '%x'), |
|
1282 | + array('YYYY', 'YY', 'MM', 'DD', 'HH24', 'HH', 'MI', 'SS', 'IW', 'IW', 'YYYY', 'YYYY'), |
|
1283 | 1283 | $format); |
1284 | 1284 | return "TO_CHAR($expr,'$format')"; |
1285 | 1285 | |
1286 | 1286 | case 'mssql': |
1287 | 1287 | $from = $to = array(); |
1288 | - foreach(array('%Y'=>'yyyy','%y'=>'yy','%m'=>'mm','%d'=>'dd','%H'=>'hh','%i'=>'mi','%s'=>'ss','%V'=>'wk','%v'=>'wk','%X'=>'yyyy','%x'=>'yyyy') as $f => $t) |
|
1288 | + foreach (array('%Y'=>'yyyy', '%y'=>'yy', '%m'=>'mm', '%d'=>'dd', '%H'=>'hh', '%i'=>'mi', '%s'=>'ss', '%V'=>'wk', '%v'=>'wk', '%X'=>'yyyy', '%x'=>'yyyy') as $f => $t) |
|
1289 | 1289 | { |
1290 | 1290 | $from[] = $f; |
1291 | 1291 | $to[] = "'+DATEPART($t,($expr))+'"; |
1292 | 1292 | } |
1293 | 1293 | $from[] = "''+"; $to[] = ''; |
1294 | 1294 | $from[] = "+''"; $to[] = ''; |
1295 | - return str_replace($from,$to,$format); |
|
1295 | + return str_replace($from, $to, $format); |
|
1296 | 1296 | } |
1297 | 1297 | return false; |
1298 | 1298 | } |
@@ -1305,7 +1305,7 @@ discard block |
||
1305 | 1305 | */ |
1306 | 1306 | function to_double($expr) |
1307 | 1307 | { |
1308 | - switch($this->Type) |
|
1308 | + switch ($this->Type) |
|
1309 | 1309 | { |
1310 | 1310 | case 'pgsql': |
1311 | 1311 | return $expr.'::double'; |
@@ -1323,7 +1323,7 @@ discard block |
||
1323 | 1323 | */ |
1324 | 1324 | function to_int($expr) |
1325 | 1325 | { |
1326 | - switch($this->Type) |
|
1326 | + switch ($this->Type) |
|
1327 | 1327 | { |
1328 | 1328 | case 'pgsql': |
1329 | 1329 | return $expr.'::integer'; |
@@ -1341,7 +1341,7 @@ discard block |
||
1341 | 1341 | */ |
1342 | 1342 | function to_varchar($expr) |
1343 | 1343 | { |
1344 | - switch($this->Type) |
|
1344 | + switch ($this->Type) |
|
1345 | 1345 | { |
1346 | 1346 | case 'pgsql': |
1347 | 1347 | return 'CAST('.$expr.' AS varchar)'; |
@@ -1385,7 +1385,7 @@ discard block |
||
1385 | 1385 | // always quote for postgreSQL, as this is the only way to support mixed case names |
1386 | 1386 | if (preg_match('/\W/', $name) || $type == 'pgsql' && preg_match('/[A-Z]+/', $name) || $name == 'index') |
1387 | 1387 | { |
1388 | - return $quote . $name . $quote; |
|
1388 | + return $quote.$name.$quote; |
|
1389 | 1389 | } |
1390 | 1390 | return $name; |
1391 | 1391 | }, explode('.', $name)); |
@@ -1407,27 +1407,27 @@ discard block |
||
1407 | 1407 | * @param string $glue =',' used to glue array values together for the string type |
1408 | 1408 | * @return string escaped sting |
1409 | 1409 | */ |
1410 | - function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
|
1410 | + function quote($value, $type = False, $not_null = true, $length = null, $glue = ',') |
|
1411 | 1411 | { |
1412 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1412 | + if ($this->Debug) echo "<p>db::quote(".(is_null($value) ? 'NULL' : "'$value'").",'$type','$not_null')</p>\n"; |
|
1413 | 1413 | |
1414 | 1414 | if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
1415 | 1415 | { |
1416 | 1416 | return 'NULL'; |
1417 | 1417 | } |
1418 | - switch($type) |
|
1418 | + switch ($type) |
|
1419 | 1419 | { |
1420 | 1420 | case 'int': |
1421 | 1421 | // if DateTime object given, convert it to a unix timestamp (NOT converting the timezone!) |
1422 | 1422 | if (is_object($value) && ($value instanceof \DateTime)) |
1423 | 1423 | { |
1424 | - return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value,'ts'); |
|
1424 | + return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value, 'ts'); |
|
1425 | 1425 | } |
1426 | 1426 | case 'auto': |
1427 | 1427 | // atm. (php5.2) php has only 32bit integers, it converts everything else to float. |
1428 | 1428 | // Casting it to int gives a negative number instead of the big 64bit integer! |
1429 | 1429 | // There for we have to keep it as float by using round instead the int cast. |
1430 | - return is_float($value) ? round($value) : (int) $value; |
|
1430 | + return is_float($value) ? round($value) : (int)$value; |
|
1431 | 1431 | case 'bool': |
1432 | 1432 | if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
1433 | 1433 | { |
@@ -1436,23 +1436,23 @@ discard block |
||
1436 | 1436 | return $value ? 'true' : 'false'; |
1437 | 1437 | case 'float': |
1438 | 1438 | case 'decimal': |
1439 | - return (double) $value; |
|
1439 | + return (double)$value; |
|
1440 | 1440 | } |
1441 | 1441 | if (!$this->Link_ID && !$this->connect()) |
1442 | 1442 | { |
1443 | 1443 | return False; |
1444 | 1444 | } |
1445 | - switch($type) |
|
1445 | + switch ($type) |
|
1446 | 1446 | { |
1447 | 1447 | case 'blob': |
1448 | 1448 | switch ($this->Link_ID->blobEncodeType) |
1449 | 1449 | { |
1450 | 1450 | case 'C': // eg. postgres |
1451 | - return "'" . $this->Link_ID->BlobEncode($value) . "'"; |
|
1451 | + return "'".$this->Link_ID->BlobEncode($value)."'"; |
|
1452 | 1452 | case 'I': |
1453 | 1453 | return $this->Link_ID->BlobEncode($value); |
1454 | 1454 | } |
1455 | - break; // handled like strings |
|
1455 | + break; // handled like strings |
|
1456 | 1456 | case 'date': |
1457 | 1457 | // if DateTime object given, convert it (NOT converting the timezone!) |
1458 | 1458 | if (is_object($value) && ($value instanceof \DateTime)) |
@@ -1470,7 +1470,7 @@ discard block |
||
1470 | 1470 | } |
1471 | 1471 | if (is_array($value)) |
1472 | 1472 | { |
1473 | - $value = implode($glue,$value); |
|
1473 | + $value = implode($glue, $value); |
|
1474 | 1474 | } |
1475 | 1475 | // only truncate string if length given and <= 255 |
1476 | 1476 | // to not unnecessary truncate varchar(>255) as PostgreSQL uses text anyway and MySQL truncates itself silently (unless strict mode!) |
@@ -1508,7 +1508,7 @@ discard block |
||
1508 | 1508 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
1509 | 1509 | * @return string SQL |
1510 | 1510 | */ |
1511 | - function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
|
1511 | + function column_data_implode($glue, $array, $use_key = True, $only = False, $column_definitions = False) |
|
1512 | 1512 | { |
1513 | 1513 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
1514 | 1514 | { |
@@ -1518,16 +1518,16 @@ discard block |
||
1518 | 1518 | { |
1519 | 1519 | $column_definitions = $this->column_definitions; |
1520 | 1520 | } |
1521 | - if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
1521 | + if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array, True).",'$use_key',".print_r($only, True).",<pre>".print_r($column_definitions, True)."</pre>\n"; |
|
1522 | 1522 | |
1523 | 1523 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
1524 | 1524 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
1525 | 1525 | |
1526 | 1526 | $keys = $values = array(); |
1527 | - foreach($array as $key => $data) |
|
1527 | + foreach ($array as $key => $data) |
|
1528 | 1528 | { |
1529 | 1529 | if (is_int($key) && $use_key !== 'VALUES' || !$only || $only === True && isset($column_definitions[$key]) || |
1530 | - is_array($only) && in_array($key,$only)) |
|
1530 | + is_array($only) && in_array($key, $only)) |
|
1531 | 1531 | { |
1532 | 1532 | $keys[] = $this->name_quote($key); |
1533 | 1533 | |
@@ -1538,7 +1538,7 @@ discard block |
||
1538 | 1538 | if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
1539 | 1539 | if (!isset($column_definitions[$col])) |
1540 | 1540 | { |
1541 | - throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>"); |
|
1541 | + throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array, True).",'$use_key',".print_r($only, True).",<pre>".print_r($column_definitions, True)."</pre><b>nothing known about column '$key'!</b>"); |
|
1542 | 1542 | } |
1543 | 1543 | } |
1544 | 1544 | $column_type = is_array($column_definitions) ? @$column_definitions[$col]['type'] : False; |
@@ -1547,7 +1547,7 @@ discard block |
||
1547 | 1547 | $maxlength = null; |
1548 | 1548 | if ($truncate_varchar) |
1549 | 1549 | { |
1550 | - $maxlength = in_array($column_definitions[$col]['type'], array('varchar','ascii')) ? $column_definitions[$col]['precision'] : null; |
|
1550 | + $maxlength = in_array($column_definitions[$col]['type'], array('varchar', 'ascii')) ? $column_definitions[$col]['precision'] : null; |
|
1551 | 1551 | } |
1552 | 1552 | // dont use IN ( ), if there's only one value, it's slower for MySQL |
1553 | 1553 | if (is_array($data) && count($data) == 1) |
@@ -1557,39 +1557,38 @@ discard block |
||
1557 | 1557 | if (is_array($data)) |
1558 | 1558 | { |
1559 | 1559 | $or_null = ''; |
1560 | - foreach($data as $k => $v) |
|
1560 | + foreach ($data as $k => $v) |
|
1561 | 1561 | { |
1562 | - if (!$not_null && $use_key===True && is_null($v)) |
|
1562 | + if (!$not_null && $use_key === True && is_null($v)) |
|
1563 | 1563 | { |
1564 | 1564 | $or_null = $this->name_quote($key).' IS NULL)'; |
1565 | 1565 | unset($data[$k]); |
1566 | 1566 | continue; |
1567 | 1567 | } |
1568 | - $data[$k] = $this->quote($v,$column_type,$not_null,$maxlength); |
|
1568 | + $data[$k] = $this->quote($v, $column_type, $not_null, $maxlength); |
|
1569 | 1569 | } |
1570 | - $values[] = ($or_null?'(':'').(!count($data) ? |
|
1570 | + $values[] = ($or_null ? '(' : '').(!count($data) ? |
|
1571 | 1571 | // empty array on insert/update, store as NULL, or if not allowed whatever value NULL is casted to |
1572 | - $this->quote(null, $column_type, $not_null) : |
|
1573 | - ($use_key===True ? $this->name_quote($key).' IN ' : '') . |
|
1574 | - '('.implode(',',$data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
1572 | + $this->quote(null, $column_type, $not_null) : ($use_key === True ? $this->name_quote($key).' IN ' : ''). |
|
1573 | + '('.implode(',', $data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
1575 | 1574 | } |
1576 | - elseif (is_int($key) && $use_key===True) |
|
1575 | + elseif (is_int($key) && $use_key === True) |
|
1577 | 1576 | { |
1578 | - if (empty($data)) continue; // would give SQL error |
|
1577 | + if (empty($data)) continue; // would give SQL error |
|
1579 | 1578 | $values[] = $data; |
1580 | 1579 | } |
1581 | 1580 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
1582 | 1581 | { |
1583 | - $values[] = $this->name_quote($key) .' IS NULL'; |
|
1582 | + $values[] = $this->name_quote($key).' IS NULL'; |
|
1584 | 1583 | } |
1585 | 1584 | else |
1586 | 1585 | { |
1587 | - $values[] = ($use_key===True ? $this->name_quote($key) . '=' : '') . $this->quote($data,$column_type,$not_null,$maxlength); |
|
1586 | + $values[] = ($use_key === True ? $this->name_quote($key).'=' : '').$this->quote($data, $column_type, $not_null, $maxlength); |
|
1588 | 1587 | } |
1589 | 1588 | } |
1590 | 1589 | } |
1591 | - return ($use_key==='VALUES' ? '('.implode(',',$keys).') VALUES (' : ''). |
|
1592 | - implode($glue,$values) . ($use_key==='VALUES' ? ')' : ''); |
|
1590 | + return ($use_key === 'VALUES' ? '('.implode(',', $keys).') VALUES (' : ''). |
|
1591 | + implode($glue, $values).($use_key === 'VALUES' ? ')' : ''); |
|
1593 | 1592 | } |
1594 | 1593 | |
1595 | 1594 | /** |
@@ -1601,9 +1600,9 @@ discard block |
||
1601 | 1600 | * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
1602 | 1601 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
1603 | 1602 | */ |
1604 | - function set_column_definitions($column_definitions=False) |
|
1603 | + function set_column_definitions($column_definitions = False) |
|
1605 | 1604 | { |
1606 | - $this->column_definitions=$column_definitions; |
|
1605 | + $this->column_definitions = $column_definitions; |
|
1607 | 1606 | } |
1608 | 1607 | |
1609 | 1608 | /** |
@@ -1616,7 +1615,7 @@ discard block |
||
1616 | 1615 | * |
1617 | 1616 | * @var string |
1618 | 1617 | */ |
1619 | - private $app=self::API_APPNAME; |
|
1618 | + private $app = self::API_APPNAME; |
|
1620 | 1619 | |
1621 | 1620 | /** |
1622 | 1621 | * Sets the application in which the db-class looks for table-defintions |
@@ -1651,7 +1650,7 @@ discard block |
||
1651 | 1650 | * @param bool|string $table if set return only defintions of that table, else return all defintions |
1652 | 1651 | * @return mixed array with table-defintions or False if file not found |
1653 | 1652 | */ |
1654 | - function get_table_definitions($app=False,$table=False) |
|
1653 | + function get_table_definitions($app = False, $table = False) |
|
1655 | 1654 | { |
1656 | 1655 | // ease the transition to api |
1657 | 1656 | if ($app === 'phpgwapi') $app = 'api'; |
@@ -1659,7 +1658,7 @@ discard block |
||
1659 | 1658 | static $all_app_data = array(); |
1660 | 1659 | if ($app === true && $table) |
1661 | 1660 | { |
1662 | - foreach($all_app_data as $app => &$app_data) |
|
1661 | + foreach ($all_app_data as $app => &$app_data) |
|
1663 | 1662 | { |
1664 | 1663 | if (isset($app_data[$table])) |
1665 | 1664 | { |
@@ -1667,13 +1666,13 @@ discard block |
||
1667 | 1666 | } |
1668 | 1667 | } |
1669 | 1668 | // $table not found in loaded apps, check not yet loaded ones |
1670 | - foreach(scandir(EGW_INCLUDE_ROOT) as $app) |
|
1669 | + foreach (scandir(EGW_INCLUDE_ROOT) as $app) |
|
1671 | 1670 | { |
1672 | 1671 | if ($app[0] == '.' || !is_dir(EGW_INCLUDE_ROOT.'/'.$app) || isset($all_app_data[$app])) |
1673 | 1672 | { |
1674 | 1673 | continue; |
1675 | 1674 | } |
1676 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
1675 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
1677 | 1676 | if (!@file_exists($tables_current)) |
1678 | 1677 | { |
1679 | 1678 | $all_app_data[$app] = False; |
@@ -1682,7 +1681,7 @@ discard block |
||
1682 | 1681 | { |
1683 | 1682 | $phpgw_baseline = null; |
1684 | 1683 | include($tables_current); |
1685 | - $all_app_data[$app] =& $phpgw_baseline; |
|
1684 | + $all_app_data[$app] = & $phpgw_baseline; |
|
1686 | 1685 | unset($phpgw_baseline); |
1687 | 1686 | |
1688 | 1687 | if (isset($all_app_data[$app][$table])) |
@@ -1697,17 +1696,17 @@ discard block |
||
1697 | 1696 | { |
1698 | 1697 | $app = $this->app ? $this->app : $GLOBALS['egw_info']['flags']['currentapp']; |
1699 | 1698 | } |
1700 | - $app_data =& $all_app_data[$app]; |
|
1699 | + $app_data = & $all_app_data[$app]; |
|
1701 | 1700 | |
1702 | 1701 | if (!isset($app_data)) |
1703 | 1702 | { |
1704 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
1703 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
1705 | 1704 | if (!@file_exists($tables_current)) |
1706 | 1705 | { |
1707 | 1706 | return $app_data = False; |
1708 | 1707 | } |
1709 | 1708 | include($tables_current); |
1710 | - $app_data =& $phpgw_baseline; |
|
1709 | + $app_data = & $phpgw_baseline; |
|
1711 | 1710 | unset($phpgw_baseline); |
1712 | 1711 | } |
1713 | 1712 | if ($table && (!$app_data || !isset($app_data[$table]))) |
@@ -1730,14 +1729,14 @@ discard block |
||
1730 | 1729 | * @param string $attribute='comment' what field to return, NULL for array with all fields, default 'comment' to return the comment |
1731 | 1730 | * @return string|array NULL if table or column or attribute not found |
1732 | 1731 | */ |
1733 | - /* static */ function get_column_attribute($column,$table,$app=null,$attribute='comment') |
|
1732 | + /* static */ function get_column_attribute($column, $table, $app = null, $attribute = 'comment') |
|
1734 | 1733 | { |
1735 | - static $cached_columns=null,$cached_table=null; // some caching |
|
1734 | + static $cached_columns = null, $cached_table = null; // some caching |
|
1736 | 1735 | |
1737 | 1736 | if ($cached_table !== $table || is_null($cached_columns)) |
1738 | 1737 | { |
1739 | 1738 | $db = isset($this) ? $this : $GLOBALS['egw']->db; |
1740 | - $table_def = $db->get_table_definitions($app,$table); |
|
1739 | + $table_def = $db->get_table_definitions($app, $table); |
|
1741 | 1740 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
1742 | 1741 | } |
1743 | 1742 | if ($cached_columns === false) return null; |
@@ -1761,38 +1760,38 @@ discard block |
||
1761 | 1760 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1762 | 1761 | * @return ADORecordSet or false, if the query fails |
1763 | 1762 | */ |
1764 | - function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
1763 | + function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
1765 | 1764 | { |
1766 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1765 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app')</p>\n"; |
|
1767 | 1766 | |
1768 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1767 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1769 | 1768 | |
1770 | 1769 | $sql_append = ''; |
1771 | 1770 | $cmd = 'INSERT'; |
1772 | 1771 | if (is_array($where) && count($where)) |
1773 | 1772 | { |
1774 | - switch($this->Type) |
|
1773 | + switch ($this->Type) |
|
1775 | 1774 | { |
1776 | 1775 | case 'sapdb': case 'maxdb': |
1777 | 1776 | $sql_append = ' UPDATE DUPLICATES'; |
1778 | 1777 | break; |
1779 | 1778 | case 'mysql': |
1780 | 1779 | // use replace if primary keys are included |
1781 | - if (count(array_intersect(array_keys($where),(array)$table_def['pk'])) == count($table_def['pk'])) |
|
1780 | + if (count(array_intersect(array_keys($where), (array)$table_def['pk'])) == count($table_def['pk'])) |
|
1782 | 1781 | { |
1783 | 1782 | $cmd = 'REPLACE'; |
1784 | 1783 | break; |
1785 | 1784 | } |
1786 | 1785 | // fall through !!! |
1787 | 1786 | default: |
1788 | - if ($this->select($table,'count(*)',$where,$line,$file)->fetchColumn()) |
|
1787 | + if ($this->select($table, 'count(*)', $where, $line, $file)->fetchColumn()) |
|
1789 | 1788 | { |
1790 | - return !!$this->update($table,$data,$where,$line,$file,$app,$use_prepared_statement,$table_def); |
|
1789 | + return !!$this->update($table, $data, $where, $line, $file, $app, $use_prepared_statement, $table_def); |
|
1791 | 1790 | } |
1792 | 1791 | break; |
1793 | 1792 | } |
1794 | 1793 | // the checked values need to be inserted too, value in data has precedence, also cant insert sql strings (numerical id) |
1795 | - foreach($where as $column => $value) |
|
1794 | + foreach ($where as $column => $value) |
|
1796 | 1795 | { |
1797 | 1796 | if (!is_numeric($column) && !isset($data[$column]) && |
1798 | 1797 | // skip auto-id of 0 or NULL, as PostgreSQL does NOT create an auto-id, if they are given |
@@ -1812,24 +1811,24 @@ discard block |
||
1812 | 1811 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
1813 | 1812 | |
1814 | 1813 | $sql = "$cmd INTO $table "; |
1815 | - foreach($data as $k => $d) |
|
1814 | + foreach ($data as $k => $d) |
|
1816 | 1815 | { |
1817 | 1816 | if (!$k) |
1818 | 1817 | { |
1819 | - $sql .= $this->column_data_implode(',',$d,'VALUES',true,$table_def['fd']); |
|
1818 | + $sql .= $this->column_data_implode(',', $d, 'VALUES', true, $table_def['fd']); |
|
1820 | 1819 | } |
1821 | 1820 | else |
1822 | 1821 | { |
1823 | - $sql .= ",\n(".$this->column_data_implode(',',$d,false,true,$table_def['fd']).')'; |
|
1822 | + $sql .= ",\n(".$this->column_data_implode(',', $d, false, true, $table_def['fd']).')'; |
|
1824 | 1823 | } |
1825 | 1824 | } |
1826 | 1825 | $sql .= $sql_append; |
1827 | 1826 | } |
1828 | 1827 | elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
1829 | 1828 | { |
1830 | - $this->Link_ID->Param(false); // reset param-counter |
|
1829 | + $this->Link_ID->Param(false); // reset param-counter |
|
1831 | 1830 | $cols = array_keys($data); |
1832 | - foreach($cols as $k => $col) |
|
1831 | + foreach ($cols as $k => $col) |
|
1833 | 1832 | { |
1834 | 1833 | if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
1835 | 1834 | { |
@@ -1838,7 +1837,7 @@ discard block |
||
1838 | 1837 | } |
1839 | 1838 | $params[] = $this->Link_ID->Param($col); |
1840 | 1839 | } |
1841 | - $sql = "$cmd INTO $table (".implode(',',$cols).') VALUES ('.implode(',',$params).')'.$sql_append; |
|
1840 | + $sql = "$cmd INTO $table (".implode(',', $cols).') VALUES ('.implode(',', $params).')'.$sql_append; |
|
1842 | 1841 | // check if we already prepared that statement |
1843 | 1842 | if (!isset($this->prepared_sql[$sql])) |
1844 | 1843 | { |
@@ -1849,10 +1848,10 @@ discard block |
||
1849 | 1848 | } |
1850 | 1849 | else |
1851 | 1850 | { |
1852 | - $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
|
1851 | + $sql = "$cmd INTO $table ".$this->column_data_implode(',', $data, 'VALUES', true, $table_def['fd']).$sql_append; |
|
1853 | 1852 | } |
1854 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1855 | - return $this->query($sql,$line,$file,0,-1,$inputarr); |
|
1853 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1854 | + return $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
1856 | 1855 | } |
1857 | 1856 | |
1858 | 1857 | /** |
@@ -1870,10 +1869,10 @@ discard block |
||
1870 | 1869 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1871 | 1870 | * @return ADORecordSet or false, if the query fails |
1872 | 1871 | */ |
1873 | - function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
1872 | + function update($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
1874 | 1873 | { |
1875 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
1876 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1874 | + if ($this->Debug) echo "<p>db::update('$table',".print_r($data, true).','.print_r($where, true).",$line,$file,'$app')</p>\n"; |
|
1875 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1877 | 1876 | |
1878 | 1877 | $blobs2update = array(); |
1879 | 1878 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1884,7 +1883,7 @@ discard block |
||
1884 | 1883 | case 'maxdb': |
1885 | 1884 | if ($use_prepared_statement) break; |
1886 | 1885 | // check if data contains any LONG columns |
1887 | - foreach($data as $col => $val) |
|
1886 | + foreach ($data as $col => $val) |
|
1888 | 1887 | { |
1889 | 1888 | switch ($table_def['fd'][$col]['type']) |
1890 | 1889 | { |
@@ -1898,7 +1897,7 @@ discard block |
||
1898 | 1897 | } |
1899 | 1898 | break; |
1900 | 1899 | } |
1901 | - $where_str = $this->column_data_implode(' AND ',$where,True,true,$table_def['fd']); |
|
1900 | + $where_str = $this->column_data_implode(' AND ', $where, True, true, $table_def['fd']); |
|
1902 | 1901 | |
1903 | 1902 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
1904 | 1903 | { |
@@ -1909,13 +1908,13 @@ discard block |
||
1909 | 1908 | $inputarr = false; |
1910 | 1909 | if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
1911 | 1910 | { |
1912 | - $this->Link_ID->Param(false); // reset param-counter |
|
1913 | - foreach($data as $col => $val) |
|
1911 | + $this->Link_ID->Param(false); // reset param-counter |
|
1912 | + foreach ($data as $col => $val) |
|
1914 | 1913 | { |
1915 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
1914 | + if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
1916 | 1915 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
1917 | 1916 | } |
1918 | - $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
1917 | + $sql = "UPDATE $table SET ".implode(',', $params).' WHERE '.$where_str; |
|
1919 | 1918 | // check if we already prepared that statement |
1920 | 1919 | if (!isset($this->prepared_sql[$sql])) |
1921 | 1920 | { |
@@ -1927,19 +1926,19 @@ discard block |
||
1927 | 1926 | else |
1928 | 1927 | { |
1929 | 1928 | $sql = "UPDATE $table SET ". |
1930 | - $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
|
1929 | + $this->column_data_implode(',', $data, True, true, $table_def['fd']).' WHERE '.$where_str; |
|
1931 | 1930 | } |
1932 | - $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
|
1931 | + $ret = $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
1933 | 1932 | if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
1934 | 1933 | } |
1935 | 1934 | // if we have any blobs to update, we do so now |
1936 | 1935 | if (($ret || !count($data)) && count($blobs2update)) |
1937 | 1936 | { |
1938 | - foreach($blobs2update as $col => $val) |
|
1937 | + foreach ($blobs2update as $col => $val) |
|
1939 | 1938 | { |
1940 | - $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
1939 | + $ret = $this->Link_ID->UpdateBlob($table, $col, $val, $where_str, $table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
1941 | 1940 | if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
1942 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
1941 | + if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)", $line, $file); |
|
1943 | 1942 | } |
1944 | 1943 | } |
1945 | 1944 | return $ret; |
@@ -1958,18 +1957,18 @@ discard block |
||
1958 | 1957 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1959 | 1958 | * @return ADORecordSet or false, if the query fails |
1960 | 1959 | */ |
1961 | - function delete($table,$where,$line,$file,$app=False,$table_def=False) |
|
1960 | + function delete($table, $where, $line, $file, $app = False, $table_def = False) |
|
1962 | 1961 | { |
1963 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1962 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1964 | 1963 | |
1965 | 1964 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
1966 | 1965 | { |
1967 | 1966 | $table = self::$tablealiases[$table]; |
1968 | 1967 | } |
1969 | 1968 | $sql = "DELETE FROM $table WHERE ". |
1970 | - $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
1969 | + $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
1971 | 1970 | |
1972 | - return $this->query($sql,$line,$file); |
|
1971 | + return $this->query($sql, $line, $file); |
|
1973 | 1972 | } |
1974 | 1973 | |
1975 | 1974 | /** |
@@ -1992,12 +1991,12 @@ discard block |
||
1992 | 1991 | */ |
1993 | 1992 | function expression($table_def/*,$args, ...*/) |
1994 | 1993 | { |
1995 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
1994 | + if (!is_array($table_def)) $table_def = $this->get_table_definitions(true, $table_def); |
|
1996 | 1995 | $sql = ''; |
1997 | 1996 | $ignore_next = 0; |
1998 | - foreach(func_get_args() as $n => $arg) |
|
1997 | + foreach (func_get_args() as $n => $arg) |
|
1999 | 1998 | { |
2000 | - if ($n < 1) continue; // table-name |
|
1999 | + if ($n < 1) continue; // table-name |
|
2001 | 2000 | |
2002 | 2001 | if ($ignore_next) |
2003 | 2002 | { |
@@ -2006,7 +2005,7 @@ discard block |
||
2006 | 2005 | } |
2007 | 2006 | if (is_null($arg)) $arg = False; |
2008 | 2007 | |
2009 | - switch(gettype($arg)) |
|
2008 | + switch (gettype($arg)) |
|
2010 | 2009 | { |
2011 | 2010 | case 'string': |
2012 | 2011 | $sql .= $arg; |
@@ -2015,7 +2014,7 @@ discard block |
||
2015 | 2014 | $ignore_next += !$arg ? 2 : 0; |
2016 | 2015 | break; |
2017 | 2016 | case 'array': |
2018 | - $sql .= $this->column_data_implode(' AND ',$arg,True,False,$table_def['fd']); |
|
2017 | + $sql .= $this->column_data_implode(' AND ', $arg, True, False, $table_def['fd']); |
|
2019 | 2018 | break; |
2020 | 2019 | } |
2021 | 2020 | } |
@@ -2042,18 +2041,18 @@ discard block |
||
2042 | 2041 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
2043 | 2042 | * @return ADORecordSet or false, if the query fails |
2044 | 2043 | */ |
2045 | - function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
|
2044 | + function select($table, $cols, $where, $line, $file, $offset = False, $append = '', $app = False, $num_rows = 0, $join = '', $table_def = False, $fetchmode = self::FETCH_ASSOC) |
|
2046 | 2045 | { |
2047 | - if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
2046 | + if ($this->Debug) echo "<p>db::select('$table',".print_r($cols, True).",".print_r($where, True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
2048 | 2047 | |
2049 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2048 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
2050 | 2049 | if (is_array($cols)) |
2051 | 2050 | { |
2052 | - $cols = implode(',',$cols); |
|
2051 | + $cols = implode(',', $cols); |
|
2053 | 2052 | } |
2054 | 2053 | if (is_array($where)) |
2055 | 2054 | { |
2056 | - $where = $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
2055 | + $where = $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
2057 | 2056 | } |
2058 | 2057 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
2059 | 2058 | { |
@@ -2062,7 +2061,7 @@ discard block |
||
2062 | 2061 | $sql = "SELECT $cols FROM $table $join"; |
2063 | 2062 | |
2064 | 2063 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
2065 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2064 | + if ($where) $sql .= (strpos($join, "WHERE") !== false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2066 | 2065 | |
2067 | 2066 | if ($append) $sql .= ' '.$append; |
2068 | 2067 | |
@@ -2072,7 +2071,7 @@ discard block |
||
2072 | 2071 | { |
2073 | 2072 | return $sql; |
2074 | 2073 | } |
2075 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
2074 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
2076 | 2075 | } |
2077 | 2076 | |
2078 | 2077 | /** |
@@ -2090,34 +2089,34 @@ discard block |
||
2090 | 2089 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
2091 | 2090 | * @return ADORecordSet or false, if the query fails |
2092 | 2091 | */ |
2093 | - function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
|
2092 | + function union($selects, $line, $file, $order_by = '', $offset = false, $num_rows = 0, $fetchmode = self::FETCH_ASSOC) |
|
2094 | 2093 | { |
2095 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2094 | + if ($this->Debug) echo "<p>db::union(".print_r($selects, True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2096 | 2095 | |
2097 | 2096 | $union = array(); |
2098 | - foreach($selects as $select) |
|
2097 | + foreach ($selects as $select) |
|
2099 | 2098 | { |
2100 | - $union[] = call_user_func_array(array($this,'select'),array( |
|
2099 | + $union[] = call_user_func_array(array($this, 'select'), array( |
|
2101 | 2100 | $select['table'], |
2102 | 2101 | $select['cols'], |
2103 | 2102 | $select['where'], |
2104 | - false, // line |
|
2105 | - false, // file |
|
2106 | - false, // offset |
|
2103 | + false, // line |
|
2104 | + false, // file |
|
2105 | + false, // offset |
|
2107 | 2106 | $select['append'], |
2108 | 2107 | $select['app'], |
2109 | - 0, // num_rows, |
|
2108 | + 0, // num_rows, |
|
2110 | 2109 | $select['join'], |
2111 | 2110 | $select['table_def'], |
2112 | 2111 | )); |
2113 | 2112 | } |
2114 | - $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
|
2113 | + $sql = count($union) > 1 ? '('.implode(")\nUNION\n(", $union).')' : 'SELECT DISTINCT'.substr($union[0], 6); |
|
2115 | 2114 | |
2116 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2115 | + if ($order_by) $sql .= (!stristr($order_by, 'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2117 | 2116 | |
2118 | 2117 | if ($this->Debug) echo "<p>sql='$sql'</p>"; |
2119 | 2118 | |
2120 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
2119 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
2121 | 2120 | } |
2122 | 2121 | |
2123 | 2122 | /** |
@@ -2127,15 +2126,15 @@ discard block |
||
2127 | 2126 | * @param string|array $strip |
2128 | 2127 | * @return array |
2129 | 2128 | */ |
2130 | - static function strip_array_keys($arr,$strip) |
|
2129 | + static function strip_array_keys($arr, $strip) |
|
2131 | 2130 | { |
2132 | 2131 | $keys = array_keys($arr); |
2133 | 2132 | |
2134 | 2133 | return array_walk($keys, function(&$v, $k, $strip) |
2135 | 2134 | { |
2136 | - unset($k); // not used, but required by function signature |
|
2135 | + unset($k); // not used, but required by function signature |
|
2137 | 2136 | $v = str_replace($strip, '', $v); |
2138 | 2137 | }, $strip) ? |
2139 | - array_combine($keys,$arr) : $arr; |
|
2138 | + array_combine($keys, $arr) : $arr; |
|
2140 | 2139 | } |
2141 | 2140 | } |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * Restore data from a (compressed) csv file |
497 | 497 | * |
498 | 498 | * @param resource $f file opened with fopen for reading |
499 | - * @param int|string $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
|
499 | + * @param integer $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
|
500 | 500 | * @returns int number of rows read from csv file |
501 | 501 | */ |
502 | 502 | function db_restore($f, $insert_n_rows=10) |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | /** |
1045 | 1045 | * Backup all schemas in the form of a setup/tables_current.inc.php file |
1046 | 1046 | * |
1047 | - * @param resource|boolean $f |
|
1047 | + * @param resource $f |
|
1048 | 1048 | */ |
1049 | 1049 | function schema_backup($f=False) |
1050 | 1050 | { |
@@ -1089,6 +1089,7 @@ discard block |
||
1089 | 1089 | * Dump an array as php source |
1090 | 1090 | * |
1091 | 1091 | * copied from etemplate/inc/class.db_tools.inc.php |
1092 | + * @param integer $depth |
|
1092 | 1093 | */ |
1093 | 1094 | private static function write_array($arr,$depth,$parent='') |
1094 | 1095 | { |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | $zip = NULL; |
382 | 382 | $_f = NULL; |
383 | 383 | if($type == 'zip') |
384 | - { |
|
384 | + { |
|
385 | 385 | // has already been verified to be available in fopen_backup |
386 | 386 | $zip = new ZipArchive; |
387 | 387 | if(($zip->open($filename)) !== TRUE) |
@@ -719,9 +719,9 @@ discard block |
||
719 | 719 | while($file = $list[0]) |
720 | 720 | { |
721 | 721 | if(is_dir($file) && $file != '.' && $file != '..') |
722 | - self::remove_dir_content($dir.'/'.$file); |
|
722 | + self::remove_dir_content($dir.'/'.$file); |
|
723 | 723 | if(is_file($file) && $file != '.' && $file != '..') |
724 | - unlink($dir.'/'.$file); |
|
724 | + unlink($dir.'/'.$file); |
|
725 | 725 | array_shift($list); |
726 | 726 | } |
727 | 727 | //rmdir($dir); // dont remove own dir |
@@ -967,8 +967,8 @@ discard block |
||
967 | 967 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
968 | 968 | } |
969 | 969 | |
970 | - fclose($f); |
|
971 | - if (file_exists($name)) unlink($name); |
|
970 | + fclose($f); |
|
971 | + if (file_exists($name)) unlink($name); |
|
972 | 972 | return TRUE; |
973 | 973 | } |
974 | 974 | // save files .... |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | * @var array |
52 | 52 | */ |
53 | 53 | var $exclude_tables = array( |
54 | - 'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables |
|
55 | - 'phpgw_anglemail', // email's cache |
|
56 | - 'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache |
|
54 | + 'egw_sessions', 'egw_app_sessions', 'phpgw_sessions', 'phpgw_app_sessions', // eGW's session-tables |
|
55 | + 'phpgw_anglemail', // email's cache |
|
56 | + 'egw_felamimail_cache', 'egw_felamimail_folderstatus', 'phpgw_felamimail_cache', 'phpgw_felamimail_folderstatus', // felamimail's cache |
|
57 | 57 | 'egw_phpfreechat', // as of the fieldnames of the table a restore would fail within egroupware, and chatcontent is of no particular intrest |
58 | 58 | ); |
59 | 59 | /** |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @var boolean |
87 | 87 | */ |
88 | - var $backup_files = false ; |
|
88 | + var $backup_files = false; |
|
89 | 89 | /** |
90 | 90 | * Reference to schema_proc's Api\Db object |
91 | 91 | * |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | { |
101 | 101 | if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db)) |
102 | 102 | { |
103 | - $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
103 | + $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
104 | 104 | } |
105 | 105 | if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it |
106 | 106 | { |
@@ -118,21 +118,21 @@ discard block |
||
118 | 118 | { |
119 | 119 | if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table))) |
120 | 120 | { |
121 | - if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__)->fetchColumn())) |
|
121 | + if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'", __LINE__, __FILE__)->fetchColumn())) |
|
122 | 122 | { |
123 | 123 | error_log(__METHOD__."->"."No files Directory set/found"); |
124 | 124 | } |
125 | - if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__)->fetchColumn())) |
|
125 | + if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'", __LINE__, __FILE__)->fetchColumn())) |
|
126 | 126 | { |
127 | 127 | $this->backup_dir = $this->files_dir.'/db_backup'; |
128 | 128 | } |
129 | - $this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__)->fetchColumn(); |
|
130 | - $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table,'app_version',array('app_name'=>array('api','phpgwapi')), |
|
131 | - __LINE__,__FILE__,0,'ORDER BY app_name ASC')->fetchColumn(); |
|
129 | + $this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'", __LINE__, __FILE__)->fetchColumn(); |
|
130 | + $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table, 'app_version', array('app_name'=>array('api', 'phpgwapi')), |
|
131 | + __LINE__, __FILE__, 0, 'ORDER BY app_name ASC')->fetchColumn(); |
|
132 | 132 | // Backup settings |
133 | - $this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'",__LINE__,__FILE__)->fetchColumn(); |
|
133 | + $this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'", __LINE__, __FILE__)->fetchColumn(); |
|
134 | 134 | // backup files too |
135 | - $this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__)->fetchColumn(); |
|
135 | + $this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'", __LINE__, __FILE__)->fetchColumn(); |
|
136 | 136 | } |
137 | 137 | if (!$this->charset) $this->charset = 'utf-8'; |
138 | 138 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $this->backup_files = $GLOBALS['egw_info']['server']['backup_files']; |
148 | 148 | $this->charset = Api\Translation::charset(); |
149 | 149 | |
150 | - $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api'])?'api':'phpgwapi']['version']; |
|
150 | + $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api']) ? 'api' : 'phpgwapi']['version']; |
|
151 | 151 | } |
152 | 152 | // Set a default value if not set. |
153 | 153 | if (!isset($this->backup_mincount)) |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | { |
164 | 164 | mkdir($this->backup_dir); |
165 | 165 | } |
166 | - switch($this->db->Type) |
|
166 | + switch ($this->db->Type) |
|
167 | 167 | { |
168 | 168 | case 'sapdb': |
169 | 169 | case 'maxdb': |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @param $reading =false opening for reading ('rb') or writing ('wb') |
181 | 181 | * @return string/resource/zip error-msg of file-handle |
182 | 182 | */ |
183 | - function fopen_backup($name=false,$reading=false) |
|
183 | + function fopen_backup($name = false, $reading = false) |
|
184 | 184 | { |
185 | 185 | //echo "function fopen_backup($name,$reading)<br>"; // ! |
186 | 186 | if (!$name) |
@@ -189,27 +189,27 @@ discard block |
||
189 | 189 | if (!$this->backup_dir || !is_writable($this->backup_dir)) |
190 | 190 | { |
191 | 191 | //echo ' -> !$this->backup_dir || !is_writable($this->backup_dir)<br>'; // ! |
192 | - return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir); |
|
192 | + return lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir); |
|
193 | 193 | } |
194 | 194 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
195 | 195 | } |
196 | 196 | else // remove the extension, to use the correct wrapper based on the extension |
197 | 197 | { |
198 | 198 | //echo '-> else<br>'; // ! |
199 | - $name = preg_replace('/\.(bz2|gz)$/i','',$name); |
|
199 | + $name = preg_replace('/\.(bz2|gz)$/i', '', $name); |
|
200 | 200 | } |
201 | 201 | $mode = $reading ? 'rb' : 'wb'; |
202 | - list( , $type) = explode('.', basename($name)); |
|
203 | - if($type == 'zip' && $reading && $this->backup_files) |
|
202 | + list(, $type) = explode('.', basename($name)); |
|
203 | + if ($type == 'zip' && $reading && $this->backup_files) |
|
204 | 204 | { |
205 | 205 | //echo '-> $type == "zip" && $reading<br>'; // ! |
206 | - if(!class_exists('ZipArchive', false)) |
|
206 | + if (!class_exists('ZipArchive', false)) |
|
207 | 207 | { |
208 | 208 | $this->backup_files = false; |
209 | 209 | //echo ' -> (new ZipArchive) == NULL<br>'; // ! |
210 | 210 | return lang("Cant open %1, needs ZipArchive", $name)."<br>\n"; |
211 | 211 | } |
212 | - if(!($f = fopen($name, $mode))) |
|
212 | + if (!($f = fopen($name, $mode))) |
|
213 | 213 | { |
214 | 214 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
215 | 215 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | } |
218 | 218 | return $f; |
219 | 219 | } |
220 | - if(class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
220 | + if (class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
221 | 221 | { |
222 | 222 | //echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'<br>'; // ! |
223 | - if(!($f = fopen($name, $mode))) |
|
223 | + if (!($f = fopen($name, $mode))) |
|
224 | 224 | { |
225 | 225 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
226 | 226 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | } |
229 | 229 | return $f; |
230 | 230 | } |
231 | - if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
232 | - !($f = fopen("compress.zlib://$name.gz",$mode)) && |
|
233 | - !($f = fopen($name,$mode)) |
|
231 | + if (!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
232 | + !($f = fopen("compress.zlib://$name.gz", $mode)) && |
|
233 | + !($f = fopen($name, $mode)) |
|
234 | 234 | ) |
235 | 235 | { |
236 | 236 | //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>'; // ! |
@@ -257,13 +257,13 @@ discard block |
||
257 | 257 | /* Search the backup directory for matching files. */ |
258 | 258 | $handle = @opendir($this->backup_dir); |
259 | 259 | $files = array(); |
260 | - while($handle && ($file = readdir($handle))) |
|
260 | + while ($handle && ($file = readdir($handle))) |
|
261 | 261 | { |
262 | 262 | /* Filter for only the files with the regular name (un-renamed). |
263 | 263 | * Leave special backup files (renamed) in place. |
264 | 264 | * Note that this also excludes "." and "..". |
265 | 265 | */ |
266 | - if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/",$file)) |
|
266 | + if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/", $file)) |
|
267 | 267 | { |
268 | 268 | $files[filectime($this->backup_dir.'/'.$file)] = $file; |
269 | 269 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | /* Sort the files by ctime. */ |
274 | 274 | krsort($files); |
275 | 275 | $count = 0; |
276 | - foreach($files as $file) |
|
276 | + foreach ($files as $file) |
|
277 | 277 | { |
278 | 278 | if ($count >= $this->backup_mincount)// |
279 | 279 | { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | array_push($files_return, $file); |
284 | 284 | } |
285 | 285 | } |
286 | - $count ++; |
|
286 | + $count++; |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
@@ -293,13 +293,13 @@ discard block |
||
293 | 293 | * @param int $minCount Minimum number of backups to keep. |
294 | 294 | * @param boolean $backupFiles include files in backup or not, default dont change! |
295 | 295 | */ |
296 | - function saveConfig($minCount,$backupFiles=null) |
|
296 | + function saveConfig($minCount, $backupFiles = null) |
|
297 | 297 | { |
298 | - Api\Config::save_value('backup_mincount',$this->backup_mincount=(int)$minCount,'phpgwapi'); |
|
298 | + Api\Config::save_value('backup_mincount', $this->backup_mincount = (int)$minCount, 'phpgwapi'); |
|
299 | 299 | |
300 | 300 | if (!is_null($backupFiles)) |
301 | 301 | { |
302 | - Api\Config::save_value('backup_files',$this->backup_files=(boolean)$backupFiles,'phpgwapi'); |
|
302 | + Api\Config::save_value('backup_files', $this->backup_files = (boolean)$backupFiles, 'phpgwapi'); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | 'httpproxy_server_password', |
323 | 323 | 'system_charset', |
324 | 324 | 'usecookies', |
325 | - 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
325 | + 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
326 | 326 | ); |
327 | 327 | |
328 | 328 | /** |
@@ -336,20 +336,20 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @returns An empty string or an error message in case of failure. |
338 | 338 | */ |
339 | - function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10) |
|
339 | + function restore($f, $convert_to_system_charset = true, $filename = '', $protect_system_config = true, $insert_n_rows = 10) |
|
340 | 340 | { |
341 | 341 | @set_time_limit(0); |
342 | - ini_set('auto_detect_line_endings',true); |
|
342 | + ini_set('auto_detect_line_endings', true); |
|
343 | 343 | |
344 | - if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
344 | + if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
345 | 345 | |
346 | 346 | if ($protect_system_config) |
347 | 347 | { |
348 | 348 | $system_config = array(); |
349 | - foreach($this->db->select(self::TABLE,'*',array( |
|
349 | + foreach ($this->db->select(self::TABLE, '*', array( |
|
350 | 350 | 'config_app' => 'phpgwapi', |
351 | 351 | 'config_name' => self::$system_config, |
352 | - ),__LINE__,__FILE__) as $row) |
|
352 | + ), __LINE__, __FILE__) as $row) |
|
353 | 353 | { |
354 | 354 | $system_config[] = $row; |
355 | 355 | } |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | // as MySQL 5.7+ has sql_mode STRICT_(ALL|TRANS)_TABLES enabled by default, |
359 | 359 | // it will no longer restore '0000-00-00 00:00:00' in timestamps it created before, |
360 | 360 | // so switching strict-mode off temporary for the restore (we dont create these!) |
361 | - if (substr($this->db->Type,0,5) == 'mysql') |
|
361 | + if (substr($this->db->Type, 0, 5) == 'mysql') |
|
362 | 362 | { |
363 | 363 | $this->query("SET SESSION sql_mode=(SELECT REPLACE(REPLACE(@@sql_mode,'STRICT_ALL_TABLES',''),'STRICT_TRANS_TABLES',''))", __LINE__, __FILE__); |
364 | 364 | } |
@@ -369,17 +369,17 @@ discard block |
||
369 | 369 | |
370 | 370 | |
371 | 371 | // drop all existing tables |
372 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
372 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
373 | 373 | { |
374 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
375 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
374 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
375 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
376 | 376 | { |
377 | 377 | continue; |
378 | 378 | } |
379 | 379 | $this->schema_proc->DropTable($table); |
380 | 380 | } |
381 | 381 | // it could be an old backup |
382 | - list( , $type) = explode('.', basename($filename)); |
|
382 | + list(, $type) = explode('.', basename($filename)); |
|
383 | 383 | $dir = $this->files_dir; // $GLOBALS['egw_info']['server']['files_dir']; |
384 | 384 | // we may have to clean up old backup - left overs |
385 | 385 | if (is_dir($dir.'/database_backup')) |
@@ -392,20 +392,20 @@ discard block |
||
392 | 392 | $name = ""; |
393 | 393 | $zip = NULL; |
394 | 394 | $_f = NULL; |
395 | - if($type == 'zip') |
|
395 | + if ($type == 'zip') |
|
396 | 396 | { |
397 | 397 | // has already been verified to be available in fopen_backup |
398 | 398 | $zip = new ZipArchive; |
399 | - if(($zip->open($filename)) !== TRUE) |
|
399 | + if (($zip->open($filename)) !== TRUE) |
|
400 | 400 | { |
401 | 401 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
402 | 402 | } |
403 | - self::remove_dir_content($dir); // removes the files-dir |
|
403 | + self::remove_dir_content($dir); // removes the files-dir |
|
404 | 404 | $zip->extractTo($dir); |
405 | 405 | $_f = $f; |
406 | 406 | $list = $this->get_file_list($dir.'/database_backup/'); |
407 | 407 | $name = $dir.'/database_backup/'.basename($list[0]); |
408 | - if(!($f = fopen($name, 'rb'))) |
|
408 | + if (!($f = fopen($name, 'rb'))) |
|
409 | 409 | { |
410 | 410 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
411 | 411 | } |
@@ -422,46 +422,46 @@ discard block |
||
422 | 422 | { |
423 | 423 | $this->db->insert(Api\Config::TABLE, array( |
424 | 424 | 'config_value' => $this->schema_proc->system_charset, |
425 | - ),array( |
|
425 | + ), array( |
|
426 | 426 | 'config_app' => 'phpgwapi', |
427 | 427 | 'config_name' => 'system_charset', |
428 | - ),__LINE__,__FILE__); |
|
428 | + ), __LINE__, __FILE__); |
|
429 | 429 | } |
430 | 430 | // restore protected system config |
431 | 431 | if ($protect_system_config) |
432 | 432 | { |
433 | - foreach($system_config as $row) |
|
433 | + foreach ($system_config as $row) |
|
434 | 434 | { |
435 | - $this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array( |
|
435 | + $this->db->insert(self::TABLE, array('config_value'=>$row['config_value']), array( |
|
436 | 436 | 'config_name' => $row['config_name'], |
437 | 437 | 'config_app' => $row['config_app'], |
438 | - ),__LINE__,__FILE__); |
|
438 | + ), __LINE__, __FILE__); |
|
439 | 439 | } |
440 | 440 | // check and reset cookie configuration, if it does not match current enviroment |
441 | 441 | // if $_SERVER[HTTP_HOST] does not end with cookiedomain --> delete cookiedomain |
442 | - if (($cookiedomain = $this->db->select(self::TABLE,'config_value',array( |
|
442 | + if (($cookiedomain = $this->db->select(self::TABLE, 'config_value', array( |
|
443 | 443 | 'config_app' => 'phpgwapi', |
444 | 444 | 'config_name' => 'cookiedomain', |
445 | - ),__LINE__,__FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
446 | - (list($hostname) = explode(':',$_SERVER['HTTP_HOST'])) && |
|
447 | - substr($hostname,-strlen($cookiedomain) !== $cookiedomain)) |
|
445 | + ), __LINE__, __FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
446 | + (list($hostname) = explode(':', $_SERVER['HTTP_HOST'])) && |
|
447 | + substr($hostname, -strlen($cookiedomain) !== $cookiedomain)) |
|
448 | 448 | { |
449 | - $this->db->delete(self::TABLE,array( |
|
449 | + $this->db->delete(self::TABLE, array( |
|
450 | 450 | 'config_app' => 'phpgwapi', |
451 | 451 | 'config_name' => 'cookiedomain', |
452 | - ),__LINE__,__FILE__); |
|
452 | + ), __LINE__, __FILE__); |
|
453 | 453 | } |
454 | 454 | // if configured webserver_url does NOT start with cookiepath --> delete cookiepath |
455 | - if (($cookiepath = $this->db->select(self::TABLE,'config_value',array( |
|
455 | + if (($cookiepath = $this->db->select(self::TABLE, 'config_value', array( |
|
456 | 456 | 'config_app' => 'phpgwapi', |
457 | 457 | 'config_name' => 'cookiepath', |
458 | - ),__LINE__,__FILE__)->fetchColumn()) && |
|
459 | - substr(parse_url($system_config['webserver_url'], PHP_URL_PATH),0,strlen($cookiepath) !== $cookiepath)) |
|
458 | + ), __LINE__, __FILE__)->fetchColumn()) && |
|
459 | + substr(parse_url($system_config['webserver_url'], PHP_URL_PATH), 0, strlen($cookiepath) !== $cookiepath)) |
|
460 | 460 | { |
461 | - $this->db->delete(self::TABLE,array( |
|
461 | + $this->db->delete(self::TABLE, array( |
|
462 | 462 | 'config_app' => 'phpgwapi', |
463 | 463 | 'config_name' => 'cookiepath', |
464 | - ),__LINE__,__FILE__); |
|
464 | + ), __LINE__, __FILE__); |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | // restore original Halt_On_Error state (if changed) |
@@ -470,13 +470,13 @@ discard block |
||
470 | 470 | $this->db->Halt_On_Error = $backup_db_halt_on_error; |
471 | 471 | } |
472 | 472 | // zip? |
473 | - if($type == 'zip') |
|
473 | + if ($type == 'zip') |
|
474 | 474 | { |
475 | 475 | fclose($f); |
476 | 476 | unlink($name); |
477 | 477 | rmdir($dir.'/database_backup'); |
478 | 478 | } |
479 | - if (substr($this->db->Type,0,5) != 'mysql') |
|
479 | + if (substr($this->db->Type, 0, 5) != 'mysql') |
|
480 | 480 | { |
481 | 481 | if (!$this->db->transaction_commit()) |
482 | 482 | { |
@@ -511,26 +511,26 @@ discard block |
||
511 | 511 | * @param int|string $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
512 | 512 | * @returns int number of rows read from csv file |
513 | 513 | */ |
514 | - function db_restore($f, $insert_n_rows=10) |
|
514 | + function db_restore($f, $insert_n_rows = 10) |
|
515 | 515 | { |
516 | 516 | $convert_to_system_charset = true; |
517 | 517 | $table = null; |
518 | 518 | $n = 0; |
519 | 519 | $rows = array(); |
520 | - while(!feof($f)) |
|
520 | + while (!feof($f)) |
|
521 | 521 | { |
522 | 522 | $line = trim(fgets($f)); ++$n; |
523 | 523 | |
524 | 524 | if (empty($line)) continue; |
525 | 525 | |
526 | - if (substr($line,0,9) == 'version: ') |
|
526 | + if (substr($line, 0, 9) == 'version: ') |
|
527 | 527 | { |
528 | - $api_version = trim(substr($line,9)); |
|
528 | + $api_version = trim(substr($line, 9)); |
|
529 | 529 | continue; |
530 | 530 | } |
531 | - if (substr($line,0,9) == 'charset: ') |
|
531 | + if (substr($line, 0, 9) == 'charset: ') |
|
532 | 532 | { |
533 | - $charset = trim(substr($line,9)); |
|
533 | + $charset = trim(substr($line, 9)); |
|
534 | 534 | // needed if mbstring.func_overload > 0, else eg. substr does not work with non ascii chars |
535 | 535 | $ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset'; |
536 | 536 | @ini_set($ini_default_charset, $charset); |
@@ -538,29 +538,29 @@ discard block |
||
538 | 538 | // check if we really need to convert the charset, as it's not perfect and can do some damage |
539 | 539 | if ($convert_to_system_charset && !strcasecmp($this->schema_proc->system_charset, $charset)) |
540 | 540 | { |
541 | - $convert_to_system_charset = false; // no conversation necessary |
|
541 | + $convert_to_system_charset = false; // no conversation necessary |
|
542 | 542 | } |
543 | 543 | // set the DB's client encoding (for mysql only if api_version >= 1.0.1.019) |
544 | 544 | if ((!$convert_to_system_charset || $this->db->capabilities['client_encoding']) && |
545 | - (substr($this->db->Type,0,5) != 'mysql' || !is_object($GLOBALS['egw_setup']) || |
|
546 | - $api_version && !$GLOBALS['egw_setup']->alessthanb($api_version,'1.0.1.019'))) |
|
545 | + (substr($this->db->Type, 0, 5) != 'mysql' || !is_object($GLOBALS['egw_setup']) || |
|
546 | + $api_version && !$GLOBALS['egw_setup']->alessthanb($api_version, '1.0.1.019'))) |
|
547 | 547 | { |
548 | 548 | $this->db->Link_ID->SetCharSet($charset); |
549 | 549 | if (!$convert_to_system_charset) |
550 | 550 | { |
551 | - $this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables |
|
551 | + $this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | continue; |
555 | 555 | } |
556 | - if (substr($line,0,8) == 'schema: ') |
|
556 | + if (substr($line, 0, 8) == 'schema: ') |
|
557 | 557 | { |
558 | 558 | // create the tables in the backup set |
559 | - $this->schemas = json_php_unserialize(trim(substr($line,8))); |
|
560 | - foreach($this->schemas as $table_name => $schema) |
|
559 | + $this->schemas = json_php_unserialize(trim(substr($line, 8))); |
|
560 | + foreach ($this->schemas as $table_name => $schema) |
|
561 | 561 | { |
562 | 562 | // if column is longtext in current schema, convert text to longtext, in case user already updated column |
563 | - foreach($schema['fd'] as $col => &$def) |
|
563 | + foreach ($schema['fd'] as $col => &$def) |
|
564 | 564 | { |
565 | 565 | if ($def['type'] == 'text' && $this->db->get_column_attribute($col, $table_name, true, 'type') == 'longtext') |
566 | 566 | { |
@@ -572,27 +572,27 @@ discard block |
||
572 | 572 | } |
573 | 573 | continue; |
574 | 574 | } |
575 | - if (substr($line,0,7) == 'table: ') |
|
575 | + if (substr($line, 0, 7) == 'table: ') |
|
576 | 576 | { |
577 | 577 | if ($rows) // flush pending rows of last table |
578 | 578 | { |
579 | 579 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
580 | 580 | } |
581 | 581 | $rows = array(); |
582 | - $table = substr($line,7); |
|
582 | + $table = substr($line, 7); |
|
583 | 583 | if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
584 | 584 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
585 | 585 | |
586 | - $cols = self::csv_split($line=fgets($f)); ++$n; |
|
586 | + $cols = self::csv_split($line = fgets($f)); ++$n; |
|
587 | 587 | $blobs = array(); |
588 | - foreach($this->schemas[$table]['fd'] as $col => $data) |
|
588 | + foreach ($this->schemas[$table]['fd'] as $col => $data) |
|
589 | 589 | { |
590 | 590 | if ($data['type'] == 'blob') $blobs[] = $col; |
591 | 591 | } |
592 | 592 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
593 | 593 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
594 | 594 | $bools = array(); |
595 | - foreach($this->schemas[$table]['fd'] as $col => $def) |
|
595 | + foreach ($this->schemas[$table]['fd'] as $col => $def) |
|
596 | 596 | { |
597 | 597 | if ($def['type'] === 'bool') $bools[] = $col; |
598 | 598 | } |
@@ -616,15 +616,15 @@ discard block |
||
616 | 616 | $import = true; |
617 | 617 | $data = self::csv_split($line, $cols, $blobs, $bools); |
618 | 618 | |
619 | - if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
|
619 | + if ($table == 'egw_async' && in_array('##last-check-run##', $data)) |
|
620 | 620 | { |
621 | 621 | //echo '<p>'.lang("Line %1: '%2'<br><b>csv data does contain ##last-check-run## of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n"; |
622 | 622 | //echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
623 | 623 | $import = false; |
624 | 624 | } |
625 | - if (in_array($table,$this->exclude_tables)) |
|
625 | + if (in_array($table, $this->exclude_tables)) |
|
626 | 626 | { |
627 | - echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n"; |
|
627 | + echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n"; |
|
628 | 628 | $import = false; // dont restore data of excluded tables |
629 | 629 | } |
630 | 630 | if ($import) |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | { |
634 | 634 | if ($convert_to_system_charset && !$this->db->capabilities['client_encoding']) |
635 | 635 | { |
636 | - $data = Api\Translation::convert($data,$charset); |
|
636 | + $data = Api\Translation::convert($data, $charset); |
|
637 | 637 | } |
638 | 638 | if ($insert_n_rows > 1) |
639 | 639 | { |
@@ -645,27 +645,27 @@ discard block |
||
645 | 645 | } |
646 | 646 | } |
647 | 647 | // update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence) |
648 | - elseif(!is_numeric($insert_n_rows)) |
|
648 | + elseif (!is_numeric($insert_n_rows)) |
|
649 | 649 | { |
650 | 650 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
651 | 651 | unset($data[$insert_n_rows]); |
652 | 652 | if ($auto_id) unset($data[$auto_id]); |
653 | - $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
653 | + $this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
654 | 654 | } |
655 | 655 | else |
656 | 656 | { |
657 | 657 | try { |
658 | - $this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
658 | + $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
659 | 659 | } |
660 | - catch(Exception\InvalidSql $e) { |
|
660 | + catch (Exception\InvalidSql $e) { |
|
661 | 661 | echo "<p>".$e->getMessage()."</p>\n"; |
662 | 662 | } |
663 | 663 | } |
664 | 664 | } |
665 | 665 | else |
666 | 666 | { |
667 | - echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n"; |
|
668 | - echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
|
667 | + echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>", $n, $line, $table)."</p>\n"; |
|
668 | + echo 'data=<pre>'.print_r($data, true)."</pre>\n"; |
|
669 | 669 | } |
670 | 670 | } |
671 | 671 | } |
@@ -675,14 +675,14 @@ discard block |
||
675 | 675 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
676 | 676 | } |
677 | 677 | // updated the sequences, if the DB uses them |
678 | - foreach($this->schemas as $table => $schema) |
|
678 | + foreach ($this->schemas as $table => $schema) |
|
679 | 679 | { |
680 | - foreach($schema['fd'] as $column => $definition) |
|
680 | + foreach ($schema['fd'] as $column => $definition) |
|
681 | 681 | { |
682 | 682 | if ($definition['type'] == 'auto') |
683 | 683 | { |
684 | - $this->schema_proc->UpdateSequence($table,$column); |
|
685 | - break; // max. one per table |
|
684 | + $this->schema_proc->UpdateSequence($table, $column); |
|
685 | + break; // max. one per table |
|
686 | 686 | } |
687 | 687 | } |
688 | 688 | } |
@@ -705,15 +705,15 @@ discard block |
||
705 | 705 | try { |
706 | 706 | $this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema); |
707 | 707 | } |
708 | - catch(Exception\InvalidSql $e) |
|
708 | + catch (Exception\InvalidSql $e) |
|
709 | 709 | { |
710 | 710 | // try inserting them one by one, ignoring doublicates |
711 | - foreach($rows as $data) |
|
711 | + foreach ($rows as $data) |
|
712 | 712 | { |
713 | 713 | try { |
714 | 714 | $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema); |
715 | 715 | } |
716 | - catch(Exception\InvalidSql $e) { |
|
716 | + catch (Exception\InvalidSql $e) { |
|
717 | 717 | echo "<p>".$e->getMessage()."</p>\n"; |
718 | 718 | } |
719 | 719 | } |
@@ -728,11 +728,11 @@ discard block |
||
728 | 728 | private static function remove_dir_content($dir) |
729 | 729 | { |
730 | 730 | $list = scandir($dir); |
731 | - while($file = $list[0]) |
|
731 | + while ($file = $list[0]) |
|
732 | 732 | { |
733 | - if(is_dir($file) && $file != '.' && $file != '..') |
|
733 | + if (is_dir($file) && $file != '.' && $file != '..') |
|
734 | 734 | self::remove_dir_content($dir.'/'.$file); |
735 | - if(is_file($file) && $file != '.' && $file != '..') |
|
735 | + if (is_file($file) && $file != '.' && $file != '..') |
|
736 | 736 | unlink($dir.'/'.$file); |
737 | 737 | array_shift($list); |
738 | 738 | } |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups |
758 | 758 | * @return array |
759 | 759 | */ |
760 | - public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
|
760 | + public static function csv_split($line, $keys = null, $blobs = array(), $bools = array()) |
|
761 | 761 | { |
762 | 762 | if (function_exists('str_getcsv')) // php5.3+ |
763 | 763 | { |
@@ -770,9 +770,9 @@ discard block |
||
770 | 770 | '\\n' => "\n", |
771 | 771 | '\\r' => "\r")), ',', '"', '\0'); |
772 | 772 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
773 | - foreach($fields as &$field) |
|
773 | + foreach ($fields as &$field) |
|
774 | 774 | { |
775 | - switch($field) |
|
775 | + switch ($field) |
|
776 | 776 | { |
777 | 777 | case self::NULL_TOKEN: |
778 | 778 | $field = 'NULL'; |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | { |
790 | 790 | $fields = array_combine($keys, $fields); |
791 | 791 | // base64-decode blob columns, if they are base64 encoded |
792 | - foreach($blobs as $key) |
|
792 | + foreach ($blobs as $key) |
|
793 | 793 | { |
794 | 794 | if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false) |
795 | 795 | { |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | } |
798 | 798 | } |
799 | 799 | // decode bool columns, they might be 't'/'f' for old PostgreSQL backups |
800 | - foreach($bools as $key) |
|
800 | + foreach ($bools as $key) |
|
801 | 801 | { |
802 | 802 | $fields[$key] = Api\Db::from_bool($fields[$key]); |
803 | 803 | } |
@@ -805,11 +805,11 @@ discard block |
||
805 | 805 | return $fields; |
806 | 806 | } |
807 | 807 | // pre 5.3 implementation |
808 | - $fields = explode(',',trim($line)); |
|
808 | + $fields = explode(',', trim($line)); |
|
809 | 809 | |
810 | 810 | $str_pending = False; |
811 | 811 | $n = 0; |
812 | - foreach($fields as $field) |
|
812 | + foreach ($fields as $field) |
|
813 | 813 | { |
814 | 814 | if ($str_pending !== False) |
815 | 815 | { |
@@ -820,12 +820,12 @@ discard block |
||
820 | 820 | |
821 | 821 | if ($field[0] == '"') |
822 | 822 | { |
823 | - if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field)) |
|
823 | + if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field)) |
|
824 | 824 | { |
825 | 825 | $str_pending = $field; |
826 | 826 | continue; |
827 | 827 | } |
828 | - $arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1))); |
|
828 | + $arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1))); |
|
829 | 829 | } |
830 | 830 | elseif ($keys && strlen($field) > 26) |
831 | 831 | { |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | /** |
848 | 848 | * escape data for csv |
849 | 849 | */ |
850 | - public static function escape_data(&$data,$col,$defs) |
|
850 | + public static function escape_data(&$data, $col, $defs) |
|
851 | 851 | { |
852 | 852 | if (is_null($data)) |
853 | 853 | { |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | } |
856 | 856 | else |
857 | 857 | { |
858 | - switch($defs[$col]['type']) |
|
858 | + switch ($defs[$col]['type']) |
|
859 | 859 | { |
860 | 860 | case 'int': |
861 | 861 | case 'auto': |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | $data = (int)Api\Db::from_bool($data); |
871 | 871 | break; |
872 | 872 | default: |
873 | - $data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"'; |
|
873 | + $data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"'; |
|
874 | 874 | break; |
875 | 875 | } |
876 | 876 | } |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | * default of null limits memory usage if there is no primary key, by locking table and use ROW_CHUCK |
890 | 890 | * @todo use https://github.com/maennchen/ZipStream-PHP to not assemble all files in memmory |
891 | 891 | */ |
892 | - function backup($f, $lock_table=null) |
|
892 | + function backup($f, $lock_table = null) |
|
893 | 893 | { |
894 | 894 | //echo "function backup($f)<br>"; // ! |
895 | 895 | @set_time_limit(0); |
@@ -905,15 +905,15 @@ discard block |
||
905 | 905 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
906 | 906 | $filename = $name.'.zip'; |
907 | 907 | $zippresent = false; |
908 | - if(class_exists('ZipArchive') && $this->backup_files) |
|
908 | + if (class_exists('ZipArchive') && $this->backup_files) |
|
909 | 909 | { |
910 | 910 | $zip = new ZipArchive; |
911 | - if(is_object($zip)) |
|
911 | + if (is_object($zip)) |
|
912 | 912 | { |
913 | 913 | $zippresent = true; |
914 | 914 | //echo '-> is_object($zip); '.$filename.'<br>'; // ! |
915 | 915 | $res = $zip->open($filename, ZipArchive::CREATE); |
916 | - if($res !== TRUE) |
|
916 | + if ($res !== TRUE) |
|
917 | 917 | { |
918 | 918 | //echo ' -> !$res<br>'; // ! |
919 | 919 | return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n"; |
@@ -921,19 +921,19 @@ discard block |
||
921 | 921 | $file_list = $this->get_file_list($dir); |
922 | 922 | } |
923 | 923 | } |
924 | - fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
924 | + fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
925 | 925 | |
926 | - fwrite($f,"version: $this->api_version\n\n"); |
|
926 | + fwrite($f, "version: $this->api_version\n\n"); |
|
927 | 927 | |
928 | - fwrite($f,"charset: $this->charset\n\n"); |
|
928 | + fwrite($f, "charset: $this->charset\n\n"); |
|
929 | 929 | |
930 | - $this->schema_backup($f); // add the schema in a human readable form too |
|
930 | + $this->schema_backup($f); // add the schema in a human readable form too |
|
931 | 931 | |
932 | - fwrite($f,"\nschema: ".json_encode($this->schemas)."\n"); |
|
932 | + fwrite($f, "\nschema: ".json_encode($this->schemas)."\n"); |
|
933 | 933 | |
934 | - foreach($this->schemas as $table => $schema) |
|
934 | + foreach ($this->schemas as $table => $schema) |
|
935 | 935 | { |
936 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
936 | + if (in_array($table, $this->exclude_tables)) continue; // dont backup |
|
937 | 937 | |
938 | 938 | // do we have a primary key? |
939 | 939 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | do { |
950 | 950 | $num_rows = 0; |
951 | 951 | // querying only chunks for 10000 rows, to not run into memory limit on huge tables |
952 | - foreach($this->db->select($table, '*', |
|
952 | + foreach ($this->db->select($table, '*', |
|
953 | 953 | // limit by maximum primary key already received |
954 | 954 | empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']), |
955 | 955 | __LINE__, __FILE__, |
@@ -960,19 +960,19 @@ discard block |
||
960 | 960 | false, self::ROW_CHUNK) as $row) |
961 | 961 | { |
962 | 962 | if (!empty($pk)) $max = $row[$pk]; |
963 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
963 | + if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n"); |
|
964 | 964 | |
965 | 965 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
966 | - fwrite($f,implode(',',$row)."\n"); |
|
966 | + fwrite($f, implode(',', $row)."\n"); |
|
967 | 967 | ++$total; |
968 | 968 | ++$num_rows; |
969 | 969 | } |
970 | 970 | } |
971 | - while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
971 | + while ((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
972 | 972 | |
973 | 973 | if (!$pk) $this->db->Link_ID->RollbackLock($table); |
974 | 974 | } |
975 | - if(!$zippresent) // save without files |
|
975 | + if (!$zippresent) // save without files |
|
976 | 976 | { |
977 | 977 | if ($this->backup_files) |
978 | 978 | { |
@@ -987,16 +987,16 @@ discard block |
||
987 | 987 | //echo $name.'<br>'; |
988 | 988 | $zip->addFile($name, 'database_backup/'.basename($name)); |
989 | 989 | $count = 1; |
990 | - foreach($file_list as $file) |
|
990 | + foreach ($file_list as $file) |
|
991 | 991 | { |
992 | 992 | //echo substr($file,strlen($dir)+1).'<br>'; |
993 | 993 | //echo $file.'<br>'; |
994 | - $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
|
995 | - if(($count++) == 100) { // the file descriptor limit |
|
994 | + $zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file); |
|
995 | + if (($count++) == 100) { // the file descriptor limit |
|
996 | 996 | $zip->close(); |
997 | - if(($zip = new ZipArchive())) { |
|
997 | + if (($zip = new ZipArchive())) { |
|
998 | 998 | $zip->open($filename); |
999 | - $count =0; |
|
999 | + $count = 0; |
|
1000 | 1000 | } |
1001 | 1001 | } |
1002 | 1002 | } |
@@ -1019,17 +1019,17 @@ discard block |
||
1019 | 1019 | { |
1020 | 1020 | //chdir($f); |
1021 | 1021 | //echo "Processing $f <br>"; |
1022 | - if ($path_name =='') $path_name = $f; |
|
1022 | + if ($path_name == '') $path_name = $f; |
|
1023 | 1023 | $tlist = scandir($f); |
1024 | 1024 | $list = array(); |
1025 | 1025 | $i = $cnt; |
1026 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1026 | + while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1027 | 1027 | { |
1028 | - if($file == '.' || $file == '..') |
|
1028 | + if ($file == '.' || $file == '..') |
|
1029 | 1029 | { |
1030 | 1030 | array_shift($tlist); |
1031 | 1031 | } |
1032 | - elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
|
1032 | + elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false) |
|
1033 | 1033 | { |
1034 | 1034 | // skip activesync debug.txt on backupFiles |
1035 | 1035 | //error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file); |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | } |
1038 | 1038 | else |
1039 | 1039 | { |
1040 | - if(is_dir($f.'/'.$file)) |
|
1040 | + if (is_dir($f.'/'.$file)) |
|
1041 | 1041 | { |
1042 | 1042 | $nlist = $this->get_file_list($f.'/'.$file, $i); |
1043 | 1043 | $list += $nlist; |
@@ -1058,12 +1058,12 @@ discard block |
||
1058 | 1058 | * |
1059 | 1059 | * @param resource|boolean $f |
1060 | 1060 | */ |
1061 | - function schema_backup($f=False) |
|
1061 | + function schema_backup($f = False) |
|
1062 | 1062 | { |
1063 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
1063 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
1064 | 1064 | { |
1065 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
1066 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
1065 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
1066 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
1067 | 1067 | { |
1068 | 1068 | continue; |
1069 | 1069 | } |
@@ -1082,17 +1082,17 @@ discard block |
||
1082 | 1082 | } |
1083 | 1083 | } |
1084 | 1084 | $def = "\t\$phpgw_baseline = "; |
1085 | - $def .= self::write_array($this->schemas,1); |
|
1085 | + $def .= self::write_array($this->schemas, 1); |
|
1086 | 1086 | $def .= ";\n"; |
1087 | 1087 | |
1088 | 1088 | if ($f) |
1089 | 1089 | { |
1090 | - fwrite($f,$def); |
|
1090 | + fwrite($f, $def); |
|
1091 | 1091 | } |
1092 | 1092 | else |
1093 | 1093 | { |
1094 | 1094 | $def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def; |
1095 | - Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def)); |
|
1095 | + Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def)); |
|
1096 | 1096 | echo $def; |
1097 | 1097 | } |
1098 | 1098 | } |
@@ -1102,9 +1102,9 @@ discard block |
||
1102 | 1102 | * |
1103 | 1103 | * copied from etemplate/inc/class.db_tools.inc.php |
1104 | 1104 | */ |
1105 | - private static function write_array($arr,$depth,$parent='') |
|
1105 | + private static function write_array($arr, $depth, $parent = '') |
|
1106 | 1106 | { |
1107 | - if (in_array($parent,array('pk','fk','ix','uc'))) |
|
1107 | + if (in_array($parent, array('pk', 'fk', 'ix', 'uc'))) |
|
1108 | 1108 | { |
1109 | 1109 | $depth = 0; |
1110 | 1110 | } |
@@ -1120,7 +1120,7 @@ discard block |
||
1120 | 1120 | $def = "array($tabs".($tabs ? "\t" : ''); |
1121 | 1121 | |
1122 | 1122 | $n = 0; |
1123 | - foreach($arr as $key => $val) |
|
1123 | + foreach ($arr as $key => $val) |
|
1124 | 1124 | { |
1125 | 1125 | if (!is_int($key)) |
1126 | 1126 | { |
@@ -1128,7 +1128,7 @@ discard block |
||
1128 | 1128 | } |
1129 | 1129 | if (is_array($val)) |
1130 | 1130 | { |
1131 | - $def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key); |
|
1131 | + $def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key); |
|
1132 | 1132 | } |
1133 | 1133 | else |
1134 | 1134 | { |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | $def .= "'$val'"; |
1142 | 1142 | } |
1143 | 1143 | } |
1144 | - if ($n < count($arr)-1) |
|
1144 | + if ($n < count($arr) - 1) |
|
1145 | 1145 | { |
1146 | 1146 | $def .= ",$tabs".($tabs ? "\t" : ''); |
1147 | 1147 | } |
@@ -102,25 +102,34 @@ discard block |
||
102 | 102 | { |
103 | 103 | $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
104 | 104 | } |
105 | - if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it |
|
105 | + if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) |
|
106 | + { |
|
107 | + // schema_proc already instanciated, use it |
|
106 | 108 | { |
107 | 109 | $this->schema_proc = $GLOBALS['egw_setup']->oProc; |
108 | 110 | } |
111 | + } |
|
109 | 112 | else |
110 | 113 | { |
111 | 114 | $this->schema_proc = new Api\Db\Schema(); |
112 | 115 | } |
113 | 116 | |
114 | 117 | $this->db = $this->schema_proc->m_odb; |
115 | - if (!$this->db->Link_ID) $this->db->connect(); |
|
118 | + if (!$this->db->Link_ID) |
|
119 | + { |
|
120 | + $this->db->connect(); |
|
121 | + } |
|
116 | 122 | $this->adodb = $this->db->Link_ID; |
117 | - if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup'])) // called from setup |
|
123 | + if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup'])) |
|
124 | + { |
|
125 | + // called from setup |
|
118 | 126 | { |
119 | 127 | if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table))) |
120 | 128 | { |
121 | 129 | if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__)->fetchColumn())) |
122 | 130 | { |
123 | 131 | error_log(__METHOD__."->"."No files Directory set/found"); |
132 | + } |
|
124 | 133 | } |
125 | 134 | if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__)->fetchColumn())) |
126 | 135 | { |
@@ -134,7 +143,10 @@ discard block |
||
134 | 143 | // backup files too |
135 | 144 | $this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__)->fetchColumn(); |
136 | 145 | } |
137 | - if (!$this->charset) $this->charset = 'utf-8'; |
|
146 | + if (!$this->charset) |
|
147 | + { |
|
148 | + $this->charset = 'utf-8'; |
|
149 | + } |
|
138 | 150 | } |
139 | 151 | else // called from eGW |
140 | 152 | { |
@@ -231,8 +243,7 @@ discard block |
||
231 | 243 | if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
232 | 244 | !($f = fopen("compress.zlib://$name.gz",$mode)) && |
233 | 245 | !($f = fopen($name,$mode)) |
234 | - ) |
|
235 | - { |
|
246 | + ) { |
|
236 | 247 | //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>'; // ! |
237 | 248 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
238 | 249 | return lang("Cant open '%1' for %2", $name, $lang_mode)."<br>"; |
@@ -268,16 +279,22 @@ discard block |
||
268 | 279 | $files[filectime($this->backup_dir.'/'.$file)] = $file; |
269 | 280 | } |
270 | 281 | } |
271 | - if ($handle) closedir($handle); |
|
282 | + if ($handle) |
|
283 | + { |
|
284 | + closedir($handle); |
|
285 | + } |
|
272 | 286 | |
273 | 287 | /* Sort the files by ctime. */ |
274 | 288 | krsort($files); |
275 | 289 | $count = 0; |
276 | 290 | foreach($files as $file) |
277 | 291 | { |
278 | - if ($count >= $this->backup_mincount)// |
|
292 | + if ($count >= $this->backup_mincount) |
|
293 | + { |
|
294 | + // |
|
279 | 295 | { |
280 | 296 | $ret = unlink($this->backup_dir.'/'.$file); |
297 | + } |
|
281 | 298 | if (($ret) && (is_array($files_return))) |
282 | 299 | { |
283 | 300 | array_push($files_return, $file); |
@@ -341,7 +358,11 @@ discard block |
||
341 | 358 | @set_time_limit(0); |
342 | 359 | ini_set('auto_detect_line_endings',true); |
343 | 360 | |
344 | - if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
361 | + if (true) |
|
362 | + { |
|
363 | + $convert_to_system_charset = true; |
|
364 | + } |
|
365 | + // enforce now utf-8 as system charset restores of old backups |
|
345 | 366 | |
346 | 367 | if ($protect_system_config) |
347 | 368 | { |
@@ -393,7 +414,7 @@ discard block |
||
393 | 414 | $zip = NULL; |
394 | 415 | $_f = NULL; |
395 | 416 | if($type == 'zip') |
396 | - { |
|
417 | + { |
|
397 | 418 | // has already been verified to be available in fopen_backup |
398 | 419 | $zip = new ZipArchive; |
399 | 420 | if(($zip->open($filename)) !== TRUE) |
@@ -412,7 +433,9 @@ discard block |
||
412 | 433 | } |
413 | 434 | $this->db_restore($f, $insert_n_rows); |
414 | 435 | |
415 | - if ($convert_to_system_charset) // store the changed charset |
|
436 | + if ($convert_to_system_charset) |
|
437 | + { |
|
438 | + // store the changed charset |
|
416 | 439 | { |
417 | 440 | $this->db->insert(Api\Config::TABLE, array( |
418 | 441 | 'config_value' => $this->schema_proc->system_charset, |
@@ -421,6 +444,7 @@ discard block |
||
421 | 444 | 'config_name' => 'system_charset', |
422 | 445 | ),__LINE__,__FILE__); |
423 | 446 | } |
447 | + } |
|
424 | 448 | // restore protected system config |
425 | 449 | if ($protect_system_config) |
426 | 450 | { |
@@ -510,7 +534,10 @@ discard block |
||
510 | 534 | { |
511 | 535 | $line = trim(fgets($f)); ++$n; |
512 | 536 | |
513 | - if (empty($line)) continue; |
|
537 | + if (empty($line)) |
|
538 | + { |
|
539 | + continue; |
|
540 | + } |
|
514 | 541 | |
515 | 542 | if (substr($line,0,9) == 'version: ') |
516 | 543 | { |
@@ -563,31 +590,49 @@ discard block |
||
563 | 590 | } |
564 | 591 | if (substr($line,0,7) == 'table: ') |
565 | 592 | { |
566 | - if ($rows) // flush pending rows of last table |
|
593 | + if ($rows) |
|
594 | + { |
|
595 | + // flush pending rows of last table |
|
567 | 596 | { |
568 | 597 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
569 | 598 | } |
599 | + } |
|
570 | 600 | $rows = array(); |
571 | 601 | $table = substr($line,7); |
572 | - if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
602 | + if (!isset($this->schemas[$table])) |
|
603 | + { |
|
604 | + $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
605 | + } |
|
573 | 606 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
574 | 607 | |
575 | 608 | $cols = self::csv_split($line=fgets($f)); ++$n; |
576 | 609 | $blobs = array(); |
577 | 610 | foreach($this->schemas[$table]['fd'] as $col => $data) |
578 | 611 | { |
579 | - if ($data['type'] == 'blob') $blobs[] = $col; |
|
612 | + if ($data['type'] == 'blob') |
|
613 | + { |
|
614 | + $blobs[] = $col; |
|
615 | + } |
|
580 | 616 | } |
581 | 617 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
582 | 618 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
583 | 619 | $bools = array(); |
584 | 620 | foreach($this->schemas[$table]['fd'] as $col => $def) |
585 | 621 | { |
586 | - if ($def['type'] === 'bool') $bools[] = $col; |
|
622 | + if ($def['type'] === 'bool') |
|
623 | + { |
|
624 | + $bools[] = $col; |
|
625 | + } |
|
626 | + } |
|
627 | + if ($table == 'egw_cal_dates') |
|
628 | + { |
|
629 | + error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd'])); |
|
587 | 630 | } |
588 | - if ($table == 'egw_cal_dates') error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd'])); |
|
589 | 631 | |
590 | - if (feof($f)) break; |
|
632 | + if (feof($f)) |
|
633 | + { |
|
634 | + break; |
|
635 | + } |
|
591 | 636 | continue; |
592 | 637 | } |
593 | 638 | if ($convert_to_system_charset && !$this->db->capabilities['client_encoding']) |
@@ -600,9 +645,12 @@ discard block |
||
600 | 645 | } |
601 | 646 | } |
602 | 647 | } |
603 | - if ($table) // do we already reached the data part |
|
648 | + if ($table) |
|
649 | + { |
|
650 | + // do we already reached the data part |
|
604 | 651 | { |
605 | 652 | $import = true; |
653 | + } |
|
606 | 654 | $data = self::csv_split($line, $cols, $blobs, $bools); |
607 | 655 | |
608 | 656 | if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
@@ -638,7 +686,10 @@ discard block |
||
638 | 686 | { |
639 | 687 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
640 | 688 | unset($data[$insert_n_rows]); |
641 | - if ($auto_id) unset($data[$auto_id]); |
|
689 | + if ($auto_id) |
|
690 | + { |
|
691 | + unset($data[$auto_id]); |
|
692 | + } |
|
642 | 693 | $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
643 | 694 | } |
644 | 695 | else |
@@ -659,10 +710,13 @@ discard block |
||
659 | 710 | } |
660 | 711 | } |
661 | 712 | } |
662 | - if ($rows) // flush pending rows |
|
713 | + if ($rows) |
|
714 | + { |
|
715 | + // flush pending rows |
|
663 | 716 | { |
664 | 717 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
665 | 718 | } |
719 | + } |
|
666 | 720 | // updated the sequences, if the DB uses them |
667 | 721 | foreach($this->schemas as $table => $schema) |
668 | 722 | { |
@@ -720,9 +774,13 @@ discard block |
||
720 | 774 | while($file = $list[0]) |
721 | 775 | { |
722 | 776 | if(is_dir($file) && $file != '.' && $file != '..') |
723 | - self::remove_dir_content($dir.'/'.$file); |
|
777 | + { |
|
778 | + self::remove_dir_content($dir.'/'.$file); |
|
779 | + } |
|
724 | 780 | if(is_file($file) && $file != '.' && $file != '..') |
725 | - unlink($dir.'/'.$file); |
|
781 | + { |
|
782 | + unlink($dir.'/'.$file); |
|
783 | + } |
|
726 | 784 | array_shift($list); |
727 | 785 | } |
728 | 786 | //rmdir($dir); // dont remove own dir |
@@ -748,7 +806,9 @@ discard block |
||
748 | 806 | */ |
749 | 807 | public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
750 | 808 | { |
751 | - if (function_exists('str_getcsv')) // php5.3+ |
|
809 | + if (function_exists('str_getcsv')) |
|
810 | + { |
|
811 | + // php5.3+ |
|
752 | 812 | { |
753 | 813 | // we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings |
754 | 814 | // str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes) |
@@ -758,6 +818,7 @@ discard block |
||
758 | 818 | '\\"' => '""', |
759 | 819 | '\\n' => "\n", |
760 | 820 | '\\r' => "\r")), ',', '"', '\0'); |
821 | + } |
|
761 | 822 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
762 | 823 | foreach($fields as &$field) |
763 | 824 | { |
@@ -774,9 +835,12 @@ discard block |
||
774 | 835 | break; |
775 | 836 | } |
776 | 837 | } |
777 | - if ($keys) // if string keys are to be used --> combine keys and values |
|
838 | + if ($keys) |
|
839 | + { |
|
840 | + // if string keys are to be used --> combine keys and values |
|
778 | 841 | { |
779 | 842 | $fields = array_combine($keys, $fields); |
843 | + } |
|
780 | 844 | // base64-decode blob columns, if they are base64 encoded |
781 | 845 | foreach($blobs as $key) |
782 | 846 | { |
@@ -925,7 +989,11 @@ discard block |
||
925 | 989 | |
926 | 990 | foreach($this->schemas as $table => $schema) |
927 | 991 | { |
928 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
992 | + if (in_array($table,$this->exclude_tables)) |
|
993 | + { |
|
994 | + continue; |
|
995 | + } |
|
996 | + // dont backup |
|
929 | 997 | |
930 | 998 | // do we have a primary key? |
931 | 999 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -951,8 +1019,14 @@ discard block |
||
951 | 1019 | empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC', |
952 | 1020 | false, self::ROW_CHUNK) as $row) |
953 | 1021 | { |
954 | - if (!empty($pk)) $max = $row[$pk]; |
|
955 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
1022 | + if (!empty($pk)) |
|
1023 | + { |
|
1024 | + $max = $row[$pk]; |
|
1025 | + } |
|
1026 | + if ($total === 0) |
|
1027 | + { |
|
1028 | + fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
1029 | + } |
|
956 | 1030 | |
957 | 1031 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
958 | 1032 | fwrite($f,implode(',',$row)."\n"); |
@@ -962,21 +1036,30 @@ discard block |
||
962 | 1036 | } |
963 | 1037 | while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
964 | 1038 | |
965 | - if (!$pk) $this->db->rollback_lock($table); |
|
1039 | + if (!$pk) |
|
1040 | + { |
|
1041 | + $this->db->rollback_lock($table); |
|
1042 | + } |
|
966 | 1043 | } |
967 | 1044 | |
968 | 1045 | // let apps know that backup is finished |
969 | 1046 | Api\Hooks::process('backup_finished', array(), true); |
970 | 1047 | |
971 | - if(!$zippresent) // save without files |
|
1048 | + if(!$zippresent) |
|
1049 | + { |
|
1050 | + // save without files |
|
972 | 1051 | { |
973 | 1052 | if ($this->backup_files) |
974 | 1053 | { |
975 | 1054 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
1055 | + } |
|
976 | 1056 | } |
977 | 1057 | |
978 | 1058 | fclose($f); |
979 | - if (file_exists($name)) unlink($name); |
|
1059 | + if (file_exists($name)) |
|
1060 | + { |
|
1061 | + unlink($name); |
|
1062 | + } |
|
980 | 1063 | return TRUE; |
981 | 1064 | } |
982 | 1065 | // save files .... |
@@ -988,9 +1071,12 @@ discard block |
||
988 | 1071 | //echo substr($file,strlen($dir)+1).'<br>'; |
989 | 1072 | //echo $file.'<br>'; |
990 | 1073 | $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
991 | - if(($count++) == 100) { // the file descriptor limit |
|
1074 | + if(($count++) == 100) |
|
1075 | + { |
|
1076 | +// the file descriptor limit |
|
992 | 1077 | $zip->close(); |
993 | - if(($zip = new ZipArchive())) { |
|
1078 | + if(($zip = new ZipArchive())) |
|
1079 | + { |
|
994 | 1080 | $zip->open($filename); |
995 | 1081 | $count =0; |
996 | 1082 | } |
@@ -1015,15 +1101,21 @@ discard block |
||
1015 | 1101 | { |
1016 | 1102 | //chdir($f); |
1017 | 1103 | //echo "Processing $f <br>"; |
1018 | - if ($path_name =='') $path_name = $f; |
|
1104 | + if ($path_name =='') |
|
1105 | + { |
|
1106 | + $path_name = $f; |
|
1107 | + } |
|
1019 | 1108 | $tlist = scandir($f); |
1020 | 1109 | $list = array(); |
1021 | 1110 | $i = $cnt; |
1022 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1111 | + while($file = $tlist[0]) |
|
1112 | + { |
|
1113 | + // remove all '.' and '..' and transfer to $list |
|
1023 | 1114 | { |
1024 | 1115 | if($file == '.' || $file == '..') |
1025 | 1116 | { |
1026 | 1117 | array_shift($tlist); |
1118 | + } |
|
1027 | 1119 | } |
1028 | 1120 | elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
1029 | 1121 | { |
@@ -94,10 +94,10 @@ |
||
94 | 94 | /** |
95 | 95 | * Constructor |
96 | 96 | * |
97 | - * @param Traversable $rs |
|
97 | + * @param \Traversable $rs |
|
98 | 98 | * @param callback $callback |
99 | 99 | * @param array $params =array() additional parameters, row is always first parameter |
100 | - * @param $key_callback =null optional callback, if you want different keys |
|
100 | + * @param \Closure $key_callback =null optional callback, if you want different keys |
|
101 | 101 | */ |
102 | 102 | public function __construct(\Traversable $rs, $callback, $params=array(), $key_callback=null) |
103 | 103 | { |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @param array $params =array() additional parameters, row is always first parameter |
100 | 100 | * @param $key_callback =null optional callback, if you want different keys |
101 | 101 | */ |
102 | - public function __construct(\Traversable $rs, $callback, $params=array(), $key_callback=null) |
|
102 | + public function __construct(\Traversable $rs, $callback, $params = array(), $key_callback = null) |
|
103 | 103 | { |
104 | 104 | $this->callback = $callback; |
105 | 105 | $this->params = $params; |
106 | 106 | $this->key_callback = $key_callback; |
107 | 107 | |
108 | - if (is_a($rs,'IteratorAggregate')) |
|
108 | + if (is_a($rs, 'IteratorAggregate')) |
|
109 | 109 | { |
110 | 110 | $this->rs = $rs->getIterator(); |
111 | 111 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function current() |
124 | 124 | { |
125 | - if (is_a($this->rs,'iterator')) |
|
125 | + if (is_a($this->rs, 'iterator')) |
|
126 | 126 | { |
127 | 127 | $params = $this->params; |
128 | 128 | array_unshift($params, $this->rs->current()); |
@@ -138,11 +138,10 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function key() |
140 | 140 | { |
141 | - if (is_a($this->rs,'iterator')) |
|
141 | + if (is_a($this->rs, 'iterator')) |
|
142 | 142 | { |
143 | 143 | return $this->key_callback ? |
144 | - call_user_func($this->key_callback, $this->rs->current()) : |
|
145 | - $this->rs->key(); |
|
144 | + call_user_func($this->key_callback, $this->rs->current()) : $this->rs->key(); |
|
146 | 145 | } |
147 | 146 | return 0; |
148 | 147 | } |
@@ -152,7 +151,7 @@ discard block |
||
152 | 151 | */ |
153 | 152 | public function next() |
154 | 153 | { |
155 | - if (is_a($this->rs,'iterator')) |
|
154 | + if (is_a($this->rs, 'iterator')) |
|
156 | 155 | { |
157 | 156 | return $this->rs->next(); |
158 | 157 | } |
@@ -163,7 +162,7 @@ discard block |
||
163 | 162 | */ |
164 | 163 | public function rewind() |
165 | 164 | { |
166 | - if (is_a($this->rs,'iterator')) |
|
165 | + if (is_a($this->rs, 'iterator')) |
|
167 | 166 | { |
168 | 167 | return $this->rs->rewind(); |
169 | 168 | } |
@@ -174,9 +173,9 @@ discard block |
||
174 | 173 | * |
175 | 174 | * @return boolean |
176 | 175 | */ |
177 | - public function valid () |
|
176 | + public function valid() |
|
178 | 177 | { |
179 | - if (is_a($this->rs,'iterator')) |
|
178 | + if (is_a($this->rs, 'iterator')) |
|
180 | 179 | { |
181 | 180 | return $this->rs->valid(); |
182 | 181 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @deprecated not used anymore as it costs to much performance, use transactions if needed |
186 | 186 | * @param string $table name of table to lock |
187 | 187 | * @param string $mode type of lock required (optional), default write |
188 | - * @return bool True if sucessful, False if fails |
|
188 | + * @return boolean|null True if sucessful, False if fails |
|
189 | 189 | */ |
190 | 190 | function lock($table, $mode='write') |
191 | 191 | { |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * Unlock a table |
197 | 197 | * |
198 | 198 | * @deprecated not used anymore as it costs to much performance, use transactions if needed |
199 | - * @return bool True if sucessful, False if fails |
|
199 | + * @return boolean|null True if sucessful, False if fails |
|
200 | 200 | */ |
201 | 201 | function unlock() |
202 | 202 | {} |
@@ -41,19 +41,19 @@ discard block |
||
41 | 41 | var $Query_ID = 0; |
42 | 42 | |
43 | 43 | /** |
44 | - * Execute a query |
|
45 | - * |
|
46 | - * @param string $Query_String the query to be executed |
|
47 | - * @param int $line the line method was called from - use __LINE__ |
|
48 | - * @param string $file the file method was called from - use __FILE__ |
|
49 | - * @param int $offset row to start from, default 0 |
|
50 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
51 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
52 | - * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
53 | - * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
54 | - * @return ADORecordSet or false, if the query fails |
|
55 | - * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
56 | - */ |
|
44 | + * Execute a query |
|
45 | + * |
|
46 | + * @param string $Query_String the query to be executed |
|
47 | + * @param int $line the line method was called from - use __LINE__ |
|
48 | + * @param string $file the file method was called from - use __FILE__ |
|
49 | + * @param int $offset row to start from, default 0 |
|
50 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
51 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
52 | + * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
53 | + * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
54 | + * @return ADORecordSet or false, if the query fails |
|
55 | + * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
56 | + */ |
|
57 | 57 | function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
58 | 58 | { |
59 | 59 | // New query, discard previous result. |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Escape strings before sending them to the database |
|
80 | - * |
|
81 | - * @deprecated use quote($value,$type='') instead |
|
82 | - * @param string $str the string to be escaped |
|
83 | - * @return string escaped sting |
|
84 | - */ |
|
79 | + * Escape strings before sending them to the database |
|
80 | + * |
|
81 | + * @deprecated use quote($value,$type='') instead |
|
82 | + * @param string $str the string to be escaped |
|
83 | + * @return string escaped sting |
|
84 | + */ |
|
85 | 85 | function db_addslashes($str) |
86 | 86 | { |
87 | 87 | if (!isset($str) || $str == '') |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | - * Move to the next row in the results set |
|
111 | - * |
|
112 | - * Specifying a fetch_mode only works for newly fetched rows, the first row always gets fetched by query!!! |
|
113 | - * |
|
114 | - * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
115 | - * @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM |
|
116 | - * @return bool was another row found? |
|
117 | - */ |
|
110 | + * Move to the next row in the results set |
|
111 | + * |
|
112 | + * Specifying a fetch_mode only works for newly fetched rows, the first row always gets fetched by query!!! |
|
113 | + * |
|
114 | + * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
115 | + * @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM |
|
116 | + * @return bool was another row found? |
|
117 | + */ |
|
118 | 118 | function next_record($fetch_mode=self::FETCH_BOTH) |
119 | 119 | { |
120 | 120 | if (!$this->Query_ID) |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | - * Move to position in result set |
|
168 | - * |
|
169 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
170 | - * @param int $pos required row (optional), default first row |
|
171 | - * @return boolean true if sucessful or false if not found |
|
172 | - */ |
|
167 | + * Move to position in result set |
|
168 | + * |
|
169 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
170 | + * @param int $pos required row (optional), default first row |
|
171 | + * @return boolean true if sucessful or false if not found |
|
172 | + */ |
|
173 | 173 | function seek($pos = 0) |
174 | 174 | { |
175 | 175 | if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) |
@@ -180,74 +180,74 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Lock a table |
|
184 | - * |
|
185 | - * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
186 | - * @param string $table name of table to lock |
|
187 | - * @param string $mode type of lock required (optional), default write |
|
188 | - * @return bool True if sucessful, False if fails |
|
189 | - */ |
|
183 | + * Lock a table |
|
184 | + * |
|
185 | + * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
186 | + * @param string $table name of table to lock |
|
187 | + * @param string $mode type of lock required (optional), default write |
|
188 | + * @return bool True if sucessful, False if fails |
|
189 | + */ |
|
190 | 190 | function lock($table, $mode='write') |
191 | 191 | { |
192 | 192 | unset($table, $mode); // not used anymore |
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Unlock a table |
|
197 | - * |
|
198 | - * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
199 | - * @return bool True if sucessful, False if fails |
|
200 | - */ |
|
196 | + * Unlock a table |
|
197 | + * |
|
198 | + * @deprecated not used anymore as it costs to much performance, use transactions if needed |
|
199 | + * @return bool True if sucessful, False if fails |
|
200 | + */ |
|
201 | 201 | function unlock() |
202 | 202 | {} |
203 | 203 | |
204 | 204 | /** |
205 | - * Number of rows in current result set |
|
206 | - * |
|
207 | - * @deprecated use the result-object returned by query/select()->NumRows(), so you can use the global db-object and not a clone |
|
208 | - * @return int number of rows |
|
209 | - */ |
|
205 | + * Number of rows in current result set |
|
206 | + * |
|
207 | + * @deprecated use the result-object returned by query/select()->NumRows(), so you can use the global db-object and not a clone |
|
208 | + * @return int number of rows |
|
209 | + */ |
|
210 | 210 | function num_rows() |
211 | 211 | { |
212 | 212 | return $this->Query_ID ? $this->Query_ID->RecordCount() : False; |
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | - * Number of fields in current row |
|
217 | - * |
|
218 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
219 | - * @return int number of fields |
|
220 | - */ |
|
216 | + * Number of fields in current row |
|
217 | + * |
|
218 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
219 | + * @return int number of fields |
|
220 | + */ |
|
221 | 221 | function num_fields() |
222 | 222 | { |
223 | 223 | return $this->Query_ID ? $this->Query_ID->FieldCount() : False; |
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
227 | - * @deprecated use num_rows() |
|
228 | - */ |
|
227 | + * @deprecated use num_rows() |
|
228 | + */ |
|
229 | 229 | function nf() |
230 | 230 | { |
231 | 231 | return $this->num_rows(); |
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | - * @deprecated use print num_rows() |
|
236 | - */ |
|
235 | + * @deprecated use print num_rows() |
|
236 | + */ |
|
237 | 237 | function np() |
238 | 238 | { |
239 | 239 | print $this->num_rows(); |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Return the value of a column |
|
244 | - * |
|
245 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
246 | - * @param string|integer $Name name of field or positional index starting from 0 |
|
247 | - * @param bool $strip_slashes string escape chars from field(optional), default false |
|
248 | - * depricated param, as correctly quoted values dont need any stripslashes! |
|
249 | - * @return string the field value |
|
250 | - */ |
|
243 | + * Return the value of a column |
|
244 | + * |
|
245 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
246 | + * @param string|integer $Name name of field or positional index starting from 0 |
|
247 | + * @param bool $strip_slashes string escape chars from field(optional), default false |
|
248 | + * depricated param, as correctly quoted values dont need any stripslashes! |
|
249 | + * @return string the field value |
|
250 | + */ |
|
251 | 251 | function f($Name, $strip_slashes = False) |
252 | 252 | { |
253 | 253 | if ($strip_slashes) |
@@ -258,26 +258,26 @@ discard block |
||
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Print the value of a field |
|
262 | - * |
|
263 | - * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
264 | - * @param string $Name name of field to print |
|
265 | - * @param bool $strip_slashes string escape chars from field(optional), default false |
|
266 | - * depricated param, as correctly quoted values dont need any stripslashes! |
|
267 | - */ |
|
261 | + * Print the value of a field |
|
262 | + * |
|
263 | + * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone |
|
264 | + * @param string $Name name of field to print |
|
265 | + * @param bool $strip_slashes string escape chars from field(optional), default false |
|
266 | + * depricated param, as correctly quoted values dont need any stripslashes! |
|
267 | + */ |
|
268 | 268 | function p($Name, $strip_slashes = True) |
269 | 269 | { |
270 | 270 | print $this->f($Name, $strip_slashes); |
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | - * Returns a query-result-row as an associative array (no numerical keys !!!) |
|
275 | - * |
|
276 | - * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
277 | - * @param bool $do_next_record should next_record() be called or not (default not) |
|
278 | - * @param string $strip ='' string to strip of the column-name, default '' |
|
279 | - * @return array/bool the associative array or False if no (more) result-row is availible |
|
280 | - */ |
|
274 | + * Returns a query-result-row as an associative array (no numerical keys !!!) |
|
275 | + * |
|
276 | + * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object |
|
277 | + * @param bool $do_next_record should next_record() be called or not (default not) |
|
278 | + * @param string $strip ='' string to strip of the column-name, default '' |
|
279 | + * @return array/bool the associative array or False if no (more) result-row is availible |
|
280 | + */ |
|
281 | 281 | function row($do_next_record=False,$strip='') |
282 | 282 | { |
283 | 283 | if ($do_next_record && !$this->next_record(self::FETCH_ASSOC) || !is_array($this->Record)) |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return ADORecordSet or false, if the query fails |
55 | 55 | * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
56 | 56 | */ |
57 | - function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
|
57 | + function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true) |
|
58 | 58 | { |
59 | 59 | // New query, discard previous result. |
60 | 60 | if ($this->Query_ID) |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function free() |
104 | 104 | { |
105 | - unset($this->Query_ID); // else copying of the db-object does not work |
|
105 | + unset($this->Query_ID); // else copying of the db-object does not work |
|
106 | 106 | $this->Query_ID = 0; |
107 | 107 | } |
108 | 108 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM |
116 | 116 | * @return bool was another row found? |
117 | 117 | */ |
118 | - function next_record($fetch_mode=self::FETCH_BOTH) |
|
118 | + function next_record($fetch_mode = self::FETCH_BOTH) |
|
119 | 119 | { |
120 | 120 | if (!$this->Query_ID) |
121 | 121 | { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') // maxdb, oracle, ... |
137 | 137 | { |
138 | - switch($fetch_mode) |
|
138 | + switch ($fetch_mode) |
|
139 | 139 | { |
140 | 140 | case self::FETCH_ASSOC: |
141 | 141 | $this->Record = array_change_key_case($this->Record); |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | */ |
173 | 173 | function seek($pos = 0) |
174 | 174 | { |
175 | - if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) |
|
175 | + if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) |
|
176 | 176 | { |
177 | - throw new Exception("seek($pos) failed: resultset has " . $this->num_rows() . " rows"); |
|
177 | + throw new Exception("seek($pos) failed: resultset has ".$this->num_rows()." rows"); |
|
178 | 178 | } |
179 | 179 | return True; |
180 | 180 | } |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | * @param string $mode type of lock required (optional), default write |
188 | 188 | * @return bool True if sucessful, False if fails |
189 | 189 | */ |
190 | - function lock($table, $mode='write') |
|
190 | + function lock($table, $mode = 'write') |
|
191 | 191 | { |
192 | - unset($table, $mode); // not used anymore |
|
192 | + unset($table, $mode); // not used anymore |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -278,18 +278,18 @@ discard block |
||
278 | 278 | * @param string $strip ='' string to strip of the column-name, default '' |
279 | 279 | * @return array/bool the associative array or False if no (more) result-row is availible |
280 | 280 | */ |
281 | - function row($do_next_record=False,$strip='') |
|
281 | + function row($do_next_record = False, $strip = '') |
|
282 | 282 | { |
283 | 283 | if ($do_next_record && !$this->next_record(self::FETCH_ASSOC) || !is_array($this->Record)) |
284 | 284 | { |
285 | 285 | return False; |
286 | 286 | } |
287 | 287 | $result = array(); |
288 | - foreach($this->Record as $column => $value) |
|
288 | + foreach ($this->Record as $column => $value) |
|
289 | 289 | { |
290 | 290 | if (!is_numeric($column)) |
291 | 291 | { |
292 | - if ($strip) $column = str_replace($strip,'',$column); |
|
292 | + if ($strip) $column = str_replace($strip, '', $column); |
|
293 | 293 | |
294 | 294 | $result[$column] = $value; |
295 | 295 | } |
@@ -121,10 +121,13 @@ discard block |
||
121 | 121 | { |
122 | 122 | throw new Exception('next_record called with no query pending.'); |
123 | 123 | } |
124 | - if ($this->Row) // first row is already fetched |
|
124 | + if ($this->Row) |
|
125 | + { |
|
126 | + // first row is already fetched |
|
125 | 127 | { |
126 | 128 | $this->Query_ID->MoveNext(); |
127 | 129 | } |
130 | + } |
|
128 | 131 | ++$this->Row; |
129 | 132 | |
130 | 133 | $this->Record = $this->Query_ID->fields; |
@@ -133,12 +136,15 @@ discard block |
||
133 | 136 | { |
134 | 137 | return False; |
135 | 138 | } |
136 | - if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') // maxdb, oracle, ... |
|
139 | + if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') |
|
140 | + { |
|
141 | + // maxdb, oracle, ... |
|
137 | 142 | { |
138 | 143 | switch($fetch_mode) |
139 | 144 | { |
140 | 145 | case self::FETCH_ASSOC: |
141 | 146 | $this->Record = array_change_key_case($this->Record); |
147 | + } |
|
142 | 148 | break; |
143 | 149 | case self::FETCH_NUM: |
144 | 150 | $this->Record = array_values($this->Record); |
@@ -199,7 +205,8 @@ discard block |
||
199 | 205 | * @return bool True if sucessful, False if fails |
200 | 206 | */ |
201 | 207 | function unlock() |
202 | - {} |
|
208 | + { |
|
209 | +} |
|
203 | 210 | |
204 | 211 | /** |
205 | 212 | * Number of rows in current result set |
@@ -289,7 +296,10 @@ discard block |
||
289 | 296 | { |
290 | 297 | if (!is_numeric($column)) |
291 | 298 | { |
292 | - if ($strip) $column = str_replace($strip,'',$column); |
|
299 | + if ($strip) |
|
300 | + { |
|
301 | + $column = str_replace($strip,'',$column); |
|
302 | + } |
|
293 | 303 | |
294 | 304 | $result[$column] = $value; |
295 | 305 | } |
@@ -301,4 +311,6 @@ discard block |
||
301 | 311 | /** |
302 | 312 | * @deprecated use EGroupware\Api\Db\CallbackIterator |
303 | 313 | */ |
304 | -class egw_db_callback_iterator extends Api\Db\CallbackIterator {} |
|
314 | +class egw_db_callback_iterator extends Api\Db\CallbackIterator |
|
315 | +{ |
|
316 | +} |