@@ -213,7 +213,6 @@ |
||
213 | 213 | /** |
214 | 214 | * Remove attributes we are not allowed to update |
215 | 215 | * |
216 | - * @param array $attributes |
|
217 | 216 | */ |
218 | 217 | function sanitize_update(array &$ldapContact) |
219 | 218 | { |
@@ -170,7 +170,7 @@ |
||
170 | 170 | * |
171 | 171 | * @param string/array $_contact_id contact_id or array with values for id or account_id |
172 | 172 | * @return array/boolean data if row could be retrived else False |
173 | - */ |
|
173 | + */ |
|
174 | 174 | function read($_contact_id) |
175 | 175 | { |
176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email'); |
36 | 36 | */ |
37 | 37 | var $search_attributes = array( |
38 | - 'n_family','n_middle','n_given','org_name','org_unit', |
|
39 | - 'adr_one_location','note','email','samaccountname', |
|
38 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
39 | + 'adr_one_location', 'note', 'email', 'samaccountname', |
|
40 | 40 | ); |
41 | 41 | |
42 | 42 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @var string |
52 | 52 | */ |
53 | - var $dn_attribute='cn'; |
|
53 | + var $dn_attribute = 'cn'; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!) |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server'] |
83 | 83 | * @param resource $ds =null ldap connection to use |
84 | 84 | */ |
85 | - function __construct(array $ldap_config=null, $ds=null) |
|
85 | + function __construct(array $ldap_config = null, $ds = null) |
|
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) parent::__construct(); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 88 | |
89 | - $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
89 | + $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
90 | 90 | |
91 | 91 | if ($ldap_config) |
92 | 92 | { |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | else |
96 | 96 | { |
97 | - $this->ldap_config =& $GLOBALS['egw_info']['server']; |
|
97 | + $this->ldap_config = & $GLOBALS['egw_info']['server']; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $this->accounts_ads = $GLOBALS['egw']->accounts->backend; |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | 'account_id' => 'objectsid', |
120 | 120 | 'id' => 'objectguid', |
121 | 121 | 'uid' => 'objectguid', |
122 | - 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | - 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
122 | + 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
123 | + 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
124 | 124 | )); |
125 | 125 | unset($this->schema2egw['user']['n_fileas']); |
126 | 126 | unset($this->schema2egw['inetorgperson']); |
127 | 127 | |
128 | - foreach($this->schema2egw as $attributes) |
|
128 | + foreach ($this->schema2egw as $attributes) |
|
129 | 129 | { |
130 | - $this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); |
|
130 | + $this->all_attributes = array_merge($this->all_attributes, array_values($attributes)); |
|
131 | 131 | } |
132 | 132 | $this->all_attributes = array_values(array_unique($this->all_attributes)); |
133 | 133 | |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param boolean $admin =false true (re-)connect with admin not user credentials, eg. to modify accounts |
141 | 141 | */ |
142 | - function connect($admin=false) |
|
142 | + function connect($admin = false) |
|
143 | 143 | { |
144 | - unset($admin); // not used, but required by function signature |
|
144 | + unset($admin); // not used, but required by function signature |
|
145 | 145 | |
146 | 146 | $this->ds = $this->accounts_ads->ldap_connection(); |
147 | 147 | } |
@@ -174,15 +174,14 @@ discard block |
||
174 | 174 | function read($_contact_id) |
175 | 175 | { |
176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
177 | - !is_array($_contact_id) && substr($_contact_id,0,8) == 'account:') |
|
177 | + !is_array($_contact_id) && substr($_contact_id, 0, 8) == 'account:') |
|
178 | 178 | { |
179 | - $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id,8)); |
|
179 | + $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id, 8)); |
|
180 | 180 | $_contact_id = $GLOBALS['egw']->accounts->id2name($account_id, 'person_id'); |
181 | 181 | } |
182 | - $contact_id = !is_array($_contact_id) ? $_contact_id : |
|
183 | - (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
182 | + $contact_id = !is_array($_contact_id) ? $_contact_id : (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
184 | 183 | |
185 | - $rows = $this->_searchLDAP($this->allContactsDN, $filter=$this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
184 | + $rows = $this->_searchLDAP($this->allContactsDN, $filter = $this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
186 | 185 | //error_log(__METHOD__."('$contact_id') _searchLDAP($this->allContactsDN, '$filter',...)=".array2string($rows)); |
187 | 186 | return $rows ? $rows[0] : false; |
188 | 187 | } |
@@ -84,7 +84,11 @@ discard block |
||
84 | 84 | */ |
85 | 85 | function __construct(array $ldap_config=null, $ds=null) |
86 | 86 | { |
87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
87 | + if (false) |
|
88 | + { |
|
89 | + parent::__construct (); |
|
90 | + } |
|
91 | + // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
88 | 92 | |
89 | 93 | $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
90 | 94 | |
@@ -202,10 +206,16 @@ discard block |
||
202 | 206 | $contact['id'] = $contact['uid'] = $this->accounts_ads->objectguid2str($data['objectguid']); |
203 | 207 | |
204 | 208 | // ignore system accounts |
205 | - if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) return false; |
|
209 | + if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) |
|
210 | + { |
|
211 | + return false; |
|
212 | + } |
|
206 | 213 | |
207 | 214 | // ignore deactivated or expired accounts |
208 | - if (!$this->accounts_ads->user_active($data)) return false; |
|
215 | + if (!$this->accounts_ads->user_active($data)) |
|
216 | + { |
|
217 | + return false; |
|
218 | + } |
|
209 | 219 | |
210 | 220 | $this->_inetorgperson2egw($contact, $data, 'displayname'); |
211 | 221 | } |
@@ -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__); |
@@ -336,18 +336,18 @@ discard block |
||
336 | 336 | $match_count = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] ? |
337 | 337 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] : 3; |
338 | 338 | |
339 | - $columns = Array(); |
|
340 | - $extra = Array(); |
|
339 | + $columns = array(); |
|
340 | + $extra = array(); |
|
341 | 341 | $order = in_array($param['order'], $group) ? $param['order'] : $group[0]; |
342 | 342 | $join .= $this->table_name .'.contact_id != a2.contact_id AND ('; |
343 | - $join_fields = Array(); |
|
343 | + $join_fields = array(); |
|
344 | 344 | foreach($group as $field) |
345 | 345 | { |
346 | 346 | $extra[] = "IF({$this->table_name}.$field = a2.$field, 1, 0)"; |
347 | 347 | $join_fields[] = $this->table_name . ".$field = a2.$field"; |
348 | 348 | $columns[] = "IF({$this->table_name}.$field = a2.$field, {$this->table_name}.$field, '') AS $field"; |
349 | 349 | } |
350 | - $extra = Array( |
|
350 | + $extra = array( |
|
351 | 351 | implode('+', $extra) . ' AS match_count' |
352 | 352 | ); |
353 | 353 | $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | } |
383 | 383 | |
384 | 384 | $rows = $this->db->query( |
385 | - "SELECT $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
385 | + "select $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
386 | 386 | ' FROM (' . $sub_query . ') AS matches GROUP BY ' . implode(',',$group) . |
387 | 387 | ' HAVING group_count > 1 ORDER BY ' . $order, |
388 | 388 | __LINE__, __FILE__, (int)$param['start'],$mysql_calc_rows ? (int)$param['num_rows'] : -1 |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
721 | 721 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
722 | 722 | __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
723 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
723 | + '',false,0,"join $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
724 | 724 | { |
725 | 725 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
726 | 726 | } |
@@ -112,11 +112,20 @@ discard block |
||
112 | 112 | $filter = is_array($param['col_filter']) ? $param['col_filter'] : array(); |
113 | 113 | $join = ''; |
114 | 114 | $op = 'OR'; |
115 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
115 | + if (isset($param['op']) && !empty($param['op'])) |
|
116 | + { |
|
117 | + $op = $param['op']; |
|
118 | + } |
|
116 | 119 | $advanced_search = false; |
117 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
120 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
121 | + { |
|
122 | + $advanced_search = true; |
|
123 | + } |
|
118 | 124 | $wildcard ='%'; |
119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
125 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
126 | + { |
|
127 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
128 | + } |
|
120 | 129 | |
121 | 130 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
122 | 131 | if ($filter['cat_id']) |
@@ -134,7 +143,11 @@ discard block |
||
134 | 143 | // we have no private grants in addressbook at the moment, they have then to be added here too |
135 | 144 | if ($param['owner']) |
136 | 145 | { |
137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
146 | + if (!$this->grants[(int) $filter['owner']]) |
|
147 | + { |
|
148 | + return false; |
|
149 | + } |
|
150 | + // we have no access to that addressbook |
|
138 | 151 | |
139 | 152 | $filter['owner'] = $param['owner']; |
140 | 153 | $filter['private'] = 0; |
@@ -209,7 +222,10 @@ discard block |
||
209 | 222 | $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
210 | 223 | array($param['start'],$param['num_rows']),$filter,$join); |
211 | 224 | |
212 | - if (!$rows) return false; |
|
225 | + if (!$rows) |
|
226 | + { |
|
227 | + return false; |
|
228 | + } |
|
213 | 229 | |
214 | 230 | // query the values for *_count == 1, to display them instead |
215 | 231 | $filter['org_name'] = $orgs = array(); |
@@ -284,11 +300,20 @@ discard block |
||
284 | 300 | $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
285 | 301 | $filter = $param['col_filter']; |
286 | 302 | $op = 'OR'; |
287 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
303 | + if (isset($param['op']) && !empty($param['op'])) |
|
304 | + { |
|
305 | + $op = $param['op']; |
|
306 | + } |
|
288 | 307 | $advanced_search = false; |
289 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
308 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
309 | + { |
|
310 | + $advanced_search = true; |
|
311 | + } |
|
290 | 312 | $wildcard ='%'; |
291 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
313 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
314 | + { |
|
315 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
316 | + } |
|
292 | 317 | |
293 | 318 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
294 | 319 | if ($param['cat_id']) |
@@ -319,7 +344,11 @@ discard block |
||
319 | 344 | // we have no private grants in addressbook at the moment, they have then to be added here too |
320 | 345 | if (array_key_exists('owner', $param)) |
321 | 346 | { |
322 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
347 | + if (!$this->grants[(int) $param['owner']]) |
|
348 | + { |
|
349 | + return false; |
|
350 | + } |
|
351 | + // we have no access to that addressbook |
|
323 | 352 | |
324 | 353 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
325 | 354 | $filter[$this->table_name.'.private'] = 0; |
@@ -459,7 +488,10 @@ discard block |
||
459 | 488 | */ |
460 | 489 | function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false) |
461 | 490 | { |
462 | - 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"; |
|
491 | + if ((int) $this->debug >= 4) |
|
492 | + { |
|
493 | + echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
494 | + } |
|
463 | 495 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
464 | 496 | |
465 | 497 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -508,7 +540,10 @@ discard block |
||
508 | 540 | // no grants for selected owner/addressbook |
509 | 541 | if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
510 | 542 | { |
511 | - if (!isset($groupmember_sql)) return false; |
|
543 | + if (!isset($groupmember_sql)) |
|
544 | + { |
|
545 | + return false; |
|
546 | + } |
|
512 | 547 | $filter[] = substr($groupmember_sql,4); |
513 | 548 | unset($filter['owner']); |
514 | 549 | } |
@@ -560,13 +595,16 @@ discard block |
||
560 | 595 | $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
561 | 596 | } |
562 | 597 | } |
563 | - if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
|
598 | + if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) |
|
599 | + { |
|
600 | + // search also adds a join for custom fields! |
|
564 | 601 | { |
565 | 602 | switch(gettype($only_keys)) |
566 | 603 | { |
567 | 604 | case 'boolean': |
568 | 605 | // Correctly handled by parent class |
569 | 606 | break; |
607 | + } |
|
570 | 608 | case 'string': |
571 | 609 | $only_keys = explode(',',$only_keys); |
572 | 610 | // fall through |
@@ -576,13 +614,23 @@ discard block |
||
576 | 614 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
577 | 615 | $order_by, $all_matches, PREG_SET_ORDER)) |
578 | 616 | { |
579 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
617 | + if (!is_array($extra_cols)) |
|
618 | + { |
|
619 | + $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
620 | + } |
|
580 | 621 | foreach($all_matches as $matches) |
581 | 622 | { |
582 | 623 | $table = ''; |
583 | 624 | $column = $matches[1]; |
584 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
585 | - if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
|
625 | + if ($column[0] == '#') |
|
626 | + { |
|
627 | + continue; |
|
628 | + } |
|
629 | + // order by custom field is handeled in so_sql_cf anyway |
|
630 | + if (($key = array_search($column, $this->db_cols)) !== false) |
|
631 | + { |
|
632 | + $column = $key; |
|
633 | + } |
|
586 | 634 | if (strpos($column,'.') === false) |
587 | 635 | { |
588 | 636 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
@@ -597,10 +645,13 @@ discard block |
||
597 | 645 | } |
598 | 646 | $extra_cols[] = $table.$column.' '.$matches[2]; |
599 | 647 | //_debug_array($matches); |
600 | - if (!empty($order_by) && $table) // postgres requires explizit order by |
|
648 | + if (!empty($order_by) && $table) |
|
649 | + { |
|
650 | + // postgres requires explizit order by |
|
601 | 651 | { |
602 | 652 | $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
603 | 653 | } |
654 | + } |
|
604 | 655 | } |
605 | 656 | //_debug_array($order_by); _debug_array($extra_cols); |
606 | 657 | } |
@@ -626,7 +677,11 @@ discard block |
||
626 | 677 | } |
627 | 678 | $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
628 | 679 | |
629 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
680 | + if ($start === false) |
|
681 | + { |
|
682 | + $this->total = is_array($rows) ? count($rows) : 0; |
|
683 | + } |
|
684 | + // so_sql sets total only for $start !== false! |
|
630 | 685 | |
631 | 686 | return $rows; |
632 | 687 | } |
@@ -668,7 +723,10 @@ discard block |
||
668 | 723 | $cat_filter = array(); |
669 | 724 | foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
670 | 725 | { |
671 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
726 | + if (is_numeric($cat)) |
|
727 | + { |
|
728 | + $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
729 | + } |
|
672 | 730 | } |
673 | 731 | return $cat_filter; |
674 | 732 | } |
@@ -681,10 +739,13 @@ discard block |
||
681 | 739 | */ |
682 | 740 | function change_owner($account_id,$new_owner) |
683 | 741 | { |
684 | - if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
|
742 | + if (!$new_owner) |
|
743 | + { |
|
744 | + // otherwise we would create an account (contact_owner==0) |
|
685 | 745 | { |
686 | 746 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
687 | 747 | } |
748 | + } |
|
688 | 749 | // contacts |
689 | 750 | $this->db->update($this->table_name,array( |
690 | 751 | 'contact_owner' => $new_owner, |
@@ -729,7 +790,10 @@ discard block |
||
729 | 790 | foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
730 | 791 | false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
731 | 792 | { |
732 | - if ($member_attr) $row['members'] = array(); |
|
793 | + if ($member_attr) |
|
794 | + { |
|
795 | + $row['members'] = array(); |
|
796 | + } |
|
733 | 797 | $lists[$row['list_id']] = $row; |
734 | 798 | } |
735 | 799 | if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
@@ -792,9 +856,15 @@ discard block |
||
792 | 856 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
793 | 857 | { |
794 | 858 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
795 | - if (!$keys && !$data || !(int)$owner) return false; |
|
859 | + if (!$keys && !$data || !(int)$owner) |
|
860 | + { |
|
861 | + return false; |
|
862 | + } |
|
796 | 863 | |
797 | - if ($keys && !is_array($keys)) $keys = array('list_name' => $keys); |
|
864 | + if ($keys && !is_array($keys)) |
|
865 | + { |
|
866 | + $keys = array('list_name' => $keys); |
|
867 | + } |
|
798 | 868 | if ($keys) |
799 | 869 | { |
800 | 870 | $keys['list_owner'] = $owner; |
@@ -814,9 +884,15 @@ discard block |
||
814 | 884 | } |
815 | 885 | $data['list_modified'] = time(); |
816 | 886 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
817 | - if (!$data['list_id']) unset($data['list_id']); |
|
887 | + if (!$data['list_id']) |
|
888 | + { |
|
889 | + unset($data['list_id']); |
|
890 | + } |
|
818 | 891 | |
819 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
892 | + if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) |
|
893 | + { |
|
894 | + return false; |
|
895 | + } |
|
820 | 896 | |
821 | 897 | if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
822 | 898 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
@@ -834,7 +910,10 @@ discard block |
||
834 | 910 | |
835 | 911 | $this->add2list($list_id,$contacts,array()); |
836 | 912 | } |
837 | - if ($keys) $data += $keys; |
|
913 | + if ($keys) |
|
914 | + { |
|
915 | + $data += $keys; |
|
916 | + } |
|
838 | 917 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
839 | 918 | return $list_id; |
840 | 919 | } |
@@ -849,7 +928,10 @@ discard block |
||
849 | 928 | */ |
850 | 929 | function add2list($contact,$list,array $existing=null) |
851 | 930 | { |
852 | - if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
|
931 | + if (!(int)$list || !is_array($contact) && !(int)$contact) |
|
932 | + { |
|
933 | + return false; |
|
934 | + } |
|
853 | 935 | |
854 | 936 | if (!is_array($existing)) |
855 | 937 | { |
@@ -891,7 +973,10 @@ discard block |
||
891 | 973 | */ |
892 | 974 | function remove_from_list($contact,$list=null) |
893 | 975 | { |
894 | - if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
|
976 | + if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) |
|
977 | + { |
|
978 | + return false; |
|
979 | + } |
|
895 | 980 | |
896 | 981 | $where = array( |
897 | 982 | 'contact_id' => $contact, |
@@ -933,7 +1018,10 @@ discard block |
||
933 | 1018 | */ |
934 | 1019 | function delete_list($list) |
935 | 1020 | { |
936 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
1021 | + if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) |
|
1022 | + { |
|
1023 | + return false; |
|
1024 | + } |
|
937 | 1025 | |
938 | 1026 | $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
939 | 1027 | |
@@ -948,7 +1036,10 @@ discard block |
||
948 | 1036 | */ |
949 | 1037 | function lists_ctag($owner=null) |
950 | 1038 | { |
951 | - if (is_null($owner)) $owner = array_keys($this->grants); |
|
1039 | + if (is_null($owner)) |
|
1040 | + { |
|
1041 | + $owner = array_keys($this->grants); |
|
1042 | + } |
|
952 | 1043 | |
953 | 1044 | if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
954 | 1045 | __LINE__,__FILE__)->fetchColumn())) |
@@ -968,9 +1059,12 @@ discard block |
||
968 | 1059 | */ |
969 | 1060 | function read($keys,$extra_cols='',$join='') |
970 | 1061 | { |
971 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
1062 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
1063 | + { |
|
972 | 1064 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
973 | - } else { |
|
1065 | + } |
|
1066 | + else |
|
1067 | + { |
|
974 | 1068 | $minimum_uid_length = 8; |
975 | 1069 | } |
976 | 1070 | |
@@ -990,7 +1084,8 @@ discard block |
||
990 | 1084 | |
991 | 1085 | // enforce a minium uid strength |
992 | 1086 | if (is_array($contact) && (!isset($contact['uid']) |
993 | - || strlen($contact['uid']) < $minimum_uid_length)) { |
|
1087 | + || strlen($contact['uid']) < $minimum_uid_length)) |
|
1088 | + { |
|
994 | 1089 | parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
995 | 1090 | } |
996 | 1091 | return $contact; |
@@ -1007,19 +1102,28 @@ discard block |
||
1007 | 1102 | { |
1008 | 1103 | unset($extra_where); // not used, but required by function signature |
1009 | 1104 | |
1010 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
1105 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
1106 | + { |
|
1011 | 1107 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
1012 | - } else { |
|
1108 | + } |
|
1109 | + else |
|
1110 | + { |
|
1013 | 1111 | $minimum_uid_length = 8; |
1014 | 1112 | } |
1015 | 1113 | |
1016 | - if (is_array($keys) && count($keys)) $this->data_merge($keys); |
|
1114 | + if (is_array($keys) && count($keys)) |
|
1115 | + { |
|
1116 | + $this->data_merge($keys); |
|
1117 | + } |
|
1017 | 1118 | |
1018 | 1119 | $new_entry = !$this->data['id']; |
1019 | 1120 | |
1020 | - if (isset($this->data['etag'])) // do we have an etag in the data to write |
|
1121 | + if (isset($this->data['etag'])) |
|
1122 | + { |
|
1123 | + // do we have an etag in the data to write |
|
1021 | 1124 | { |
1022 | 1125 | $etag = $this->data['etag']; |
1126 | + } |
|
1023 | 1127 | unset($this->data['etag']); |
1024 | 1128 | if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
1025 | 1129 | { |
@@ -1091,7 +1195,10 @@ discard block |
||
1091 | 1195 | */ |
1092 | 1196 | function read_list($list) |
1093 | 1197 | { |
1094 | - if (!$list) return false; |
|
1198 | + if (!$list) |
|
1199 | + { |
|
1200 | + return false; |
|
1201 | + } |
|
1095 | 1202 | |
1096 | 1203 | return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
1097 | 1204 | } |
@@ -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); |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
116 | 116 | $advanced_search = false; |
117 | 117 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
118 | - $wildcard ='%'; |
|
119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
118 | + $wildcard = '%'; |
|
119 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
120 | 120 | |
121 | 121 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
122 | 122 | if ($filter['cat_id']) |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | // we have no private grants in addressbook at the moment, they have then to be added here too |
135 | 135 | if ($param['owner']) |
136 | 136 | { |
137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
137 | + if (!$this->grants[(int)$filter['owner']]) return false; // we have no access to that addressbook |
|
138 | 138 | |
139 | 139 | $filter['owner'] = $param['owner']; |
140 | 140 | $filter['private'] = 0; |
@@ -143,18 +143,18 @@ discard block |
||
143 | 143 | { |
144 | 144 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
145 | 145 | { |
146 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
146 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
147 | 147 | } |
148 | 148 | $filter[] = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
149 | 149 | " OR contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
150 | - implode(',',array_keys($this->grants))."))"; |
|
150 | + implode(',', array_keys($this->grants))."))"; |
|
151 | 151 | } |
152 | 152 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
153 | 153 | { |
154 | 154 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
155 | 155 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
156 | 156 | { |
157 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
157 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
158 | 158 | } |
159 | 159 | else |
160 | 160 | { |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } |
169 | 169 | else |
170 | 170 | { |
171 | - $filter[] = "org_name != ''";// AND org_name IS NOT NULL"; |
|
171 | + $filter[] = "org_name != ''"; // AND org_name IS NOT NULL"; |
|
172 | 172 | } |
173 | 173 | if (isset($filter['list'])) |
174 | 174 | { |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } |
187 | 187 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
188 | 188 | |
189 | - list(,$by) = explode(',',$param['org_view']); |
|
189 | + list(,$by) = explode(',', $param['org_view']); |
|
190 | 190 | if (!$by) |
191 | 191 | { |
192 | 192 | $extra = array( |
@@ -199,41 +199,40 @@ discard block |
||
199 | 199 | else // by adr_one_location or org_unit |
200 | 200 | { |
201 | 201 | // org total for more then one $by |
202 | - $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : |
|
203 | - "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
204 | - parent::search($param['search'],array('org_name'), |
|
202 | + $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)"; |
|
203 | + parent::search($param['search'], array('org_name'), |
|
205 | 204 | "GROUP BY org_name HAVING $by_expr > 1 ORDER BY org_name $sort", array( |
206 | 205 | "NULL AS $by", |
207 | 206 | '1 AS is_main', |
208 | 207 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
209 | 208 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
210 | 209 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
211 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
210 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
212 | 211 | // org by location |
213 | - parent::search($param['search'],array('org_name'), |
|
212 | + parent::search($param['search'], array('org_name'), |
|
214 | 213 | "GROUP BY org_name,$by ORDER BY org_name $sort,$by $sort", array( |
215 | 214 | "CASE WHEN $by IS NULL THEN '' ELSE $by END AS $by", |
216 | 215 | '0 AS is_main', |
217 | 216 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
218 | 217 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
219 | 218 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
220 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
219 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
221 | 220 | $append = "ORDER BY org_name $sort,is_main DESC,$by $sort"; |
222 | 221 | } |
223 | - $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
|
224 | - array($param['start'],$param['num_rows']),$filter,$join); |
|
222 | + $rows = parent::search($param['search'], array('org_name'), $append, $extra, $wildcard, false, $op/*'OR'*/, |
|
223 | + array($param['start'], $param['num_rows']), $filter, $join); |
|
225 | 224 | |
226 | 225 | if (!$rows) return false; |
227 | 226 | |
228 | 227 | // query the values for *_count == 1, to display them instead |
229 | 228 | $filter['org_name'] = $orgs = array(); |
230 | - foreach($rows as $row) |
|
229 | + foreach ($rows as $row) |
|
231 | 230 | { |
232 | 231 | if ($row['org_unit_count'] == 1 || $row['adr_one_locality_count'] == 1) |
233 | 232 | { |
234 | - $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
233 | + $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
235 | 234 | } |
236 | - $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count']==1 ? $row[$by] : '|||') : ''); |
|
235 | + $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count'] == 1 ? $row[$by] : '|||') : ''); |
|
237 | 236 | $row['group_count'] = $row['org_count']; |
238 | 237 | $orgs[$org_key] = $row; |
239 | 238 | } |
@@ -241,9 +240,9 @@ discard block |
||
241 | 240 | |
242 | 241 | if (count($filter['org_name'])) |
243 | 242 | { |
244 | - foreach((array) parent::search(null, array('org_name','org_unit','adr_one_locality'), |
|
243 | + foreach ((array)parent::search(null, array('org_name', 'org_unit', 'adr_one_locality'), |
|
245 | 244 | 'GROUP BY org_name,org_unit,adr_one_locality', |
246 | - '',$wildcard,false,$op/*'AND'*/,false,$filter,$join) as $row) |
|
245 | + '', $wildcard, false, $op/*'AND'*/, false, $filter, $join) as $row) |
|
247 | 246 | { |
248 | 247 | $org_key = $row['org_name'].($by ? '|||'.$row[$by] : ''); |
249 | 248 | if ($orgs[$org_key]['org_unit_count'] == 1) |
@@ -295,27 +294,27 @@ discard block |
||
295 | 294 | */ |
296 | 295 | function duplicates($param) |
297 | 296 | { |
298 | - $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
|
297 | + $join = 'JOIN '.$this->table_name.' AS a2 ON '; |
|
299 | 298 | $filter = $param['col_filter']; |
300 | 299 | $op = 'OR'; |
301 | 300 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
302 | 301 | $advanced_search = false; |
303 | 302 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
304 | - $wildcard ='%'; |
|
305 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
303 | + $wildcard = '%'; |
|
304 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
306 | 305 | |
307 | 306 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
308 | 307 | if ($param['cat_id']) |
309 | 308 | { |
310 | 309 | $cat_filter = $this->_cat_filter($filter['cat_id']); |
311 | - $filter[] = str_replace('cat_id', $this->table_name . '.cat_id', $cat_filter); |
|
312 | - $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter) . ' AND '; |
|
310 | + $filter[] = str_replace('cat_id', $this->table_name.'.cat_id', $cat_filter); |
|
311 | + $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter).' AND '; |
|
313 | 312 | unset($filter['cat_id']); |
314 | 313 | } |
315 | 314 | if ($filter['tid']) |
316 | 315 | { |
317 | - $filter[$this->table_name . '.contact_tid'] = $param['col_filter']['tid']; |
|
318 | - $join .= 'a2.contact_tid = ' . $this->db->quote($filter['tid']) . ' AND '; |
|
316 | + $filter[$this->table_name.'.contact_tid'] = $param['col_filter']['tid']; |
|
317 | + $join .= 'a2.contact_tid = '.$this->db->quote($filter['tid']).' AND '; |
|
319 | 318 | unset($filter['tid']); |
320 | 319 | } |
321 | 320 | else |
@@ -323,33 +322,33 @@ discard block |
||
323 | 322 | $join .= 'a2.contact_tid != \'D\' AND '; |
324 | 323 | } |
325 | 324 | // add filter for read ACL in sql, if user is NOT the owner of the addressbook |
326 | - if (array_key_exists('owner',$param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
325 | + if (array_key_exists('owner', $param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
327 | 326 | { |
328 | 327 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
329 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
328 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
330 | 329 | } |
331 | 330 | else |
332 | 331 | { |
333 | 332 | // we have no private grants in addressbook at the moment, they have then to be added here too |
334 | 333 | if (array_key_exists('owner', $param)) |
335 | 334 | { |
336 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
335 | + if (!$this->grants[(int)$param['owner']]) return false; // we have no access to that addressbook |
|
337 | 336 | |
338 | 337 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
339 | 338 | $filter[$this->table_name.'.private'] = 0; |
340 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
341 | - $join .= 'a2.contact_private = ' . $this->db->quote($filter['private']) . ' AND '; |
|
339 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
340 | + $join .= 'a2.contact_private = '.$this->db->quote($filter['private']).' AND '; |
|
342 | 341 | } |
343 | 342 | else // search all addressbooks, incl. accounts |
344 | 343 | { |
345 | 344 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
346 | 345 | { |
347 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
346 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
348 | 347 | } |
349 | 348 | $filter[] = $access = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
350 | 349 | " OR {$this->table_name}.contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
351 | - implode(',',array_keys($this->grants))."))"; |
|
352 | - $join .= str_replace($this->table_name, 'a2', $access) . ' AND '; |
|
350 | + implode(',', array_keys($this->grants))."))"; |
|
351 | + $join .= str_replace($this->table_name, 'a2', $access).' AND '; |
|
353 | 352 | } |
354 | 353 | } |
355 | 354 | if ($param['searchletter']) |
@@ -358,34 +357,33 @@ discard block |
||
358 | 357 | } |
359 | 358 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
360 | 359 | $group = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields'] ? |
361 | - explode(',',$GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']): |
|
362 | - array('n_family', 'org_name', 'contact_email'); |
|
360 | + explode(',', $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']) : array('n_family', 'org_name', 'contact_email'); |
|
363 | 361 | $match_count = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] ? |
364 | 362 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] : 3; |
365 | 363 | |
366 | 364 | $columns = Array(); |
367 | 365 | $extra = Array(); |
368 | 366 | $order = in_array($param['order'], $group) ? $param['order'] : $group[0]; |
369 | - $join .= $this->table_name .'.contact_id != a2.contact_id AND ('; |
|
367 | + $join .= $this->table_name.'.contact_id != a2.contact_id AND ('; |
|
370 | 368 | $join_fields = Array(); |
371 | - foreach($group as $field) |
|
369 | + foreach ($group as $field) |
|
372 | 370 | { |
373 | 371 | $extra[] = "IF({$this->table_name}.$field = a2.$field, 1, 0)"; |
374 | - $join_fields[] = $this->table_name . ".$field = a2.$field"; |
|
372 | + $join_fields[] = $this->table_name.".$field = a2.$field"; |
|
375 | 373 | $columns[] = "IF({$this->table_name}.$field = a2.$field, {$this->table_name}.$field, '') AS $field"; |
376 | 374 | } |
377 | 375 | $extra = Array( |
378 | - implode('+', $extra) . ' AS match_count' |
|
376 | + implode('+', $extra).' AS match_count' |
|
379 | 377 | ); |
380 | - $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; |
|
378 | + $join .= $this->db->column_data_implode(' OR ', $join_fields).')'; |
|
381 | 379 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
382 | 380 | { |
383 | 381 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
384 | 382 | { |
385 | - $join .=' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
386 | - $join .=' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
387 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_1.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
388 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_2.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
383 | + $join .= ' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
384 | + $join .= ' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
385 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_1.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
386 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_2.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
389 | 387 | } |
390 | 388 | else |
391 | 389 | { |
@@ -399,17 +397,17 @@ discard block |
||
399 | 397 | if ($param['search'] && !is_array($param['search'])) |
400 | 398 | { |
401 | 399 | $search_cols = array(); |
402 | - foreach($group as $col) |
|
400 | + foreach ($group as $col) |
|
403 | 401 | { |
404 | - $search_cols[] = $this->table_name . '.' . $col; |
|
402 | + $search_cols[] = $this->table_name.'.'.$col; |
|
405 | 403 | } |
406 | - $search = $this->search2criteria($param['search'],$wildcard,$op, null, $search_cols); |
|
404 | + $search = $this->search2criteria($param['search'], $wildcard, $op, null, $search_cols); |
|
407 | 405 | $criteria = array($search); |
408 | 406 | } |
409 | 407 | $query = $this->parse_search(array_merge($criteria, $filter), $wildcard, false, ' AND '); |
410 | 408 | |
411 | 409 | $sub_query = $this->db->select($this->table_name, |
412 | - 'DISTINCT ' . implode(', ',array_merge($columns, $extra)), |
|
410 | + 'DISTINCT '.implode(', ', array_merge($columns, $extra)), |
|
413 | 411 | $query, |
414 | 412 | False, False, 0, $append, False, -1, |
415 | 413 | $join |
@@ -422,15 +420,15 @@ discard block |
||
422 | 420 | } |
423 | 421 | |
424 | 422 | $rows = $this->db->query( |
425 | - "SELECT $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
426 | - ' FROM (' . $sub_query . ') AS matches GROUP BY ' . implode(',',$group) . |
|
427 | - ' HAVING group_count > 1 ORDER BY ' . $order, |
|
428 | - __LINE__, __FILE__, (int)$param['start'],$mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
423 | + "SELECT $mysql_calc_rows ".$columns.', COUNT(contact_id) AS group_count'. |
|
424 | + ' FROM ('.$sub_query.') AS matches GROUP BY '.implode(',', $group). |
|
425 | + ' HAVING group_count > 1 ORDER BY '.$order, |
|
426 | + __LINE__, __FILE__, (int)$param['start'], $mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
429 | 427 | ); |
430 | 428 | |
431 | 429 | // Go through rows and only return one for each pair/triplet/etc. of matches |
432 | 430 | $dupes = array(); |
433 | - foreach($rows as $key => $row) |
|
431 | + foreach ($rows as $key => $row) |
|
434 | 432 | { |
435 | 433 | $row['email'] = $row['contact_email']; |
436 | 434 | $row['email_home'] = $row['contact_email_home']; |
@@ -471,9 +469,9 @@ discard block |
||
471 | 469 | * @param boolean $ignore_acl =false true: no acl check |
472 | 470 | * @return boolean/array of matching rows (the row is an array of the cols) or False |
473 | 471 | */ |
474 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false) |
|
472 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false, $ignore_acl = false) |
|
475 | 473 | { |
476 | - 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"; |
|
474 | + 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"; |
|
477 | 475 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
478 | 476 | |
479 | 477 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -489,10 +487,10 @@ discard block |
||
489 | 487 | { |
490 | 488 | if ($filter['cat_id'][0] == '!') |
491 | 489 | { |
492 | - $filter['cat_id'] = substr($filter['cat_id'],1); |
|
490 | + $filter['cat_id'] = substr($filter['cat_id'], 1); |
|
493 | 491 | $not = 'NOT'; |
494 | 492 | } |
495 | - $filter[] = $this->_cat_filter($filter['cat_id'],$not); |
|
493 | + $filter[] = $this->_cat_filter($filter['cat_id'], $not); |
|
496 | 494 | unset($filter['cat_id']); |
497 | 495 | } |
498 | 496 | |
@@ -502,17 +500,17 @@ discard block |
||
502 | 500 | { |
503 | 501 | // add read ACL for groupmembers (they have no |
504 | 502 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
505 | - (!isset($filter['owner']) || in_array('0',(array)$filter['owner']))) |
|
503 | + (!isset($filter['owner']) || in_array('0', (array)$filter['owner']))) |
|
506 | 504 | { |
507 | 505 | $groupmembers = array(); |
508 | - foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $group_id) |
|
506 | + foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $group_id) |
|
509 | 507 | { |
510 | - if (($members = $GLOBALS['egw']->accounts->members($group_id,true))) |
|
508 | + if (($members = $GLOBALS['egw']->accounts->members($group_id, true))) |
|
511 | 509 | { |
512 | - $groupmembers = array_merge($groupmembers,$members); |
|
510 | + $groupmembers = array_merge($groupmembers, $members); |
|
513 | 511 | } |
514 | 512 | } |
515 | - $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.',array( |
|
513 | + $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.', array( |
|
516 | 514 | 'account_id' => array_unique($groupmembers), |
517 | 515 | )); |
518 | 516 | } |
@@ -520,34 +518,34 @@ discard block |
||
520 | 518 | if (isset($filter['owner'])) |
521 | 519 | { |
522 | 520 | // no grants for selected owner/addressbook |
523 | - if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
|
521 | + if (!($filter['owner'] = array_intersect((array)$filter['owner'], array_keys($this->grants)))) |
|
524 | 522 | { |
525 | 523 | if (!isset($groupmember_sql)) return false; |
526 | - $filter[] = substr($groupmember_sql,4); |
|
524 | + $filter[] = substr($groupmember_sql, 4); |
|
527 | 525 | unset($filter['owner']); |
528 | 526 | } |
529 | 527 | // for an owner filter, which does NOT include current user, filter out private entries |
530 | - elseif (!in_array($GLOBALS['egw_info']['user']['account_id'],$filter['owner'])) |
|
528 | + elseif (!in_array($GLOBALS['egw_info']['user']['account_id'], $filter['owner'])) |
|
531 | 529 | { |
532 | 530 | $filter['private'] = 0; |
533 | 531 | } |
534 | 532 | // if multiple addressbooks (incl. current owner) are searched, we need full acl filter |
535 | - elseif(count($filter['owner']) > 1) |
|
533 | + elseif (count($filter['owner']) > 1) |
|
536 | 534 | { |
537 | 535 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
538 | 536 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
539 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
537 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
540 | 538 | } |
541 | 539 | } |
542 | 540 | else // search all addressbooks, incl. accounts |
543 | 541 | { |
544 | 542 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
545 | 543 | { |
546 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
544 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
547 | 545 | } |
548 | 546 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
549 | 547 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
550 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
548 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
551 | 549 | } |
552 | 550 | } |
553 | 551 | if (isset($filter['list'])) |
@@ -565,24 +563,24 @@ discard block |
||
565 | 563 | unset($filter['list']); |
566 | 564 | } |
567 | 565 | // 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) |
568 | - if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' && |
|
569 | - strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter)) |
|
566 | + if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository, 0, 3) == 'sql' && |
|
567 | + strpos($join, $GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id', $filter)) |
|
570 | 568 | { |
571 | 569 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
572 | 570 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
573 | 571 | { |
574 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
572 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
575 | 573 | } |
576 | 574 | } |
577 | 575 | if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
578 | 576 | { |
579 | - switch(gettype($only_keys)) |
|
577 | + switch (gettype($only_keys)) |
|
580 | 578 | { |
581 | 579 | case 'boolean': |
582 | 580 | // Correctly handled by parent class |
583 | 581 | break; |
584 | 582 | case 'string': |
585 | - $only_keys = explode(',',$only_keys); |
|
583 | + $only_keys = explode(',', $only_keys); |
|
586 | 584 | // fall through |
587 | 585 | } |
588 | 586 | // postgres requires that expressions in order by appear in the columns of a distinct select |
@@ -590,14 +588,14 @@ discard block |
||
590 | 588 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
591 | 589 | $order_by, $all_matches, PREG_SET_ORDER)) |
592 | 590 | { |
593 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
594 | - foreach($all_matches as $matches) |
|
591 | + if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',', $extra_cols) : array(); |
|
592 | + foreach ($all_matches as $matches) |
|
595 | 593 | { |
596 | 594 | $table = ''; |
597 | 595 | $column = $matches[1]; |
598 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
596 | + if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
599 | 597 | if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
600 | - if (strpos($column,'.') === false) |
|
598 | + if (strpos($column, '.') === false) |
|
601 | 599 | { |
602 | 600 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
603 | 601 | if (isset($this->db_cols[$column])) |
@@ -613,34 +611,34 @@ discard block |
||
613 | 611 | //_debug_array($matches); |
614 | 612 | if (!empty($order_by) && $table) // postgres requires explizit order by |
615 | 613 | { |
616 | - $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
|
614 | + $order_by = str_replace($matches[0], $table.$column.' '.$matches[2].' '.$matches[3].$matches[4], $order_by); |
|
617 | 615 | } |
618 | 616 | } |
619 | 617 | //_debug_array($order_by); _debug_array($extra_cols); |
620 | 618 | } |
621 | 619 | |
622 | 620 | // Understand search by date with wildcard (????.10.??) according to user date preference |
623 | - if(is_string($criteria) && strpos($criteria, '?') !== false) |
|
621 | + if (is_string($criteria) && strpos($criteria, '?') !== false) |
|
624 | 622 | { |
625 | 623 | // First, check for a 'date', with wildcards, in the user's format |
626 | - $date_regex = str_replace('Q','d', |
|
627 | - str_replace(array('Y','m','d','.','-'), |
|
628 | - array('(?P<Y>(?:\?|\Q){4})','(?P<m>(?:\?|\Q){2})','(?P<d>(?:\?|\Q){2})','\.','\-'), |
|
624 | + $date_regex = str_replace('Q', 'd', |
|
625 | + str_replace(array('Y', 'm', 'd', '.', '-'), |
|
626 | + array('(?P<Y>(?:\?|\Q){4})', '(?P<m>(?:\?|\Q){2})', '(?P<d>(?:\?|\Q){2})', '\.', '\-'), |
|
629 | 627 | $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); |
630 | 628 | |
631 | - if(preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
629 | + if (preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
632 | 630 | { |
633 | - foreach($matches[0] as $m_id => $match) |
|
631 | + foreach ($matches[0] as $m_id => $match) |
|
634 | 632 | { |
635 | 633 | // Birthday is Y-m-d |
636 | - $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*",$criteria); |
|
634 | + $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*", $criteria); |
|
637 | 635 | } |
638 | 636 | } |
639 | 637 | } |
640 | 638 | } |
641 | - $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
639 | + $rows = & parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
642 | 640 | |
643 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
641 | + if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
644 | 642 | |
645 | 643 | return $rows; |
646 | 644 | } |
@@ -652,18 +650,18 @@ discard block |
||
652 | 650 | * @param int|array $cat_id |
653 | 651 | * @return string sql to filter by given cat |
654 | 652 | */ |
655 | - function _cat_filter($cat_id, $not='') |
|
653 | + function _cat_filter($cat_id, $not = '') |
|
656 | 654 | { |
657 | 655 | if (!is_object($GLOBALS['egw']->categories)) |
658 | 656 | { |
659 | 657 | $GLOBALS['egw']->categories = new Api\Categories; |
660 | 658 | } |
661 | - foreach($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
659 | + foreach ($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
662 | 660 | { |
663 | - $cat_filter[] = $this->db->concat("','",cat_id,"','")." $not LIKE '%,$cat,%'"; |
|
661 | + $cat_filter[] = $this->db->concat("','", cat_id, "','")." $not LIKE '%,$cat,%'"; |
|
664 | 662 | } |
665 | - $cfilter = '('.implode(' OR ',$cat_filter).')'; |
|
666 | - if(!empty($not)) |
|
663 | + $cfilter = '('.implode(' OR ', $cat_filter).')'; |
|
664 | + if (!empty($not)) |
|
667 | 665 | { |
668 | 666 | $cfilter = "( $cfilter OR cat_id IS NULL )"; |
669 | 667 | } |
@@ -680,9 +678,9 @@ discard block |
||
680 | 678 | function _cat_search($cats) |
681 | 679 | { |
682 | 680 | $cat_filter = array(); |
683 | - foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
|
681 | + foreach (is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',', $cats)) as $cat) |
|
684 | 682 | { |
685 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
683 | + if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','", cat_id, "','")." LIKE '%,$cat,%'"; |
|
686 | 684 | } |
687 | 685 | return $cat_filter; |
688 | 686 | } |
@@ -693,32 +691,32 @@ discard block |
||
693 | 691 | * @param int $account_id account-id of the old owner |
694 | 692 | * @param int $new_owner account-id of the new owner |
695 | 693 | */ |
696 | - function change_owner($account_id,$new_owner) |
|
694 | + function change_owner($account_id, $new_owner) |
|
697 | 695 | { |
698 | 696 | if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
699 | 697 | { |
700 | 698 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
701 | 699 | } |
702 | 700 | // contacts |
703 | - $this->db->update($this->table_name,array( |
|
701 | + $this->db->update($this->table_name, array( |
|
704 | 702 | 'contact_owner' => $new_owner, |
705 | - ),array( |
|
703 | + ), array( |
|
706 | 704 | 'contact_owner' => $account_id, |
707 | - ),__LINE__,__FILE__); |
|
705 | + ), __LINE__, __FILE__); |
|
708 | 706 | |
709 | 707 | // cfs |
710 | 708 | $this->db->update(self::EXTRA_TABLE, array( |
711 | 709 | 'contact_owner' => $new_owner |
712 | - ),array( |
|
710 | + ), array( |
|
713 | 711 | 'contact_owner' => $account_id |
714 | 712 | ), __LINE__, __FILE__); |
715 | 713 | |
716 | 714 | // lists |
717 | 715 | $this->db->update($this->lists_table, array( |
718 | 716 | 'list_owner' => $new_owner, |
719 | - ),array( |
|
717 | + ), array( |
|
720 | 718 | 'list_owner' => $account_id, |
721 | - ),__LINE__,__FILE__); |
|
719 | + ), __LINE__, __FILE__); |
|
722 | 720 | } |
723 | 721 | |
724 | 722 | /** |
@@ -732,21 +730,21 @@ discard block |
||
732 | 730 | * if int|array only return members from the given owners addressbook(s) |
733 | 731 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
734 | 732 | */ |
735 | - function get_lists($uids,$uid_column='list_owner',$member_attr=null,$limit_in_ab=false) |
|
733 | + function get_lists($uids, $uid_column = 'list_owner', $member_attr = null, $limit_in_ab = false) |
|
736 | 734 | { |
737 | 735 | if (is_array($uids) && array_key_exists('list_id', $uids)) |
738 | 736 | { |
739 | - $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.',array('list_id' => $uids['list_id'])); |
|
737 | + $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.', array('list_id' => $uids['list_id'])); |
|
740 | 738 | unset($uids['list_id']); |
741 | 739 | } |
742 | 740 | $lists = array(); |
743 | - foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
|
744 | - false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
741 | + foreach ($this->db->select($this->lists_table, '*', $uid_column ? array($uid_column=>$uids) : $uids, __LINE__, __FILE__, |
|
742 | + false, 'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
745 | 743 | { |
746 | 744 | if ($member_attr) $row['members'] = array(); |
747 | 745 | $lists[$row['list_id']] = $row; |
748 | 746 | } |
749 | - if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
|
747 | + if ($lists && $member_attr && in_array($member_attr, array('contact_id', 'contact_uid', 'caldav_name'))) |
|
750 | 748 | { |
751 | 749 | if ($limit_in_ab) |
752 | 750 | { |
@@ -760,10 +758,9 @@ discard block |
||
760 | 758 | $in_ab_join .= "list_owner=$this->table_name.contact_owner"; |
761 | 759 | } |
762 | 760 | } |
763 | - foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
761 | + foreach ($this->db->select($this->ab2list_table, "$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
764 | 762 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
765 | - __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
|
766 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
763 | + __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) |
|
767 | 764 | { |
768 | 765 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
769 | 766 | } |
@@ -803,7 +800,7 @@ discard block |
||
803 | 800 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
804 | 801 | * @return int|boolean integer list_id or false on error |
805 | 802 | */ |
806 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
803 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
807 | 804 | { |
808 | 805 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
809 | 806 | if (!$keys && !$data || !(int)$owner) return false; |
@@ -817,7 +814,7 @@ discard block |
||
817 | 814 | { |
818 | 815 | $data['list_owner'] = $owner; |
819 | 816 | } |
820 | - if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys,__LINE__,__FILE__)->fetchColumn())) |
|
817 | + if (!$keys || !($list_id = $this->db->select($this->lists_table, 'list_id', $keys, __LINE__, __FILE__)->fetchColumn())) |
|
821 | 818 | { |
822 | 819 | $data['list_created'] = time(); |
823 | 820 | $data['list_creator'] = $GLOBALS['egw_info']['user']['account_id']; |
@@ -830,9 +827,9 @@ discard block |
||
830 | 827 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
831 | 828 | if (!$data['list_id']) unset($data['list_id']); |
832 | 829 | |
833 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
830 | + if (!$this->db->insert($this->lists_table, $data, $keys, __LINE__, __FILE__)) return false; |
|
834 | 831 | |
835 | - if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
|
832 | + if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table, 'list_id')) && |
|
836 | 833 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
837 | 834 | { |
838 | 835 | $update = array(); |
@@ -844,9 +841,9 @@ discard block |
||
844 | 841 | { |
845 | 842 | $update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf'; |
846 | 843 | } |
847 | - $this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__); |
|
844 | + $this->db->update($this->lists_table, $update, array('list_id'=>$list_id), __LINE__, __FILE__); |
|
848 | 845 | |
849 | - $this->add2list($list_id,$contacts,array()); |
|
846 | + $this->add2list($list_id, $contacts, array()); |
|
850 | 847 | } |
851 | 848 | if ($keys) $data += $keys; |
852 | 849 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
@@ -861,39 +858,39 @@ discard block |
||
861 | 858 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
862 | 859 | * @return false on error |
863 | 860 | */ |
864 | - function add2list($contact,$list,array $existing=null) |
|
861 | + function add2list($contact, $list, array $existing = null) |
|
865 | 862 | { |
866 | 863 | if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
867 | 864 | |
868 | 865 | if (!is_array($existing)) |
869 | 866 | { |
870 | 867 | $existing = array(); |
871 | - foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row) |
|
868 | + foreach ($this->db->select($this->ab2list_table, 'contact_id', array('list_id'=>$list), __LINE__, __FILE__) as $row) |
|
872 | 869 | { |
873 | 870 | $existing[] = $row['contact_id']; |
874 | 871 | } |
875 | 872 | } |
876 | - if (!($to_add = array_diff((array)$contact,$existing))) |
|
873 | + if (!($to_add = array_diff((array)$contact, $existing))) |
|
877 | 874 | { |
878 | - return true; // no need to insert it, would give sql error |
|
875 | + return true; // no need to insert it, would give sql error |
|
879 | 876 | } |
880 | - foreach($to_add as $contact) |
|
877 | + foreach ($to_add as $contact) |
|
881 | 878 | { |
882 | - $this->db->insert($this->ab2list_table,array( |
|
879 | + $this->db->insert($this->ab2list_table, array( |
|
883 | 880 | 'contact_id' => $contact, |
884 | 881 | 'list_id' => $list, |
885 | 882 | 'list_added' => time(), |
886 | 883 | 'list_added_by' => $GLOBALS['egw_info']['user']['account_id'], |
887 | - ),array(),__LINE__,__FILE__); |
|
884 | + ), array(), __LINE__, __FILE__); |
|
888 | 885 | } |
889 | 886 | // update etag |
890 | - return $this->db->update($this->lists_table,array( |
|
887 | + return $this->db->update($this->lists_table, array( |
|
891 | 888 | 'list_etag=list_etag+1', |
892 | 889 | 'list_modified' => time(), |
893 | 890 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
894 | - ),array( |
|
891 | + ), array( |
|
895 | 892 | 'list_id' => $list, |
896 | - ),__LINE__,__FILE__); |
|
893 | + ), __LINE__, __FILE__); |
|
897 | 894 | } |
898 | 895 | |
899 | 896 | /** |
@@ -903,7 +900,7 @@ discard block |
||
903 | 900 | * @param int $list =null list-id or null to remove from all lists |
904 | 901 | * @return false on error |
905 | 902 | */ |
906 | - function remove_from_list($contact,$list=null) |
|
903 | + function remove_from_list($contact, $list = null) |
|
907 | 904 | { |
908 | 905 | if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
909 | 906 | |
@@ -917,24 +914,24 @@ discard block |
||
917 | 914 | else |
918 | 915 | { |
919 | 916 | $list = array(); |
920 | - foreach($this->db->select($this->ab2list_table,'list_id',$where,__LINE__,__FILE__) as $row) |
|
917 | + foreach ($this->db->select($this->ab2list_table, 'list_id', $where, __LINE__, __FILE__) as $row) |
|
921 | 918 | { |
922 | 919 | $list[] = $row['list_id']; |
923 | 920 | } |
924 | 921 | } |
925 | - if (!$this->db->delete($this->ab2list_table,$where,__LINE__,__FILE__)) |
|
922 | + if (!$this->db->delete($this->ab2list_table, $where, __LINE__, __FILE__)) |
|
926 | 923 | { |
927 | 924 | return false; |
928 | 925 | } |
929 | - foreach((array)$list as $list_id) |
|
926 | + foreach ((array)$list as $list_id) |
|
930 | 927 | { |
931 | - $this->db->update($this->lists_table,array( |
|
928 | + $this->db->update($this->lists_table, array( |
|
932 | 929 | 'list_etag=list_etag+1', |
933 | 930 | 'list_modified' => time(), |
934 | 931 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
935 | - ),array( |
|
932 | + ), array( |
|
936 | 933 | 'list_id' => $list_id, |
937 | - ),__LINE__,__FILE__); |
|
934 | + ), __LINE__, __FILE__); |
|
938 | 935 | } |
939 | 936 | return true; |
940 | 937 | } |
@@ -947,9 +944,9 @@ discard block |
||
947 | 944 | */ |
948 | 945 | function delete_list($list) |
949 | 946 | { |
950 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
947 | + if (!$this->db->delete($this->lists_table, array('list_id' => $list), __LINE__, __FILE__)) return false; |
|
951 | 948 | |
952 | - $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
|
949 | + $this->db->delete($this->ab2list_table, array('list_id' => $list), __LINE__, __FILE__); |
|
953 | 950 | |
954 | 951 | return $this->db->affected_rows(); |
955 | 952 | } |
@@ -960,12 +957,12 @@ discard block |
||
960 | 957 | * @param int|array $owner =null null for all lists user has access too |
961 | 958 | * @return int |
962 | 959 | */ |
963 | - function lists_ctag($owner=null) |
|
960 | + function lists_ctag($owner = null) |
|
964 | 961 | { |
965 | 962 | if (is_null($owner)) $owner = array_keys($this->grants); |
966 | 963 | |
967 | - if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
|
968 | - __LINE__,__FILE__)->fetchColumn())) |
|
964 | + if (!($modified = $this->db->select($this->lists_table, 'MAX(list_modified)', array('list_owner'=>$owner), |
|
965 | + __LINE__, __FILE__)->fetchColumn())) |
|
969 | 966 | { |
970 | 967 | return 0; |
971 | 968 | } |
@@ -980,7 +977,7 @@ discard block |
||
980 | 977 | * @param string $join |
981 | 978 | * @return array|boolean |
982 | 979 | */ |
983 | - function read($keys,$extra_cols='',$join='') |
|
980 | + function read($keys, $extra_cols = '', $join = '') |
|
984 | 981 | { |
985 | 982 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
986 | 983 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -993,11 +990,11 @@ discard block |
||
993 | 990 | $keys = array('uid' => $keys); |
994 | 991 | } |
995 | 992 | try { |
996 | - $contact = parent::read($keys,$extra_cols,$join); |
|
993 | + $contact = parent::read($keys, $extra_cols, $join); |
|
997 | 994 | } |
998 | 995 | // catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267) |
999 | 996 | // caused by non-ascii chars compared with ascii field uid |
1000 | - catch(Api\Db\Exception $e) { |
|
997 | + catch (Api\Db\Exception $e) { |
|
1001 | 998 | _egw_log_exception($e); |
1002 | 999 | return false; |
1003 | 1000 | } |
@@ -1005,7 +1002,7 @@ discard block |
||
1005 | 1002 | // enforce a minium uid strength |
1006 | 1003 | if (is_array($contact) && (!isset($contact['uid']) |
1007 | 1004 | || strlen($contact['uid']) < $minimum_uid_length)) { |
1008 | - parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
|
1005 | + parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook', $contact['id']))); |
|
1009 | 1006 | } |
1010 | 1007 | return $contact; |
1011 | 1008 | } |
@@ -1019,7 +1016,7 @@ discard block |
||
1019 | 1016 | */ |
1020 | 1017 | function save($keys = NULL, $extra_where = NULL) |
1021 | 1018 | { |
1022 | - unset($extra_where); // not used, but required by function signature |
|
1019 | + unset($extra_where); // not used, but required by function signature |
|
1023 | 1020 | |
1024 | 1021 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
1025 | 1022 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -1035,9 +1032,9 @@ discard block |
||
1035 | 1032 | { |
1036 | 1033 | $etag = $this->data['etag']; |
1037 | 1034 | unset($this->data['etag']); |
1038 | - if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
|
1035 | + if (!($err = parent::save(array('contact_etag=contact_etag+1'), array('contact_etag' => $etag)))) |
|
1039 | 1036 | { |
1040 | - $this->data['etag'] = $etag+1; |
|
1037 | + $this->data['etag'] = $etag + 1; |
|
1041 | 1038 | } |
1042 | 1039 | else |
1043 | 1040 | { |
@@ -1057,7 +1054,7 @@ discard block |
||
1057 | 1054 | // enforce a minium uid strength |
1058 | 1055 | if (!isset($this->data['uid']) || strlen($this->data['uid']) < $minimum_uid_length) |
1059 | 1056 | { |
1060 | - $update['uid'] = Api\CalDAV::generate_uid('addressbook',$this->data['id']); |
|
1057 | + $update['uid'] = Api\CalDAV::generate_uid('addressbook', $this->data['id']); |
|
1061 | 1058 | //echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>"; |
1062 | 1059 | } |
1063 | 1060 | // set carddav_name, if not given by caller |
@@ -1075,17 +1072,17 @@ discard block |
||
1075 | 1072 | 'contact_id' => $this->data['id'], |
1076 | 1073 | ), __LINE__, __FILE__)->fetchColumn(); |
1077 | 1074 | } |
1078 | - $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
1075 | + $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
1079 | 1076 | $backup = Api\Vfs::$is_root; Api\Vfs::$is_root = true; |
1080 | 1077 | if (empty($this->data['jpegphoto'])) |
1081 | 1078 | { |
1082 | 1079 | unlink($path); |
1083 | - $update['files'] = $this->data['files'] & ~Api\Contacts::FILES_BIT_PHOTO; |
|
1080 | + $update['files'] = $this->data['files']&~Api\Contacts::FILES_BIT_PHOTO; |
|
1084 | 1081 | } |
1085 | 1082 | else |
1086 | 1083 | { |
1087 | 1084 | file_put_contents($path, $this->data['jpegphoto']); |
1088 | - $update['files'] = $this->data['files'] | Api\Contacts::FILES_BIT_PHOTO; |
|
1085 | + $update['files'] = $this->data['files']|Api\Contacts::FILES_BIT_PHOTO; |
|
1089 | 1086 | } |
1090 | 1087 | Api\Vfs::$is_root = $backup; |
1091 | 1088 | } |
@@ -1107,7 +1104,7 @@ discard block |
||
1107 | 1104 | { |
1108 | 1105 | if (!$list) return false; |
1109 | 1106 | |
1110 | - return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
|
1107 | + return $this->db->select($this->lists_table, '*', array('list_id'=>$list), __LINE__, __FILE__)->fetch(); |
|
1111 | 1108 | } |
1112 | 1109 | |
1113 | 1110 | /** |
@@ -1118,9 +1115,9 @@ discard block |
||
1118 | 1115 | * @param array $extra_cols =array() extra-data to be saved |
1119 | 1116 | * @return bool false on success, errornumber on failure |
1120 | 1117 | */ |
1121 | - function save_customfields(&$data, array $extra_cols=array()) |
|
1118 | + function save_customfields(&$data, array $extra_cols = array()) |
|
1122 | 1119 | { |
1123 | - return parent::save_customfields($data, array('contact_owner' => $data['owner'])+$extra_cols); |
|
1120 | + return parent::save_customfields($data, array('contact_owner' => $data['owner']) + $extra_cols); |
|
1124 | 1121 | } |
1125 | 1122 | |
1126 | 1123 | /** |
@@ -1129,6 +1126,6 @@ discard block |
||
1129 | 1126 | */ |
1130 | 1127 | function delete_customfields($data) |
1131 | 1128 | { |
1132 | - $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
|
1129 | + $this->db->delete($this->extra_table, $data, __LINE__, __FILE__); |
|
1133 | 1130 | } |
1134 | 1131 | } |
@@ -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); |
@@ -520,8 +561,12 @@ discard block |
||
520 | 561 | $time, |
521 | 562 | static::$user_timezone |
522 | 563 | ); |
523 | - if($date) break; |
|
524 | - } catch (\Exception $e) { |
|
564 | + if($date) |
|
565 | + { |
|
566 | + break; |
|
567 | + } |
|
568 | + } |
|
569 | + catch (\Exception $e) { |
|
525 | 570 | |
526 | 571 | } |
527 | 572 | } |
@@ -540,7 +585,10 @@ discard block |
||
540 | 585 | public static function setUserPrefs($tz,$dateformat='',$timeformat='') |
541 | 586 | { |
542 | 587 | //echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n"; |
543 | - if (!empty($dateformat)) self::$user_dateformat = $dateformat; |
|
588 | + if (!empty($dateformat)) |
|
589 | + { |
|
590 | + self::$user_dateformat = $dateformat; |
|
591 | + } |
|
544 | 592 | |
545 | 593 | switch($timeformat) |
546 | 594 | { |
@@ -578,7 +626,10 @@ discard block |
||
578 | 626 | */ |
579 | 627 | public static function tz_offset_s($time='now') |
580 | 628 | { |
581 | - if (!($time instanceof DateTime)) $time = new DateTime($time); |
|
629 | + if (!($time instanceof DateTime)) |
|
630 | + { |
|
631 | + $time = new DateTime($time); |
|
632 | + } |
|
582 | 633 | |
583 | 634 | return self::$user_timezone->getOffset($time) - self::$server_timezone->getOffset($time); |
584 | 635 | } |
@@ -686,9 +737,17 @@ discard block |
||
686 | 737 | ); |
687 | 738 | foreach(DateTimeZone::listIdentifiers() as $name) |
688 | 739 | { |
689 | - if (in_array($name,$no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
740 | + if (in_array($name,$no_vtimezone)) |
|
741 | + { |
|
742 | + continue; |
|
743 | + } |
|
744 | + // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
690 | 745 | list($continent) = explode('/',$name,2); |
691 | - if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
746 | + if (!isset($tzs[$continent])) |
|
747 | + { |
|
748 | + continue; |
|
749 | + } |
|
750 | + // old depricated timezones |
|
692 | 751 | $datetime = new DateTime('now',new DateTimeZone($name)); |
693 | 752 | $tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)." ".$datetime->format(); |
694 | 753 | unset($datetime); |
@@ -727,10 +786,13 @@ discard block |
||
727 | 786 | { |
728 | 787 | $user_tzs = array_merge(array($tz),$user_tzs); |
729 | 788 | } |
730 | - if (!$user_tzs) // if we have no user timezones, eg. user set no pref --> use server default |
|
789 | + if (!$user_tzs) |
|
790 | + { |
|
791 | + // if we have no user timezones, eg. user set no pref --> use server default |
|
731 | 792 | { |
732 | 793 | $user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']); |
733 | 794 | } |
795 | + } |
|
734 | 796 | if ($extra && !in_array($extra,$user_tzs)) |
735 | 797 | { |
736 | 798 | $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 'Monday': |
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 | { |
@@ -470,10 +470,10 @@ discard block |
||
470 | 470 | // Try user format first |
471 | 471 | $time = static::createFromUserFormat($time); |
472 | 472 | } |
473 | - catch(\Exception $e) |
|
473 | + catch (\Exception $e) |
|
474 | 474 | { |
475 | 475 | unset($e); |
476 | - return null; // time could not be parsed |
|
476 | + return null; // time could not be parsed |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | return $time->format($type); |
@@ -497,22 +497,22 @@ discard block |
||
497 | 497 | $date = null; |
498 | 498 | |
499 | 499 | // If numeric, just let normal constructor do it |
500 | - if(is_numeric($time) || is_array($time)) |
|
500 | + if (is_numeric($time) || is_array($time)) |
|
501 | 501 | { |
502 | 502 | return new DateTime($time); |
503 | 503 | } |
504 | 504 | |
505 | 505 | // Various date formats in decreasing preference |
506 | 506 | $formats = array( |
507 | - '!'.static::$user_dateformat . ' ' .static::$user_timeformat.':s', |
|
508 | - '!'.static::$user_dateformat . '*' .static::$user_timeformat.':s', |
|
509 | - '!'.static::$user_dateformat . '* ' .static::$user_timeformat, |
|
510 | - '!'.static::$user_dateformat . '*', |
|
507 | + '!'.static::$user_dateformat.' '.static::$user_timeformat.':s', |
|
508 | + '!'.static::$user_dateformat.'*'.static::$user_timeformat.':s', |
|
509 | + '!'.static::$user_dateformat.'* '.static::$user_timeformat, |
|
510 | + '!'.static::$user_dateformat.'*', |
|
511 | 511 | '!'.static::$user_dateformat, |
512 | 512 | '!Y-m-d\TH:i:s' |
513 | 513 | ); |
514 | 514 | // Try the different formats, stop when one works |
515 | - foreach($formats as $f) |
|
515 | + foreach ($formats as $f) |
|
516 | 516 | { |
517 | 517 | try { |
518 | 518 | $date = static::createFromFormat( |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | $time, |
521 | 521 | static::$user_timezone |
522 | 522 | ); |
523 | - if($date) break; |
|
523 | + if ($date) break; |
|
524 | 524 | } catch (\Exception $e) { |
525 | 525 | |
526 | 526 | } |
@@ -537,12 +537,12 @@ discard block |
||
537 | 537 | * @param string|int $timeformat ='' integer 12, 24, or format string eg. 'H:i' |
538 | 538 | * @return DateTimeZone |
539 | 539 | */ |
540 | - public static function setUserPrefs($tz,$dateformat='',$timeformat='') |
|
540 | + public static function setUserPrefs($tz, $dateformat = '', $timeformat = '') |
|
541 | 541 | { |
542 | 542 | //echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n"; |
543 | 543 | if (!empty($dateformat)) self::$user_dateformat = $dateformat; |
544 | 544 | |
545 | - switch($timeformat) |
|
545 | + switch ($timeformat) |
|
546 | 546 | { |
547 | 547 | case '': |
548 | 548 | break; |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | try { |
560 | 560 | self::$user_timezone = new DateTimeZone($tz); |
561 | 561 | } |
562 | - catch(\Exception $e) |
|
562 | + catch (\Exception $e) |
|
563 | 563 | { |
564 | 564 | unset($e); |
565 | 565 | // silently use server timezone, as we have no means to report the wrong timezone to the user from this class |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | * @param int|string|DateTime $time ='now' |
577 | 577 | * @return int difference in seconds between user and server time (for the given time!) |
578 | 578 | */ |
579 | - public static function tz_offset_s($time='now') |
|
579 | + public static function tz_offset_s($time = 'now') |
|
580 | 580 | { |
581 | 581 | if (!($time instanceof DateTime)) $time = new DateTime($time); |
582 | 582 | |
@@ -597,17 +597,17 @@ discard block |
||
597 | 597 | try { |
598 | 598 | self::$server_timezone = new DateTimeZone($GLOBALS['egw_info']['server']['server_timezone']); |
599 | 599 | } |
600 | - catch(\Exception $e) |
|
600 | + catch (\Exception $e) |
|
601 | 601 | { |
602 | 602 | try { |
603 | 603 | self::$server_timezone = new DateTimeZone(date_default_timezone_get()); |
604 | 604 | } |
605 | - catch(\Exception $e) |
|
605 | + catch (\Exception $e) |
|
606 | 606 | { |
607 | 607 | self::$server_timezone = new DateTimeZone('Europe/Berlin'); |
608 | 608 | } |
609 | 609 | error_log(__METHOD__."() invalid server_timezone='{$GLOBALS['egw_info']['server']['server_timezone']}' setting now '".self::$server_timezone->getName()."'!"); |
610 | - Config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(),'phpgwapi'); |
|
610 | + Config::save_value('server_timezone', $GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(), 'phpgwapi'); |
|
611 | 611 | } |
612 | 612 | if (!isset($GLOBALS['egw_info']['user']['preferences']['common']['tz'])) |
613 | 613 | { |
@@ -630,15 +630,15 @@ discard block |
||
630 | 630 | { |
631 | 631 | // prepare list of timezones from php, ignoring depricated ones and sort as follows |
632 | 632 | $tzs = array( |
633 | - 'Africa' => array(), // Contients |
|
633 | + 'Africa' => array(), // Contients |
|
634 | 634 | 'America' => array(), |
635 | 635 | 'Asia' => array(), |
636 | 636 | 'Australia' => array(), |
637 | 637 | 'Europe' => array(), |
638 | - 'Atlantic' => array(), // Oceans |
|
638 | + 'Atlantic' => array(), // Oceans |
|
639 | 639 | 'Pacific' => array(), |
640 | 640 | 'Indian' => array(), |
641 | - 'Antarctica' => array(), // Poles |
|
641 | + 'Antarctica' => array(), // Poles |
|
642 | 642 | 'Arctic' => array(), |
643 | 643 | 'UTC' => array('UTC' => 'UTC'), |
644 | 644 | ); |
@@ -684,27 +684,27 @@ discard block |
||
684 | 684 | 'Australia/Yancowinna', |
685 | 685 | 'Pacific/Samoa', |
686 | 686 | ); |
687 | - foreach(DateTimeZone::listIdentifiers() as $name) |
|
687 | + foreach (DateTimeZone::listIdentifiers() as $name) |
|
688 | 688 | { |
689 | - if (in_array($name,$no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
690 | - list($continent) = explode('/',$name,2); |
|
691 | - if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
692 | - $datetime = new DateTime('now',new DateTimeZone($name)); |
|
693 | - $tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)." ".$datetime->format(); |
|
689 | + if (in_array($name, $no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
690 | + list($continent) = explode('/', $name, 2); |
|
691 | + if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
692 | + $datetime = new DateTime('now', new DateTimeZone($name)); |
|
693 | + $tzs[$continent][$name] = str_replace(array('_', '/'), array(' ', ' / '), $name)." ".$datetime->format(); |
|
694 | 694 | unset($datetime); |
695 | 695 | } |
696 | - foreach($tzs as $continent => &$data) |
|
696 | + foreach ($tzs as $continent => &$data) |
|
697 | 697 | { |
698 | - natcasesort($data); // sort cities |
|
698 | + natcasesort($data); // sort cities |
|
699 | 699 | } |
700 | 700 | unset($data); |
701 | 701 | |
702 | 702 | // if user lang or installed langs contain a european language --> move Europe to top of tz list |
703 | 703 | $langs = class_exists('EGroupware\\Api\\Translation') ? Translation::get_installed_langs() : array(); |
704 | - if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang'])+array_keys($langs), |
|
705 | - 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'))) |
|
704 | + if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang']) + array_keys($langs), |
|
705 | + 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'))) |
|
706 | 706 | { |
707 | - $tzs = array_merge(array('Europe' => $tzs['Europe']),$tzs); |
|
707 | + $tzs = array_merge(array('Europe' => $tzs['Europe']), $tzs); |
|
708 | 708 | } |
709 | 709 | return $tzs; |
710 | 710 | } |
@@ -715,30 +715,30 @@ discard block |
||
715 | 715 | * @param string $extra extra timezone to add, if not already included in user timezones |
716 | 716 | * @return array tzid => label |
717 | 717 | */ |
718 | - public static function getUserTimezones($extra=null) |
|
718 | + public static function getUserTimezones($extra = null) |
|
719 | 719 | { |
720 | 720 | $tz = $GLOBALS['egw_info']['user']['preferences']['common']['tz']; |
721 | - $user_tzs = explode(',',$GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']); |
|
721 | + $user_tzs = explode(',', $GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']); |
|
722 | 722 | if (count($user_tzs) <= 1) |
723 | 723 | { |
724 | 724 | $user_tzs = $tz ? array($tz) : array(); |
725 | 725 | } |
726 | - if ($tz && !in_array($tz,$user_tzs)) |
|
726 | + if ($tz && !in_array($tz, $user_tzs)) |
|
727 | 727 | { |
728 | - $user_tzs = array_merge(array($tz),$user_tzs); |
|
728 | + $user_tzs = array_merge(array($tz), $user_tzs); |
|
729 | 729 | } |
730 | 730 | if (!$user_tzs) // if we have no user timezones, eg. user set no pref --> use server default |
731 | 731 | { |
732 | 732 | $user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']); |
733 | 733 | } |
734 | - if ($extra && !in_array($extra,$user_tzs)) |
|
734 | + if ($extra && !in_array($extra, $user_tzs)) |
|
735 | 735 | { |
736 | - $user_tzs = array_merge(array($extra),$user_tzs); |
|
736 | + $user_tzs = array_merge(array($extra), $user_tzs); |
|
737 | 737 | } |
738 | - $ret_user_tzs = array_combine($user_tzs,$user_tzs); |
|
739 | - foreach($ret_user_tzs as &$label) |
|
738 | + $ret_user_tzs = array_combine($user_tzs, $user_tzs); |
|
739 | + foreach ($ret_user_tzs as &$label) |
|
740 | 740 | { |
741 | - $label = str_replace(array('_','/'),array(' ',' / '),$label); |
|
741 | + $label = str_replace(array('_', '/'), array(' ', ' / '), $label); |
|
742 | 742 | } |
743 | 743 | return $ret_user_tzs; |
744 | 744 | } |
@@ -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) |
@@ -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; |
@@ -67,38 +67,38 @@ 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 | /** |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | var $readonly = false; |
108 | 108 | |
109 | 109 | /** |
110 | - * @var int $Debug enable debuging - 0 no, 1 yes |
|
111 | - */ |
|
110 | + * @var int $Debug enable debuging - 0 no, 1 yes |
|
111 | + */ |
|
112 | 112 | var $Debug = 0; |
113 | 113 | |
114 | 114 | /** |
@@ -119,23 +119,23 @@ discard block |
||
119 | 119 | var $log_updates = false; |
120 | 120 | |
121 | 121 | /** |
122 | - * @var array $Record current record |
|
123 | - */ |
|
122 | + * @var array $Record current record |
|
123 | + */ |
|
124 | 124 | var $Record = array(); |
125 | 125 | |
126 | 126 | /** |
127 | - * @var int row number for current record |
|
128 | - */ |
|
127 | + * @var int row number for current record |
|
128 | + */ |
|
129 | 129 | var $Row; |
130 | 130 | |
131 | 131 | /** |
132 | - * @var int $Errno internal rdms error number for last error |
|
133 | - */ |
|
132 | + * @var int $Errno internal rdms error number for last error |
|
133 | + */ |
|
134 | 134 | var $Errno = 0; |
135 | 135 | |
136 | 136 | /** |
137 | - * @var string descriptive text from last error |
|
138 | - */ |
|
137 | + * @var string descriptive text from last error |
|
138 | + */ |
|
139 | 139 | var $Error = ''; |
140 | 140 | |
141 | 141 | /** |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | - * @param string $query query to be executed (optional) |
|
280 | - */ |
|
279 | + * @param string $query query to be executed (optional) |
|
280 | + */ |
|
281 | 281 | |
282 | 282 | function db($query = '') |
283 | 283 | { |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | - * @return int current connection id |
|
289 | - */ |
|
288 | + * @return int current connection id |
|
289 | + */ |
|
290 | 290 | function link_id() |
291 | 291 | { |
292 | 292 | return $this->Link_ID; |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
666 | - * Close a connection to a database |
|
667 | - */ |
|
666 | + * Close a connection to a database |
|
667 | + */ |
|
668 | 668 | function disconnect() |
669 | 669 | { |
670 | 670 | if (!$this->privat_Link_ID) |
@@ -678,11 +678,11 @@ discard block |
||
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
681 | - * Convert a unix timestamp to a rdms specific timestamp |
|
682 | - * |
|
683 | - * @param int unix timestamp |
|
684 | - * @return string rdms specific timestamp |
|
685 | - */ |
|
681 | + * Convert a unix timestamp to a rdms specific timestamp |
|
682 | + * |
|
683 | + * @param int unix timestamp |
|
684 | + * @return string rdms specific timestamp |
|
685 | + */ |
|
686 | 686 | function to_timestamp($epoch) |
687 | 687 | { |
688 | 688 | if (!$this->Link_ID && !$this->connect()) |
@@ -694,11 +694,11 @@ discard block |
||
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
697 | - * Convert a rdms specific timestamp to a unix timestamp |
|
698 | - * |
|
699 | - * @param string rdms specific timestamp |
|
700 | - * @return int unix timestamp |
|
701 | - */ |
|
697 | + * Convert a rdms specific timestamp to a unix timestamp |
|
698 | + * |
|
699 | + * @param string rdms specific timestamp |
|
700 | + * @return int unix timestamp |
|
701 | + */ |
|
702 | 702 | function from_timestamp($timestamp) |
703 | 703 | { |
704 | 704 | if (!$this->Link_ID && !$this->connect()) |
@@ -720,19 +720,19 @@ discard block |
||
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
723 | - * Execute a query |
|
724 | - * |
|
725 | - * @param string $Query_String the query to be executed |
|
726 | - * @param int $line the line method was called from - use __LINE__ |
|
727 | - * @param string $file the file method was called from - use __FILE__ |
|
728 | - * @param int $offset row to start from, default 0 |
|
729 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
730 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
731 | - * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
732 | - * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
733 | - * @return ADORecordSet or false, if the query fails |
|
734 | - * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
735 | - */ |
|
723 | + * Execute a query |
|
724 | + * |
|
725 | + * @param string $Query_String the query to be executed |
|
726 | + * @param int $line the line method was called from - use __LINE__ |
|
727 | + * @param string $file the file method was called from - use __FILE__ |
|
728 | + * @param int $offset row to start from, default 0 |
|
729 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
730 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
731 | + * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
732 | + * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
733 | + * @return ADORecordSet or false, if the query fails |
|
734 | + * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
735 | + */ |
|
736 | 736 | function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
737 | 737 | { |
738 | 738 | unset($line, $file); // not used anymore |
@@ -797,26 +797,26 @@ discard block |
||
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
800 | - * Execute a query with limited result set |
|
801 | - * |
|
802 | - * @param string $Query_String the query to be executed |
|
803 | - * @param int $offset row to start from, default 0 |
|
804 | - * @param int $line the line method was called from - use __LINE__ |
|
805 | - * @param string $file the file method was called from - use __FILE__ |
|
806 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
807 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
808 | - * @return ADORecordSet or false, if the query fails |
|
809 | - */ |
|
800 | + * Execute a query with limited result set |
|
801 | + * |
|
802 | + * @param string $Query_String the query to be executed |
|
803 | + * @param int $offset row to start from, default 0 |
|
804 | + * @param int $line the line method was called from - use __LINE__ |
|
805 | + * @param string $file the file method was called from - use __FILE__ |
|
806 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
807 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
808 | + * @return ADORecordSet or false, if the query fails |
|
809 | + */ |
|
810 | 810 | function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
811 | 811 | { |
812 | 812 | return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | - * Begin Transaction |
|
817 | - * |
|
818 | - * @return int/boolean current transaction-id, of false if no connection |
|
819 | - */ |
|
816 | + * Begin Transaction |
|
817 | + * |
|
818 | + * @return int/boolean current transaction-id, of false if no connection |
|
819 | + */ |
|
820 | 820 | function transaction_begin() |
821 | 821 | { |
822 | 822 | if (!$this->Link_ID && !$this->connect()) |
@@ -828,10 +828,10 @@ discard block |
||
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
831 | - * Complete the transaction |
|
832 | - * |
|
833 | - * @return bool True if sucessful, False if fails |
|
834 | - */ |
|
831 | + * Complete the transaction |
|
832 | + * |
|
833 | + * @return bool True if sucessful, False if fails |
|
834 | + */ |
|
835 | 835 | function transaction_commit() |
836 | 836 | { |
837 | 837 | if (!$this->Link_ID && !$this->connect()) |
@@ -843,10 +843,10 @@ discard block |
||
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Rollback the current transaction |
|
847 | - * |
|
848 | - * @return bool True if sucessful, False if fails |
|
849 | - */ |
|
846 | + * Rollback the current transaction |
|
847 | + * |
|
848 | + * @return bool True if sucessful, False if fails |
|
849 | + */ |
|
850 | 850 | function transaction_abort() |
851 | 851 | { |
852 | 852 | if (!$this->Link_ID && !$this->connect()) |
@@ -922,12 +922,12 @@ discard block |
||
922 | 922 | } |
923 | 923 | |
924 | 924 | /** |
925 | - * Find the primary key of the last insertion on the current db connection |
|
926 | - * |
|
927 | - * @param string $table name of table the insert was performed on |
|
928 | - * @param string $field the autoincrement primary key of the table |
|
929 | - * @return int the id, -1 if fails |
|
930 | - */ |
|
925 | + * Find the primary key of the last insertion on the current db connection |
|
926 | + * |
|
927 | + * @param string $table name of table the insert was performed on |
|
928 | + * @param string $field the autoincrement primary key of the table |
|
929 | + * @return int the id, -1 if fails |
|
930 | + */ |
|
931 | 931 | function get_last_insert_id($table, $field) |
932 | 932 | { |
933 | 933 | if (!$this->Link_ID && !$this->connect()) |
@@ -950,10 +950,10 @@ discard block |
||
950 | 950 | } |
951 | 951 | |
952 | 952 | /** |
953 | - * Get the number of rows affected by last update or delete |
|
954 | - * |
|
955 | - * @return int number of rows |
|
956 | - */ |
|
953 | + * Get the number of rows affected by last update or delete |
|
954 | + * |
|
955 | + * @return int number of rows |
|
956 | + */ |
|
957 | 957 | function affected_rows() |
958 | 958 | { |
959 | 959 | if ($this->log_updates) return 0; |
@@ -966,14 +966,14 @@ discard block |
||
966 | 966 | } |
967 | 967 | |
968 | 968 | /** |
969 | - * Get description of a table |
|
970 | - * |
|
971 | - * Beside the column-name all other data depends on the db-type !!! |
|
972 | - * |
|
973 | - * @param string $table name of table to describe |
|
974 | - * @param bool $full optional, default False summary information, True full information |
|
975 | - * @return array table meta data |
|
976 | - */ |
|
969 | + * Get description of a table |
|
970 | + * |
|
971 | + * Beside the column-name all other data depends on the db-type !!! |
|
972 | + * |
|
973 | + * @param string $table name of table to describe |
|
974 | + * @param bool $full optional, default False summary information, True full information |
|
975 | + * @return array table meta data |
|
976 | + */ |
|
977 | 977 | function metadata($table='',$full=false) |
978 | 978 | { |
979 | 979 | if (!$this->Link_ID && !$this->connect()) |
@@ -1055,10 +1055,10 @@ discard block |
||
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | /** |
1058 | - * Return a list of indexes in current database |
|
1059 | - * |
|
1060 | - * @return array list of indexes |
|
1061 | - */ |
|
1058 | + * Return a list of indexes in current database |
|
1059 | + * |
|
1060 | + * @return array list of indexes |
|
1061 | + */ |
|
1062 | 1062 | function index_names() |
1063 | 1063 | { |
1064 | 1064 | $indices = array(); |
@@ -1079,10 +1079,10 @@ discard block |
||
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
1082 | - * Returns an array containing column names that are the primary keys of $tablename. |
|
1083 | - * |
|
1084 | - * @return array of columns |
|
1085 | - */ |
|
1082 | + * Returns an array containing column names that are the primary keys of $tablename. |
|
1083 | + * |
|
1084 | + * @return array of columns |
|
1085 | + */ |
|
1086 | 1086 | function pkey_columns($tablename) |
1087 | 1087 | { |
1088 | 1088 | if (!$this->Link_ID && !$this->connect()) |
@@ -1093,13 +1093,13 @@ discard block |
||
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
1096 | - * Create a new database |
|
1097 | - * |
|
1098 | - * @param string $adminname name of database administrator user (optional) |
|
1099 | - * @param string $adminpasswd password for the database administrator user (optional) |
|
1100 | - * @param string $charset default charset for the database |
|
1101 | - * @param string $grant_host ='localhost' host/ip of the webserver |
|
1102 | - */ |
|
1096 | + * Create a new database |
|
1097 | + * |
|
1098 | + * @param string $adminname name of database administrator user (optional) |
|
1099 | + * @param string $adminpasswd password for the database administrator user (optional) |
|
1100 | + * @param string $charset default charset for the database |
|
1101 | + * @param string $grant_host ='localhost' host/ip of the webserver |
|
1102 | + */ |
|
1103 | 1103 | function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
1104 | 1104 | { |
1105 | 1105 | $currentUser = $this->User; |
@@ -1356,12 +1356,12 @@ discard block |
||
1356 | 1356 | } |
1357 | 1357 | |
1358 | 1358 | /** |
1359 | - * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
1360 | - * |
|
1361 | - * This is mostly copy & paste from adodb's datadict class |
|
1362 | - * @param string $_name |
|
1363 | - * @return string quoted string |
|
1364 | - */ |
|
1359 | + * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
1360 | + * |
|
1361 | + * This is mostly copy & paste from adodb's datadict class |
|
1362 | + * @param string $_name |
|
1363 | + * @return string quoted string |
|
1364 | + */ |
|
1365 | 1365 | function name_quote($_name = NULL) |
1366 | 1366 | { |
1367 | 1367 | if (!is_string($_name)) |
@@ -1400,19 +1400,19 @@ discard block |
||
1400 | 1400 | } |
1401 | 1401 | |
1402 | 1402 | /** |
1403 | - * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
1404 | - * |
|
1405 | - * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
1406 | - * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
1407 | - * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
1408 | - * |
|
1409 | - * @param mixed $value the value to be escaped |
|
1410 | - * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
1411 | - * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
1412 | - * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
1413 | - * @param string $glue =',' used to glue array values together for the string type |
|
1414 | - * @return string escaped sting |
|
1415 | - */ |
|
1403 | + * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
1404 | + * |
|
1405 | + * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
1406 | + * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
1407 | + * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
1408 | + * |
|
1409 | + * @param mixed $value the value to be escaped |
|
1410 | + * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
1411 | + * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
1412 | + * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
1413 | + * @param string $glue =',' used to glue array values together for the string type |
|
1414 | + * @return string escaped sting |
|
1415 | + */ |
|
1416 | 1416 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
1417 | 1417 | { |
1418 | 1418 | if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
@@ -1493,27 +1493,27 @@ discard block |
||
1493 | 1493 | } |
1494 | 1494 | |
1495 | 1495 | /** |
1496 | - * Implodes an array of column-value pairs for the use in sql-querys. |
|
1497 | - * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
1498 | - * |
|
1499 | - * @author RalfBecker<at>outdoor-training.de |
|
1500 | - * |
|
1501 | - * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
1502 | - * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
1503 | - * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
1504 | - * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
1505 | - * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
1506 | - * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
1507 | - * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
1508 | - * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
1509 | - * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1510 | - * typicaly used to form a WHERE-clause from the primary keys. |
|
1511 | - * If set to True, only columns from the colum_definitons are written. |
|
1512 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1513 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1514 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1515 | - * @return string SQL |
|
1516 | - */ |
|
1496 | + * Implodes an array of column-value pairs for the use in sql-querys. |
|
1497 | + * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
1498 | + * |
|
1499 | + * @author RalfBecker<at>outdoor-training.de |
|
1500 | + * |
|
1501 | + * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
1502 | + * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
1503 | + * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
1504 | + * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
1505 | + * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
1506 | + * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
1507 | + * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
1508 | + * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
1509 | + * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1510 | + * typicaly used to form a WHERE-clause from the primary keys. |
|
1511 | + * If set to True, only columns from the colum_definitons are written. |
|
1512 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1513 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1514 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1515 | + * @return string SQL |
|
1516 | + */ |
|
1517 | 1517 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
1518 | 1518 | { |
1519 | 1519 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
@@ -1599,14 +1599,14 @@ discard block |
||
1599 | 1599 | } |
1600 | 1600 | |
1601 | 1601 | /** |
1602 | - * Sets the default column-definitions for use with column_data_implode() |
|
1603 | - * |
|
1604 | - * @author RalfBecker<at>outdoor-training.de |
|
1605 | - * |
|
1606 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1607 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1608 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1609 | - */ |
|
1602 | + * Sets the default column-definitions for use with column_data_implode() |
|
1603 | + * |
|
1604 | + * @author RalfBecker<at>outdoor-training.de |
|
1605 | + * |
|
1606 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1607 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1608 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1609 | + */ |
|
1610 | 1610 | function set_column_definitions($column_definitions=False) |
1611 | 1611 | { |
1612 | 1612 | $this->column_definitions=$column_definitions; |
@@ -1668,17 +1668,17 @@ discard block |
||
1668 | 1668 | } |
1669 | 1669 | |
1670 | 1670 | /** |
1671 | - * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
1672 | - * |
|
1673 | - * The already read table-definitions are shared between all db-instances via a static var. |
|
1674 | - * |
|
1675 | - * @author RalfBecker<at>outdoor-training.de |
|
1676 | - * |
|
1677 | - * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
1678 | - * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
1679 | - * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
1680 | - * @return mixed array with table-defintions or False if file not found |
|
1681 | - */ |
|
1671 | + * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
1672 | + * |
|
1673 | + * The already read table-definitions are shared between all db-instances via a static var. |
|
1674 | + * |
|
1675 | + * @author RalfBecker<at>outdoor-training.de |
|
1676 | + * |
|
1677 | + * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
1678 | + * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
1679 | + * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
1680 | + * @return mixed array with table-defintions or False if file not found |
|
1681 | + */ |
|
1682 | 1682 | function get_table_definitions($app=False,$table=False) |
1683 | 1683 | { |
1684 | 1684 | // ease the transition to api |
@@ -1773,21 +1773,21 @@ discard block |
||
1773 | 1773 | } |
1774 | 1774 | |
1775 | 1775 | /** |
1776 | - * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
1777 | - * |
|
1778 | - * @author RalfBecker<at>outdoor-training.de |
|
1779 | - * |
|
1780 | - * @param string $table name of the table |
|
1781 | - * @param array $data with column-name / value pairs |
|
1782 | - * @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 |
|
1783 | - * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
1784 | - * @param int $line line-number to pass to query |
|
1785 | - * @param string $file file-name to pass to query |
|
1786 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1787 | - * @param bool $use_prepared_statement use a prepared statement |
|
1788 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1789 | - * @return ADORecordSet or false, if the query fails |
|
1790 | - */ |
|
1776 | + * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
1777 | + * |
|
1778 | + * @author RalfBecker<at>outdoor-training.de |
|
1779 | + * |
|
1780 | + * @param string $table name of the table |
|
1781 | + * @param array $data with column-name / value pairs |
|
1782 | + * @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 |
|
1783 | + * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
1784 | + * @param int $line line-number to pass to query |
|
1785 | + * @param string $file file-name to pass to query |
|
1786 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1787 | + * @param bool $use_prepared_statement use a prepared statement |
|
1788 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1789 | + * @return ADORecordSet or false, if the query fails |
|
1790 | + */ |
|
1791 | 1791 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1792 | 1792 | { |
1793 | 1793 | if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
@@ -1883,20 +1883,20 @@ discard block |
||
1883 | 1883 | } |
1884 | 1884 | |
1885 | 1885 | /** |
1886 | - * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
1887 | - * |
|
1888 | - * @author RalfBecker<at>outdoor-training.de |
|
1889 | - * |
|
1890 | - * @param string $table name of the table |
|
1891 | - * @param array $data with column-name / value pairs |
|
1892 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
1893 | - * @param int $line line-number to pass to query |
|
1894 | - * @param string $file file-name to pass to query |
|
1895 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1896 | - * @param bool $use_prepared_statement use a prepared statement |
|
1897 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1898 | - * @return ADORecordSet or false, if the query fails |
|
1899 | - */ |
|
1886 | + * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
1887 | + * |
|
1888 | + * @author RalfBecker<at>outdoor-training.de |
|
1889 | + * |
|
1890 | + * @param string $table name of the table |
|
1891 | + * @param array $data with column-name / value pairs |
|
1892 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
1893 | + * @param int $line line-number to pass to query |
|
1894 | + * @param string $file file-name to pass to query |
|
1895 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1896 | + * @param bool $use_prepared_statement use a prepared statement |
|
1897 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1898 | + * @return ADORecordSet or false, if the query fails |
|
1899 | + */ |
|
1900 | 1900 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1901 | 1901 | { |
1902 | 1902 | if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
@@ -1973,18 +1973,18 @@ discard block |
||
1973 | 1973 | } |
1974 | 1974 | |
1975 | 1975 | /** |
1976 | - * Deletes one or more rows in table, all data is quoted according to it's type |
|
1977 | - * |
|
1978 | - * @author RalfBecker<at>outdoor-training.de |
|
1979 | - * |
|
1980 | - * @param string $table name of the table |
|
1981 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
1982 | - * @param int $line line-number to pass to query |
|
1983 | - * @param string $file file-name to pass to query |
|
1984 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1985 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1986 | - * @return ADORecordSet or false, if the query fails |
|
1987 | - */ |
|
1976 | + * Deletes one or more rows in table, all data is quoted according to it's type |
|
1977 | + * |
|
1978 | + * @author RalfBecker<at>outdoor-training.de |
|
1979 | + * |
|
1980 | + * @param string $table name of the table |
|
1981 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
1982 | + * @param int $line line-number to pass to query |
|
1983 | + * @param string $file file-name to pass to query |
|
1984 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1985 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1986 | + * @return ADORecordSet or false, if the query fails |
|
1987 | + */ |
|
1988 | 1988 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
1989 | 1989 | { |
1990 | 1990 | if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
@@ -2050,25 +2050,25 @@ discard block |
||
2050 | 2050 | } |
2051 | 2051 | |
2052 | 2052 | /** |
2053 | - * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
2054 | - * |
|
2055 | - * @author RalfBecker<at>outdoor-training.de |
|
2056 | - * |
|
2057 | - * @param string $table name of the table |
|
2058 | - * @param array|string $cols string or array of column-names / select-expressions |
|
2059 | - * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
2060 | - * @param int $line line-number to pass to query |
|
2061 | - * @param string $file file-name to pass to query |
|
2062 | - * @param int|bool $offset offset for a limited query or False (default) |
|
2063 | - * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
2064 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
2065 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2066 | - * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
2067 | - * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
2068 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
2069 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2070 | - * @return ADORecordSet or false, if the query fails |
|
2071 | - */ |
|
2053 | + * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
2054 | + * |
|
2055 | + * @author RalfBecker<at>outdoor-training.de |
|
2056 | + * |
|
2057 | + * @param string $table name of the table |
|
2058 | + * @param array|string $cols string or array of column-names / select-expressions |
|
2059 | + * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
2060 | + * @param int $line line-number to pass to query |
|
2061 | + * @param string $file file-name to pass to query |
|
2062 | + * @param int|bool $offset offset for a limited query or False (default) |
|
2063 | + * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
2064 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
2065 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2066 | + * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
2067 | + * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
2068 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
2069 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2070 | + * @return ADORecordSet or false, if the query fails |
|
2071 | + */ |
|
2072 | 2072 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
2073 | 2073 | { |
2074 | 2074 | 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"; |
@@ -2103,20 +2103,20 @@ discard block |
||
2103 | 2103 | } |
2104 | 2104 | |
2105 | 2105 | /** |
2106 | - * Does a union over multiple selects |
|
2107 | - * |
|
2108 | - * @author RalfBecker<at>outdoor-training.de |
|
2109 | - * |
|
2110 | - * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
2111 | - * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
2112 | - * @param int $line line-number to pass to query |
|
2113 | - * @param string $file file-name to pass to query |
|
2114 | - * @param string $order_by ORDER BY statement for the union |
|
2115 | - * @param int|bool $offset offset for a limited query or False (default) |
|
2116 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2117 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2118 | - * @return ADORecordSet or false, if the query fails |
|
2119 | - */ |
|
2106 | + * Does a union over multiple selects |
|
2107 | + * |
|
2108 | + * @author RalfBecker<at>outdoor-training.de |
|
2109 | + * |
|
2110 | + * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
2111 | + * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
2112 | + * @param int $line line-number to pass to query |
|
2113 | + * @param string $file file-name to pass to query |
|
2114 | + * @param string $order_by ORDER BY statement for the union |
|
2115 | + * @param int|bool $offset offset for a limited query or False (default) |
|
2116 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2117 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2118 | + * @return ADORecordSet or false, if the query fails |
|
2119 | + */ |
|
2120 | 2120 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
2121 | 2121 | { |
2122 | 2122 | if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
@@ -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 |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * @var int $Debug enable debuging - 0 no, 1 yes |
111 | 111 | */ |
112 | - var $Debug = 0; |
|
112 | + var $Debug = 0; |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Log update querys to error_log |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | /** |
122 | 122 | * @var array $Record current record |
123 | 123 | */ |
124 | - var $Record = array(); |
|
124 | + var $Record = array(); |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * @var int row number for current record |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | /** |
132 | 132 | * @var int $Errno internal rdms error number for last error |
133 | 133 | */ |
134 | - var $Errno = 0; |
|
134 | + var $Errno = 0; |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * @var string descriptive text from last error |
138 | 138 | */ |
139 | - var $Error = ''; |
|
139 | + var $Error = ''; |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * eGW's own query log, independent of the db-type, eg. /tmp/query.log |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @var ADOConnection |
158 | 158 | */ |
159 | - var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
159 | + var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Can be used to transparently convert tablenames, eg. 'mytable' => 'otherdb.othertable' |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | /** |
193 | 193 | * db is able to use DISTINCT on text or blob columns |
194 | 194 | */ |
195 | - const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
195 | + const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
196 | 196 | /** |
197 | 197 | * DB is able to use LIKE on text columns |
198 | 198 | */ |
199 | - const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
199 | + const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
200 | 200 | /** |
201 | 201 | * DB allows ORDER on text columns |
202 | 202 | * |
@@ -248,18 +248,18 @@ discard block |
||
248 | 248 | self::CAPABILITY_CAST_AS_VARCHAR => 'CAST(%s AS varchar)', |
249 | 249 | ); |
250 | 250 | |
251 | - var $prepared_sql = array(); // sql is the index |
|
251 | + var $prepared_sql = array(); // sql is the index |
|
252 | 252 | |
253 | 253 | /** |
254 | 254 | * Constructor |
255 | 255 | * |
256 | 256 | * @param array $db_data =null values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type', 'db_readonly' |
257 | 257 | */ |
258 | - function __construct(array $db_data=null) |
|
258 | + function __construct(array $db_data = null) |
|
259 | 259 | { |
260 | 260 | if (!is_null($db_data)) |
261 | 261 | { |
262 | - foreach(array( |
|
262 | + foreach (array( |
|
263 | 263 | 'Database' => 'db_name', |
264 | 264 | 'Host' => 'db_host', |
265 | 265 | 'Port' => 'db_port', |
@@ -313,15 +313,15 @@ discard block |
||
313 | 313 | } |
314 | 314 | if (!is_null($Host) && $Host) |
315 | 315 | { |
316 | - $this->Host = $Host; |
|
316 | + $this->Host = $Host; |
|
317 | 317 | } |
318 | 318 | if (!is_null($Port) && $Port) |
319 | 319 | { |
320 | - $this->Port = $Port; |
|
320 | + $this->Port = $Port; |
|
321 | 321 | } |
322 | 322 | if (!is_null($User) && $User) |
323 | 323 | { |
324 | - $this->User = $User; |
|
324 | + $this->User = $User; |
|
325 | 325 | } |
326 | 326 | if (!is_null($Password) && $Password) |
327 | 327 | { |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | // on connection failure re-try with an other host |
339 | 339 | // remembering in session which host we used last time |
340 | 340 | $use_host_from_session = true; |
341 | - while(($host = $this->get_host(!$use_host_from_session))) |
|
341 | + while (($host = $this->get_host(!$use_host_from_session))) |
|
342 | 342 | { |
343 | 343 | try { |
344 | 344 | //error_log(__METHOD__."() this->Host(s)=$this->Host, n=$n --> host=$host"); |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | //error_log(__METHOD__."() host=$host, new_connection=$new_connection, this->Type=$this->Type, this->Host=$this->Host, wsrep_local_state=".array2string($state)); |
353 | 353 | return $this->Link_ID; |
354 | 354 | } |
355 | - catch(Db\Exception\Connection $e) { |
|
355 | + catch (Db\Exception\Connection $e) { |
|
356 | 356 | //_egw_log_exception($e); |
357 | - $this->disconnect(); // force a new connect |
|
358 | - $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
359 | - $use_host_from_session = false; // re-try with next host from list |
|
357 | + $this->disconnect(); // force a new connect |
|
358 | + $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
359 | + $use_host_from_session = false; // re-try with next host from list |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | if (!isset($e)) |
@@ -407,12 +407,12 @@ discard block |
||
407 | 407 | { |
408 | 408 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
409 | 409 | $num_hosts = count($hosts); |
410 | - $n =& Cache::getSession(__CLASS__, $this->Host); |
|
410 | + $n = & Cache::getSession(__CLASS__, $this->Host); |
|
411 | 411 | if (!isset($n)) $n = 0; |
412 | 412 | |
413 | - if ($next && ++$n >= $num_hosts+2) |
|
413 | + if ($next && ++$n >= $num_hosts + 2) |
|
414 | 414 | { |
415 | - $n = 0; // start search again with default on next request |
|
415 | + $n = 0; // start search again with default on next request |
|
416 | 416 | $ret = false; |
417 | 417 | } |
418 | 418 | else |
@@ -435,21 +435,21 @@ discard block |
||
435 | 435 | if (!$this->Link_ID) |
436 | 436 | { |
437 | 437 | $Database = $User = $Password = $Port = $Type = ''; |
438 | - foreach(array('Database','User','Password','Port','Type') as $name) |
|
438 | + foreach (array('Database', 'User', 'Password', 'Port', 'Type') as $name) |
|
439 | 439 | { |
440 | 440 | $$name = $this->$name; |
441 | 441 | if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
442 | 442 | } |
443 | 443 | $this->setupType = $php_extension = $Type; |
444 | 444 | |
445 | - switch($Type) // convert to ADO db-type-names |
|
445 | + switch ($Type) // convert to ADO db-type-names |
|
446 | 446 | { |
447 | 447 | case 'pgsql': |
448 | 448 | $Type = 'postgres'; // name in ADOdb |
449 | 449 | // create our own pgsql connection-string, to allow unix domain soccets if !$Host |
450 | 450 | $Host = "dbname=$Database".($Host ? " host=$Host".($Port ? " port=$Port" : '') : ''). |
451 | 451 | " user=$User".($Password ? " password='".addslashes($Password)."'" : ''); |
452 | - $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
452 | + $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
453 | 453 | break; |
454 | 454 | |
455 | 455 | case 'odbc_mssql': |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $Type = 'maxdb'; |
473 | 473 | // fall through |
474 | 474 | case 'maxdb': |
475 | - $Type ='sapdb'; // name in ADOdb |
|
475 | + $Type = 'sapdb'; // name in ADOdb |
|
476 | 476 | $php_extension = 'odbc'; |
477 | 477 | break; |
478 | 478 | |
@@ -485,18 +485,18 @@ discard block |
||
485 | 485 | } |
486 | 486 | else |
487 | 487 | { |
488 | - $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
488 | + $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
489 | 489 | } |
490 | 490 | // fall through |
491 | 491 | case 'mysqli': |
492 | - $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
492 | + $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
493 | 493 | // fall through |
494 | 494 | default: |
495 | 495 | if ($Port) $Host .= ':'.$Port; |
496 | 496 | break; |
497 | 497 | } |
498 | - if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
499 | - (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
498 | + if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
499 | + (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
500 | 500 | ($this->Type != $GLOBALS['egw']->db->Type || |
501 | 501 | $this->Database != $GLOBALS['egw']->db->Database || |
502 | 502 | $this->User != $GLOBALS['egw']->db->User || |
@@ -509,11 +509,11 @@ discard block |
||
509 | 509 | } |
510 | 510 | if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
511 | 511 | { |
512 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
512 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
513 | 513 | } |
514 | 514 | else |
515 | 515 | { |
516 | - $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
516 | + $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
517 | 517 | } |
518 | 518 | $this->Link_ID = ADONewConnection($Type); |
519 | 519 | if (!$this->Link_ID) |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database))) |
530 | 530 | { |
531 | 531 | $this->ServerInfo = $this->Link_ID->ServerInfo(); |
532 | - $this->set_capabilities($Type,$this->ServerInfo['version']); |
|
532 | + $this->set_capabilities($Type, $this->ServerInfo['version']); |
|
533 | 533 | |
534 | 534 | // switch off MySQL 5.7+ ONLY_FULL_GROUP_BY sql_mode |
535 | 535 | if (substr($this->Type, 0, 5) == 'mysql' && $this->ServerInfo['version'] >= 5.7 && $this->ServerInfo['version'] < 10.0) |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | } |
540 | 540 | if (!$Ok) |
541 | 541 | { |
542 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
542 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
543 | 543 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); |
544 | 544 | } |
545 | 545 | if ($this->Debug) |
@@ -555,8 +555,8 @@ discard block |
||
555 | 555 | // this is the format ADOdb expects |
556 | 556 | $this->Link_ID->Execute('SET DATEFORMAT ymd'); |
557 | 557 | // sets the limit to the maximum |
558 | - ini_set('mssql.textlimit',2147483647); |
|
559 | - ini_set('mssql.sizelimit',2147483647); |
|
558 | + ini_set('mssql.textlimit', 2147483647); |
|
559 | + ini_set('mssql.sizelimit', 2147483647); |
|
560 | 560 | } |
561 | 561 | // set our default charset |
562 | 562 | $this->Link_ID->SetCharSet($this->Type == 'mysql' ? 'utf8' : 'utf-8'); |
@@ -565,12 +565,12 @@ discard block |
||
565 | 565 | } |
566 | 566 | else |
567 | 567 | { |
568 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
568 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | if (!$this->Link_ID->isConnected() && !$this->Link_ID->Connect()) |
572 | 572 | { |
573 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
573 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
574 | 574 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) reconnect failed."); |
575 | 575 | } |
576 | 576 | // fix due to caching and reusing of connection not correctly set $this->Type == 'mysql' |
@@ -581,9 +581,9 @@ discard block |
||
581 | 581 | } |
582 | 582 | if ($new_connection) |
583 | 583 | { |
584 | - foreach(get_included_files() as $file) |
|
584 | + foreach (get_included_files() as $file) |
|
585 | 585 | { |
586 | - if (strpos($file,'adodb') !== false && !in_array($file,(array)$_SESSION['egw_required_files'])) |
|
586 | + if (strpos($file, 'adodb') !== false && !in_array($file, (array)$_SESSION['egw_required_files'])) |
|
587 | 587 | { |
588 | 588 | $_SESSION['egw_required_files'][] = $file; |
589 | 589 | //error_log(__METHOD__."() egw_required_files[] = $file"); |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | */ |
600 | 600 | function __wakeup() |
601 | 601 | { |
602 | - $this->connect(); // we need to re-connect |
|
602 | + $this->connect(); // we need to re-connect |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | */ |
613 | 613 | function __sleep() |
614 | 614 | { |
615 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
615 | + if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
616 | 616 | |
617 | 617 | $vars = get_object_vars($this); |
618 | 618 | unset($vars['Link_ID'], $vars['Query_ID'], $vars['privat_Link_ID']); |
@@ -625,23 +625,23 @@ discard block |
||
625 | 625 | * @param string $adodb_driver mysql, postgres, mssql, sapdb, oci8 |
626 | 626 | * @param string $db_version version-number of connected db-server, as reported by ServerInfo |
627 | 627 | */ |
628 | - function set_capabilities($adodb_driver,$db_version) |
|
628 | + function set_capabilities($adodb_driver, $db_version) |
|
629 | 629 | { |
630 | - switch($adodb_driver) |
|
630 | + switch ($adodb_driver) |
|
631 | 631 | { |
632 | 632 | case 'mysql': |
633 | 633 | case 'mysqlt': |
634 | 634 | case 'mysqli': |
635 | - $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float) $db_version >= 4.1; |
|
636 | - $this->capabilities[self::CAPABILITY_UNION] = (float) $db_version >= 4.0; |
|
635 | + $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float)$db_version >= 4.1; |
|
636 | + $this->capabilities[self::CAPABILITY_UNION] = (float)$db_version >= 4.0; |
|
637 | 637 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'preserv'; |
638 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 4.1; |
|
638 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 4.1; |
|
639 | 639 | $this->capabilities[self::CAPABILITY_CAST_AS_VARCHAR] = 'CAST(%s AS char)'; |
640 | 640 | break; |
641 | 641 | |
642 | 642 | case 'postgres': |
643 | 643 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'lower'; |
644 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 7.4; |
|
644 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 7.4; |
|
645 | 645 | $this->capabilities[self::CAPABILITY_OUTER_JOIN] = true; |
646 | 646 | $this->capabilities[self::CAPABILITY_CASE_INSENSITIV_LIKE] = '::text ILIKE'; |
647 | 647 | $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR] = true; |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | return False; |
691 | 691 | } |
692 | 692 | // the substring is needed as the string is already in quotes |
693 | - return substr($this->Link_ID->DBTimeStamp($epoch),1,-1); |
|
693 | + return substr($this->Link_ID->DBTimeStamp($epoch), 1, -1); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | */ |
717 | 717 | public static function from_bool($val) |
718 | 718 | { |
719 | - return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
719 | + return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -733,9 +733,9 @@ discard block |
||
733 | 733 | * @return ADORecordSet or false, if the query fails |
734 | 734 | * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
735 | 735 | */ |
736 | - function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
|
736 | + function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true) |
|
737 | 737 | { |
738 | - unset($line, $file); // not used anymore |
|
738 | + unset($line, $file); // not used anymore |
|
739 | 739 | |
740 | 740 | if ($Query_String == '') |
741 | 741 | { |
@@ -761,23 +761,23 @@ discard block |
||
761 | 761 | } |
762 | 762 | if ($num_rows > 0) |
763 | 763 | { |
764 | - $rs = $this->Link_ID->SelectLimit($Query_String,$num_rows,(int)$offset,$inputarr); |
|
764 | + $rs = $this->Link_ID->SelectLimit($Query_String, $num_rows, (int)$offset, $inputarr); |
|
765 | 765 | } |
766 | 766 | else |
767 | 767 | { |
768 | - $rs = $this->Link_ID->Execute($Query_String,$inputarr); |
|
768 | + $rs = $this->Link_ID->Execute($Query_String, $inputarr); |
|
769 | 769 | } |
770 | 770 | $this->Row = 0; |
771 | 771 | $this->Errno = $this->Link_ID->ErrorNo(); |
772 | 772 | $this->Error = $this->Link_ID->ErrorMsg(); |
773 | 773 | |
774 | - if ($this->query_log && ($f = @fopen($this->query_log,'a+'))) |
|
774 | + if ($this->query_log && ($f = @fopen($this->query_log, 'a+'))) |
|
775 | 775 | { |
776 | - fwrite($f,'['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
777 | - fwrite($f,date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr,true) : '')."\n"); |
|
776 | + fwrite($f, '['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
777 | + fwrite($f, date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr, true) : '')."\n"); |
|
778 | 778 | if (!$rs) |
779 | 779 | { |
780 | - fwrite($f,"*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
780 | + fwrite($f, "*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
781 | 781 | } |
782 | 782 | fclose($f); |
783 | 783 | } |
@@ -788,11 +788,11 @@ discard block |
||
788 | 788 | $this->disconnect(); |
789 | 789 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
790 | 790 | } |
791 | - throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
|
791 | + throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String) ? $Query_String[0] : $Query_String). |
|
792 | 792 | "\n$this->Error ($this->Errno)". |
793 | - ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
|
793 | + ($inputarr ? "\nParameters: '".implode("','", $inputarr)."'" : ''), $this->Errno); |
|
794 | 794 | } |
795 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
795 | + elseif (empty($rs->sql)) $rs->sql = $Query_String; |
|
796 | 796 | return $rs; |
797 | 797 | } |
798 | 798 | |
@@ -807,9 +807,9 @@ discard block |
||
807 | 807 | * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
808 | 808 | * @return ADORecordSet or false, if the query fails |
809 | 809 | */ |
810 | - function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
|
810 | + function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '', $inputarr = false) |
|
811 | 811 | { |
812 | - return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
|
812 | + return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | * @param string $where ='true' where clause to use, eg: "WHERE row=12". Defaults to lock whole table. |
868 | 868 | * @param string $col ='1 as adodbignore' |
869 | 869 | */ |
870 | - function row_lock($table, $where='true', $col='1 as adodbignore') |
|
870 | + function row_lock($table, $where = 'true', $col = '1 as adodbignore') |
|
871 | 871 | { |
872 | 872 | if (!$this->Link_ID && !$this->connect()) |
873 | 873 | { |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | { |
939 | 939 | $table = self::$tablealiases[$table]; |
940 | 940 | } |
941 | - $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
941 | + $id = $this->Link_ID->PO_Insert_ID($table, $field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
942 | 942 | |
943 | 943 | if ($id === False) // function not supported |
944 | 944 | { |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | * @param bool $full optional, default False summary information, True full information |
975 | 975 | * @return array table meta data |
976 | 976 | */ |
977 | - function metadata($table='',$full=false) |
|
977 | + function metadata($table = '', $full = false) |
|
978 | 978 | { |
979 | 979 | if (!$this->Link_ID && !$this->connect()) |
980 | 980 | { |
@@ -986,13 +986,13 @@ discard block |
||
986 | 986 | |
987 | 987 | $metadata = array(); |
988 | 988 | $i = 0; |
989 | - foreach($columns as $column) |
|
989 | + foreach ($columns as $column) |
|
990 | 990 | { |
991 | 991 | // for backwards compatibilty (depreciated) |
992 | 992 | $flags = null; |
993 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
994 | - if($column->primary_key) $flags .= "primary_key "; |
|
995 | - if($column->binary) $flags .= "binary "; |
|
993 | + if ($column->auto_increment) $flags .= "auto_increment "; |
|
994 | + if ($column->primary_key) $flags .= "primary_key "; |
|
995 | + if ($column->binary) $flags .= "binary "; |
|
996 | 996 | |
997 | 997 | $metadata[$i] = array( |
998 | 998 | 'table' => $table, |
@@ -1027,7 +1027,7 @@ discard block |
||
1027 | 1027 | * @param boolean $just_name =false true return array of table-names, false return old format |
1028 | 1028 | * @return array list of the tables |
1029 | 1029 | */ |
1030 | - function table_names($just_name=false) |
|
1030 | + function table_names($just_name = false) |
|
1031 | 1031 | { |
1032 | 1032 | if (!$this->Link_ID) $this->connect(); |
1033 | 1033 | if (!$this->Link_ID) |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | $tables = $this->Link_ID->MetaTables('TABLES'); |
1039 | 1039 | if (is_array($tables)) |
1040 | 1040 | { |
1041 | - foreach($tables as $table) |
|
1041 | + foreach ($tables as $table) |
|
1042 | 1042 | { |
1043 | 1043 | if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') |
1044 | 1044 | { |
@@ -1067,7 +1067,7 @@ discard block |
||
1067 | 1067 | echo "<p>db::index_names() not yet implemented for db-type '$this->Type'</p>\n"; |
1068 | 1068 | return $indices; |
1069 | 1069 | } |
1070 | - foreach($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
1070 | + foreach ($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
1071 | 1071 | { |
1072 | 1072 | $indices[] = array( |
1073 | 1073 | 'index_name' => $row[0], |
@@ -1100,7 +1100,7 @@ discard block |
||
1100 | 1100 | * @param string $charset default charset for the database |
1101 | 1101 | * @param string $grant_host ='localhost' host/ip of the webserver |
1102 | 1102 | */ |
1103 | - function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
|
1103 | + function create_database($adminname = '', $adminpasswd = '', $charset = '', $grant_host = 'localhost') |
|
1104 | 1104 | { |
1105 | 1105 | $currentUser = $this->User; |
1106 | 1106 | $currentPassword = $this->Password; |
@@ -1124,7 +1124,7 @@ discard block |
||
1124 | 1124 | case 'mysqli': |
1125 | 1125 | case 'mysqlt': |
1126 | 1126 | $create = "CREATE DATABASE `$currentDatabase`"; |
1127 | - if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float) $this->ServerInfo['version'] >= 4.1) |
|
1127 | + if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float)$this->ServerInfo['version'] >= 4.1) |
|
1128 | 1128 | { |
1129 | 1129 | $create .= ' DEFAULT CHARACTER SET '.$this->Link_ID->charset2mysql[$charset].';'; |
1130 | 1130 | } |
@@ -1135,9 +1135,9 @@ discard block |
||
1135 | 1135 | throw new Exception\WrongParameter(__METHOD__."(user=$adminname, \$pw) not yet implemented for DB-type '$this->Type'"); |
1136 | 1136 | } |
1137 | 1137 | //error_log(__METHOD__."() this->Type=$this->Type: sqls=".array2string($sqls)); |
1138 | - foreach($sqls as $sql) |
|
1138 | + foreach ($sqls as $sql) |
|
1139 | 1139 | { |
1140 | - $this->query($sql,__LINE__,__FILE__); |
|
1140 | + $this->query($sql, __LINE__, __FILE__); |
|
1141 | 1141 | } |
1142 | 1142 | $this->disconnect(); |
1143 | 1143 | |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | { |
1164 | 1164 | return False; |
1165 | 1165 | } |
1166 | - return call_user_func_array(array(&$this->Link_ID,'concat'),$args); |
|
1166 | + return call_user_func_array(array(&$this->Link_ID, 'concat'), $args); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | /** |
@@ -1174,9 +1174,9 @@ discard block |
||
1174 | 1174 | * @param string $separator =',' optional separator, default is comma |
1175 | 1175 | * @return string|boolean false if not supported by dbms |
1176 | 1176 | */ |
1177 | - function group_concat($expr, $order_by='', $separator=',') |
|
1177 | + function group_concat($expr, $order_by = '', $separator = ',') |
|
1178 | 1178 | { |
1179 | - switch($this->Type) |
|
1179 | + switch ($this->Type) |
|
1180 | 1180 | { |
1181 | 1181 | case 'mysqli': |
1182 | 1182 | case 'mysql': |
@@ -1211,7 +1211,7 @@ discard block |
||
1211 | 1211 | */ |
1212 | 1212 | function strpos($str, $substr) |
1213 | 1213 | { |
1214 | - switch($this->Type) |
|
1214 | + switch ($this->Type) |
|
1215 | 1215 | { |
1216 | 1216 | case 'mysql': |
1217 | 1217 | return "LOCATE($substr,$str)"; |
@@ -1231,7 +1231,7 @@ discard block |
||
1231 | 1231 | */ |
1232 | 1232 | function unix_timestamp($expr) |
1233 | 1233 | { |
1234 | - switch($this->Type) |
|
1234 | + switch ($this->Type) |
|
1235 | 1235 | { |
1236 | 1236 | case 'mysql': |
1237 | 1237 | return "UNIX_TIMESTAMP($expr)"; |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | */ |
1253 | 1253 | function from_unixtime($expr) |
1254 | 1254 | { |
1255 | - switch($this->Type) |
|
1255 | + switch ($this->Type) |
|
1256 | 1256 | { |
1257 | 1257 | case 'mysql': |
1258 | 1258 | return "FROM_UNIXTIME($expr)"; |
@@ -1261,7 +1261,7 @@ discard block |
||
1261 | 1261 | return "(TIMESTAMP WITH TIME ZONE 'epoch' + ($expr) * INTERVAL '1 sec')"; |
1262 | 1262 | |
1263 | 1263 | case 'mssql': // we use date(,0) as we store server-time |
1264 | - return "DATEADD(second,($expr),'".date('Y-m-d H:i:s',0)."')"; |
|
1264 | + return "DATEADD(second,($expr),'".date('Y-m-d H:i:s', 0)."')"; |
|
1265 | 1265 | } |
1266 | 1266 | return false; |
1267 | 1267 | } |
@@ -1275,30 +1275,30 @@ discard block |
||
1275 | 1275 | * @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 |
1276 | 1276 | * @return string SQL expression of type timestamp |
1277 | 1277 | */ |
1278 | - function date_format($expr,$format) |
|
1278 | + function date_format($expr, $format) |
|
1279 | 1279 | { |
1280 | - switch($this->Type) |
|
1280 | + switch ($this->Type) |
|
1281 | 1281 | { |
1282 | 1282 | case 'mysql': |
1283 | 1283 | return "DATE_FORMAT($expr,'$format')"; |
1284 | 1284 | |
1285 | 1285 | case 'pgsql': |
1286 | 1286 | $format = str_replace( |
1287 | - array('%Y', '%y','%m','%d','%H', '%h','%i','%s','%V','%v','%X', '%x'), |
|
1288 | - array('YYYY','YY','MM','DD','HH24','HH','MI','SS','IW','IW','YYYY','YYYY'), |
|
1287 | + array('%Y', '%y', '%m', '%d', '%H', '%h', '%i', '%s', '%V', '%v', '%X', '%x'), |
|
1288 | + array('YYYY', 'YY', 'MM', 'DD', 'HH24', 'HH', 'MI', 'SS', 'IW', 'IW', 'YYYY', 'YYYY'), |
|
1289 | 1289 | $format); |
1290 | 1290 | return "TO_CHAR($expr,'$format')"; |
1291 | 1291 | |
1292 | 1292 | case 'mssql': |
1293 | 1293 | $from = $to = array(); |
1294 | - 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) |
|
1294 | + 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) |
|
1295 | 1295 | { |
1296 | 1296 | $from[] = $f; |
1297 | 1297 | $to[] = "'+DATEPART($t,($expr))+'"; |
1298 | 1298 | } |
1299 | 1299 | $from[] = "''+"; $to[] = ''; |
1300 | 1300 | $from[] = "+''"; $to[] = ''; |
1301 | - return str_replace($from,$to,$format); |
|
1301 | + return str_replace($from, $to, $format); |
|
1302 | 1302 | } |
1303 | 1303 | return false; |
1304 | 1304 | } |
@@ -1311,7 +1311,7 @@ discard block |
||
1311 | 1311 | */ |
1312 | 1312 | function to_double($expr) |
1313 | 1313 | { |
1314 | - switch($this->Type) |
|
1314 | + switch ($this->Type) |
|
1315 | 1315 | { |
1316 | 1316 | case 'pgsql': |
1317 | 1317 | return $expr.'::double'; |
@@ -1329,7 +1329,7 @@ discard block |
||
1329 | 1329 | */ |
1330 | 1330 | function to_int($expr) |
1331 | 1331 | { |
1332 | - switch($this->Type) |
|
1332 | + switch ($this->Type) |
|
1333 | 1333 | { |
1334 | 1334 | case 'pgsql': |
1335 | 1335 | return $expr.'::integer'; |
@@ -1347,7 +1347,7 @@ discard block |
||
1347 | 1347 | */ |
1348 | 1348 | function to_varchar($expr) |
1349 | 1349 | { |
1350 | - switch($this->Type) |
|
1350 | + switch ($this->Type) |
|
1351 | 1351 | { |
1352 | 1352 | case 'pgsql': |
1353 | 1353 | return 'CAST('.$expr.' AS varchar)'; |
@@ -1391,7 +1391,7 @@ discard block |
||
1391 | 1391 | // always quote for postgreSQL, as this is the only way to support mixed case names |
1392 | 1392 | if (preg_match('/\W/', $name) || $type == 'pgsql' && preg_match('/[A-Z]+/', $name) || $name == 'index') |
1393 | 1393 | { |
1394 | - return $quote . $name . $quote; |
|
1394 | + return $quote.$name.$quote; |
|
1395 | 1395 | } |
1396 | 1396 | return $name; |
1397 | 1397 | }, explode('.', $name)); |
@@ -1413,27 +1413,27 @@ discard block |
||
1413 | 1413 | * @param string $glue =',' used to glue array values together for the string type |
1414 | 1414 | * @return string escaped sting |
1415 | 1415 | */ |
1416 | - function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
|
1416 | + function quote($value, $type = False, $not_null = true, $length = null, $glue = ',') |
|
1417 | 1417 | { |
1418 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1418 | + if ($this->Debug) echo "<p>db::quote(".(is_null($value) ? 'NULL' : "'$value'").",'$type','$not_null')</p>\n"; |
|
1419 | 1419 | |
1420 | 1420 | if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
1421 | 1421 | { |
1422 | 1422 | return 'NULL'; |
1423 | 1423 | } |
1424 | - switch($type) |
|
1424 | + switch ($type) |
|
1425 | 1425 | { |
1426 | 1426 | case 'int': |
1427 | 1427 | // if DateTime object given, convert it to a unix timestamp (NOT converting the timezone!) |
1428 | 1428 | if (is_object($value) && ($value instanceof \DateTime)) |
1429 | 1429 | { |
1430 | - return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value,'ts'); |
|
1430 | + return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value, 'ts'); |
|
1431 | 1431 | } |
1432 | 1432 | case 'auto': |
1433 | 1433 | // atm. (php5.2) php has only 32bit integers, it converts everything else to float. |
1434 | 1434 | // Casting it to int gives a negative number instead of the big 64bit integer! |
1435 | 1435 | // There for we have to keep it as float by using round instead the int cast. |
1436 | - return is_float($value) ? round($value) : (int) $value; |
|
1436 | + return is_float($value) ? round($value) : (int)$value; |
|
1437 | 1437 | case 'bool': |
1438 | 1438 | if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
1439 | 1439 | { |
@@ -1442,23 +1442,23 @@ discard block |
||
1442 | 1442 | return $value ? 'true' : 'false'; |
1443 | 1443 | case 'float': |
1444 | 1444 | case 'decimal': |
1445 | - return (double) $value; |
|
1445 | + return (double)$value; |
|
1446 | 1446 | } |
1447 | 1447 | if (!$this->Link_ID && !$this->connect()) |
1448 | 1448 | { |
1449 | 1449 | return False; |
1450 | 1450 | } |
1451 | - switch($type) |
|
1451 | + switch ($type) |
|
1452 | 1452 | { |
1453 | 1453 | case 'blob': |
1454 | 1454 | switch ($this->Link_ID->blobEncodeType) |
1455 | 1455 | { |
1456 | 1456 | case 'C': // eg. postgres |
1457 | - return "'" . $this->Link_ID->BlobEncode($value) . "'"; |
|
1457 | + return "'".$this->Link_ID->BlobEncode($value)."'"; |
|
1458 | 1458 | case 'I': |
1459 | 1459 | return $this->Link_ID->BlobEncode($value); |
1460 | 1460 | } |
1461 | - break; // handled like strings |
|
1461 | + break; // handled like strings |
|
1462 | 1462 | case 'date': |
1463 | 1463 | // if DateTime object given, convert it (NOT converting the timezone!) |
1464 | 1464 | if (is_object($value) && ($value instanceof \DateTime)) |
@@ -1476,7 +1476,7 @@ discard block |
||
1476 | 1476 | } |
1477 | 1477 | if (is_array($value)) |
1478 | 1478 | { |
1479 | - $value = implode($glue,$value); |
|
1479 | + $value = implode($glue, $value); |
|
1480 | 1480 | } |
1481 | 1481 | // only truncate string if length given and <= 255 |
1482 | 1482 | // to not unnecessary truncate varchar(>255) as PostgreSQL uses text anyway and MySQL truncates itself silently (unless strict mode!) |
@@ -1514,7 +1514,7 @@ discard block |
||
1514 | 1514 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
1515 | 1515 | * @return string SQL |
1516 | 1516 | */ |
1517 | - function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
|
1517 | + function column_data_implode($glue, $array, $use_key = True, $only = False, $column_definitions = False) |
|
1518 | 1518 | { |
1519 | 1519 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
1520 | 1520 | { |
@@ -1524,16 +1524,16 @@ discard block |
||
1524 | 1524 | { |
1525 | 1525 | $column_definitions = $this->column_definitions; |
1526 | 1526 | } |
1527 | - 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"; |
|
1527 | + 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"; |
|
1528 | 1528 | |
1529 | 1529 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
1530 | 1530 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
1531 | 1531 | |
1532 | 1532 | $keys = $values = array(); |
1533 | - foreach($array as $key => $data) |
|
1533 | + foreach ($array as $key => $data) |
|
1534 | 1534 | { |
1535 | 1535 | if (is_int($key) && $use_key !== 'VALUES' || !$only || $only === True && isset($column_definitions[$key]) || |
1536 | - is_array($only) && in_array($key,$only)) |
|
1536 | + is_array($only) && in_array($key, $only)) |
|
1537 | 1537 | { |
1538 | 1538 | $keys[] = $this->name_quote($key); |
1539 | 1539 | |
@@ -1544,7 +1544,7 @@ discard block |
||
1544 | 1544 | if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
1545 | 1545 | if (!isset($column_definitions[$col])) |
1546 | 1546 | { |
1547 | - 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>"); |
|
1547 | + 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>"); |
|
1548 | 1548 | } |
1549 | 1549 | } |
1550 | 1550 | $column_type = is_array($column_definitions) ? @$column_definitions[$col]['type'] : False; |
@@ -1553,7 +1553,7 @@ discard block |
||
1553 | 1553 | $maxlength = null; |
1554 | 1554 | if ($truncate_varchar) |
1555 | 1555 | { |
1556 | - $maxlength = in_array($column_definitions[$col]['type'], array('varchar','ascii')) ? $column_definitions[$col]['precision'] : null; |
|
1556 | + $maxlength = in_array($column_definitions[$col]['type'], array('varchar', 'ascii')) ? $column_definitions[$col]['precision'] : null; |
|
1557 | 1557 | } |
1558 | 1558 | // dont use IN ( ), if there's only one value, it's slower for MySQL |
1559 | 1559 | if (is_array($data) && count($data) == 1) |
@@ -1563,39 +1563,38 @@ discard block |
||
1563 | 1563 | if (is_array($data)) |
1564 | 1564 | { |
1565 | 1565 | $or_null = ''; |
1566 | - foreach($data as $k => $v) |
|
1566 | + foreach ($data as $k => $v) |
|
1567 | 1567 | { |
1568 | - if (!$not_null && $use_key===True && is_null($v)) |
|
1568 | + if (!$not_null && $use_key === True && is_null($v)) |
|
1569 | 1569 | { |
1570 | 1570 | $or_null = $this->name_quote($key).' IS NULL)'; |
1571 | 1571 | unset($data[$k]); |
1572 | 1572 | continue; |
1573 | 1573 | } |
1574 | - $data[$k] = $this->quote($v,$column_type,$not_null,$maxlength); |
|
1574 | + $data[$k] = $this->quote($v, $column_type, $not_null, $maxlength); |
|
1575 | 1575 | } |
1576 | - $values[] = ($or_null?'(':'').(!count($data) ? |
|
1576 | + $values[] = ($or_null ? '(' : '').(!count($data) ? |
|
1577 | 1577 | // empty array on insert/update, store as NULL, or if not allowed whatever value NULL is casted to |
1578 | - $this->quote(null, $column_type, $not_null) : |
|
1579 | - ($use_key===True ? $this->name_quote($key).' IN ' : '') . |
|
1580 | - '('.implode(',',$data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
1578 | + $this->quote(null, $column_type, $not_null) : ($use_key === True ? $this->name_quote($key).' IN ' : ''). |
|
1579 | + '('.implode(',', $data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
1581 | 1580 | } |
1582 | - elseif (is_int($key) && $use_key===True) |
|
1581 | + elseif (is_int($key) && $use_key === True) |
|
1583 | 1582 | { |
1584 | - if (empty($data)) continue; // would give SQL error |
|
1583 | + if (empty($data)) continue; // would give SQL error |
|
1585 | 1584 | $values[] = $data; |
1586 | 1585 | } |
1587 | 1586 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
1588 | 1587 | { |
1589 | - $values[] = $this->name_quote($key) .' IS NULL'; |
|
1588 | + $values[] = $this->name_quote($key).' IS NULL'; |
|
1590 | 1589 | } |
1591 | 1590 | else |
1592 | 1591 | { |
1593 | - $values[] = ($use_key===True ? $this->name_quote($key) . '=' : '') . $this->quote($data,$column_type,$not_null,$maxlength); |
|
1592 | + $values[] = ($use_key === True ? $this->name_quote($key).'=' : '').$this->quote($data, $column_type, $not_null, $maxlength); |
|
1594 | 1593 | } |
1595 | 1594 | } |
1596 | 1595 | } |
1597 | - return ($use_key==='VALUES' ? '('.implode(',',$keys).') VALUES (' : ''). |
|
1598 | - implode($glue,$values) . ($use_key==='VALUES' ? ')' : ''); |
|
1596 | + return ($use_key === 'VALUES' ? '('.implode(',', $keys).') VALUES (' : ''). |
|
1597 | + implode($glue, $values).($use_key === 'VALUES' ? ')' : ''); |
|
1599 | 1598 | } |
1600 | 1599 | |
1601 | 1600 | /** |
@@ -1607,9 +1606,9 @@ discard block |
||
1607 | 1606 | * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
1608 | 1607 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
1609 | 1608 | */ |
1610 | - function set_column_definitions($column_definitions=False) |
|
1609 | + function set_column_definitions($column_definitions = False) |
|
1611 | 1610 | { |
1612 | - $this->column_definitions=$column_definitions; |
|
1611 | + $this->column_definitions = $column_definitions; |
|
1613 | 1612 | } |
1614 | 1613 | |
1615 | 1614 | /** |
@@ -1622,7 +1621,7 @@ discard block |
||
1622 | 1621 | * |
1623 | 1622 | * @var string |
1624 | 1623 | */ |
1625 | - private $app=self::API_APPNAME; |
|
1624 | + private $app = self::API_APPNAME; |
|
1626 | 1625 | |
1627 | 1626 | /** |
1628 | 1627 | * Sets the application in which the db-class looks for table-defintions |
@@ -1679,14 +1678,14 @@ discard block |
||
1679 | 1678 | * @param bool|string $table if set return only defintions of that table, else return all defintions |
1680 | 1679 | * @return mixed array with table-defintions or False if file not found |
1681 | 1680 | */ |
1682 | - function get_table_definitions($app=False,$table=False) |
|
1681 | + function get_table_definitions($app = False, $table = False) |
|
1683 | 1682 | { |
1684 | 1683 | // ease the transition to api |
1685 | 1684 | if ($app === 'phpgwapi') $app = 'api'; |
1686 | 1685 | |
1687 | 1686 | if ($app === true && $table) |
1688 | 1687 | { |
1689 | - foreach(self::$all_app_data as $app => &$app_data) |
|
1688 | + foreach (self::$all_app_data as $app => &$app_data) |
|
1690 | 1689 | { |
1691 | 1690 | if (isset($app_data[$table])) |
1692 | 1691 | { |
@@ -1694,13 +1693,13 @@ discard block |
||
1694 | 1693 | } |
1695 | 1694 | } |
1696 | 1695 | // $table not found in loaded apps, check not yet loaded ones |
1697 | - foreach(scandir(EGW_INCLUDE_ROOT) as $app) |
|
1696 | + foreach (scandir(EGW_INCLUDE_ROOT) as $app) |
|
1698 | 1697 | { |
1699 | 1698 | if ($app[0] == '.' || !is_dir(EGW_INCLUDE_ROOT.'/'.$app) || isset(self::$all_app_data[$app])) |
1700 | 1699 | { |
1701 | 1700 | continue; |
1702 | 1701 | } |
1703 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
1702 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
1704 | 1703 | if (!@file_exists($tables_current)) |
1705 | 1704 | { |
1706 | 1705 | self::$all_app_data[$app] = False; |
@@ -1709,7 +1708,7 @@ discard block |
||
1709 | 1708 | { |
1710 | 1709 | $phpgw_baseline = null; |
1711 | 1710 | include($tables_current); |
1712 | - self::$all_app_data[$app] =& $phpgw_baseline; |
|
1711 | + self::$all_app_data[$app] = & $phpgw_baseline; |
|
1713 | 1712 | unset($phpgw_baseline); |
1714 | 1713 | |
1715 | 1714 | if (isset(self::$all_app_data[$app][$table])) |
@@ -1724,17 +1723,17 @@ discard block |
||
1724 | 1723 | { |
1725 | 1724 | $app = $this->app ? $this->app : $GLOBALS['egw_info']['flags']['currentapp']; |
1726 | 1725 | } |
1727 | - $app_data =& self::$all_app_data[$app]; |
|
1726 | + $app_data = & self::$all_app_data[$app]; |
|
1728 | 1727 | |
1729 | 1728 | if (!isset($app_data)) |
1730 | 1729 | { |
1731 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
1730 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
1732 | 1731 | if (!@file_exists($tables_current)) |
1733 | 1732 | { |
1734 | 1733 | return $app_data = False; |
1735 | 1734 | } |
1736 | 1735 | include($tables_current); |
1737 | - $app_data =& $phpgw_baseline; |
|
1736 | + $app_data = & $phpgw_baseline; |
|
1738 | 1737 | unset($phpgw_baseline); |
1739 | 1738 | } |
1740 | 1739 | if ($table && (!$app_data || !isset($app_data[$table]))) |
@@ -1757,14 +1756,14 @@ discard block |
||
1757 | 1756 | * @param string $attribute='comment' what field to return, NULL for array with all fields, default 'comment' to return the comment |
1758 | 1757 | * @return string|array NULL if table or column or attribute not found |
1759 | 1758 | */ |
1760 | - /* static */ function get_column_attribute($column,$table,$app=null,$attribute='comment') |
|
1759 | + /* static */ function get_column_attribute($column, $table, $app = null, $attribute = 'comment') |
|
1761 | 1760 | { |
1762 | - static $cached_columns=null,$cached_table=null; // some caching |
|
1761 | + static $cached_columns = null, $cached_table = null; // some caching |
|
1763 | 1762 | |
1764 | 1763 | if ($cached_table !== $table || is_null($cached_columns)) |
1765 | 1764 | { |
1766 | 1765 | $db = isset($this) ? $this : $GLOBALS['egw']->db; |
1767 | - $table_def = $db->get_table_definitions($app,$table); |
|
1766 | + $table_def = $db->get_table_definitions($app, $table); |
|
1768 | 1767 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
1769 | 1768 | } |
1770 | 1769 | if ($cached_columns === false) return null; |
@@ -1788,38 +1787,38 @@ discard block |
||
1788 | 1787 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1789 | 1788 | * @return ADORecordSet or false, if the query fails |
1790 | 1789 | */ |
1791 | - function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
1790 | + function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
1792 | 1791 | { |
1793 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1792 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app')</p>\n"; |
|
1794 | 1793 | |
1795 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1794 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1796 | 1795 | |
1797 | 1796 | $sql_append = ''; |
1798 | 1797 | $cmd = 'INSERT'; |
1799 | 1798 | if (is_array($where) && count($where)) |
1800 | 1799 | { |
1801 | - switch($this->Type) |
|
1800 | + switch ($this->Type) |
|
1802 | 1801 | { |
1803 | 1802 | case 'sapdb': case 'maxdb': |
1804 | 1803 | $sql_append = ' UPDATE DUPLICATES'; |
1805 | 1804 | break; |
1806 | 1805 | case 'mysql': |
1807 | 1806 | // use replace if primary keys are included |
1808 | - if (count(array_intersect(array_keys($where),(array)$table_def['pk'])) == count($table_def['pk'])) |
|
1807 | + if (count(array_intersect(array_keys($where), (array)$table_def['pk'])) == count($table_def['pk'])) |
|
1809 | 1808 | { |
1810 | 1809 | $cmd = 'REPLACE'; |
1811 | 1810 | break; |
1812 | 1811 | } |
1813 | 1812 | // fall through !!! |
1814 | 1813 | default: |
1815 | - if ($this->select($table,'count(*)',$where,$line,$file)->fetchColumn()) |
|
1814 | + if ($this->select($table, 'count(*)', $where, $line, $file)->fetchColumn()) |
|
1816 | 1815 | { |
1817 | - return !!$this->update($table,$data,$where,$line,$file,$app,$use_prepared_statement,$table_def); |
|
1816 | + return !!$this->update($table, $data, $where, $line, $file, $app, $use_prepared_statement, $table_def); |
|
1818 | 1817 | } |
1819 | 1818 | break; |
1820 | 1819 | } |
1821 | 1820 | // the checked values need to be inserted too, value in data has precedence, also cant insert sql strings (numerical id) |
1822 | - foreach($where as $column => $value) |
|
1821 | + foreach ($where as $column => $value) |
|
1823 | 1822 | { |
1824 | 1823 | if (!is_numeric($column) && !isset($data[$column]) && |
1825 | 1824 | // skip auto-id of 0 or NULL, as PostgreSQL does NOT create an auto-id, if they are given |
@@ -1839,24 +1838,24 @@ discard block |
||
1839 | 1838 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
1840 | 1839 | |
1841 | 1840 | $sql = "$cmd INTO $table "; |
1842 | - foreach($data as $k => $d) |
|
1841 | + foreach ($data as $k => $d) |
|
1843 | 1842 | { |
1844 | 1843 | if (!$k) |
1845 | 1844 | { |
1846 | - $sql .= $this->column_data_implode(',',$d,'VALUES',true,$table_def['fd']); |
|
1845 | + $sql .= $this->column_data_implode(',', $d, 'VALUES', true, $table_def['fd']); |
|
1847 | 1846 | } |
1848 | 1847 | else |
1849 | 1848 | { |
1850 | - $sql .= ",\n(".$this->column_data_implode(',',$d,false,true,$table_def['fd']).')'; |
|
1849 | + $sql .= ",\n(".$this->column_data_implode(',', $d, false, true, $table_def['fd']).')'; |
|
1851 | 1850 | } |
1852 | 1851 | } |
1853 | 1852 | $sql .= $sql_append; |
1854 | 1853 | } |
1855 | 1854 | elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
1856 | 1855 | { |
1857 | - $this->Link_ID->Param(false); // reset param-counter |
|
1856 | + $this->Link_ID->Param(false); // reset param-counter |
|
1858 | 1857 | $cols = array_keys($data); |
1859 | - foreach($cols as $k => $col) |
|
1858 | + foreach ($cols as $k => $col) |
|
1860 | 1859 | { |
1861 | 1860 | if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
1862 | 1861 | { |
@@ -1865,7 +1864,7 @@ discard block |
||
1865 | 1864 | } |
1866 | 1865 | $params[] = $this->Link_ID->Param($col); |
1867 | 1866 | } |
1868 | - $sql = "$cmd INTO $table (".implode(',',$cols).') VALUES ('.implode(',',$params).')'.$sql_append; |
|
1867 | + $sql = "$cmd INTO $table (".implode(',', $cols).') VALUES ('.implode(',', $params).')'.$sql_append; |
|
1869 | 1868 | // check if we already prepared that statement |
1870 | 1869 | if (!isset($this->prepared_sql[$sql])) |
1871 | 1870 | { |
@@ -1876,10 +1875,10 @@ discard block |
||
1876 | 1875 | } |
1877 | 1876 | else |
1878 | 1877 | { |
1879 | - $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
|
1878 | + $sql = "$cmd INTO $table ".$this->column_data_implode(',', $data, 'VALUES', true, $table_def['fd']).$sql_append; |
|
1880 | 1879 | } |
1881 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1882 | - return $this->query($sql,$line,$file,0,-1,$inputarr); |
|
1880 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1881 | + return $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
1883 | 1882 | } |
1884 | 1883 | |
1885 | 1884 | /** |
@@ -1897,10 +1896,10 @@ discard block |
||
1897 | 1896 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1898 | 1897 | * @return ADORecordSet or false, if the query fails |
1899 | 1898 | */ |
1900 | - function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
1899 | + function update($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
1901 | 1900 | { |
1902 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
1903 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1901 | + if ($this->Debug) echo "<p>db::update('$table',".print_r($data, true).','.print_r($where, true).",$line,$file,'$app')</p>\n"; |
|
1902 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1904 | 1903 | |
1905 | 1904 | $blobs2update = array(); |
1906 | 1905 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1911,7 +1910,7 @@ discard block |
||
1911 | 1910 | case 'maxdb': |
1912 | 1911 | if ($use_prepared_statement) break; |
1913 | 1912 | // check if data contains any LONG columns |
1914 | - foreach($data as $col => $val) |
|
1913 | + foreach ($data as $col => $val) |
|
1915 | 1914 | { |
1916 | 1915 | switch ($table_def['fd'][$col]['type']) |
1917 | 1916 | { |
@@ -1925,7 +1924,7 @@ discard block |
||
1925 | 1924 | } |
1926 | 1925 | break; |
1927 | 1926 | } |
1928 | - $where_str = $this->column_data_implode(' AND ',$where,True,true,$table_def['fd']); |
|
1927 | + $where_str = $this->column_data_implode(' AND ', $where, True, true, $table_def['fd']); |
|
1929 | 1928 | |
1930 | 1929 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
1931 | 1930 | { |
@@ -1936,13 +1935,13 @@ discard block |
||
1936 | 1935 | $inputarr = false; |
1937 | 1936 | if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
1938 | 1937 | { |
1939 | - $this->Link_ID->Param(false); // reset param-counter |
|
1940 | - foreach($data as $col => $val) |
|
1938 | + $this->Link_ID->Param(false); // reset param-counter |
|
1939 | + foreach ($data as $col => $val) |
|
1941 | 1940 | { |
1942 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
1941 | + if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
1943 | 1942 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
1944 | 1943 | } |
1945 | - $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
1944 | + $sql = "UPDATE $table SET ".implode(',', $params).' WHERE '.$where_str; |
|
1946 | 1945 | // check if we already prepared that statement |
1947 | 1946 | if (!isset($this->prepared_sql[$sql])) |
1948 | 1947 | { |
@@ -1954,19 +1953,19 @@ discard block |
||
1954 | 1953 | else |
1955 | 1954 | { |
1956 | 1955 | $sql = "UPDATE $table SET ". |
1957 | - $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
|
1956 | + $this->column_data_implode(',', $data, True, true, $table_def['fd']).' WHERE '.$where_str; |
|
1958 | 1957 | } |
1959 | - $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
|
1958 | + $ret = $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
1960 | 1959 | if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
1961 | 1960 | } |
1962 | 1961 | // if we have any blobs to update, we do so now |
1963 | 1962 | if (($ret || !count($data)) && count($blobs2update)) |
1964 | 1963 | { |
1965 | - foreach($blobs2update as $col => $val) |
|
1964 | + foreach ($blobs2update as $col => $val) |
|
1966 | 1965 | { |
1967 | - $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
1966 | + $ret = $this->Link_ID->UpdateBlob($table, $col, $val, $where_str, $table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
1968 | 1967 | if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
1969 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
1968 | + if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)", $line, $file); |
|
1970 | 1969 | } |
1971 | 1970 | } |
1972 | 1971 | return $ret; |
@@ -1985,18 +1984,18 @@ discard block |
||
1985 | 1984 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1986 | 1985 | * @return ADORecordSet or false, if the query fails |
1987 | 1986 | */ |
1988 | - function delete($table,$where,$line,$file,$app=False,$table_def=False) |
|
1987 | + function delete($table, $where, $line, $file, $app = False, $table_def = False) |
|
1989 | 1988 | { |
1990 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1989 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1991 | 1990 | |
1992 | 1991 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
1993 | 1992 | { |
1994 | 1993 | $table = self::$tablealiases[$table]; |
1995 | 1994 | } |
1996 | 1995 | $sql = "DELETE FROM $table WHERE ". |
1997 | - $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
1996 | + $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
1998 | 1997 | |
1999 | - return $this->query($sql,$line,$file); |
|
1998 | + return $this->query($sql, $line, $file); |
|
2000 | 1999 | } |
2001 | 2000 | |
2002 | 2001 | /** |
@@ -2019,12 +2018,12 @@ discard block |
||
2019 | 2018 | */ |
2020 | 2019 | function expression($table_def/*,$args, ...*/) |
2021 | 2020 | { |
2022 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
2021 | + if (!is_array($table_def)) $table_def = $this->get_table_definitions(true, $table_def); |
|
2023 | 2022 | $sql = ''; |
2024 | 2023 | $ignore_next = 0; |
2025 | - foreach(func_get_args() as $n => $arg) |
|
2024 | + foreach (func_get_args() as $n => $arg) |
|
2026 | 2025 | { |
2027 | - if ($n < 1) continue; // table-name |
|
2026 | + if ($n < 1) continue; // table-name |
|
2028 | 2027 | |
2029 | 2028 | if ($ignore_next) |
2030 | 2029 | { |
@@ -2033,7 +2032,7 @@ discard block |
||
2033 | 2032 | } |
2034 | 2033 | if (is_null($arg)) $arg = False; |
2035 | 2034 | |
2036 | - switch(gettype($arg)) |
|
2035 | + switch (gettype($arg)) |
|
2037 | 2036 | { |
2038 | 2037 | case 'string': |
2039 | 2038 | $sql .= $arg; |
@@ -2042,7 +2041,7 @@ discard block |
||
2042 | 2041 | $ignore_next += !$arg ? 2 : 0; |
2043 | 2042 | break; |
2044 | 2043 | case 'array': |
2045 | - $sql .= $this->column_data_implode(' AND ',$arg,True,False,$table_def['fd']); |
|
2044 | + $sql .= $this->column_data_implode(' AND ', $arg, True, False, $table_def['fd']); |
|
2046 | 2045 | break; |
2047 | 2046 | } |
2048 | 2047 | } |
@@ -2069,18 +2068,18 @@ discard block |
||
2069 | 2068 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
2070 | 2069 | * @return ADORecordSet or false, if the query fails |
2071 | 2070 | */ |
2072 | - function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
|
2071 | + function select($table, $cols, $where, $line, $file, $offset = False, $append = '', $app = False, $num_rows = 0, $join = '', $table_def = False, $fetchmode = self::FETCH_ASSOC) |
|
2073 | 2072 | { |
2074 | - 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"; |
|
2073 | + 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"; |
|
2075 | 2074 | |
2076 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2075 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
2077 | 2076 | if (is_array($cols)) |
2078 | 2077 | { |
2079 | - $cols = implode(',',$cols); |
|
2078 | + $cols = implode(',', $cols); |
|
2080 | 2079 | } |
2081 | 2080 | if (is_array($where)) |
2082 | 2081 | { |
2083 | - $where = $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
2082 | + $where = $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
2084 | 2083 | } |
2085 | 2084 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
2086 | 2085 | { |
@@ -2089,7 +2088,7 @@ discard block |
||
2089 | 2088 | $sql = "SELECT $cols FROM $table $join"; |
2090 | 2089 | |
2091 | 2090 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
2092 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2091 | + if ($where) $sql .= (strpos($join, "WHERE") !== false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2093 | 2092 | |
2094 | 2093 | if ($append) $sql .= ' '.$append; |
2095 | 2094 | |
@@ -2099,7 +2098,7 @@ discard block |
||
2099 | 2098 | { |
2100 | 2099 | return $sql; |
2101 | 2100 | } |
2102 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
2101 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
2103 | 2102 | } |
2104 | 2103 | |
2105 | 2104 | /** |
@@ -2117,34 +2116,34 @@ discard block |
||
2117 | 2116 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
2118 | 2117 | * @return ADORecordSet or false, if the query fails |
2119 | 2118 | */ |
2120 | - function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
|
2119 | + function union($selects, $line, $file, $order_by = '', $offset = false, $num_rows = 0, $fetchmode = self::FETCH_ASSOC) |
|
2121 | 2120 | { |
2122 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2121 | + if ($this->Debug) echo "<p>db::union(".print_r($selects, True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2123 | 2122 | |
2124 | 2123 | $union = array(); |
2125 | - foreach($selects as $select) |
|
2124 | + foreach ($selects as $select) |
|
2126 | 2125 | { |
2127 | - $union[] = call_user_func_array(array($this,'select'),array( |
|
2126 | + $union[] = call_user_func_array(array($this, 'select'), array( |
|
2128 | 2127 | $select['table'], |
2129 | 2128 | $select['cols'], |
2130 | 2129 | $select['where'], |
2131 | - false, // line |
|
2132 | - false, // file |
|
2133 | - false, // offset |
|
2130 | + false, // line |
|
2131 | + false, // file |
|
2132 | + false, // offset |
|
2134 | 2133 | $select['append'], |
2135 | 2134 | $select['app'], |
2136 | - 0, // num_rows, |
|
2135 | + 0, // num_rows, |
|
2137 | 2136 | $select['join'], |
2138 | 2137 | $select['table_def'], |
2139 | 2138 | )); |
2140 | 2139 | } |
2141 | - $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
|
2140 | + $sql = count($union) > 1 ? '('.implode(")\nUNION\n(", $union).')' : 'SELECT DISTINCT'.substr($union[0], 6); |
|
2142 | 2141 | |
2143 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2142 | + if ($order_by) $sql .= (!stristr($order_by, 'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2144 | 2143 | |
2145 | 2144 | if ($this->Debug) echo "<p>sql='$sql'</p>"; |
2146 | 2145 | |
2147 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
2146 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
2148 | 2147 | } |
2149 | 2148 | |
2150 | 2149 | /** |
@@ -2154,15 +2153,15 @@ discard block |
||
2154 | 2153 | * @param string|array $strip |
2155 | 2154 | * @return array |
2156 | 2155 | */ |
2157 | - static function strip_array_keys($arr,$strip) |
|
2156 | + static function strip_array_keys($arr, $strip) |
|
2158 | 2157 | { |
2159 | 2158 | $keys = array_keys($arr); |
2160 | 2159 | |
2161 | 2160 | return array_walk($keys, function(&$v, $k, $strip) |
2162 | 2161 | { |
2163 | - unset($k); // not used, but required by function signature |
|
2162 | + unset($k); // not used, but required by function signature |
|
2164 | 2163 | $v = str_replace($strip, '', $v); |
2165 | 2164 | }, $strip) ? |
2166 | - array_combine($keys,$arr) : $arr; |
|
2165 | + array_combine($keys, $arr) : $arr; |
|
2167 | 2166 | } |
2168 | 2167 | } |
@@ -389,7 +389,10 @@ discard block |
||
389 | 389 | if ($state['wsrep_local_state_comment'] == 'Synced' || |
390 | 390 | // if we have only 2 nodes (2. one starting), we can only use the donor |
391 | 391 | $state['wsrep_local_state_comment'] == 'Donor/Desynced' && |
392 | - $state['wsrep_cluster_size'] == 2) return; |
|
392 | + $state['wsrep_cluster_size'] == 2) |
|
393 | + { |
|
394 | + return; |
|
395 | + } |
|
393 | 396 | |
394 | 397 | throw new Db\Exception\Connection('Node is NOT Synced! '.array2string($state)); |
395 | 398 | } |
@@ -408,7 +411,10 @@ discard block |
||
408 | 411 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
409 | 412 | $num_hosts = count($hosts); |
410 | 413 | $n =& Cache::getSession(__CLASS__, $this->Host); |
411 | - if (!isset($n)) $n = 0; |
|
414 | + if (!isset($n)) |
|
415 | + { |
|
416 | + $n = 0; |
|
417 | + } |
|
412 | 418 | |
413 | 419 | if ($next && ++$n >= $num_hosts+2) |
414 | 420 | { |
@@ -438,7 +444,10 @@ discard block |
||
438 | 444 | foreach(array('Database','User','Password','Port','Type') as $name) |
439 | 445 | { |
440 | 446 | $$name = $this->$name; |
441 | - if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
|
447 | + if (${$name}[0] == '@' && $name != 'Password') |
|
448 | + { |
|
449 | + $$name = getenv(substr($$name, 1)); |
|
450 | + } |
|
442 | 451 | } |
443 | 452 | $this->setupType = $php_extension = $Type; |
444 | 453 | |
@@ -457,7 +466,10 @@ discard block |
||
457 | 466 | $Type = 'mssql'; |
458 | 467 | // fall through |
459 | 468 | case 'mssql': |
460 | - if ($Port) $Host .= ','.$Port; |
|
469 | + if ($Port) |
|
470 | + { |
|
471 | + $Host .= ','.$Port; |
|
472 | + } |
|
461 | 473 | break; |
462 | 474 | |
463 | 475 | case 'odbc_oracle': |
@@ -492,7 +504,10 @@ discard block |
||
492 | 504 | $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
493 | 505 | // fall through |
494 | 506 | default: |
495 | - if ($Port) $Host .= ':'.$Port; |
|
507 | + if ($Port) |
|
508 | + { |
|
509 | + $Host .= ':'.$Port; |
|
510 | + } |
|
496 | 511 | break; |
497 | 512 | } |
498 | 513 | if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
@@ -507,10 +522,13 @@ discard block |
||
507 | 522 | { |
508 | 523 | 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 !!!"); |
509 | 524 | } |
510 | - if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
|
525 | + if (!isset($GLOBALS['egw']->ADOdb)) |
|
526 | + { |
|
527 | + // use the global object to store the connection |
|
511 | 528 | { |
512 | 529 | $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
513 | 530 | } |
531 | + } |
|
514 | 532 | else |
515 | 533 | { |
516 | 534 | $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
@@ -612,7 +630,11 @@ discard block |
||
612 | 630 | */ |
613 | 631 | function __sleep() |
614 | 632 | { |
615 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
633 | + if (!empty($this->setupType)) |
|
634 | + { |
|
635 | + $this->Type = $this->setupType; |
|
636 | + } |
|
637 | + // restore Type eg. to mysqli |
|
616 | 638 | |
617 | 639 | $vars = get_object_vars($this); |
618 | 640 | unset($vars['Link_ID'], $vars['Query_ID'], $vars['privat_Link_ID']); |
@@ -674,7 +696,10 @@ discard block |
||
674 | 696 | unset($this->Link_ID); |
675 | 697 | $this->Link_ID = 0; |
676 | 698 | |
677 | - if (!empty($this->setupType)) $this->Type = $this->setupType; |
|
699 | + if (!empty($this->setupType)) |
|
700 | + { |
|
701 | + $this->Type = $this->setupType; |
|
702 | + } |
|
678 | 703 | } |
679 | 704 | |
680 | 705 | /** |
@@ -756,8 +781,14 @@ discard block |
||
756 | 781 | } |
757 | 782 | if (($this->readonly || $this->log_updates) && !preg_match('/^\(?(SELECT|SET|SHOW)/i', $Query_String)) |
758 | 783 | { |
759 | - if ($this->log_updates) error_log($Query_String.': '.function_backtrace()); |
|
760 | - if ($this->readonly) return 0; |
|
784 | + if ($this->log_updates) |
|
785 | + { |
|
786 | + error_log($Query_String.': '.function_backtrace()); |
|
787 | + } |
|
788 | + if ($this->readonly) |
|
789 | + { |
|
790 | + return 0; |
|
791 | + } |
|
761 | 792 | } |
762 | 793 | if ($num_rows > 0) |
763 | 794 | { |
@@ -783,16 +814,22 @@ discard block |
||
783 | 814 | } |
784 | 815 | if (!$rs) |
785 | 816 | { |
786 | - if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) // Server has gone away |
|
817 | + if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) |
|
818 | + { |
|
819 | + // Server has gone away |
|
787 | 820 | { |
788 | 821 | $this->disconnect(); |
822 | + } |
|
789 | 823 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
790 | 824 | } |
791 | 825 | throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
792 | 826 | "\n$this->Error ($this->Errno)". |
793 | 827 | ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
794 | 828 | } |
795 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
829 | + elseif(empty($rs->sql)) |
|
830 | + { |
|
831 | + $rs->sql = $Query_String; |
|
832 | + } |
|
796 | 833 | return $rs; |
797 | 834 | } |
798 | 835 | |
@@ -940,9 +977,12 @@ discard block |
||
940 | 977 | } |
941 | 978 | $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
942 | 979 | |
943 | - if ($id === False) // function not supported |
|
980 | + if ($id === False) |
|
981 | + { |
|
982 | + // function not supported |
|
944 | 983 | { |
945 | 984 | 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"; |
985 | + } |
|
946 | 986 | echo '<p>'.function_backtrace()."</p>\n"; |
947 | 987 | return -1; |
948 | 988 | } |
@@ -956,7 +996,10 @@ discard block |
||
956 | 996 | */ |
957 | 997 | function affected_rows() |
958 | 998 | { |
959 | - if ($this->log_updates) return 0; |
|
999 | + if ($this->log_updates) |
|
1000 | + { |
|
1001 | + return 0; |
|
1002 | + } |
|
960 | 1003 | |
961 | 1004 | if (!$this->Link_ID && !$this->connect()) |
962 | 1005 | { |
@@ -990,9 +1033,18 @@ discard block |
||
990 | 1033 | { |
991 | 1034 | // for backwards compatibilty (depreciated) |
992 | 1035 | $flags = null; |
993 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
994 | - if($column->primary_key) $flags .= "primary_key "; |
|
995 | - if($column->binary) $flags .= "binary "; |
|
1036 | + if($column->auto_increment) |
|
1037 | + { |
|
1038 | + $flags .= "auto_increment "; |
|
1039 | + } |
|
1040 | + if($column->primary_key) |
|
1041 | + { |
|
1042 | + $flags .= "primary_key "; |
|
1043 | + } |
|
1044 | + if($column->binary) |
|
1045 | + { |
|
1046 | + $flags .= "binary "; |
|
1047 | + } |
|
996 | 1048 | |
997 | 1049 | $metadata[$i] = array( |
998 | 1050 | 'table' => $table, |
@@ -1029,7 +1081,10 @@ discard block |
||
1029 | 1081 | */ |
1030 | 1082 | function table_names($just_name=false) |
1031 | 1083 | { |
1032 | - if (!$this->Link_ID) $this->connect(); |
|
1084 | + if (!$this->Link_ID) |
|
1085 | + { |
|
1086 | + $this->connect(); |
|
1087 | + } |
|
1033 | 1088 | if (!$this->Link_ID) |
1034 | 1089 | { |
1035 | 1090 | return False; |
@@ -1181,8 +1236,14 @@ discard block |
||
1181 | 1236 | case 'mysqli': |
1182 | 1237 | case 'mysql': |
1183 | 1238 | $sql = 'GROUP_CONCAT('.$expr; |
1184 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
1185 | - if ($separator != ',') $sql .= ' SEPARATOR '.$this->quote($separator); |
|
1239 | + if ($order_by) |
|
1240 | + { |
|
1241 | + $sql .= ' ORDER BY '.$order_by; |
|
1242 | + } |
|
1243 | + if ($separator != ',') |
|
1244 | + { |
|
1245 | + $sql .= ' SEPARATOR '.$this->quote($separator); |
|
1246 | + } |
|
1186 | 1247 | $sql .= ')'; |
1187 | 1248 | break; |
1188 | 1249 | |
@@ -1192,7 +1253,10 @@ discard block |
||
1192 | 1253 | return false; |
1193 | 1254 | } |
1194 | 1255 | $sql = 'ARRAY_TO_STRING(ARRAY_AGG('.$expr; |
1195 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
1256 | + if ($order_by) |
|
1257 | + { |
|
1258 | + $sql .= ' ORDER BY '.$order_by; |
|
1259 | + } |
|
1196 | 1260 | $sql .= '), '.$this->quote($separator).')'; |
1197 | 1261 | break; |
1198 | 1262 | |
@@ -1415,12 +1479,18 @@ discard block |
||
1415 | 1479 | */ |
1416 | 1480 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
1417 | 1481 | { |
1418 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1482 | + if ($this->Debug) |
|
1483 | + { |
|
1484 | + echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1485 | + } |
|
1419 | 1486 | |
1420 | - if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
|
1487 | + if (!$not_null && is_null($value)) |
|
1488 | + { |
|
1489 | + // writing unset php-variables and those set to NULL now as SQL NULL |
|
1421 | 1490 | { |
1422 | 1491 | return 'NULL'; |
1423 | 1492 | } |
1493 | + } |
|
1424 | 1494 | switch($type) |
1425 | 1495 | { |
1426 | 1496 | case 'int': |
@@ -1435,10 +1505,13 @@ discard block |
||
1435 | 1505 | // There for we have to keep it as float by using round instead the int cast. |
1436 | 1506 | return is_float($value) ? round($value) : (int) $value; |
1437 | 1507 | case 'bool': |
1438 | - if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
|
1508 | + if ($this->Type == 'mysql') |
|
1509 | + { |
|
1510 | + // maybe it's not longer necessary with mysql5 |
|
1439 | 1511 | { |
1440 | 1512 | return $value ? 1 : 0; |
1441 | 1513 | } |
1514 | + } |
|
1442 | 1515 | return $value ? 'true' : 'false'; |
1443 | 1516 | case 'float': |
1444 | 1517 | case 'decimal': |
@@ -1486,7 +1559,10 @@ discard block |
||
1486 | 1559 | } |
1487 | 1560 | // casting boolean explicitly to string, as ADODB_postgres64::qstr() has an unwanted special handling |
1488 | 1561 | // for boolean types, causing it to return "true" or "false" and not a quoted string like "'1'"! |
1489 | - if (is_bool($value)) $value = (string)$value; |
|
1562 | + if (is_bool($value)) |
|
1563 | + { |
|
1564 | + $value = (string)$value; |
|
1565 | + } |
|
1490 | 1566 | |
1491 | 1567 | // MySQL and MariaDB before 10.1 need 4-byte utf8 chars replaced with our default utf8 charset |
1492 | 1568 | // (MariaDB 10.1 does the replacement automatic, 10.0 cuts everything off behind and MySQL gives an error) |
@@ -1524,15 +1600,21 @@ discard block |
||
1524 | 1600 | */ |
1525 | 1601 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
1526 | 1602 | { |
1527 | - if (!is_array($array)) // this allows to give an SQL-string for delete or update |
|
1603 | + if (!is_array($array)) |
|
1604 | + { |
|
1605 | + // this allows to give an SQL-string for delete or update |
|
1528 | 1606 | { |
1529 | 1607 | return $array; |
1530 | 1608 | } |
1609 | + } |
|
1531 | 1610 | if (!$column_definitions) |
1532 | 1611 | { |
1533 | 1612 | $column_definitions = $this->column_definitions; |
1534 | 1613 | } |
1535 | - 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"; |
|
1614 | + if ($this->Debug) |
|
1615 | + { |
|
1616 | + 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"; |
|
1617 | + } |
|
1536 | 1618 | |
1537 | 1619 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
1538 | 1620 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
@@ -1549,7 +1631,10 @@ discard block |
||
1549 | 1631 | // fix "table.column" expressions, to not trigger exception, if column alone would work |
1550 | 1632 | if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key])) |
1551 | 1633 | { |
1552 | - if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
|
1634 | + if (strpos($key, '.') !== false) |
|
1635 | + { |
|
1636 | + list(, $col) = explode('.', $key); |
|
1637 | + } |
|
1553 | 1638 | if (!isset($column_definitions[$col])) |
1554 | 1639 | { |
1555 | 1640 | 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>"); |
@@ -1589,7 +1674,11 @@ discard block |
||
1589 | 1674 | } |
1590 | 1675 | elseif (is_int($key) && $use_key===True) |
1591 | 1676 | { |
1592 | - if (empty($data)) continue; // would give SQL error |
|
1677 | + if (empty($data)) |
|
1678 | + { |
|
1679 | + continue; |
|
1680 | + } |
|
1681 | + // would give SQL error |
|
1593 | 1682 | $values[] = $data; |
1594 | 1683 | } |
1595 | 1684 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
@@ -1643,7 +1732,10 @@ discard block |
||
1643 | 1732 | function set_app($app) |
1644 | 1733 | { |
1645 | 1734 | // ease the transition to api |
1646 | - if ($app == 'phpgwapi') $app = 'api'; |
|
1735 | + if ($app == 'phpgwapi') |
|
1736 | + { |
|
1737 | + $app = 'api'; |
|
1738 | + } |
|
1647 | 1739 | |
1648 | 1740 | if ($this === $GLOBALS['egw']->db && $app != self::API_APPNAME) |
1649 | 1741 | { |
@@ -1690,7 +1782,10 @@ discard block |
||
1690 | 1782 | function get_table_definitions($app=False,$table=False) |
1691 | 1783 | { |
1692 | 1784 | // ease the transition to api |
1693 | - if ($app === 'phpgwapi') $app = 'api'; |
|
1785 | + if ($app === 'phpgwapi') |
|
1786 | + { |
|
1787 | + $app = 'api'; |
|
1788 | + } |
|
1694 | 1789 | |
1695 | 1790 | if ($app === true && $table) |
1696 | 1791 | { |
@@ -1747,10 +1842,16 @@ discard block |
||
1747 | 1842 | } |
1748 | 1843 | if ($table && (!$app_data || !isset($app_data[$table]))) |
1749 | 1844 | { |
1750 | - if ($this->Debug) echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
1845 | + if ($this->Debug) |
|
1846 | + { |
|
1847 | + echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
1848 | + } |
|
1751 | 1849 | return False; |
1752 | 1850 | } |
1753 | - if ($this->Debug) echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
1851 | + if ($this->Debug) |
|
1852 | + { |
|
1853 | + echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
1854 | + } |
|
1754 | 1855 | return $table ? $app_data[$table] : $app_data; |
1755 | 1856 | } |
1756 | 1857 | |
@@ -1775,7 +1876,10 @@ discard block |
||
1775 | 1876 | $table_def = $db->get_table_definitions($app,$table); |
1776 | 1877 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
1777 | 1878 | } |
1778 | - if ($cached_columns === false) return null; |
|
1879 | + if ($cached_columns === false) |
|
1880 | + { |
|
1881 | + return null; |
|
1882 | + } |
|
1779 | 1883 | |
1780 | 1884 | return is_null($attribute) ? $cached_columns[$column] : $cached_columns[$column][$attribute]; |
1781 | 1885 | } |
@@ -1798,9 +1902,15 @@ discard block |
||
1798 | 1902 | */ |
1799 | 1903 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1800 | 1904 | { |
1801 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1905 | + if ($this->Debug) |
|
1906 | + { |
|
1907 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1908 | + } |
|
1802 | 1909 | |
1803 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1910 | + if (!$table_def) |
|
1911 | + { |
|
1912 | + $table_def = $this->get_table_definitions($app,$table); |
|
1913 | + } |
|
1804 | 1914 | |
1805 | 1915 | $sql_append = ''; |
1806 | 1916 | $cmd = 'INSERT'; |
@@ -1842,9 +1952,12 @@ discard block |
||
1842 | 1952 | $table = self::$tablealiases[$table]; |
1843 | 1953 | } |
1844 | 1954 | $inputarr = false; |
1845 | - if (isset($data[0]) && is_array($data[0])) // multiple data rows |
|
1955 | + if (isset($data[0]) && is_array($data[0])) |
|
1956 | + { |
|
1957 | + // multiple data rows |
|
1846 | 1958 | { |
1847 | 1959 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
1960 | + } |
|
1848 | 1961 | |
1849 | 1962 | $sql = "$cmd INTO $table "; |
1850 | 1963 | foreach($data as $k => $d) |
@@ -1860,15 +1973,22 @@ discard block |
||
1860 | 1973 | } |
1861 | 1974 | $sql .= $sql_append; |
1862 | 1975 | } |
1863 | - elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
1976 | + elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
1864 | 1977 | { |
1865 | - $this->Link_ID->Param(false); // reset param-counter |
|
1978 | + // eg. MaxDB |
|
1979 | + { |
|
1980 | + $this->Link_ID->Param(false); |
|
1981 | + } |
|
1982 | + // reset param-counter |
|
1866 | 1983 | $cols = array_keys($data); |
1867 | 1984 | foreach($cols as $k => $col) |
1868 | 1985 | { |
1869 | - if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
|
1986 | + if (!isset($table_def['fd'][$col])) |
|
1987 | + { |
|
1988 | + // ignore columns not in this table |
|
1870 | 1989 | { |
1871 | 1990 | unset($cols[$k]); |
1991 | + } |
|
1872 | 1992 | continue; |
1873 | 1993 | } |
1874 | 1994 | $params[] = $this->Link_ID->Param($col); |
@@ -1886,7 +2006,10 @@ discard block |
||
1886 | 2006 | { |
1887 | 2007 | $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
1888 | 2008 | } |
1889 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
2009 | + if ($this->Debug) |
|
2010 | + { |
|
2011 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
2012 | + } |
|
1890 | 2013 | return $this->query($sql,$line,$file,0,-1,$inputarr); |
1891 | 2014 | } |
1892 | 2015 | |
@@ -1907,8 +2030,14 @@ discard block |
||
1907 | 2030 | */ |
1908 | 2031 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1909 | 2032 | { |
1910 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
1911 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2033 | + if ($this->Debug) |
|
2034 | + { |
|
2035 | + echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
2036 | + } |
|
2037 | + if (!$table_def) |
|
2038 | + { |
|
2039 | + $table_def = $this->get_table_definitions($app,$table); |
|
2040 | + } |
|
1912 | 2041 | |
1913 | 2042 | $blobs2update = array(); |
1914 | 2043 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1917,7 +2046,10 @@ discard block |
||
1917 | 2046 | { |
1918 | 2047 | case 'sapdb': |
1919 | 2048 | case 'maxdb': |
1920 | - if ($use_prepared_statement) break; |
|
2049 | + if ($use_prepared_statement) |
|
2050 | + { |
|
2051 | + break; |
|
2052 | + } |
|
1921 | 2053 | // check if data contains any LONG columns |
1922 | 2054 | foreach($data as $col => $val) |
1923 | 2055 | { |
@@ -1942,12 +2074,20 @@ discard block |
||
1942 | 2074 | if (!empty($data)) |
1943 | 2075 | { |
1944 | 2076 | $inputarr = false; |
1945 | - if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
2077 | + if ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
2078 | + { |
|
2079 | + // eg. MaxDB |
|
1946 | 2080 | { |
1947 | - $this->Link_ID->Param(false); // reset param-counter |
|
2081 | + $this->Link_ID->Param(false); |
|
2082 | + } |
|
2083 | + // reset param-counter |
|
1948 | 2084 | foreach($data as $col => $val) |
1949 | 2085 | { |
1950 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
2086 | + if (!isset($table_def['fd'][$col])) |
|
2087 | + { |
|
2088 | + continue; |
|
2089 | + } |
|
2090 | + // ignore columns not in this table |
|
1951 | 2091 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
1952 | 2092 | } |
1953 | 2093 | $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
@@ -1965,7 +2105,10 @@ discard block |
||
1965 | 2105 | $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
1966 | 2106 | } |
1967 | 2107 | $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
1968 | - if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
2108 | + if ($this->Debug) |
|
2109 | + { |
|
2110 | + echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
2111 | + } |
|
1969 | 2112 | } |
1970 | 2113 | // if we have any blobs to update, we do so now |
1971 | 2114 | if (($ret || !count($data)) && count($blobs2update)) |
@@ -1973,8 +2116,14 @@ discard block |
||
1973 | 2116 | foreach($blobs2update as $col => $val) |
1974 | 2117 | { |
1975 | 2118 | $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
1976 | - if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
1977 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
2119 | + if ($this->Debug) |
|
2120 | + { |
|
2121 | + echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
2122 | + } |
|
2123 | + if (!$ret) |
|
2124 | + { |
|
2125 | + throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
2126 | + } |
|
1978 | 2127 | } |
1979 | 2128 | } |
1980 | 2129 | return $ret; |
@@ -1995,7 +2144,10 @@ discard block |
||
1995 | 2144 | */ |
1996 | 2145 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
1997 | 2146 | { |
1998 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2147 | + if (!$table_def) |
|
2148 | + { |
|
2149 | + $table_def = $this->get_table_definitions($app,$table); |
|
2150 | + } |
|
1999 | 2151 | |
2000 | 2152 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
2001 | 2153 | { |
@@ -2027,19 +2179,29 @@ discard block |
||
2027 | 2179 | */ |
2028 | 2180 | function expression($table_def/*,$args, ...*/) |
2029 | 2181 | { |
2030 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
2182 | + if (!is_array($table_def)) |
|
2183 | + { |
|
2184 | + $table_def = $this->get_table_definitions(true,$table_def); |
|
2185 | + } |
|
2031 | 2186 | $sql = ''; |
2032 | 2187 | $ignore_next = 0; |
2033 | 2188 | foreach(func_get_args() as $n => $arg) |
2034 | 2189 | { |
2035 | - if ($n < 1) continue; // table-name |
|
2190 | + if ($n < 1) |
|
2191 | + { |
|
2192 | + continue; |
|
2193 | + } |
|
2194 | + // table-name |
|
2036 | 2195 | |
2037 | 2196 | if ($ignore_next) |
2038 | 2197 | { |
2039 | 2198 | --$ignore_next; |
2040 | 2199 | continue; |
2041 | 2200 | } |
2042 | - if (is_null($arg)) $arg = False; |
|
2201 | + if (is_null($arg)) |
|
2202 | + { |
|
2203 | + $arg = False; |
|
2204 | + } |
|
2043 | 2205 | |
2044 | 2206 | switch(gettype($arg)) |
2045 | 2207 | { |
@@ -2079,9 +2241,15 @@ discard block |
||
2079 | 2241 | */ |
2080 | 2242 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
2081 | 2243 | { |
2082 | - 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"; |
|
2244 | + if ($this->Debug) |
|
2245 | + { |
|
2246 | + echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
2247 | + } |
|
2083 | 2248 | |
2084 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2249 | + if (!$table_def) |
|
2250 | + { |
|
2251 | + $table_def = $this->get_table_definitions($app,$table); |
|
2252 | + } |
|
2085 | 2253 | if (is_array($cols)) |
2086 | 2254 | { |
2087 | 2255 | $cols = implode(',',$cols); |
@@ -2097,16 +2265,28 @@ discard block |
||
2097 | 2265 | $sql = "SELECT $cols FROM $table $join"; |
2098 | 2266 | |
2099 | 2267 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
2100 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2268 | + if ($where) |
|
2269 | + { |
|
2270 | + $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2271 | + } |
|
2101 | 2272 | |
2102 | - if ($append) $sql .= ' '.$append; |
|
2273 | + if ($append) |
|
2274 | + { |
|
2275 | + $sql .= ' '.$append; |
|
2276 | + } |
|
2103 | 2277 | |
2104 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
2278 | + if ($this->Debug) |
|
2279 | + { |
|
2280 | + echo "<p>sql='$sql'</p>"; |
|
2281 | + } |
|
2105 | 2282 | |
2106 | - if ($line === false && $file === false) // call by union, to return the sql rather then run the query |
|
2283 | + if ($line === false && $file === false) |
|
2284 | + { |
|
2285 | + // call by union, to return the sql rather then run the query |
|
2107 | 2286 | { |
2108 | 2287 | return $sql; |
2109 | 2288 | } |
2289 | + } |
|
2110 | 2290 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
2111 | 2291 | } |
2112 | 2292 | |
@@ -2127,7 +2307,10 @@ discard block |
||
2127 | 2307 | */ |
2128 | 2308 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
2129 | 2309 | { |
2130 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2310 | + if ($this->Debug) |
|
2311 | + { |
|
2312 | + echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2313 | + } |
|
2131 | 2314 | |
2132 | 2315 | $union = array(); |
2133 | 2316 | foreach($selects as $select) |
@@ -2148,9 +2331,15 @@ discard block |
||
2148 | 2331 | } |
2149 | 2332 | $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
2150 | 2333 | |
2151 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2334 | + if ($order_by) |
|
2335 | + { |
|
2336 | + $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2337 | + } |
|
2152 | 2338 | |
2153 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
2339 | + if ($this->Debug) |
|
2340 | + { |
|
2341 | + echo "<p>sql='$sql'</p>"; |
|
2342 | + } |
|
2154 | 2343 | |
2155 | 2344 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
2156 | 2345 | } |
@@ -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 .... |
@@ -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 | { |
@@ -552,35 +579,53 @@ discard block |
||
552 | 579 | } |
553 | 580 | if (substr($line,0,7) == 'table: ') |
554 | 581 | { |
555 | - if ($rows) // flush pending rows of last table |
|
582 | + if ($rows) |
|
583 | + { |
|
584 | + // flush pending rows of last table |
|
556 | 585 | { |
557 | 586 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
558 | 587 | } |
588 | + } |
|
559 | 589 | $rows = array(); |
560 | 590 | $table = substr($line,7); |
561 | - if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
591 | + if (!isset($this->schemas[$table])) |
|
592 | + { |
|
593 | + $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
594 | + } |
|
562 | 595 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
563 | 596 | |
564 | 597 | $cols = self::csv_split($line=fgets($f)); ++$n; |
565 | 598 | $blobs = array(); |
566 | 599 | foreach($this->schemas[$table]['fd'] as $col => $data) |
567 | 600 | { |
568 | - if ($data['type'] == 'blob') $blobs[] = $col; |
|
601 | + if ($data['type'] == 'blob') |
|
602 | + { |
|
603 | + $blobs[] = $col; |
|
604 | + } |
|
569 | 605 | } |
570 | 606 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
571 | 607 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
572 | 608 | $bools = array(); |
573 | 609 | foreach($this->schemas[$table]['fd'] as $col => $def) |
574 | 610 | { |
575 | - if ($def['type'] === 'bool') $bools[] = $col; |
|
611 | + if ($def['type'] === 'bool') |
|
612 | + { |
|
613 | + $bools[] = $col; |
|
614 | + } |
|
576 | 615 | } |
577 | 616 | |
578 | - if (feof($f)) break; |
|
617 | + if (feof($f)) |
|
618 | + { |
|
619 | + break; |
|
620 | + } |
|
579 | 621 | continue; |
580 | 622 | } |
581 | - if ($table) // do we already reached the data part |
|
623 | + if ($table) |
|
624 | + { |
|
625 | + // do we already reached the data part |
|
582 | 626 | { |
583 | 627 | $import = true; |
628 | + } |
|
584 | 629 | $data = self::csv_split($line, $cols, $blobs, $bools); |
585 | 630 | |
586 | 631 | if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
@@ -616,7 +661,10 @@ discard block |
||
616 | 661 | { |
617 | 662 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
618 | 663 | unset($data[$insert_n_rows]); |
619 | - if ($auto_id) unset($data[$auto_id]); |
|
664 | + if ($auto_id) |
|
665 | + { |
|
666 | + unset($data[$auto_id]); |
|
667 | + } |
|
620 | 668 | $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
621 | 669 | } |
622 | 670 | else |
@@ -637,10 +685,13 @@ discard block |
||
637 | 685 | } |
638 | 686 | } |
639 | 687 | } |
640 | - if ($rows) // flush pending rows |
|
688 | + if ($rows) |
|
689 | + { |
|
690 | + // flush pending rows |
|
641 | 691 | { |
642 | 692 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
643 | 693 | } |
694 | + } |
|
644 | 695 | // updated the sequences, if the DB uses them |
645 | 696 | foreach($this->schemas as $table => $schema) |
646 | 697 | { |
@@ -698,9 +749,13 @@ discard block |
||
698 | 749 | while($file = $list[0]) |
699 | 750 | { |
700 | 751 | if(is_dir($file) && $file != '.' && $file != '..') |
701 | - self::remove_dir_content($dir.'/'.$file); |
|
752 | + { |
|
753 | + self::remove_dir_content($dir.'/'.$file); |
|
754 | + } |
|
702 | 755 | if(is_file($file) && $file != '.' && $file != '..') |
703 | - unlink($dir.'/'.$file); |
|
756 | + { |
|
757 | + unlink($dir.'/'.$file); |
|
758 | + } |
|
704 | 759 | array_shift($list); |
705 | 760 | } |
706 | 761 | //rmdir($dir); // dont remove own dir |
@@ -726,7 +781,9 @@ discard block |
||
726 | 781 | */ |
727 | 782 | public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
728 | 783 | { |
729 | - if (function_exists('str_getcsv')) // php5.3+ |
|
784 | + if (function_exists('str_getcsv')) |
|
785 | + { |
|
786 | + // php5.3+ |
|
730 | 787 | { |
731 | 788 | // we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings |
732 | 789 | // str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes) |
@@ -736,6 +793,7 @@ discard block |
||
736 | 793 | '\\"' => '""', |
737 | 794 | '\\n' => "\n", |
738 | 795 | '\\r' => "\r")), ',', '"', '\0'); |
796 | + } |
|
739 | 797 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
740 | 798 | foreach($fields as &$field) |
741 | 799 | { |
@@ -752,9 +810,12 @@ discard block |
||
752 | 810 | break; |
753 | 811 | } |
754 | 812 | } |
755 | - if ($keys) // if string keys are to be used --> combine keys and values |
|
813 | + if ($keys) |
|
814 | + { |
|
815 | + // if string keys are to be used --> combine keys and values |
|
756 | 816 | { |
757 | 817 | $fields = array_combine($keys, $fields); |
818 | + } |
|
758 | 819 | // base64-decode blob columns, if they are base64 encoded |
759 | 820 | foreach($blobs as $key) |
760 | 821 | { |
@@ -903,7 +964,11 @@ discard block |
||
903 | 964 | |
904 | 965 | foreach($this->schemas as $table => $schema) |
905 | 966 | { |
906 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
967 | + if (in_array($table,$this->exclude_tables)) |
|
968 | + { |
|
969 | + continue; |
|
970 | + } |
|
971 | + // dont backup |
|
907 | 972 | |
908 | 973 | // do we have a primary key? |
909 | 974 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -929,8 +994,14 @@ discard block |
||
929 | 994 | empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC', |
930 | 995 | false, self::ROW_CHUNK) as $row) |
931 | 996 | { |
932 | - if (!empty($pk)) $max = $row[$pk]; |
|
933 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
997 | + if (!empty($pk)) |
|
998 | + { |
|
999 | + $max = $row[$pk]; |
|
1000 | + } |
|
1001 | + if ($total === 0) |
|
1002 | + { |
|
1003 | + fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
1004 | + } |
|
934 | 1005 | |
935 | 1006 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
936 | 1007 | fwrite($f,implode(',',$row)."\n"); |
@@ -940,21 +1011,30 @@ discard block |
||
940 | 1011 | } |
941 | 1012 | while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
942 | 1013 | |
943 | - if (!$pk) $this->db->rollback_lock($table); |
|
1014 | + if (!$pk) |
|
1015 | + { |
|
1016 | + $this->db->rollback_lock($table); |
|
1017 | + } |
|
944 | 1018 | } |
945 | 1019 | |
946 | 1020 | // let apps know that backup is finished |
947 | 1021 | Api\Hooks::process('backup_finished', array(), true); |
948 | 1022 | |
949 | - if(!$zippresent) // save without files |
|
1023 | + if(!$zippresent) |
|
1024 | + { |
|
1025 | + // save without files |
|
950 | 1026 | { |
951 | 1027 | if ($this->backup_files) |
952 | 1028 | { |
953 | 1029 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
1030 | + } |
|
954 | 1031 | } |
955 | 1032 | |
956 | 1033 | fclose($f); |
957 | - if (file_exists($name)) unlink($name); |
|
1034 | + if (file_exists($name)) |
|
1035 | + { |
|
1036 | + unlink($name); |
|
1037 | + } |
|
958 | 1038 | return TRUE; |
959 | 1039 | } |
960 | 1040 | // save files .... |
@@ -966,9 +1046,12 @@ discard block |
||
966 | 1046 | //echo substr($file,strlen($dir)+1).'<br>'; |
967 | 1047 | //echo $file.'<br>'; |
968 | 1048 | $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
969 | - if(($count++) == 100) { // the file descriptor limit |
|
1049 | + if(($count++) == 100) |
|
1050 | + { |
|
1051 | +// the file descriptor limit |
|
970 | 1052 | $zip->close(); |
971 | - if(($zip = new ZipArchive())) { |
|
1053 | + if(($zip = new ZipArchive())) |
|
1054 | + { |
|
972 | 1055 | $zip->open($filename); |
973 | 1056 | $count =0; |
974 | 1057 | } |
@@ -993,15 +1076,21 @@ discard block |
||
993 | 1076 | { |
994 | 1077 | //chdir($f); |
995 | 1078 | //echo "Processing $f <br>"; |
996 | - if ($path_name =='') $path_name = $f; |
|
1079 | + if ($path_name =='') |
|
1080 | + { |
|
1081 | + $path_name = $f; |
|
1082 | + } |
|
997 | 1083 | $tlist = scandir($f); |
998 | 1084 | $list = array(); |
999 | 1085 | $i = $cnt; |
1000 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1086 | + while($file = $tlist[0]) |
|
1087 | + { |
|
1088 | + // remove all '.' and '..' and transfer to $list |
|
1001 | 1089 | { |
1002 | 1090 | if($file == '.' || $file == '..') |
1003 | 1091 | { |
1004 | 1092 | array_shift($tlist); |
1093 | + } |
|
1005 | 1094 | } |
1006 | 1095 | elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
1007 | 1096 | { |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @var array |
51 | 51 | */ |
52 | 52 | var $exclude_tables = array( |
53 | - 'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables |
|
54 | - 'phpgw_anglemail', // email's cache |
|
55 | - 'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache |
|
53 | + 'egw_sessions', 'egw_app_sessions', 'phpgw_sessions', 'phpgw_app_sessions', // eGW's session-tables |
|
54 | + 'phpgw_anglemail', // email's cache |
|
55 | + 'egw_felamimail_cache', 'egw_felamimail_folderstatus', 'phpgw_felamimail_cache', 'phpgw_felamimail_folderstatus', // felamimail's cache |
|
56 | 56 | 'egw_phpfreechat', // as of the fieldnames of the table a restore would fail within egroupware, and chatcontent is of no particular intrest |
57 | 57 | ); |
58 | 58 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @var boolean |
86 | 86 | */ |
87 | - var $backup_files = false ; |
|
87 | + var $backup_files = false; |
|
88 | 88 | /** |
89 | 89 | * Reference to schema_proc's Api\Db object |
90 | 90 | * |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db)) |
101 | 101 | { |
102 | - $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
102 | + $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
103 | 103 | } |
104 | 104 | if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it |
105 | 105 | { |
@@ -117,21 +117,21 @@ discard block |
||
117 | 117 | { |
118 | 118 | if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table))) |
119 | 119 | { |
120 | - 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())) |
|
120 | + 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 | 121 | { |
122 | 122 | error_log(__METHOD__."->"."No files Directory set/found"); |
123 | 123 | } |
124 | - 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())) |
|
124 | + 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 | 125 | { |
126 | 126 | $this->backup_dir = $this->files_dir.'/db_backup'; |
127 | 127 | } |
128 | - $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(); |
|
129 | - $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table,'app_version',array('app_name'=>array('api','phpgwapi')), |
|
130 | - __LINE__,__FILE__,0,'ORDER BY app_name ASC')->fetchColumn(); |
|
128 | + $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(); |
|
129 | + $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table, 'app_version', array('app_name'=>array('api', 'phpgwapi')), |
|
130 | + __LINE__, __FILE__, 0, 'ORDER BY app_name ASC')->fetchColumn(); |
|
131 | 131 | // Backup settings |
132 | - $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(); |
|
132 | + $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 | 133 | // backup files too |
134 | - $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(); |
|
134 | + $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 | 135 | } |
136 | 136 | if (!$this->charset) $this->charset = 'utf-8'; |
137 | 137 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $this->backup_files = $GLOBALS['egw_info']['server']['backup_files']; |
147 | 147 | $this->charset = Api\Translation::charset(); |
148 | 148 | |
149 | - $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api'])?'api':'phpgwapi']['version']; |
|
149 | + $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api']) ? 'api' : 'phpgwapi']['version']; |
|
150 | 150 | } |
151 | 151 | // Set a default value if not set. |
152 | 152 | if (!isset($this->backup_mincount)) |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | { |
163 | 163 | mkdir($this->backup_dir); |
164 | 164 | } |
165 | - switch($this->db->Type) |
|
165 | + switch ($this->db->Type) |
|
166 | 166 | { |
167 | 167 | case 'sapdb': |
168 | 168 | case 'maxdb': |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param $reading =false opening for reading ('rb') or writing ('wb') |
180 | 180 | * @return string/resource/zip error-msg of file-handle |
181 | 181 | */ |
182 | - function fopen_backup($name=false,$reading=false) |
|
182 | + function fopen_backup($name = false, $reading = false) |
|
183 | 183 | { |
184 | 184 | //echo "function fopen_backup($name,$reading)<br>"; // ! |
185 | 185 | if (!$name) |
@@ -188,27 +188,27 @@ discard block |
||
188 | 188 | if (!$this->backup_dir || !is_writable($this->backup_dir)) |
189 | 189 | { |
190 | 190 | //echo ' -> !$this->backup_dir || !is_writable($this->backup_dir)<br>'; // ! |
191 | - return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir); |
|
191 | + return lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir); |
|
192 | 192 | } |
193 | 193 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
194 | 194 | } |
195 | 195 | else // remove the extension, to use the correct wrapper based on the extension |
196 | 196 | { |
197 | 197 | //echo '-> else<br>'; // ! |
198 | - $name = preg_replace('/\.(bz2|gz)$/i','',$name); |
|
198 | + $name = preg_replace('/\.(bz2|gz)$/i', '', $name); |
|
199 | 199 | } |
200 | 200 | $mode = $reading ? 'rb' : 'wb'; |
201 | - list( , $type) = explode('.', basename($name)); |
|
202 | - if($type == 'zip' && $reading && $this->backup_files) |
|
201 | + list(, $type) = explode('.', basename($name)); |
|
202 | + if ($type == 'zip' && $reading && $this->backup_files) |
|
203 | 203 | { |
204 | 204 | //echo '-> $type == "zip" && $reading<br>'; // ! |
205 | - if(!class_exists('ZipArchive', false)) |
|
205 | + if (!class_exists('ZipArchive', false)) |
|
206 | 206 | { |
207 | 207 | $this->backup_files = false; |
208 | 208 | //echo ' -> (new ZipArchive) == NULL<br>'; // ! |
209 | 209 | return lang("Cant open %1, needs ZipArchive", $name)."<br>\n"; |
210 | 210 | } |
211 | - if(!($f = fopen($name, $mode))) |
|
211 | + if (!($f = fopen($name, $mode))) |
|
212 | 212 | { |
213 | 213 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
214 | 214 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | } |
217 | 217 | return $f; |
218 | 218 | } |
219 | - if(class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
219 | + if (class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
220 | 220 | { |
221 | 221 | //echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'<br>'; // ! |
222 | - if(!($f = fopen($name, $mode))) |
|
222 | + if (!($f = fopen($name, $mode))) |
|
223 | 223 | { |
224 | 224 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
225 | 225 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | } |
228 | 228 | return $f; |
229 | 229 | } |
230 | - if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
231 | - !($f = fopen("compress.zlib://$name.gz",$mode)) && |
|
232 | - !($f = fopen($name,$mode)) |
|
230 | + if (!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
231 | + !($f = fopen("compress.zlib://$name.gz", $mode)) && |
|
232 | + !($f = fopen($name, $mode)) |
|
233 | 233 | ) |
234 | 234 | { |
235 | 235 | //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>'; // ! |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | /* Search the backup directory for matching files. */ |
257 | 257 | $handle = @opendir($this->backup_dir); |
258 | 258 | $files = array(); |
259 | - while($handle && ($file = readdir($handle))) |
|
259 | + while ($handle && ($file = readdir($handle))) |
|
260 | 260 | { |
261 | 261 | /* Filter for only the files with the regular name (un-renamed). |
262 | 262 | * Leave special backup files (renamed) in place. |
263 | 263 | * Note that this also excludes "." and "..". |
264 | 264 | */ |
265 | - if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/",$file)) |
|
265 | + if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/", $file)) |
|
266 | 266 | { |
267 | 267 | $files[filectime($this->backup_dir.'/'.$file)] = $file; |
268 | 268 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | /* Sort the files by ctime. */ |
273 | 273 | krsort($files); |
274 | 274 | $count = 0; |
275 | - foreach($files as $file) |
|
275 | + foreach ($files as $file) |
|
276 | 276 | { |
277 | 277 | if ($count >= $this->backup_mincount)// |
278 | 278 | { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | array_push($files_return, $file); |
283 | 283 | } |
284 | 284 | } |
285 | - $count ++; |
|
285 | + $count++; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
@@ -292,13 +292,13 @@ discard block |
||
292 | 292 | * @param int $minCount Minimum number of backups to keep. |
293 | 293 | * @param boolean $backupFiles include files in backup or not, default dont change! |
294 | 294 | */ |
295 | - function saveConfig($minCount,$backupFiles=null) |
|
295 | + function saveConfig($minCount, $backupFiles = null) |
|
296 | 296 | { |
297 | - Api\Config::save_value('backup_mincount',$this->backup_mincount=(int)$minCount,'phpgwapi'); |
|
297 | + Api\Config::save_value('backup_mincount', $this->backup_mincount = (int)$minCount, 'phpgwapi'); |
|
298 | 298 | |
299 | 299 | if (!is_null($backupFiles)) |
300 | 300 | { |
301 | - Api\Config::save_value('backup_files',$this->backup_files=(boolean)$backupFiles,'phpgwapi'); |
|
301 | + Api\Config::save_value('backup_files', $this->backup_files = (boolean)$backupFiles, 'phpgwapi'); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | 'httpproxy_server_password', |
322 | 322 | 'system_charset', |
323 | 323 | 'usecookies', |
324 | - 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
324 | + 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
325 | 325 | ); |
326 | 326 | |
327 | 327 | /** |
@@ -335,20 +335,20 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @returns An empty string or an error message in case of failure. |
337 | 337 | */ |
338 | - function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10) |
|
338 | + function restore($f, $convert_to_system_charset = true, $filename = '', $protect_system_config = true, $insert_n_rows = 10) |
|
339 | 339 | { |
340 | 340 | @set_time_limit(0); |
341 | - ini_set('auto_detect_line_endings',true); |
|
341 | + ini_set('auto_detect_line_endings', true); |
|
342 | 342 | |
343 | - if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
343 | + if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
344 | 344 | |
345 | 345 | if ($protect_system_config) |
346 | 346 | { |
347 | 347 | $system_config = array(); |
348 | - foreach($this->db->select(self::TABLE,'*',array( |
|
348 | + foreach ($this->db->select(self::TABLE, '*', array( |
|
349 | 349 | 'config_app' => 'phpgwapi', |
350 | 350 | 'config_name' => self::$system_config, |
351 | - ),__LINE__,__FILE__) as $row) |
|
351 | + ), __LINE__, __FILE__) as $row) |
|
352 | 352 | { |
353 | 353 | $system_config[] = $row; |
354 | 354 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | // as MySQL 5.7+ has sql_mode STRICT_(ALL|TRANS)_TABLES enabled by default, |
358 | 358 | // it will no longer restore '0000-00-00 00:00:00' in timestamps it created before, |
359 | 359 | // so switching strict-mode off temporary for the restore (we dont create these!) |
360 | - if (substr($this->db->Type,0,5) == 'mysql') |
|
360 | + if (substr($this->db->Type, 0, 5) == 'mysql') |
|
361 | 361 | { |
362 | 362 | $this->db->query("SET SESSION sql_mode=(SELECT REPLACE(REPLACE(@@sql_mode,'STRICT_ALL_TABLES',''),'STRICT_TRANS_TABLES',''))", __LINE__, __FILE__); |
363 | 363 | } |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | |
369 | 369 | |
370 | 370 | // drop all existing tables |
371 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
371 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
372 | 372 | { |
373 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
374 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
373 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
374 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
375 | 375 | { |
376 | 376 | continue; |
377 | 377 | } |
378 | 378 | $this->schema_proc->DropTable($table); |
379 | 379 | } |
380 | 380 | // it could be an old backup |
381 | - list( , $type) = explode('.', basename($filename)); |
|
381 | + list(, $type) = explode('.', basename($filename)); |
|
382 | 382 | $dir = $this->files_dir; // $GLOBALS['egw_info']['server']['files_dir']; |
383 | 383 | // we may have to clean up old backup - left overs |
384 | 384 | if (is_dir($dir.'/database_backup')) |
@@ -391,20 +391,20 @@ discard block |
||
391 | 391 | $name = ""; |
392 | 392 | $zip = NULL; |
393 | 393 | $_f = NULL; |
394 | - if($type == 'zip') |
|
394 | + if ($type == 'zip') |
|
395 | 395 | { |
396 | 396 | // has already been verified to be available in fopen_backup |
397 | 397 | $zip = new ZipArchive; |
398 | - if(($zip->open($filename)) !== TRUE) |
|
398 | + if (($zip->open($filename)) !== TRUE) |
|
399 | 399 | { |
400 | 400 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
401 | 401 | } |
402 | - self::remove_dir_content($dir); // removes the files-dir |
|
402 | + self::remove_dir_content($dir); // removes the files-dir |
|
403 | 403 | $zip->extractTo($dir); |
404 | 404 | $_f = $f; |
405 | 405 | $list = $this->get_file_list($dir.'/database_backup/'); |
406 | 406 | $name = $dir.'/database_backup/'.basename($list[0]); |
407 | - if(!($f = fopen($name, 'rb'))) |
|
407 | + if (!($f = fopen($name, 'rb'))) |
|
408 | 408 | { |
409 | 409 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
410 | 410 | } |
@@ -415,56 +415,56 @@ discard block |
||
415 | 415 | { |
416 | 416 | $this->db->insert(Api\Config::TABLE, array( |
417 | 417 | 'config_value' => $this->schema_proc->system_charset, |
418 | - ),array( |
|
418 | + ), array( |
|
419 | 419 | 'config_app' => 'phpgwapi', |
420 | 420 | 'config_name' => 'system_charset', |
421 | - ),__LINE__,__FILE__); |
|
421 | + ), __LINE__, __FILE__); |
|
422 | 422 | } |
423 | 423 | // restore protected system config |
424 | 424 | if ($protect_system_config) |
425 | 425 | { |
426 | - foreach($system_config as $row) |
|
426 | + foreach ($system_config as $row) |
|
427 | 427 | { |
428 | - $this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array( |
|
428 | + $this->db->insert(self::TABLE, array('config_value'=>$row['config_value']), array( |
|
429 | 429 | 'config_name' => $row['config_name'], |
430 | 430 | 'config_app' => $row['config_app'], |
431 | - ),__LINE__,__FILE__); |
|
431 | + ), __LINE__, __FILE__); |
|
432 | 432 | } |
433 | 433 | // check and reset cookie configuration, if it does not match current enviroment |
434 | 434 | // if $_SERVER[HTTP_HOST] does not end with cookiedomain --> delete cookiedomain |
435 | - if (($cookiedomain = $this->db->select(self::TABLE,'config_value',array( |
|
435 | + if (($cookiedomain = $this->db->select(self::TABLE, 'config_value', array( |
|
436 | 436 | 'config_app' => 'phpgwapi', |
437 | 437 | 'config_name' => 'cookiedomain', |
438 | - ),__LINE__,__FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
439 | - (list($hostname) = explode(':',$_SERVER['HTTP_HOST'])) && |
|
440 | - substr($hostname,-strlen($cookiedomain) !== $cookiedomain)) |
|
438 | + ), __LINE__, __FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
439 | + (list($hostname) = explode(':', $_SERVER['HTTP_HOST'])) && |
|
440 | + substr($hostname, -strlen($cookiedomain) !== $cookiedomain)) |
|
441 | 441 | { |
442 | - $this->db->delete(self::TABLE,array( |
|
442 | + $this->db->delete(self::TABLE, array( |
|
443 | 443 | 'config_app' => 'phpgwapi', |
444 | 444 | 'config_name' => 'cookiedomain', |
445 | - ),__LINE__,__FILE__); |
|
445 | + ), __LINE__, __FILE__); |
|
446 | 446 | } |
447 | 447 | // if configured webserver_url does NOT start with cookiepath --> delete cookiepath |
448 | - if (($cookiepath = $this->db->select(self::TABLE,'config_value',array( |
|
448 | + if (($cookiepath = $this->db->select(self::TABLE, 'config_value', array( |
|
449 | 449 | 'config_app' => 'phpgwapi', |
450 | 450 | 'config_name' => 'cookiepath', |
451 | - ),__LINE__,__FILE__)->fetchColumn()) && |
|
452 | - substr(parse_url($system_config['webserver_url'], PHP_URL_PATH),0,strlen($cookiepath) !== $cookiepath)) |
|
451 | + ), __LINE__, __FILE__)->fetchColumn()) && |
|
452 | + substr(parse_url($system_config['webserver_url'], PHP_URL_PATH), 0, strlen($cookiepath) !== $cookiepath)) |
|
453 | 453 | { |
454 | - $this->db->delete(self::TABLE,array( |
|
454 | + $this->db->delete(self::TABLE, array( |
|
455 | 455 | 'config_app' => 'phpgwapi', |
456 | 456 | 'config_name' => 'cookiepath', |
457 | - ),__LINE__,__FILE__); |
|
457 | + ), __LINE__, __FILE__); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | // zip? |
461 | - if($type == 'zip') |
|
461 | + if ($type == 'zip') |
|
462 | 462 | { |
463 | 463 | fclose($f); |
464 | 464 | unlink($name); |
465 | 465 | rmdir($dir.'/database_backup'); |
466 | 466 | } |
467 | - if (substr($this->db->Type,0,5) != 'mysql') |
|
467 | + if (substr($this->db->Type, 0, 5) != 'mysql') |
|
468 | 468 | { |
469 | 469 | if (!$this->db->transaction_commit()) |
470 | 470 | { |
@@ -499,26 +499,26 @@ discard block |
||
499 | 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 |
500 | 500 | * @returns int number of rows read from csv file |
501 | 501 | */ |
502 | - function db_restore($f, $insert_n_rows=10) |
|
502 | + function db_restore($f, $insert_n_rows = 10) |
|
503 | 503 | { |
504 | 504 | $convert_to_system_charset = true; |
505 | 505 | $table = null; |
506 | 506 | $n = 0; |
507 | 507 | $rows = array(); |
508 | - while(!feof($f)) |
|
508 | + while (!feof($f)) |
|
509 | 509 | { |
510 | 510 | $line = trim(fgets($f)); ++$n; |
511 | 511 | |
512 | 512 | if (empty($line)) continue; |
513 | 513 | |
514 | - if (substr($line,0,9) == 'version: ') |
|
514 | + if (substr($line, 0, 9) == 'version: ') |
|
515 | 515 | { |
516 | 516 | // currenty not used: $api_version = trim(substr($line,9)); |
517 | 517 | continue; |
518 | 518 | } |
519 | - if (substr($line,0,9) == 'charset: ') |
|
519 | + if (substr($line, 0, 9) == 'charset: ') |
|
520 | 520 | { |
521 | - $charset = trim(substr($line,9)); |
|
521 | + $charset = trim(substr($line, 9)); |
|
522 | 522 | // needed if mbstring.func_overload > 0, else eg. substr does not work with non ascii chars |
523 | 523 | $ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset'; |
524 | 524 | @ini_set($ini_default_charset, $charset); |
@@ -526,18 +526,18 @@ discard block |
||
526 | 526 | // check if we really need to convert the charset, as it's not perfect and can do some damage |
527 | 527 | if ($convert_to_system_charset && !strcasecmp($this->schema_proc->system_charset, $charset)) |
528 | 528 | { |
529 | - $convert_to_system_charset = false; // no conversation necessary |
|
529 | + $convert_to_system_charset = false; // no conversation necessary |
|
530 | 530 | } |
531 | 531 | continue; |
532 | 532 | } |
533 | - if (substr($line,0,8) == 'schema: ') |
|
533 | + if (substr($line, 0, 8) == 'schema: ') |
|
534 | 534 | { |
535 | 535 | // create the tables in the backup set |
536 | - $this->schemas = json_php_unserialize(trim(substr($line,8))); |
|
537 | - foreach($this->schemas as $table_name => $schema) |
|
536 | + $this->schemas = json_php_unserialize(trim(substr($line, 8))); |
|
537 | + foreach ($this->schemas as $table_name => $schema) |
|
538 | 538 | { |
539 | 539 | // if column is longtext in current schema, convert text to longtext, in case user already updated column |
540 | - foreach($schema['fd'] as $col => &$def) |
|
540 | + foreach ($schema['fd'] as $col => &$def) |
|
541 | 541 | { |
542 | 542 | if ($def['type'] == 'text' && $this->db->get_column_attribute($col, $table_name, true, 'type') == 'longtext') |
543 | 543 | { |
@@ -549,27 +549,27 @@ discard block |
||
549 | 549 | } |
550 | 550 | continue; |
551 | 551 | } |
552 | - if (substr($line,0,7) == 'table: ') |
|
552 | + if (substr($line, 0, 7) == 'table: ') |
|
553 | 553 | { |
554 | 554 | if ($rows) // flush pending rows of last table |
555 | 555 | { |
556 | 556 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
557 | 557 | } |
558 | 558 | $rows = array(); |
559 | - $table = substr($line,7); |
|
559 | + $table = substr($line, 7); |
|
560 | 560 | if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
561 | 561 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
562 | 562 | |
563 | - $cols = self::csv_split($line=fgets($f)); ++$n; |
|
563 | + $cols = self::csv_split($line = fgets($f)); ++$n; |
|
564 | 564 | $blobs = array(); |
565 | - foreach($this->schemas[$table]['fd'] as $col => $data) |
|
565 | + foreach ($this->schemas[$table]['fd'] as $col => $data) |
|
566 | 566 | { |
567 | 567 | if ($data['type'] == 'blob') $blobs[] = $col; |
568 | 568 | } |
569 | 569 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
570 | 570 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
571 | 571 | $bools = array(); |
572 | - foreach($this->schemas[$table]['fd'] as $col => $def) |
|
572 | + foreach ($this->schemas[$table]['fd'] as $col => $def) |
|
573 | 573 | { |
574 | 574 | if ($def['type'] === 'bool') $bools[] = $col; |
575 | 575 | } |
@@ -582,15 +582,15 @@ discard block |
||
582 | 582 | $import = true; |
583 | 583 | $data = self::csv_split($line, $cols, $blobs, $bools); |
584 | 584 | |
585 | - if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
|
585 | + if ($table == 'egw_async' && in_array('##last-check-run##', $data)) |
|
586 | 586 | { |
587 | 587 | //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"; |
588 | 588 | //echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
589 | 589 | $import = false; |
590 | 590 | } |
591 | - if (in_array($table,$this->exclude_tables)) |
|
591 | + if (in_array($table, $this->exclude_tables)) |
|
592 | 592 | { |
593 | - echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n"; |
|
593 | + echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n"; |
|
594 | 594 | $import = false; // dont restore data of excluded tables |
595 | 595 | } |
596 | 596 | if ($import) |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | { |
600 | 600 | if ($convert_to_system_charset) |
601 | 601 | { |
602 | - $data = Api\Translation::convert($data,$charset); |
|
602 | + $data = Api\Translation::convert($data, $charset); |
|
603 | 603 | } |
604 | 604 | if ($insert_n_rows > 1) |
605 | 605 | { |
@@ -611,27 +611,27 @@ discard block |
||
611 | 611 | } |
612 | 612 | } |
613 | 613 | // update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence) |
614 | - elseif(!is_numeric($insert_n_rows)) |
|
614 | + elseif (!is_numeric($insert_n_rows)) |
|
615 | 615 | { |
616 | 616 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
617 | 617 | unset($data[$insert_n_rows]); |
618 | 618 | if ($auto_id) unset($data[$auto_id]); |
619 | - $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
619 | + $this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
620 | 620 | } |
621 | 621 | else |
622 | 622 | { |
623 | 623 | try { |
624 | - $this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
624 | + $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
625 | 625 | } |
626 | - catch(Exception\InvalidSql $e) { |
|
626 | + catch (Exception\InvalidSql $e) { |
|
627 | 627 | echo "<p>".$e->getMessage()."</p>\n"; |
628 | 628 | } |
629 | 629 | } |
630 | 630 | } |
631 | 631 | else |
632 | 632 | { |
633 | - 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"; |
|
634 | - echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
|
633 | + 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"; |
|
634 | + echo 'data=<pre>'.print_r($data, true)."</pre>\n"; |
|
635 | 635 | } |
636 | 636 | } |
637 | 637 | } |
@@ -641,14 +641,14 @@ discard block |
||
641 | 641 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
642 | 642 | } |
643 | 643 | // updated the sequences, if the DB uses them |
644 | - foreach($this->schemas as $table => $schema) |
|
644 | + foreach ($this->schemas as $table => $schema) |
|
645 | 645 | { |
646 | - foreach($schema['fd'] as $column => $definition) |
|
646 | + foreach ($schema['fd'] as $column => $definition) |
|
647 | 647 | { |
648 | 648 | if ($definition['type'] == 'auto') |
649 | 649 | { |
650 | - $this->schema_proc->UpdateSequence($table,$column); |
|
651 | - break; // max. one per table |
|
650 | + $this->schema_proc->UpdateSequence($table, $column); |
|
651 | + break; // max. one per table |
|
652 | 652 | } |
653 | 653 | } |
654 | 654 | } |
@@ -671,15 +671,15 @@ discard block |
||
671 | 671 | try { |
672 | 672 | $this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema); |
673 | 673 | } |
674 | - catch(Exception\InvalidSql $e) |
|
674 | + catch (Exception\InvalidSql $e) |
|
675 | 675 | { |
676 | 676 | // try inserting them one by one, ignoring doublicates |
677 | - foreach($rows as $data) |
|
677 | + foreach ($rows as $data) |
|
678 | 678 | { |
679 | 679 | try { |
680 | 680 | $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema); |
681 | 681 | } |
682 | - catch(Exception\InvalidSql $e) { |
|
682 | + catch (Exception\InvalidSql $e) { |
|
683 | 683 | echo "<p>".$e->getMessage()."</p>\n"; |
684 | 684 | } |
685 | 685 | } |
@@ -694,11 +694,11 @@ discard block |
||
694 | 694 | private static function remove_dir_content($dir) |
695 | 695 | { |
696 | 696 | $list = scandir($dir); |
697 | - while($file = $list[0]) |
|
697 | + while ($file = $list[0]) |
|
698 | 698 | { |
699 | - if(is_dir($file) && $file != '.' && $file != '..') |
|
699 | + if (is_dir($file) && $file != '.' && $file != '..') |
|
700 | 700 | self::remove_dir_content($dir.'/'.$file); |
701 | - if(is_file($file) && $file != '.' && $file != '..') |
|
701 | + if (is_file($file) && $file != '.' && $file != '..') |
|
702 | 702 | unlink($dir.'/'.$file); |
703 | 703 | array_shift($list); |
704 | 704 | } |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups |
724 | 724 | * @return array |
725 | 725 | */ |
726 | - public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
|
726 | + public static function csv_split($line, $keys = null, $blobs = array(), $bools = array()) |
|
727 | 727 | { |
728 | 728 | if (function_exists('str_getcsv')) // php5.3+ |
729 | 729 | { |
@@ -736,9 +736,9 @@ discard block |
||
736 | 736 | '\\n' => "\n", |
737 | 737 | '\\r' => "\r")), ',', '"', '\0'); |
738 | 738 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
739 | - foreach($fields as &$field) |
|
739 | + foreach ($fields as &$field) |
|
740 | 740 | { |
741 | - switch($field) |
|
741 | + switch ($field) |
|
742 | 742 | { |
743 | 743 | case self::NULL_TOKEN: |
744 | 744 | $field = 'NULL'; |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | { |
756 | 756 | $fields = array_combine($keys, $fields); |
757 | 757 | // base64-decode blob columns, if they are base64 encoded |
758 | - foreach($blobs as $key) |
|
758 | + foreach ($blobs as $key) |
|
759 | 759 | { |
760 | 760 | if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false) |
761 | 761 | { |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | } |
764 | 764 | } |
765 | 765 | // decode bool columns, they might be 't'/'f' for old PostgreSQL backups |
766 | - foreach($bools as $key) |
|
766 | + foreach ($bools as $key) |
|
767 | 767 | { |
768 | 768 | $fields[$key] = Api\Db::from_bool($fields[$key]); |
769 | 769 | } |
@@ -771,11 +771,11 @@ discard block |
||
771 | 771 | return $fields; |
772 | 772 | } |
773 | 773 | // pre 5.3 implementation |
774 | - $fields = explode(',',trim($line)); |
|
774 | + $fields = explode(',', trim($line)); |
|
775 | 775 | |
776 | 776 | $str_pending = False; |
777 | 777 | $n = 0; |
778 | - foreach($fields as $field) |
|
778 | + foreach ($fields as $field) |
|
779 | 779 | { |
780 | 780 | if ($str_pending !== False) |
781 | 781 | { |
@@ -786,12 +786,12 @@ discard block |
||
786 | 786 | |
787 | 787 | if ($field[0] == '"') |
788 | 788 | { |
789 | - if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field)) |
|
789 | + if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field)) |
|
790 | 790 | { |
791 | 791 | $str_pending = $field; |
792 | 792 | continue; |
793 | 793 | } |
794 | - $arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1))); |
|
794 | + $arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1))); |
|
795 | 795 | } |
796 | 796 | elseif ($keys && strlen($field) > 26) |
797 | 797 | { |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * escape data for csv |
815 | 815 | */ |
816 | - public static function escape_data(&$data,$col,$defs) |
|
816 | + public static function escape_data(&$data, $col, $defs) |
|
817 | 817 | { |
818 | 818 | if (is_null($data)) |
819 | 819 | { |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | } |
822 | 822 | else |
823 | 823 | { |
824 | - switch($defs[$col]['type']) |
|
824 | + switch ($defs[$col]['type']) |
|
825 | 825 | { |
826 | 826 | case 'int': |
827 | 827 | case 'auto': |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | $data = (int)Api\Db::from_bool($data); |
837 | 837 | break; |
838 | 838 | default: |
839 | - $data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"'; |
|
839 | + $data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"'; |
|
840 | 840 | break; |
841 | 841 | } |
842 | 842 | } |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | * default of null limits memory usage if there is no primary key, by locking table and use ROW_CHUCK |
856 | 856 | * @todo use https://github.com/maennchen/ZipStream-PHP to not assemble all files in memmory |
857 | 857 | */ |
858 | - function backup($f, $lock_table=null) |
|
858 | + function backup($f, $lock_table = null) |
|
859 | 859 | { |
860 | 860 | //echo "function backup($f)<br>"; // ! |
861 | 861 | @set_time_limit(0); |
@@ -871,15 +871,15 @@ discard block |
||
871 | 871 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
872 | 872 | $filename = $name.'.zip'; |
873 | 873 | $zippresent = false; |
874 | - if(class_exists('ZipArchive') && $this->backup_files) |
|
874 | + if (class_exists('ZipArchive') && $this->backup_files) |
|
875 | 875 | { |
876 | 876 | $zip = new ZipArchive; |
877 | - if(is_object($zip)) |
|
877 | + if (is_object($zip)) |
|
878 | 878 | { |
879 | 879 | $zippresent = true; |
880 | 880 | //echo '-> is_object($zip); '.$filename.'<br>'; // ! |
881 | 881 | $res = $zip->open($filename, ZipArchive::CREATE); |
882 | - if($res !== TRUE) |
|
882 | + if ($res !== TRUE) |
|
883 | 883 | { |
884 | 884 | //echo ' -> !$res<br>'; // ! |
885 | 885 | return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n"; |
@@ -887,22 +887,22 @@ discard block |
||
887 | 887 | $file_list = $this->get_file_list($dir); |
888 | 888 | } |
889 | 889 | } |
890 | - fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
890 | + fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
891 | 891 | |
892 | - fwrite($f,"version: $this->api_version\n\n"); |
|
892 | + fwrite($f, "version: $this->api_version\n\n"); |
|
893 | 893 | |
894 | - fwrite($f,"charset: $this->charset\n\n"); |
|
894 | + fwrite($f, "charset: $this->charset\n\n"); |
|
895 | 895 | |
896 | - $this->schema_backup($f); // add the schema in a human readable form too |
|
896 | + $this->schema_backup($f); // add the schema in a human readable form too |
|
897 | 897 | |
898 | - fwrite($f,"\nschema: ".json_encode($this->schemas)."\n"); |
|
898 | + fwrite($f, "\nschema: ".json_encode($this->schemas)."\n"); |
|
899 | 899 | |
900 | 900 | // let apps know that backup is about to start |
901 | 901 | Api\Hooks::process('backup_starts', array(), true); |
902 | 902 | |
903 | - foreach($this->schemas as $table => $schema) |
|
903 | + foreach ($this->schemas as $table => $schema) |
|
904 | 904 | { |
905 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
905 | + if (in_array($table, $this->exclude_tables)) continue; // dont backup |
|
906 | 906 | |
907 | 907 | // do we have a primary key? |
908 | 908 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | do { |
919 | 919 | $num_rows = 0; |
920 | 920 | // querying only chunks for 10000 rows, to not run into memory limit on huge tables |
921 | - foreach($this->db->select($table, '*', |
|
921 | + foreach ($this->db->select($table, '*', |
|
922 | 922 | // limit by maximum primary key already received |
923 | 923 | empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']), |
924 | 924 | __LINE__, __FILE__, |
@@ -929,15 +929,15 @@ discard block |
||
929 | 929 | false, self::ROW_CHUNK) as $row) |
930 | 930 | { |
931 | 931 | if (!empty($pk)) $max = $row[$pk]; |
932 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
932 | + if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n"); |
|
933 | 933 | |
934 | 934 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
935 | - fwrite($f,implode(',',$row)."\n"); |
|
935 | + fwrite($f, implode(',', $row)."\n"); |
|
936 | 936 | ++$total; |
937 | 937 | ++$num_rows; |
938 | 938 | } |
939 | 939 | } |
940 | - while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
940 | + while ((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
941 | 941 | |
942 | 942 | if (!$pk) $this->db->rollback_lock($table); |
943 | 943 | } |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | // let apps know that backup is finished |
946 | 946 | Api\Hooks::process('backup_finished', array(), true); |
947 | 947 | |
948 | - if(!$zippresent) // save without files |
|
948 | + if (!$zippresent) // save without files |
|
949 | 949 | { |
950 | 950 | if ($this->backup_files) |
951 | 951 | { |
@@ -960,16 +960,16 @@ discard block |
||
960 | 960 | //echo $name.'<br>'; |
961 | 961 | $zip->addFile($name, 'database_backup/'.basename($name)); |
962 | 962 | $count = 1; |
963 | - foreach($file_list as $file) |
|
963 | + foreach ($file_list as $file) |
|
964 | 964 | { |
965 | 965 | //echo substr($file,strlen($dir)+1).'<br>'; |
966 | 966 | //echo $file.'<br>'; |
967 | - $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
|
968 | - if(($count++) == 100) { // the file descriptor limit |
|
967 | + $zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file); |
|
968 | + if (($count++) == 100) { // the file descriptor limit |
|
969 | 969 | $zip->close(); |
970 | - if(($zip = new ZipArchive())) { |
|
970 | + if (($zip = new ZipArchive())) { |
|
971 | 971 | $zip->open($filename); |
972 | - $count =0; |
|
972 | + $count = 0; |
|
973 | 973 | } |
974 | 974 | } |
975 | 975 | } |
@@ -992,17 +992,17 @@ discard block |
||
992 | 992 | { |
993 | 993 | //chdir($f); |
994 | 994 | //echo "Processing $f <br>"; |
995 | - if ($path_name =='') $path_name = $f; |
|
995 | + if ($path_name == '') $path_name = $f; |
|
996 | 996 | $tlist = scandir($f); |
997 | 997 | $list = array(); |
998 | 998 | $i = $cnt; |
999 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
999 | + while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1000 | 1000 | { |
1001 | - if($file == '.' || $file == '..') |
|
1001 | + if ($file == '.' || $file == '..') |
|
1002 | 1002 | { |
1003 | 1003 | array_shift($tlist); |
1004 | 1004 | } |
1005 | - elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
|
1005 | + elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false) |
|
1006 | 1006 | { |
1007 | 1007 | // skip activesync debug.txt on backupFiles |
1008 | 1008 | //error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file); |
@@ -1010,7 +1010,7 @@ discard block |
||
1010 | 1010 | } |
1011 | 1011 | else |
1012 | 1012 | { |
1013 | - if(is_dir($f.'/'.$file)) |
|
1013 | + if (is_dir($f.'/'.$file)) |
|
1014 | 1014 | { |
1015 | 1015 | $nlist = $this->get_file_list($f.'/'.$file, $i); |
1016 | 1016 | $list += $nlist; |
@@ -1031,12 +1031,12 @@ discard block |
||
1031 | 1031 | * |
1032 | 1032 | * @param resource|boolean $f |
1033 | 1033 | */ |
1034 | - function schema_backup($f=False) |
|
1034 | + function schema_backup($f = False) |
|
1035 | 1035 | { |
1036 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
1036 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
1037 | 1037 | { |
1038 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
1039 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
1038 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
1039 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
1040 | 1040 | { |
1041 | 1041 | continue; |
1042 | 1042 | } |
@@ -1055,17 +1055,17 @@ discard block |
||
1055 | 1055 | } |
1056 | 1056 | } |
1057 | 1057 | $def = "\t\$phpgw_baseline = "; |
1058 | - $def .= self::write_array($this->schemas,1); |
|
1058 | + $def .= self::write_array($this->schemas, 1); |
|
1059 | 1059 | $def .= ";\n"; |
1060 | 1060 | |
1061 | 1061 | if ($f) |
1062 | 1062 | { |
1063 | - fwrite($f,$def); |
|
1063 | + fwrite($f, $def); |
|
1064 | 1064 | } |
1065 | 1065 | else |
1066 | 1066 | { |
1067 | 1067 | $def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def; |
1068 | - Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def)); |
|
1068 | + Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def)); |
|
1069 | 1069 | echo $def; |
1070 | 1070 | } |
1071 | 1071 | } |
@@ -1075,9 +1075,9 @@ discard block |
||
1075 | 1075 | * |
1076 | 1076 | * copied from etemplate/inc/class.db_tools.inc.php |
1077 | 1077 | */ |
1078 | - private static function write_array($arr,$depth,$parent='') |
|
1078 | + private static function write_array($arr, $depth, $parent = '') |
|
1079 | 1079 | { |
1080 | - if (in_array($parent,array('pk','fk','ix','uc'))) |
|
1080 | + if (in_array($parent, array('pk', 'fk', 'ix', 'uc'))) |
|
1081 | 1081 | { |
1082 | 1082 | $depth = 0; |
1083 | 1083 | } |
@@ -1093,7 +1093,7 @@ discard block |
||
1093 | 1093 | $def = "array($tabs".($tabs ? "\t" : ''); |
1094 | 1094 | |
1095 | 1095 | $n = 0; |
1096 | - foreach($arr as $key => $val) |
|
1096 | + foreach ($arr as $key => $val) |
|
1097 | 1097 | { |
1098 | 1098 | if (!is_int($key)) |
1099 | 1099 | { |
@@ -1101,7 +1101,7 @@ discard block |
||
1101 | 1101 | } |
1102 | 1102 | if (is_array($val)) |
1103 | 1103 | { |
1104 | - $def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key); |
|
1104 | + $def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key); |
|
1105 | 1105 | } |
1106 | 1106 | else |
1107 | 1107 | { |
@@ -1114,7 +1114,7 @@ discard block |
||
1114 | 1114 | $def .= "'$val'"; |
1115 | 1115 | } |
1116 | 1116 | } |
1117 | - if ($n < count($arr)-1) |
|
1117 | + if ($n < count($arr) - 1) |
|
1118 | 1118 | { |
1119 | 1119 | $def .= ",$tabs".($tabs ? "\t" : ''); |
1120 | 1120 | } |
@@ -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 | +} |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * Constructor of schema-processor |
97 | 97 | * |
98 | 98 | * @param string $dbms type of the database: 'mysql','pgsql','mssql','maxdb' |
99 | - * @param Db $db =null database class, if null we use $GLOBALS['egw']->db |
|
99 | + * @param $db =null database class, if null we use $GLOBALS['egw']->db |
|
100 | 100 | * @return schema_proc |
101 | 101 | */ |
102 | 102 | function __construct($dbms=False, Api\Db $db=null) |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @param string $sTableName |
398 | 398 | * @param bool $preserveValue |
399 | - * @return boolean|string sequence-name or false |
|
399 | + * @return false|string sequence-name or false |
|
400 | 400 | */ |
401 | 401 | function _PostgresHasOldSequence($sTableName,$preserveValue=False) |
402 | 402 | { |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | /** |
423 | 423 | * Check if we have an old, not automaticaly droped sequence and drop it |
424 | 424 | * |
425 | - * @param $sTableName |
|
425 | + * @param string $sTableName |
|
426 | 426 | */ |
427 | 427 | function _PostgresTestDropOldSequence($sTableName) |
428 | 428 | { |
@@ -877,12 +877,7 @@ discard block |
||
877 | 877 | /** |
878 | 878 | * Execute a query |
879 | 879 | * |
880 | - * @param string $Query_String the query to be executed |
|
881 | - * @param mixed $line the line method was called from - use __LINE__ |
|
882 | - * @param string $file the file method was called from - use __FILE__ |
|
883 | - * @param int $offset row to start from |
|
884 | - * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] |
|
885 | - * @return ADORecordSet or false, if the query fails |
|
880 | + * @param integer $line |
|
886 | 881 | */ |
887 | 882 | function query($sQuery, $line='', $file='') |
888 | 883 | { |
@@ -898,8 +893,6 @@ discard block |
||
898 | 893 | * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
899 | 894 | * @param int $line line-number to pass to query |
900 | 895 | * @param string $file file-name to pass to query |
901 | - * @param string $app=false string with name of app, this need to be set in setup anyway!!! |
|
902 | - * @return ADORecordSet or false, if the query fails |
|
903 | 896 | */ |
904 | 897 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false) |
905 | 898 | { |
@@ -910,7 +903,6 @@ discard block |
||
910 | 903 | * Execute the Sql statements in an array and give diagnostics, if any error occures |
911 | 904 | * |
912 | 905 | * @param array $aSql array of SQL strings to execute |
913 | - * @param int $debug_level for which debug_level (and higher) should the diagnostics always been printed |
|
914 | 906 | * @param string $debug variable number of arguments for the debug_message functions in case of an error |
915 | 907 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
916 | 908 | */ |
@@ -953,7 +945,7 @@ discard block |
||
953 | 945 | * b) we use the table-names plus all column-names and remove dublicate parts |
954 | 946 | * |
955 | 947 | * @internal |
956 | - * @param $sTableName string name of the table |
|
948 | + * @param string $sTableName string name of the table |
|
957 | 949 | * @param $aColumnNames array of column-names or string with a single column-name |
958 | 950 | * @return string the index-name |
959 | 951 | */ |
@@ -1010,6 +1002,7 @@ discard block |
||
1010 | 1002 | |
1011 | 1003 | /** |
1012 | 1004 | * Giving a non-fatal error-message |
1005 | + * @param string $str |
|
1013 | 1006 | */ |
1014 | 1007 | function error($str) |
1015 | 1008 | { |
@@ -1038,7 +1031,7 @@ discard block |
||
1038 | 1031 | * |
1039 | 1032 | * The parameters get formated depending on their type. |
1040 | 1033 | * |
1041 | - * @param $msg string message with parameters/variables like lang(), eg. '%1' |
|
1034 | + * @param string $msg string message with parameters/variables like lang(), eg. '%1' |
|
1042 | 1035 | * @param $backtrace include a function-backtrace, default True=On |
1043 | 1036 | * should only be set to False=Off, if your code ensures a call with backtrace=On was made before !!! |
1044 | 1037 | * @param $param mixed a variable number of parameters, to be inserted in $msg |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | */ |
102 | 102 | function __construct($dbms=False, Api\Db $db=null) |
103 | 103 | { |
104 | - if(is_object($db)) |
|
104 | + if(is_object($db)) |
|
105 | 105 | { |
106 | 106 | $this->m_odb = $db; |
107 | - } |
|
108 | - else |
|
109 | - { |
|
107 | + } |
|
108 | + else |
|
109 | + { |
|
110 | 110 | $this->m_odb = isset($GLOBALS['egw']->db) && is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db; |
111 | - } |
|
112 | - if (!($this->m_odb instanceof Api\Db)) |
|
113 | - { |
|
114 | - throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!'); |
|
115 | - } |
|
116 | - $this->m_odb->connect(); |
|
111 | + } |
|
112 | + if (!($this->m_odb instanceof Api\Db)) |
|
113 | + { |
|
114 | + throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!'); |
|
115 | + } |
|
116 | + $this->m_odb->connect(); |
|
117 | 117 | $this->capabilities =& $this->m_odb->capabilities; |
118 | 118 | |
119 | 119 | $this->sType = $dbms ? $dbms : $this->m_odb->Type; |
@@ -828,79 +828,79 @@ discard block |
||
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
831 | - * Return the value of a column |
|
832 | - * |
|
833 | - * @param string|integer $value name of field or positional index starting from 0 |
|
834 | - * @param bool $strip_slashes string escape chars from field(optional), default false |
|
835 | - * @deprecated use result-set returned by query/select |
|
836 | - * @return string the field value |
|
837 | - */ |
|
831 | + * Return the value of a column |
|
832 | + * |
|
833 | + * @param string|integer $value name of field or positional index starting from 0 |
|
834 | + * @param bool $strip_slashes string escape chars from field(optional), default false |
|
835 | + * @deprecated use result-set returned by query/select |
|
836 | + * @return string the field value |
|
837 | + */ |
|
838 | 838 | function f($value,$strip_slashes=False) |
839 | 839 | { |
840 | 840 | if (!($this->m_odb instanceof Deprecated)) |
841 | 841 | { |
842 | - throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
|
842 | + throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
|
843 | 843 | } |
844 | 844 | return $this->m_odb->f($value,$strip_slashes); |
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
848 | - * Number of rows in current result set |
|
849 | - * |
|
850 | - * @deprecated use result-set returned by query/select |
|
851 | - * @return int number of rows |
|
852 | - */ |
|
848 | + * Number of rows in current result set |
|
849 | + * |
|
850 | + * @deprecated use result-set returned by query/select |
|
851 | + * @return int number of rows |
|
852 | + */ |
|
853 | 853 | function num_rows() |
854 | 854 | { |
855 | 855 | if (!($this->m_odb instanceof Deprecated)) |
856 | 856 | { |
857 | - throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
|
857 | + throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
|
858 | 858 | } |
859 | 859 | return $this->m_odb->num_rows(); |
860 | 860 | } |
861 | 861 | |
862 | 862 | /** |
863 | - * Move to the next row in the results set |
|
864 | - * |
|
865 | - * @deprecated use result-set returned by query/select |
|
866 | - * @return bool was another row found? |
|
867 | - */ |
|
863 | + * Move to the next row in the results set |
|
864 | + * |
|
865 | + * @deprecated use result-set returned by query/select |
|
866 | + * @return bool was another row found? |
|
867 | + */ |
|
868 | 868 | function next_record() |
869 | 869 | { |
870 | 870 | if (!($this->m_odb instanceof Deprecated)) |
871 | 871 | { |
872 | - throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
|
872 | + throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
|
873 | 873 | } |
874 | 874 | return $this->m_odb->next_record(); |
875 | 875 | } |
876 | 876 | |
877 | 877 | /** |
878 | - * Execute a query |
|
879 | - * |
|
880 | - * @param string $Query_String the query to be executed |
|
881 | - * @param mixed $line the line method was called from - use __LINE__ |
|
882 | - * @param string $file the file method was called from - use __FILE__ |
|
883 | - * @param int $offset row to start from |
|
884 | - * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] |
|
885 | - * @return ADORecordSet or false, if the query fails |
|
886 | - */ |
|
878 | + * Execute a query |
|
879 | + * |
|
880 | + * @param string $Query_String the query to be executed |
|
881 | + * @param mixed $line the line method was called from - use __LINE__ |
|
882 | + * @param string $file the file method was called from - use __FILE__ |
|
883 | + * @param int $offset row to start from |
|
884 | + * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] |
|
885 | + * @return ADORecordSet or false, if the query fails |
|
886 | + */ |
|
887 | 887 | function query($sQuery, $line='', $file='') |
888 | 888 | { |
889 | 889 | return $this->m_odb->query($sQuery, $line, $file); |
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
893 | - * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
894 | - * |
|
895 | - * @param string $table name of the table |
|
896 | - * @param array $data with column-name / value pairs |
|
897 | - * @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 |
|
898 | - * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
899 | - * @param int $line line-number to pass to query |
|
900 | - * @param string $file file-name to pass to query |
|
901 | - * @param string $app=false string with name of app, this need to be set in setup anyway!!! |
|
902 | - * @return ADORecordSet or false, if the query fails |
|
903 | - */ |
|
893 | + * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
894 | + * |
|
895 | + * @param string $table name of the table |
|
896 | + * @param array $data with column-name / value pairs |
|
897 | + * @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 |
|
898 | + * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
899 | + * @param int $line line-number to pass to query |
|
900 | + * @param string $file file-name to pass to query |
|
901 | + * @param string $app=false string with name of app, this need to be set in setup anyway!!! |
|
902 | + * @return ADORecordSet or false, if the query fails |
|
903 | + */ |
|
904 | 904 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false) |
905 | 905 | { |
906 | 906 | return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement); |
@@ -797,7 +797,7 @@ |
||
797 | 797 | */ |
798 | 798 | function ExecuteScripts($aTables, $bOutputHTML=False) |
799 | 799 | { |
800 | - if(!is_array($aTables) || !IsSet($this->m_odb)) |
|
800 | + if(!is_array($aTables) || !isset($this->m_odb)) |
|
801 | 801 | { |
802 | 802 | return False; |
803 | 803 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @var array |
58 | 58 | */ |
59 | - var $max_index_length=array( |
|
59 | + var $max_index_length = array( |
|
60 | 60 | 'maxdb' => 32, |
61 | 61 | 'oracle' => 30, |
62 | 62 | ); |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @param Db $db =null database class, if null we use $GLOBALS['egw']->db |
99 | 99 | * @return schema_proc |
100 | 100 | */ |
101 | - function __construct($dbms=False, Api\Db $db=null) |
|
101 | + function __construct($dbms = False, Api\Db $db = null) |
|
102 | 102 | { |
103 | - if(is_object($db)) |
|
103 | + if (is_object($db)) |
|
104 | 104 | { |
105 | 105 | $this->m_odb = $db; |
106 | 106 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!'); |
114 | 114 | } |
115 | 115 | $this->m_odb->connect(); |
116 | - $this->capabilities =& $this->m_odb->capabilities; |
|
116 | + $this->capabilities = & $this->m_odb->capabilities; |
|
117 | 117 | |
118 | 118 | $this->sType = $dbms ? $dbms : $this->m_odb->Type; |
119 | 119 | $this->adodb = &$this->m_odb->Link_ID; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | // to allow some of the former translator-functions to be called, we assign ourself as the translator |
126 | 126 | $this->m_oTranslator = &$this; |
127 | 127 | |
128 | - switch($this->sType) |
|
128 | + switch ($this->sType) |
|
129 | 129 | { |
130 | 130 | case 'maxdb': |
131 | 131 | $this->max_varchar_length = 8000; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | if (is_object($GLOBALS['egw_setup'])) |
143 | 143 | { |
144 | - $this->system_charset =& $GLOBALS['egw_setup']->system_charset; |
|
144 | + $this->system_charset = & $GLOBALS['egw_setup']->system_charset; |
|
145 | 145 | } |
146 | 146 | elseif (isset($GLOBALS['egw_info']['server']['system_charset'])) |
147 | 147 | { |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | * @param boolean $ignore_length_limit =false should we take lenght-limits of indexes into account or not |
158 | 158 | * @return boolean true if index over $columns exist in the $indexes array |
159 | 159 | */ |
160 | - function _in_index($columns, $indexs, $ignore_length_limit=false) |
|
160 | + function _in_index($columns, $indexs, $ignore_length_limit = false) |
|
161 | 161 | { |
162 | 162 | if (is_array($columns)) |
163 | 163 | { |
164 | 164 | unset($columns['options']); |
165 | - $columns = implode('-',$columns); |
|
165 | + $columns = implode('-', $columns); |
|
166 | 166 | if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns); |
167 | 167 | } |
168 | - foreach($indexs as $index) |
|
168 | + foreach ($indexs as $index) |
|
169 | 169 | { |
170 | 170 | if (is_array($index)) |
171 | 171 | { |
172 | 172 | unset($index['options']); |
173 | - $index = implode('-',$index); |
|
173 | + $index = implode('-', $index); |
|
174 | 174 | } |
175 | 175 | if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index); |
176 | 176 | if ($columns == $index) return true; |
@@ -186,21 +186,21 @@ discard block |
||
186 | 186 | * @param bool $preserveSequence |
187 | 187 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
188 | 188 | */ |
189 | - function CreateTable($sTableName, $aTableDef, $preserveSequence=False) |
|
189 | + function CreateTable($sTableName, $aTableDef, $preserveSequence = False) |
|
190 | 190 | { |
191 | 191 | if ($this->debug) |
192 | 192 | { |
193 | - $this->debug_message('schema_proc::CreateTable(%1,%2)',False,$sTableName, $aTableDef); |
|
193 | + $this->debug_message('schema_proc::CreateTable(%1,%2)', False, $sTableName, $aTableDef); |
|
194 | 194 | } |
195 | 195 | // for mysql 4.0+ we set the charset for the table |
196 | - if ($this->system_charset && substr($this->sType,0,5) == 'mysql' && |
|
197 | - (float) $this->m_odb->ServerInfo['version'] >= 4.0) |
|
196 | + if ($this->system_charset && substr($this->sType, 0, 5) == 'mysql' && |
|
197 | + (float)$this->m_odb->ServerInfo['version'] >= 4.0) |
|
198 | 198 | { |
199 | 199 | $set_table_charset = array($this->sType => 'CHARACTER SET utf8'); |
200 | 200 | } |
201 | 201 | // creating the table |
202 | - $aSql = $this->dict->CreateTableSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef($aTableDef),$set_table_charset); |
|
203 | - if (!($retVal = $this->ExecuteSQLArray($aSql,2,'CreateTableSQL(%1,%2) sql=%3',False,$sTableName,$ado_cols,$aSql))) |
|
202 | + $aSql = $this->dict->CreateTableSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef($aTableDef), $set_table_charset); |
|
203 | + if (!($retVal = $this->ExecuteSQLArray($aSql, 2, 'CreateTableSQL(%1,%2) sql=%3', False, $sTableName, $ado_cols, $aSql))) |
|
204 | 204 | { |
205 | 205 | return $retVal; |
206 | 206 | } |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | { |
210 | 210 | if (empty($mFields)) |
211 | 211 | { |
212 | - continue; // cant create an index without fields (was observed in broken backups) |
|
212 | + continue; // cant create an index without fields (was observed in broken backups) |
|
213 | 213 | } |
214 | - if ($this->_in_index($mFields,array($aTableDef['pk']))) |
|
214 | + if ($this->_in_index($mFields, array($aTableDef['pk']))) |
|
215 | 215 | { |
216 | - continue; // is already created as primary key |
|
216 | + continue; // is already created as primary key |
|
217 | 217 | } |
218 | - if (!($retVal = $this->CreateIndex($sTableName,$mFields,true,'',$name))) |
|
218 | + if (!($retVal = $this->CreateIndex($sTableName, $mFields, true, '', $name))) |
|
219 | 219 | { |
220 | 220 | return $retVal; |
221 | 221 | } |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | { |
226 | 226 | if (empty($mFields)) |
227 | 227 | { |
228 | - continue; // cant create an index without fields (was observed in broken backups) |
|
228 | + continue; // cant create an index without fields (was observed in broken backups) |
|
229 | 229 | } |
230 | - if ($this->_in_index($mFields,array($aTableDef['pk'])) || |
|
231 | - $this->_in_index($mFields,$aTableDef['uc'])) |
|
230 | + if ($this->_in_index($mFields, array($aTableDef['pk'])) || |
|
231 | + $this->_in_index($mFields, $aTableDef['uc'])) |
|
232 | 232 | { |
233 | - continue; // is already created as primary key or unique index |
|
233 | + continue; // is already created as primary key or unique index |
|
234 | 234 | } |
235 | 235 | $options = False; |
236 | 236 | if (is_array($mFields)) |
@@ -239,21 +239,21 @@ discard block |
||
239 | 239 | { |
240 | 240 | if (isset($mFields['options'][$this->sType])) |
241 | 241 | { |
242 | - $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
243 | - if (!$options) continue; // no index for our db-type |
|
242 | + $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
243 | + if (!$options) continue; // no index for our db-type |
|
244 | 244 | } |
245 | 245 | unset($mFields['options']); |
246 | 246 | } |
247 | 247 | } |
248 | - foreach((array)$mFields as $k => $col) |
|
248 | + foreach ((array)$mFields as $k => $col) |
|
249 | 249 | { |
250 | 250 | // only create indexes on text-columns, if (db-)specifiy options are given or FULLTEXT for mysql |
251 | 251 | // most DB's cant do them and give errors |
252 | - if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext'))) |
|
252 | + if (in_array($aTableDef['fd'][$col]['type'], array('text', 'longtext'))) |
|
253 | 253 | { |
254 | 254 | if (is_array($mFields)) // index over multiple columns including a text column |
255 | 255 | { |
256 | - $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
256 | + $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
257 | 257 | } |
258 | 258 | elseif (!$options) // index over a single text column and no options given |
259 | 259 | { |
@@ -263,12 +263,12 @@ discard block |
||
263 | 263 | } |
264 | 264 | else |
265 | 265 | { |
266 | - continue 2; // ignore that index, 2=not just column but whole index! |
|
266 | + continue 2; // ignore that index, 2=not just column but whole index! |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | } |
270 | 270 | } |
271 | - if (!($retVal = $this->CreateIndex($sTableName,$mFields,false,$options,$name))) |
|
271 | + if (!($retVal = $this->CreateIndex($sTableName, $mFields, false, $options, $name))) |
|
272 | 272 | { |
273 | 273 | return $retVal; |
274 | 274 | } |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | if (($seq = $this->_PostgresHasOldSequence($sTableName))) |
280 | 280 | { |
281 | 281 | $this->pgsql_old_seq = $this->pgsql_old_seq + 1; |
282 | - $this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH " . $this->pgsql_old_seq,__LINE__,__FILE__); |
|
282 | + $this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH ".$this->pgsql_old_seq, __LINE__, __FILE__); |
|
283 | 283 | } |
284 | 284 | $this->pgsql_old_seq = 0; |
285 | 285 | } |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | * @param boolean $bOutputHTML should we give diagnostics, default False |
294 | 294 | * @return boolean True if no error, else False |
295 | 295 | */ |
296 | - function DropAllTables($aTables, $bOutputHTML=False) |
|
296 | + function DropAllTables($aTables, $bOutputHTML = False) |
|
297 | 297 | { |
298 | - if(!is_array($aTables) || !isset($this->m_odb)) |
|
298 | + if (!is_array($aTables) || !isset($this->m_odb)) |
|
299 | 299 | { |
300 | 300 | return False; |
301 | 301 | } |
@@ -303,13 +303,13 @@ discard block |
||
303 | 303 | if ($this->debug) $bOutputHTML = True; |
304 | 304 | if ($bOutputHTML && !$this->debug) $this->debug = 2; |
305 | 305 | |
306 | - foreach(array_keys($aTables) as $sTableName) |
|
306 | + foreach (array_keys($aTables) as $sTableName) |
|
307 | 307 | { |
308 | - if($this->DropTable($sTableName)) |
|
308 | + if ($this->DropTable($sTableName)) |
|
309 | 309 | { |
310 | - if($bOutputHTML) |
|
310 | + if ($bOutputHTML) |
|
311 | 311 | { |
312 | - echo '<br>Drop Table <b>' . $sTableName . '</b>'; |
|
312 | + echo '<br>Drop Table <b>'.$sTableName.'</b>'; |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | else |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | |
333 | 333 | $aSql = $this->dict->DropTableSql($sTableName); |
334 | 334 | |
335 | - return $this->ExecuteSQLArray($aSql,2,'DropTable(%1) sql=%2',False,$sTableName,$aSql); |
|
335 | + return $this->ExecuteSQLArray($aSql, 2, 'DropTable(%1) sql=%2', False, $sTableName, $aSql); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -345,14 +345,14 @@ discard block |
||
345 | 345 | */ |
346 | 346 | function DropColumn($sTableName, $aTableDef, $sColumnName) |
347 | 347 | { |
348 | - unset($aTableDef); // not used, but required by function signature |
|
348 | + unset($aTableDef); // not used, but required by function signature |
|
349 | 349 | |
350 | 350 | if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
351 | 351 | unset($table_def['fd'][$sColumnName]); |
352 | 352 | |
353 | - $aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def)); |
|
353 | + $aSql = $this->dict->DropColumnSql($sTableName, $sColumnName, $ado_table = $this->_egw2adodb_columndef($table_def)); |
|
354 | 354 | |
355 | - return $this->ExecuteSQLArray($aSql,2,'DropColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName,$ado_table,$aSql); |
|
355 | + return $this->ExecuteSQLArray($aSql, 2, 'DropColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $ado_table, $aSql); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -371,12 +371,12 @@ discard block |
||
371 | 371 | if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0; |
372 | 372 | |
373 | 373 | // only use old PostgreSQL stuff, if we have an old sequence, otherwise rely on it being new enough |
374 | - if ($this->_PostgresHasOldSequence($sOldTableName,True) && |
|
374 | + if ($this->_PostgresHasOldSequence($sOldTableName, True) && |
|
375 | 375 | (count($table_def['pk']) || count($table_def['ix']) || count($table_def['uc']))) |
376 | 376 | { |
377 | 377 | if ($this->adodb->BeginTrans() && |
378 | - $this->CreateTable($sNewTableName,$table_def,True) && |
|
379 | - $this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName",__LINE__,__FILE__) && |
|
378 | + $this->CreateTable($sNewTableName, $table_def, True) && |
|
379 | + $this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName", __LINE__, __FILE__) && |
|
380 | 380 | // sequence must be updated, after inserts containing pkey, otherwise new inserst will fail! |
381 | 381 | (count($table_def['pk']) !== 1 || $this->UpdateSequence($sNewTableName, $table_def['pk'][0])) && |
382 | 382 | $this->DropTable($sOldTableName)) |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | } |
391 | 391 | $aSql = $this->dict->RenameTableSQL($sOldTableName, $sNewTableName); |
392 | 392 | |
393 | - return $this->ExecuteSQLArray($aSql,2,'RenameTableSQL(%1,%2) sql=%3',False,$sOldTableName,$sNewTableName,$aSql); |
|
393 | + return $this->ExecuteSQLArray($aSql, 2, 'RenameTableSQL(%1,%2) sql=%3', False, $sOldTableName, $sNewTableName, $aSql); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @param bool $preserveValue |
401 | 401 | * @return boolean|string sequence-name or false |
402 | 402 | */ |
403 | - function _PostgresHasOldSequence($sTableName,$preserveValue=False) |
|
403 | + function _PostgresHasOldSequence($sTableName, $preserveValue = False) |
|
404 | 404 | { |
405 | 405 | if ($this->sType != 'pgsql') return false; |
406 | 406 | |
@@ -408,14 +408,14 @@ discard block |
||
408 | 408 | $seq2 = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%$sTableName%_seq''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum"); |
409 | 409 | |
410 | 410 | $matches = null; |
411 | - if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches)) |
|
411 | + if ($seq && preg_match('/^nextval\(\'(.*)\'/', $seq, $matches)) |
|
412 | 412 | { |
413 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
413 | + if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]); |
|
414 | 414 | return $matches[1]; |
415 | 415 | } |
416 | - if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches)) |
|
416 | + if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/', $seq2, $matches)) |
|
417 | 417 | { |
418 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
418 | + if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]); |
|
419 | 419 | return $matches[1]; |
420 | 420 | } |
421 | 421 | return false; |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | // only drop sequence, if there is no dependency on it |
435 | 435 | if (!$this->adodb->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'")) |
436 | 436 | { |
437 | - $this->query('DROP SEQUENCE '.$seq,__LINE__,__FILE__); |
|
437 | + $this->query('DROP SEQUENCE '.$seq, __LINE__, __FILE__); |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | } |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
453 | 453 | |
454 | 454 | // PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long |
455 | - if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
|
455 | + if ($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
|
456 | 456 | in_array($aColumnDef['type'], array('varchar', 'ascii')) && |
457 | 457 | $table_def['fd'][$sColumnName]['precision'] > $aColumnDef['precision']) |
458 | 458 | { |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | } |
468 | 468 | $table_def['fd'][$sColumnName] = $aColumnDef; |
469 | 469 | |
470 | - $aSql = $this->dict->AlterColumnSQL($sTableName,$ado_col = $this->_egw2adodb_columndef(array( |
|
470 | + $aSql = $this->dict->AlterColumnSQL($sTableName, $ado_col = $this->_egw2adodb_columndef(array( |
|
471 | 471 | 'fd' => array($sColumnName => $aColumnDef), |
472 | 472 | 'pk' => array(), |
473 | - )),$ado_table=$this->_egw2adodb_columndef($table_def)); |
|
473 | + )), $ado_table = $this->_egw2adodb_columndef($table_def)); |
|
474 | 474 | |
475 | - return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$ado_col,$ado_table,$aSql); |
|
475 | + return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $ado_col, $ado_table, $aSql); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | } |
495 | 495 | else |
496 | 496 | { |
497 | - foreach($table_def['fd'] as $col => $def) |
|
497 | + foreach ($table_def['fd'] as $col => $def) |
|
498 | 498 | { |
499 | 499 | if (strtolower($col) == strtolower($sOldColumnName)) |
500 | 500 | { |
@@ -508,9 +508,9 @@ discard block |
||
508 | 508 | 'pk' => array(), |
509 | 509 | )); |
510 | 510 | |
511 | - $aSql = $this->dict->RenameColumnSQL($sTableName,$sOldColumnName,$sNewColumnName,$col_def); |
|
511 | + $aSql = $this->dict->RenameColumnSQL($sTableName, $sOldColumnName, $sNewColumnName, $col_def); |
|
512 | 512 | |
513 | - return $this->ExecuteSQLArray($aSql,2,'RenameColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sOldColumnName, $sNewColumnName,$aSql); |
|
513 | + return $this->ExecuteSQLArray($aSql, 2, 'RenameColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sOldColumnName, $sNewColumnName, $aSql); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -523,12 +523,12 @@ discard block |
||
523 | 523 | */ |
524 | 524 | function AddColumn($sTableName, $sColumnName, $aColumnDef) |
525 | 525 | { |
526 | - $aSql = $this->dict->AddColumnSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef(array( |
|
526 | + $aSql = $this->dict->AddColumnSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef(array( |
|
527 | 527 | 'fd' => array($sColumnName => $aColumnDef), |
528 | 528 | 'pk' => array(), |
529 | 529 | ))); |
530 | 530 | |
531 | - return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName, $aColumnDef,$aSql); |
|
531 | + return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $aColumnDef, $aSql); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
@@ -541,16 +541,16 @@ discard block |
||
541 | 541 | * @param string $sIdxName ='' name of the index, if not given (default) its created automaticaly |
542 | 542 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
543 | 543 | */ |
544 | - function CreateIndex($sTableName,$aColumnNames,$bUnique=false,$options='',$sIdxName='') |
|
544 | + function CreateIndex($sTableName, $aColumnNames, $bUnique = false, $options = '', $sIdxName = '') |
|
545 | 545 | { |
546 | 546 | // remove length limits from column names, if DB type is NOT MySQL |
547 | 547 | if ($this->sType != 'mysql') |
548 | 548 | { |
549 | - $aColumnNames = preg_replace('/ *\(\d+\)$/','',$aColumnNames); |
|
549 | + $aColumnNames = preg_replace('/ *\(\d+\)$/', '', $aColumnNames); |
|
550 | 550 | } |
551 | 551 | if (!$sIdxName || is_numeric($sIdxName)) |
552 | 552 | { |
553 | - $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
|
553 | + $sIdxName = $this->_index_name($sTableName, $aColumnNames); |
|
554 | 554 | } |
555 | 555 | if (!is_array($options)) $options = $options ? array($options) : array(); |
556 | 556 | if ($bUnique) $options[] = 'UNIQUE'; |
@@ -567,9 +567,9 @@ discard block |
||
567 | 567 | $this->DropIndex($sTableName, (array)$aColumnNames); |
568 | 568 | } |
569 | 569 | |
570 | - $aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options); |
|
570 | + $aSql = $this->dict->CreateIndexSQL($sIdxName, $sTableName, $aColumnNames, $options); |
|
571 | 571 | |
572 | - return $this->ExecuteSQLArray($aSql,2,'CreateIndexSQL(%1,%2,%3,%4) sql=%5',False,$sTableName,$aColumnNames,$options,$sIdxName,$aSql); |
|
572 | + return $this->ExecuteSQLArray($aSql, 2, 'CreateIndexSQL(%1,%2,%3,%4) sql=%5', False, $sTableName, $aColumnNames, $options, $sIdxName, $aSql); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * @param array|string $aColumnNames columns of the index or the name of the index |
580 | 580 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
581 | 581 | */ |
582 | - function DropIndex($sTableName,$aColumnNames) |
|
582 | + function DropIndex($sTableName, $aColumnNames) |
|
583 | 583 | { |
584 | 584 | if (is_array($aColumnNames)) |
585 | 585 | { |
@@ -589,13 +589,13 @@ discard block |
||
589 | 589 | { |
590 | 590 | // if MetaIndexes is not availible for the DB, we try the name the index was created with |
591 | 591 | // this fails if one of the columns have been renamed |
592 | - $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
|
592 | + $sIdxName = $this->_index_name($sTableName, $aColumnNames); |
|
593 | 593 | } |
594 | 594 | else |
595 | 595 | { |
596 | - foreach($indexes as $idx => $idx_data) |
|
596 | + foreach ($indexes as $idx => $idx_data) |
|
597 | 597 | { |
598 | - if (strtolower(implode(':',$idx_data['columns'])) == implode(':',$aColumnNames)) |
|
598 | + if (strtolower(implode(':', $idx_data['columns'])) == implode(':', $aColumnNames)) |
|
599 | 599 | { |
600 | 600 | $sIdxName = $idx; |
601 | 601 | break; |
@@ -607,13 +607,13 @@ discard block |
||
607 | 607 | { |
608 | 608 | $sIdxName = $aColumnNames; |
609 | 609 | } |
610 | - if(!$sIdxName) |
|
610 | + if (!$sIdxName) |
|
611 | 611 | { |
612 | 612 | return True; |
613 | 613 | } |
614 | - $aSql = $this->dict->DropIndexSQL($sIdxName,$sTableName); |
|
614 | + $aSql = $this->dict->DropIndexSQL($sIdxName, $sTableName); |
|
615 | 615 | |
616 | - return $this->ExecuteSQLArray($aSql,2,'DropIndexSQL(%1(%2),%3) sql=%4',False,$sIdxName,$aColumnNames,$sTableName,$aSql); |
|
616 | + return $this->ExecuteSQLArray($aSql, 2, 'DropIndexSQL(%1(%2),%3) sql=%4', False, $sIdxName, $aColumnNames, $sTableName, $aSql); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -621,22 +621,22 @@ discard block |
||
621 | 621 | * @param string $sTableName table-name |
622 | 622 | * @param string $sColumnName column-name, which default is set to nextval() |
623 | 623 | */ |
624 | - function UpdateSequence($sTableName,$sColumnName) |
|
624 | + function UpdateSequence($sTableName, $sColumnName) |
|
625 | 625 | { |
626 | - switch($this->sType) |
|
626 | + switch ($this->sType) |
|
627 | 627 | { |
628 | 628 | case 'pgsql': |
629 | 629 | // identify the sequence name, ADOdb uses a different name or it might be renamed |
630 | 630 | $columns = $this->dict->MetaColumns($sTableName); |
631 | 631 | $seq_name = 'seq_'.$sTableName; |
632 | 632 | $matches = null; |
633 | - if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$columns[strtoupper($sColumnName)]->default_value,$matches)) |
|
633 | + if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $columns[strtoupper($sColumnName)]->default_value, $matches)) |
|
634 | 634 | { |
635 | 635 | $seq_name = $matches[1]; |
636 | 636 | } |
637 | 637 | $sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName"; |
638 | - if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
639 | - return $this->query($sql,__LINE__,__FILE__); |
|
638 | + if ($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
639 | + return $this->query($sql, __LINE__, __FILE__); |
|
640 | 640 | } |
641 | 641 | return True; |
642 | 642 | } |
@@ -653,9 +653,9 @@ discard block |
||
653 | 653 | * @param array $aTableDef eGW table-defintion |
654 | 654 | * @param array|boolean $aDefaults array with default for the colums during copying, values are either (old) column-names or quoted string-literals |
655 | 655 | */ |
656 | - function RefreshTable($sTableName, $aTableDef, $aDefaults=False) |
|
656 | + function RefreshTable($sTableName, $aTableDef, $aDefaults = False) |
|
657 | 657 | { |
658 | - if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
658 | + if ($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef, False).")\n"; } |
|
659 | 659 | |
660 | 660 | $old_table_def = $this->GetTableDefinition($sTableName); |
661 | 661 | |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | |
665 | 665 | $select = array(); |
666 | 666 | $blob_column_included = $auto_column_included = False; |
667 | - foreach($aTableDef['fd'] as $name => $data) |
|
667 | + foreach ($aTableDef['fd'] as $name => $data) |
|
668 | 668 | { |
669 | 669 | // new auto column with no default or explicit NULL as default (can be an existing column too!) |
670 | 670 | if ($data['type'] == 'auto' && |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | $aDefaults && strtoupper($aDefaults[$name]) == 'NULL')) |
673 | 673 | { |
674 | 674 | $sequence_name = $sTableName.'_'.$name.'_seq'; |
675 | - switch($GLOBALS['egw_setup']->db->Type) |
|
675 | + switch ($GLOBALS['egw_setup']->db->Type) |
|
676 | 676 | { |
677 | 677 | case 'mysql': |
678 | 678 | $value = 'NULL'; break; |
@@ -693,25 +693,25 @@ discard block |
||
693 | 693 | if ($this->sType == 'pgsql') // some postgres specific code |
694 | 694 | { |
695 | 695 | // this is eg. necessary to change a varchar into an int column under postgres |
696 | - if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) && |
|
697 | - in_array($data['type'],array('int','decimal'))) |
|
696 | + if (in_array($old_table_def['fd'][$name]['type'], array('char', 'varchar', 'text', 'blob')) && |
|
697 | + in_array($data['type'], array('int', 'decimal'))) |
|
698 | 698 | { |
699 | 699 | $value = "to_number($name,'S9999999999999D99')"; |
700 | 700 | } |
701 | 701 | // blobs cant be casted to text |
702 | - elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
|
702 | + elseif ($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
|
703 | 703 | { |
704 | 704 | $value = "ENCODE($value,'escape')"; |
705 | 705 | } |
706 | 706 | // varchar or ascii column shortened, use substring to avoid error if current content is to long |
707 | - elseif(in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) && |
|
707 | + elseif (in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) && |
|
708 | 708 | in_array($data['type'], array('varchar', 'ascii')) && |
709 | 709 | $old_table_def['fd'][$name]['precision'] > $data['precision']) |
710 | 710 | { |
711 | 711 | $value = "SUBSTRING($value FROM 1 FOR ".(int)$data['precision'].')'; |
712 | 712 | } |
713 | 713 | // cast everything which is a different type |
714 | - elseif($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type']))) |
|
714 | + elseif ($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type']))) |
|
715 | 715 | { |
716 | 716 | $value = "CAST($value AS $type_translated)"; |
717 | 717 | } |
@@ -724,42 +724,42 @@ discard block |
||
724 | 724 | $value = 'NULL'; |
725 | 725 | } |
726 | 726 | // some stuff is NOT to be quoted |
727 | - elseif (in_array(strtoupper($data['default']),array('CURRENT_TIMESTAMP','CURRENT_DATE','NULL','NOW()'))) |
|
727 | + elseif (in_array(strtoupper($data['default']), array('CURRENT_TIMESTAMP', 'CURRENT_DATE', 'NULL', 'NOW()'))) |
|
728 | 728 | { |
729 | 729 | $value = $data['default']; |
730 | 730 | } |
731 | 731 | else |
732 | 732 | { |
733 | - $value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '',$data['type']); |
|
733 | + $value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '', $data['type']); |
|
734 | 734 | } |
735 | 735 | if ($this->sType == 'pgsql') |
736 | 736 | { |
737 | 737 | // fix for postgres error "no '<' operator for type 'unknown'" |
738 | - if(($type_translated = $this->TranslateType($data['type']))) |
|
738 | + if (($type_translated = $this->TranslateType($data['type']))) |
|
739 | 739 | { |
740 | 740 | $value = "CAST($value AS $type_translated)"; |
741 | 741 | } |
742 | 742 | } |
743 | 743 | } |
744 | - $blob_column_included = $blob_column_included || in_array($data['type'],array('blob','text','longtext')); |
|
744 | + $blob_column_included = $blob_column_included || in_array($data['type'], array('blob', 'text', 'longtext')); |
|
745 | 745 | $auto_column_included = $auto_column_included || $data['type'] == 'auto'; |
746 | 746 | $select[] = $value; |
747 | 747 | } |
748 | 748 | |
749 | 749 | $extra = ''; |
750 | 750 | $distinct = 'DISTINCT'; |
751 | - switch($this->sType) |
|
751 | + switch ($this->sType) |
|
752 | 752 | { |
753 | 753 | case 'mssql': |
754 | 754 | if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
755 | - if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
755 | + if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
756 | 756 | break; |
757 | 757 | } |
758 | 758 | // because of all the trouble with sequences and indexes in the global namespace, |
759 | 759 | // we use an additional temp. table for postgres and not rename the existing one, but drop it. |
760 | 760 | if ($this->sType == 'pgsql') |
761 | 761 | { |
762 | - $Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName",__LINE__,__FILE__) && |
|
762 | + $Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName", __LINE__, __FILE__) && |
|
763 | 763 | $this->DropTable($sTableName); |
764 | 764 | } |
765 | 765 | else |
@@ -769,12 +769,12 @@ discard block |
||
769 | 769 | { |
770 | 770 | $this->DropTable($tmp_name); |
771 | 771 | } |
772 | - $Ok = $this->RenameTable($sTableName,$tmp_name); |
|
772 | + $Ok = $this->RenameTable($sTableName, $tmp_name); |
|
773 | 773 | } |
774 | - $Ok = $Ok && $this->CreateTable($sTableName,$aTableDef) && |
|
775 | - $this->m_odb->query($sql_copy_data="$extra INSERT INTO $sTableName (". |
|
776 | - implode(',',array_keys($aTableDef['fd'])). |
|
777 | - ") SELEcT $distinct ".implode(',',$select)." FROM $tmp_name",__LINE__,__FILE__) && |
|
774 | + $Ok = $Ok && $this->CreateTable($sTableName, $aTableDef) && |
|
775 | + $this->m_odb->query($sql_copy_data = "$extra INSERT INTO $sTableName (". |
|
776 | + implode(',', array_keys($aTableDef['fd'])). |
|
777 | + ") SELEcT $distinct ".implode(',', $select)." FROM $tmp_name", __LINE__, __FILE__) && |
|
778 | 778 | $this->DropTable($tmp_name); |
779 | 779 | //error_log($sql_copy_data); |
780 | 780 | |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | // do we need to update the new sequences value ? |
787 | 787 | if (count($aTableDef['pk']) == 1 && $aTableDef['fd'][$aTableDef['pk'][0]]['type'] == 'auto') |
788 | 788 | { |
789 | - $this->UpdateSequence($sTableName,$aTableDef['pk'][0]); |
|
789 | + $this->UpdateSequence($sTableName, $aTableDef['pk'][0]); |
|
790 | 790 | } |
791 | 791 | $this->m_odb->transaction_commit(); |
792 | 792 | |
@@ -809,9 +809,9 @@ discard block |
||
809 | 809 | * @param boolean $bOutputHTML =false should we give diagnostics, default False |
810 | 810 | * @return boolean True on success, False if an (fatal) error occured |
811 | 811 | */ |
812 | - function ExecuteScripts($aTables, $bOutputHTML=False) |
|
812 | + function ExecuteScripts($aTables, $bOutputHTML = False) |
|
813 | 813 | { |
814 | - if(!is_array($aTables) || !IsSet($this->m_odb)) |
|
814 | + if (!is_array($aTables) || !IsSet($this->m_odb)) |
|
815 | 815 | { |
816 | 816 | return False; |
817 | 817 | } |
@@ -819,20 +819,20 @@ discard block |
||
819 | 819 | if ($this->debug) $bOutputHTML = True; |
820 | 820 | if ($bOutputHTML && !$this->debug) $this->debug = 2; |
821 | 821 | |
822 | - foreach($aTables as $sTableName => $aTableDef) |
|
822 | + foreach ($aTables as $sTableName => $aTableDef) |
|
823 | 823 | { |
824 | - if($this->CreateTable($sTableName, $aTableDef)) |
|
824 | + if ($this->CreateTable($sTableName, $aTableDef)) |
|
825 | 825 | { |
826 | - if($bOutputHTML) |
|
826 | + if ($bOutputHTML) |
|
827 | 827 | { |
828 | - echo '<br>Create Table <b>' . $sTableName . '</b>'; |
|
828 | + echo '<br>Create Table <b>'.$sTableName.'</b>'; |
|
829 | 829 | } |
830 | 830 | } |
831 | 831 | else |
832 | 832 | { |
833 | - if($bOutputHTML) |
|
833 | + if ($bOutputHTML) |
|
834 | 834 | { |
835 | - echo '<br>Create Table Failed For <b>' . $sTableName . '</b>'; |
|
835 | + echo '<br>Create Table Failed For <b>'.$sTableName.'</b>'; |
|
836 | 836 | } |
837 | 837 | |
838 | 838 | return False; |
@@ -849,13 +849,13 @@ discard block |
||
849 | 849 | * @deprecated use result-set returned by query/select |
850 | 850 | * @return string the field value |
851 | 851 | */ |
852 | - function f($value,$strip_slashes=False) |
|
852 | + function f($value, $strip_slashes = False) |
|
853 | 853 | { |
854 | 854 | if (!($this->m_odb instanceof Deprecated)) |
855 | 855 | { |
856 | 856 | throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
857 | 857 | } |
858 | - return $this->m_odb->f($value,$strip_slashes); |
|
858 | + return $this->m_odb->f($value, $strip_slashes); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | /** |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] |
899 | 899 | * @return ADORecordSet or false, if the query fails |
900 | 900 | */ |
901 | - function query($sQuery, $line='', $file='') |
|
901 | + function query($sQuery, $line = '', $file = '') |
|
902 | 902 | { |
903 | 903 | return $this->m_odb->query($sQuery, $line, $file); |
904 | 904 | } |
@@ -915,9 +915,9 @@ discard block |
||
915 | 915 | * @param string $app=false string with name of app, this need to be set in setup anyway!!! |
916 | 916 | * @return ADORecordSet or false, if the query fails |
917 | 917 | */ |
918 | - function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false) |
|
918 | + function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false) |
|
919 | 919 | { |
920 | - return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement); |
|
920 | + return $this->m_odb->insert($table, $data, $where, $line, $file, $app, $use_prepared_statement); |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | /** |
@@ -928,14 +928,14 @@ discard block |
||
928 | 928 | * @param string $debug variable number of arguments for the debug_message functions in case of an error |
929 | 929 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
930 | 930 | */ |
931 | - function ExecuteSqlArray($aSql,$debug_level) |
|
931 | + function ExecuteSqlArray($aSql, $debug_level) |
|
932 | 932 | { |
933 | 933 | if ($this->m_odb->query_log) // we use Db::query to log the queries |
934 | 934 | { |
935 | 935 | $retval = 2; |
936 | - foreach($aSql as $sql) |
|
936 | + foreach ($aSql as $sql) |
|
937 | 937 | { |
938 | - if (!$this->m_odb->query($sql,__LINE__,__FILE__)) |
|
938 | + if (!$this->m_odb->query($sql, __LINE__, __FILE__)) |
|
939 | 939 | { |
940 | 940 | $retval = 1; |
941 | 941 | } |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | $debug_params = func_get_args(); |
951 | 951 | array_shift($debug_params); |
952 | 952 | array_shift($debug_params); |
953 | - call_user_func_array(array($this,'debug_message'),$debug_params); |
|
953 | + call_user_func_array(array($this, 'debug_message'), $debug_params); |
|
954 | 954 | if ($retval < 2 && !$this->dict->debug) |
955 | 955 | { |
956 | 956 | echo '<p><b>'.$this->adodb->ErrorMsg()."</b></p>\n"; |
@@ -971,7 +971,7 @@ discard block |
||
971 | 971 | * @param $aColumnNames array of column-names or string with a single column-name |
972 | 972 | * @return string the index-name |
973 | 973 | */ |
974 | - function _index_name($sTableName,$aColumnNames) |
|
974 | + function _index_name($sTableName, $aColumnNames) |
|
975 | 975 | { |
976 | 976 | // this code creates extrem short index-names, eg. for MaxDB |
977 | 977 | // if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32) |
@@ -996,28 +996,28 @@ discard block |
||
996 | 996 | // return $name; |
997 | 997 | // } |
998 | 998 | // This code creates longer index-names incl. the table-names and the used columns |
999 | - $table = str_replace(array('phpgw_','egw_'),'',$sTableName); |
|
999 | + $table = str_replace(array('phpgw_', 'egw_'), '', $sTableName); |
|
1000 | 1000 | // if the table-name or a part of it is repeated in the column-name, remove it there |
1001 | 1001 | $remove[] = $table.'_'; |
1002 | 1002 | // also remove 3 or 4 letter shortcuts of the table- or app-name |
1003 | - $remove[] = substr($table,0,3).'_'; |
|
1004 | - $remove[] = substr($table,0,4).'_'; |
|
1003 | + $remove[] = substr($table, 0, 3).'_'; |
|
1004 | + $remove[] = substr($table, 0, 4).'_'; |
|
1005 | 1005 | // if the table-name consists of '_' limtied parts, remove occurences of these parts too |
1006 | - foreach (explode('_',$table) as $part) |
|
1006 | + foreach (explode('_', $table) as $part) |
|
1007 | 1007 | { |
1008 | 1008 | $remove[] = $part.'_'; |
1009 | 1009 | } |
1010 | - $cols = str_replace($remove,'',$aColumnNames); |
|
1010 | + $cols = str_replace($remove, '', $aColumnNames); |
|
1011 | 1011 | |
1012 | - $name = $sTableName.'_'.(is_array($cols) ? implode('_',$cols) : $cols); |
|
1012 | + $name = $sTableName.'_'.(is_array($cols) ? implode('_', $cols) : $cols); |
|
1013 | 1013 | // remove length limits from column names |
1014 | - $name = preg_replace('/ *\(\d+\)/','',$name); |
|
1014 | + $name = preg_replace('/ *\(\d+\)/', '', $name); |
|
1015 | 1015 | |
1016 | 1016 | // this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle |
1017 | 1017 | if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 || |
1018 | 1018 | strlen($name) >= 64) // even mysql has a limit here ;-) |
1019 | 1019 | { |
1020 | - $name = "i".substr(md5($name),0,29); |
|
1020 | + $name = "i".substr(md5($name), 0, 29); |
|
1021 | 1021 | } |
1022 | 1022 | return $name; |
1023 | 1023 | } |
@@ -1058,19 +1058,19 @@ discard block |
||
1058 | 1058 | * @param $param mixed a variable number of parameters, to be inserted in $msg |
1059 | 1059 | * arrays get serialized with print_r() ! |
1060 | 1060 | */ |
1061 | - function debug_message($msg,$backtrace=True) |
|
1061 | + function debug_message($msg, $backtrace = True) |
|
1062 | 1062 | { |
1063 | - for($i = 2; $i < func_num_args(); ++$i) |
|
1063 | + for ($i = 2; $i < func_num_args(); ++$i) |
|
1064 | 1064 | { |
1065 | 1065 | $param = func_get_arg($i); |
1066 | 1066 | |
1067 | 1067 | if (is_null($param)) |
1068 | 1068 | { |
1069 | - $param='NULL'; |
|
1069 | + $param = 'NULL'; |
|
1070 | 1070 | } |
1071 | 1071 | else |
1072 | 1072 | { |
1073 | - switch(gettype($param)) |
|
1073 | + switch (gettype($param)) |
|
1074 | 1074 | { |
1075 | 1075 | case 'string': |
1076 | 1076 | $param = "'$param'"; |
@@ -1078,15 +1078,15 @@ discard block |
||
1078 | 1078 | case 'array': |
1079 | 1079 | case 'object': |
1080 | 1080 | list(,$content) = @each($param); |
1081 | - $do_pre = is_array($param) ? count($param) > 6 || is_array($content)&&count($content) : True; |
|
1082 | - $param = ($do_pre ? '<pre>' : '').print_r($param,True).($do_pre ? '</pre>' : ''); |
|
1081 | + $do_pre = is_array($param) ? count($param) > 6 || is_array($content) && count($content) : True; |
|
1082 | + $param = ($do_pre ? '<pre>' : '').print_r($param, True).($do_pre ? '</pre>' : ''); |
|
1083 | 1083 | break; |
1084 | 1084 | case 'boolean': |
1085 | 1085 | $param = $param ? 'True' : 'False'; |
1086 | 1086 | break; |
1087 | 1087 | } |
1088 | 1088 | } |
1089 | - $msg = str_replace('%'.($i-1),$param,$msg); |
|
1089 | + $msg = str_replace('%'.($i - 1), $param, $msg); |
|
1090 | 1090 | } |
1091 | 1091 | echo '<p>'.$msg."<br>\n".($backtrace ? 'Backtrace: '.function_backtrace(1)."</p>\n" : ''); |
1092 | 1092 | } |
@@ -1101,15 +1101,15 @@ discard block |
||
1101 | 1101 | function _egw2adodb_columndef($aTableDef) |
1102 | 1102 | { |
1103 | 1103 | $ado_defs = array(); |
1104 | - foreach($aTableDef['fd'] as $col => $col_data) |
|
1104 | + foreach ($aTableDef['fd'] as $col => $col_data) |
|
1105 | 1105 | { |
1106 | 1106 | $ado_col = False; |
1107 | 1107 | |
1108 | - switch($col_data['type']) |
|
1108 | + switch ($col_data['type']) |
|
1109 | 1109 | { |
1110 | 1110 | case 'auto': |
1111 | 1111 | $ado_col = 'I AUTOINCREMENT NOTNULL'; |
1112 | - unset($col_data['nullable']); // else we set it twice |
|
1112 | + unset($col_data['nullable']); // else we set it twice |
|
1113 | 1113 | break; |
1114 | 1114 | case 'binary': // varbinary column for MySQL/MariaDB |
1115 | 1115 | if ($this->sType == 'mysql' && $col_data['precision'] <= $this->max_varchar_length) |
@@ -1129,11 +1129,11 @@ discard block |
||
1129 | 1129 | case 'ascii': |
1130 | 1130 | case 'varchar': |
1131 | 1131 | $ado_col = "C"; |
1132 | - if(0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length) |
|
1132 | + if (0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length) |
|
1133 | 1133 | { |
1134 | 1134 | $ado_col .= "($col_data[precision])"; |
1135 | 1135 | } |
1136 | - if($col_data['precision'] > $this->max_varchar_length) |
|
1136 | + if ($col_data['precision'] > $this->max_varchar_length) |
|
1137 | 1137 | { |
1138 | 1138 | $ado_col = 'X'; |
1139 | 1139 | } |
@@ -1145,7 +1145,7 @@ discard block |
||
1145 | 1145 | case 'date': |
1146 | 1146 | $ado_col = 'D'; |
1147 | 1147 | // allow to use now() beside current_date, as Postgres backups contain it and it's easier to remember anyway |
1148 | - if (in_array($col_data['default'],array('current_date','now()'))) |
|
1148 | + if (in_array($col_data['default'], array('current_date', 'now()'))) |
|
1149 | 1149 | { |
1150 | 1150 | $ado_col .= ' DEFDATE'; |
1151 | 1151 | unset($col_data['default']); |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | break; |
1162 | 1162 | case 'int': |
1163 | 1163 | $ado_col = 'I'; |
1164 | - switch($col_data['precision']) |
|
1164 | + switch ($col_data['precision']) |
|
1165 | 1165 | { |
1166 | 1166 | case 1: |
1167 | 1167 | case 2: |
@@ -1180,7 +1180,7 @@ discard block |
||
1180 | 1180 | case 'timestamp': |
1181 | 1181 | $ado_col = 'T'; |
1182 | 1182 | // allow to use now() beside current_timestamp, as Postgres backups contain it and it's easier to remember anyway |
1183 | - if (in_array($col_data['default'],array('current_timestamp','now()'))) |
|
1183 | + if (in_array($col_data['default'], array('current_timestamp', 'now()'))) |
|
1184 | 1184 | { |
1185 | 1185 | $ado_col .= ' DEFTIMESTAMP'; |
1186 | 1186 | unset($col_data['default']); |
@@ -1198,17 +1198,17 @@ discard block |
||
1198 | 1198 | } |
1199 | 1199 | if (isset($col_data['default'])) |
1200 | 1200 | { |
1201 | - $ado_col .= (in_array($col_data['type'],array('bool','int','decimal','float','double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : ''). |
|
1202 | - ' DEFAULT '.$this->m_odb->quote($col_data['default'],$col_data['type']); |
|
1201 | + $ado_col .= (in_array($col_data['type'], array('bool', 'int', 'decimal', 'float', 'double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : ''). |
|
1202 | + ' DEFAULT '.$this->m_odb->quote($col_data['default'], $col_data['type']); |
|
1203 | 1203 | } |
1204 | - if (in_array($col,$aTableDef['pk'])) |
|
1204 | + if (in_array($col, $aTableDef['pk'])) |
|
1205 | 1205 | { |
1206 | 1206 | $ado_col .= ' PRIMARY'; |
1207 | 1207 | } |
1208 | - $ado_defs[] = $col . ' ' . $ado_col; |
|
1208 | + $ado_defs[] = $col.' '.$ado_col; |
|
1209 | 1209 | } |
1210 | 1210 | //print_r($aTableDef); echo implode(",\n",$ado_defs)."\n"; |
1211 | - return implode(",\n",$ado_defs); |
|
1211 | + return implode(",\n", $ado_defs); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1224,7 +1224,7 @@ discard block |
||
1224 | 1224 | 'pk' => array(), |
1225 | 1225 | )); |
1226 | 1226 | $matches = null; |
1227 | - return preg_match('/test ([A-Z0-9]+)/i',$ado_col,$matches) ? $this->dict->ActualType($matches[1]) : false; |
|
1227 | + return preg_match('/test ([A-Z0-9]+)/i', $ado_col, $matches) ? $this->dict->ActualType($matches[1]) : false; |
|
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | /** |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | // MetaType returns all varchar >= blobSize as blob, it's by default 100, which is wrong |
1241 | 1241 | $this->dict->blobSize = $this->max_varchar_length; |
1242 | 1242 | |
1243 | - if (!method_exists($this->dict,'MetaColumns') || |
|
1243 | + if (!method_exists($this->dict, 'MetaColumns') || |
|
1244 | 1244 | !($columns = $this->dict->MetaColumns($sTableName))) |
1245 | 1245 | { |
1246 | 1246 | return False; |
@@ -1253,11 +1253,11 @@ discard block |
||
1253 | 1253 | 'uc' => array(), |
1254 | 1254 | ); |
1255 | 1255 | //echo "$sTableName: <pre>".print_r($columns,true)."</pre>"; |
1256 | - foreach($columns as $column) |
|
1256 | + foreach ($columns as $column) |
|
1257 | 1257 | { |
1258 | 1258 | $name = $this->capabilities['name_case'] == 'upper' ? strtolower($column->name) : $column->name; |
1259 | 1259 | |
1260 | - $type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
|
1260 | + $type = method_exists($this->dict, 'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
|
1261 | 1261 | |
1262 | 1262 | // fix longtext not correctly handled by ADOdb |
1263 | 1263 | if ($type == 'X' && $column->type == 'longtext') $type = 'XL'; |
@@ -1279,11 +1279,11 @@ discard block |
||
1279 | 1279 | ); |
1280 | 1280 | $definition['fd'][$name]['type'] = $ado_type2egw[$type]; |
1281 | 1281 | |
1282 | - switch($type) |
|
1282 | + switch ($type) |
|
1283 | 1283 | { |
1284 | 1284 | case 'D': case 'T': |
1285 | 1285 | // detecting the automatic timestamps again |
1286 | - if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i',$column->default_value)) |
|
1286 | + if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i', $column->default_value)) |
|
1287 | 1287 | { |
1288 | 1288 | $column->default_value = $type == 'D' ? 'current_date' : 'current_timestamp'; |
1289 | 1289 | } |
@@ -1310,10 +1310,10 @@ discard block |
||
1310 | 1310 | $column->auto_increment = true; |
1311 | 1311 | // fall-through |
1312 | 1312 | case 'I': case 'I1': case 'I2': case 'I4': case 'I8': |
1313 | - switch($type) |
|
1313 | + switch ($type) |
|
1314 | 1314 | { |
1315 | 1315 | case 'I1': case 'I2': case 'I4': case 'I8': |
1316 | - $definition['fd'][$name]['precision'] = (int) $type[1]; |
|
1316 | + $definition['fd'][$name]['precision'] = (int)$type[1]; |
|
1317 | 1317 | break; |
1318 | 1318 | default: |
1319 | 1319 | if ($column->max_length > 11) |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | $definition['fd'][$name]['type'] = 'int'; |
1350 | 1350 | // detect postgres type-spec and remove it |
1351 | 1351 | $matches = null; |
1352 | - if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/',$column->default_value,$matches)) |
|
1352 | + if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/', $column->default_value, $matches)) |
|
1353 | 1353 | { |
1354 | 1354 | $definition['fd'][$name]['default'] = $matches[1]; |
1355 | 1355 | $column->has_default = False; |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | } |
1368 | 1368 | if ($column->has_default) |
1369 | 1369 | { |
1370 | - if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) // postgres |
|
1370 | + if (preg_match("/^'(.*)'::.*$/", $column->default_value, $matches)) // postgres |
|
1371 | 1371 | { |
1372 | 1372 | $column->default_value = $matches[1]; |
1373 | 1373 | } |
@@ -1377,18 +1377,18 @@ discard block |
||
1377 | 1377 | { |
1378 | 1378 | $definition['fd'][$name]['nullable'] = False; |
1379 | 1379 | } |
1380 | - if ($column->primary_key && !in_array($name,$definition['pk'])) |
|
1380 | + if ($column->primary_key && !in_array($name, $definition['pk'])) |
|
1381 | 1381 | { |
1382 | 1382 | $definition['pk'][] = $name; |
1383 | 1383 | } |
1384 | 1384 | } |
1385 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
1385 | + if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2", False, $sTableName, $columns); |
|
1386 | 1386 | |
1387 | 1387 | // not all DB's (odbc) return the primary keys via MetaColumns |
1388 | - if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') && |
|
1388 | + if (!count($definition['pk']) && method_exists($this->dict, 'MetaPrimaryKeys') && |
|
1389 | 1389 | is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary)) |
1390 | 1390 | { |
1391 | - if($this->capabilities['name_case'] == 'upper') |
|
1391 | + if ($this->capabilities['name_case'] == 'upper') |
|
1392 | 1392 | { |
1393 | 1393 | array_walk($primary, function(&$s) |
1394 | 1394 | { |
@@ -1397,10 +1397,10 @@ discard block |
||
1397 | 1397 | } |
1398 | 1398 | $definition['pk'] = $primary; |
1399 | 1399 | } |
1400 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
1400 | + if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2", False, $sTableName, $primary); |
|
1401 | 1401 | |
1402 | 1402 | $this->GetIndexes($sTableName, $definition); |
1403 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
1403 | + if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2", False, $sTableName, $definition); |
|
1404 | 1404 | |
1405 | 1405 | return $definition; |
1406 | 1406 | } |
@@ -1412,35 +1412,35 @@ discard block |
||
1412 | 1412 | * @param array& $definition=array() |
1413 | 1413 | * @return array of arrays with keys 'ix' and 'uc' |
1414 | 1414 | */ |
1415 | - public function GetIndexes($sTableName, array &$definition=array()) |
|
1415 | + public function GetIndexes($sTableName, array &$definition = array()) |
|
1416 | 1416 | { |
1417 | - if (method_exists($this->dict,'MetaIndexes') && |
|
1417 | + if (method_exists($this->dict, 'MetaIndexes') && |
|
1418 | 1418 | is_array($indexes = $this->dict->MetaIndexes($sTableName)) && count($indexes)) |
1419 | 1419 | { |
1420 | - foreach($indexes as $index) |
|
1420 | + foreach ($indexes as $index) |
|
1421 | 1421 | { |
1422 | 1422 | // append (optional) length of index in brackets to column |
1423 | - foreach((array)$index['length'] as $col => $length) |
|
1423 | + foreach ((array)$index['length'] as $col => $length) |
|
1424 | 1424 | { |
1425 | 1425 | if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')'; |
1426 | 1426 | } |
1427 | - if($this->capabilities['name_case'] == 'upper') |
|
1427 | + if ($this->capabilities['name_case'] == 'upper') |
|
1428 | 1428 | { |
1429 | 1429 | array_walk($index['columns'], function(&$s) |
1430 | 1430 | { |
1431 | 1431 | $s = strtolower($s); |
1432 | 1432 | }); |
1433 | 1433 | } |
1434 | - if (!empty($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) || |
|
1435 | - $index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk']))) |
|
1434 | + if (!empty($definition['pk']) && (implode(':', $definition['pk']) == implode(':', $index['columns']) || |
|
1435 | + $index['unique'] && count(array_intersect($definition['pk'], $index['columns'])) == count($definition['pk']))) |
|
1436 | 1436 | { |
1437 | - continue; // is already the primary key => ignore it |
|
1437 | + continue; // is already the primary key => ignore it |
|
1438 | 1438 | } |
1439 | 1439 | $kind = $index['unique'] ? 'uc' : 'ix'; |
1440 | 1440 | |
1441 | 1441 | $definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0]; |
1442 | 1442 | } |
1443 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
1443 | + if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2", False, $sTableName, $indexes); |
|
1444 | 1444 | } |
1445 | 1445 | return $definition; |
1446 | 1446 | } |
@@ -1454,7 +1454,7 @@ discard block |
||
1454 | 1454 | */ |
1455 | 1455 | function CheckCreateIndexes() |
1456 | 1456 | { |
1457 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
1457 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
1458 | 1458 | { |
1459 | 1459 | if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue; |
1460 | 1460 | |
@@ -1463,9 +1463,9 @@ discard block |
||
1463 | 1463 | $current = $this->m_odb->metadata($table, true); |
1464 | 1464 | |
1465 | 1465 | // iterate though indexes we should have according to tables_current |
1466 | - foreach(array('uc', 'ix') as $type) |
|
1466 | + foreach (array('uc', 'ix') as $type) |
|
1467 | 1467 | { |
1468 | - foreach($table_def[$type] as $columns) |
|
1468 | + foreach ($table_def[$type] as $columns) |
|
1469 | 1469 | { |
1470 | 1470 | // sometimes primary key is listed as (unique) index too --> ignore it |
1471 | 1471 | if ($this->_in_index($columns, array($table_def['pk']), true)) continue; |
@@ -1502,27 +1502,26 @@ discard block |
||
1502 | 1502 | * old translator function, use GetTableDefition() instead |
1503 | 1503 | * @depricated |
1504 | 1504 | */ |
1505 | - function _GetColumns($oProc,$sTableName,&$sColumns) |
|
1505 | + function _GetColumns($oProc, $sTableName, &$sColumns) |
|
1506 | 1506 | { |
1507 | - unset($oProc); // unused, but required by function signature |
|
1507 | + unset($oProc); // unused, but required by function signature |
|
1508 | 1508 | $this->sCol = $this->pk = $this->fk = $this->ix = $this->uc = array(); |
1509 | 1509 | |
1510 | 1510 | $tabledef = $this->GetTableDefinition($sTableName); |
1511 | 1511 | |
1512 | - $sColumns = implode(',',array_keys($tabledef['fd'])); |
|
1512 | + $sColumns = implode(',', array_keys($tabledef['fd'])); |
|
1513 | 1513 | |
1514 | - foreach($tabledef['fd'] as $column => $data) |
|
1514 | + foreach ($tabledef['fd'] as $column => $data) |
|
1515 | 1515 | { |
1516 | 1516 | $col_def = "'type' => '$data[type]'"; |
1517 | 1517 | unset($data['type']); |
1518 | - foreach($data as $key => $val) |
|
1518 | + foreach ($data as $key => $val) |
|
1519 | 1519 | { |
1520 | - $col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : |
|
1521 | - (is_int($val) ? $val : "'$val'")); |
|
1520 | + $col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : (is_int($val) ? $val : "'$val'")); |
|
1522 | 1521 | } |
1523 | 1522 | $this->sCol[] = "\t\t\t\t'$column' => array($col_def),\n"; |
1524 | 1523 | } |
1525 | - foreach(array('pk','fk','ix','uc') as $kind) |
|
1524 | + foreach (array('pk', 'fk', 'ix', 'uc') as $kind) |
|
1526 | 1525 | { |
1527 | 1526 | $this->$kind = $tabledef[$kind]; |
1528 | 1527 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | function __construct($dbms=False, Api\Db $db=null) |
102 | 102 | { |
103 | 103 | if(is_object($db)) |
104 | - { |
|
104 | + { |
|
105 | 105 | $this->m_odb = $db; |
106 | 106 | } |
107 | 107 | else |
@@ -120,7 +120,10 @@ discard block |
||
120 | 120 | $this->dict = NewDataDictionary($this->adodb); |
121 | 121 | |
122 | 122 | // enable the debuging in ADOdb's datadictionary if the debug-level is greater then 1 |
123 | - if ($this->debug > 1) $this->dict->debug = True; |
|
123 | + if ($this->debug > 1) |
|
124 | + { |
|
125 | + $this->dict->debug = True; |
|
126 | + } |
|
124 | 127 | |
125 | 128 | // to allow some of the former translator-functions to be called, we assign ourself as the translator |
126 | 129 | $this->m_oTranslator = &$this; |
@@ -163,7 +166,10 @@ discard block |
||
163 | 166 | { |
164 | 167 | unset($columns['options']); |
165 | 168 | $columns = implode('-',$columns); |
166 | - if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns); |
|
169 | + if ($ignore_length_limit) |
|
170 | + { |
|
171 | + $columns = preg_replace('/\(\d+\)/', '', $columns); |
|
172 | + } |
|
167 | 173 | } |
168 | 174 | foreach($indexs as $index) |
169 | 175 | { |
@@ -172,8 +178,14 @@ discard block |
||
172 | 178 | unset($index['options']); |
173 | 179 | $index = implode('-',$index); |
174 | 180 | } |
175 | - if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index); |
|
176 | - if ($columns == $index) return true; |
|
181 | + if ($ignore_length_limit) |
|
182 | + { |
|
183 | + $index = preg_replace('/\(\d+\)/', '', $index); |
|
184 | + } |
|
185 | + if ($columns == $index) |
|
186 | + { |
|
187 | + return true; |
|
188 | + } |
|
177 | 189 | } |
178 | 190 | return false; |
179 | 191 | } |
@@ -235,12 +247,20 @@ discard block |
||
235 | 247 | $options = False; |
236 | 248 | if (is_array($mFields)) |
237 | 249 | { |
238 | - if (isset($mFields['options'])) // array sets additional options |
|
250 | + if (isset($mFields['options'])) |
|
251 | + { |
|
252 | + // array sets additional options |
|
239 | 253 | { |
240 | 254 | if (isset($mFields['options'][$this->sType])) |
241 | 255 | { |
242 | - $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
243 | - if (!$options) continue; // no index for our db-type |
|
256 | + $options = $mFields['options'][$this->sType]; |
|
257 | + } |
|
258 | + // db-specific options, eg. index-type |
|
259 | + if (!$options) |
|
260 | + { |
|
261 | + continue; |
|
262 | + } |
|
263 | + // no index for our db-type |
|
244 | 264 | } |
245 | 265 | unset($mFields['options']); |
246 | 266 | } |
@@ -251,15 +271,22 @@ discard block |
||
251 | 271 | // most DB's cant do them and give errors |
252 | 272 | if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext'))) |
253 | 273 | { |
254 | - if (is_array($mFields)) // index over multiple columns including a text column |
|
274 | + if (is_array($mFields)) |
|
255 | 275 | { |
256 | - $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
276 | + // index over multiple columns including a text column |
|
277 | + { |
|
278 | + $mFields[$k] .= '(32)'; |
|
279 | + } |
|
280 | + // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
257 | 281 | } |
258 | - elseif (!$options) // index over a single text column and no options given |
|
282 | + elseif (!$options) |
|
283 | + { |
|
284 | + // index over a single text column and no options given |
|
259 | 285 | { |
260 | 286 | if ($this->sType == 'mysql') |
261 | 287 | { |
262 | 288 | $options = 'FULLTEXT'; |
289 | + } |
|
263 | 290 | } |
264 | 291 | else |
265 | 292 | { |
@@ -300,8 +327,14 @@ discard block |
||
300 | 327 | return False; |
301 | 328 | } |
302 | 329 | // set our debug-mode or $bOutputHTML is the other one is set |
303 | - if ($this->debug) $bOutputHTML = True; |
|
304 | - if ($bOutputHTML && !$this->debug) $this->debug = 2; |
|
330 | + if ($this->debug) |
|
331 | + { |
|
332 | + $bOutputHTML = True; |
|
333 | + } |
|
334 | + if ($bOutputHTML && !$this->debug) |
|
335 | + { |
|
336 | + $this->debug = 2; |
|
337 | + } |
|
305 | 338 | |
306 | 339 | foreach(array_keys($aTables) as $sTableName) |
307 | 340 | { |
@@ -328,7 +361,10 @@ discard block |
||
328 | 361 | */ |
329 | 362 | function DropTable($sTableName) |
330 | 363 | { |
331 | - if ($this->sType == 'pgsql') $this->_PostgresTestDropOldSequence($sTableName); |
|
364 | + if ($this->sType == 'pgsql') |
|
365 | + { |
|
366 | + $this->_PostgresTestDropOldSequence($sTableName); |
|
367 | + } |
|
332 | 368 | |
333 | 369 | $aSql = $this->dict->DropTableSql($sTableName); |
334 | 370 | |
@@ -347,7 +383,10 @@ discard block |
||
347 | 383 | { |
348 | 384 | unset($aTableDef); // not used, but required by function signature |
349 | 385 | |
350 | - if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
|
386 | + if (!($table_def = $this->GetTableDefinition($sTableName))) |
|
387 | + { |
|
388 | + return 0; |
|
389 | + } |
|
351 | 390 | unset($table_def['fd'][$sColumnName]); |
352 | 391 | |
353 | 392 | $aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def)); |
@@ -368,7 +407,10 @@ discard block |
||
368 | 407 | // we create a new table, copy the content and drop the old one |
369 | 408 | if ($this->sType == 'pgsql') |
370 | 409 | { |
371 | - if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0; |
|
410 | + if (!($table_def = $this->GetTableDefinition($sOldTableName))) |
|
411 | + { |
|
412 | + return 0; |
|
413 | + } |
|
372 | 414 | |
373 | 415 | // only use old PostgreSQL stuff, if we have an old sequence, otherwise rely on it being new enough |
374 | 416 | if ($this->_PostgresHasOldSequence($sOldTableName,True) && |
@@ -402,7 +444,10 @@ discard block |
||
402 | 444 | */ |
403 | 445 | function _PostgresHasOldSequence($sTableName,$preserveValue=False) |
404 | 446 | { |
405 | - if ($this->sType != 'pgsql') return false; |
|
447 | + if ($this->sType != 'pgsql') |
|
448 | + { |
|
449 | + return false; |
|
450 | + } |
|
406 | 451 | |
407 | 452 | $seq = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%seq_$sTableName''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum"); |
408 | 453 | $seq2 = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%$sTableName%_seq''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum"); |
@@ -410,12 +455,18 @@ discard block |
||
410 | 455 | $matches = null; |
411 | 456 | if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches)) |
412 | 457 | { |
413 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
458 | + if ($preserveValue) |
|
459 | + { |
|
460 | + $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
461 | + } |
|
414 | 462 | return $matches[1]; |
415 | 463 | } |
416 | 464 | if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches)) |
417 | 465 | { |
418 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
466 | + if ($preserveValue) |
|
467 | + { |
|
468 | + $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
469 | + } |
|
419 | 470 | return $matches[1]; |
420 | 471 | } |
421 | 472 | return false; |
@@ -449,7 +500,10 @@ discard block |
||
449 | 500 | */ |
450 | 501 | function AlterColumn($sTableName, $sColumnName, $aColumnDef) |
451 | 502 | { |
452 | - if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
|
503 | + if (!($table_def = $this->GetTableDefinition($sTableName))) |
|
504 | + { |
|
505 | + return 0; |
|
506 | + } |
|
453 | 507 | |
454 | 508 | // PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long |
455 | 509 | if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
@@ -552,8 +606,14 @@ discard block |
||
552 | 606 | { |
553 | 607 | $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
554 | 608 | } |
555 | - if (!is_array($options)) $options = $options ? array($options) : array(); |
|
556 | - if ($bUnique) $options[] = 'UNIQUE'; |
|
609 | + if (!is_array($options)) |
|
610 | + { |
|
611 | + $options = $options ? array($options) : array(); |
|
612 | + } |
|
613 | + if ($bUnique) |
|
614 | + { |
|
615 | + $options[] = 'UNIQUE'; |
|
616 | + } |
|
557 | 617 | |
558 | 618 | // if index already exists drop it first |
559 | 619 | $definition = array(); |
@@ -635,7 +695,9 @@ discard block |
||
635 | 695 | $seq_name = $matches[1]; |
636 | 696 | } |
637 | 697 | $sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName"; |
638 | - if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
698 | + if($this->debug) |
|
699 | + { |
|
700 | +echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
639 | 701 | return $this->query($sql,__LINE__,__FILE__); |
640 | 702 | } |
641 | 703 | return True; |
@@ -655,7 +717,9 @@ discard block |
||
655 | 717 | */ |
656 | 718 | function RefreshTable($sTableName, $aTableDef, $aDefaults=False) |
657 | 719 | { |
658 | - if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
720 | + if($this->debug) |
|
721 | + { |
|
722 | +echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
659 | 723 | |
660 | 724 | $old_table_def = $this->GetTableDefinition($sTableName); |
661 | 725 | |
@@ -682,21 +746,30 @@ discard block |
||
682 | 746 | $value = "nextval('$sequence_name')"; break; |
683 | 747 | } |
684 | 748 | } |
685 | - elseif ($aDefaults && isset($aDefaults[$name])) // use given default |
|
749 | + elseif ($aDefaults && isset($aDefaults[$name])) |
|
750 | + { |
|
751 | + // use given default |
|
686 | 752 | { |
687 | 753 | $value = $aDefaults[$name]; |
688 | 754 | } |
689 | - elseif (isset($old_table_def['fd'][$name])) // existing column, use its value => column-name in query |
|
755 | + } |
|
756 | + elseif (isset($old_table_def['fd'][$name])) |
|
757 | + { |
|
758 | + // existing column, use its value => column-name in query |
|
690 | 759 | { |
691 | 760 | $value = $name; |
761 | + } |
|
692 | 762 | |
693 | - if ($this->sType == 'pgsql') // some postgres specific code |
|
763 | + if ($this->sType == 'pgsql') |
|
764 | + { |
|
765 | + // some postgres specific code |
|
694 | 766 | { |
695 | 767 | // this is eg. necessary to change a varchar into an int column under postgres |
696 | 768 | if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) && |
697 | 769 | in_array($data['type'],array('int','decimal'))) |
698 | 770 | { |
699 | 771 | $value = "to_number($name,'S9999999999999D99')"; |
772 | + } |
|
700 | 773 | } |
701 | 774 | // blobs cant be casted to text |
702 | 775 | elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
@@ -751,8 +824,15 @@ discard block |
||
751 | 824 | switch($this->sType) |
752 | 825 | { |
753 | 826 | case 'mssql': |
754 | - if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
|
755 | - if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
827 | + if ($auto_column_included) |
|
828 | + { |
|
829 | + $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
|
830 | + } |
|
831 | + if ($blob_column_included) |
|
832 | + { |
|
833 | + $distinct = ''; |
|
834 | + } |
|
835 | + // no distinct on blob-columns |
|
756 | 836 | break; |
757 | 837 | } |
758 | 838 | // because of all the trouble with sequences and indexes in the global namespace, |
@@ -816,8 +896,14 @@ discard block |
||
816 | 896 | return False; |
817 | 897 | } |
818 | 898 | // set our debug-mode or $bOutputHTML is the other one is set |
819 | - if ($this->debug) $bOutputHTML = True; |
|
820 | - if ($bOutputHTML && !$this->debug) $this->debug = 2; |
|
899 | + if ($this->debug) |
|
900 | + { |
|
901 | + $bOutputHTML = True; |
|
902 | + } |
|
903 | + if ($bOutputHTML && !$this->debug) |
|
904 | + { |
|
905 | + $this->debug = 2; |
|
906 | + } |
|
821 | 907 | |
822 | 908 | foreach($aTables as $sTableName => $aTableDef) |
823 | 909 | { |
@@ -930,9 +1016,12 @@ discard block |
||
930 | 1016 | */ |
931 | 1017 | function ExecuteSqlArray($aSql,$debug_level) |
932 | 1018 | { |
933 | - if ($this->m_odb->query_log) // we use Db::query to log the queries |
|
1019 | + if ($this->m_odb->query_log) |
|
1020 | + { |
|
1021 | + // we use Db::query to log the queries |
|
934 | 1022 | { |
935 | 1023 | $retval = 2; |
1024 | + } |
|
936 | 1025 | foreach($aSql as $sql) |
937 | 1026 | { |
938 | 1027 | if (!$this->m_odb->query($sql,__LINE__,__FILE__)) |
@@ -1015,10 +1104,13 @@ discard block |
||
1015 | 1104 | |
1016 | 1105 | // this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle |
1017 | 1106 | if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 || |
1018 | - strlen($name) >= 64) // even mysql has a limit here ;-) |
|
1107 | + strlen($name) >= 64) |
|
1108 | + { |
|
1109 | + // even mysql has a limit here ;-) |
|
1019 | 1110 | { |
1020 | 1111 | $name = "i".substr(md5($name),0,29); |
1021 | 1112 | } |
1113 | + } |
|
1022 | 1114 | return $name; |
1023 | 1115 | } |
1024 | 1116 | |
@@ -1260,7 +1352,10 @@ discard block |
||
1260 | 1352 | $type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
1261 | 1353 | |
1262 | 1354 | // fix longtext not correctly handled by ADOdb |
1263 | - if ($type == 'X' && $column->type == 'longtext') $type = 'XL'; |
|
1355 | + if ($type == 'X' && $column->type == 'longtext') |
|
1356 | + { |
|
1357 | + $type = 'XL'; |
|
1358 | + } |
|
1264 | 1359 | |
1265 | 1360 | static $ado_type2egw = array( |
1266 | 1361 | 'C' => 'varchar', |
@@ -1367,10 +1462,13 @@ discard block |
||
1367 | 1462 | } |
1368 | 1463 | if ($column->has_default) |
1369 | 1464 | { |
1370 | - if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) // postgres |
|
1465 | + if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) |
|
1466 | + { |
|
1467 | + // postgres |
|
1371 | 1468 | { |
1372 | 1469 | $column->default_value = $matches[1]; |
1373 | 1470 | } |
1471 | + } |
|
1374 | 1472 | $definition['fd'][$name]['default'] = $column->default_value; |
1375 | 1473 | } |
1376 | 1474 | if ($column->not_null) |
@@ -1382,7 +1480,10 @@ discard block |
||
1382 | 1480 | $definition['pk'][] = $name; |
1383 | 1481 | } |
1384 | 1482 | } |
1385 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
1483 | + if ($this->debug > 2) |
|
1484 | + { |
|
1485 | + $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
1486 | + } |
|
1386 | 1487 | |
1387 | 1488 | // not all DB's (odbc) return the primary keys via MetaColumns |
1388 | 1489 | if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') && |
@@ -1397,10 +1498,16 @@ discard block |
||
1397 | 1498 | } |
1398 | 1499 | $definition['pk'] = $primary; |
1399 | 1500 | } |
1400 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
1501 | + if ($this->debug > 1) |
|
1502 | + { |
|
1503 | + $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
1504 | + } |
|
1401 | 1505 | |
1402 | 1506 | $this->GetIndexes($sTableName, $definition); |
1403 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
1507 | + if ($this->debug > 1) |
|
1508 | + { |
|
1509 | + $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
1510 | + } |
|
1404 | 1511 | |
1405 | 1512 | return $definition; |
1406 | 1513 | } |
@@ -1422,7 +1529,10 @@ discard block |
||
1422 | 1529 | // append (optional) length of index in brackets to column |
1423 | 1530 | foreach((array)$index['length'] as $col => $length) |
1424 | 1531 | { |
1425 | - if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')'; |
|
1532 | + if (($key = array_search($col, $index['columns']))) |
|
1533 | + { |
|
1534 | + $index['columns'][$key] .= '('.$length.')'; |
|
1535 | + } |
|
1426 | 1536 | } |
1427 | 1537 | if($this->capabilities['name_case'] == 'upper') |
1428 | 1538 | { |
@@ -1440,7 +1550,10 @@ discard block |
||
1440 | 1550 | |
1441 | 1551 | $definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0]; |
1442 | 1552 | } |
1443 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
1553 | + if ($this->debug > 2) |
|
1554 | + { |
|
1555 | + $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
1556 | + } |
|
1444 | 1557 | } |
1445 | 1558 | return $definition; |
1446 | 1559 | } |
@@ -1456,7 +1569,10 @@ discard block |
||
1456 | 1569 | { |
1457 | 1570 | foreach($this->adodb->MetaTables('TABLES') as $table) |
1458 | 1571 | { |
1459 | - if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue; |
|
1572 | + if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) |
|
1573 | + { |
|
1574 | + continue; |
|
1575 | + } |
|
1460 | 1576 | |
1461 | 1577 | $definition = array(); |
1462 | 1578 | $this->GetIndexes($table, $definition); |
@@ -1468,7 +1584,10 @@ discard block |
||
1468 | 1584 | foreach($table_def[$type] as $columns) |
1469 | 1585 | { |
1470 | 1586 | // sometimes primary key is listed as (unique) index too --> ignore it |
1471 | - if ($this->_in_index($columns, array($table_def['pk']), true)) continue; |
|
1587 | + if ($this->_in_index($columns, array($table_def['pk']), true)) |
|
1588 | + { |
|
1589 | + continue; |
|
1590 | + } |
|
1472 | 1591 | |
1473 | 1592 | // current table does NOT contain all columns, eg. not yet updated --> ignore index |
1474 | 1593 | if (array_diff((array)$columns, array_keys($current['meta']))) |
@@ -1485,7 +1604,10 @@ discard block |
||
1485 | 1604 | if ($this->_in_index($columns, $definition[$type], true)) |
1486 | 1605 | { |
1487 | 1606 | // for PostgreSQL we dont use length-limited indexes --> nothing to do |
1488 | - if ($this->m_odb->Type == 'pgsql') continue; |
|
1607 | + if ($this->m_odb->Type == 'pgsql') |
|
1608 | + { |
|
1609 | + continue; |
|
1610 | + } |
|
1489 | 1611 | // for MySQL we drop current index and create it with correct length |
1490 | 1612 | $this->DropIndex($table, $columns); |
1491 | 1613 | } |
@@ -543,7 +543,7 @@ |
||
543 | 543 | * |
544 | 544 | * @param string $name cell-name |
545 | 545 | * @param string $attr attribute-name |
546 | - * @param mixed $val if not NULL sets attribute else returns it |
|
546 | + * @param boolean|string $val if not NULL sets attribute else returns it |
|
547 | 547 | * @return reference to attribute |
548 | 548 | * @deprecated use setElementAttribute($name, $attr, $val) |
549 | 549 | */ |
@@ -158,7 +158,7 @@ |
||
158 | 158 | // instanciate template to fill self::$request->sel_options for select-* widgets |
159 | 159 | // not sure if we want to handle it this way, thought otherwise we will have a few ajax request for each dialog fetching predefined selectboxes |
160 | 160 | $template = self::instance($this->name, $this->template_set, $this->version, $this->laod_via); |
161 | - if (!$template) throw new Exception\AssertionFailed("Template $this->name not instanciable! Maybe you forgot to rename template id."); |
|
161 | + if (!$template) throw new Exception\AssertionFailed("template $this->name not instanciable! Maybe you forgot to rename template id."); |
|
162 | 162 | $this->children = array($template); |
163 | 163 | $template->run('beforeSendToClient', array('', array('cont'=>$content))); |
164 | 164 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @public boolean |
31 | 31 | */ |
32 | - public $sitemgr=false; |
|
32 | + public $sitemgr = false; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Tell egw framework it's ok to call this |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | * @param string $name of etemplate or array with name and other keys |
45 | 45 | * @param string|array $load_via with keys of other etemplate to load in order to get $name |
46 | 46 | */ |
47 | - function __construct($name='',$load_via='') |
|
47 | + function __construct($name = '', $load_via = '') |
|
48 | 48 | { |
49 | 49 | // we do NOT call parent consturctor, as we only want to enherit it's (static) methods |
50 | - if (false) parent::__construct ($name); // satisfy IDE, as we dont call parent constructor |
|
50 | + if (false) parent::__construct($name); // satisfy IDE, as we dont call parent constructor |
|
51 | 51 | |
52 | 52 | $this->sitemgr = isset($GLOBALS['Common_BO']) && is_object($GLOBALS['Common_BO']); |
53 | 53 | |
54 | - if ($name) $this->read($name,$template='default','default',0,'',$load_via); |
|
54 | + if ($name) $this->read($name, $template = 'default', 'default', 0, '', $load_via); |
|
55 | 55 | |
56 | 56 | // generate new etemplate request object, if not already existing |
57 | - if(!isset(self::$request)) self::$request = Etemplate\Request::read(); |
|
57 | + if (!isset(self::$request)) self::$request = Etemplate\Request::read(); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param string|array $params url or array with get-params incl. menuaction |
67 | 67 | */ |
68 | - static function location($params='') |
|
68 | + static function location($params = '') |
|
69 | 69 | { |
70 | 70 | Framework::redirect_link(is_array($params) ? '/index.php' : $params, |
71 | 71 | is_array($params) ? $params : ''); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @param array $changes change made in the last call if looping, only used internaly by process_exec |
101 | 101 | * @return string html for $output_mode == 1, else nothing |
102 | 102 | */ |
103 | - function exec($method,array $content,array $sel_options=null,array $readonlys=null,array $preserv=null,$output_mode=0,$ignore_validation='',array $changes=null) |
|
103 | + function exec($method, array $content, array $sel_options = null, array $readonlys = null, array $preserv = null, $output_mode = 0, $ignore_validation = '', array $changes = null) |
|
104 | 104 | { |
105 | 105 | $hook_data = Hooks::process( |
106 | 106 | array('hook_location' => 'etemplate2_before_exec') + |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | $content |
110 | 110 | ); |
111 | 111 | |
112 | - foreach($hook_data as $extras) |
|
112 | + foreach ($hook_data as $extras) |
|
113 | 113 | { |
114 | 114 | if (!$extras) continue; |
115 | 115 | |
116 | - foreach(count(array_filter(array_keys($extras), 'is_int')) ? $extras : array($extras) as $extra) |
|
116 | + foreach (count(array_filter(array_keys($extras), 'is_int')) ? $extras : array($extras) as $extra) |
|
117 | 117 | { |
118 | 118 | if ($extra['data'] && is_array($extra['data'])) |
119 | 119 | { |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $output_mode = 0; |
149 | 149 | self::$response = Json\Response::get(); |
150 | 150 | } |
151 | - self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup |
|
151 | + self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup |
|
152 | 152 | self::$request->content = self::$cont = $content; |
153 | 153 | self::$request->changes = $changes; |
154 | 154 | self::$request->sel_options = is_array($sel_options) ? self::fix_sel_options($sel_options) : array(); |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | |
173 | 173 | // compile required translations translations |
174 | 174 | $currentapp = $GLOBALS['egw_info']['flags']['currentapp']; |
175 | - $langRequire = array('common' => array(), 'etemplate' => array()); // keep that order |
|
176 | - foreach(Translation::$loaded_apps as $l_app => $lang) |
|
175 | + $langRequire = array('common' => array(), 'etemplate' => array()); // keep that order |
|
176 | + foreach (Translation::$loaded_apps as $l_app => $lang) |
|
177 | 177 | { |
178 | 178 | if (!in_array($l_app, array($currentapp, 'custom'))) |
179 | 179 | { |
180 | 180 | $langRequire[$l_app] = array('app' => $l_app, 'lang' => $lang, 'etag' => Translation::etag($l_app, $lang)); |
181 | 181 | } |
182 | 182 | } |
183 | - foreach(array($currentapp, 'custom') as $l_app) |
|
183 | + foreach (array($currentapp, 'custom') as $l_app) |
|
184 | 184 | { |
185 | 185 | if (isset(Translation::$loaded_apps[$l_app])) |
186 | 186 | { |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | ); |
202 | 202 | |
203 | 203 | // Info required to load the etemplate client-side |
204 | - $dom_id = str_replace('.','-',$this->dom_id); |
|
204 | + $dom_id = str_replace('.', '-', $this->dom_id); |
|
205 | 205 | $load_array = array( |
206 | 206 | 'name' => $this->name, |
207 | 207 | 'url' => self::rel2url($this->rel_path), |
@@ -211,16 +211,16 @@ discard block |
||
211 | 211 | if (self::$response) // call is within an ajax event / form submit |
212 | 212 | { |
213 | 213 | //error_log("Ajax " . __LINE__); |
214 | - self::$response->generic('et2_load', $load_array+Framework::get_extra()); |
|
215 | - Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
214 | + self::$response->generic('et2_load', $load_array + Framework::get_extra()); |
|
215 | + Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
216 | 216 | } |
217 | 217 | else // first call |
218 | 218 | { |
219 | 219 | // check if application of template has a app.js file --> load it |
220 | - list($app) = explode('.',$this->name); |
|
220 | + list($app) = explode('.', $this->name); |
|
221 | 221 | if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js')) |
222 | 222 | { |
223 | - Framework::includeJS('.','app',$app,true); |
|
223 | + Framework::includeJS('.', 'app', $app, true); |
|
224 | 224 | } |
225 | 225 | // Category styles |
226 | 226 | Categories::css($app); |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | $content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n". |
239 | 239 | '<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>'; |
240 | 240 | $GLOBALS['egw']->framework->response->generic("data", array($content)); |
241 | - $GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra()); |
|
242 | - Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
241 | + $GLOBALS['egw']->framework->response->generic('et2_load', $load_array + Framework::get_extra()); |
|
242 | + Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
243 | 243 | self::$request = null; |
244 | 244 | return; |
245 | 245 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | echo '<div id="popupMainDiv" class="popupMainDiv">'."\n"; |
259 | 259 | } |
260 | 260 | // Send any accumulated json responses - after flush to avoid sending the buffer as a response |
261 | - if(Json\Response::isJSONResponse()) |
|
261 | + if (Json\Response::isJSONResponse()) |
|
262 | 262 | { |
263 | 263 | $load_array['response'] = Json\Response::get()->returnResult(); |
264 | 264 | } |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | */ |
288 | 288 | static protected function fix_sel_options(array $sel_options) |
289 | 289 | { |
290 | - foreach($sel_options as &$options) |
|
290 | + foreach ($sel_options as &$options) |
|
291 | 291 | { |
292 | - if (!is_array($options)||empty($options)) continue; |
|
293 | - foreach($options as $key => $value) |
|
292 | + if (!is_array($options) || empty($options)) continue; |
|
293 | + foreach ($options as $key => $value) |
|
294 | 294 | { |
295 | 295 | if (is_numeric($key) && (!is_array($value) || !isset($value['value']))) |
296 | 296 | { |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | $GLOBALS['egw']->session->set_action('Etemplate: '.self::$request->method); |
330 | 330 | |
331 | 331 | // Set current app for validation |
332 | - list($app) = explode('.',self::$request->method); |
|
333 | - if(!$app) list($app) = explode('::',self::$request->method); |
|
334 | - if($app) |
|
332 | + list($app) = explode('.', self::$request->method); |
|
333 | + if (!$app) list($app) = explode('::', self::$request->method); |
|
334 | + if ($app) |
|
335 | 335 | { |
336 | 336 | Translation::add_app($app); |
337 | 337 | $GLOBALS['egw_info']['flags']['currentapp'] = $app; |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | $expand = array( |
341 | 341 | 'cont' => &self::$request->content, |
342 | 342 | ); |
343 | - $template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
343 | + $template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
344 | 344 | |
345 | 345 | if ($no_validation) |
346 | 346 | { |
@@ -356,14 +356,14 @@ discard block |
||
356 | 356 | // tell request call to remove request, if it is not modified eg. by call to exec in callback |
357 | 357 | self::$request->remove_if_not_modified(); |
358 | 358 | |
359 | - foreach(Hooks::process(array( |
|
359 | + foreach (Hooks::process(array( |
|
360 | 360 | 'hook_location' => 'etemplate2_before_process', |
361 | 361 | 'location_name' => $template->id, |
362 | 362 | ) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras) |
363 | 363 | { |
364 | 364 | if (!$extras) continue; |
365 | 365 | |
366 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
|
366 | + foreach (isset($extras[0]) ? $extras : array($extras) as $extra) |
|
367 | 367 | { |
368 | 368 | if ($extra['data'] && is_array($extra['data'])) |
369 | 369 | { |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | |
375 | 375 | //error_log(__METHOD__."(,".array2string($content).')'); |
376 | 376 | //error_log(' validated='.array2string($validated)); |
377 | - if(is_callable(self::$request->method)) |
|
377 | + if (is_callable(self::$request->method)) |
|
378 | 378 | { |
379 | - call_user_func(self::$request->method,self::complete_array_merge(self::$request->preserv, $validated)); |
|
379 | + call_user_func(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated)); |
|
380 | 380 | } |
381 | 381 | else |
382 | 382 | { |
@@ -384,8 +384,7 @@ discard block |
||
384 | 384 | $content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated)); |
385 | 385 | } |
386 | 386 | |
387 | - $tcontent = is_array($content) ? $content : |
|
388 | - self::complete_array_merge(self::$request->preserv, $validated); |
|
387 | + $tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated); |
|
389 | 388 | |
390 | 389 | $hook_data = Hooks::process( |
391 | 390 | array( |
@@ -397,11 +396,11 @@ discard block |
||
397 | 396 | |
398 | 397 | if (is_array($content)) |
399 | 398 | { |
400 | - foreach($hook_data as $extras) |
|
399 | + foreach ($hook_data as $extras) |
|
401 | 400 | { |
402 | 401 | if (!$extras) continue; |
403 | 402 | |
404 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
403 | + foreach (isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
405 | 404 | if ($extra['data'] && is_array($extra['data'])) { |
406 | 405 | $content = array_merge($content, $extra['data']); |
407 | 406 | } |
@@ -413,7 +412,7 @@ discard block |
||
413 | 412 | if (isset($GLOBALS['egw_info']['flags']['java_script'])) |
414 | 413 | { |
415 | 414 | // Strip out any script tags |
416 | - $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']); |
|
415 | + $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']); |
|
417 | 416 | self::$response->script($GLOBALS['egw_info']['flags']['java_script']); |
418 | 417 | //error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.'); |
419 | 418 | } |
@@ -442,7 +441,7 @@ discard block |
||
442 | 441 | static public function process_exec() |
443 | 442 | { |
444 | 443 | if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']); |
445 | - $content = json_decode($_POST['value'],true); |
|
444 | + $content = json_decode($_POST['value'], true); |
|
446 | 445 | //error_log(__METHOD__."(".array2string($content).")"); |
447 | 446 | |
448 | 447 | self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']); |
@@ -456,7 +455,7 @@ discard block |
||
456 | 455 | $expand = array( |
457 | 456 | 'cont' => &self::$request->content, |
458 | 457 | ); |
459 | - $template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
458 | + $template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
460 | 459 | if (self::validation_errors(self::$request->ignore_validation)) |
461 | 460 | { |
462 | 461 | error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors)); |
@@ -492,7 +491,7 @@ discard block |
||
492 | 491 | * |
493 | 492 | * @ToDo supported customized templates stored in DB |
494 | 493 | */ |
495 | - public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='') |
|
494 | + public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '') |
|
496 | 495 | { |
497 | 496 | |
498 | 497 | // For mobile experience try to load custom mobile templates |
@@ -501,9 +500,9 @@ discard block |
||
501 | 500 | $template_set = "mobile"; |
502 | 501 | } |
503 | 502 | |
504 | - unset($lang); unset($group); // not used, but in old signature |
|
505 | - $this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set, |
|
506 | - $this->version=$version, $this->laod_via = $load_via); |
|
503 | + unset($lang); unset($group); // not used, but in old signature |
|
504 | + $this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set, |
|
505 | + $this->version = $version, $this->laod_via = $load_via); |
|
507 | 506 | //error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path)); |
508 | 507 | |
509 | 508 | $this->dom_id = $name; |
@@ -557,7 +556,7 @@ discard block |
||
557 | 556 | * @return mixed reference to attribute, usually NULL |
558 | 557 | * @deprecated use getElementAttribute($name, $attr) |
559 | 558 | */ |
560 | - public function &get_cell_attribute($name,$attr) |
|
559 | + public function &get_cell_attribute($name, $attr) |
|
561 | 560 | { |
562 | 561 | return self::getElementAttribute($name, $attr); |
563 | 562 | } |
@@ -571,7 +570,7 @@ discard block |
||
571 | 570 | * @return reference to attribute |
572 | 571 | * @deprecated use setElementAttribute($name, $attr, $val) |
573 | 572 | */ |
574 | - public function &set_cell_attribute($name,$attr,$val) |
|
573 | + public function &set_cell_attribute($name, $attr, $val) |
|
575 | 574 | { |
576 | 575 | return self::setElementAttribute($name, $attr, $val); |
577 | 576 | } |
@@ -584,7 +583,7 @@ discard block |
||
584 | 583 | * @return reference to attribute |
585 | 584 | * @deprecated use disableElement($name, $disabled=true) |
586 | 585 | */ |
587 | - public function disable_cells($name,$disabled=True) |
|
586 | + public function disable_cells($name, $disabled = True) |
|
588 | 587 | { |
589 | 588 | return self::disableElement($name, $disabled); |
590 | 589 | } |
@@ -600,23 +599,23 @@ discard block |
||
600 | 599 | * @param array $new |
601 | 600 | * @return array the merged array |
602 | 601 | */ |
603 | - public static function complete_array_merge($old,$new) |
|
602 | + public static function complete_array_merge($old, $new) |
|
604 | 603 | { |
605 | 604 | if (is_array($new)) |
606 | 605 | { |
607 | - if (!is_array($old)) $old = (array) $old; |
|
606 | + if (!is_array($old)) $old = (array)$old; |
|
608 | 607 | |
609 | - foreach($new as $k => $v) |
|
608 | + foreach ($new as $k => $v) |
|
610 | 609 | { |
611 | - if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
|
612 | - isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1]) || // or no associative array, eg. selecting multiple accounts |
|
610 | + if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
|
611 | + isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts |
|
613 | 612 | is_array($v) && count($v) == 0) // Empty array replacing non-empty |
614 | 613 | { |
615 | 614 | $old[$k] = $v; |
616 | 615 | } |
617 | 616 | else |
618 | 617 | { |
619 | - $old[$k] = self::complete_array_merge($old[$k],$v); |
|
618 | + $old[$k] = self::complete_array_merge($old[$k], $v); |
|
620 | 619 | } |
621 | 620 | } |
622 | 621 | } |
@@ -628,7 +627,7 @@ discard block |
||
628 | 627 | * |
629 | 628 | * @param array $content =null |
630 | 629 | */ |
631 | - public function debug(array $content=null) |
|
630 | + public function debug(array $content = null) |
|
632 | 631 | { |
633 | 632 | $GLOBALS['egw']->framework->render(print_r($content, true)); |
634 | 633 | } |
@@ -642,11 +641,11 @@ discard block |
||
642 | 641 | * @param int &$max_upload=null on return max. upload size in byte |
643 | 642 | * @return string |
644 | 643 | */ |
645 | - static function max_upload_size_message(&$max_upload=null) |
|
644 | + static function max_upload_size_message(&$max_upload = null) |
|
646 | 645 | { |
647 | 646 | $upload_max_filesize = ini_get('upload_max_filesize'); |
648 | 647 | $post_max_size = ini_get('post_max_size'); |
649 | - $max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800); |
|
648 | + $max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800); |
|
650 | 649 | |
651 | 650 | return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload). |
652 | 651 | " (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)"; |
@@ -660,9 +659,9 @@ discard block |
||
660 | 659 | * @param boolean $readonly =true |
661 | 660 | * @return string |
662 | 661 | */ |
663 | - static public function number_format($number,$num_decimal_places=2,$readonly=true) |
|
662 | + static public function number_format($number, $num_decimal_places = 2, $readonly = true) |
|
664 | 663 | { |
665 | - static $dec_separator=null,$thousands_separator=null; |
|
664 | + static $dec_separator = null, $thousands_separator = null; |
|
666 | 665 | if (is_null($dec_separator)) |
667 | 666 | { |
668 | 667 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
@@ -671,7 +670,7 @@ discard block |
||
671 | 670 | } |
672 | 671 | if ((string)$number === '') return ''; |
673 | 672 | |
674 | - return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : ''); |
|
673 | + return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : ''); |
|
675 | 674 | } |
676 | 675 | |
677 | 676 | /** |
@@ -684,13 +683,13 @@ discard block |
||
684 | 683 | { |
685 | 684 | if (!is_numeric($size)) |
686 | 685 | { |
687 | - switch(strtolower(substr($size,-1))) |
|
686 | + switch (strtolower(substr($size, -1))) |
|
688 | 687 | { |
689 | 688 | case 'm': |
690 | - $size = 1024*1024*(int)$size; |
|
689 | + $size = 1024 * 1024 * (int)$size; |
|
691 | 690 | break; |
692 | 691 | case 'k': |
693 | - $size = 1024*(int)$size; |
|
692 | + $size = 1024 * (int)$size; |
|
694 | 693 | break; |
695 | 694 | } |
696 | 695 | } |
@@ -47,14 +47,24 @@ discard block |
||
47 | 47 | function __construct($name='',$load_via='') |
48 | 48 | { |
49 | 49 | // we do NOT call parent consturctor, as we only want to enherit it's (static) methods |
50 | - if (false) parent::__construct ($name); // satisfy IDE, as we dont call parent constructor |
|
50 | + if (false) |
|
51 | + { |
|
52 | + parent::__construct ($name); |
|
53 | + } |
|
54 | + // satisfy IDE, as we dont call parent constructor |
|
51 | 55 | |
52 | 56 | $this->sitemgr = isset($GLOBALS['Common_BO']) && is_object($GLOBALS['Common_BO']); |
53 | 57 | |
54 | - if ($name) $this->read($name,$template='default','default',0,'',$load_via); |
|
58 | + if ($name) |
|
59 | + { |
|
60 | + $this->read($name,$template='default','default',0,'',$load_via); |
|
61 | + } |
|
55 | 62 | |
56 | 63 | // generate new etemplate request object, if not already existing |
57 | - if(!isset(self::$request)) self::$request = Etemplate\Request::read(); |
|
64 | + if(!isset(self::$request)) |
|
65 | + { |
|
66 | + self::$request = Etemplate\Request::read(); |
|
67 | + } |
|
58 | 68 | } |
59 | 69 | |
60 | 70 | /** |
@@ -111,7 +121,10 @@ discard block |
||
111 | 121 | |
112 | 122 | foreach($hook_data as $extras) |
113 | 123 | { |
114 | - if (!$extras) continue; |
|
124 | + if (!$extras) |
|
125 | + { |
|
126 | + continue; |
|
127 | + } |
|
115 | 128 | |
116 | 129 | foreach(count(array_filter(array_keys($extras), 'is_int')) ? $extras : array($extras) as $extra) |
117 | 130 | { |
@@ -141,7 +154,10 @@ discard block |
||
141 | 154 | // Include the etemplate2 javascript code |
142 | 155 | Framework::includeJS('etemplate', 'etemplate2', 'api'); |
143 | 156 | |
144 | - if (!$this->rel_path) throw new Exception\AssertionFailed("No (valid) template '$this->name' found!"); |
|
157 | + if (!$this->rel_path) |
|
158 | + { |
|
159 | + throw new Exception\AssertionFailed("No (valid) template '$this->name' found!"); |
|
160 | + } |
|
145 | 161 | |
146 | 162 | if ($output_mode == 4) |
147 | 163 | { |
@@ -156,14 +172,23 @@ discard block |
||
156 | 172 | self::$request->preserv = $preserv ? $preserv : array(); |
157 | 173 | self::$request->method = $method; |
158 | 174 | self::$request->ignore_validation = $ignore_validation; |
159 | - if (self::$request->output_mode == -1) self::$request->output_mode = 0; |
|
175 | + if (self::$request->output_mode == -1) |
|
176 | + { |
|
177 | + self::$request->output_mode = 0; |
|
178 | + } |
|
160 | 179 | self::$request->template = $this->as_array(); |
161 | 180 | |
162 | - if (empty($this->name)) throw new Exception\AssertionFailed("Template name is not set '$this->name' !"); |
|
181 | + if (empty($this->name)) |
|
182 | + { |
|
183 | + throw new Exception\AssertionFailed("Template name is not set '$this->name' !"); |
|
184 | + } |
|
163 | 185 | // instanciate template to fill self::$request->sel_options for select-* widgets |
164 | 186 | // not sure if we want to handle it this way, thought otherwise we will have a few ajax request for each dialog fetching predefined selectboxes |
165 | 187 | $template = self::instance($this->name, $this->template_set, $this->version, $this->laod_via); |
166 | - if (!$template) throw new Exception\AssertionFailed("Template $this->name not instanciable! Maybe you forgot to rename template id."); |
|
188 | + if (!$template) |
|
189 | + { |
|
190 | + throw new Exception\AssertionFailed("Template $this->name not instanciable! Maybe you forgot to rename template id."); |
|
191 | + } |
|
167 | 192 | $this->children = array($template); |
168 | 193 | $template->run('beforeSendToClient', array('', array('cont'=>$content))); |
169 | 194 | |
@@ -208,10 +233,13 @@ discard block |
||
208 | 233 | 'data' => $data, |
209 | 234 | 'DOMNodeID' => $dom_id, |
210 | 235 | ); |
211 | - if (self::$response) // call is within an ajax event / form submit |
|
236 | + if (self::$response) |
|
237 | + { |
|
238 | + // call is within an ajax event / form submit |
|
212 | 239 | { |
213 | 240 | //error_log("Ajax " . __LINE__); |
214 | 241 | self::$response->generic('et2_load', $load_array+Framework::get_extra()); |
242 | + } |
|
215 | 243 | Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
216 | 244 | } |
217 | 245 | else // first call |
@@ -274,7 +302,10 @@ discard block |
||
274 | 302 | echo $GLOBALS['egw']->framework->footer(); |
275 | 303 | } |
276 | 304 | ob_flush(); |
277 | - if ($output_mode == 1) return $form; |
|
305 | + if ($output_mode == 1) |
|
306 | + { |
|
307 | + return $form; |
|
308 | + } |
|
278 | 309 | } |
279 | 310 | self::$request = null; |
280 | 311 | } |
@@ -289,7 +320,10 @@ discard block |
||
289 | 320 | { |
290 | 321 | foreach($sel_options as &$options) |
291 | 322 | { |
292 | - if (!is_array($options)||empty($options)) continue; |
|
323 | + if (!is_array($options)||empty($options)) |
|
324 | + { |
|
325 | + continue; |
|
326 | + } |
|
293 | 327 | foreach($options as $key => $value) |
294 | 328 | { |
295 | 329 | if (is_numeric($key) && (!is_array($value) || !isset($value['value']))) |
@@ -330,7 +364,10 @@ discard block |
||
330 | 364 | |
331 | 365 | // Set current app for validation |
332 | 366 | list($app) = explode('.',self::$request->method); |
333 | - if(!$app) list($app) = explode('::',self::$request->method); |
|
367 | + if(!$app) |
|
368 | + { |
|
369 | + list($app) = explode('::',self::$request->method); |
|
370 | + } |
|
334 | 371 | if($app) |
335 | 372 | { |
336 | 373 | Translation::add_app($app); |
@@ -361,7 +398,10 @@ discard block |
||
361 | 398 | 'location_name' => $template->id, |
362 | 399 | ) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras) |
363 | 400 | { |
364 | - if (!$extras) continue; |
|
401 | + if (!$extras) |
|
402 | + { |
|
403 | + continue; |
|
404 | + } |
|
365 | 405 | |
366 | 406 | foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
367 | 407 | { |
@@ -399,10 +439,15 @@ discard block |
||
399 | 439 | { |
400 | 440 | foreach($hook_data as $extras) |
401 | 441 | { |
402 | - if (!$extras) continue; |
|
442 | + if (!$extras) |
|
443 | + { |
|
444 | + continue; |
|
445 | + } |
|
403 | 446 | |
404 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
405 | - if ($extra['data'] && is_array($extra['data'])) { |
|
447 | + foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
|
448 | + { |
|
449 | + if ($extra['data'] && is_array($extra['data'])) |
|
450 | + { |
|
406 | 451 | $content = array_merge($content, $extra['data']); |
407 | 452 | } |
408 | 453 | } |
@@ -441,7 +486,10 @@ discard block |
||
441 | 486 | */ |
442 | 487 | static public function process_exec() |
443 | 488 | { |
444 | - if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']); |
|
489 | + if (get_magic_quotes_gpc()) |
|
490 | + { |
|
491 | + $_POST['value'] = stripslashes($_POST['value']); |
|
492 | + } |
|
445 | 493 | $content = json_decode($_POST['value'],true); |
446 | 494 | //error_log(__METHOD__."(".array2string($content).")"); |
447 | 495 | |
@@ -604,16 +652,22 @@ discard block |
||
604 | 652 | { |
605 | 653 | if (is_array($new)) |
606 | 654 | { |
607 | - if (!is_array($old)) $old = (array) $old; |
|
655 | + if (!is_array($old)) |
|
656 | + { |
|
657 | + $old = (array) $old; |
|
658 | + } |
|
608 | 659 | |
609 | 660 | foreach($new as $k => $v) |
610 | 661 | { |
611 | 662 | if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
612 | 663 | isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1]) || // or no associative array, eg. selecting multiple accounts |
613 | - is_array($v) && count($v) == 0) // Empty array replacing non-empty |
|
664 | + is_array($v) && count($v) == 0) |
|
665 | + { |
|
666 | + // Empty array replacing non-empty |
|
614 | 667 | { |
615 | 668 | $old[$k] = $v; |
616 | 669 | } |
670 | + } |
|
617 | 671 | else |
618 | 672 | { |
619 | 673 | $old[$k] = self::complete_array_merge($old[$k],$v); |
@@ -666,10 +720,16 @@ discard block |
||
666 | 720 | if (is_null($dec_separator)) |
667 | 721 | { |
668 | 722 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
669 | - if (empty($dec_separator)) $dec_separator = '.'; |
|
723 | + if (empty($dec_separator)) |
|
724 | + { |
|
725 | + $dec_separator = '.'; |
|
726 | + } |
|
670 | 727 | $thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1]; |
671 | 728 | } |
672 | - if ((string)$number === '') return ''; |
|
729 | + if ((string)$number === '') |
|
730 | + { |
|
731 | + return ''; |
|
732 | + } |
|
673 | 733 | |
674 | 734 | return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : ''); |
675 | 735 | } |