@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | * @param array|string $criteria array of key and data cols, OR string to search over all standard search fields |
| 593 | 593 | * @param boolean|string $only_keys =true True returns only keys, False returns all cols. comma seperated list of keys to return |
| 594 | 594 | * @param string $order_by ='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) |
| 595 | - * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
| 595 | + * @param string $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
| 596 | 596 | * @param string $wildcard ='' appended befor and after each criteria |
| 597 | 597 | * @param boolean $empty =false False=empty criteria are ignored in query, True=empty have to be empty in row |
| 598 | 598 | * @param string $op ='AND' defaults to 'AND', can be set to 'OR' too, then criteria's are OR'ed together |
@@ -814,8 +814,6 @@ discard block |
||
| 814 | 814 | * delete / move all contacts of an addressbook |
| 815 | 815 | * |
| 816 | 816 | * @param array $data |
| 817 | - * @param int $data['account_id'] owner to change |
|
| 818 | - * @param int $data['new_owner'] new owner or 0 for delete |
|
| 819 | 817 | */ |
| 820 | 818 | function deleteaccount($data) |
| 821 | 819 | { |
@@ -44,23 +44,23 @@ discard block |
||
| 44 | 44 | var $extra_table = 'egw_addressbook_extra'; |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * @var string |
|
| 48 | - */ |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | 49 | var $extra_id = 'contact_id'; |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * @var string |
|
| 53 | - */ |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | 54 | var $extra_owner = 'contact_owner'; |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * @var string |
|
| 58 | - */ |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | 59 | var $extra_key = 'contact_name'; |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * @var string |
|
| 63 | - */ |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | 64 | var $extra_value = 'contact_value'; |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -71,23 +71,23 @@ discard block |
||
| 71 | 71 | var $distributionlist_view ='(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
| 72 | 72 | var $distributionlist_tabledef = array(); |
| 73 | 73 | /** |
| 74 | - * @var string |
|
| 75 | - */ |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | 76 | var $distri_id = 'contact_id'; |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * @var string |
|
| 80 | - */ |
|
| 79 | + * @var string |
|
| 80 | + */ |
|
| 81 | 81 | var $distri_owner = 'list_owner'; |
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | - * @var string |
|
| 85 | - */ |
|
| 84 | + * @var string |
|
| 85 | + */ |
|
| 86 | 86 | var $distri_key = 'list_id'; |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * @var string |
|
| 90 | - */ |
|
| 89 | + * @var string |
|
| 90 | + */ |
|
| 91 | 91 | var $distri_value = 'list_name'; |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | var $content_types = array(); |
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | - * Special content type to indicate a deleted addressbook |
|
| 164 | - * |
|
| 165 | - * @var String; |
|
| 166 | - */ |
|
| 163 | + * Special content type to indicate a deleted addressbook |
|
| 164 | + * |
|
| 165 | + * @var String; |
|
| 166 | + */ |
|
| 167 | 167 | const DELETED_TYPE = 'D'; |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | $this->distributionlist_tabledef = array('fd' => array( |
| 269 | 269 | $this->distri_id => $tda2list['fd'][$this->distri_id], |
| 270 | 270 | $this->distri_owner => $tdlists['fd'][$this->distri_owner], |
| 271 | - $this->distri_key => $tdlists['fd'][$this->distri_key], |
|
| 271 | + $this->distri_key => $tdlists['fd'][$this->distri_key], |
|
| 272 | 272 | $this->distri_value => $tdlists['fd'][$this->distri_value], |
| 273 | 273 | ), 'pk' => array(), 'fk' => array(), 'ix' => array(), 'uc' => array(), |
| 274 | 274 | ); |
@@ -469,12 +469,12 @@ discard block |
||
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
| 472 | - * deletes contact entry including custom fields |
|
| 473 | - * |
|
| 474 | - * @param mixed $contact array with id or just the id |
|
| 475 | - * @param int $check_etag =null |
|
| 476 | - * @return boolean|int true on success or false on failiure, 0 if etag does not match |
|
| 477 | - */ |
|
| 472 | + * deletes contact entry including custom fields |
|
| 473 | + * |
|
| 474 | + * @param mixed $contact array with id or just the id |
|
| 475 | + * @param int $check_etag =null |
|
| 476 | + * @return boolean|int true on success or false on failiure, 0 if etag does not match |
|
| 477 | + */ |
|
| 478 | 478 | function delete($contact,$check_etag=null) |
| 479 | 479 | { |
| 480 | 480 | if (is_array($contact)) $contact = $contact['id']; |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
| 513 | - * saves contact data including custom fields |
|
| 514 | - * |
|
| 515 | - * @param array &$contact contact data from etemplate::exec |
|
| 516 | - * @return bool false on success, errornumber on failure |
|
| 517 | - */ |
|
| 513 | + * saves contact data including custom fields |
|
| 514 | + * |
|
| 515 | + * @param array &$contact contact data from etemplate::exec |
|
| 516 | + * @return bool false on success, errornumber on failure |
|
| 517 | + */ |
|
| 518 | 518 | function save(&$contact) |
| 519 | 519 | { |
| 520 | 520 | // save mainfields |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | * |
| 567 | 567 | * @param int|string $contact_id contact_id or 'a'.account_id |
| 568 | 568 | * @return array|boolean data if row could be retrived else False |
| 569 | - */ |
|
| 569 | + */ |
|
| 570 | 570 | function read($contact_id) |
| 571 | 571 | { |
| 572 | 572 | if (!is_array($contact_id) && substr($contact_id,0,8) == 'account:') |
@@ -796,10 +796,10 @@ discard block |
||
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
| 799 | - * gets all contact fields from database |
|
| 800 | - * |
|
| 801 | - * @return array of (internal) field-names |
|
| 802 | - */ |
|
| 799 | + * gets all contact fields from database |
|
| 800 | + * |
|
| 801 | + * @return array of (internal) field-names |
|
| 802 | + */ |
|
| 803 | 803 | function get_contact_columns() |
| 804 | 804 | { |
| 805 | 805 | $fields = $this->get_fields('all'); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @var string |
| 70 | 70 | */ |
| 71 | - var $distributionlist_view ='(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
|
| 71 | + var $distributionlist_view = '(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
|
| 72 | 72 | var $distributionlist_tabledef = array(); |
| 73 | 73 | /** |
| 74 | 74 | * @var string |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | * In SQL we can search all columns, though a view make on real sense |
| 123 | 123 | */ |
| 124 | 124 | var $sql_cols_not_to_search = array( |
| 125 | - 'jpegphoto','owner','tid','private','cat_id','etag', |
|
| 126 | - 'modified','modifier','creator','created','tz','account_id', |
|
| 127 | - 'uid','carddav_name','freebusy_uri','calendar_uri', |
|
| 128 | - 'geo','pubkey', |
|
| 125 | + 'jpegphoto', 'owner', 'tid', 'private', 'cat_id', 'etag', |
|
| 126 | + 'modified', 'modifier', 'creator', 'created', 'tz', 'account_id', |
|
| 127 | + 'uid', 'carddav_name', 'freebusy_uri', 'calendar_uri', |
|
| 128 | + 'geo', 'pubkey', |
|
| 129 | 129 | ); |
| 130 | 130 | /** |
| 131 | 131 | * columns to search, if we search for a single pattern |
@@ -205,12 +205,12 @@ discard block |
||
| 205 | 205 | * @param string $contact_app ='addressbook' used for acl->get_grants() |
| 206 | 206 | * @param Api\Db $db =null |
| 207 | 207 | */ |
| 208 | - function __construct($contact_app='addressbook',Api\Db $db=null) |
|
| 208 | + function __construct($contact_app = 'addressbook', Api\Db $db = null) |
|
| 209 | 209 | { |
| 210 | - $this->db = is_null($db) ? $GLOBALS['egw']->db : $db; |
|
| 210 | + $this->db = is_null($db) ? $GLOBALS['egw']->db : $db; |
|
| 211 | 211 | |
| 212 | 212 | $this->user = $GLOBALS['egw_info']['user']['account_id']; |
| 213 | - $this->memberships = $GLOBALS['egw']->accounts->memberships($this->user,true); |
|
| 213 | + $this->memberships = $GLOBALS['egw']->accounts->memberships($this->user, true); |
|
| 214 | 214 | |
| 215 | 215 | // account backend used |
| 216 | 216 | if ($GLOBALS['egw_info']['server']['account_repository']) |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | $this->customfields = Api\Storage\Customfields::get('addressbook'); |
| 225 | 225 | // contacts backend (contacts in LDAP require accounts in LDAP!) |
| 226 | - if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
| 226 | + if ($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
| 227 | 227 | { |
| 228 | 228 | $this->contact_repository = 'ldap'; |
| 229 | 229 | $this->somain = new Ldap(); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $this->somain = new Sql($db); |
| 239 | 239 | |
| 240 | 240 | // remove some columns, absolutly not necessary to search in sql |
| 241 | - $this->columns_to_search = array_diff(array_values($this->somain->db_cols),$this->sql_cols_not_to_search); |
|
| 241 | + $this->columns_to_search = array_diff(array_values($this->somain->db_cols), $this->sql_cols_not_to_search); |
|
| 242 | 242 | if ($this->customfields) // add custom fields, if configured |
| 243 | 243 | { |
| 244 | 244 | $this->columns_to_search[] = Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE; |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | if ($this->user) |
| 248 | 248 | { |
| 249 | - $this->grants = $this->get_grants($this->user,$contact_app); |
|
| 249 | + $this->grants = $this->get_grants($this->user, $contact_app); |
|
| 250 | 250 | } |
| 251 | 251 | if ($this->account_repository != 'sql' && $this->contact_repository == 'sql') |
| 252 | 252 | { |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | if ($this->contact_repository == 'sql' || $this->contact_repository == 'sql-ldap') |
| 265 | 265 | { |
| 266 | - $tda2list = $this->db->get_table_definitions('api','egw_addressbook2list'); |
|
| 267 | - $tdlists = $this->db->get_table_definitions('api','egw_addressbook_lists'); |
|
| 266 | + $tda2list = $this->db->get_table_definitions('api', 'egw_addressbook2list'); |
|
| 267 | + $tdlists = $this->db->get_table_definitions('api', 'egw_addressbook_lists'); |
|
| 268 | 268 | $this->distributionlist_tabledef = array('fd' => array( |
| 269 | 269 | $this->distri_id => $tda2list['fd'][$this->distri_id], |
| 270 | 270 | $this->distri_owner => $tdlists['fd'][$this->distri_owner], |
@@ -274,11 +274,11 @@ discard block |
||
| 274 | 274 | ); |
| 275 | 275 | } |
| 276 | 276 | // ToDo: it should be the other way arround, the backend should set the grants it uses |
| 277 | - $this->somain->grants =& $this->grants; |
|
| 277 | + $this->somain->grants = & $this->grants; |
|
| 278 | 278 | |
| 279 | - if($this->somain instanceof Sql) |
|
| 279 | + if ($this->somain instanceof Sql) |
|
| 280 | 280 | { |
| 281 | - $this->soextra =& $this->somain; |
|
| 281 | + $this->soextra = & $this->somain; |
|
| 282 | 282 | } |
| 283 | 283 | else |
| 284 | 284 | { |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | |
| 299 | 299 | // Add in deleted type, if holding deleted contacts |
| 300 | 300 | $config = Api\Config::read('phpgwapi'); |
| 301 | - if($config['history']) |
|
| 301 | + if ($config['history']) |
|
| 302 | 302 | { |
| 303 | 303 | $this->content_types[self::DELETED_TYPE] = array( |
| 304 | 304 | 'name' => lang('Deleted'), |
@@ -317,18 +317,18 @@ discard block |
||
| 317 | 317 | * @param string $contact_app ='addressbook' |
| 318 | 318 | * @return array |
| 319 | 319 | */ |
| 320 | - function get_grants($user, $contact_app='addressbook', $preferences=null) |
|
| 320 | + function get_grants($user, $contact_app = 'addressbook', $preferences = null) |
|
| 321 | 321 | { |
| 322 | 322 | if (!isset($preferences)) $preferences = $GLOBALS['egw_info']['user']['preferences']; |
| 323 | 323 | |
| 324 | 324 | if ($user) |
| 325 | 325 | { |
| 326 | 326 | // contacts backend (contacts in LDAP require accounts in LDAP!) |
| 327 | - if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
| 327 | + if ($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
| 328 | 328 | { |
| 329 | 329 | // static grants from ldap: all rights for the own personal addressbook and the group ones of the meberships |
| 330 | 330 | $grants = array($user => ~0); |
| 331 | - foreach($GLOBALS['egw']->accounts->memberships($user,true) as $gid) |
|
| 331 | + foreach ($GLOBALS['egw']->accounts->memberships($user, true) as $gid) |
|
| 332 | 332 | { |
| 333 | 333 | $grants[$gid] = ~0; |
| 334 | 334 | } |
@@ -337,22 +337,22 @@ discard block |
||
| 337 | 337 | { |
| 338 | 338 | // group grants are now grants for the group addressbook and NOT grants for all its members, |
| 339 | 339 | // therefor the param false! |
| 340 | - $grants = $GLOBALS['egw']->acl->get_grants($contact_app,false,$user); |
|
| 340 | + $grants = $GLOBALS['egw']->acl->get_grants($contact_app, false, $user); |
|
| 341 | 341 | } |
| 342 | 342 | // add grants for accounts: if account_selection not in ('none','groupmembers'): everyone has read access, |
| 343 | 343 | // if he has not set the hide_accounts preference |
| 344 | 344 | // ToDo: be more specific for 'groupmembers', they should be able to see the groupmembers |
| 345 | - if (!in_array($preferences['common']['account_selection'], array('none','groupmembers'))) |
|
| 345 | + if (!in_array($preferences['common']['account_selection'], array('none', 'groupmembers'))) |
|
| 346 | 346 | { |
| 347 | 347 | $grants[0] = Api\Acl::READ; |
| 348 | 348 | } |
| 349 | 349 | // add account grants for admins (only for current user!) |
| 350 | 350 | if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL! |
| 351 | 351 | { |
| 352 | - $grants[0] = Api\Acl::READ; // admins always have read-access |
|
| 353 | - if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= Api\Acl::EDIT; |
|
| 354 | - if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) $grants[0] |= Api\Acl::ADD; |
|
| 355 | - if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) $grants[0] |= Api\Acl::DELETE; |
|
| 352 | + $grants[0] = Api\Acl::READ; // admins always have read-access |
|
| 353 | + if (!$GLOBALS['egw']->acl->check('account_access', 16, 'admin')) $grants[0] |= Api\Acl::EDIT; |
|
| 354 | + if (!$GLOBALS['egw']->acl->check('account_access', 4, 'admin')) $grants[0] |= Api\Acl::ADD; |
|
| 355 | + if (!$GLOBALS['egw']->acl->check('account_access', 32, 'admin')) $grants[0] |= Api\Acl::DELETE; |
|
| 356 | 356 | } |
| 357 | 357 | // allow certain groups to edit contact-data of accounts |
| 358 | 358 | if (self::allow_account_edit($user)) |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @param array $contact =null for future use, where admins might not be admins for all accounts |
| 377 | 377 | * @return boolean |
| 378 | 378 | */ |
| 379 | - function is_admin($contact=null) |
|
| 379 | + function is_admin($contact = null) |
|
| 380 | 380 | { |
| 381 | - unset($contact); // not (yet) used |
|
| 381 | + unset($contact); // not (yet) used |
|
| 382 | 382 | |
| 383 | - return isset($GLOBALS['egw_info']['user']['apps']['admin']) && !$GLOBALS['egw']->acl->check('account_access',16,'admin'); |
|
| 383 | + return isset($GLOBALS['egw_info']['user']['apps']['admin']) && !$GLOBALS['egw']->acl->check('account_access', 16, 'admin'); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * @param int $user =null default $this->user |
| 390 | 390 | * @return boolean |
| 391 | 391 | */ |
| 392 | - function allow_account_edit($user=null) |
|
| 392 | + function allow_account_edit($user = null) |
|
| 393 | 393 | { |
| 394 | 394 | return $GLOBALS['egw_info']['server']['allow_account_edit'] && |
| 395 | 395 | array_intersect($GLOBALS['egw_info']['server']['allow_account_edit'], |
@@ -403,9 +403,9 @@ discard block |
||
| 403 | 403 | * @param array $field_names =null custom fields to read, default all |
| 404 | 404 | * @return array id => name => value |
| 405 | 405 | */ |
| 406 | - function read_customfields($ids,$field_names=null) |
|
| 406 | + function read_customfields($ids, $field_names = null) |
|
| 407 | 407 | { |
| 408 | - return $this->soextra->read_customfields($ids,$field_names); |
|
| 408 | + return $this->soextra->read_customfields($ids, $field_names); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -414,26 +414,26 @@ discard block |
||
| 414 | 414 | * @param int|array $ids |
| 415 | 415 | * @return array id => name => value |
| 416 | 416 | */ |
| 417 | - function read_distributionlist($ids, $dl_allowed=array()) |
|
| 417 | + function read_distributionlist($ids, $dl_allowed = array()) |
|
| 418 | 418 | { |
| 419 | 419 | if ($this->contact_repository == 'ldap') |
| 420 | 420 | { |
| 421 | - return array(); // ldap does not support distributionlists |
|
| 421 | + return array(); // ldap does not support distributionlists |
|
| 422 | 422 | } |
| 423 | - foreach($ids as $key => $id) |
|
| 423 | + foreach ($ids as $key => $id) |
|
| 424 | 424 | { |
| 425 | 425 | if (!is_numeric($id)) unset($ids[$key]); |
| 426 | 426 | } |
| 427 | - if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
| 427 | + if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
| 428 | 428 | $fields = array(); |
| 429 | - $filter[$this->distri_id]=$ids; |
|
| 430 | - if (count($dl_allowed)) $filter[$this->distri_key]=$dl_allowed; |
|
| 431 | - $distri_view = str_replace(') d_view',' and '.$this->distri_id.' in ('.implode(',',$ids).')) d_view',$this->distributionlist_view); |
|
| 429 | + $filter[$this->distri_id] = $ids; |
|
| 430 | + if (count($dl_allowed)) $filter[$this->distri_key] = $dl_allowed; |
|
| 431 | + $distri_view = str_replace(') d_view', ' and '.$this->distri_id.' in ('.implode(',', $ids).')) d_view', $this->distributionlist_view); |
|
| 432 | 432 | #_debug_array($this->distributionlist_tabledef); |
| 433 | - foreach($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
|
| 433 | + foreach ($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
|
| 434 | 434 | false, 'ORDER BY '.$this->distri_id, false, 0, '', $this->distributionlist_tabledef) as $row) |
| 435 | 435 | { |
| 436 | - if ((isset($row[$this->distri_id])&&strlen($row[$this->distri_value])>0)) |
|
| 436 | + if ((isset($row[$this->distri_id]) && strlen($row[$this->distri_value]) > 0)) |
|
| 437 | 437 | { |
| 438 | 438 | $fields[$row[$this->distri_id]][$row[$this->distri_key]] = $row[$this->distri_value].' ('. |
| 439 | 439 | Api\Accounts::username($row[$this->distri_owner]).')'; |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | * @param int $check_etag =null |
| 476 | 476 | * @return boolean|int true on success or false on failiure, 0 if etag does not match |
| 477 | 477 | */ |
| 478 | - function delete($contact,$check_etag=null) |
|
| 478 | + function delete($contact, $check_etag = null) |
|
| 479 | 479 | { |
| 480 | 480 | if (is_array($contact)) $contact = $contact['id']; |
| 481 | 481 | |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | if ($this->somain->delete($where)) |
| 487 | 487 | { |
| 488 | 488 | // delete customfields, can return 0 if there are no customfields |
| 489 | - if(!($this->somain instanceof Sql)) |
|
| 489 | + if (!($this->somain instanceof Sql)) |
|
| 490 | 490 | { |
| 491 | 491 | $this->soextra->delete_customfields(array($this->extra_id => $contact)); |
| 492 | 492 | } |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | } |
| 507 | 507 | return true; |
| 508 | 508 | } |
| 509 | - return $check_etag ? 0 : false; // if etag given, we return 0 on failure, thought it could also mean the whole contact does not exist |
|
| 509 | + return $check_etag ? 0 : false; // if etag given, we return 0 on failure, thought it could also mean the whole contact does not exist |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -556,9 +556,9 @@ discard block |
||
| 556 | 556 | } |
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | - if($error_nr) return $error_nr; |
|
| 559 | + if ($error_nr) return $error_nr; |
|
| 560 | 560 | |
| 561 | - return false; // no error |
|
| 561 | + return false; // no error |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -569,18 +569,18 @@ discard block |
||
| 569 | 569 | */ |
| 570 | 570 | function read($contact_id) |
| 571 | 571 | { |
| 572 | - if (!is_array($contact_id) && substr($contact_id,0,8) == 'account:') |
|
| 572 | + if (!is_array($contact_id) && substr($contact_id, 0, 8) == 'account:') |
|
| 573 | 573 | { |
| 574 | - $contact_id = array('account_id' => (int) substr($contact_id,8)); |
|
| 574 | + $contact_id = array('account_id' => (int)substr($contact_id, 8)); |
|
| 575 | 575 | } |
| 576 | 576 | // read main data |
| 577 | - $backend =& $this->get_backend($contact_id); |
|
| 577 | + $backend = & $this->get_backend($contact_id); |
|
| 578 | 578 | if (!($contact = $backend->read($contact_id))) |
| 579 | 579 | { |
| 580 | 580 | return $contact; |
| 581 | 581 | } |
| 582 | - $dl_list=$this->read_distributionlist(array($contact['id'])); |
|
| 583 | - if (count($dl_list)) $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
| 582 | + $dl_list = $this->read_distributionlist(array($contact['id'])); |
|
| 583 | + if (count($dl_list)) $contact['distrib_lists'] = implode("\n", $dl_list[$contact['id']]); |
|
| 584 | 584 | return $this->db2data($contact); |
| 585 | 585 | } |
| 586 | 586 | |
@@ -602,18 +602,18 @@ discard block |
||
| 602 | 602 | * @param string $join ='' sql to do a join (only used by sql backend!), eg. " RIGHT JOIN egw_accounts USING(account_id)" |
| 603 | 603 | * @return array of matching rows (the row is an array of the cols) or False |
| 604 | 604 | */ |
| 605 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='') |
|
| 605 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '') |
|
| 606 | 606 | { |
| 607 | 607 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',".array2string($start).','.array2string($filter,true).",'$join')"); |
| 608 | 608 | |
| 609 | 609 | // Handle 'None' country option |
| 610 | - if(is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
| 610 | + if (is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
| 611 | 611 | { |
| 612 | 612 | $filter[] = 'adr_one_countrycode IS NULL'; |
| 613 | 613 | unset($filter['adr_one_countrycode']); |
| 614 | 614 | } |
| 615 | 615 | // Hide deleted items unless type is specifically deleted |
| 616 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
| 616 | + if (!is_array($filter)) $filter = $filter ? (array)$filter : array(); |
|
| 617 | 617 | |
| 618 | 618 | if (isset($filter['cols_to_search'])) |
| 619 | 619 | { |
@@ -622,22 +622,22 @@ discard block |
||
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
| 625 | - if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
| 625 | + if (!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
| 626 | 626 | { |
| 627 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
| 627 | + if ($join && strpos($join, 'RIGHT JOIN') !== false) // used eg. to search for groups |
|
| 628 | 628 | { |
| 629 | - $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
|
| 629 | + $filter[] = '(contact_tid != \''.self::DELETED_TYPE.'\' OR contact_tid IS NULL)'; |
|
| 630 | 630 | } |
| 631 | 631 | else |
| 632 | 632 | { |
| 633 | - $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
| 633 | + $filter[] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
| 634 | 634 | } |
| 635 | 635 | } |
| 636 | - elseif(is_null($filter['tid'])) |
|
| 636 | + elseif (is_null($filter['tid'])) |
|
| 637 | 637 | { |
| 638 | - unset($filter['tid']); // return all entries incl. deleted |
|
| 638 | + unset($filter['tid']); // return all entries incl. deleted |
|
| 639 | 639 | } |
| 640 | - $backend = $this->get_backend(null,$filter['owner']); |
|
| 640 | + $backend = $this->get_backend(null, $filter['owner']); |
|
| 641 | 641 | // single string to search for --> create so_sql conformant search criterial for the standard search columns |
| 642 | 642 | if ($criteria && !is_array($criteria)) |
| 643 | 643 | { |
@@ -658,34 +658,34 @@ discard block |
||
| 658 | 658 | { |
| 659 | 659 | $cols = $this->account_cols_to_search; |
| 660 | 660 | } |
| 661 | - if($backend instanceof Sql) |
|
| 661 | + if ($backend instanceof Sql) |
|
| 662 | 662 | { |
| 663 | 663 | // Keep a string, let the parent handle it |
| 664 | 664 | $criteria = $search; |
| 665 | 665 | |
| 666 | - foreach($cols as $key => &$col) |
|
| 666 | + foreach ($cols as $key => &$col) |
|
| 667 | 667 | { |
| 668 | - if($col != Sql::EXTRA_VALUE && |
|
| 668 | + if ($col != Sql::EXTRA_VALUE && |
|
| 669 | 669 | $col != Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE && |
| 670 | 670 | !array_key_exists($col, $backend->db_cols)) |
| 671 | 671 | { |
| 672 | - if(!($col = array_search($col, $backend->db_cols))) |
|
| 672 | + if (!($col = array_search($col, $backend->db_cols))) |
|
| 673 | 673 | { |
| 674 | 674 | // Can't search this column, it will error if we try |
| 675 | 675 | unset($cols[$key]); |
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
| 678 | + if ($col == 'contact_id') $col = 'egw_addressbook.contact_id'; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | $backend->columns_to_search = $cols; |
| 682 | 682 | } |
| 683 | 683 | else |
| 684 | 684 | { |
| 685 | - foreach($cols as $col) |
|
| 685 | + foreach ($cols as $col) |
|
| 686 | 686 | { |
| 687 | 687 | // remove from LDAP backend not understood use-AND-syntax |
| 688 | - $criteria[$col] = str_replace(' +',' ',$search); |
|
| 688 | + $criteria[$col] = str_replace(' +', ' ', $search); |
|
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | 691 | } |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | |
| 710 | 710 | if ($rows) |
| 711 | 711 | { |
| 712 | - foreach($rows as $n => $row) |
|
| 712 | + foreach ($rows as $n => $row) |
|
| 713 | 713 | { |
| 714 | 714 | $rows[$n] = $this->db2data($row); |
| 715 | 715 | } |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | */ |
| 733 | 733 | function organisations($param) |
| 734 | 734 | { |
| 735 | - if (!method_exists($this->somain,'organisations')) |
|
| 735 | + if (!method_exists($this->somain, 'organisations')) |
|
| 736 | 736 | { |
| 737 | 737 | $this->total = 0; |
| 738 | 738 | return false; |
@@ -741,16 +741,16 @@ discard block |
||
| 741 | 741 | { |
| 742 | 742 | $search = $param['search']; |
| 743 | 743 | $param['search'] = array(); |
| 744 | - if($this->somain instanceof Sql) |
|
| 744 | + if ($this->somain instanceof Sql) |
|
| 745 | 745 | { |
| 746 | 746 | // Keep the string, let the parent deal with it |
| 747 | 747 | $param['search'] = $search; |
| 748 | 748 | } |
| 749 | 749 | else |
| 750 | 750 | { |
| 751 | - foreach($this->columns_to_search as $col) |
|
| 751 | + foreach ($this->columns_to_search as $col) |
|
| 752 | 752 | { |
| 753 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
| 753 | + if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
| 754 | 754 | } |
| 755 | 755 | } |
| 756 | 756 | } |
@@ -758,13 +758,13 @@ discard block |
||
| 758 | 758 | { |
| 759 | 759 | $param['search'] = $this->data2db($param['search']); |
| 760 | 760 | } |
| 761 | - if(!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
| 761 | + if (!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
| 762 | 762 | { |
| 763 | - $param['col_filter'][] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
| 763 | + $param['col_filter'][] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
| 764 | 764 | } |
| 765 | - elseif(is_null($param['col_filter']['tid'])) |
|
| 765 | + elseif (is_null($param['col_filter']['tid'])) |
|
| 766 | 766 | { |
| 767 | - unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
| 767 | + unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | $rows = $this->somain->organisations($param); |
@@ -772,11 +772,11 @@ discard block |
||
| 772 | 772 | |
| 773 | 773 | if (!$rows) return array(); |
| 774 | 774 | |
| 775 | - foreach($rows as $n => $row) |
|
| 775 | + foreach ($rows as $n => $row) |
|
| 776 | 776 | { |
| 777 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
| 777 | + if (strpos($row['org_name'], '&') !== false) $row['org_name'] = str_replace('&', '*AND*', $row['org_name']); |
|
| 778 | 778 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
| 779 | - foreach(array( |
|
| 779 | + foreach (array( |
|
| 780 | 780 | 'org_unit' => lang('departments'), |
| 781 | 781 | 'adr_one_locality' => lang('locations'), |
| 782 | 782 | ) as $by => $by_label) |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | } |
| 788 | 788 | else |
| 789 | 789 | { |
| 790 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
| 790 | + if (strpos($row[$by], '&') !== false) $row[$by] = str_replace('&', '*AND*', $row[$by]); |
|
| 791 | 791 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
| 792 | 792 | } |
| 793 | 793 | } |
@@ -820,11 +820,11 @@ discard block |
||
| 820 | 820 | function deleteaccount($data) |
| 821 | 821 | { |
| 822 | 822 | $account_id = $data['account_id']; |
| 823 | - $new_owner = $data['new_owner']; |
|
| 823 | + $new_owner = $data['new_owner']; |
|
| 824 | 824 | |
| 825 | 825 | if (!$new_owner) |
| 826 | 826 | { |
| 827 | - $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
| 827 | + $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
| 828 | 828 | |
| 829 | 829 | if (method_exists($this->somain, 'get_lists') && |
| 830 | 830 | ($lists = $this->somain->get_lists($account_id))) |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | else |
| 836 | 836 | { |
| 837 | - $this->somain->change_owner($account_id,$new_owner); |
|
| 837 | + $this->somain->change_owner($account_id, $new_owner); |
|
| 838 | 838 | } |
| 839 | 839 | } |
| 840 | 840 | |
@@ -845,16 +845,15 @@ discard block |
||
| 845 | 845 | * @param int $owner =null account_id of owner or 0 for accounts |
| 846 | 846 | * @return Sql |
| 847 | 847 | */ |
| 848 | - function get_backend($keys=null,$owner=null) |
|
| 848 | + function get_backend($keys = null, $owner = null) |
|
| 849 | 849 | { |
| 850 | 850 | if ($owner === '') $owner = null; |
| 851 | 851 | |
| 852 | - $contact_id = !is_array($keys) ? $keys : |
|
| 853 | - (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
| 852 | + $contact_id = !is_array($keys) ? $keys : (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
| 854 | 853 | |
| 855 | 854 | if ($this->contact_repository != $this->account_repository && is_object($this->so_accounts) && |
| 856 | 855 | (!is_null($owner) && !$owner || is_array($keys) && $keys['account_id'] || !is_null($contact_id) && |
| 857 | - ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id) )|| |
|
| 856 | + ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id)) || |
|
| 858 | 857 | $this->contact_repository == 'ldap' && is_numeric($contact_id)))) |
| 859 | 858 | { |
| 860 | 859 | return $this->so_accounts; |
@@ -870,28 +869,28 @@ discard block |
||
| 870 | 869 | * @param int $owner =null account_id of owner or 0 for accounts |
| 871 | 870 | * @return array with eGW contact field names |
| 872 | 871 | */ |
| 873 | - function get_fields($type='all',$contact_id=null,$owner=null) |
|
| 872 | + function get_fields($type = 'all', $contact_id = null, $owner = null) |
|
| 874 | 873 | { |
| 875 | - $def = $this->db->get_table_definitions('api','egw_addressbook'); |
|
| 874 | + $def = $this->db->get_table_definitions('api', 'egw_addressbook'); |
|
| 876 | 875 | |
| 877 | 876 | $all_fields = array(); |
| 878 | - foreach(array_keys($def['fd']) as $field) |
|
| 877 | + foreach (array_keys($def['fd']) as $field) |
|
| 879 | 878 | { |
| 880 | - $all_fields[] = substr($field,0,8) == 'contact_' ? substr($field,8) : $field; |
|
| 879 | + $all_fields[] = substr($field, 0, 8) == 'contact_' ? substr($field, 8) : $field; |
|
| 881 | 880 | } |
| 882 | 881 | if ($type == 'all') |
| 883 | 882 | { |
| 884 | 883 | return $all_fields; |
| 885 | 884 | } |
| 886 | - $backend =& $this->get_backend($contact_id,$owner); |
|
| 885 | + $backend = & $this->get_backend($contact_id, $owner); |
|
| 887 | 886 | |
| 888 | - $supported_fields = method_exists($backend,supported_fields) ? $backend->supported_fields() : $all_fields; |
|
| 887 | + $supported_fields = method_exists($backend, supported_fields) ? $backend->supported_fields() : $all_fields; |
|
| 889 | 888 | |
| 890 | 889 | if ($type == 'supported') |
| 891 | 890 | { |
| 892 | 891 | return $supported_fields; |
| 893 | 892 | } |
| 894 | - return array_diff($all_fields,$supported_fields); |
|
| 893 | + return array_diff($all_fields, $supported_fields); |
|
| 895 | 894 | } |
| 896 | 895 | |
| 897 | 896 | /** |
@@ -919,13 +918,12 @@ discard block |
||
| 919 | 918 | // direction SQL --> LDAP, either only accounts, or only contacts or both |
| 920 | 919 | if (($do = array_intersect($type, array('contacts', 'accounts')))) |
| 921 | 920 | { |
| 922 | - $filter = count($do) == 2 ? null : |
|
| 923 | - array($do[0] == 'contacts' ? 'contact_owner != 0' : 'contact_owner = 0'); |
|
| 921 | + $filter = count($do) == 2 ? null : array($do[0] == 'contacts' ? 'contact_owner != 0' : 'contact_owner = 0'); |
|
| 924 | 922 | |
| 925 | - while (($contacts = $sql_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
| 926 | - array($start,$num),$filter))) |
|
| 923 | + while (($contacts = $sql_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
| 924 | + array($start, $num), $filter))) |
|
| 927 | 925 | { |
| 928 | - foreach($contacts as $contact) |
|
| 926 | + foreach ($contacts as $contact) |
|
| 929 | 927 | { |
| 930 | 928 | if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
| 931 | 929 | |
@@ -946,12 +944,12 @@ discard block |
||
| 946 | 944 | } |
| 947 | 945 | } |
| 948 | 946 | // direction LDAP --> SQL: either "sql" (contacts and accounts) or "accounts-back" (only accounts) |
| 949 | - if (($do = array_intersect(array('accounts-back','sql'), $type))) |
|
| 947 | + if (($do = array_intersect(array('accounts-back', 'sql'), $type))) |
|
| 950 | 948 | { |
| 951 | 949 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)); |
| 952 | 950 | $filter = in_array('sql', $do) ? null : array('owner' => 0); |
| 953 | 951 | |
| 954 | - foreach($ldap_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
| 952 | + foreach ($ldap_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
| 955 | 953 | false, $filter) as $contact) |
| 956 | 954 | { |
| 957 | 955 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
@@ -959,7 +957,7 @@ discard block |
||
| 959 | 957 | { |
| 960 | 958 | $contact = $ldap_contacts->read($contact['id']); |
| 961 | 959 | } |
| 962 | - unset($contact['id']); // ldap uid/account_lid |
|
| 960 | + unset($contact['id']); // ldap uid/account_lid |
|
| 963 | 961 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
| 964 | 962 | { |
| 965 | 963 | $contact['id'] = $old['id']; |
@@ -971,7 +969,7 @@ discard block |
||
| 971 | 969 | { |
| 972 | 970 | echo '<p style="margin: 0px;">'.$n.': '.$contact['n_fn']. |
| 973 | 971 | ($contact['org_name'] ? ' ('.$contact['org_name'].')' : '')." --> SQL (". |
| 974 | - ($contact['owner']?lang('User'):lang('Contact')).")</p>\n"; |
|
| 972 | + ($contact['owner'] ? lang('User') : lang('Contact')).")</p>\n"; |
|
| 975 | 973 | } |
| 976 | 974 | else |
| 977 | 975 | { |
@@ -990,21 +988,21 @@ discard block |
||
| 990 | 988 | * @param string $extra_labels =null first labels if given (already translated) |
| 991 | 989 | * @return array with id => label pairs or false if backend does not support lists |
| 992 | 990 | */ |
| 993 | - function get_lists($required=Api\Acl::READ,$extra_labels=null) |
|
| 991 | + function get_lists($required = Api\Acl::READ, $extra_labels = null) |
|
| 994 | 992 | { |
| 995 | - if (!method_exists($this->somain,'get_lists')) return false; |
|
| 993 | + if (!method_exists($this->somain, 'get_lists')) return false; |
|
| 996 | 994 | |
| 997 | 995 | $uids = array(); |
| 998 | - foreach($this->grants as $uid => $rights) |
|
| 996 | + foreach ($this->grants as $uid => $rights) |
|
| 999 | 997 | { |
| 1000 | - if (($rights & $required) == $required) |
|
| 998 | + if (($rights&$required) == $required) |
|
| 1001 | 999 | { |
| 1002 | 1000 | $uids[] = $uid; |
| 1003 | 1001 | } |
| 1004 | 1002 | } |
| 1005 | 1003 | $lists = is_array($extra_labels) ? $extra_labels : array(); |
| 1006 | 1004 | |
| 1007 | - foreach($this->somain->get_lists($uids) as $list_id => $data) |
|
| 1005 | + foreach ($this->somain->get_lists($uids) as $list_id => $data) |
|
| 1008 | 1006 | { |
| 1009 | 1007 | $lists[$list_id] = $data['list_name']; |
| 1010 | 1008 | if ($data['list_owner'] != $this->user) |
@@ -1023,12 +1021,12 @@ discard block |
||
| 1023 | 1021 | * @param boolean $limit_in_ab =false if true only return members from the same owners addressbook |
| 1024 | 1022 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
| 1025 | 1023 | */ |
| 1026 | - function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
|
| 1024 | + function read_lists($keys, $member_attr = null, $limit_in_ab = false) |
|
| 1027 | 1025 | { |
| 1028 | 1026 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
| 1029 | 1027 | if (!method_exists($backend, 'get_lists')) return false; |
| 1030 | 1028 | |
| 1031 | - return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
|
| 1029 | + return $backend->get_lists($keys, null, $member_attr, $limit_in_ab); |
|
| 1032 | 1030 | } |
| 1033 | 1031 | |
| 1034 | 1032 | /** |
@@ -1040,12 +1038,12 @@ discard block |
||
| 1040 | 1038 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
| 1041 | 1039 | * @return int|boolean integer list_id or false on error |
| 1042 | 1040 | */ |
| 1043 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
| 1041 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
| 1044 | 1042 | { |
| 1045 | 1043 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
| 1046 | 1044 | if (!method_exists($backend, 'add_list')) return false; |
| 1047 | 1045 | |
| 1048 | - return $backend->add_list($keys,$owner,$contacts,$data); |
|
| 1046 | + return $backend->add_list($keys, $owner, $contacts, $data); |
|
| 1049 | 1047 | } |
| 1050 | 1048 | |
| 1051 | 1049 | /** |
@@ -1056,11 +1054,11 @@ discard block |
||
| 1056 | 1054 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
| 1057 | 1055 | * @return false on error |
| 1058 | 1056 | */ |
| 1059 | - function add2list($contact,$list,array $existing=null) |
|
| 1057 | + function add2list($contact, $list, array $existing = null) |
|
| 1060 | 1058 | { |
| 1061 | - if (!method_exists($this->somain,'add2list')) return false; |
|
| 1059 | + if (!method_exists($this->somain, 'add2list')) return false; |
|
| 1062 | 1060 | |
| 1063 | - return $this->somain->add2list($contact,$list,$existing); |
|
| 1061 | + return $this->somain->add2list($contact, $list, $existing); |
|
| 1064 | 1062 | } |
| 1065 | 1063 | |
| 1066 | 1064 | /** |
@@ -1070,11 +1068,11 @@ discard block |
||
| 1070 | 1068 | * @param int $list =null list-id or null to remove from all lists |
| 1071 | 1069 | * @return false on error |
| 1072 | 1070 | */ |
| 1073 | - function remove_from_list($contact,$list=null) |
|
| 1071 | + function remove_from_list($contact, $list = null) |
|
| 1074 | 1072 | { |
| 1075 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
| 1073 | + if (!method_exists($this->somain, 'remove_from_list')) return false; |
|
| 1076 | 1074 | |
| 1077 | - return $this->somain->remove_from_list($contact,$list); |
|
| 1075 | + return $this->somain->remove_from_list($contact, $list); |
|
| 1078 | 1076 | } |
| 1079 | 1077 | |
| 1080 | 1078 | /** |
@@ -1085,7 +1083,7 @@ discard block |
||
| 1085 | 1083 | */ |
| 1086 | 1084 | function delete_list($list) |
| 1087 | 1085 | { |
| 1088 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
| 1086 | + if (!method_exists($this->somain, 'delete_list')) return false; |
|
| 1089 | 1087 | |
| 1090 | 1088 | return $this->somain->delete_list($list); |
| 1091 | 1089 | } |
@@ -1098,7 +1096,7 @@ discard block |
||
| 1098 | 1096 | */ |
| 1099 | 1097 | function read_list($list) |
| 1100 | 1098 | { |
| 1101 | - if (!method_exists($this->somain,'read_list')) return false; |
|
| 1099 | + if (!method_exists($this->somain, 'read_list')) return false; |
|
| 1102 | 1100 | |
| 1103 | 1101 | return $this->somain->read_list($list); |
| 1104 | 1102 | } |
@@ -1109,11 +1107,11 @@ discard block |
||
| 1109 | 1107 | * @param int|string $owner ='' addressbook (eg. 0 = accounts), default '' = "all" addressbook (uses the main backend) |
| 1110 | 1108 | * @return boolean |
| 1111 | 1109 | */ |
| 1112 | - function lists_available($owner='') |
|
| 1110 | + function lists_available($owner = '') |
|
| 1113 | 1111 | { |
| 1114 | - $backend =& $this->get_backend(null,$owner); |
|
| 1112 | + $backend = & $this->get_backend(null, $owner); |
|
| 1115 | 1113 | |
| 1116 | - return method_exists($backend,'read_list'); |
|
| 1114 | + return method_exists($backend, 'read_list'); |
|
| 1117 | 1115 | } |
| 1118 | 1116 | |
| 1119 | 1117 | /** |
@@ -1122,9 +1120,9 @@ discard block |
||
| 1122 | 1120 | * @param int|array $owner =null null for all lists user has access too |
| 1123 | 1121 | * @return int |
| 1124 | 1122 | */ |
| 1125 | - function lists_ctag($owner=null) |
|
| 1123 | + function lists_ctag($owner = null) |
|
| 1126 | 1124 | { |
| 1127 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
| 1125 | + if (!method_exists($this->somain, 'lists_ctag')) return 0; |
|
| 1128 | 1126 | |
| 1129 | 1127 | return $this->somain->lists_ctag($owner); |
| 1130 | 1128 | } |
@@ -239,10 +239,13 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | // remove some columns, absolutly not necessary to search in sql |
| 241 | 241 | $this->columns_to_search = array_diff(array_values($this->somain->db_cols),$this->sql_cols_not_to_search); |
| 242 | - if ($this->customfields) // add custom fields, if configured |
|
| 242 | + if ($this->customfields) |
|
| 243 | + { |
|
| 244 | + // add custom fields, if configured |
|
| 243 | 245 | { |
| 244 | 246 | $this->columns_to_search[] = Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE; |
| 245 | 247 | } |
| 248 | + } |
|
| 246 | 249 | } |
| 247 | 250 | if ($this->user) |
| 248 | 251 | { |
@@ -319,7 +322,10 @@ discard block |
||
| 319 | 322 | */ |
| 320 | 323 | function get_grants($user, $contact_app='addressbook', $preferences=null) |
| 321 | 324 | { |
| 322 | - if (!isset($preferences)) $preferences = $GLOBALS['egw_info']['user']['preferences']; |
|
| 325 | + if (!isset($preferences)) |
|
| 326 | + { |
|
| 327 | + $preferences = $GLOBALS['egw_info']['user']['preferences']; |
|
| 328 | + } |
|
| 323 | 329 | |
| 324 | 330 | if ($user) |
| 325 | 331 | { |
@@ -347,12 +353,25 @@ discard block |
||
| 347 | 353 | $grants[0] = Api\Acl::READ; |
| 348 | 354 | } |
| 349 | 355 | // add account grants for admins (only for current user!) |
| 350 | - if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL! |
|
| 356 | + if ($user == $this->user && $this->is_admin()) |
|
| 357 | + { |
|
| 358 | + // admin rights can be limited by ACL! |
|
| 351 | 359 | { |
| 352 | - $grants[0] = Api\Acl::READ; // admins always have read-access |
|
| 353 | - if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= Api\Acl::EDIT; |
|
| 354 | - if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) $grants[0] |= Api\Acl::ADD; |
|
| 355 | - if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) $grants[0] |= Api\Acl::DELETE; |
|
| 360 | + $grants[0] = Api\Acl::READ; |
|
| 361 | + } |
|
| 362 | + // admins always have read-access |
|
| 363 | + if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) |
|
| 364 | + { |
|
| 365 | + $grants[0] |= Api\Acl::EDIT; |
|
| 366 | + } |
|
| 367 | + if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) |
|
| 368 | + { |
|
| 369 | + $grants[0] |= Api\Acl::ADD; |
|
| 370 | + } |
|
| 371 | + if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) |
|
| 372 | + { |
|
| 373 | + $grants[0] |= Api\Acl::DELETE; |
|
| 374 | + } |
|
| 356 | 375 | } |
| 357 | 376 | // allow certain groups to edit contact-data of accounts |
| 358 | 377 | if (self::allow_account_edit($user)) |
@@ -422,12 +441,22 @@ discard block |
||
| 422 | 441 | } |
| 423 | 442 | foreach($ids as $key => $id) |
| 424 | 443 | { |
| 425 | - if (!is_numeric($id)) unset($ids[$key]); |
|
| 444 | + if (!is_numeric($id)) |
|
| 445 | + { |
|
| 446 | + unset($ids[$key]); |
|
| 447 | + } |
|
| 426 | 448 | } |
| 427 | - if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
| 449 | + if (!$ids) |
|
| 450 | + { |
|
| 451 | + return array(); |
|
| 452 | + } |
|
| 453 | + // nothing to do, eg. all these contacts are in ldap |
|
| 428 | 454 | $fields = array(); |
| 429 | 455 | $filter[$this->distri_id]=$ids; |
| 430 | - if (count($dl_allowed)) $filter[$this->distri_key]=$dl_allowed; |
|
| 456 | + if (count($dl_allowed)) |
|
| 457 | + { |
|
| 458 | + $filter[$this->distri_key]=$dl_allowed; |
|
| 459 | + } |
|
| 431 | 460 | $distri_view = str_replace(') d_view',' and '.$this->distri_id.' in ('.implode(',',$ids).')) d_view',$this->distributionlist_view); |
| 432 | 461 | #_debug_array($this->distributionlist_tabledef); |
| 433 | 462 | foreach($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
@@ -477,10 +506,16 @@ discard block |
||
| 477 | 506 | */ |
| 478 | 507 | function delete($contact,$check_etag=null) |
| 479 | 508 | { |
| 480 | - if (is_array($contact)) $contact = $contact['id']; |
|
| 509 | + if (is_array($contact)) |
|
| 510 | + { |
|
| 511 | + $contact = $contact['id']; |
|
| 512 | + } |
|
| 481 | 513 | |
| 482 | 514 | $where = array('id' => $contact); |
| 483 | - if ($check_etag) $where['etag'] = $check_etag; |
|
| 515 | + if ($check_etag) |
|
| 516 | + { |
|
| 517 | + $where['etag'] = $check_etag; |
|
| 518 | + } |
|
| 484 | 519 | |
| 485 | 520 | // delete mainfields |
| 486 | 521 | if ($this->somain->delete($where)) |
@@ -556,7 +591,10 @@ discard block |
||
| 556 | 591 | } |
| 557 | 592 | } |
| 558 | 593 | } |
| 559 | - if($error_nr) return $error_nr; |
|
| 594 | + if($error_nr) |
|
| 595 | + { |
|
| 596 | + return $error_nr; |
|
| 597 | + } |
|
| 560 | 598 | |
| 561 | 599 | return false; // no error |
| 562 | 600 | } |
@@ -580,7 +618,10 @@ discard block |
||
| 580 | 618 | return $contact; |
| 581 | 619 | } |
| 582 | 620 | $dl_list=$this->read_distributionlist(array($contact['id'])); |
| 583 | - if (count($dl_list)) $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
| 621 | + if (count($dl_list)) |
|
| 622 | + { |
|
| 623 | + $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
| 624 | + } |
|
| 584 | 625 | return $this->db2data($contact); |
| 585 | 626 | } |
| 586 | 627 | |
@@ -613,7 +654,10 @@ discard block |
||
| 613 | 654 | unset($filter['adr_one_countrycode']); |
| 614 | 655 | } |
| 615 | 656 | // Hide deleted items unless type is specifically deleted |
| 616 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
| 657 | + if(!is_array($filter)) |
|
| 658 | + { |
|
| 659 | + $filter = $filter ? (array) $filter : array(); |
|
| 660 | + } |
|
| 617 | 661 | |
| 618 | 662 | if (isset($filter['cols_to_search'])) |
| 619 | 663 | { |
@@ -624,10 +668,13 @@ discard block |
||
| 624 | 668 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
| 625 | 669 | if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
| 626 | 670 | { |
| 627 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
| 671 | + if ($join && strpos($join,'RIGHT JOIN') !== false) |
|
| 672 | + { |
|
| 673 | + // used eg. to search for groups |
|
| 628 | 674 | { |
| 629 | 675 | $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
| 630 | 676 | } |
| 677 | + } |
|
| 631 | 678 | else |
| 632 | 679 | { |
| 633 | 680 | $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
@@ -675,7 +722,10 @@ discard block |
||
| 675 | 722 | unset($cols[$key]); |
| 676 | 723 | } |
| 677 | 724 | } |
| 678 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
| 725 | + if ($col=='contact_id') |
|
| 726 | + { |
|
| 727 | + $col='egw_addressbook.contact_id'; |
|
| 728 | + } |
|
| 679 | 729 | } |
| 680 | 730 | |
| 681 | 731 | $backend->columns_to_search = $cols; |
@@ -750,7 +800,11 @@ discard block |
||
| 750 | 800 | { |
| 751 | 801 | foreach($this->columns_to_search as $col) |
| 752 | 802 | { |
| 753 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
| 803 | + if ($col != 'contact_value') |
|
| 804 | + { |
|
| 805 | + $param['search'][$col] = $search; |
|
| 806 | + } |
|
| 807 | + // we dont search the customfields |
|
| 754 | 808 | } |
| 755 | 809 | } |
| 756 | 810 | } |
@@ -770,11 +824,17 @@ discard block |
||
| 770 | 824 | $rows = $this->somain->organisations($param); |
| 771 | 825 | $this->total = $this->somain->total; |
| 772 | 826 | |
| 773 | - if (!$rows) return array(); |
|
| 827 | + if (!$rows) |
|
| 828 | + { |
|
| 829 | + return array(); |
|
| 830 | + } |
|
| 774 | 831 | |
| 775 | 832 | foreach($rows as $n => $row) |
| 776 | 833 | { |
| 777 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
| 834 | + if (strpos($row['org_name'],'&')!==false) |
|
| 835 | + { |
|
| 836 | + $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
| 837 | + } |
|
| 778 | 838 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
| 779 | 839 | foreach(array( |
| 780 | 840 | 'org_unit' => lang('departments'), |
@@ -787,7 +847,10 @@ discard block |
||
| 787 | 847 | } |
| 788 | 848 | else |
| 789 | 849 | { |
| 790 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
| 850 | + if (strpos($row[$by],'&')!==false) |
|
| 851 | + { |
|
| 852 | + $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
| 853 | + } |
|
| 791 | 854 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
| 792 | 855 | } |
| 793 | 856 | } |
@@ -847,7 +910,10 @@ discard block |
||
| 847 | 910 | */ |
| 848 | 911 | function get_backend($keys=null,$owner=null) |
| 849 | 912 | { |
| 850 | - if ($owner === '') $owner = null; |
|
| 913 | + if ($owner === '') |
|
| 914 | + { |
|
| 915 | + $owner = null; |
|
| 916 | + } |
|
| 851 | 917 | |
| 852 | 918 | $contact_id = !is_array($keys) ? $keys : |
| 853 | 919 | (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
@@ -911,7 +977,10 @@ discard block |
||
| 911 | 977 | $ds = $GLOBALS['egw']->ldap->ldapConnect(); |
| 912 | 978 | $ldap_contacts = new Ldap(null, $ds); |
| 913 | 979 | |
| 914 | - if (!is_array($type)) $type = explode(',', $type); |
|
| 980 | + if (!is_array($type)) |
|
| 981 | + { |
|
| 982 | + $type = explode(',', $type); |
|
| 983 | + } |
|
| 915 | 984 | |
| 916 | 985 | $start = $n = 0; |
| 917 | 986 | $num = 100; |
@@ -927,7 +996,10 @@ discard block |
||
| 927 | 996 | { |
| 928 | 997 | foreach($contacts as $contact) |
| 929 | 998 | { |
| 930 | - if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
| 999 | + if ($contact['account_id']) |
|
| 1000 | + { |
|
| 1001 | + $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
| 1002 | + } |
|
| 931 | 1003 | |
| 932 | 1004 | $ldap_contacts->data = $contact; |
| 933 | 1005 | $n++; |
@@ -955,10 +1027,13 @@ discard block |
||
| 955 | 1027 | false, $filter) as $contact) |
| 956 | 1028 | { |
| 957 | 1029 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
| 958 | - if ($contact['jpegphoto']) // photo is NOT read by LDAP backend on search, need to do an extra read |
|
| 1030 | + if ($contact['jpegphoto']) |
|
| 1031 | + { |
|
| 1032 | + // photo is NOT read by LDAP backend on search, need to do an extra read |
|
| 959 | 1033 | { |
| 960 | 1034 | $contact = $ldap_contacts->read($contact['id']); |
| 961 | 1035 | } |
| 1036 | + } |
|
| 962 | 1037 | unset($contact['id']); // ldap uid/account_lid |
| 963 | 1038 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
| 964 | 1039 | { |
@@ -992,7 +1067,10 @@ discard block |
||
| 992 | 1067 | */ |
| 993 | 1068 | function get_lists($required=Api\Acl::READ,$extra_labels=null) |
| 994 | 1069 | { |
| 995 | - if (!method_exists($this->somain,'get_lists')) return false; |
|
| 1070 | + if (!method_exists($this->somain,'get_lists')) |
|
| 1071 | + { |
|
| 1072 | + return false; |
|
| 1073 | + } |
|
| 996 | 1074 | |
| 997 | 1075 | $uids = array(); |
| 998 | 1076 | foreach($this->grants as $uid => $rights) |
@@ -1026,7 +1104,10 @@ discard block |
||
| 1026 | 1104 | function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
| 1027 | 1105 | { |
| 1028 | 1106 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
| 1029 | - if (!method_exists($backend, 'get_lists')) return false; |
|
| 1107 | + if (!method_exists($backend, 'get_lists')) |
|
| 1108 | + { |
|
| 1109 | + return false; |
|
| 1110 | + } |
|
| 1030 | 1111 | |
| 1031 | 1112 | return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
| 1032 | 1113 | } |
@@ -1043,7 +1124,10 @@ discard block |
||
| 1043 | 1124 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
| 1044 | 1125 | { |
| 1045 | 1126 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
| 1046 | - if (!method_exists($backend, 'add_list')) return false; |
|
| 1127 | + if (!method_exists($backend, 'add_list')) |
|
| 1128 | + { |
|
| 1129 | + return false; |
|
| 1130 | + } |
|
| 1047 | 1131 | |
| 1048 | 1132 | return $backend->add_list($keys,$owner,$contacts,$data); |
| 1049 | 1133 | } |
@@ -1058,7 +1142,10 @@ discard block |
||
| 1058 | 1142 | */ |
| 1059 | 1143 | function add2list($contact,$list,array $existing=null) |
| 1060 | 1144 | { |
| 1061 | - if (!method_exists($this->somain,'add2list')) return false; |
|
| 1145 | + if (!method_exists($this->somain,'add2list')) |
|
| 1146 | + { |
|
| 1147 | + return false; |
|
| 1148 | + } |
|
| 1062 | 1149 | |
| 1063 | 1150 | return $this->somain->add2list($contact,$list,$existing); |
| 1064 | 1151 | } |
@@ -1072,7 +1159,10 @@ discard block |
||
| 1072 | 1159 | */ |
| 1073 | 1160 | function remove_from_list($contact,$list=null) |
| 1074 | 1161 | { |
| 1075 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
| 1162 | + if (!method_exists($this->somain,'remove_from_list')) |
|
| 1163 | + { |
|
| 1164 | + return false; |
|
| 1165 | + } |
|
| 1076 | 1166 | |
| 1077 | 1167 | return $this->somain->remove_from_list($contact,$list); |
| 1078 | 1168 | } |
@@ -1085,7 +1175,10 @@ discard block |
||
| 1085 | 1175 | */ |
| 1086 | 1176 | function delete_list($list) |
| 1087 | 1177 | { |
| 1088 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
| 1178 | + if (!method_exists($this->somain,'delete_list')) |
|
| 1179 | + { |
|
| 1180 | + return false; |
|
| 1181 | + } |
|
| 1089 | 1182 | |
| 1090 | 1183 | return $this->somain->delete_list($list); |
| 1091 | 1184 | } |
@@ -1098,7 +1191,10 @@ discard block |
||
| 1098 | 1191 | */ |
| 1099 | 1192 | function read_list($list) |
| 1100 | 1193 | { |
| 1101 | - if (!method_exists($this->somain,'read_list')) return false; |
|
| 1194 | + if (!method_exists($this->somain,'read_list')) |
|
| 1195 | + { |
|
| 1196 | + return false; |
|
| 1197 | + } |
|
| 1102 | 1198 | |
| 1103 | 1199 | return $this->somain->read_list($list); |
| 1104 | 1200 | } |
@@ -1124,7 +1220,10 @@ discard block |
||
| 1124 | 1220 | */ |
| 1125 | 1221 | function lists_ctag($owner=null) |
| 1126 | 1222 | { |
| 1127 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
| 1223 | + if (!method_exists($this->somain,'lists_ctag')) |
|
| 1224 | + { |
|
| 1225 | + return 0; |
|
| 1226 | + } |
|
| 1128 | 1227 | |
| 1129 | 1228 | return $this->somain->lists_ctag($owner); |
| 1130 | 1229 | } |
@@ -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 | { |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | * @param string &$type=null on return type of $time (optional) |
| 94 | 94 | * @throws Exception if $time can NOT be parsed |
| 95 | 95 | */ |
| 96 | - public function __construct($time='now',DateTimeZone $tz=null,&$type=null) |
|
| 96 | + public function __construct($time = 'now', DateTimeZone $tz = null, &$type = null) |
|
| 97 | 97 | { |
| 98 | - if (is_null($tz)) $tz = self::$user_timezone; // default user timezone |
|
| 98 | + if (is_null($tz)) $tz = self::$user_timezone; // default user timezone |
|
| 99 | 99 | |
| 100 | - switch(($type = gettype($time))) |
|
| 100 | + switch (($type = gettype($time))) |
|
| 101 | 101 | { |
| 102 | 102 | case 'NULL': |
| 103 | 103 | case 'boolean': // depricated use in calendar for 'now' |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000))) |
| 109 | 109 | { |
| 110 | 110 | $t_str = $time; |
| 111 | - if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date |
|
| 111 | + if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date |
|
| 112 | 112 | // $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself |
| 113 | 113 | try { |
| 114 | - parent::__construct($t_str,$tz); |
|
| 114 | + parent::__construct($t_str, $tz); |
|
| 115 | 115 | break; |
| 116 | 116 | } |
| 117 | - catch(Exception $e) { |
|
| 117 | + catch (Exception $e) { |
|
| 118 | 118 | // if string is nummeric, ignore the exception and treat string as timestamp |
| 119 | 119 | if (!is_numeric($time)) throw $e; |
| 120 | 120 | } |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | else*/ |
| 133 | 133 | { |
| 134 | - parent::__construct(date('Y-m-d H:i:s',$time),$tz); |
|
| 134 | + parent::__construct(date('Y-m-d H:i:s', $time), $tz); |
|
| 135 | 135 | } |
| 136 | 136 | break; |
| 137 | 137 | |
| 138 | 138 | case 'array': |
| 139 | - parent::__construct('now',$tz); |
|
| 139 | + parent::__construct('now', $tz); |
|
| 140 | 140 | if (isset($time['Y'])) // array format used in eTemplate |
| 141 | 141 | { |
| 142 | 142 | $time = array( |
@@ -150,18 +150,18 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | if (!empty($time['full']) && empty($time['year'])) |
| 152 | 152 | { |
| 153 | - $time['year'] = (int)substr($time['full'],0,4); |
|
| 154 | - $time['month'] = (int)substr($time['full'],4,2); |
|
| 155 | - $time['day'] = (int)substr($time['full'],6,2); |
|
| 153 | + $time['year'] = (int)substr($time['full'], 0, 4); |
|
| 154 | + $time['month'] = (int)substr($time['full'], 4, 2); |
|
| 155 | + $time['day'] = (int)substr($time['full'], 6, 2); |
|
| 156 | 156 | } |
| 157 | - if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
| 158 | - $this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']); |
|
| 157 | + if (isset($time['year'])) $this->setDate((int)$time['year'], (int)$time['month'], isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
| 158 | + $this->setTime((int)$time['hour'], (int)$time['minute'], (int)$time['second']); |
|
| 159 | 159 | break; |
| 160 | 160 | |
| 161 | 161 | case 'object': |
| 162 | 162 | if ($time instanceof \DateTime) |
| 163 | 163 | { |
| 164 | - parent::__construct($time->format('Y-m-d H:i:s'),$time->getTimezone()); |
|
| 164 | + parent::__construct($time->format('Y-m-d H:i:s'), $time->getTimezone()); |
|
| 165 | 165 | $this->setTimezone($tz); |
| 166 | 166 | break; |
| 167 | 167 | } |
@@ -188,18 +188,18 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function setWeekstart() |
| 190 | 190 | { |
| 191 | - $wday = (int) $this->format('w'); // 0=sun, ..., 6=sat |
|
| 192 | - switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
| 191 | + $wday = (int)$this->format('w'); // 0=sun, ..., 6=sat |
|
| 192 | + switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
| 193 | 193 | { |
| 194 | 194 | case 'Sunday': |
| 195 | 195 | $wstart = -$wday; |
| 196 | 196 | break; |
| 197 | 197 | case 'Saturday': |
| 198 | - $wstart = -(6-$wday); |
|
| 198 | + $wstart = -(6 - $wday); |
|
| 199 | 199 | break; |
| 200 | 200 | case 'Moday': |
| 201 | 201 | default: |
| 202 | - $wstart = -($wday ? $wday-1 : 6); |
|
| 202 | + $wstart = -($wday ? $wday - 1 : 6); |
|
| 203 | 203 | break; |
| 204 | 204 | } |
| 205 | 205 | if ($wstart) $this->add($wstart.'days'); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @param array $filters $name => list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) pairs with offsets |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public static function sql_filter($name, &$start, &$end, $column, array $filters=array()) |
|
| 218 | + public static function sql_filter($name, &$start, &$end, $column, array $filters = array()) |
|
| 219 | 219 | { |
| 220 | 220 | if ($name == 'custom' && $start) |
| 221 | 221 | { |
@@ -240,26 +240,26 @@ discard block |
||
| 240 | 240 | $end = new DateTime('now'); |
| 241 | 241 | $end->setTime(0, 0, 0); |
| 242 | 242 | |
| 243 | - $year = (int) $start->format('Y'); |
|
| 244 | - $month = (int) $start->format('m'); |
|
| 243 | + $year = (int)$start->format('Y'); |
|
| 244 | + $month = (int)$start->format('m'); |
|
| 245 | 245 | |
| 246 | - list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $filters[$name]; |
|
| 246 | + list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $filters[$name]; |
|
| 247 | 247 | |
| 248 | 248 | // Handle quarters |
| 249 | - if(stripos($name, 'quarter') !== false) |
|
| 249 | + if (stripos($name, 'quarter') !== false) |
|
| 250 | 250 | { |
| 251 | - $start->setDate($year, ((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1); |
|
| 252 | - $end->setDate($year, ((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1); |
|
| 251 | + $start->setDate($year, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1); |
|
| 252 | + $end->setDate($year, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1); |
|
| 253 | 253 | } |
| 254 | 254 | elseif ($syear || $eyear) |
| 255 | 255 | { |
| 256 | - $start->setDate($year+$syear, 1, 1); |
|
| 257 | - $end->setDate($year+$eyear, 1, 1); |
|
| 256 | + $start->setDate($year + $syear, 1, 1); |
|
| 257 | + $end->setDate($year + $eyear, 1, 1); |
|
| 258 | 258 | } |
| 259 | 259 | elseif ($smonth || $emonth) |
| 260 | 260 | { |
| 261 | - $start->setDate($year, $month+$smonth, 1); |
|
| 262 | - $end->setDate($year, $month+$emonth, 1); |
|
| 261 | + $start->setDate($year, $month + $smonth, 1); |
|
| 262 | + $end->setDate($year, $month + $emonth, 1); |
|
| 263 | 263 | } |
| 264 | 264 | elseif ($sday || $eday) |
| 265 | 265 | { |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | } |
| 277 | 277 | // convert start + end from user to servertime for the filter |
| 278 | 278 | $sql = '('.DateTime::user2server($start, 'ts').' <= '.$column; |
| 279 | - if($end) |
|
| 279 | + if ($end) |
|
| 280 | 280 | { |
| 281 | - $sql .=' AND '.$column.' < '.DateTime::user2server($end, 'ts'); |
|
| 281 | + $sql .= ' AND '.$column.' < '.DateTime::user2server($end, 'ts'); |
|
| 282 | 282 | |
| 283 | 283 | // returned timestamps: $end is an inclusive date, eg. for today it's equal to start! |
| 284 | 284 | $end->add('-1day'); |
@@ -320,9 +320,9 @@ discard block |
||
| 320 | 320 | * true = date only, false = time only as in user prefs, '' = date+time as in user prefs |
| 321 | 321 | * @return int|string|array|datetime see $type |
| 322 | 322 | */ |
| 323 | - public function format($type='') |
|
| 323 | + public function format($type = '') |
|
| 324 | 324 | { |
| 325 | - switch((string)$type) |
|
| 325 | + switch ((string)$type) |
|
| 326 | 326 | { |
| 327 | 327 | case '': // empty string: date and time as in user prefs |
| 328 | 328 | //case '': // boolean false: time as in user prefs |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | case 'integer': |
| 348 | 348 | case 'ts': |
| 349 | 349 | // ToDo: Check if PHP5.3 getTimestamp does the same, or always returns UTC timestamp |
| 350 | - return mktime(parent::format('H'),parent::format('i'),parent::format('s'),parent::format('m'),parent::format('d'),parent::format('Y')); |
|
| 350 | + return mktime(parent::format('H'), parent::format('i'), parent::format('s'), parent::format('m'), parent::format('d'), parent::format('Y')); |
|
| 351 | 351 | |
| 352 | 352 | case 'object': |
| 353 | 353 | case 'datetime': |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | 'second' => (int)parent::format('s'), |
| 366 | 366 | 'full' => parent::format('Ymd'), |
| 367 | 367 | ); |
| 368 | - $arr['raw'] = mktime($arr['hour'],$arr['minute'],$arr['second'],$arr['month'],$arr['day'],$arr['year']); |
|
| 368 | + $arr['raw'] = mktime($arr['hour'], $arr['minute'], $arr['second'], $arr['month'], $arr['day'], $arr['year']); |
|
| 369 | 369 | return $arr; |
| 370 | 370 | |
| 371 | 371 | case 'date_array': // array with short keys used by date: Y, m, d, H, i, s (used in eTemplate) |
@@ -399,19 +399,19 @@ discard block |
||
| 399 | 399 | * @param string $type =null type or return-value, default (null) same as $time |
| 400 | 400 | * @return int|string|array|datetime null if time could not be parsed |
| 401 | 401 | */ |
| 402 | - public static function server2user($time,$type=null) |
|
| 402 | + public static function server2user($time, $type = null) |
|
| 403 | 403 | { |
| 404 | - $typeof='DateTime'; |
|
| 404 | + $typeof = 'DateTime'; |
|
| 405 | 405 | if (!($time instanceof DateTime)) |
| 406 | 406 | { |
| 407 | 407 | try |
| 408 | 408 | { |
| 409 | 409 | $time = new DateTime($time, self::$server_timezone, $typeof); |
| 410 | 410 | } |
| 411 | - catch(Exception $e) |
|
| 411 | + catch (Exception $e) |
|
| 412 | 412 | { |
| 413 | 413 | unset($e); |
| 414 | - return null; // time could not be parsed |
|
| 414 | + return null; // time could not be parsed |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | $time->setUser(); |
@@ -429,19 +429,19 @@ discard block |
||
| 429 | 429 | * @param string $type =null type or return-value, default (null) same as $time |
| 430 | 430 | * @return int|string|array|datetime null if time could not be parsed |
| 431 | 431 | */ |
| 432 | - public static function user2server($time,$type=null) |
|
| 432 | + public static function user2server($time, $type = null) |
|
| 433 | 433 | { |
| 434 | - $typeof='DateTime'; |
|
| 434 | + $typeof = 'DateTime'; |
|
| 435 | 435 | if (!($time instanceof DateTime)) |
| 436 | 436 | { |
| 437 | 437 | try |
| 438 | 438 | { |
| 439 | - $time = new DateTime($time,self::$user_timezone,$typeof); |
|
| 439 | + $time = new DateTime($time, self::$user_timezone, $typeof); |
|
| 440 | 440 | } |
| 441 | - catch(Exception $e) |
|
| 441 | + catch (Exception $e) |
|
| 442 | 442 | { |
| 443 | 443 | unset($e); |
| 444 | - return null; // time could not be parsed |
|
| 444 | + return null; // time could not be parsed |
|
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | $time->setServer(); |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * true = date only, false = time only as in user prefs, '' = date+time as in user prefs |
| 462 | 462 | * @return int|string|array|datetime see $type, null if time could not be parsed |
| 463 | 463 | */ |
| 464 | - public static function to($time='now',$type='') |
|
| 464 | + public static function to($time = 'now', $type = '') |
|
| 465 | 465 | { |
| 466 | 466 | if (!($time instanceof DateTime)) |
| 467 | 467 | { |
@@ -469,10 +469,10 @@ discard block |
||
| 469 | 469 | { |
| 470 | 470 | $time = new DateTime($time); |
| 471 | 471 | } |
| 472 | - catch(Exception $e) |
|
| 472 | + catch (Exception $e) |
|
| 473 | 473 | { |
| 474 | 474 | unset($e); |
| 475 | - return null; // time could not be parsed |
|
| 475 | + return null; // time could not be parsed |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | return $time->format($type); |
@@ -486,12 +486,12 @@ discard block |
||
| 486 | 486 | * @param string|int $timeformat ='' integer 12, 24, or format string eg. 'H:i' |
| 487 | 487 | * @return DateTimeZone |
| 488 | 488 | */ |
| 489 | - public static function setUserPrefs($tz,$dateformat='',$timeformat='') |
|
| 489 | + public static function setUserPrefs($tz, $dateformat = '', $timeformat = '') |
|
| 490 | 490 | { |
| 491 | 491 | //echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n"; |
| 492 | 492 | if (!empty($dateformat)) self::$user_dateformat = $dateformat; |
| 493 | 493 | |
| 494 | - switch($timeformat) |
|
| 494 | + switch ($timeformat) |
|
| 495 | 495 | { |
| 496 | 496 | case '': |
| 497 | 497 | break; |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | try { |
| 509 | 509 | self::$user_timezone = new DateTimeZone($tz); |
| 510 | 510 | } |
| 511 | - catch(\Exception $e) |
|
| 511 | + catch (\Exception $e) |
|
| 512 | 512 | { |
| 513 | 513 | unset($e); |
| 514 | 514 | // silently use server timezone, as we have no means to report the wrong timezone to the user from this class |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @param int|string|DateTime $time ='now' |
| 526 | 526 | * @return int difference in seconds between user and server time (for the given time!) |
| 527 | 527 | */ |
| 528 | - public static function tz_offset_s($time='now') |
|
| 528 | + public static function tz_offset_s($time = 'now') |
|
| 529 | 529 | { |
| 530 | 530 | if (!($time instanceof DateTime)) $time = new DateTime($time); |
| 531 | 531 | |
@@ -546,17 +546,17 @@ discard block |
||
| 546 | 546 | try { |
| 547 | 547 | self::$server_timezone = new DateTimeZone($GLOBALS['egw_info']['server']['server_timezone']); |
| 548 | 548 | } |
| 549 | - catch(Exception $e) |
|
| 549 | + catch (Exception $e) |
|
| 550 | 550 | { |
| 551 | 551 | try { |
| 552 | 552 | self::$server_timezone = new DateTimeZone(date_default_timezone_get()); |
| 553 | 553 | } |
| 554 | - catch(Exception $e) |
|
| 554 | + catch (Exception $e) |
|
| 555 | 555 | { |
| 556 | 556 | self::$server_timezone = new DateTimeZone('Europe/Berlin'); |
| 557 | 557 | } |
| 558 | 558 | error_log(__METHOD__."() invalid server_timezone='{$GLOBALS['egw_info']['server']['server_timezone']}' setting now '".self::$server_timezone->getName()."'!"); |
| 559 | - Config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(),'phpgwapi'); |
|
| 559 | + Config::save_value('server_timezone', $GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(), 'phpgwapi'); |
|
| 560 | 560 | } |
| 561 | 561 | if (!isset($GLOBALS['egw_info']['user']['preferences']['common']['tz'])) |
| 562 | 562 | { |
@@ -579,15 +579,15 @@ discard block |
||
| 579 | 579 | { |
| 580 | 580 | // prepare list of timezones from php, ignoring depricated ones and sort as follows |
| 581 | 581 | $tzs = array( |
| 582 | - 'Africa' => array(), // Contients |
|
| 582 | + 'Africa' => array(), // Contients |
|
| 583 | 583 | 'America' => array(), |
| 584 | 584 | 'Asia' => array(), |
| 585 | 585 | 'Australia' => array(), |
| 586 | 586 | 'Europe' => array(), |
| 587 | - 'Atlantic' => array(), // Oceans |
|
| 587 | + 'Atlantic' => array(), // Oceans |
|
| 588 | 588 | 'Pacific' => array(), |
| 589 | 589 | 'Indian' => array(), |
| 590 | - 'Antarctica' => array(), // Poles |
|
| 590 | + 'Antarctica' => array(), // Poles |
|
| 591 | 591 | 'Arctic' => array(), |
| 592 | 592 | 'UTC' => array('UTC' => 'UTC'), |
| 593 | 593 | ); |
@@ -633,27 +633,27 @@ discard block |
||
| 633 | 633 | 'Australia/Yancowinna', |
| 634 | 634 | 'Pacific/Samoa', |
| 635 | 635 | ); |
| 636 | - foreach(DateTimeZone::listIdentifiers() as $name) |
|
| 636 | + foreach (DateTimeZone::listIdentifiers() as $name) |
|
| 637 | 637 | { |
| 638 | - if (in_array($name,$no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
| 639 | - list($continent) = explode('/',$name,2); |
|
| 640 | - if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
| 641 | - $datetime = new DateTime('now',new DateTimeZone($name)); |
|
| 642 | - $tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)." ".$datetime->format(); |
|
| 638 | + if (in_array($name, $no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
| 639 | + list($continent) = explode('/', $name, 2); |
|
| 640 | + if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
| 641 | + $datetime = new DateTime('now', new DateTimeZone($name)); |
|
| 642 | + $tzs[$continent][$name] = str_replace(array('_', '/'), array(' ', ' / '), $name)." ".$datetime->format(); |
|
| 643 | 643 | unset($datetime); |
| 644 | 644 | } |
| 645 | - foreach($tzs as $continent => &$data) |
|
| 645 | + foreach ($tzs as $continent => &$data) |
|
| 646 | 646 | { |
| 647 | - natcasesort($data); // sort cities |
|
| 647 | + natcasesort($data); // sort cities |
|
| 648 | 648 | } |
| 649 | 649 | unset($data); |
| 650 | 650 | |
| 651 | 651 | // if user lang or installed langs contain a european language --> move Europe to top of tz list |
| 652 | 652 | $langs = class_exists('EGroupware\\Api\\Translation') ? Translation::get_installed_langs() : array(); |
| 653 | - if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang'])+array_keys($langs), |
|
| 654 | - array('de','fr','it','nl','bg','ca','cs','da','el','es-es','et','eu','fi','hr','hu','lt','no','pl','pt','sk','sl','sv','tr','uk'))) |
|
| 653 | + if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang']) + array_keys($langs), |
|
| 654 | + array('de', 'fr', 'it', 'nl', 'bg', 'ca', 'cs', 'da', 'el', 'es-es', 'et', 'eu', 'fi', 'hr', 'hu', 'lt', 'no', 'pl', 'pt', 'sk', 'sl', 'sv', 'tr', 'uk'))) |
|
| 655 | 655 | { |
| 656 | - $tzs = array_merge(array('Europe' => $tzs['Europe']),$tzs); |
|
| 656 | + $tzs = array_merge(array('Europe' => $tzs['Europe']), $tzs); |
|
| 657 | 657 | } |
| 658 | 658 | return $tzs; |
| 659 | 659 | } |
@@ -664,30 +664,30 @@ discard block |
||
| 664 | 664 | * @param string $extra extra timezone to add, if not already included in user timezones |
| 665 | 665 | * @return array tzid => label |
| 666 | 666 | */ |
| 667 | - public static function getUserTimezones($extra=null) |
|
| 667 | + public static function getUserTimezones($extra = null) |
|
| 668 | 668 | { |
| 669 | 669 | $tz = $GLOBALS['egw_info']['user']['preferences']['common']['tz']; |
| 670 | - $user_tzs = explode(',',$GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']); |
|
| 670 | + $user_tzs = explode(',', $GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']); |
|
| 671 | 671 | if (count($user_tzs) <= 1) |
| 672 | 672 | { |
| 673 | 673 | $user_tzs = $tz ? array($tz) : array(); |
| 674 | 674 | } |
| 675 | - if ($tz && !in_array($tz,$user_tzs)) |
|
| 675 | + if ($tz && !in_array($tz, $user_tzs)) |
|
| 676 | 676 | { |
| 677 | - $user_tzs = array_merge(array($tz),$user_tzs); |
|
| 677 | + $user_tzs = array_merge(array($tz), $user_tzs); |
|
| 678 | 678 | } |
| 679 | 679 | if (!$user_tzs) // if we have no user timezones, eg. user set no pref --> use server default |
| 680 | 680 | { |
| 681 | 681 | $user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']); |
| 682 | 682 | } |
| 683 | - if ($extra && !in_array($extra,$user_tzs)) |
|
| 683 | + if ($extra && !in_array($extra, $user_tzs)) |
|
| 684 | 684 | { |
| 685 | - $user_tzs = array_merge(array($extra),$user_tzs); |
|
| 685 | + $user_tzs = array_merge(array($extra), $user_tzs); |
|
| 686 | 686 | } |
| 687 | - $ret_user_tzs = array_combine($user_tzs,$user_tzs); |
|
| 688 | - foreach($ret_user_tzs as &$label) |
|
| 687 | + $ret_user_tzs = array_combine($user_tzs, $user_tzs); |
|
| 688 | + foreach ($ret_user_tzs as &$label) |
|
| 689 | 689 | { |
| 690 | - $label = str_replace(array('_','/'),array(' ',' / '),$label); |
|
| 690 | + $label = str_replace(array('_', '/'), array(' ', ' / '), $label); |
|
| 691 | 691 | } |
| 692 | 692 | return $ret_user_tzs; |
| 693 | 693 | } |
@@ -95,7 +95,11 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function __construct($time='now',DateTimeZone $tz=null,&$type=null) |
| 97 | 97 | { |
| 98 | - if (is_null($tz)) $tz = self::$user_timezone; // default user timezone |
|
| 98 | + if (is_null($tz)) |
|
| 99 | + { |
|
| 100 | + $tz = self::$user_timezone; |
|
| 101 | + } |
|
| 102 | + // default user timezone |
|
| 99 | 103 | |
| 100 | 104 | switch(($type = gettype($time))) |
| 101 | 105 | { |
@@ -108,7 +112,11 @@ discard block |
||
| 108 | 112 | if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000))) |
| 109 | 113 | { |
| 110 | 114 | $t_str = $time; |
| 111 | - if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date |
|
| 115 | + if (is_numeric($time) && strlen($time) == 8) |
|
| 116 | + { |
|
| 117 | + $t_str .= 'T000000'; |
|
| 118 | + } |
|
| 119 | + // 'Ymd' string used in calendar to represent a date |
|
| 112 | 120 | // $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself |
| 113 | 121 | try { |
| 114 | 122 | parent::__construct($t_str,$tz); |
@@ -116,7 +124,10 @@ discard block |
||
| 116 | 124 | } |
| 117 | 125 | catch(Exception $e) { |
| 118 | 126 | // if string is nummeric, ignore the exception and treat string as timestamp |
| 119 | - if (!is_numeric($time)) throw $e; |
|
| 127 | + if (!is_numeric($time)) |
|
| 128 | + { |
|
| 129 | + throw $e; |
|
| 130 | + } |
|
| 120 | 131 | } |
| 121 | 132 | } |
| 122 | 133 | $type = 'integer'; |
@@ -137,7 +148,9 @@ discard block |
||
| 137 | 148 | |
| 138 | 149 | case 'array': |
| 139 | 150 | parent::__construct('now',$tz); |
| 140 | - if (isset($time['Y'])) // array format used in eTemplate |
|
| 151 | + if (isset($time['Y'])) |
|
| 152 | + { |
|
| 153 | + // array format used in eTemplate |
|
| 141 | 154 | { |
| 142 | 155 | $time = array( |
| 143 | 156 | 'year' => $time['Y'], |
@@ -148,13 +161,17 @@ discard block |
||
| 148 | 161 | 'second' => $time['s'], |
| 149 | 162 | ); |
| 150 | 163 | } |
| 164 | + } |
|
| 151 | 165 | if (!empty($time['full']) && empty($time['year'])) |
| 152 | 166 | { |
| 153 | 167 | $time['year'] = (int)substr($time['full'],0,4); |
| 154 | 168 | $time['month'] = (int)substr($time['full'],4,2); |
| 155 | 169 | $time['day'] = (int)substr($time['full'],6,2); |
| 156 | 170 | } |
| 157 | - if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
| 171 | + if (isset($time['year'])) |
|
| 172 | + { |
|
| 173 | + $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
| 174 | + } |
|
| 158 | 175 | $this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']); |
| 159 | 176 | break; |
| 160 | 177 | |
@@ -178,7 +195,10 @@ discard block |
||
| 178 | 195 | */ |
| 179 | 196 | public function add($interval) |
| 180 | 197 | { |
| 181 | - if (is_string($interval)) $interval = DateInterval::createFromDateString($interval); |
|
| 198 | + if (is_string($interval)) |
|
| 199 | + { |
|
| 200 | + $interval = DateInterval::createFromDateString($interval); |
|
| 201 | + } |
|
| 182 | 202 | |
| 183 | 203 | parent::add($interval); |
| 184 | 204 | } |
@@ -202,7 +222,10 @@ discard block |
||
| 202 | 222 | $wstart = -($wday ? $wday-1 : 6); |
| 203 | 223 | break; |
| 204 | 224 | } |
| 205 | - if ($wstart) $this->add($wstart.'days'); |
|
| 225 | + if ($wstart) |
|
| 226 | + { |
|
| 227 | + $this->add($wstart.'days'); |
|
| 228 | + } |
|
| 206 | 229 | } |
| 207 | 230 | |
| 208 | 231 | /** |
@@ -263,15 +286,27 @@ discard block |
||
| 263 | 286 | } |
| 264 | 287 | elseif ($sday || $eday) |
| 265 | 288 | { |
| 266 | - if ($sday) $start->add($sday.'days'); |
|
| 267 | - if ($eday) $end->add($eday.'days'); |
|
| 289 | + if ($sday) |
|
| 290 | + { |
|
| 291 | + $start->add($sday.'days'); |
|
| 292 | + } |
|
| 293 | + if ($eday) |
|
| 294 | + { |
|
| 295 | + $end->add($eday.'days'); |
|
| 296 | + } |
|
| 268 | 297 | } |
| 269 | 298 | elseif ($sweek || $eweek) |
| 270 | 299 | { |
| 271 | 300 | $start->setWeekstart(); |
| 272 | - if ($sweek) $start->add($sweek.'weeks'); |
|
| 301 | + if ($sweek) |
|
| 302 | + { |
|
| 303 | + $start->add($sweek.'weeks'); |
|
| 304 | + } |
|
| 273 | 305 | $end->setWeekstart(); |
| 274 | - if ($eweek) $end->add($eweek.'weeks'); |
|
| 306 | + if ($eweek) |
|
| 307 | + { |
|
| 308 | + $end->add($eweek.'weeks'); |
|
| 309 | + } |
|
| 275 | 310 | } |
| 276 | 311 | } |
| 277 | 312 | // convert start + end from user to servertime for the filter |
@@ -416,7 +451,10 @@ discard block |
||
| 416 | 451 | } |
| 417 | 452 | $time->setUser(); |
| 418 | 453 | |
| 419 | - if (is_null($type)) $type = $typeof; |
|
| 454 | + if (is_null($type)) |
|
| 455 | + { |
|
| 456 | + $type = $typeof; |
|
| 457 | + } |
|
| 420 | 458 | |
| 421 | 459 | //echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n"; |
| 422 | 460 | return $time->format($type); |
@@ -446,7 +484,10 @@ discard block |
||
| 446 | 484 | } |
| 447 | 485 | $time->setServer(); |
| 448 | 486 | |
| 449 | - if (is_null($type)) $type = $typeof; |
|
| 487 | + if (is_null($type)) |
|
| 488 | + { |
|
| 489 | + $type = $typeof; |
|
| 490 | + } |
|
| 450 | 491 | |
| 451 | 492 | //echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n"; |
| 452 | 493 | return $time->format($type); |
@@ -489,7 +530,10 @@ discard block |
||
| 489 | 530 | public static function setUserPrefs($tz,$dateformat='',$timeformat='') |
| 490 | 531 | { |
| 491 | 532 | //echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n"; |
| 492 | - if (!empty($dateformat)) self::$user_dateformat = $dateformat; |
|
| 533 | + if (!empty($dateformat)) |
|
| 534 | + { |
|
| 535 | + self::$user_dateformat = $dateformat; |
|
| 536 | + } |
|
| 493 | 537 | |
| 494 | 538 | switch($timeformat) |
| 495 | 539 | { |
@@ -527,7 +571,10 @@ discard block |
||
| 527 | 571 | */ |
| 528 | 572 | public static function tz_offset_s($time='now') |
| 529 | 573 | { |
| 530 | - if (!($time instanceof DateTime)) $time = new DateTime($time); |
|
| 574 | + if (!($time instanceof DateTime)) |
|
| 575 | + { |
|
| 576 | + $time = new DateTime($time); |
|
| 577 | + } |
|
| 531 | 578 | |
| 532 | 579 | return self::$user_timezone->getOffset($time) - self::$server_timezone->getOffset($time); |
| 533 | 580 | } |
@@ -635,9 +682,17 @@ discard block |
||
| 635 | 682 | ); |
| 636 | 683 | foreach(DateTimeZone::listIdentifiers() as $name) |
| 637 | 684 | { |
| 638 | - if (in_array($name,$no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
| 685 | + if (in_array($name,$no_vtimezone)) |
|
| 686 | + { |
|
| 687 | + continue; |
|
| 688 | + } |
|
| 689 | + // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
| 639 | 690 | list($continent) = explode('/',$name,2); |
| 640 | - if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
| 691 | + if (!isset($tzs[$continent])) |
|
| 692 | + { |
|
| 693 | + continue; |
|
| 694 | + } |
|
| 695 | + // old depricated timezones |
|
| 641 | 696 | $datetime = new DateTime('now',new DateTimeZone($name)); |
| 642 | 697 | $tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)." ".$datetime->format(); |
| 643 | 698 | unset($datetime); |
@@ -676,10 +731,13 @@ discard block |
||
| 676 | 731 | { |
| 677 | 732 | $user_tzs = array_merge(array($tz),$user_tzs); |
| 678 | 733 | } |
| 679 | - if (!$user_tzs) // if we have no user timezones, eg. user set no pref --> use server default |
|
| 734 | + if (!$user_tzs) |
|
| 735 | + { |
|
| 736 | + // if we have no user timezones, eg. user set no pref --> use server default |
|
| 680 | 737 | { |
| 681 | 738 | $user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']); |
| 682 | 739 | } |
| 740 | + } |
|
| 683 | 741 | if ($extra && !in_array($extra,$user_tzs)) |
| 684 | 742 | { |
| 685 | 743 | $user_tzs = array_merge(array($extra),$user_tzs); |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * require_once(EGW_INCLUDE_ROOT.'/api/src/Db.php'); |
| 372 | 372 | * EGroupware\Api\Db::$health_check = array('EGroupware\Api\Db', 'galera_cluster_health'); |
| 373 | 373 | * |
| 374 | - * @param Api\Db $db already connected Api\Db instance to check |
|
| 374 | + * @param Db $db already connected Api\Db instance to check |
|
| 375 | 375 | * @throws Db\Exception\Connection if node should NOT be used |
| 376 | 376 | */ |
| 377 | 377 | static function galera_cluster_health(Db $db) |
@@ -1077,7 +1077,6 @@ discard block |
||
| 1077 | 1077 | * |
| 1078 | 1078 | * Example: $db->concat($db->quote('Hallo '),'username') would return |
| 1079 | 1079 | * for mysql "concat('Hallo ',username)" or "'Hallo ' || username" for postgres |
| 1080 | - * @param string $str1 already quoted stringliteral or column-name, variable number of arguments |
|
| 1081 | 1080 | * @return string to be used in a query |
| 1082 | 1081 | */ |
| 1083 | 1082 | function concat(/*$str1, ...*/) |
@@ -1097,7 +1096,7 @@ discard block |
||
| 1097 | 1096 | * @param string $expr column-name or expression optional prefixed with "DISTINCT" |
| 1098 | 1097 | * @param string $order_by ='' optional order |
| 1099 | 1098 | * @param string $separator =',' optional separator, default is comma |
| 1100 | - * @return string|boolean false if not supported by dbms |
|
| 1099 | + * @return false|string false if not supported by dbms |
|
| 1101 | 1100 | */ |
| 1102 | 1101 | function group_concat($expr, $order_by='', $separator=',') |
| 1103 | 1102 | { |
@@ -1430,7 +1429,7 @@ discard block |
||
| 1430 | 1429 | * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
| 1431 | 1430 | * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
| 1432 | 1431 | * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
| 1433 | - * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
| 1432 | + * @param boolean $only if set to an array only colums which are set (as data !!!) are written |
|
| 1434 | 1433 | * typicaly used to form a WHERE-clause from the primary keys. |
| 1435 | 1434 | * If set to True, only columns from the colum_definitons are written. |
| 1436 | 1435 | * @param array|boolean $column_definitions this can be set to the column-definitions-array |
@@ -1910,13 +1909,6 @@ discard block |
||
| 1910 | 1909 | * gives "(name='test\'ed' AND lang='en') OR 'owner' IN (0,4,5,6,10)" if name,lang are strings and owner is an integer |
| 1911 | 1910 | * |
| 1912 | 1911 | * @param string|array $table_def table-name or definition array |
| 1913 | - * @param mixed $args variable number of arguments of the following types: |
|
| 1914 | - * string: get's as is into the result |
|
| 1915 | - * array: column-name / value pairs: the value gets quoted according to the type of the column and prefixed |
|
| 1916 | - * with column-name=, multiple pairs are AND'ed together, see db::column_data_implode |
|
| 1917 | - * bool: If False or is_null($arg): the next 2 (!) arguments gets ignored |
|
| 1918 | - * |
|
| 1919 | - * Please note: As the function has a variable number of arguments, you CAN NOT add further parameters !!! |
|
| 1920 | 1912 | * |
| 1921 | 1913 | * @return string the expression generated from the arguments |
| 1922 | 1914 | */ |
@@ -2054,7 +2046,7 @@ discard block |
||
| 2054 | 2046 | * Strip eg. a prefix from the keys of an array |
| 2055 | 2047 | * |
| 2056 | 2048 | * @param array $arr |
| 2057 | - * @param string|array $strip |
|
| 2049 | + * @param string $strip |
|
| 2058 | 2050 | * @return array |
| 2059 | 2051 | */ |
| 2060 | 2052 | static function strip_array_keys($arr,$strip) |
@@ -67,43 +67,43 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | const FETCH_BOTH = ADODB_FETCH_BOTH; |
| 69 | 69 | /** |
| 70 | - * @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types |
|
| 71 | - */ |
|
| 70 | + * @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types |
|
| 71 | + */ |
|
| 72 | 72 | var $Type = ''; |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | - * @var string $type database type as defined in the header.inc.php, eg. mysqlt |
|
| 76 | - */ |
|
| 75 | + * @var string $type database type as defined in the header.inc.php, eg. mysqlt |
|
| 76 | + */ |
|
| 77 | 77 | var $setupType = ''; |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | - * @var string $Host database host to connect to |
|
| 81 | - */ |
|
| 80 | + * @var string $Host database host to connect to |
|
| 81 | + */ |
|
| 82 | 82 | var $Host = ''; |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * @var string $Port port number of database to connect to |
|
| 86 | - */ |
|
| 85 | + * @var string $Port port number of database to connect to |
|
| 86 | + */ |
|
| 87 | 87 | var $Port = ''; |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | - * @var string $Database name of database to use |
|
| 91 | - */ |
|
| 90 | + * @var string $Database name of database to use |
|
| 91 | + */ |
|
| 92 | 92 | var $Database = ''; |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * @var string $User name of database user |
|
| 96 | - */ |
|
| 95 | + * @var string $User name of database user |
|
| 96 | + */ |
|
| 97 | 97 | var $User = ''; |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | - * @var string $Password password for database user |
|
| 101 | - */ |
|
| 100 | + * @var string $Password password for database user |
|
| 101 | + */ |
|
| 102 | 102 | var $Password = ''; |
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | - * @var int $Debug enable debuging - 0 no, 1 yes |
|
| 106 | - */ |
|
| 105 | + * @var int $Debug enable debuging - 0 no, 1 yes |
|
| 106 | + */ |
|
| 107 | 107 | var $Debug = 0; |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -114,23 +114,23 @@ discard block |
||
| 114 | 114 | var $log_updates = false; |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * @var array $Record current record |
|
| 118 | - */ |
|
| 117 | + * @var array $Record current record |
|
| 118 | + */ |
|
| 119 | 119 | var $Record = array(); |
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | - * @var int row number for current record |
|
| 123 | - */ |
|
| 122 | + * @var int row number for current record |
|
| 123 | + */ |
|
| 124 | 124 | var $Row; |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | - * @var int $Errno internal rdms error number for last error |
|
| 128 | - */ |
|
| 127 | + * @var int $Errno internal rdms error number for last error |
|
| 128 | + */ |
|
| 129 | 129 | var $Errno = 0; |
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | - * @var string descriptive text from last error |
|
| 133 | - */ |
|
| 132 | + * @var string descriptive text from last error |
|
| 133 | + */ |
|
| 134 | 134 | var $Error = ''; |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | - * @param string $query query to be executed (optional) |
|
| 274 | - */ |
|
| 273 | + * @param string $query query to be executed (optional) |
|
| 274 | + */ |
|
| 275 | 275 | |
| 276 | 276 | function db($query = '') |
| 277 | 277 | { |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | - * @return int current connection id |
|
| 283 | - */ |
|
| 282 | + * @return int current connection id |
|
| 283 | + */ |
|
| 284 | 284 | function link_id() |
| 285 | 285 | { |
| 286 | 286 | return $this->Link_ID; |
@@ -652,8 +652,8 @@ discard block |
||
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
| 655 | - * Close a connection to a database |
|
| 656 | - */ |
|
| 655 | + * Close a connection to a database |
|
| 656 | + */ |
|
| 657 | 657 | function disconnect() |
| 658 | 658 | { |
| 659 | 659 | if (!$this->privat_Link_ID) |
@@ -667,11 +667,11 @@ discard block |
||
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
| 670 | - * Convert a unix timestamp to a rdms specific timestamp |
|
| 671 | - * |
|
| 672 | - * @param int unix timestamp |
|
| 673 | - * @return string rdms specific timestamp |
|
| 674 | - */ |
|
| 670 | + * Convert a unix timestamp to a rdms specific timestamp |
|
| 671 | + * |
|
| 672 | + * @param int unix timestamp |
|
| 673 | + * @return string rdms specific timestamp |
|
| 674 | + */ |
|
| 675 | 675 | function to_timestamp($epoch) |
| 676 | 676 | { |
| 677 | 677 | if (!$this->Link_ID && !$this->connect()) |
@@ -683,11 +683,11 @@ discard block |
||
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
| 686 | - * Convert a rdms specific timestamp to a unix timestamp |
|
| 687 | - * |
|
| 688 | - * @param string rdms specific timestamp |
|
| 689 | - * @return int unix timestamp |
|
| 690 | - */ |
|
| 686 | + * Convert a rdms specific timestamp to a unix timestamp |
|
| 687 | + * |
|
| 688 | + * @param string rdms specific timestamp |
|
| 689 | + * @return int unix timestamp |
|
| 690 | + */ |
|
| 691 | 691 | function from_timestamp($timestamp) |
| 692 | 692 | { |
| 693 | 693 | if (!$this->Link_ID && !$this->connect()) |
@@ -709,19 +709,19 @@ discard block |
||
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
| 712 | - * Execute a query |
|
| 713 | - * |
|
| 714 | - * @param string $Query_String the query to be executed |
|
| 715 | - * @param int $line the line method was called from - use __LINE__ |
|
| 716 | - * @param string $file the file method was called from - use __FILE__ |
|
| 717 | - * @param int $offset row to start from, default 0 |
|
| 718 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
| 719 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
| 720 | - * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
| 721 | - * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
| 722 | - * @return ADORecordSet or false, if the query fails |
|
| 723 | - * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
| 724 | - */ |
|
| 712 | + * Execute a query |
|
| 713 | + * |
|
| 714 | + * @param string $Query_String the query to be executed |
|
| 715 | + * @param int $line the line method was called from - use __LINE__ |
|
| 716 | + * @param string $file the file method was called from - use __FILE__ |
|
| 717 | + * @param int $offset row to start from, default 0 |
|
| 718 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
| 719 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
| 720 | + * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
| 721 | + * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
| 722 | + * @return ADORecordSet or false, if the query fails |
|
| 723 | + * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
| 724 | + */ |
|
| 725 | 725 | function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
| 726 | 726 | { |
| 727 | 727 | unset($line, $file); // not used anymore |
@@ -786,26 +786,26 @@ discard block |
||
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | /** |
| 789 | - * Execute a query with limited result set |
|
| 790 | - * |
|
| 791 | - * @param string $Query_String the query to be executed |
|
| 792 | - * @param int $offset row to start from, default 0 |
|
| 793 | - * @param int $line the line method was called from - use __LINE__ |
|
| 794 | - * @param string $file the file method was called from - use __FILE__ |
|
| 795 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
| 796 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
| 797 | - * @return ADORecordSet or false, if the query fails |
|
| 798 | - */ |
|
| 789 | + * Execute a query with limited result set |
|
| 790 | + * |
|
| 791 | + * @param string $Query_String the query to be executed |
|
| 792 | + * @param int $offset row to start from, default 0 |
|
| 793 | + * @param int $line the line method was called from - use __LINE__ |
|
| 794 | + * @param string $file the file method was called from - use __FILE__ |
|
| 795 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
| 796 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
| 797 | + * @return ADORecordSet or false, if the query fails |
|
| 798 | + */ |
|
| 799 | 799 | function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
| 800 | 800 | { |
| 801 | 801 | return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
| 805 | - * Begin Transaction |
|
| 806 | - * |
|
| 807 | - * @return int/boolean current transaction-id, of false if no connection |
|
| 808 | - */ |
|
| 805 | + * Begin Transaction |
|
| 806 | + * |
|
| 807 | + * @return int/boolean current transaction-id, of false if no connection |
|
| 808 | + */ |
|
| 809 | 809 | function transaction_begin() |
| 810 | 810 | { |
| 811 | 811 | if (!$this->Link_ID && !$this->connect()) |
@@ -817,10 +817,10 @@ discard block |
||
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | /** |
| 820 | - * Complete the transaction |
|
| 821 | - * |
|
| 822 | - * @return bool True if sucessful, False if fails |
|
| 823 | - */ |
|
| 820 | + * Complete the transaction |
|
| 821 | + * |
|
| 822 | + * @return bool True if sucessful, False if fails |
|
| 823 | + */ |
|
| 824 | 824 | function transaction_commit() |
| 825 | 825 | { |
| 826 | 826 | if (!$this->Link_ID && !$this->connect()) |
@@ -832,10 +832,10 @@ discard block |
||
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
| 835 | - * Rollback the current transaction |
|
| 836 | - * |
|
| 837 | - * @return bool True if sucessful, False if fails |
|
| 838 | - */ |
|
| 835 | + * Rollback the current transaction |
|
| 836 | + * |
|
| 837 | + * @return bool True if sucessful, False if fails |
|
| 838 | + */ |
|
| 839 | 839 | function transaction_abort() |
| 840 | 840 | { |
| 841 | 841 | if (!$this->Link_ID && !$this->connect()) |
@@ -847,12 +847,12 @@ discard block |
||
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
| 850 | - * Find the primary key of the last insertion on the current db connection |
|
| 851 | - * |
|
| 852 | - * @param string $table name of table the insert was performed on |
|
| 853 | - * @param string $field the autoincrement primary key of the table |
|
| 854 | - * @return int the id, -1 if fails |
|
| 855 | - */ |
|
| 850 | + * Find the primary key of the last insertion on the current db connection |
|
| 851 | + * |
|
| 852 | + * @param string $table name of table the insert was performed on |
|
| 853 | + * @param string $field the autoincrement primary key of the table |
|
| 854 | + * @return int the id, -1 if fails |
|
| 855 | + */ |
|
| 856 | 856 | function get_last_insert_id($table, $field) |
| 857 | 857 | { |
| 858 | 858 | if (!$this->Link_ID && !$this->connect()) |
@@ -875,10 +875,10 @@ discard block |
||
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | /** |
| 878 | - * Get the number of rows affected by last update or delete |
|
| 879 | - * |
|
| 880 | - * @return int number of rows |
|
| 881 | - */ |
|
| 878 | + * Get the number of rows affected by last update or delete |
|
| 879 | + * |
|
| 880 | + * @return int number of rows |
|
| 881 | + */ |
|
| 882 | 882 | function affected_rows() |
| 883 | 883 | { |
| 884 | 884 | if ($this->log_updates) return 0; |
@@ -891,14 +891,14 @@ discard block |
||
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | /** |
| 894 | - * Get description of a table |
|
| 895 | - * |
|
| 896 | - * Beside the column-name all other data depends on the db-type !!! |
|
| 897 | - * |
|
| 898 | - * @param string $table name of table to describe |
|
| 899 | - * @param bool $full optional, default False summary information, True full information |
|
| 900 | - * @return array table meta data |
|
| 901 | - */ |
|
| 894 | + * Get description of a table |
|
| 895 | + * |
|
| 896 | + * Beside the column-name all other data depends on the db-type !!! |
|
| 897 | + * |
|
| 898 | + * @param string $table name of table to describe |
|
| 899 | + * @param bool $full optional, default False summary information, True full information |
|
| 900 | + * @return array table meta data |
|
| 901 | + */ |
|
| 902 | 902 | function metadata($table='',$full=false) |
| 903 | 903 | { |
| 904 | 904 | if (!$this->Link_ID && !$this->connect()) |
@@ -980,10 +980,10 @@ discard block |
||
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | /** |
| 983 | - * Return a list of indexes in current database |
|
| 984 | - * |
|
| 985 | - * @return array list of indexes |
|
| 986 | - */ |
|
| 983 | + * Return a list of indexes in current database |
|
| 984 | + * |
|
| 985 | + * @return array list of indexes |
|
| 986 | + */ |
|
| 987 | 987 | function index_names() |
| 988 | 988 | { |
| 989 | 989 | $indices = array(); |
@@ -1004,10 +1004,10 @@ discard block |
||
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | /** |
| 1007 | - * Returns an array containing column names that are the primary keys of $tablename. |
|
| 1008 | - * |
|
| 1009 | - * @return array of columns |
|
| 1010 | - */ |
|
| 1007 | + * Returns an array containing column names that are the primary keys of $tablename. |
|
| 1008 | + * |
|
| 1009 | + * @return array of columns |
|
| 1010 | + */ |
|
| 1011 | 1011 | function pkey_columns($tablename) |
| 1012 | 1012 | { |
| 1013 | 1013 | if (!$this->Link_ID && !$this->connect()) |
@@ -1018,13 +1018,13 @@ discard block |
||
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | 1020 | /** |
| 1021 | - * Create a new database |
|
| 1022 | - * |
|
| 1023 | - * @param string $adminname name of database administrator user (optional) |
|
| 1024 | - * @param string $adminpasswd password for the database administrator user (optional) |
|
| 1025 | - * @param string $charset default charset for the database |
|
| 1026 | - * @param string $grant_host ='localhost' host/ip of the webserver |
|
| 1027 | - */ |
|
| 1021 | + * Create a new database |
|
| 1022 | + * |
|
| 1023 | + * @param string $adminname name of database administrator user (optional) |
|
| 1024 | + * @param string $adminpasswd password for the database administrator user (optional) |
|
| 1025 | + * @param string $charset default charset for the database |
|
| 1026 | + * @param string $grant_host ='localhost' host/ip of the webserver |
|
| 1027 | + */ |
|
| 1028 | 1028 | function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
| 1029 | 1029 | { |
| 1030 | 1030 | $currentUser = $this->User; |
@@ -1280,12 +1280,12 @@ discard block |
||
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | /** |
| 1283 | - * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
| 1284 | - * |
|
| 1285 | - * This is mostly copy & paste from adodb's datadict class |
|
| 1286 | - * @param string $_name |
|
| 1287 | - * @return string quoted string |
|
| 1288 | - */ |
|
| 1283 | + * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
| 1284 | + * |
|
| 1285 | + * This is mostly copy & paste from adodb's datadict class |
|
| 1286 | + * @param string $_name |
|
| 1287 | + * @return string quoted string |
|
| 1288 | + */ |
|
| 1289 | 1289 | function name_quote($_name = NULL) |
| 1290 | 1290 | { |
| 1291 | 1291 | if (!is_string($_name)) |
@@ -1324,19 +1324,19 @@ discard block |
||
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | /** |
| 1327 | - * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
| 1328 | - * |
|
| 1329 | - * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
| 1330 | - * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
| 1331 | - * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
| 1332 | - * |
|
| 1333 | - * @param mixed $value the value to be escaped |
|
| 1334 | - * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
| 1335 | - * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
| 1336 | - * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
| 1337 | - * @param string $glue =',' used to glue array values together for the string type |
|
| 1338 | - * @return string escaped sting |
|
| 1339 | - */ |
|
| 1327 | + * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
| 1328 | + * |
|
| 1329 | + * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
| 1330 | + * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
| 1331 | + * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
| 1332 | + * |
|
| 1333 | + * @param mixed $value the value to be escaped |
|
| 1334 | + * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
| 1335 | + * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
| 1336 | + * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
| 1337 | + * @param string $glue =',' used to glue array values together for the string type |
|
| 1338 | + * @return string escaped sting |
|
| 1339 | + */ |
|
| 1340 | 1340 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
| 1341 | 1341 | { |
| 1342 | 1342 | if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
@@ -1417,27 +1417,27 @@ discard block |
||
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | /** |
| 1420 | - * Implodes an array of column-value pairs for the use in sql-querys. |
|
| 1421 | - * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
| 1422 | - * |
|
| 1423 | - * @author RalfBecker<at>outdoor-training.de |
|
| 1424 | - * |
|
| 1425 | - * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
| 1426 | - * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
| 1427 | - * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
| 1428 | - * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
| 1429 | - * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
| 1430 | - * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
| 1431 | - * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
| 1432 | - * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
| 1433 | - * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
| 1434 | - * typicaly used to form a WHERE-clause from the primary keys. |
|
| 1435 | - * If set to True, only columns from the colum_definitons are written. |
|
| 1436 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
| 1437 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
| 1438 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
| 1439 | - * @return string SQL |
|
| 1440 | - */ |
|
| 1420 | + * Implodes an array of column-value pairs for the use in sql-querys. |
|
| 1421 | + * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
| 1422 | + * |
|
| 1423 | + * @author RalfBecker<at>outdoor-training.de |
|
| 1424 | + * |
|
| 1425 | + * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
| 1426 | + * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
| 1427 | + * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
| 1428 | + * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
| 1429 | + * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
| 1430 | + * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
| 1431 | + * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
| 1432 | + * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
| 1433 | + * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
| 1434 | + * typicaly used to form a WHERE-clause from the primary keys. |
|
| 1435 | + * If set to True, only columns from the colum_definitons are written. |
|
| 1436 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
| 1437 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
| 1438 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
| 1439 | + * @return string SQL |
|
| 1440 | + */ |
|
| 1441 | 1441 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
| 1442 | 1442 | { |
| 1443 | 1443 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
@@ -1523,14 +1523,14 @@ discard block |
||
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | 1525 | /** |
| 1526 | - * Sets the default column-definitions for use with column_data_implode() |
|
| 1527 | - * |
|
| 1528 | - * @author RalfBecker<at>outdoor-training.de |
|
| 1529 | - * |
|
| 1530 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
| 1531 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
| 1532 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
| 1533 | - */ |
|
| 1526 | + * Sets the default column-definitions for use with column_data_implode() |
|
| 1527 | + * |
|
| 1528 | + * @author RalfBecker<at>outdoor-training.de |
|
| 1529 | + * |
|
| 1530 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
| 1531 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
| 1532 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
| 1533 | + */ |
|
| 1534 | 1534 | function set_column_definitions($column_definitions=False) |
| 1535 | 1535 | { |
| 1536 | 1536 | $this->column_definitions=$column_definitions; |
@@ -1570,17 +1570,17 @@ discard block |
||
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | /** |
| 1573 | - * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
| 1574 | - * |
|
| 1575 | - * The already read table-definitions are shared between all db-instances via a static var. |
|
| 1576 | - * |
|
| 1577 | - * @author RalfBecker<at>outdoor-training.de |
|
| 1578 | - * |
|
| 1579 | - * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
| 1580 | - * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
| 1581 | - * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
| 1582 | - * @return mixed array with table-defintions or False if file not found |
|
| 1583 | - */ |
|
| 1573 | + * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
| 1574 | + * |
|
| 1575 | + * The already read table-definitions are shared between all db-instances via a static var. |
|
| 1576 | + * |
|
| 1577 | + * @author RalfBecker<at>outdoor-training.de |
|
| 1578 | + * |
|
| 1579 | + * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
| 1580 | + * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
| 1581 | + * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
| 1582 | + * @return mixed array with table-defintions or False if file not found |
|
| 1583 | + */ |
|
| 1584 | 1584 | function get_table_definitions($app=False,$table=False) |
| 1585 | 1585 | { |
| 1586 | 1586 | // ease the transition to api |
@@ -1676,21 +1676,21 @@ discard block |
||
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | 1678 | /** |
| 1679 | - * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
| 1680 | - * |
|
| 1681 | - * @author RalfBecker<at>outdoor-training.de |
|
| 1682 | - * |
|
| 1683 | - * @param string $table name of the table |
|
| 1684 | - * @param array $data with column-name / value pairs |
|
| 1685 | - * @param mixed $where string with where clause or array with column-name / values pairs to check if a row with that keys already exists, or false for an unconditional insert |
|
| 1686 | - * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
| 1687 | - * @param int $line line-number to pass to query |
|
| 1688 | - * @param string $file file-name to pass to query |
|
| 1689 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1690 | - * @param bool $use_prepared_statement use a prepared statement |
|
| 1691 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1692 | - * @return ADORecordSet or false, if the query fails |
|
| 1693 | - */ |
|
| 1679 | + * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
| 1680 | + * |
|
| 1681 | + * @author RalfBecker<at>outdoor-training.de |
|
| 1682 | + * |
|
| 1683 | + * @param string $table name of the table |
|
| 1684 | + * @param array $data with column-name / value pairs |
|
| 1685 | + * @param mixed $where string with where clause or array with column-name / values pairs to check if a row with that keys already exists, or false for an unconditional insert |
|
| 1686 | + * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
| 1687 | + * @param int $line line-number to pass to query |
|
| 1688 | + * @param string $file file-name to pass to query |
|
| 1689 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1690 | + * @param bool $use_prepared_statement use a prepared statement |
|
| 1691 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1692 | + * @return ADORecordSet or false, if the query fails |
|
| 1693 | + */ |
|
| 1694 | 1694 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
| 1695 | 1695 | { |
| 1696 | 1696 | if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
@@ -1786,20 +1786,20 @@ discard block |
||
| 1786 | 1786 | } |
| 1787 | 1787 | |
| 1788 | 1788 | /** |
| 1789 | - * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
| 1790 | - * |
|
| 1791 | - * @author RalfBecker<at>outdoor-training.de |
|
| 1792 | - * |
|
| 1793 | - * @param string $table name of the table |
|
| 1794 | - * @param array $data with column-name / value pairs |
|
| 1795 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
| 1796 | - * @param int $line line-number to pass to query |
|
| 1797 | - * @param string $file file-name to pass to query |
|
| 1798 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1799 | - * @param bool $use_prepared_statement use a prepared statement |
|
| 1800 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1801 | - * @return ADORecordSet or false, if the query fails |
|
| 1802 | - */ |
|
| 1789 | + * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
| 1790 | + * |
|
| 1791 | + * @author RalfBecker<at>outdoor-training.de |
|
| 1792 | + * |
|
| 1793 | + * @param string $table name of the table |
|
| 1794 | + * @param array $data with column-name / value pairs |
|
| 1795 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
| 1796 | + * @param int $line line-number to pass to query |
|
| 1797 | + * @param string $file file-name to pass to query |
|
| 1798 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1799 | + * @param bool $use_prepared_statement use a prepared statement |
|
| 1800 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1801 | + * @return ADORecordSet or false, if the query fails |
|
| 1802 | + */ |
|
| 1803 | 1803 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
| 1804 | 1804 | { |
| 1805 | 1805 | if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
@@ -1876,18 +1876,18 @@ discard block |
||
| 1876 | 1876 | } |
| 1877 | 1877 | |
| 1878 | 1878 | /** |
| 1879 | - * Deletes one or more rows in table, all data is quoted according to it's type |
|
| 1880 | - * |
|
| 1881 | - * @author RalfBecker<at>outdoor-training.de |
|
| 1882 | - * |
|
| 1883 | - * @param string $table name of the table |
|
| 1884 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
| 1885 | - * @param int $line line-number to pass to query |
|
| 1886 | - * @param string $file file-name to pass to query |
|
| 1887 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1888 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1889 | - * @return ADORecordSet or false, if the query fails |
|
| 1890 | - */ |
|
| 1879 | + * Deletes one or more rows in table, all data is quoted according to it's type |
|
| 1880 | + * |
|
| 1881 | + * @author RalfBecker<at>outdoor-training.de |
|
| 1882 | + * |
|
| 1883 | + * @param string $table name of the table |
|
| 1884 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
| 1885 | + * @param int $line line-number to pass to query |
|
| 1886 | + * @param string $file file-name to pass to query |
|
| 1887 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1888 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1889 | + * @return ADORecordSet or false, if the query fails |
|
| 1890 | + */ |
|
| 1891 | 1891 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
| 1892 | 1892 | { |
| 1893 | 1893 | if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
@@ -1953,25 +1953,25 @@ discard block |
||
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | 1955 | /** |
| 1956 | - * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
| 1957 | - * |
|
| 1958 | - * @author RalfBecker<at>outdoor-training.de |
|
| 1959 | - * |
|
| 1960 | - * @param string $table name of the table |
|
| 1961 | - * @param array|string $cols string or array of column-names / select-expressions |
|
| 1962 | - * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
| 1963 | - * @param int $line line-number to pass to query |
|
| 1964 | - * @param string $file file-name to pass to query |
|
| 1965 | - * @param int|bool $offset offset for a limited query or False (default) |
|
| 1966 | - * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
| 1967 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1968 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
| 1969 | - * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
| 1970 | - * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
| 1971 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1972 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
| 1973 | - * @return ADORecordSet or false, if the query fails |
|
| 1974 | - */ |
|
| 1956 | + * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
| 1957 | + * |
|
| 1958 | + * @author RalfBecker<at>outdoor-training.de |
|
| 1959 | + * |
|
| 1960 | + * @param string $table name of the table |
|
| 1961 | + * @param array|string $cols string or array of column-names / select-expressions |
|
| 1962 | + * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
| 1963 | + * @param int $line line-number to pass to query |
|
| 1964 | + * @param string $file file-name to pass to query |
|
| 1965 | + * @param int|bool $offset offset for a limited query or False (default) |
|
| 1966 | + * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
| 1967 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
| 1968 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
| 1969 | + * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
| 1970 | + * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
| 1971 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
| 1972 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
| 1973 | + * @return ADORecordSet or false, if the query fails |
|
| 1974 | + */ |
|
| 1975 | 1975 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
| 1976 | 1976 | { |
| 1977 | 1977 | if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
@@ -2006,20 +2006,20 @@ discard block |
||
| 2006 | 2006 | } |
| 2007 | 2007 | |
| 2008 | 2008 | /** |
| 2009 | - * Does a union over multiple selects |
|
| 2010 | - * |
|
| 2011 | - * @author RalfBecker<at>outdoor-training.de |
|
| 2012 | - * |
|
| 2013 | - * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
| 2014 | - * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
| 2015 | - * @param int $line line-number to pass to query |
|
| 2016 | - * @param string $file file-name to pass to query |
|
| 2017 | - * @param string $order_by ORDER BY statement for the union |
|
| 2018 | - * @param int|bool $offset offset for a limited query or False (default) |
|
| 2019 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
| 2020 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
| 2021 | - * @return ADORecordSet or false, if the query fails |
|
| 2022 | - */ |
|
| 2009 | + * Does a union over multiple selects |
|
| 2010 | + * |
|
| 2011 | + * @author RalfBecker<at>outdoor-training.de |
|
| 2012 | + * |
|
| 2013 | + * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
| 2014 | + * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
| 2015 | + * @param int $line line-number to pass to query |
|
| 2016 | + * @param string $file file-name to pass to query |
|
| 2017 | + * @param string $order_by ORDER BY statement for the union |
|
| 2018 | + * @param int|bool $offset offset for a limited query or False (default) |
|
| 2019 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
| 2020 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
| 2021 | + * @return ADORecordSet or false, if the query fails |
|
| 2022 | + */ |
|
| 2023 | 2023 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
| 2024 | 2024 | { |
| 2025 | 2025 | if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | namespace EGroupware\Api; |
| 15 | 15 | |
| 16 | -if(empty($GLOBALS['egw_info']['server']['db_type'])) |
|
| 16 | +if (empty($GLOBALS['egw_info']['server']['db_type'])) |
|
| 17 | 17 | { |
| 18 | 18 | $GLOBALS['egw_info']['server']['db_type'] = 'mysql'; |
| 19 | 19 | } |
@@ -69,22 +69,22 @@ discard block |
||
| 69 | 69 | /** |
| 70 | 70 | * @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types |
| 71 | 71 | */ |
| 72 | - var $Type = ''; |
|
| 72 | + var $Type = ''; |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @var string $type database type as defined in the header.inc.php, eg. mysqlt |
| 76 | 76 | */ |
| 77 | - var $setupType = ''; |
|
| 77 | + var $setupType = ''; |
|
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * @var string $Host database host to connect to |
| 81 | 81 | */ |
| 82 | - var $Host = ''; |
|
| 82 | + var $Host = ''; |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * @var string $Port port number of database to connect to |
| 86 | 86 | */ |
| 87 | - var $Port = ''; |
|
| 87 | + var $Port = ''; |
|
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * @var string $Database name of database to use |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @var string $User name of database user |
| 96 | 96 | */ |
| 97 | - var $User = ''; |
|
| 97 | + var $User = ''; |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @var string $Password password for database user |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * @var int $Debug enable debuging - 0 no, 1 yes |
| 106 | 106 | */ |
| 107 | - var $Debug = 0; |
|
| 107 | + var $Debug = 0; |
|
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * Log update querys to error_log, do not run them |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | /** |
| 117 | 117 | * @var array $Record current record |
| 118 | 118 | */ |
| 119 | - var $Record = array(); |
|
| 119 | + var $Record = array(); |
|
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | 122 | * @var int row number for current record |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | /** |
| 127 | 127 | * @var int $Errno internal rdms error number for last error |
| 128 | 128 | */ |
| 129 | - var $Errno = 0; |
|
| 129 | + var $Errno = 0; |
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * @var string descriptive text from last error |
| 133 | 133 | */ |
| 134 | - var $Error = ''; |
|
| 134 | + var $Error = ''; |
|
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * eGW's own query log, independent of the db-type, eg. /tmp/query.log |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @var ADOConnection |
| 153 | 153 | */ |
| 154 | - var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
| 154 | + var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * Can be used to transparently convert tablenames, eg. 'mytable' => 'otherdb.othertable' |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | /** |
| 188 | 188 | * db is able to use DISTINCT on text or blob columns |
| 189 | 189 | */ |
| 190 | - const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
| 190 | + const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
| 191 | 191 | /** |
| 192 | 192 | * DB is able to use LIKE on text columns |
| 193 | 193 | */ |
| 194 | - const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
| 194 | + const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
| 195 | 195 | /** |
| 196 | 196 | * DB allows ORDER on text columns |
| 197 | 197 | * |
@@ -243,18 +243,18 @@ discard block |
||
| 243 | 243 | self::CAPABILITY_CAST_AS_VARCHAR => 'CAST(%s AS varchar)', |
| 244 | 244 | ); |
| 245 | 245 | |
| 246 | - var $prepared_sql = array(); // sql is the index |
|
| 246 | + var $prepared_sql = array(); // sql is the index |
|
| 247 | 247 | |
| 248 | 248 | /** |
| 249 | 249 | * Constructor |
| 250 | 250 | * |
| 251 | 251 | * @param array $db_data =null values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type' |
| 252 | 252 | */ |
| 253 | - function __construct(array $db_data=null) |
|
| 253 | + function __construct(array $db_data = null) |
|
| 254 | 254 | { |
| 255 | 255 | if (!is_null($db_data)) |
| 256 | 256 | { |
| 257 | - foreach(array( |
|
| 257 | + foreach (array( |
|
| 258 | 258 | 'Database' => 'db_name', |
| 259 | 259 | 'Host' => 'db_host', |
| 260 | 260 | 'Port' => 'db_port', |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @throws Db\Exception\Connection |
| 299 | 299 | * @return ADOConnection |
| 300 | 300 | */ |
| 301 | - function connect($Database = NULL, $Host = NULL, $Port = NULL, $User = NULL, $Password = NULL,$Type = NULL) |
|
| 301 | + function connect($Database = NULL, $Host = NULL, $Port = NULL, $User = NULL, $Password = NULL, $Type = NULL) |
|
| 302 | 302 | { |
| 303 | 303 | /* Handle defaults */ |
| 304 | 304 | if (!is_null($Database) && $Database) |
@@ -307,15 +307,15 @@ discard block |
||
| 307 | 307 | } |
| 308 | 308 | if (!is_null($Host) && $Host) |
| 309 | 309 | { |
| 310 | - $this->Host = $Host; |
|
| 310 | + $this->Host = $Host; |
|
| 311 | 311 | } |
| 312 | 312 | if (!is_null($Port) && $Port) |
| 313 | 313 | { |
| 314 | - $this->Port = $Port; |
|
| 314 | + $this->Port = $Port; |
|
| 315 | 315 | } |
| 316 | 316 | if (!is_null($User) && $User) |
| 317 | 317 | { |
| 318 | - $this->User = $User; |
|
| 318 | + $this->User = $User; |
|
| 319 | 319 | } |
| 320 | 320 | if (!is_null($Password) && $Password) |
| 321 | 321 | { |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | // on connection failure re-try with an other host |
| 333 | 333 | // remembering in session which host we used last time |
| 334 | 334 | $use_host_from_session = true; |
| 335 | - while(($host = $this->get_host(!$use_host_from_session))) |
|
| 335 | + while (($host = $this->get_host(!$use_host_from_session))) |
|
| 336 | 336 | { |
| 337 | 337 | try { |
| 338 | 338 | //error_log(__METHOD__."() this->Host(s)=$this->Host, n=$n --> host=$host"); |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | //error_log(__METHOD__."() host=$host, new_connection=$new_connection, this->Type=$this->Type, this->Host=$this->Host, wsrep_local_state=".array2string($state)); |
| 347 | 347 | return $this->Link_ID; |
| 348 | 348 | } |
| 349 | - catch(Db\Exception\Connection $e) { |
|
| 349 | + catch (Db\Exception\Connection $e) { |
|
| 350 | 350 | _egw_log_exception($e); |
| 351 | - $this->disconnect(); // force a new connect |
|
| 352 | - $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
| 353 | - $use_host_from_session = false; // re-try with next host from list |
|
| 351 | + $this->disconnect(); // force a new connect |
|
| 352 | + $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
| 353 | + $use_host_from_session = false; // re-try with next host from list |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | if (!isset($e)) |
@@ -401,12 +401,12 @@ discard block |
||
| 401 | 401 | { |
| 402 | 402 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
| 403 | 403 | $num_hosts = count($hosts); |
| 404 | - $n =& Cache::getSession(__CLASS__, $this->Host); |
|
| 404 | + $n = & Cache::getSession(__CLASS__, $this->Host); |
|
| 405 | 405 | if (!isset($n)) $n = 0; |
| 406 | 406 | |
| 407 | - if ($next && ++$n >= $num_hosts+2) |
|
| 407 | + if ($next && ++$n >= $num_hosts + 2) |
|
| 408 | 408 | { |
| 409 | - $n = 0; // start search again with default on next request |
|
| 409 | + $n = 0; // start search again with default on next request |
|
| 410 | 410 | $ret = false; |
| 411 | 411 | } |
| 412 | 412 | else |
@@ -429,21 +429,21 @@ discard block |
||
| 429 | 429 | if (!$this->Link_ID) |
| 430 | 430 | { |
| 431 | 431 | $Database = $User = $Password = $Port = $Type = ''; |
| 432 | - foreach(array('Database','User','Password','Port','Type') as $name) |
|
| 432 | + foreach (array('Database', 'User', 'Password', 'Port', 'Type') as $name) |
|
| 433 | 433 | { |
| 434 | 434 | $$name = $this->$name; |
| 435 | 435 | if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
| 436 | 436 | } |
| 437 | 437 | $this->setupType = $php_extension = $Type; |
| 438 | 438 | |
| 439 | - switch($Type) // convert to ADO db-type-names |
|
| 439 | + switch ($Type) // convert to ADO db-type-names |
|
| 440 | 440 | { |
| 441 | 441 | case 'pgsql': |
| 442 | 442 | $Type = 'postgres'; // name in ADOdb |
| 443 | 443 | // create our own pgsql connection-string, to allow unix domain soccets if !$Host |
| 444 | 444 | $Host = "dbname=$Database".($Host ? " host=$Host".($Port ? " port=$Port" : '') : ''). |
| 445 | 445 | " user=$User".($Password ? " password='".addslashes($Password)."'" : ''); |
| 446 | - $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
| 446 | + $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
| 447 | 447 | break; |
| 448 | 448 | |
| 449 | 449 | case 'odbc_mssql': |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | $Type = 'maxdb'; |
| 467 | 467 | // fall through |
| 468 | 468 | case 'maxdb': |
| 469 | - $Type ='sapdb'; // name in ADOdb |
|
| 469 | + $Type = 'sapdb'; // name in ADOdb |
|
| 470 | 470 | $php_extension = 'odbc'; |
| 471 | 471 | break; |
| 472 | 472 | |
@@ -479,18 +479,18 @@ discard block |
||
| 479 | 479 | } |
| 480 | 480 | else |
| 481 | 481 | { |
| 482 | - $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
| 482 | + $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
| 483 | 483 | } |
| 484 | 484 | // fall through |
| 485 | 485 | case 'mysqli': |
| 486 | - $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
| 486 | + $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
| 487 | 487 | // fall through |
| 488 | 488 | default: |
| 489 | 489 | if ($Port) $Host .= ':'.$Port; |
| 490 | 490 | break; |
| 491 | 491 | } |
| 492 | - if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
| 493 | - (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
| 492 | + if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
| 493 | + (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
| 494 | 494 | ($this->Type != $GLOBALS['egw']->db->Type || |
| 495 | 495 | $this->Database != $GLOBALS['egw']->db->Database || |
| 496 | 496 | $this->User != $GLOBALS['egw']->db->User || |
@@ -503,11 +503,11 @@ discard block |
||
| 503 | 503 | } |
| 504 | 504 | if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
| 505 | 505 | { |
| 506 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
| 506 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
| 507 | 507 | } |
| 508 | 508 | else |
| 509 | 509 | { |
| 510 | - $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
| 510 | + $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
| 511 | 511 | } |
| 512 | 512 | $this->Link_ID = ADONewConnection($Type); |
| 513 | 513 | if (!$this->Link_ID) |
@@ -523,11 +523,11 @@ discard block |
||
| 523 | 523 | if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database))) |
| 524 | 524 | { |
| 525 | 525 | $this->ServerInfo = $this->Link_ID->ServerInfo(); |
| 526 | - $this->set_capabilities($Type,$this->ServerInfo['version']); |
|
| 526 | + $this->set_capabilities($Type, $this->ServerInfo['version']); |
|
| 527 | 527 | } |
| 528 | 528 | if (!$Ok) |
| 529 | 529 | { |
| 530 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
| 530 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
| 531 | 531 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); |
| 532 | 532 | } |
| 533 | 533 | if ($this->Debug) |
@@ -543,8 +543,8 @@ discard block |
||
| 543 | 543 | // this is the format ADOdb expects |
| 544 | 544 | $this->Link_ID->Execute('SET DATEFORMAT ymd'); |
| 545 | 545 | // sets the limit to the maximum |
| 546 | - ini_set('mssql.textlimit',2147483647); |
|
| 547 | - ini_set('mssql.sizelimit',2147483647); |
|
| 546 | + ini_set('mssql.textlimit', 2147483647); |
|
| 547 | + ini_set('mssql.sizelimit', 2147483647); |
|
| 548 | 548 | } |
| 549 | 549 | // set our default charset |
| 550 | 550 | $this->Link_ID->SetCharSet($this->Type == 'mysql' ? 'utf8' : 'utf-8'); |
@@ -553,12 +553,12 @@ discard block |
||
| 553 | 553 | } |
| 554 | 554 | else |
| 555 | 555 | { |
| 556 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
| 556 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | if (!$this->Link_ID->isConnected() && !$this->Link_ID->Connect()) |
| 560 | 560 | { |
| 561 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
| 561 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
| 562 | 562 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) reconnect failed."); |
| 563 | 563 | } |
| 564 | 564 | // fix due to caching and reusing of connection not correctly set $this->Type == 'mysql' |
@@ -569,9 +569,9 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | if ($new_connection) |
| 571 | 571 | { |
| 572 | - foreach(get_included_files() as $file) |
|
| 572 | + foreach (get_included_files() as $file) |
|
| 573 | 573 | { |
| 574 | - if (strpos($file,'adodb') !== false && !in_array($file,(array)$_SESSION['egw_required_files'])) |
|
| 574 | + if (strpos($file, 'adodb') !== false && !in_array($file, (array)$_SESSION['egw_required_files'])) |
|
| 575 | 575 | { |
| 576 | 576 | $_SESSION['egw_required_files'][] = $file; |
| 577 | 577 | //error_log(__METHOD__."() egw_required_files[] = $file"); |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | function __wakeup() |
| 589 | 589 | { |
| 590 | - $this->connect(); // we need to re-connect |
|
| 590 | + $this->connect(); // we need to re-connect |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | */ |
| 601 | 601 | function __sleep() |
| 602 | 602 | { |
| 603 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
| 603 | + if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
| 604 | 604 | |
| 605 | 605 | $vars = get_object_vars($this); |
| 606 | 606 | unset($vars['Link_ID']); |
@@ -614,23 +614,23 @@ discard block |
||
| 614 | 614 | * @param string $adodb_driver mysql, postgres, mssql, sapdb, oci8 |
| 615 | 615 | * @param string $db_version version-number of connected db-server, as reported by ServerInfo |
| 616 | 616 | */ |
| 617 | - function set_capabilities($adodb_driver,$db_version) |
|
| 617 | + function set_capabilities($adodb_driver, $db_version) |
|
| 618 | 618 | { |
| 619 | - switch($adodb_driver) |
|
| 619 | + switch ($adodb_driver) |
|
| 620 | 620 | { |
| 621 | 621 | case 'mysql': |
| 622 | 622 | case 'mysqlt': |
| 623 | 623 | case 'mysqli': |
| 624 | - $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float) $db_version >= 4.1; |
|
| 625 | - $this->capabilities[self::CAPABILITY_UNION] = (float) $db_version >= 4.0; |
|
| 624 | + $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float)$db_version >= 4.1; |
|
| 625 | + $this->capabilities[self::CAPABILITY_UNION] = (float)$db_version >= 4.0; |
|
| 626 | 626 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'preserv'; |
| 627 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 4.1; |
|
| 627 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 4.1; |
|
| 628 | 628 | $this->capabilities[self::CAPABILITY_CAST_AS_VARCHAR] = 'CAST(%s AS char)'; |
| 629 | 629 | break; |
| 630 | 630 | |
| 631 | 631 | case 'postgres': |
| 632 | 632 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'lower'; |
| 633 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 7.4; |
|
| 633 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 7.4; |
|
| 634 | 634 | $this->capabilities[self::CAPABILITY_OUTER_JOIN] = true; |
| 635 | 635 | $this->capabilities[self::CAPABILITY_CASE_INSENSITIV_LIKE] = '::text ILIKE'; |
| 636 | 636 | $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR] = true; |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | return False; |
| 680 | 680 | } |
| 681 | 681 | // the substring is needed as the string is already in quotes |
| 682 | - return substr($this->Link_ID->DBTimeStamp($epoch),1,-1); |
|
| 682 | + return substr($this->Link_ID->DBTimeStamp($epoch), 1, -1); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | */ |
| 706 | 706 | public static function from_bool($val) |
| 707 | 707 | { |
| 708 | - return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
| 708 | + return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -722,9 +722,9 @@ discard block |
||
| 722 | 722 | * @return ADORecordSet or false, if the query fails |
| 723 | 723 | * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
| 724 | 724 | */ |
| 725 | - function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
|
| 725 | + function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true) |
|
| 726 | 726 | { |
| 727 | - unset($line, $file); // not used anymore |
|
| 727 | + unset($line, $file); // not used anymore |
|
| 728 | 728 | |
| 729 | 729 | if ($Query_String == '') |
| 730 | 730 | { |
@@ -750,23 +750,23 @@ discard block |
||
| 750 | 750 | } |
| 751 | 751 | if ($num_rows > 0) |
| 752 | 752 | { |
| 753 | - $rs = $this->Link_ID->SelectLimit($Query_String,$num_rows,(int)$offset,$inputarr); |
|
| 753 | + $rs = $this->Link_ID->SelectLimit($Query_String, $num_rows, (int)$offset, $inputarr); |
|
| 754 | 754 | } |
| 755 | 755 | else |
| 756 | 756 | { |
| 757 | - $rs = $this->Link_ID->Execute($Query_String,$inputarr); |
|
| 757 | + $rs = $this->Link_ID->Execute($Query_String, $inputarr); |
|
| 758 | 758 | } |
| 759 | 759 | $this->Row = 0; |
| 760 | 760 | $this->Errno = $this->Link_ID->ErrorNo(); |
| 761 | 761 | $this->Error = $this->Link_ID->ErrorMsg(); |
| 762 | 762 | |
| 763 | - if ($this->query_log && ($f = @fopen($this->query_log,'a+'))) |
|
| 763 | + if ($this->query_log && ($f = @fopen($this->query_log, 'a+'))) |
|
| 764 | 764 | { |
| 765 | - fwrite($f,'['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
| 766 | - fwrite($f,date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr,true) : '')."\n"); |
|
| 765 | + fwrite($f, '['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
| 766 | + fwrite($f, date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr, true) : '')."\n"); |
|
| 767 | 767 | if (!$rs) |
| 768 | 768 | { |
| 769 | - fwrite($f,"*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
| 769 | + fwrite($f, "*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
| 770 | 770 | } |
| 771 | 771 | fclose($f); |
| 772 | 772 | } |
@@ -777,11 +777,11 @@ discard block |
||
| 777 | 777 | $this->disconnect(); |
| 778 | 778 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
| 779 | 779 | } |
| 780 | - throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
|
| 780 | + throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String) ? $Query_String[0] : $Query_String). |
|
| 781 | 781 | "\n$this->Error ($this->Errno)". |
| 782 | - ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
|
| 782 | + ($inputarr ? "\nParameters: '".implode("','", $inputarr)."'" : ''), $this->Errno); |
|
| 783 | 783 | } |
| 784 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
| 784 | + elseif (empty($rs->sql)) $rs->sql = $Query_String; |
|
| 785 | 785 | return $rs; |
| 786 | 786 | } |
| 787 | 787 | |
@@ -796,9 +796,9 @@ discard block |
||
| 796 | 796 | * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
| 797 | 797 | * @return ADORecordSet or false, if the query fails |
| 798 | 798 | */ |
| 799 | - function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
|
| 799 | + function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '', $inputarr = false) |
|
| 800 | 800 | { |
| 801 | - return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
|
| 801 | + return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr); |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | { |
| 864 | 864 | $table = self::$tablealiases[$table]; |
| 865 | 865 | } |
| 866 | - $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
| 866 | + $id = $this->Link_ID->PO_Insert_ID($table, $field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
| 867 | 867 | |
| 868 | 868 | if ($id === False) // function not supported |
| 869 | 869 | { |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | * @param bool $full optional, default False summary information, True full information |
| 900 | 900 | * @return array table meta data |
| 901 | 901 | */ |
| 902 | - function metadata($table='',$full=false) |
|
| 902 | + function metadata($table = '', $full = false) |
|
| 903 | 903 | { |
| 904 | 904 | if (!$this->Link_ID && !$this->connect()) |
| 905 | 905 | { |
@@ -911,13 +911,13 @@ discard block |
||
| 911 | 911 | |
| 912 | 912 | $metadata = array(); |
| 913 | 913 | $i = 0; |
| 914 | - foreach($columns as $column) |
|
| 914 | + foreach ($columns as $column) |
|
| 915 | 915 | { |
| 916 | 916 | // for backwards compatibilty (depreciated) |
| 917 | 917 | $flags = null; |
| 918 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
| 919 | - if($column->primary_key) $flags .= "primary_key "; |
|
| 920 | - if($column->binary) $flags .= "binary "; |
|
| 918 | + if ($column->auto_increment) $flags .= "auto_increment "; |
|
| 919 | + if ($column->primary_key) $flags .= "primary_key "; |
|
| 920 | + if ($column->binary) $flags .= "binary "; |
|
| 921 | 921 | |
| 922 | 922 | $metadata[$i] = array( |
| 923 | 923 | 'table' => $table, |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | * @param boolean $just_name =false true return array of table-names, false return old format |
| 953 | 953 | * @return array list of the tables |
| 954 | 954 | */ |
| 955 | - function table_names($just_name=false) |
|
| 955 | + function table_names($just_name = false) |
|
| 956 | 956 | { |
| 957 | 957 | if (!$this->Link_ID) $this->connect(); |
| 958 | 958 | if (!$this->Link_ID) |
@@ -963,7 +963,7 @@ discard block |
||
| 963 | 963 | $tables = $this->Link_ID->MetaTables('TABLES'); |
| 964 | 964 | if (is_array($tables)) |
| 965 | 965 | { |
| 966 | - foreach($tables as $table) |
|
| 966 | + foreach ($tables as $table) |
|
| 967 | 967 | { |
| 968 | 968 | if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') |
| 969 | 969 | { |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | echo "<p>db::index_names() not yet implemented for db-type '$this->Type'</p>\n"; |
| 993 | 993 | return $indices; |
| 994 | 994 | } |
| 995 | - foreach($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
| 995 | + foreach ($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
| 996 | 996 | { |
| 997 | 997 | $indices[] = array( |
| 998 | 998 | 'index_name' => $row[0], |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | * @param string $charset default charset for the database |
| 1026 | 1026 | * @param string $grant_host ='localhost' host/ip of the webserver |
| 1027 | 1027 | */ |
| 1028 | - function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
|
| 1028 | + function create_database($adminname = '', $adminpasswd = '', $charset = '', $grant_host = 'localhost') |
|
| 1029 | 1029 | { |
| 1030 | 1030 | $currentUser = $this->User; |
| 1031 | 1031 | $currentPassword = $this->Password; |
@@ -1049,7 +1049,7 @@ discard block |
||
| 1049 | 1049 | case 'mysqli': |
| 1050 | 1050 | case 'mysqlt': |
| 1051 | 1051 | $create = "CREATE DATABASE `$currentDatabase`"; |
| 1052 | - if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float) $this->ServerInfo['version'] >= 4.1) |
|
| 1052 | + if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float)$this->ServerInfo['version'] >= 4.1) |
|
| 1053 | 1053 | { |
| 1054 | 1054 | $create .= ' DEFAULT CHARACTER SET '.$this->Link_ID->charset2mysql[$charset].';'; |
| 1055 | 1055 | } |
@@ -1060,9 +1060,9 @@ discard block |
||
| 1060 | 1060 | echo "<p>db::create_database(user='$adminname',\$pw) not yet implemented for DB-type '$this->Type'</p>\n"; |
| 1061 | 1061 | break; |
| 1062 | 1062 | } |
| 1063 | - foreach($sqls as $sql) |
|
| 1063 | + foreach ($sqls as $sql) |
|
| 1064 | 1064 | { |
| 1065 | - $this->query($sql,__LINE__,__FILE__); |
|
| 1065 | + $this->query($sql, __LINE__, __FILE__); |
|
| 1066 | 1066 | } |
| 1067 | 1067 | $this->disconnect(); |
| 1068 | 1068 | |
@@ -1088,7 +1088,7 @@ discard block |
||
| 1088 | 1088 | { |
| 1089 | 1089 | return False; |
| 1090 | 1090 | } |
| 1091 | - return call_user_func_array(array(&$this->Link_ID,'concat'),$args); |
|
| 1091 | + return call_user_func_array(array(&$this->Link_ID, 'concat'), $args); |
|
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | /** |
@@ -1099,9 +1099,9 @@ discard block |
||
| 1099 | 1099 | * @param string $separator =',' optional separator, default is comma |
| 1100 | 1100 | * @return string|boolean false if not supported by dbms |
| 1101 | 1101 | */ |
| 1102 | - function group_concat($expr, $order_by='', $separator=',') |
|
| 1102 | + function group_concat($expr, $order_by = '', $separator = ',') |
|
| 1103 | 1103 | { |
| 1104 | - switch($this->Type) |
|
| 1104 | + switch ($this->Type) |
|
| 1105 | 1105 | { |
| 1106 | 1106 | case 'mysql': |
| 1107 | 1107 | $sql = 'GROUP_CONCAT('.$expr; |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | */ |
| 1136 | 1136 | function strpos($str, $substr) |
| 1137 | 1137 | { |
| 1138 | - switch($this->Type) |
|
| 1138 | + switch ($this->Type) |
|
| 1139 | 1139 | { |
| 1140 | 1140 | case 'mysql': |
| 1141 | 1141 | return "LOCATE($substr,$str)"; |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | */ |
| 1156 | 1156 | function unix_timestamp($expr) |
| 1157 | 1157 | { |
| 1158 | - switch($this->Type) |
|
| 1158 | + switch ($this->Type) |
|
| 1159 | 1159 | { |
| 1160 | 1160 | case 'mysql': |
| 1161 | 1161 | return "UNIX_TIMESTAMP($expr)"; |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | */ |
| 1177 | 1177 | function from_unixtime($expr) |
| 1178 | 1178 | { |
| 1179 | - switch($this->Type) |
|
| 1179 | + switch ($this->Type) |
|
| 1180 | 1180 | { |
| 1181 | 1181 | case 'mysql': |
| 1182 | 1182 | return "FROM_UNIXTIME($expr)"; |
@@ -1185,7 +1185,7 @@ discard block |
||
| 1185 | 1185 | return "(TIMESTAMP WITH TIME ZONE 'epoch' + ($expr) * INTERVAL '1 sec')"; |
| 1186 | 1186 | |
| 1187 | 1187 | case 'mssql': // we use date(,0) as we store server-time |
| 1188 | - return "DATEADD(second,($expr),'".date('Y-m-d H:i:s',0)."')"; |
|
| 1188 | + return "DATEADD(second,($expr),'".date('Y-m-d H:i:s', 0)."')"; |
|
| 1189 | 1189 | } |
| 1190 | 1190 | return false; |
| 1191 | 1191 | } |
@@ -1199,30 +1199,30 @@ discard block |
||
| 1199 | 1199 | * @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 |
| 1200 | 1200 | * @return string SQL expression of type timestamp |
| 1201 | 1201 | */ |
| 1202 | - function date_format($expr,$format) |
|
| 1202 | + function date_format($expr, $format) |
|
| 1203 | 1203 | { |
| 1204 | - switch($this->Type) |
|
| 1204 | + switch ($this->Type) |
|
| 1205 | 1205 | { |
| 1206 | 1206 | case 'mysql': |
| 1207 | 1207 | return "DATE_FORMAT($expr,'$format')"; |
| 1208 | 1208 | |
| 1209 | 1209 | case 'pgsql': |
| 1210 | 1210 | $format = str_replace( |
| 1211 | - array('%Y', '%y','%m','%d','%H', '%h','%i','%s','%V','%v','%X', '%x'), |
|
| 1212 | - array('YYYY','YY','MM','DD','HH24','HH','MI','SS','IW','IW','YYYY','YYYY'), |
|
| 1211 | + array('%Y', '%y', '%m', '%d', '%H', '%h', '%i', '%s', '%V', '%v', '%X', '%x'), |
|
| 1212 | + array('YYYY', 'YY', 'MM', 'DD', 'HH24', 'HH', 'MI', 'SS', 'IW', 'IW', 'YYYY', 'YYYY'), |
|
| 1213 | 1213 | $format); |
| 1214 | 1214 | return "TO_CHAR($expr,'$format')"; |
| 1215 | 1215 | |
| 1216 | 1216 | case 'mssql': |
| 1217 | 1217 | $from = $to = array(); |
| 1218 | - 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) |
|
| 1218 | + 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) |
|
| 1219 | 1219 | { |
| 1220 | 1220 | $from[] = $f; |
| 1221 | 1221 | $to[] = "'+DATEPART($t,($expr))+'"; |
| 1222 | 1222 | } |
| 1223 | 1223 | $from[] = "''+"; $to[] = ''; |
| 1224 | 1224 | $from[] = "+''"; $to[] = ''; |
| 1225 | - return str_replace($from,$to,$format); |
|
| 1225 | + return str_replace($from, $to, $format); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | return false; |
| 1228 | 1228 | } |
@@ -1235,7 +1235,7 @@ discard block |
||
| 1235 | 1235 | */ |
| 1236 | 1236 | function to_double($expr) |
| 1237 | 1237 | { |
| 1238 | - switch($this->Type) |
|
| 1238 | + switch ($this->Type) |
|
| 1239 | 1239 | { |
| 1240 | 1240 | case 'pgsql': |
| 1241 | 1241 | return $expr.'::double'; |
@@ -1253,7 +1253,7 @@ discard block |
||
| 1253 | 1253 | */ |
| 1254 | 1254 | function to_int($expr) |
| 1255 | 1255 | { |
| 1256 | - switch($this->Type) |
|
| 1256 | + switch ($this->Type) |
|
| 1257 | 1257 | { |
| 1258 | 1258 | case 'pgsql': |
| 1259 | 1259 | return $expr.'::integer'; |
@@ -1271,7 +1271,7 @@ discard block |
||
| 1271 | 1271 | */ |
| 1272 | 1272 | function to_varchar($expr) |
| 1273 | 1273 | { |
| 1274 | - switch($this->Type) |
|
| 1274 | + switch ($this->Type) |
|
| 1275 | 1275 | { |
| 1276 | 1276 | case 'pgsql': |
| 1277 | 1277 | return 'CAST('.$expr.' AS varchar)'; |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | // always quote for postgreSQL, as this is the only way to support mixed case names |
| 1316 | 1316 | if (preg_match('/\W/', $name) || $type == 'pgsql' && preg_match('/[A-Z]+/', $name) || $name == 'index') |
| 1317 | 1317 | { |
| 1318 | - return $quote . $name . $quote; |
|
| 1318 | + return $quote.$name.$quote; |
|
| 1319 | 1319 | } |
| 1320 | 1320 | return $name; |
| 1321 | 1321 | }, explode('.', $name)); |
@@ -1337,27 +1337,27 @@ discard block |
||
| 1337 | 1337 | * @param string $glue =',' used to glue array values together for the string type |
| 1338 | 1338 | * @return string escaped sting |
| 1339 | 1339 | */ |
| 1340 | - function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
|
| 1340 | + function quote($value, $type = False, $not_null = true, $length = null, $glue = ',') |
|
| 1341 | 1341 | { |
| 1342 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
| 1342 | + if ($this->Debug) echo "<p>db::quote(".(is_null($value) ? 'NULL' : "'$value'").",'$type','$not_null')</p>\n"; |
|
| 1343 | 1343 | |
| 1344 | 1344 | if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
| 1345 | 1345 | { |
| 1346 | 1346 | return 'NULL'; |
| 1347 | 1347 | } |
| 1348 | - switch($type) |
|
| 1348 | + switch ($type) |
|
| 1349 | 1349 | { |
| 1350 | 1350 | case 'int': |
| 1351 | 1351 | // if DateTime object given, convert it to a unix timestamp (NOT converting the timezone!) |
| 1352 | 1352 | if (is_object($value) && ($value instanceof \DateTime)) |
| 1353 | 1353 | { |
| 1354 | - return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value,'ts'); |
|
| 1354 | + return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value, 'ts'); |
|
| 1355 | 1355 | } |
| 1356 | 1356 | case 'auto': |
| 1357 | 1357 | // atm. (php5.2) php has only 32bit integers, it converts everything else to float. |
| 1358 | 1358 | // Casting it to int gives a negative number instead of the big 64bit integer! |
| 1359 | 1359 | // There for we have to keep it as float by using round instead the int cast. |
| 1360 | - return is_float($value) ? round($value) : (int) $value; |
|
| 1360 | + return is_float($value) ? round($value) : (int)$value; |
|
| 1361 | 1361 | case 'bool': |
| 1362 | 1362 | if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
| 1363 | 1363 | { |
@@ -1366,23 +1366,23 @@ discard block |
||
| 1366 | 1366 | return $value ? 'true' : 'false'; |
| 1367 | 1367 | case 'float': |
| 1368 | 1368 | case 'decimal': |
| 1369 | - return (double) $value; |
|
| 1369 | + return (double)$value; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | if (!$this->Link_ID && !$this->connect()) |
| 1372 | 1372 | { |
| 1373 | 1373 | return False; |
| 1374 | 1374 | } |
| 1375 | - switch($type) |
|
| 1375 | + switch ($type) |
|
| 1376 | 1376 | { |
| 1377 | 1377 | case 'blob': |
| 1378 | 1378 | switch ($this->Link_ID->blobEncodeType) |
| 1379 | 1379 | { |
| 1380 | 1380 | case 'C': // eg. postgres |
| 1381 | - return "'" . $this->Link_ID->BlobEncode($value) . "'"; |
|
| 1381 | + return "'".$this->Link_ID->BlobEncode($value)."'"; |
|
| 1382 | 1382 | case 'I': |
| 1383 | 1383 | return $this->Link_ID->BlobEncode($value); |
| 1384 | 1384 | } |
| 1385 | - break; // handled like strings |
|
| 1385 | + break; // handled like strings |
|
| 1386 | 1386 | case 'date': |
| 1387 | 1387 | // if DateTime object given, convert it (NOT converting the timezone!) |
| 1388 | 1388 | if (is_object($value) && ($value instanceof \DateTime)) |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | } |
| 1401 | 1401 | if (is_array($value)) |
| 1402 | 1402 | { |
| 1403 | - $value = implode($glue,$value); |
|
| 1403 | + $value = implode($glue, $value); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | // only truncate string if length given and <= 255 |
| 1406 | 1406 | // to not unnecessary truncate varchar(>255) as PostgreSQL uses text anyway and MySQL truncates itself silently (unless strict mode!) |
@@ -1438,7 +1438,7 @@ discard block |
||
| 1438 | 1438 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
| 1439 | 1439 | * @return string SQL |
| 1440 | 1440 | */ |
| 1441 | - function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
|
| 1441 | + function column_data_implode($glue, $array, $use_key = True, $only = False, $column_definitions = False) |
|
| 1442 | 1442 | { |
| 1443 | 1443 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
| 1444 | 1444 | { |
@@ -1448,16 +1448,16 @@ discard block |
||
| 1448 | 1448 | { |
| 1449 | 1449 | $column_definitions = $this->column_definitions; |
| 1450 | 1450 | } |
| 1451 | - if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
| 1451 | + if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array, True).",'$use_key',".print_r($only, True).",<pre>".print_r($column_definitions, True)."</pre>\n"; |
|
| 1452 | 1452 | |
| 1453 | 1453 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
| 1454 | 1454 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
| 1455 | 1455 | |
| 1456 | 1456 | $keys = $values = array(); |
| 1457 | - foreach($array as $key => $data) |
|
| 1457 | + foreach ($array as $key => $data) |
|
| 1458 | 1458 | { |
| 1459 | 1459 | if (is_int($key) && $use_key !== 'VALUES' || !$only || $only === True && isset($column_definitions[$key]) || |
| 1460 | - is_array($only) && in_array($key,$only)) |
|
| 1460 | + is_array($only) && in_array($key, $only)) |
|
| 1461 | 1461 | { |
| 1462 | 1462 | $keys[] = $this->name_quote($key); |
| 1463 | 1463 | |
@@ -1468,7 +1468,7 @@ discard block |
||
| 1468 | 1468 | if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
| 1469 | 1469 | if (!isset($column_definitions[$col])) |
| 1470 | 1470 | { |
| 1471 | - 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>"); |
|
| 1471 | + 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>"); |
|
| 1472 | 1472 | } |
| 1473 | 1473 | } |
| 1474 | 1474 | $column_type = is_array($column_definitions) ? @$column_definitions[$col]['type'] : False; |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | $maxlength = null; |
| 1478 | 1478 | if ($truncate_varchar) |
| 1479 | 1479 | { |
| 1480 | - $maxlength = in_array($column_definitions[$col]['type'], array('varchar','ascii')) ? $column_definitions[$col]['precision'] : null; |
|
| 1480 | + $maxlength = in_array($column_definitions[$col]['type'], array('varchar', 'ascii')) ? $column_definitions[$col]['precision'] : null; |
|
| 1481 | 1481 | } |
| 1482 | 1482 | // dont use IN ( ), if there's only one value, it's slower for MySQL |
| 1483 | 1483 | if (is_array($data) && count($data) == 1) |
@@ -1487,39 +1487,38 @@ discard block |
||
| 1487 | 1487 | if (is_array($data)) |
| 1488 | 1488 | { |
| 1489 | 1489 | $or_null = ''; |
| 1490 | - foreach($data as $k => $v) |
|
| 1490 | + foreach ($data as $k => $v) |
|
| 1491 | 1491 | { |
| 1492 | - if (!$not_null && $use_key===True && is_null($v)) |
|
| 1492 | + if (!$not_null && $use_key === True && is_null($v)) |
|
| 1493 | 1493 | { |
| 1494 | 1494 | $or_null = $this->name_quote($key).' IS NULL)'; |
| 1495 | 1495 | unset($data[$k]); |
| 1496 | 1496 | continue; |
| 1497 | 1497 | } |
| 1498 | - $data[$k] = $this->quote($v,$column_type,$not_null,$maxlength); |
|
| 1498 | + $data[$k] = $this->quote($v, $column_type, $not_null, $maxlength); |
|
| 1499 | 1499 | } |
| 1500 | - $values[] = ($or_null?'(':'').(!count($data) ? |
|
| 1500 | + $values[] = ($or_null ? '(' : '').(!count($data) ? |
|
| 1501 | 1501 | // empty array on insert/update, store as NULL, or if not allowed whatever value NULL is casted to |
| 1502 | - $this->quote(null, $column_type, $not_null) : |
|
| 1503 | - ($use_key===True ? $this->name_quote($key).' IN ' : '') . |
|
| 1504 | - '('.implode(',',$data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
| 1502 | + $this->quote(null, $column_type, $not_null) : ($use_key === True ? $this->name_quote($key).' IN ' : ''). |
|
| 1503 | + '('.implode(',', $data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
| 1505 | 1504 | } |
| 1506 | - elseif (is_int($key) && $use_key===True) |
|
| 1505 | + elseif (is_int($key) && $use_key === True) |
|
| 1507 | 1506 | { |
| 1508 | - if (empty($data)) continue; // would give SQL error |
|
| 1507 | + if (empty($data)) continue; // would give SQL error |
|
| 1509 | 1508 | $values[] = $data; |
| 1510 | 1509 | } |
| 1511 | 1510 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
| 1512 | 1511 | { |
| 1513 | - $values[] = $this->name_quote($key) .' IS NULL'; |
|
| 1512 | + $values[] = $this->name_quote($key).' IS NULL'; |
|
| 1514 | 1513 | } |
| 1515 | 1514 | else |
| 1516 | 1515 | { |
| 1517 | - $values[] = ($use_key===True ? $this->name_quote($key) . '=' : '') . $this->quote($data,$column_type,$not_null,$maxlength); |
|
| 1516 | + $values[] = ($use_key === True ? $this->name_quote($key).'=' : '').$this->quote($data, $column_type, $not_null, $maxlength); |
|
| 1518 | 1517 | } |
| 1519 | 1518 | } |
| 1520 | 1519 | } |
| 1521 | - return ($use_key==='VALUES' ? '('.implode(',',$keys).') VALUES (' : ''). |
|
| 1522 | - implode($glue,$values) . ($use_key==='VALUES' ? ')' : ''); |
|
| 1520 | + return ($use_key === 'VALUES' ? '('.implode(',', $keys).') VALUES (' : ''). |
|
| 1521 | + implode($glue, $values).($use_key === 'VALUES' ? ')' : ''); |
|
| 1523 | 1522 | } |
| 1524 | 1523 | |
| 1525 | 1524 | /** |
@@ -1531,9 +1530,9 @@ discard block |
||
| 1531 | 1530 | * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
| 1532 | 1531 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
| 1533 | 1532 | */ |
| 1534 | - function set_column_definitions($column_definitions=False) |
|
| 1533 | + function set_column_definitions($column_definitions = False) |
|
| 1535 | 1534 | { |
| 1536 | - $this->column_definitions=$column_definitions; |
|
| 1535 | + $this->column_definitions = $column_definitions; |
|
| 1537 | 1536 | } |
| 1538 | 1537 | |
| 1539 | 1538 | /** |
@@ -1546,7 +1545,7 @@ discard block |
||
| 1546 | 1545 | * |
| 1547 | 1546 | * @var string |
| 1548 | 1547 | */ |
| 1549 | - private $app=self::API_APPNAME; |
|
| 1548 | + private $app = self::API_APPNAME; |
|
| 1550 | 1549 | |
| 1551 | 1550 | /** |
| 1552 | 1551 | * Sets the application in which the db-class looks for table-defintions |
@@ -1581,7 +1580,7 @@ discard block |
||
| 1581 | 1580 | * @param bool|string $table if set return only defintions of that table, else return all defintions |
| 1582 | 1581 | * @return mixed array with table-defintions or False if file not found |
| 1583 | 1582 | */ |
| 1584 | - function get_table_definitions($app=False,$table=False) |
|
| 1583 | + function get_table_definitions($app = False, $table = False) |
|
| 1585 | 1584 | { |
| 1586 | 1585 | // ease the transition to api |
| 1587 | 1586 | if ($app === 'phpgwapi') $app = 'api'; |
@@ -1589,7 +1588,7 @@ discard block |
||
| 1589 | 1588 | static $all_app_data = array(); |
| 1590 | 1589 | if ($app === true && $table) |
| 1591 | 1590 | { |
| 1592 | - foreach($all_app_data as $app => &$app_data) |
|
| 1591 | + foreach ($all_app_data as $app => &$app_data) |
|
| 1593 | 1592 | { |
| 1594 | 1593 | if (isset($app_data[$table])) |
| 1595 | 1594 | { |
@@ -1597,13 +1596,13 @@ discard block |
||
| 1597 | 1596 | } |
| 1598 | 1597 | } |
| 1599 | 1598 | // $table not found in loaded apps, check not yet loaded ones |
| 1600 | - foreach(scandir(EGW_INCLUDE_ROOT) as $app) |
|
| 1599 | + foreach (scandir(EGW_INCLUDE_ROOT) as $app) |
|
| 1601 | 1600 | { |
| 1602 | 1601 | if ($app[0] == '.' || !is_dir(EGW_INCLUDE_ROOT.'/'.$app) || isset($all_app_data[$app])) |
| 1603 | 1602 | { |
| 1604 | 1603 | continue; |
| 1605 | 1604 | } |
| 1606 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
| 1605 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
| 1607 | 1606 | if (!@file_exists($tables_current)) |
| 1608 | 1607 | { |
| 1609 | 1608 | $all_app_data[$app] = False; |
@@ -1612,7 +1611,7 @@ discard block |
||
| 1612 | 1611 | { |
| 1613 | 1612 | $phpgw_baseline = null; |
| 1614 | 1613 | include($tables_current); |
| 1615 | - $all_app_data[$app] =& $phpgw_baseline; |
|
| 1614 | + $all_app_data[$app] = & $phpgw_baseline; |
|
| 1616 | 1615 | unset($phpgw_baseline); |
| 1617 | 1616 | |
| 1618 | 1617 | if (isset($all_app_data[$app][$table])) |
@@ -1627,17 +1626,17 @@ discard block |
||
| 1627 | 1626 | { |
| 1628 | 1627 | $app = $this->app ? $this->app : $GLOBALS['egw_info']['flags']['currentapp']; |
| 1629 | 1628 | } |
| 1630 | - $app_data =& $all_app_data[$app]; |
|
| 1629 | + $app_data = & $all_app_data[$app]; |
|
| 1631 | 1630 | |
| 1632 | 1631 | if (!isset($app_data)) |
| 1633 | 1632 | { |
| 1634 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
| 1633 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
| 1635 | 1634 | if (!@file_exists($tables_current)) |
| 1636 | 1635 | { |
| 1637 | 1636 | return $app_data = False; |
| 1638 | 1637 | } |
| 1639 | 1638 | include($tables_current); |
| 1640 | - $app_data =& $phpgw_baseline; |
|
| 1639 | + $app_data = & $phpgw_baseline; |
|
| 1641 | 1640 | unset($phpgw_baseline); |
| 1642 | 1641 | } |
| 1643 | 1642 | if ($table && (!$app_data || !isset($app_data[$table]))) |
@@ -1660,14 +1659,14 @@ discard block |
||
| 1660 | 1659 | * @param string $attribute='comment' what field to return, NULL for array with all fields, default 'comment' to return the comment |
| 1661 | 1660 | * @return string|array NULL if table or column or attribute not found |
| 1662 | 1661 | */ |
| 1663 | - /* static */ function get_column_attribute($column,$table,$app=null,$attribute='comment') |
|
| 1662 | + /* static */ function get_column_attribute($column, $table, $app = null, $attribute = 'comment') |
|
| 1664 | 1663 | { |
| 1665 | - static $cached_columns=null,$cached_table=null; // some caching |
|
| 1664 | + static $cached_columns = null, $cached_table = null; // some caching |
|
| 1666 | 1665 | |
| 1667 | 1666 | if ($cached_table !== $table || is_null($cached_columns)) |
| 1668 | 1667 | { |
| 1669 | 1668 | $db = isset($this) ? $this : $GLOBALS['egw']->db; |
| 1670 | - $table_def = $db->get_table_definitions($app,$table); |
|
| 1669 | + $table_def = $db->get_table_definitions($app, $table); |
|
| 1671 | 1670 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
| 1672 | 1671 | } |
| 1673 | 1672 | if ($cached_columns === false) return null; |
@@ -1691,38 +1690,38 @@ discard block |
||
| 1691 | 1690 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
| 1692 | 1691 | * @return ADORecordSet or false, if the query fails |
| 1693 | 1692 | */ |
| 1694 | - function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
| 1693 | + function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
| 1695 | 1694 | { |
| 1696 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
| 1695 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app')</p>\n"; |
|
| 1697 | 1696 | |
| 1698 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1697 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
| 1699 | 1698 | |
| 1700 | 1699 | $sql_append = ''; |
| 1701 | 1700 | $cmd = 'INSERT'; |
| 1702 | 1701 | if (is_array($where) && count($where)) |
| 1703 | 1702 | { |
| 1704 | - switch($this->Type) |
|
| 1703 | + switch ($this->Type) |
|
| 1705 | 1704 | { |
| 1706 | 1705 | case 'sapdb': case 'maxdb': |
| 1707 | 1706 | $sql_append = ' UPDATE DUPLICATES'; |
| 1708 | 1707 | break; |
| 1709 | 1708 | case 'mysql': |
| 1710 | 1709 | // use replace if primary keys are included |
| 1711 | - if (count(array_intersect(array_keys($where),(array)$table_def['pk'])) == count($table_def['pk'])) |
|
| 1710 | + if (count(array_intersect(array_keys($where), (array)$table_def['pk'])) == count($table_def['pk'])) |
|
| 1712 | 1711 | { |
| 1713 | 1712 | $cmd = 'REPLACE'; |
| 1714 | 1713 | break; |
| 1715 | 1714 | } |
| 1716 | 1715 | // fall through !!! |
| 1717 | 1716 | default: |
| 1718 | - if ($this->select($table,'count(*)',$where,$line,$file)->fetchColumn()) |
|
| 1717 | + if ($this->select($table, 'count(*)', $where, $line, $file)->fetchColumn()) |
|
| 1719 | 1718 | { |
| 1720 | - return !!$this->update($table,$data,$where,$line,$file,$app,$use_prepared_statement,$table_def); |
|
| 1719 | + return !!$this->update($table, $data, $where, $line, $file, $app, $use_prepared_statement, $table_def); |
|
| 1721 | 1720 | } |
| 1722 | 1721 | break; |
| 1723 | 1722 | } |
| 1724 | 1723 | // the checked values need to be inserted too, value in data has precedence, also cant insert sql strings (numerical id) |
| 1725 | - foreach($where as $column => $value) |
|
| 1724 | + foreach ($where as $column => $value) |
|
| 1726 | 1725 | { |
| 1727 | 1726 | if (!is_numeric($column) && !isset($data[$column]) && |
| 1728 | 1727 | // skip auto-id of 0 or NULL, as PostgreSQL does NOT create an auto-id, if they are given |
@@ -1742,24 +1741,24 @@ discard block |
||
| 1742 | 1741 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
| 1743 | 1742 | |
| 1744 | 1743 | $sql = "$cmd INTO $table "; |
| 1745 | - foreach($data as $k => $d) |
|
| 1744 | + foreach ($data as $k => $d) |
|
| 1746 | 1745 | { |
| 1747 | 1746 | if (!$k) |
| 1748 | 1747 | { |
| 1749 | - $sql .= $this->column_data_implode(',',$d,'VALUES',true,$table_def['fd']); |
|
| 1748 | + $sql .= $this->column_data_implode(',', $d, 'VALUES', true, $table_def['fd']); |
|
| 1750 | 1749 | } |
| 1751 | 1750 | else |
| 1752 | 1751 | { |
| 1753 | - $sql .= ",\n(".$this->column_data_implode(',',$d,false,true,$table_def['fd']).')'; |
|
| 1752 | + $sql .= ",\n(".$this->column_data_implode(',', $d, false, true, $table_def['fd']).')'; |
|
| 1754 | 1753 | } |
| 1755 | 1754 | } |
| 1756 | 1755 | $sql .= $sql_append; |
| 1757 | 1756 | } |
| 1758 | 1757 | elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
| 1759 | 1758 | { |
| 1760 | - $this->Link_ID->Param(false); // reset param-counter |
|
| 1759 | + $this->Link_ID->Param(false); // reset param-counter |
|
| 1761 | 1760 | $cols = array_keys($data); |
| 1762 | - foreach($cols as $k => $col) |
|
| 1761 | + foreach ($cols as $k => $col) |
|
| 1763 | 1762 | { |
| 1764 | 1763 | if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
| 1765 | 1764 | { |
@@ -1768,7 +1767,7 @@ discard block |
||
| 1768 | 1767 | } |
| 1769 | 1768 | $params[] = $this->Link_ID->Param($col); |
| 1770 | 1769 | } |
| 1771 | - $sql = "$cmd INTO $table (".implode(',',$cols).') VALUES ('.implode(',',$params).')'.$sql_append; |
|
| 1770 | + $sql = "$cmd INTO $table (".implode(',', $cols).') VALUES ('.implode(',', $params).')'.$sql_append; |
|
| 1772 | 1771 | // check if we already prepared that statement |
| 1773 | 1772 | if (!isset($this->prepared_sql[$sql])) |
| 1774 | 1773 | { |
@@ -1779,10 +1778,10 @@ discard block |
||
| 1779 | 1778 | } |
| 1780 | 1779 | else |
| 1781 | 1780 | { |
| 1782 | - $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
|
| 1781 | + $sql = "$cmd INTO $table ".$this->column_data_implode(',', $data, 'VALUES', true, $table_def['fd']).$sql_append; |
|
| 1783 | 1782 | } |
| 1784 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
| 1785 | - return $this->query($sql,$line,$file,0,-1,$inputarr); |
|
| 1783 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
| 1784 | + return $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
| 1786 | 1785 | } |
| 1787 | 1786 | |
| 1788 | 1787 | /** |
@@ -1800,10 +1799,10 @@ discard block |
||
| 1800 | 1799 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
| 1801 | 1800 | * @return ADORecordSet or false, if the query fails |
| 1802 | 1801 | */ |
| 1803 | - function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
| 1802 | + function update($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
| 1804 | 1803 | { |
| 1805 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
| 1806 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1804 | + if ($this->Debug) echo "<p>db::update('$table',".print_r($data, true).','.print_r($where, true).",$line,$file,'$app')</p>\n"; |
|
| 1805 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
| 1807 | 1806 | |
| 1808 | 1807 | $blobs2update = array(); |
| 1809 | 1808 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1814,7 +1813,7 @@ discard block |
||
| 1814 | 1813 | case 'maxdb': |
| 1815 | 1814 | if ($use_prepared_statement) break; |
| 1816 | 1815 | // check if data contains any LONG columns |
| 1817 | - foreach($data as $col => $val) |
|
| 1816 | + foreach ($data as $col => $val) |
|
| 1818 | 1817 | { |
| 1819 | 1818 | switch ($table_def['fd'][$col]['type']) |
| 1820 | 1819 | { |
@@ -1828,7 +1827,7 @@ discard block |
||
| 1828 | 1827 | } |
| 1829 | 1828 | break; |
| 1830 | 1829 | } |
| 1831 | - $where_str = $this->column_data_implode(' AND ',$where,True,true,$table_def['fd']); |
|
| 1830 | + $where_str = $this->column_data_implode(' AND ', $where, True, true, $table_def['fd']); |
|
| 1832 | 1831 | |
| 1833 | 1832 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
| 1834 | 1833 | { |
@@ -1839,13 +1838,13 @@ discard block |
||
| 1839 | 1838 | $inputarr = false; |
| 1840 | 1839 | if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
| 1841 | 1840 | { |
| 1842 | - $this->Link_ID->Param(false); // reset param-counter |
|
| 1843 | - foreach($data as $col => $val) |
|
| 1841 | + $this->Link_ID->Param(false); // reset param-counter |
|
| 1842 | + foreach ($data as $col => $val) |
|
| 1844 | 1843 | { |
| 1845 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
| 1844 | + if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
| 1846 | 1845 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
| 1847 | 1846 | } |
| 1848 | - $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
| 1847 | + $sql = "UPDATE $table SET ".implode(',', $params).' WHERE '.$where_str; |
|
| 1849 | 1848 | // check if we already prepared that statement |
| 1850 | 1849 | if (!isset($this->prepared_sql[$sql])) |
| 1851 | 1850 | { |
@@ -1857,19 +1856,19 @@ discard block |
||
| 1857 | 1856 | else |
| 1858 | 1857 | { |
| 1859 | 1858 | $sql = "UPDATE $table SET ". |
| 1860 | - $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
|
| 1859 | + $this->column_data_implode(',', $data, True, true, $table_def['fd']).' WHERE '.$where_str; |
|
| 1861 | 1860 | } |
| 1862 | - $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
|
| 1861 | + $ret = $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
| 1863 | 1862 | if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
| 1864 | 1863 | } |
| 1865 | 1864 | // if we have any blobs to update, we do so now |
| 1866 | 1865 | if (($ret || !count($data)) && count($blobs2update)) |
| 1867 | 1866 | { |
| 1868 | - foreach($blobs2update as $col => $val) |
|
| 1867 | + foreach ($blobs2update as $col => $val) |
|
| 1869 | 1868 | { |
| 1870 | - $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
| 1869 | + $ret = $this->Link_ID->UpdateBlob($table, $col, $val, $where_str, $table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
| 1871 | 1870 | if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
| 1872 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
| 1871 | + if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)", $line, $file); |
|
| 1873 | 1872 | } |
| 1874 | 1873 | } |
| 1875 | 1874 | return $ret; |
@@ -1888,18 +1887,18 @@ discard block |
||
| 1888 | 1887 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
| 1889 | 1888 | * @return ADORecordSet or false, if the query fails |
| 1890 | 1889 | */ |
| 1891 | - function delete($table,$where,$line,$file,$app=False,$table_def=False) |
|
| 1890 | + function delete($table, $where, $line, $file, $app = False, $table_def = False) |
|
| 1892 | 1891 | { |
| 1893 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1892 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
| 1894 | 1893 | |
| 1895 | 1894 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
| 1896 | 1895 | { |
| 1897 | 1896 | $table = self::$tablealiases[$table]; |
| 1898 | 1897 | } |
| 1899 | 1898 | $sql = "DELETE FROM $table WHERE ". |
| 1900 | - $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
| 1899 | + $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
| 1901 | 1900 | |
| 1902 | - return $this->query($sql,$line,$file); |
|
| 1901 | + return $this->query($sql, $line, $file); |
|
| 1903 | 1902 | } |
| 1904 | 1903 | |
| 1905 | 1904 | /** |
@@ -1922,12 +1921,12 @@ discard block |
||
| 1922 | 1921 | */ |
| 1923 | 1922 | function expression($table_def/*,$args, ...*/) |
| 1924 | 1923 | { |
| 1925 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
| 1924 | + if (!is_array($table_def)) $table_def = $this->get_table_definitions(true, $table_def); |
|
| 1926 | 1925 | $sql = ''; |
| 1927 | 1926 | $ignore_next = 0; |
| 1928 | - foreach(func_get_args() as $n => $arg) |
|
| 1927 | + foreach (func_get_args() as $n => $arg) |
|
| 1929 | 1928 | { |
| 1930 | - if ($n < 1) continue; // table-name |
|
| 1929 | + if ($n < 1) continue; // table-name |
|
| 1931 | 1930 | |
| 1932 | 1931 | if ($ignore_next) |
| 1933 | 1932 | { |
@@ -1936,7 +1935,7 @@ discard block |
||
| 1936 | 1935 | } |
| 1937 | 1936 | if (is_null($arg)) $arg = False; |
| 1938 | 1937 | |
| 1939 | - switch(gettype($arg)) |
|
| 1938 | + switch (gettype($arg)) |
|
| 1940 | 1939 | { |
| 1941 | 1940 | case 'string': |
| 1942 | 1941 | $sql .= $arg; |
@@ -1945,7 +1944,7 @@ discard block |
||
| 1945 | 1944 | $ignore_next += !$arg ? 2 : 0; |
| 1946 | 1945 | break; |
| 1947 | 1946 | case 'array': |
| 1948 | - $sql .= $this->column_data_implode(' AND ',$arg,True,False,$table_def['fd']); |
|
| 1947 | + $sql .= $this->column_data_implode(' AND ', $arg, True, False, $table_def['fd']); |
|
| 1949 | 1948 | break; |
| 1950 | 1949 | } |
| 1951 | 1950 | } |
@@ -1972,18 +1971,18 @@ discard block |
||
| 1972 | 1971 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
| 1973 | 1972 | * @return ADORecordSet or false, if the query fails |
| 1974 | 1973 | */ |
| 1975 | - function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
|
| 1974 | + function select($table, $cols, $where, $line, $file, $offset = False, $append = '', $app = False, $num_rows = 0, $join = '', $table_def = False, $fetchmode = self::FETCH_ASSOC) |
|
| 1976 | 1975 | { |
| 1977 | - if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
| 1976 | + 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"; |
|
| 1978 | 1977 | |
| 1979 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1978 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
| 1980 | 1979 | if (is_array($cols)) |
| 1981 | 1980 | { |
| 1982 | - $cols = implode(',',$cols); |
|
| 1981 | + $cols = implode(',', $cols); |
|
| 1983 | 1982 | } |
| 1984 | 1983 | if (is_array($where)) |
| 1985 | 1984 | { |
| 1986 | - $where = $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
| 1985 | + $where = $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
| 1987 | 1986 | } |
| 1988 | 1987 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
| 1989 | 1988 | { |
@@ -1992,7 +1991,7 @@ discard block |
||
| 1992 | 1991 | $sql = "SELECT $cols FROM $table $join"; |
| 1993 | 1992 | |
| 1994 | 1993 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
| 1995 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
| 1994 | + if ($where) $sql .= (strpos($join, "WHERE") !== false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
| 1996 | 1995 | |
| 1997 | 1996 | if ($append) $sql .= ' '.$append; |
| 1998 | 1997 | |
@@ -2002,7 +2001,7 @@ discard block |
||
| 2002 | 2001 | { |
| 2003 | 2002 | return $sql; |
| 2004 | 2003 | } |
| 2005 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
| 2004 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
| 2006 | 2005 | } |
| 2007 | 2006 | |
| 2008 | 2007 | /** |
@@ -2020,34 +2019,34 @@ discard block |
||
| 2020 | 2019 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
| 2021 | 2020 | * @return ADORecordSet or false, if the query fails |
| 2022 | 2021 | */ |
| 2023 | - function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
|
| 2022 | + function union($selects, $line, $file, $order_by = '', $offset = false, $num_rows = 0, $fetchmode = self::FETCH_ASSOC) |
|
| 2024 | 2023 | { |
| 2025 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
| 2024 | + if ($this->Debug) echo "<p>db::union(".print_r($selects, True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
| 2026 | 2025 | |
| 2027 | 2026 | $union = array(); |
| 2028 | - foreach($selects as $select) |
|
| 2027 | + foreach ($selects as $select) |
|
| 2029 | 2028 | { |
| 2030 | - $union[] = call_user_func_array(array($this,'select'),array( |
|
| 2029 | + $union[] = call_user_func_array(array($this, 'select'), array( |
|
| 2031 | 2030 | $select['table'], |
| 2032 | 2031 | $select['cols'], |
| 2033 | 2032 | $select['where'], |
| 2034 | - false, // line |
|
| 2035 | - false, // file |
|
| 2036 | - false, // offset |
|
| 2033 | + false, // line |
|
| 2034 | + false, // file |
|
| 2035 | + false, // offset |
|
| 2037 | 2036 | $select['append'], |
| 2038 | 2037 | $select['app'], |
| 2039 | - 0, // num_rows, |
|
| 2038 | + 0, // num_rows, |
|
| 2040 | 2039 | $select['join'], |
| 2041 | 2040 | $select['table_def'], |
| 2042 | 2041 | )); |
| 2043 | 2042 | } |
| 2044 | - $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
|
| 2043 | + $sql = count($union) > 1 ? '('.implode(")\nUNION\n(", $union).')' : 'SELECT DISTINCT'.substr($union[0], 6); |
|
| 2045 | 2044 | |
| 2046 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
| 2045 | + if ($order_by) $sql .= (!stristr($order_by, 'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
| 2047 | 2046 | |
| 2048 | 2047 | if ($this->Debug) echo "<p>sql='$sql'</p>"; |
| 2049 | 2048 | |
| 2050 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
| 2049 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
| 2051 | 2050 | } |
| 2052 | 2051 | |
| 2053 | 2052 | /** |
@@ -2057,15 +2056,15 @@ discard block |
||
| 2057 | 2056 | * @param string|array $strip |
| 2058 | 2057 | * @return array |
| 2059 | 2058 | */ |
| 2060 | - static function strip_array_keys($arr,$strip) |
|
| 2059 | + static function strip_array_keys($arr, $strip) |
|
| 2061 | 2060 | { |
| 2062 | 2061 | $keys = array_keys($arr); |
| 2063 | 2062 | |
| 2064 | 2063 | return array_walk($keys, function(&$v, $k, $strip) |
| 2065 | 2064 | { |
| 2066 | - unset($k); // not used, but required by function signature |
|
| 2065 | + unset($k); // not used, but required by function signature |
|
| 2067 | 2066 | $v = str_replace($strip, '', $v); |
| 2068 | 2067 | }, $strip) ? |
| 2069 | - array_combine($keys,$arr) : $arr; |
|
| 2068 | + array_combine($keys, $arr) : $arr; |
|
| 2070 | 2069 | } |
| 2071 | 2070 | } |
@@ -383,7 +383,10 @@ discard block |
||
| 383 | 383 | if ($state['wsrep_local_state_comment'] == 'Synced' || |
| 384 | 384 | // if we have only 2 nodes (2. one starting), we can only use the donor |
| 385 | 385 | $state['wsrep_local_state_comment'] == 'Donor/Desynced' && |
| 386 | - $state['wsrep_cluster_size'] == 2) return; |
|
| 386 | + $state['wsrep_cluster_size'] == 2) |
|
| 387 | + { |
|
| 388 | + return; |
|
| 389 | + } |
|
| 387 | 390 | |
| 388 | 391 | throw new Db\Exception\Connection('Node is NOT Synced! '.array2string($state)); |
| 389 | 392 | } |
@@ -402,7 +405,10 @@ discard block |
||
| 402 | 405 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
| 403 | 406 | $num_hosts = count($hosts); |
| 404 | 407 | $n =& Cache::getSession(__CLASS__, $this->Host); |
| 405 | - if (!isset($n)) $n = 0; |
|
| 408 | + if (!isset($n)) |
|
| 409 | + { |
|
| 410 | + $n = 0; |
|
| 411 | + } |
|
| 406 | 412 | |
| 407 | 413 | if ($next && ++$n >= $num_hosts+2) |
| 408 | 414 | { |
@@ -432,7 +438,10 @@ discard block |
||
| 432 | 438 | foreach(array('Database','User','Password','Port','Type') as $name) |
| 433 | 439 | { |
| 434 | 440 | $$name = $this->$name; |
| 435 | - if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
|
| 441 | + if (${$name}[0] == '@' && $name != 'Password') |
|
| 442 | + { |
|
| 443 | + $$name = getenv(substr($$name, 1)); |
|
| 444 | + } |
|
| 436 | 445 | } |
| 437 | 446 | $this->setupType = $php_extension = $Type; |
| 438 | 447 | |
@@ -451,7 +460,10 @@ discard block |
||
| 451 | 460 | $Type = 'mssql'; |
| 452 | 461 | // fall through |
| 453 | 462 | case 'mssql': |
| 454 | - if ($Port) $Host .= ','.$Port; |
|
| 463 | + if ($Port) |
|
| 464 | + { |
|
| 465 | + $Host .= ','.$Port; |
|
| 466 | + } |
|
| 455 | 467 | break; |
| 456 | 468 | |
| 457 | 469 | case 'odbc_oracle': |
@@ -486,7 +498,10 @@ discard block |
||
| 486 | 498 | $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
| 487 | 499 | // fall through |
| 488 | 500 | default: |
| 489 | - if ($Port) $Host .= ':'.$Port; |
|
| 501 | + if ($Port) |
|
| 502 | + { |
|
| 503 | + $Host .= ':'.$Port; |
|
| 504 | + } |
|
| 490 | 505 | break; |
| 491 | 506 | } |
| 492 | 507 | if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
@@ -501,10 +516,13 @@ discard block |
||
| 501 | 516 | { |
| 502 | 517 | throw new Db\Exception\Connection("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!"); |
| 503 | 518 | } |
| 504 | - if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
|
| 519 | + if (!isset($GLOBALS['egw']->ADOdb)) |
|
| 520 | + { |
|
| 521 | + // use the global object to store the connection |
|
| 505 | 522 | { |
| 506 | 523 | $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
| 507 | 524 | } |
| 525 | + } |
|
| 508 | 526 | else |
| 509 | 527 | { |
| 510 | 528 | $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
@@ -600,7 +618,11 @@ discard block |
||
| 600 | 618 | */ |
| 601 | 619 | function __sleep() |
| 602 | 620 | { |
| 603 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
| 621 | + if (!empty($this->setupType)) |
|
| 622 | + { |
|
| 623 | + $this->Type = $this->setupType; |
|
| 624 | + } |
|
| 625 | + // restore Type eg. to mysqli |
|
| 604 | 626 | |
| 605 | 627 | $vars = get_object_vars($this); |
| 606 | 628 | unset($vars['Link_ID']); |
@@ -663,7 +685,10 @@ discard block |
||
| 663 | 685 | unset($this->Link_ID); |
| 664 | 686 | $this->Link_ID = 0; |
| 665 | 687 | |
| 666 | - if (!empty($this->setupType)) $this->Type = $this->setupType; |
|
| 688 | + if (!empty($this->setupType)) |
|
| 689 | + { |
|
| 690 | + $this->Type = $this->setupType; |
|
| 691 | + } |
|
| 667 | 692 | } |
| 668 | 693 | |
| 669 | 694 | /** |
@@ -772,16 +797,22 @@ discard block |
||
| 772 | 797 | } |
| 773 | 798 | if (!$rs) |
| 774 | 799 | { |
| 775 | - if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) // Server has gone away |
|
| 800 | + if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) |
|
| 801 | + { |
|
| 802 | + // Server has gone away |
|
| 776 | 803 | { |
| 777 | 804 | $this->disconnect(); |
| 805 | + } |
|
| 778 | 806 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
| 779 | 807 | } |
| 780 | 808 | throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
| 781 | 809 | "\n$this->Error ($this->Errno)". |
| 782 | 810 | ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
| 783 | 811 | } |
| 784 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
| 812 | + elseif(empty($rs->sql)) |
|
| 813 | + { |
|
| 814 | + $rs->sql = $Query_String; |
|
| 815 | + } |
|
| 785 | 816 | return $rs; |
| 786 | 817 | } |
| 787 | 818 | |
@@ -865,9 +896,12 @@ discard block |
||
| 865 | 896 | } |
| 866 | 897 | $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
| 867 | 898 | |
| 868 | - if ($id === False) // function not supported |
|
| 899 | + if ($id === False) |
|
| 900 | + { |
|
| 901 | + // function not supported |
|
| 869 | 902 | { |
| 870 | 903 | echo "<p>db::get_last_insert_id(table='$table',field='$field') not yet implemented for db-type '$this->Type' OR no insert operation before</p>\n"; |
| 904 | + } |
|
| 871 | 905 | echo '<p>'.function_backtrace()."</p>\n"; |
| 872 | 906 | return -1; |
| 873 | 907 | } |
@@ -881,7 +915,10 @@ discard block |
||
| 881 | 915 | */ |
| 882 | 916 | function affected_rows() |
| 883 | 917 | { |
| 884 | - if ($this->log_updates) return 0; |
|
| 918 | + if ($this->log_updates) |
|
| 919 | + { |
|
| 920 | + return 0; |
|
| 921 | + } |
|
| 885 | 922 | |
| 886 | 923 | if (!$this->Link_ID && !$this->connect()) |
| 887 | 924 | { |
@@ -915,9 +952,18 @@ discard block |
||
| 915 | 952 | { |
| 916 | 953 | // for backwards compatibilty (depreciated) |
| 917 | 954 | $flags = null; |
| 918 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
| 919 | - if($column->primary_key) $flags .= "primary_key "; |
|
| 920 | - if($column->binary) $flags .= "binary "; |
|
| 955 | + if($column->auto_increment) |
|
| 956 | + { |
|
| 957 | + $flags .= "auto_increment "; |
|
| 958 | + } |
|
| 959 | + if($column->primary_key) |
|
| 960 | + { |
|
| 961 | + $flags .= "primary_key "; |
|
| 962 | + } |
|
| 963 | + if($column->binary) |
|
| 964 | + { |
|
| 965 | + $flags .= "binary "; |
|
| 966 | + } |
|
| 921 | 967 | |
| 922 | 968 | $metadata[$i] = array( |
| 923 | 969 | 'table' => $table, |
@@ -954,7 +1000,10 @@ discard block |
||
| 954 | 1000 | */ |
| 955 | 1001 | function table_names($just_name=false) |
| 956 | 1002 | { |
| 957 | - if (!$this->Link_ID) $this->connect(); |
|
| 1003 | + if (!$this->Link_ID) |
|
| 1004 | + { |
|
| 1005 | + $this->connect(); |
|
| 1006 | + } |
|
| 958 | 1007 | if (!$this->Link_ID) |
| 959 | 1008 | { |
| 960 | 1009 | return False; |
@@ -1105,8 +1154,14 @@ discard block |
||
| 1105 | 1154 | { |
| 1106 | 1155 | case 'mysql': |
| 1107 | 1156 | $sql = 'GROUP_CONCAT('.$expr; |
| 1108 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
| 1109 | - if ($separator != ',') $sql .= ' SEPARATOR '.$this->quote($separator); |
|
| 1157 | + if ($order_by) |
|
| 1158 | + { |
|
| 1159 | + $sql .= ' ORDER BY '.$order_by; |
|
| 1160 | + } |
|
| 1161 | + if ($separator != ',') |
|
| 1162 | + { |
|
| 1163 | + $sql .= ' SEPARATOR '.$this->quote($separator); |
|
| 1164 | + } |
|
| 1110 | 1165 | $sql .= ')'; |
| 1111 | 1166 | break; |
| 1112 | 1167 | |
@@ -1116,7 +1171,10 @@ discard block |
||
| 1116 | 1171 | return false; |
| 1117 | 1172 | } |
| 1118 | 1173 | $sql = 'ARRAY_TO_STRING(ARRAY_AGG('.$expr; |
| 1119 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
| 1174 | + if ($order_by) |
|
| 1175 | + { |
|
| 1176 | + $sql .= ' ORDER BY '.$order_by; |
|
| 1177 | + } |
|
| 1120 | 1178 | $sql .= '), '.$this->quote($separator).')'; |
| 1121 | 1179 | break; |
| 1122 | 1180 | |
@@ -1339,12 +1397,18 @@ discard block |
||
| 1339 | 1397 | */ |
| 1340 | 1398 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
| 1341 | 1399 | { |
| 1342 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
| 1400 | + if ($this->Debug) |
|
| 1401 | + { |
|
| 1402 | + echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
| 1403 | + } |
|
| 1343 | 1404 | |
| 1344 | - if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
|
| 1405 | + if (!$not_null && is_null($value)) |
|
| 1406 | + { |
|
| 1407 | + // writing unset php-variables and those set to NULL now as SQL NULL |
|
| 1345 | 1408 | { |
| 1346 | 1409 | return 'NULL'; |
| 1347 | 1410 | } |
| 1411 | + } |
|
| 1348 | 1412 | switch($type) |
| 1349 | 1413 | { |
| 1350 | 1414 | case 'int': |
@@ -1359,10 +1423,13 @@ discard block |
||
| 1359 | 1423 | // There for we have to keep it as float by using round instead the int cast. |
| 1360 | 1424 | return is_float($value) ? round($value) : (int) $value; |
| 1361 | 1425 | case 'bool': |
| 1362 | - if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
|
| 1426 | + if ($this->Type == 'mysql') |
|
| 1427 | + { |
|
| 1428 | + // maybe it's not longer necessary with mysql5 |
|
| 1363 | 1429 | { |
| 1364 | 1430 | return $value ? 1 : 0; |
| 1365 | 1431 | } |
| 1432 | + } |
|
| 1366 | 1433 | return $value ? 'true' : 'false'; |
| 1367 | 1434 | case 'float': |
| 1368 | 1435 | case 'decimal': |
@@ -1410,7 +1477,10 @@ discard block |
||
| 1410 | 1477 | } |
| 1411 | 1478 | // casting boolean explicitly to string, as ADODB_postgres64::qstr() has an unwanted special handling |
| 1412 | 1479 | // for boolean types, causing it to return "true" or "false" and not a quoted string like "'1'"! |
| 1413 | - if (is_bool($value)) $value = (string)$value; |
|
| 1480 | + if (is_bool($value)) |
|
| 1481 | + { |
|
| 1482 | + $value = (string)$value; |
|
| 1483 | + } |
|
| 1414 | 1484 | |
| 1415 | 1485 | // need to cast to string, as ADOdb 5.20 would return NULL instead of '' for NULL, causing us to write that into NOT NULL columns |
| 1416 | 1486 | return $this->Link_ID->qstr((string)$value); |
@@ -1440,15 +1510,21 @@ discard block |
||
| 1440 | 1510 | */ |
| 1441 | 1511 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
| 1442 | 1512 | { |
| 1443 | - if (!is_array($array)) // this allows to give an SQL-string for delete or update |
|
| 1513 | + if (!is_array($array)) |
|
| 1514 | + { |
|
| 1515 | + // this allows to give an SQL-string for delete or update |
|
| 1444 | 1516 | { |
| 1445 | 1517 | return $array; |
| 1446 | 1518 | } |
| 1519 | + } |
|
| 1447 | 1520 | if (!$column_definitions) |
| 1448 | 1521 | { |
| 1449 | 1522 | $column_definitions = $this->column_definitions; |
| 1450 | 1523 | } |
| 1451 | - if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
| 1524 | + if ($this->Debug) |
|
| 1525 | + { |
|
| 1526 | + echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
| 1527 | + } |
|
| 1452 | 1528 | |
| 1453 | 1529 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
| 1454 | 1530 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
@@ -1465,7 +1541,10 @@ discard block |
||
| 1465 | 1541 | // fix "table.column" expressions, to not trigger exception, if column alone would work |
| 1466 | 1542 | if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key])) |
| 1467 | 1543 | { |
| 1468 | - if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
|
| 1544 | + if (strpos($key, '.') !== false) |
|
| 1545 | + { |
|
| 1546 | + list(, $col) = explode('.', $key); |
|
| 1547 | + } |
|
| 1469 | 1548 | if (!isset($column_definitions[$col])) |
| 1470 | 1549 | { |
| 1471 | 1550 | throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>"); |
@@ -1505,7 +1584,11 @@ discard block |
||
| 1505 | 1584 | } |
| 1506 | 1585 | elseif (is_int($key) && $use_key===True) |
| 1507 | 1586 | { |
| 1508 | - if (empty($data)) continue; // would give SQL error |
|
| 1587 | + if (empty($data)) |
|
| 1588 | + { |
|
| 1589 | + continue; |
|
| 1590 | + } |
|
| 1591 | + // would give SQL error |
|
| 1509 | 1592 | $values[] = $data; |
| 1510 | 1593 | } |
| 1511 | 1594 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
@@ -1559,7 +1642,10 @@ discard block |
||
| 1559 | 1642 | function set_app($app) |
| 1560 | 1643 | { |
| 1561 | 1644 | // ease the transition to api |
| 1562 | - if ($app == 'phpgwapi') $app = 'api'; |
|
| 1645 | + if ($app == 'phpgwapi') |
|
| 1646 | + { |
|
| 1647 | + $app = 'api'; |
|
| 1648 | + } |
|
| 1563 | 1649 | |
| 1564 | 1650 | if ($this === $GLOBALS['egw']->db && $app != self::API_APPNAME) |
| 1565 | 1651 | { |
@@ -1584,7 +1670,10 @@ discard block |
||
| 1584 | 1670 | function get_table_definitions($app=False,$table=False) |
| 1585 | 1671 | { |
| 1586 | 1672 | // ease the transition to api |
| 1587 | - if ($app === 'phpgwapi') $app = 'api'; |
|
| 1673 | + if ($app === 'phpgwapi') |
|
| 1674 | + { |
|
| 1675 | + $app = 'api'; |
|
| 1676 | + } |
|
| 1588 | 1677 | |
| 1589 | 1678 | static $all_app_data = array(); |
| 1590 | 1679 | if ($app === true && $table) |
@@ -1642,10 +1731,16 @@ discard block |
||
| 1642 | 1731 | } |
| 1643 | 1732 | if ($table && (!$app_data || !isset($app_data[$table]))) |
| 1644 | 1733 | { |
| 1645 | - if ($this->Debug) echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
| 1734 | + if ($this->Debug) |
|
| 1735 | + { |
|
| 1736 | + echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
| 1737 | + } |
|
| 1646 | 1738 | return False; |
| 1647 | 1739 | } |
| 1648 | - if ($this->Debug) echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
| 1740 | + if ($this->Debug) |
|
| 1741 | + { |
|
| 1742 | + echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
| 1743 | + } |
|
| 1649 | 1744 | return $table ? $app_data[$table] : $app_data; |
| 1650 | 1745 | } |
| 1651 | 1746 | |
@@ -1670,7 +1765,10 @@ discard block |
||
| 1670 | 1765 | $table_def = $db->get_table_definitions($app,$table); |
| 1671 | 1766 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
| 1672 | 1767 | } |
| 1673 | - if ($cached_columns === false) return null; |
|
| 1768 | + if ($cached_columns === false) |
|
| 1769 | + { |
|
| 1770 | + return null; |
|
| 1771 | + } |
|
| 1674 | 1772 | |
| 1675 | 1773 | return is_null($attribute) ? $cached_columns[$column] : $cached_columns[$column][$attribute]; |
| 1676 | 1774 | } |
@@ -1693,9 +1791,15 @@ discard block |
||
| 1693 | 1791 | */ |
| 1694 | 1792 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
| 1695 | 1793 | { |
| 1696 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
| 1794 | + if ($this->Debug) |
|
| 1795 | + { |
|
| 1796 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
| 1797 | + } |
|
| 1697 | 1798 | |
| 1698 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1799 | + if (!$table_def) |
|
| 1800 | + { |
|
| 1801 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 1802 | + } |
|
| 1699 | 1803 | |
| 1700 | 1804 | $sql_append = ''; |
| 1701 | 1805 | $cmd = 'INSERT'; |
@@ -1737,9 +1841,12 @@ discard block |
||
| 1737 | 1841 | $table = self::$tablealiases[$table]; |
| 1738 | 1842 | } |
| 1739 | 1843 | $inputarr = false; |
| 1740 | - if (isset($data[0]) && is_array($data[0])) // multiple data rows |
|
| 1844 | + if (isset($data[0]) && is_array($data[0])) |
|
| 1845 | + { |
|
| 1846 | + // multiple data rows |
|
| 1741 | 1847 | { |
| 1742 | 1848 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
| 1849 | + } |
|
| 1743 | 1850 | |
| 1744 | 1851 | $sql = "$cmd INTO $table "; |
| 1745 | 1852 | foreach($data as $k => $d) |
@@ -1755,15 +1862,22 @@ discard block |
||
| 1755 | 1862 | } |
| 1756 | 1863 | $sql .= $sql_append; |
| 1757 | 1864 | } |
| 1758 | - elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
| 1865 | + elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
| 1759 | 1866 | { |
| 1760 | - $this->Link_ID->Param(false); // reset param-counter |
|
| 1867 | + // eg. MaxDB |
|
| 1868 | + { |
|
| 1869 | + $this->Link_ID->Param(false); |
|
| 1870 | + } |
|
| 1871 | + // reset param-counter |
|
| 1761 | 1872 | $cols = array_keys($data); |
| 1762 | 1873 | foreach($cols as $k => $col) |
| 1763 | 1874 | { |
| 1764 | - if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
|
| 1875 | + if (!isset($table_def['fd'][$col])) |
|
| 1876 | + { |
|
| 1877 | + // ignore columns not in this table |
|
| 1765 | 1878 | { |
| 1766 | 1879 | unset($cols[$k]); |
| 1880 | + } |
|
| 1767 | 1881 | continue; |
| 1768 | 1882 | } |
| 1769 | 1883 | $params[] = $this->Link_ID->Param($col); |
@@ -1781,7 +1895,10 @@ discard block |
||
| 1781 | 1895 | { |
| 1782 | 1896 | $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
| 1783 | 1897 | } |
| 1784 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
| 1898 | + if ($this->Debug) |
|
| 1899 | + { |
|
| 1900 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
| 1901 | + } |
|
| 1785 | 1902 | return $this->query($sql,$line,$file,0,-1,$inputarr); |
| 1786 | 1903 | } |
| 1787 | 1904 | |
@@ -1802,8 +1919,14 @@ discard block |
||
| 1802 | 1919 | */ |
| 1803 | 1920 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
| 1804 | 1921 | { |
| 1805 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
| 1806 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1922 | + if ($this->Debug) |
|
| 1923 | + { |
|
| 1924 | + echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
| 1925 | + } |
|
| 1926 | + if (!$table_def) |
|
| 1927 | + { |
|
| 1928 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 1929 | + } |
|
| 1807 | 1930 | |
| 1808 | 1931 | $blobs2update = array(); |
| 1809 | 1932 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1812,7 +1935,10 @@ discard block |
||
| 1812 | 1935 | { |
| 1813 | 1936 | case 'sapdb': |
| 1814 | 1937 | case 'maxdb': |
| 1815 | - if ($use_prepared_statement) break; |
|
| 1938 | + if ($use_prepared_statement) |
|
| 1939 | + { |
|
| 1940 | + break; |
|
| 1941 | + } |
|
| 1816 | 1942 | // check if data contains any LONG columns |
| 1817 | 1943 | foreach($data as $col => $val) |
| 1818 | 1944 | { |
@@ -1837,12 +1963,20 @@ discard block |
||
| 1837 | 1963 | if (count($data)) |
| 1838 | 1964 | { |
| 1839 | 1965 | $inputarr = false; |
| 1840 | - if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
| 1966 | + if ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
| 1967 | + { |
|
| 1968 | + // eg. MaxDB |
|
| 1841 | 1969 | { |
| 1842 | - $this->Link_ID->Param(false); // reset param-counter |
|
| 1970 | + $this->Link_ID->Param(false); |
|
| 1971 | + } |
|
| 1972 | + // reset param-counter |
|
| 1843 | 1973 | foreach($data as $col => $val) |
| 1844 | 1974 | { |
| 1845 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
| 1975 | + if (!isset($table_def['fd'][$col])) |
|
| 1976 | + { |
|
| 1977 | + continue; |
|
| 1978 | + } |
|
| 1979 | + // ignore columns not in this table |
|
| 1846 | 1980 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
| 1847 | 1981 | } |
| 1848 | 1982 | $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
@@ -1860,7 +1994,10 @@ discard block |
||
| 1860 | 1994 | $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
| 1861 | 1995 | } |
| 1862 | 1996 | $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
| 1863 | - if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
| 1997 | + if ($this->Debug) |
|
| 1998 | + { |
|
| 1999 | + echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
| 2000 | + } |
|
| 1864 | 2001 | } |
| 1865 | 2002 | // if we have any blobs to update, we do so now |
| 1866 | 2003 | if (($ret || !count($data)) && count($blobs2update)) |
@@ -1868,8 +2005,14 @@ discard block |
||
| 1868 | 2005 | foreach($blobs2update as $col => $val) |
| 1869 | 2006 | { |
| 1870 | 2007 | $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
| 1871 | - if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
| 1872 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
| 2008 | + if ($this->Debug) |
|
| 2009 | + { |
|
| 2010 | + echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
| 2011 | + } |
|
| 2012 | + if (!$ret) |
|
| 2013 | + { |
|
| 2014 | + throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
| 2015 | + } |
|
| 1873 | 2016 | } |
| 1874 | 2017 | } |
| 1875 | 2018 | return $ret; |
@@ -1890,7 +2033,10 @@ discard block |
||
| 1890 | 2033 | */ |
| 1891 | 2034 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
| 1892 | 2035 | { |
| 1893 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 2036 | + if (!$table_def) |
|
| 2037 | + { |
|
| 2038 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 2039 | + } |
|
| 1894 | 2040 | |
| 1895 | 2041 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
| 1896 | 2042 | { |
@@ -1922,19 +2068,29 @@ discard block |
||
| 1922 | 2068 | */ |
| 1923 | 2069 | function expression($table_def/*,$args, ...*/) |
| 1924 | 2070 | { |
| 1925 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
| 2071 | + if (!is_array($table_def)) |
|
| 2072 | + { |
|
| 2073 | + $table_def = $this->get_table_definitions(true,$table_def); |
|
| 2074 | + } |
|
| 1926 | 2075 | $sql = ''; |
| 1927 | 2076 | $ignore_next = 0; |
| 1928 | 2077 | foreach(func_get_args() as $n => $arg) |
| 1929 | 2078 | { |
| 1930 | - if ($n < 1) continue; // table-name |
|
| 2079 | + if ($n < 1) |
|
| 2080 | + { |
|
| 2081 | + continue; |
|
| 2082 | + } |
|
| 2083 | + // table-name |
|
| 1931 | 2084 | |
| 1932 | 2085 | if ($ignore_next) |
| 1933 | 2086 | { |
| 1934 | 2087 | --$ignore_next; |
| 1935 | 2088 | continue; |
| 1936 | 2089 | } |
| 1937 | - if (is_null($arg)) $arg = False; |
|
| 2090 | + if (is_null($arg)) |
|
| 2091 | + { |
|
| 2092 | + $arg = False; |
|
| 2093 | + } |
|
| 1938 | 2094 | |
| 1939 | 2095 | switch(gettype($arg)) |
| 1940 | 2096 | { |
@@ -1974,9 +2130,15 @@ discard block |
||
| 1974 | 2130 | */ |
| 1975 | 2131 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
| 1976 | 2132 | { |
| 1977 | - if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
| 2133 | + if ($this->Debug) |
|
| 2134 | + { |
|
| 2135 | + echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
| 2136 | + } |
|
| 1978 | 2137 | |
| 1979 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 2138 | + if (!$table_def) |
|
| 2139 | + { |
|
| 2140 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 2141 | + } |
|
| 1980 | 2142 | if (is_array($cols)) |
| 1981 | 2143 | { |
| 1982 | 2144 | $cols = implode(',',$cols); |
@@ -1992,16 +2154,28 @@ discard block |
||
| 1992 | 2154 | $sql = "SELECT $cols FROM $table $join"; |
| 1993 | 2155 | |
| 1994 | 2156 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
| 1995 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
| 2157 | + if ($where) |
|
| 2158 | + { |
|
| 2159 | + $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
| 2160 | + } |
|
| 1996 | 2161 | |
| 1997 | - if ($append) $sql .= ' '.$append; |
|
| 2162 | + if ($append) |
|
| 2163 | + { |
|
| 2164 | + $sql .= ' '.$append; |
|
| 2165 | + } |
|
| 1998 | 2166 | |
| 1999 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
| 2167 | + if ($this->Debug) |
|
| 2168 | + { |
|
| 2169 | + echo "<p>sql='$sql'</p>"; |
|
| 2170 | + } |
|
| 2000 | 2171 | |
| 2001 | - if ($line === false && $file === false) // call by union, to return the sql rather then run the query |
|
| 2172 | + if ($line === false && $file === false) |
|
| 2173 | + { |
|
| 2174 | + // call by union, to return the sql rather then run the query |
|
| 2002 | 2175 | { |
| 2003 | 2176 | return $sql; |
| 2004 | 2177 | } |
| 2178 | + } |
|
| 2005 | 2179 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
| 2006 | 2180 | } |
| 2007 | 2181 | |
@@ -2022,7 +2196,10 @@ discard block |
||
| 2022 | 2196 | */ |
| 2023 | 2197 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
| 2024 | 2198 | { |
| 2025 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
| 2199 | + if ($this->Debug) |
|
| 2200 | + { |
|
| 2201 | + echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
| 2202 | + } |
|
| 2026 | 2203 | |
| 2027 | 2204 | $union = array(); |
| 2028 | 2205 | foreach($selects as $select) |
@@ -2043,9 +2220,15 @@ discard block |
||
| 2043 | 2220 | } |
| 2044 | 2221 | $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
| 2045 | 2222 | |
| 2046 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
| 2223 | + if ($order_by) |
|
| 2224 | + { |
|
| 2225 | + $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
| 2226 | + } |
|
| 2047 | 2227 | |
| 2048 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
| 2228 | + if ($this->Debug) |
|
| 2229 | + { |
|
| 2230 | + echo "<p>sql='$sql'</p>"; |
|
| 2231 | + } |
|
| 2049 | 2232 | |
| 2050 | 2233 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
| 2051 | 2234 | } |
@@ -1845,7 +1845,7 @@ discard block |
||
| 1845 | 1845 | if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
| 1846 | 1846 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
| 1847 | 1847 | } |
| 1848 | - $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
| 1848 | + $sql = "update $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
| 1849 | 1849 | // check if we already prepared that statement |
| 1850 | 1850 | if (!isset($this->prepared_sql[$sql])) |
| 1851 | 1851 | { |
@@ -1856,7 +1856,7 @@ discard block |
||
| 1856 | 1856 | } |
| 1857 | 1857 | else |
| 1858 | 1858 | { |
| 1859 | - $sql = "UPDATE $table SET ". |
|
| 1859 | + $sql = "update $table SET ". |
|
| 1860 | 1860 | $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
| 1861 | 1861 | } |
| 1862 | 1862 | $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
@@ -1989,7 +1989,7 @@ discard block |
||
| 1989 | 1989 | { |
| 1990 | 1990 | $table = self::$tablealiases[$table]; |
| 1991 | 1991 | } |
| 1992 | - $sql = "SELECT $cols FROM $table $join"; |
|
| 1992 | + $sql = "select $cols FROM $table $join"; |
|
| 1993 | 1993 | |
| 1994 | 1994 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
| 1995 | 1995 | if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | * Restore data from a (compressed) csv file |
| 497 | 497 | * |
| 498 | 498 | * @param resource $f file opened with fopen for reading |
| 499 | - * @param int|string $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
|
| 499 | + * @param integer $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert |
|
| 500 | 500 | * @returns int number of rows read from csv file |
| 501 | 501 | */ |
| 502 | 502 | function db_restore($f, $insert_n_rows=10) |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | /** |
| 1045 | 1045 | * Backup all schemas in the form of a setup/tables_current.inc.php file |
| 1046 | 1046 | * |
| 1047 | - * @param resource|boolean $f |
|
| 1047 | + * @param resource $f |
|
| 1048 | 1048 | */ |
| 1049 | 1049 | function schema_backup($f=False) |
| 1050 | 1050 | { |
@@ -1089,6 +1089,7 @@ discard block |
||
| 1089 | 1089 | * Dump an array as php source |
| 1090 | 1090 | * |
| 1091 | 1091 | * copied from etemplate/inc/class.db_tools.inc.php |
| 1092 | + * @param integer $depth |
|
| 1092 | 1093 | */ |
| 1093 | 1094 | private static function write_array($arr,$depth,$parent='') |
| 1094 | 1095 | { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | $zip = NULL; |
| 382 | 382 | $_f = NULL; |
| 383 | 383 | if($type == 'zip') |
| 384 | - { |
|
| 384 | + { |
|
| 385 | 385 | // has already been verified to be available in fopen_backup |
| 386 | 386 | $zip = new ZipArchive; |
| 387 | 387 | if(($zip->open($filename)) !== TRUE) |
@@ -719,9 +719,9 @@ discard block |
||
| 719 | 719 | while($file = $list[0]) |
| 720 | 720 | { |
| 721 | 721 | if(is_dir($file) && $file != '.' && $file != '..') |
| 722 | - self::remove_dir_content($dir.'/'.$file); |
|
| 722 | + self::remove_dir_content($dir.'/'.$file); |
|
| 723 | 723 | if(is_file($file) && $file != '.' && $file != '..') |
| 724 | - unlink($dir.'/'.$file); |
|
| 724 | + unlink($dir.'/'.$file); |
|
| 725 | 725 | array_shift($list); |
| 726 | 726 | } |
| 727 | 727 | //rmdir($dir); // dont remove own dir |
@@ -967,8 +967,8 @@ discard block |
||
| 967 | 967 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
| 968 | 968 | } |
| 969 | 969 | |
| 970 | - fclose($f); |
|
| 971 | - if (file_exists($name)) unlink($name); |
|
| 970 | + fclose($f); |
|
| 971 | + if (file_exists($name)) unlink($name); |
|
| 972 | 972 | return TRUE; |
| 973 | 973 | } |
| 974 | 974 | // save files .... |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * @var array |
| 52 | 52 | */ |
| 53 | 53 | var $exclude_tables = array( |
| 54 | - 'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables |
|
| 55 | - 'phpgw_anglemail', // email's cache |
|
| 56 | - 'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache |
|
| 54 | + 'egw_sessions', 'egw_app_sessions', 'phpgw_sessions', 'phpgw_app_sessions', // eGW's session-tables |
|
| 55 | + 'phpgw_anglemail', // email's cache |
|
| 56 | + 'egw_felamimail_cache', 'egw_felamimail_folderstatus', 'phpgw_felamimail_cache', 'phpgw_felamimail_folderstatus', // felamimail's cache |
|
| 57 | 57 | 'egw_phpfreechat', // as of the fieldnames of the table a restore would fail within egroupware, and chatcontent is of no particular intrest |
| 58 | 58 | ); |
| 59 | 59 | /** |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @var boolean |
| 87 | 87 | */ |
| 88 | - var $backup_files = false ; |
|
| 88 | + var $backup_files = false; |
|
| 89 | 89 | /** |
| 90 | 90 | * Reference to schema_proc's Api\Db object |
| 91 | 91 | * |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db)) |
| 102 | 102 | { |
| 103 | - $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
| 103 | + $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
| 104 | 104 | } |
| 105 | 105 | if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it |
| 106 | 106 | { |
@@ -118,21 +118,21 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table))) |
| 120 | 120 | { |
| 121 | - if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__)->fetchColumn())) |
|
| 121 | + if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'", __LINE__, __FILE__)->fetchColumn())) |
|
| 122 | 122 | { |
| 123 | 123 | error_log(__METHOD__."->"."No files Directory set/found"); |
| 124 | 124 | } |
| 125 | - if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__)->fetchColumn())) |
|
| 125 | + if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'", __LINE__, __FILE__)->fetchColumn())) |
|
| 126 | 126 | { |
| 127 | 127 | $this->backup_dir = $this->files_dir.'/db_backup'; |
| 128 | 128 | } |
| 129 | - $this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__)->fetchColumn(); |
|
| 130 | - $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table,'app_version',array('app_name'=>array('api','phpgwapi')), |
|
| 131 | - __LINE__,__FILE__,0,'ORDER BY app_name ASC')->fetchColumn(); |
|
| 129 | + $this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'", __LINE__, __FILE__)->fetchColumn(); |
|
| 130 | + $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table, 'app_version', array('app_name'=>array('api', 'phpgwapi')), |
|
| 131 | + __LINE__, __FILE__, 0, 'ORDER BY app_name ASC')->fetchColumn(); |
|
| 132 | 132 | // Backup settings |
| 133 | - $this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'",__LINE__,__FILE__)->fetchColumn(); |
|
| 133 | + $this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'", __LINE__, __FILE__)->fetchColumn(); |
|
| 134 | 134 | // backup files too |
| 135 | - $this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__)->fetchColumn(); |
|
| 135 | + $this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'", __LINE__, __FILE__)->fetchColumn(); |
|
| 136 | 136 | } |
| 137 | 137 | if (!$this->charset) $this->charset = 'utf-8'; |
| 138 | 138 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $this->backup_files = $GLOBALS['egw_info']['server']['backup_files']; |
| 148 | 148 | $this->charset = Api\Translation::charset(); |
| 149 | 149 | |
| 150 | - $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api'])?'api':'phpgwapi']['version']; |
|
| 150 | + $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api']) ? 'api' : 'phpgwapi']['version']; |
|
| 151 | 151 | } |
| 152 | 152 | // Set a default value if not set. |
| 153 | 153 | if (!isset($this->backup_mincount)) |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | mkdir($this->backup_dir); |
| 165 | 165 | } |
| 166 | - switch($this->db->Type) |
|
| 166 | + switch ($this->db->Type) |
|
| 167 | 167 | { |
| 168 | 168 | case 'sapdb': |
| 169 | 169 | case 'maxdb': |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @param $reading =false opening for reading ('rb') or writing ('wb') |
| 181 | 181 | * @return string/resource/zip error-msg of file-handle |
| 182 | 182 | */ |
| 183 | - function fopen_backup($name=false,$reading=false) |
|
| 183 | + function fopen_backup($name = false, $reading = false) |
|
| 184 | 184 | { |
| 185 | 185 | //echo "function fopen_backup($name,$reading)<br>"; // ! |
| 186 | 186 | if (!$name) |
@@ -189,27 +189,27 @@ discard block |
||
| 189 | 189 | if (!$this->backup_dir || !is_writable($this->backup_dir)) |
| 190 | 190 | { |
| 191 | 191 | //echo ' -> !$this->backup_dir || !is_writable($this->backup_dir)<br>'; // ! |
| 192 | - return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir); |
|
| 192 | + return lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir); |
|
| 193 | 193 | } |
| 194 | 194 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
| 195 | 195 | } |
| 196 | 196 | else // remove the extension, to use the correct wrapper based on the extension |
| 197 | 197 | { |
| 198 | 198 | //echo '-> else<br>'; // ! |
| 199 | - $name = preg_replace('/\.(bz2|gz)$/i','',$name); |
|
| 199 | + $name = preg_replace('/\.(bz2|gz)$/i', '', $name); |
|
| 200 | 200 | } |
| 201 | 201 | $mode = $reading ? 'rb' : 'wb'; |
| 202 | - list( , $type) = explode('.', basename($name)); |
|
| 203 | - if($type == 'zip' && $reading && $this->backup_files) |
|
| 202 | + list(, $type) = explode('.', basename($name)); |
|
| 203 | + if ($type == 'zip' && $reading && $this->backup_files) |
|
| 204 | 204 | { |
| 205 | 205 | //echo '-> $type == "zip" && $reading<br>'; // ! |
| 206 | - if(!class_exists('ZipArchive', false)) |
|
| 206 | + if (!class_exists('ZipArchive', false)) |
|
| 207 | 207 | { |
| 208 | 208 | $this->backup_files = false; |
| 209 | 209 | //echo ' -> (new ZipArchive) == NULL<br>'; // ! |
| 210 | 210 | return lang("Cant open %1, needs ZipArchive", $name)."<br>\n"; |
| 211 | 211 | } |
| 212 | - if(!($f = fopen($name, $mode))) |
|
| 212 | + if (!($f = fopen($name, $mode))) |
|
| 213 | 213 | { |
| 214 | 214 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
| 215 | 215 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -217,10 +217,10 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | return $f; |
| 219 | 219 | } |
| 220 | - if(class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
| 220 | + if (class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
| 221 | 221 | { |
| 222 | 222 | //echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'<br>'; // ! |
| 223 | - if(!($f = fopen($name, $mode))) |
|
| 223 | + if (!($f = fopen($name, $mode))) |
|
| 224 | 224 | { |
| 225 | 225 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
| 226 | 226 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | } |
| 229 | 229 | return $f; |
| 230 | 230 | } |
| 231 | - if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
| 232 | - !($f = fopen("compress.zlib://$name.gz",$mode)) && |
|
| 233 | - !($f = fopen($name,$mode)) |
|
| 231 | + if (!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
| 232 | + !($f = fopen("compress.zlib://$name.gz", $mode)) && |
|
| 233 | + !($f = fopen($name, $mode)) |
|
| 234 | 234 | ) |
| 235 | 235 | { |
| 236 | 236 | //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>'; // ! |
@@ -257,13 +257,13 @@ discard block |
||
| 257 | 257 | /* Search the backup directory for matching files. */ |
| 258 | 258 | $handle = @opendir($this->backup_dir); |
| 259 | 259 | $files = array(); |
| 260 | - while($handle && ($file = readdir($handle))) |
|
| 260 | + while ($handle && ($file = readdir($handle))) |
|
| 261 | 261 | { |
| 262 | 262 | /* Filter for only the files with the regular name (un-renamed). |
| 263 | 263 | * Leave special backup files (renamed) in place. |
| 264 | 264 | * Note that this also excludes "." and "..". |
| 265 | 265 | */ |
| 266 | - if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/",$file)) |
|
| 266 | + if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/", $file)) |
|
| 267 | 267 | { |
| 268 | 268 | $files[filectime($this->backup_dir.'/'.$file)] = $file; |
| 269 | 269 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | /* Sort the files by ctime. */ |
| 274 | 274 | krsort($files); |
| 275 | 275 | $count = 0; |
| 276 | - foreach($files as $file) |
|
| 276 | + foreach ($files as $file) |
|
| 277 | 277 | { |
| 278 | 278 | if ($count >= $this->backup_mincount)// |
| 279 | 279 | { |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | array_push($files_return, $file); |
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | - $count ++; |
|
| 286 | + $count++; |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
@@ -293,13 +293,13 @@ discard block |
||
| 293 | 293 | * @param int $minCount Minimum number of backups to keep. |
| 294 | 294 | * @param boolean $backupFiles include files in backup or not, default dont change! |
| 295 | 295 | */ |
| 296 | - function saveConfig($minCount,$backupFiles=null) |
|
| 296 | + function saveConfig($minCount, $backupFiles = null) |
|
| 297 | 297 | { |
| 298 | - Api\Config::save_value('backup_mincount',$this->backup_mincount=(int)$minCount,'phpgwapi'); |
|
| 298 | + Api\Config::save_value('backup_mincount', $this->backup_mincount = (int)$minCount, 'phpgwapi'); |
|
| 299 | 299 | |
| 300 | 300 | if (!is_null($backupFiles)) |
| 301 | 301 | { |
| 302 | - Api\Config::save_value('backup_files',$this->backup_files=(boolean)$backupFiles,'phpgwapi'); |
|
| 302 | + Api\Config::save_value('backup_files', $this->backup_files = (boolean)$backupFiles, 'phpgwapi'); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | 'httpproxy_server_password', |
| 323 | 323 | 'system_charset', |
| 324 | 324 | 'usecookies', |
| 325 | - 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
| 325 | + 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
| 326 | 326 | ); |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -336,38 +336,38 @@ discard block |
||
| 336 | 336 | * |
| 337 | 337 | * @returns An empty string or an error message in case of failure. |
| 338 | 338 | */ |
| 339 | - function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10) |
|
| 339 | + function restore($f, $convert_to_system_charset = true, $filename = '', $protect_system_config = true, $insert_n_rows = 10) |
|
| 340 | 340 | { |
| 341 | 341 | @set_time_limit(0); |
| 342 | - ini_set('auto_detect_line_endings',true); |
|
| 342 | + ini_set('auto_detect_line_endings', true); |
|
| 343 | 343 | |
| 344 | - if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
| 344 | + if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
| 345 | 345 | |
| 346 | 346 | if ($protect_system_config) |
| 347 | 347 | { |
| 348 | 348 | $system_config = array(); |
| 349 | - foreach($this->db->select(self::TABLE,'*',array( |
|
| 349 | + foreach ($this->db->select(self::TABLE, '*', array( |
|
| 350 | 350 | 'config_app' => 'phpgwapi', |
| 351 | 351 | 'config_name' => self::$system_config, |
| 352 | - ),__LINE__,__FILE__) as $row) |
|
| 352 | + ), __LINE__, __FILE__) as $row) |
|
| 353 | 353 | { |
| 354 | 354 | $system_config[] = $row; |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | - if (substr($this->db->Type,0,5) != 'mysql') $this->db->transaction_begin(); |
|
| 357 | + if (substr($this->db->Type, 0, 5) != 'mysql') $this->db->transaction_begin(); |
|
| 358 | 358 | |
| 359 | 359 | // drop all existing tables |
| 360 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
| 360 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
| 361 | 361 | { |
| 362 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
| 363 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
| 362 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
| 363 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
| 364 | 364 | { |
| 365 | 365 | continue; |
| 366 | 366 | } |
| 367 | 367 | $this->schema_proc->DropTable($table); |
| 368 | 368 | } |
| 369 | 369 | // it could be an old backup |
| 370 | - list( , $type) = explode('.', basename($filename)); |
|
| 370 | + list(, $type) = explode('.', basename($filename)); |
|
| 371 | 371 | $dir = $this->files_dir; // $GLOBALS['egw_info']['server']['files_dir']; |
| 372 | 372 | // we may have to clean up old backup - left overs |
| 373 | 373 | if (is_dir($dir.'/database_backup')) |
@@ -380,20 +380,20 @@ discard block |
||
| 380 | 380 | $name = ""; |
| 381 | 381 | $zip = NULL; |
| 382 | 382 | $_f = NULL; |
| 383 | - if($type == 'zip') |
|
| 383 | + if ($type == 'zip') |
|
| 384 | 384 | { |
| 385 | 385 | // has already been verified to be available in fopen_backup |
| 386 | 386 | $zip = new ZipArchive; |
| 387 | - if(($zip->open($filename)) !== TRUE) |
|
| 387 | + if (($zip->open($filename)) !== TRUE) |
|
| 388 | 388 | { |
| 389 | 389 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
| 390 | 390 | } |
| 391 | - self::remove_dir_content($dir); // removes the files-dir |
|
| 391 | + self::remove_dir_content($dir); // removes the files-dir |
|
| 392 | 392 | $zip->extractTo($dir); |
| 393 | 393 | $_f = $f; |
| 394 | 394 | $list = $this->get_file_list($dir.'/database_backup/'); |
| 395 | 395 | $name = $dir.'/database_backup/'.basename($list[0]); |
| 396 | - if(!($f = fopen($name, 'rb'))) |
|
| 396 | + if (!($f = fopen($name, 'rb'))) |
|
| 397 | 397 | { |
| 398 | 398 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
| 399 | 399 | } |
@@ -410,46 +410,46 @@ discard block |
||
| 410 | 410 | { |
| 411 | 411 | $this->db->insert(Api\Config::TABLE, array( |
| 412 | 412 | 'config_value' => $this->schema_proc->system_charset, |
| 413 | - ),array( |
|
| 413 | + ), array( |
|
| 414 | 414 | 'config_app' => 'phpgwapi', |
| 415 | 415 | 'config_name' => 'system_charset', |
| 416 | - ),__LINE__,__FILE__); |
|
| 416 | + ), __LINE__, __FILE__); |
|
| 417 | 417 | } |
| 418 | 418 | // restore protected system config |
| 419 | 419 | if ($protect_system_config) |
| 420 | 420 | { |
| 421 | - foreach($system_config as $row) |
|
| 421 | + foreach ($system_config as $row) |
|
| 422 | 422 | { |
| 423 | - $this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array( |
|
| 423 | + $this->db->insert(self::TABLE, array('config_value'=>$row['config_value']), array( |
|
| 424 | 424 | 'config_name' => $row['config_name'], |
| 425 | 425 | 'config_app' => $row['config_app'], |
| 426 | - ),__LINE__,__FILE__); |
|
| 426 | + ), __LINE__, __FILE__); |
|
| 427 | 427 | } |
| 428 | 428 | // check and reset cookie configuration, if it does not match current enviroment |
| 429 | 429 | // if $_SERVER[HTTP_HOST] does not end with cookiedomain --> delete cookiedomain |
| 430 | - if (($cookiedomain = $this->db->select(self::TABLE,'config_value',array( |
|
| 430 | + if (($cookiedomain = $this->db->select(self::TABLE, 'config_value', array( |
|
| 431 | 431 | 'config_app' => 'phpgwapi', |
| 432 | 432 | 'config_name' => 'cookiedomain', |
| 433 | - ),__LINE__,__FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
| 434 | - (list($hostname) = explode(':',$_SERVER['HTTP_HOST'])) && |
|
| 435 | - substr($hostname,-strlen($cookiedomain) !== $cookiedomain)) |
|
| 433 | + ), __LINE__, __FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
| 434 | + (list($hostname) = explode(':', $_SERVER['HTTP_HOST'])) && |
|
| 435 | + substr($hostname, -strlen($cookiedomain) !== $cookiedomain)) |
|
| 436 | 436 | { |
| 437 | - $this->db->delete(self::TABLE,array( |
|
| 437 | + $this->db->delete(self::TABLE, array( |
|
| 438 | 438 | 'config_app' => 'phpgwapi', |
| 439 | 439 | 'config_name' => 'cookiedomain', |
| 440 | - ),__LINE__,__FILE__); |
|
| 440 | + ), __LINE__, __FILE__); |
|
| 441 | 441 | } |
| 442 | 442 | // if configured webserver_url does NOT start with cookiepath --> delete cookiepath |
| 443 | - if (($cookiepath = $this->db->select(self::TABLE,'config_value',array( |
|
| 443 | + if (($cookiepath = $this->db->select(self::TABLE, 'config_value', array( |
|
| 444 | 444 | 'config_app' => 'phpgwapi', |
| 445 | 445 | 'config_name' => 'cookiepath', |
| 446 | - ),__LINE__,__FILE__)->fetchColumn()) && |
|
| 447 | - substr(parse_url($system_config['webserver_url'], PHP_URL_PATH),0,strlen($cookiepath) !== $cookiepath)) |
|
| 446 | + ), __LINE__, __FILE__)->fetchColumn()) && |
|
| 447 | + substr(parse_url($system_config['webserver_url'], PHP_URL_PATH), 0, strlen($cookiepath) !== $cookiepath)) |
|
| 448 | 448 | { |
| 449 | - $this->db->delete(self::TABLE,array( |
|
| 449 | + $this->db->delete(self::TABLE, array( |
|
| 450 | 450 | 'config_app' => 'phpgwapi', |
| 451 | 451 | 'config_name' => 'cookiepath', |
| 452 | - ),__LINE__,__FILE__); |
|
| 452 | + ), __LINE__, __FILE__); |
|
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | // restore original Halt_On_Error state (if changed) |
@@ -458,13 +458,13 @@ discard block |
||
| 458 | 458 | $this->db->Halt_On_Error = $backup_db_halt_on_error; |
| 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 = False; |
| 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 | - $api_version = trim(substr($line,9)); |
|
| 516 | + $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,29 +526,29 @@ 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 | // set the DB's client encoding (for mysql only if api_version >= 1.0.1.019) |
| 532 | 532 | if ((!$convert_to_system_charset || $this->db->capabilities['client_encoding']) && |
| 533 | - (substr($this->db->Type,0,5) != 'mysql' || !is_object($GLOBALS['egw_setup']) || |
|
| 534 | - $api_version && !$GLOBALS['egw_setup']->alessthanb($api_version,'1.0.1.019'))) |
|
| 533 | + (substr($this->db->Type, 0, 5) != 'mysql' || !is_object($GLOBALS['egw_setup']) || |
|
| 534 | + $api_version && !$GLOBALS['egw_setup']->alessthanb($api_version, '1.0.1.019'))) |
|
| 535 | 535 | { |
| 536 | 536 | $this->db->Link_ID->SetCharSet($charset); |
| 537 | 537 | if (!$convert_to_system_charset) |
| 538 | 538 | { |
| 539 | - $this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables |
|
| 539 | + $this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | continue; |
| 543 | 543 | } |
| 544 | - if (substr($line,0,8) == 'schema: ') |
|
| 544 | + if (substr($line, 0, 8) == 'schema: ') |
|
| 545 | 545 | { |
| 546 | 546 | // create the tables in the backup set |
| 547 | - $this->schemas = json_php_unserialize(trim(substr($line,8))); |
|
| 548 | - foreach($this->schemas as $table_name => $schema) |
|
| 547 | + $this->schemas = json_php_unserialize(trim(substr($line, 8))); |
|
| 548 | + foreach ($this->schemas as $table_name => $schema) |
|
| 549 | 549 | { |
| 550 | 550 | // if column is longtext in current schema, convert text to longtext, in case user already updated column |
| 551 | - foreach($schema['fd'] as $col => &$def) |
|
| 551 | + foreach ($schema['fd'] as $col => &$def) |
|
| 552 | 552 | { |
| 553 | 553 | if ($def['type'] == 'text' && $this->db->get_column_attribute($col, $table_name, true, 'type') == 'longtext') |
| 554 | 554 | { |
@@ -560,27 +560,27 @@ discard block |
||
| 560 | 560 | } |
| 561 | 561 | continue; |
| 562 | 562 | } |
| 563 | - if (substr($line,0,7) == 'table: ') |
|
| 563 | + if (substr($line, 0, 7) == 'table: ') |
|
| 564 | 564 | { |
| 565 | 565 | if ($rows) // flush pending rows of last table |
| 566 | 566 | { |
| 567 | 567 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
| 568 | 568 | } |
| 569 | 569 | $rows = array(); |
| 570 | - $table = substr($line,7); |
|
| 570 | + $table = substr($line, 7); |
|
| 571 | 571 | if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
| 572 | 572 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
| 573 | 573 | |
| 574 | - $cols = self::csv_split($line=fgets($f)); ++$n; |
|
| 574 | + $cols = self::csv_split($line = fgets($f)); ++$n; |
|
| 575 | 575 | $blobs = array(); |
| 576 | - foreach($this->schemas[$table]['fd'] as $col => $data) |
|
| 576 | + foreach ($this->schemas[$table]['fd'] as $col => $data) |
|
| 577 | 577 | { |
| 578 | 578 | if ($data['type'] == 'blob') $blobs[] = $col; |
| 579 | 579 | } |
| 580 | 580 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
| 581 | 581 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
| 582 | 582 | $bools = array(); |
| 583 | - foreach($this->schemas[$table]['fd'] as $col => $def) |
|
| 583 | + foreach ($this->schemas[$table]['fd'] as $col => $def) |
|
| 584 | 584 | { |
| 585 | 585 | if ($def['type'] === 'bool') $bools[] = $col; |
| 586 | 586 | } |
@@ -604,15 +604,15 @@ discard block |
||
| 604 | 604 | $import = true; |
| 605 | 605 | $data = self::csv_split($line, $cols, $blobs, $bools); |
| 606 | 606 | |
| 607 | - if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
|
| 607 | + if ($table == 'egw_async' && in_array('##last-check-run##', $data)) |
|
| 608 | 608 | { |
| 609 | 609 | //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"; |
| 610 | 610 | //echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
| 611 | 611 | $import = false; |
| 612 | 612 | } |
| 613 | - if (in_array($table,$this->exclude_tables)) |
|
| 613 | + if (in_array($table, $this->exclude_tables)) |
|
| 614 | 614 | { |
| 615 | - echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n"; |
|
| 615 | + echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n"; |
|
| 616 | 616 | $import = false; // dont restore data of excluded tables |
| 617 | 617 | } |
| 618 | 618 | if ($import) |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | { |
| 622 | 622 | if ($convert_to_system_charset && !$this->db->capabilities['client_encoding']) |
| 623 | 623 | { |
| 624 | - $data = Api\Translation::convert($data,$charset); |
|
| 624 | + $data = Api\Translation::convert($data, $charset); |
|
| 625 | 625 | } |
| 626 | 626 | if ($insert_n_rows > 1) |
| 627 | 627 | { |
@@ -633,27 +633,27 @@ discard block |
||
| 633 | 633 | } |
| 634 | 634 | } |
| 635 | 635 | // update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence) |
| 636 | - elseif(!is_numeric($insert_n_rows)) |
|
| 636 | + elseif (!is_numeric($insert_n_rows)) |
|
| 637 | 637 | { |
| 638 | 638 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
| 639 | 639 | unset($data[$insert_n_rows]); |
| 640 | 640 | if ($auto_id) unset($data[$auto_id]); |
| 641 | - $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
| 641 | + $this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
| 642 | 642 | } |
| 643 | 643 | else |
| 644 | 644 | { |
| 645 | 645 | try { |
| 646 | - $this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
| 646 | + $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
| 647 | 647 | } |
| 648 | - catch(Exception\InvalidSql $e) { |
|
| 648 | + catch (Exception\InvalidSql $e) { |
|
| 649 | 649 | echo "<p>".$e->getMessage()."</p>\n"; |
| 650 | 650 | } |
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | 653 | else |
| 654 | 654 | { |
| 655 | - 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"; |
|
| 656 | - echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
|
| 655 | + 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"; |
|
| 656 | + echo 'data=<pre>'.print_r($data, true)."</pre>\n"; |
|
| 657 | 657 | } |
| 658 | 658 | } |
| 659 | 659 | } |
@@ -663,14 +663,14 @@ discard block |
||
| 663 | 663 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
| 664 | 664 | } |
| 665 | 665 | // updated the sequences, if the DB uses them |
| 666 | - foreach($this->schemas as $table => $schema) |
|
| 666 | + foreach ($this->schemas as $table => $schema) |
|
| 667 | 667 | { |
| 668 | - foreach($schema['fd'] as $column => $definition) |
|
| 668 | + foreach ($schema['fd'] as $column => $definition) |
|
| 669 | 669 | { |
| 670 | 670 | if ($definition['type'] == 'auto') |
| 671 | 671 | { |
| 672 | - $this->schema_proc->UpdateSequence($table,$column); |
|
| 673 | - break; // max. one per table |
|
| 672 | + $this->schema_proc->UpdateSequence($table, $column); |
|
| 673 | + break; // max. one per table |
|
| 674 | 674 | } |
| 675 | 675 | } |
| 676 | 676 | } |
@@ -693,15 +693,15 @@ discard block |
||
| 693 | 693 | try { |
| 694 | 694 | $this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema); |
| 695 | 695 | } |
| 696 | - catch(Exception\InvalidSql $e) |
|
| 696 | + catch (Exception\InvalidSql $e) |
|
| 697 | 697 | { |
| 698 | 698 | // try inserting them one by one, ignoring doublicates |
| 699 | - foreach($rows as $data) |
|
| 699 | + foreach ($rows as $data) |
|
| 700 | 700 | { |
| 701 | 701 | try { |
| 702 | 702 | $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema); |
| 703 | 703 | } |
| 704 | - catch(Exception\InvalidSql $e) { |
|
| 704 | + catch (Exception\InvalidSql $e) { |
|
| 705 | 705 | echo "<p>".$e->getMessage()."</p>\n"; |
| 706 | 706 | } |
| 707 | 707 | } |
@@ -716,11 +716,11 @@ discard block |
||
| 716 | 716 | private static function remove_dir_content($dir) |
| 717 | 717 | { |
| 718 | 718 | $list = scandir($dir); |
| 719 | - while($file = $list[0]) |
|
| 719 | + while ($file = $list[0]) |
|
| 720 | 720 | { |
| 721 | - if(is_dir($file) && $file != '.' && $file != '..') |
|
| 721 | + if (is_dir($file) && $file != '.' && $file != '..') |
|
| 722 | 722 | self::remove_dir_content($dir.'/'.$file); |
| 723 | - if(is_file($file) && $file != '.' && $file != '..') |
|
| 723 | + if (is_file($file) && $file != '.' && $file != '..') |
|
| 724 | 724 | unlink($dir.'/'.$file); |
| 725 | 725 | array_shift($list); |
| 726 | 726 | } |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups |
| 746 | 746 | * @return array |
| 747 | 747 | */ |
| 748 | - public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
|
| 748 | + public static function csv_split($line, $keys = null, $blobs = array(), $bools = array()) |
|
| 749 | 749 | { |
| 750 | 750 | if (function_exists('str_getcsv')) // php5.3+ |
| 751 | 751 | { |
@@ -758,9 +758,9 @@ discard block |
||
| 758 | 758 | '\\n' => "\n", |
| 759 | 759 | '\\r' => "\r")), ',', '"', '\0'); |
| 760 | 760 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
| 761 | - foreach($fields as &$field) |
|
| 761 | + foreach ($fields as &$field) |
|
| 762 | 762 | { |
| 763 | - switch($field) |
|
| 763 | + switch ($field) |
|
| 764 | 764 | { |
| 765 | 765 | case self::NULL_TOKEN: |
| 766 | 766 | $field = 'NULL'; |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | { |
| 778 | 778 | $fields = array_combine($keys, $fields); |
| 779 | 779 | // base64-decode blob columns, if they are base64 encoded |
| 780 | - foreach($blobs as $key) |
|
| 780 | + foreach ($blobs as $key) |
|
| 781 | 781 | { |
| 782 | 782 | if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false) |
| 783 | 783 | { |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | // decode bool columns, they might be 't'/'f' for old PostgreSQL backups |
| 788 | - foreach($bools as $key) |
|
| 788 | + foreach ($bools as $key) |
|
| 789 | 789 | { |
| 790 | 790 | $fields[$key] = Api\Db::from_bool($fields[$key]); |
| 791 | 791 | } |
@@ -793,11 +793,11 @@ discard block |
||
| 793 | 793 | return $fields; |
| 794 | 794 | } |
| 795 | 795 | // pre 5.3 implementation |
| 796 | - $fields = explode(',',trim($line)); |
|
| 796 | + $fields = explode(',', trim($line)); |
|
| 797 | 797 | |
| 798 | 798 | $str_pending = False; |
| 799 | 799 | $n = 0; |
| 800 | - foreach($fields as $field) |
|
| 800 | + foreach ($fields as $field) |
|
| 801 | 801 | { |
| 802 | 802 | if ($str_pending !== False) |
| 803 | 803 | { |
@@ -808,12 +808,12 @@ discard block |
||
| 808 | 808 | |
| 809 | 809 | if ($field[0] == '"') |
| 810 | 810 | { |
| 811 | - if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field)) |
|
| 811 | + if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field)) |
|
| 812 | 812 | { |
| 813 | 813 | $str_pending = $field; |
| 814 | 814 | continue; |
| 815 | 815 | } |
| 816 | - $arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1))); |
|
| 816 | + $arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1))); |
|
| 817 | 817 | } |
| 818 | 818 | elseif ($keys && strlen($field) > 26) |
| 819 | 819 | { |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | /** |
| 836 | 836 | * escape data for csv |
| 837 | 837 | */ |
| 838 | - public static function escape_data(&$data,$col,$defs) |
|
| 838 | + public static function escape_data(&$data, $col, $defs) |
|
| 839 | 839 | { |
| 840 | 840 | if (is_null($data)) |
| 841 | 841 | { |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | } |
| 844 | 844 | else |
| 845 | 845 | { |
| 846 | - switch($defs[$col]['type']) |
|
| 846 | + switch ($defs[$col]['type']) |
|
| 847 | 847 | { |
| 848 | 848 | case 'int': |
| 849 | 849 | case 'auto': |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | $data = (int)Api\Db::from_bool($data); |
| 859 | 859 | break; |
| 860 | 860 | default: |
| 861 | - $data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"'; |
|
| 861 | + $data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"'; |
|
| 862 | 862 | break; |
| 863 | 863 | } |
| 864 | 864 | } |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | * default of null limits memory usage if there is no primary key, by locking table and use ROW_CHUCK |
| 878 | 878 | * @todo use https://github.com/maennchen/ZipStream-PHP to not assemble all files in memmory |
| 879 | 879 | */ |
| 880 | - function backup($f, $lock_table=null) |
|
| 880 | + function backup($f, $lock_table = null) |
|
| 881 | 881 | { |
| 882 | 882 | //echo "function backup($f)<br>"; // ! |
| 883 | 883 | @set_time_limit(0); |
@@ -893,15 +893,15 @@ discard block |
||
| 893 | 893 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
| 894 | 894 | $filename = $name.'.zip'; |
| 895 | 895 | $zippresent = false; |
| 896 | - if(class_exists('ZipArchive') && $this->backup_files) |
|
| 896 | + if (class_exists('ZipArchive') && $this->backup_files) |
|
| 897 | 897 | { |
| 898 | 898 | $zip = new ZipArchive; |
| 899 | - if(is_object($zip)) |
|
| 899 | + if (is_object($zip)) |
|
| 900 | 900 | { |
| 901 | 901 | $zippresent = true; |
| 902 | 902 | //echo '-> is_object($zip); '.$filename.'<br>'; // ! |
| 903 | 903 | $res = $zip->open($filename, ZipArchive::CREATE); |
| 904 | - if($res !== TRUE) |
|
| 904 | + if ($res !== TRUE) |
|
| 905 | 905 | { |
| 906 | 906 | //echo ' -> !$res<br>'; // ! |
| 907 | 907 | return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n"; |
@@ -909,19 +909,19 @@ discard block |
||
| 909 | 909 | $file_list = $this->get_file_list($dir); |
| 910 | 910 | } |
| 911 | 911 | } |
| 912 | - fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
| 912 | + fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
| 913 | 913 | |
| 914 | - fwrite($f,"version: $this->api_version\n\n"); |
|
| 914 | + fwrite($f, "version: $this->api_version\n\n"); |
|
| 915 | 915 | |
| 916 | - fwrite($f,"charset: $this->charset\n\n"); |
|
| 916 | + fwrite($f, "charset: $this->charset\n\n"); |
|
| 917 | 917 | |
| 918 | - $this->schema_backup($f); // add the schema in a human readable form too |
|
| 918 | + $this->schema_backup($f); // add the schema in a human readable form too |
|
| 919 | 919 | |
| 920 | - fwrite($f,"\nschema: ".json_encode($this->schemas)."\n"); |
|
| 920 | + fwrite($f, "\nschema: ".json_encode($this->schemas)."\n"); |
|
| 921 | 921 | |
| 922 | - foreach($this->schemas as $table => $schema) |
|
| 922 | + foreach ($this->schemas as $table => $schema) |
|
| 923 | 923 | { |
| 924 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
| 924 | + if (in_array($table, $this->exclude_tables)) continue; // dont backup |
|
| 925 | 925 | |
| 926 | 926 | // do we have a primary key? |
| 927 | 927 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | do { |
| 938 | 938 | $num_rows = 0; |
| 939 | 939 | // querying only chunks for 10000 rows, to not run into memory limit on huge tables |
| 940 | - foreach($this->db->select($table, '*', |
|
| 940 | + foreach ($this->db->select($table, '*', |
|
| 941 | 941 | // limit by maximum primary key already received |
| 942 | 942 | empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']), |
| 943 | 943 | __LINE__, __FILE__, |
@@ -948,19 +948,19 @@ discard block |
||
| 948 | 948 | false, self::ROW_CHUNK) as $row) |
| 949 | 949 | { |
| 950 | 950 | if (!empty($pk)) $max = $row[$pk]; |
| 951 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
| 951 | + if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n"); |
|
| 952 | 952 | |
| 953 | 953 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
| 954 | - fwrite($f,implode(',',$row)."\n"); |
|
| 954 | + fwrite($f, implode(',', $row)."\n"); |
|
| 955 | 955 | ++$total; |
| 956 | 956 | ++$num_rows; |
| 957 | 957 | } |
| 958 | 958 | } |
| 959 | - while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
| 959 | + while ((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
| 960 | 960 | |
| 961 | 961 | if (!$pk) $this->db->Link_ID->RollbackLock($table); |
| 962 | 962 | } |
| 963 | - if(!$zippresent) // save without files |
|
| 963 | + if (!$zippresent) // save without files |
|
| 964 | 964 | { |
| 965 | 965 | if ($this->backup_files) |
| 966 | 966 | { |
@@ -975,16 +975,16 @@ discard block |
||
| 975 | 975 | //echo $name.'<br>'; |
| 976 | 976 | $zip->addFile($name, 'database_backup/'.basename($name)); |
| 977 | 977 | $count = 1; |
| 978 | - foreach($file_list as $file) |
|
| 978 | + foreach ($file_list as $file) |
|
| 979 | 979 | { |
| 980 | 980 | //echo substr($file,strlen($dir)+1).'<br>'; |
| 981 | 981 | //echo $file.'<br>'; |
| 982 | - $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
|
| 983 | - if(($count++) == 100) { // the file descriptor limit |
|
| 982 | + $zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file); |
|
| 983 | + if (($count++) == 100) { // the file descriptor limit |
|
| 984 | 984 | $zip->close(); |
| 985 | - if(($zip = new ZipArchive())) { |
|
| 985 | + if (($zip = new ZipArchive())) { |
|
| 986 | 986 | $zip->open($filename); |
| 987 | - $count =0; |
|
| 987 | + $count = 0; |
|
| 988 | 988 | } |
| 989 | 989 | } |
| 990 | 990 | } |
@@ -1007,17 +1007,17 @@ discard block |
||
| 1007 | 1007 | { |
| 1008 | 1008 | //chdir($f); |
| 1009 | 1009 | //echo "Processing $f <br>"; |
| 1010 | - if ($path_name =='') $path_name = $f; |
|
| 1010 | + if ($path_name == '') $path_name = $f; |
|
| 1011 | 1011 | $tlist = scandir($f); |
| 1012 | 1012 | $list = array(); |
| 1013 | 1013 | $i = $cnt; |
| 1014 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
| 1014 | + while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
| 1015 | 1015 | { |
| 1016 | - if($file == '.' || $file == '..') |
|
| 1016 | + if ($file == '.' || $file == '..') |
|
| 1017 | 1017 | { |
| 1018 | 1018 | array_shift($tlist); |
| 1019 | 1019 | } |
| 1020 | - elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
|
| 1020 | + elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false) |
|
| 1021 | 1021 | { |
| 1022 | 1022 | // skip activesync debug.txt on backupFiles |
| 1023 | 1023 | //error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file); |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | } |
| 1026 | 1026 | else |
| 1027 | 1027 | { |
| 1028 | - if(is_dir($f.'/'.$file)) |
|
| 1028 | + if (is_dir($f.'/'.$file)) |
|
| 1029 | 1029 | { |
| 1030 | 1030 | $nlist = $this->get_file_list($f.'/'.$file, $i); |
| 1031 | 1031 | $list += $nlist; |
@@ -1046,12 +1046,12 @@ discard block |
||
| 1046 | 1046 | * |
| 1047 | 1047 | * @param resource|boolean $f |
| 1048 | 1048 | */ |
| 1049 | - function schema_backup($f=False) |
|
| 1049 | + function schema_backup($f = False) |
|
| 1050 | 1050 | { |
| 1051 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
| 1051 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
| 1052 | 1052 | { |
| 1053 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
| 1054 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
| 1053 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
| 1054 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
| 1055 | 1055 | { |
| 1056 | 1056 | continue; |
| 1057 | 1057 | } |
@@ -1070,17 +1070,17 @@ discard block |
||
| 1070 | 1070 | } |
| 1071 | 1071 | } |
| 1072 | 1072 | $def = "\t\$phpgw_baseline = "; |
| 1073 | - $def .= self::write_array($this->schemas,1); |
|
| 1073 | + $def .= self::write_array($this->schemas, 1); |
|
| 1074 | 1074 | $def .= ";\n"; |
| 1075 | 1075 | |
| 1076 | 1076 | if ($f) |
| 1077 | 1077 | { |
| 1078 | - fwrite($f,$def); |
|
| 1078 | + fwrite($f, $def); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | else |
| 1081 | 1081 | { |
| 1082 | 1082 | $def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def; |
| 1083 | - Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def)); |
|
| 1083 | + Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def)); |
|
| 1084 | 1084 | echo $def; |
| 1085 | 1085 | } |
| 1086 | 1086 | } |
@@ -1090,9 +1090,9 @@ discard block |
||
| 1090 | 1090 | * |
| 1091 | 1091 | * copied from etemplate/inc/class.db_tools.inc.php |
| 1092 | 1092 | */ |
| 1093 | - private static function write_array($arr,$depth,$parent='') |
|
| 1093 | + private static function write_array($arr, $depth, $parent = '') |
|
| 1094 | 1094 | { |
| 1095 | - if (in_array($parent,array('pk','fk','ix','uc'))) |
|
| 1095 | + if (in_array($parent, array('pk', 'fk', 'ix', 'uc'))) |
|
| 1096 | 1096 | { |
| 1097 | 1097 | $depth = 0; |
| 1098 | 1098 | } |
@@ -1108,7 +1108,7 @@ discard block |
||
| 1108 | 1108 | $def = "array($tabs".($tabs ? "\t" : ''); |
| 1109 | 1109 | |
| 1110 | 1110 | $n = 0; |
| 1111 | - foreach($arr as $key => $val) |
|
| 1111 | + foreach ($arr as $key => $val) |
|
| 1112 | 1112 | { |
| 1113 | 1113 | if (!is_int($key)) |
| 1114 | 1114 | { |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | } |
| 1117 | 1117 | if (is_array($val)) |
| 1118 | 1118 | { |
| 1119 | - $def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key); |
|
| 1119 | + $def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key); |
|
| 1120 | 1120 | } |
| 1121 | 1121 | else |
| 1122 | 1122 | { |
@@ -1129,7 +1129,7 @@ discard block |
||
| 1129 | 1129 | $def .= "'$val'"; |
| 1130 | 1130 | } |
| 1131 | 1131 | } |
| 1132 | - if ($n < count($arr)-1) |
|
| 1132 | + if ($n < count($arr) - 1) |
|
| 1133 | 1133 | { |
| 1134 | 1134 | $def .= ",$tabs".($tabs ? "\t" : ''); |
| 1135 | 1135 | } |
@@ -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 | { |
@@ -354,7 +375,10 @@ discard block |
||
| 354 | 375 | $system_config[] = $row; |
| 355 | 376 | } |
| 356 | 377 | } |
| 357 | - if (substr($this->db->Type,0,5) != 'mysql') $this->db->transaction_begin(); |
|
| 378 | + if (substr($this->db->Type,0,5) != 'mysql') |
|
| 379 | + { |
|
| 380 | + $this->db->transaction_begin(); |
|
| 381 | + } |
|
| 358 | 382 | |
| 359 | 383 | // drop all existing tables |
| 360 | 384 | foreach($this->adodb->MetaTables('TABLES') as $table) |
@@ -381,7 +405,7 @@ discard block |
||
| 381 | 405 | $zip = NULL; |
| 382 | 406 | $_f = NULL; |
| 383 | 407 | if($type == 'zip') |
| 384 | - { |
|
| 408 | + { |
|
| 385 | 409 | // has already been verified to be available in fopen_backup |
| 386 | 410 | $zip = new ZipArchive; |
| 387 | 411 | if(($zip->open($filename)) !== TRUE) |
@@ -406,7 +430,9 @@ discard block |
||
| 406 | 430 | } |
| 407 | 431 | $this->db_restore($f, $insert_n_rows); |
| 408 | 432 | |
| 409 | - if ($convert_to_system_charset) // store the changed charset |
|
| 433 | + if ($convert_to_system_charset) |
|
| 434 | + { |
|
| 435 | + // store the changed charset |
|
| 410 | 436 | { |
| 411 | 437 | $this->db->insert(Api\Config::TABLE, array( |
| 412 | 438 | 'config_value' => $this->schema_proc->system_charset, |
@@ -415,6 +441,7 @@ discard block |
||
| 415 | 441 | 'config_name' => 'system_charset', |
| 416 | 442 | ),__LINE__,__FILE__); |
| 417 | 443 | } |
| 444 | + } |
|
| 418 | 445 | // restore protected system config |
| 419 | 446 | if ($protect_system_config) |
| 420 | 447 | { |
@@ -509,7 +536,10 @@ discard block |
||
| 509 | 536 | { |
| 510 | 537 | $line = trim(fgets($f)); ++$n; |
| 511 | 538 | |
| 512 | - if (empty($line)) continue; |
|
| 539 | + if (empty($line)) |
|
| 540 | + { |
|
| 541 | + continue; |
|
| 542 | + } |
|
| 513 | 543 | |
| 514 | 544 | if (substr($line,0,9) == 'version: ') |
| 515 | 545 | { |
@@ -562,31 +592,49 @@ discard block |
||
| 562 | 592 | } |
| 563 | 593 | if (substr($line,0,7) == 'table: ') |
| 564 | 594 | { |
| 565 | - if ($rows) // flush pending rows of last table |
|
| 595 | + if ($rows) |
|
| 596 | + { |
|
| 597 | + // flush pending rows of last table |
|
| 566 | 598 | { |
| 567 | 599 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
| 568 | 600 | } |
| 601 | + } |
|
| 569 | 602 | $rows = array(); |
| 570 | 603 | $table = substr($line,7); |
| 571 | - if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
| 604 | + if (!isset($this->schemas[$table])) |
|
| 605 | + { |
|
| 606 | + $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
| 607 | + } |
|
| 572 | 608 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
| 573 | 609 | |
| 574 | 610 | $cols = self::csv_split($line=fgets($f)); ++$n; |
| 575 | 611 | $blobs = array(); |
| 576 | 612 | foreach($this->schemas[$table]['fd'] as $col => $data) |
| 577 | 613 | { |
| 578 | - if ($data['type'] == 'blob') $blobs[] = $col; |
|
| 614 | + if ($data['type'] == 'blob') |
|
| 615 | + { |
|
| 616 | + $blobs[] = $col; |
|
| 617 | + } |
|
| 579 | 618 | } |
| 580 | 619 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
| 581 | 620 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
| 582 | 621 | $bools = array(); |
| 583 | 622 | foreach($this->schemas[$table]['fd'] as $col => $def) |
| 584 | 623 | { |
| 585 | - if ($def['type'] === 'bool') $bools[] = $col; |
|
| 624 | + if ($def['type'] === 'bool') |
|
| 625 | + { |
|
| 626 | + $bools[] = $col; |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + if ($table == 'egw_cal_dates') |
|
| 630 | + { |
|
| 631 | + error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd'])); |
|
| 586 | 632 | } |
| 587 | - if ($table == 'egw_cal_dates') error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd'])); |
|
| 588 | 633 | |
| 589 | - if (feof($f)) break; |
|
| 634 | + if (feof($f)) |
|
| 635 | + { |
|
| 636 | + break; |
|
| 637 | + } |
|
| 590 | 638 | continue; |
| 591 | 639 | } |
| 592 | 640 | if ($convert_to_system_charset && !$this->db->capabilities['client_encoding']) |
@@ -599,9 +647,12 @@ discard block |
||
| 599 | 647 | } |
| 600 | 648 | } |
| 601 | 649 | } |
| 602 | - if ($table) // do we already reached the data part |
|
| 650 | + if ($table) |
|
| 651 | + { |
|
| 652 | + // do we already reached the data part |
|
| 603 | 653 | { |
| 604 | 654 | $import = true; |
| 655 | + } |
|
| 605 | 656 | $data = self::csv_split($line, $cols, $blobs, $bools); |
| 606 | 657 | |
| 607 | 658 | if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
@@ -637,7 +688,10 @@ discard block |
||
| 637 | 688 | { |
| 638 | 689 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
| 639 | 690 | unset($data[$insert_n_rows]); |
| 640 | - if ($auto_id) unset($data[$auto_id]); |
|
| 691 | + if ($auto_id) |
|
| 692 | + { |
|
| 693 | + unset($data[$auto_id]); |
|
| 694 | + } |
|
| 641 | 695 | $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
| 642 | 696 | } |
| 643 | 697 | else |
@@ -658,10 +712,13 @@ discard block |
||
| 658 | 712 | } |
| 659 | 713 | } |
| 660 | 714 | } |
| 661 | - if ($rows) // flush pending rows |
|
| 715 | + if ($rows) |
|
| 716 | + { |
|
| 717 | + // flush pending rows |
|
| 662 | 718 | { |
| 663 | 719 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
| 664 | 720 | } |
| 721 | + } |
|
| 665 | 722 | // updated the sequences, if the DB uses them |
| 666 | 723 | foreach($this->schemas as $table => $schema) |
| 667 | 724 | { |
@@ -719,9 +776,13 @@ discard block |
||
| 719 | 776 | while($file = $list[0]) |
| 720 | 777 | { |
| 721 | 778 | if(is_dir($file) && $file != '.' && $file != '..') |
| 722 | - self::remove_dir_content($dir.'/'.$file); |
|
| 779 | + { |
|
| 780 | + self::remove_dir_content($dir.'/'.$file); |
|
| 781 | + } |
|
| 723 | 782 | if(is_file($file) && $file != '.' && $file != '..') |
| 724 | - unlink($dir.'/'.$file); |
|
| 783 | + { |
|
| 784 | + unlink($dir.'/'.$file); |
|
| 785 | + } |
|
| 725 | 786 | array_shift($list); |
| 726 | 787 | } |
| 727 | 788 | //rmdir($dir); // dont remove own dir |
@@ -747,7 +808,9 @@ discard block |
||
| 747 | 808 | */ |
| 748 | 809 | public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
| 749 | 810 | { |
| 750 | - if (function_exists('str_getcsv')) // php5.3+ |
|
| 811 | + if (function_exists('str_getcsv')) |
|
| 812 | + { |
|
| 813 | + // php5.3+ |
|
| 751 | 814 | { |
| 752 | 815 | // we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings |
| 753 | 816 | // str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes) |
@@ -757,6 +820,7 @@ discard block |
||
| 757 | 820 | '\\"' => '""', |
| 758 | 821 | '\\n' => "\n", |
| 759 | 822 | '\\r' => "\r")), ',', '"', '\0'); |
| 823 | + } |
|
| 760 | 824 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
| 761 | 825 | foreach($fields as &$field) |
| 762 | 826 | { |
@@ -773,9 +837,12 @@ discard block |
||
| 773 | 837 | break; |
| 774 | 838 | } |
| 775 | 839 | } |
| 776 | - if ($keys) // if string keys are to be used --> combine keys and values |
|
| 840 | + if ($keys) |
|
| 841 | + { |
|
| 842 | + // if string keys are to be used --> combine keys and values |
|
| 777 | 843 | { |
| 778 | 844 | $fields = array_combine($keys, $fields); |
| 845 | + } |
|
| 779 | 846 | // base64-decode blob columns, if they are base64 encoded |
| 780 | 847 | foreach($blobs as $key) |
| 781 | 848 | { |
@@ -921,7 +988,11 @@ discard block |
||
| 921 | 988 | |
| 922 | 989 | foreach($this->schemas as $table => $schema) |
| 923 | 990 | { |
| 924 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
| 991 | + if (in_array($table,$this->exclude_tables)) |
|
| 992 | + { |
|
| 993 | + continue; |
|
| 994 | + } |
|
| 995 | + // dont backup |
|
| 925 | 996 | |
| 926 | 997 | // do we have a primary key? |
| 927 | 998 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -947,8 +1018,14 @@ discard block |
||
| 947 | 1018 | empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC', |
| 948 | 1019 | false, self::ROW_CHUNK) as $row) |
| 949 | 1020 | { |
| 950 | - if (!empty($pk)) $max = $row[$pk]; |
|
| 951 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
| 1021 | + if (!empty($pk)) |
|
| 1022 | + { |
|
| 1023 | + $max = $row[$pk]; |
|
| 1024 | + } |
|
| 1025 | + if ($total === 0) |
|
| 1026 | + { |
|
| 1027 | + fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
| 1028 | + } |
|
| 952 | 1029 | |
| 953 | 1030 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
| 954 | 1031 | fwrite($f,implode(',',$row)."\n"); |
@@ -958,17 +1035,26 @@ discard block |
||
| 958 | 1035 | } |
| 959 | 1036 | while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
| 960 | 1037 | |
| 961 | - if (!$pk) $this->db->Link_ID->RollbackLock($table); |
|
| 1038 | + if (!$pk) |
|
| 1039 | + { |
|
| 1040 | + $this->db->Link_ID->RollbackLock($table); |
|
| 1041 | + } |
|
| 962 | 1042 | } |
| 963 | - if(!$zippresent) // save without files |
|
| 1043 | + if(!$zippresent) |
|
| 1044 | + { |
|
| 1045 | + // save without files |
|
| 964 | 1046 | { |
| 965 | 1047 | if ($this->backup_files) |
| 966 | 1048 | { |
| 967 | 1049 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
| 1050 | + } |
|
| 968 | 1051 | } |
| 969 | 1052 | |
| 970 | 1053 | fclose($f); |
| 971 | - if (file_exists($name)) unlink($name); |
|
| 1054 | + if (file_exists($name)) |
|
| 1055 | + { |
|
| 1056 | + unlink($name); |
|
| 1057 | + } |
|
| 972 | 1058 | return TRUE; |
| 973 | 1059 | } |
| 974 | 1060 | // save files .... |
@@ -980,9 +1066,12 @@ discard block |
||
| 980 | 1066 | //echo substr($file,strlen($dir)+1).'<br>'; |
| 981 | 1067 | //echo $file.'<br>'; |
| 982 | 1068 | $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
| 983 | - if(($count++) == 100) { // the file descriptor limit |
|
| 1069 | + if(($count++) == 100) |
|
| 1070 | + { |
|
| 1071 | +// the file descriptor limit |
|
| 984 | 1072 | $zip->close(); |
| 985 | - if(($zip = new ZipArchive())) { |
|
| 1073 | + if(($zip = new ZipArchive())) |
|
| 1074 | + { |
|
| 986 | 1075 | $zip->open($filename); |
| 987 | 1076 | $count =0; |
| 988 | 1077 | } |
@@ -1007,15 +1096,21 @@ discard block |
||
| 1007 | 1096 | { |
| 1008 | 1097 | //chdir($f); |
| 1009 | 1098 | //echo "Processing $f <br>"; |
| 1010 | - if ($path_name =='') $path_name = $f; |
|
| 1099 | + if ($path_name =='') |
|
| 1100 | + { |
|
| 1101 | + $path_name = $f; |
|
| 1102 | + } |
|
| 1011 | 1103 | $tlist = scandir($f); |
| 1012 | 1104 | $list = array(); |
| 1013 | 1105 | $i = $cnt; |
| 1014 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
| 1106 | + while($file = $tlist[0]) |
|
| 1107 | + { |
|
| 1108 | + // remove all '.' and '..' and transfer to $list |
|
| 1015 | 1109 | { |
| 1016 | 1110 | if($file == '.' || $file == '..') |
| 1017 | 1111 | { |
| 1018 | 1112 | array_shift($tlist); |
| 1113 | + } |
|
| 1019 | 1114 | } |
| 1020 | 1115 | elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
| 1021 | 1116 | { |
@@ -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); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @var array |
| 59 | 59 | */ |
| 60 | - var $max_index_length=array( |
|
| 60 | + var $max_index_length = array( |
|
| 61 | 61 | 'maxdb' => 32, |
| 62 | 62 | 'oracle' => 30, |
| 63 | 63 | ); |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | * @param Db $db =null database class, if null we use $GLOBALS['egw']->db |
| 100 | 100 | * @return schema_proc |
| 101 | 101 | */ |
| 102 | - function __construct($dbms=False, Api\Db $db=null) |
|
| 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 | 107 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!'); |
| 115 | 115 | } |
| 116 | 116 | $this->m_odb->connect(); |
| 117 | - $this->capabilities =& $this->m_odb->capabilities; |
|
| 117 | + $this->capabilities = & $this->m_odb->capabilities; |
|
| 118 | 118 | |
| 119 | 119 | $this->sType = $dbms ? $dbms : $this->m_odb->Type; |
| 120 | 120 | $this->adodb = &$this->m_odb->Link_ID; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | // to allow some of the former translator-functions to be called, we assign ourself as the translator |
| 127 | 127 | $this->m_oTranslator = &$this; |
| 128 | 128 | |
| 129 | - switch($this->sType) |
|
| 129 | + switch ($this->sType) |
|
| 130 | 130 | { |
| 131 | 131 | case 'maxdb': |
| 132 | 132 | $this->max_varchar_length = 8000; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | if (is_object($GLOBALS['egw_setup'])) |
| 144 | 144 | { |
| 145 | - $this->system_charset =& $GLOBALS['egw_setup']->system_charset; |
|
| 145 | + $this->system_charset = & $GLOBALS['egw_setup']->system_charset; |
|
| 146 | 146 | } |
| 147 | 147 | elseif (isset($GLOBALS['egw_info']['server']['system_charset'])) |
| 148 | 148 | { |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | * @param boolean $ignore_length_limit =false should we take lenght-limits of indexes into account or not |
| 159 | 159 | * @return boolean true if index over $columns exist in the $indexes array |
| 160 | 160 | */ |
| 161 | - function _in_index($columns, $indexs, $ignore_length_limit=false) |
|
| 161 | + function _in_index($columns, $indexs, $ignore_length_limit = false) |
|
| 162 | 162 | { |
| 163 | 163 | if (is_array($columns)) |
| 164 | 164 | { |
| 165 | 165 | unset($columns['options']); |
| 166 | - $columns = implode('-',$columns); |
|
| 166 | + $columns = implode('-', $columns); |
|
| 167 | 167 | if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns); |
| 168 | 168 | } |
| 169 | - foreach($indexs as $index) |
|
| 169 | + foreach ($indexs as $index) |
|
| 170 | 170 | { |
| 171 | 171 | if (is_array($index)) |
| 172 | 172 | { |
| 173 | 173 | unset($index['options']); |
| 174 | - $index = implode('-',$index); |
|
| 174 | + $index = implode('-', $index); |
|
| 175 | 175 | } |
| 176 | 176 | if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index); |
| 177 | 177 | if ($columns == $index) return true; |
@@ -187,21 +187,21 @@ discard block |
||
| 187 | 187 | * @param bool $preserveSequence |
| 188 | 188 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
| 189 | 189 | */ |
| 190 | - function CreateTable($sTableName, $aTableDef, $preserveSequence=False) |
|
| 190 | + function CreateTable($sTableName, $aTableDef, $preserveSequence = False) |
|
| 191 | 191 | { |
| 192 | 192 | if ($this->debug) |
| 193 | 193 | { |
| 194 | - $this->debug_message('schema_proc::CreateTable(%1,%2)',False,$sTableName, $aTableDef); |
|
| 194 | + $this->debug_message('schema_proc::CreateTable(%1,%2)', False, $sTableName, $aTableDef); |
|
| 195 | 195 | } |
| 196 | 196 | // for mysql 4.0+ we set the charset for the table |
| 197 | - if ($this->system_charset && substr($this->sType,0,5) == 'mysql' && |
|
| 198 | - (float) $this->m_odb->ServerInfo['version'] >= 4.0) |
|
| 197 | + if ($this->system_charset && substr($this->sType, 0, 5) == 'mysql' && |
|
| 198 | + (float)$this->m_odb->ServerInfo['version'] >= 4.0) |
|
| 199 | 199 | { |
| 200 | 200 | $set_table_charset = array($this->sType => 'CHARACTER SET utf8'); |
| 201 | 201 | } |
| 202 | 202 | // creating the table |
| 203 | - $aSql = $this->dict->CreateTableSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef($aTableDef),$set_table_charset); |
|
| 204 | - if (!($retVal = $this->ExecuteSQLArray($aSql,2,'CreateTableSQL(%1,%2) sql=%3',False,$sTableName,$ado_cols,$aSql))) |
|
| 203 | + $aSql = $this->dict->CreateTableSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef($aTableDef), $set_table_charset); |
|
| 204 | + if (!($retVal = $this->ExecuteSQLArray($aSql, 2, 'CreateTableSQL(%1,%2) sql=%3', False, $sTableName, $ado_cols, $aSql))) |
|
| 205 | 205 | { |
| 206 | 206 | return $retVal; |
| 207 | 207 | } |
@@ -210,13 +210,13 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | if (empty($mFields)) |
| 212 | 212 | { |
| 213 | - continue; // cant create an index without fields (was observed in broken backups) |
|
| 213 | + continue; // cant create an index without fields (was observed in broken backups) |
|
| 214 | 214 | } |
| 215 | - if ($this->_in_index($mFields,array($aTableDef['pk']))) |
|
| 215 | + if ($this->_in_index($mFields, array($aTableDef['pk']))) |
|
| 216 | 216 | { |
| 217 | - continue; // is already created as primary key |
|
| 217 | + continue; // is already created as primary key |
|
| 218 | 218 | } |
| 219 | - if (!($retVal = $this->CreateIndex($sTableName,$mFields,true,'',$name))) |
|
| 219 | + if (!($retVal = $this->CreateIndex($sTableName, $mFields, true, '', $name))) |
|
| 220 | 220 | { |
| 221 | 221 | return $retVal; |
| 222 | 222 | } |
@@ -226,12 +226,12 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | if (empty($mFields)) |
| 228 | 228 | { |
| 229 | - continue; // cant create an index without fields (was observed in broken backups) |
|
| 229 | + continue; // cant create an index without fields (was observed in broken backups) |
|
| 230 | 230 | } |
| 231 | - if ($this->_in_index($mFields,array($aTableDef['pk'])) || |
|
| 232 | - $this->_in_index($mFields,$aTableDef['uc'])) |
|
| 231 | + if ($this->_in_index($mFields, array($aTableDef['pk'])) || |
|
| 232 | + $this->_in_index($mFields, $aTableDef['uc'])) |
|
| 233 | 233 | { |
| 234 | - continue; // is already created as primary key or unique index |
|
| 234 | + continue; // is already created as primary key or unique index |
|
| 235 | 235 | } |
| 236 | 236 | $options = False; |
| 237 | 237 | if (is_array($mFields)) |
@@ -240,21 +240,21 @@ discard block |
||
| 240 | 240 | { |
| 241 | 241 | if (isset($mFields['options'][$this->sType])) |
| 242 | 242 | { |
| 243 | - $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
| 244 | - if (!$options) continue; // no index for our db-type |
|
| 243 | + $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
| 244 | + if (!$options) continue; // no index for our db-type |
|
| 245 | 245 | } |
| 246 | 246 | unset($mFields['options']); |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | - foreach((array)$mFields as $k => $col) |
|
| 249 | + foreach ((array)$mFields as $k => $col) |
|
| 250 | 250 | { |
| 251 | 251 | // only create indexes on text-columns, if (db-)specifiy options are given or FULLTEXT for mysql |
| 252 | 252 | // most DB's cant do them and give errors |
| 253 | - if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext'))) |
|
| 253 | + if (in_array($aTableDef['fd'][$col]['type'], array('text', 'longtext'))) |
|
| 254 | 254 | { |
| 255 | 255 | if (is_array($mFields)) // index over multiple columns including a text column |
| 256 | 256 | { |
| 257 | - $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
| 257 | + $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
| 258 | 258 | } |
| 259 | 259 | elseif (!$options) // index over a single text column and no options given |
| 260 | 260 | { |
@@ -264,12 +264,12 @@ discard block |
||
| 264 | 264 | } |
| 265 | 265 | else |
| 266 | 266 | { |
| 267 | - continue 2; // ignore that index, 2=not just column but whole index! |
|
| 267 | + continue 2; // ignore that index, 2=not just column but whole index! |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | - if (!($retVal = $this->CreateIndex($sTableName,$mFields,false,$options,$name))) |
|
| 272 | + if (!($retVal = $this->CreateIndex($sTableName, $mFields, false, $options, $name))) |
|
| 273 | 273 | { |
| 274 | 274 | return $retVal; |
| 275 | 275 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | if (($seq = $this->_PostgresHasOldSequence($sTableName))) |
| 281 | 281 | { |
| 282 | 282 | $this->pgsql_old_seq = $this->pgsql_old_seq + 1; |
| 283 | - $this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH " . $this->pgsql_old_seq,__LINE__,__FILE__); |
|
| 283 | + $this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH ".$this->pgsql_old_seq, __LINE__, __FILE__); |
|
| 284 | 284 | } |
| 285 | 285 | $this->pgsql_old_seq = 0; |
| 286 | 286 | } |
@@ -294,9 +294,9 @@ discard block |
||
| 294 | 294 | * @param boolean $bOutputHTML should we give diagnostics, default False |
| 295 | 295 | * @return boolean True if no error, else False |
| 296 | 296 | */ |
| 297 | - function DropAllTables($aTables, $bOutputHTML=False) |
|
| 297 | + function DropAllTables($aTables, $bOutputHTML = False) |
|
| 298 | 298 | { |
| 299 | - if(!is_array($aTables) || !isset($this->m_odb)) |
|
| 299 | + if (!is_array($aTables) || !isset($this->m_odb)) |
|
| 300 | 300 | { |
| 301 | 301 | return False; |
| 302 | 302 | } |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | if ($this->debug) $bOutputHTML = True; |
| 305 | 305 | if ($bOutputHTML && !$this->debug) $this->debug = 2; |
| 306 | 306 | |
| 307 | - foreach(array_keys($aTables) as $sTableName) |
|
| 307 | + foreach (array_keys($aTables) as $sTableName) |
|
| 308 | 308 | { |
| 309 | - if($this->DropTable($sTableName)) |
|
| 309 | + if ($this->DropTable($sTableName)) |
|
| 310 | 310 | { |
| 311 | - if($bOutputHTML) |
|
| 311 | + if ($bOutputHTML) |
|
| 312 | 312 | { |
| 313 | - echo '<br>Drop Table <b>' . $sTableName . '</b>'; |
|
| 313 | + echo '<br>Drop Table <b>'.$sTableName.'</b>'; |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | else |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | $aSql = $this->dict->DropTableSql($sTableName); |
| 335 | 335 | |
| 336 | - return $this->ExecuteSQLArray($aSql,2,'DropTable(%1) sql=%2',False,$sTableName,$aSql); |
|
| 336 | + return $this->ExecuteSQLArray($aSql, 2, 'DropTable(%1) sql=%2', False, $sTableName, $aSql); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -346,14 +346,14 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | function DropColumn($sTableName, $aTableDef, $sColumnName) |
| 348 | 348 | { |
| 349 | - unset($aTableDef); // not used, but required by function signature |
|
| 349 | + unset($aTableDef); // not used, but required by function signature |
|
| 350 | 350 | |
| 351 | 351 | $table_def = $this->GetTableDefinition($sTableName); |
| 352 | 352 | unset($table_def['fd'][$sColumnName]); |
| 353 | 353 | |
| 354 | - $aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def)); |
|
| 354 | + $aSql = $this->dict->DropColumnSql($sTableName, $sColumnName, $ado_table = $this->_egw2adodb_columndef($table_def)); |
|
| 355 | 355 | |
| 356 | - return $this->ExecuteSQLArray($aSql,2,'DropColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName,$ado_table,$aSql); |
|
| 356 | + return $this->ExecuteSQLArray($aSql, 2, 'DropColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $ado_table, $aSql); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -371,12 +371,12 @@ discard block |
||
| 371 | 371 | { |
| 372 | 372 | $table_def = $this->GetTableDefinition($sOldTableName); |
| 373 | 373 | |
| 374 | - if ($this->_PostgresHasOldSequence($sOldTableName,True) || count($table_def['pk']) || |
|
| 374 | + if ($this->_PostgresHasOldSequence($sOldTableName, True) || count($table_def['pk']) || |
|
| 375 | 375 | 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 | $this->DropTable($sOldTableName)) |
| 381 | 381 | { |
| 382 | 382 | $this->adodb->CommitTrans(); |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | $aSql = $this->dict->RenameTableSQL($sOldTableName, $sNewTableName); |
| 390 | 390 | |
| 391 | - return $this->ExecuteSQLArray($aSql,2,'RenameTableSQL(%1,%2) sql=%3',False,$sOldTableName,$sNewTableName,$aSql); |
|
| 391 | + return $this->ExecuteSQLArray($aSql, 2, 'RenameTableSQL(%1,%2) sql=%3', False, $sOldTableName, $sNewTableName, $aSql); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @param bool $preserveValue |
| 399 | 399 | * @return boolean|string sequence-name or false |
| 400 | 400 | */ |
| 401 | - function _PostgresHasOldSequence($sTableName,$preserveValue=False) |
|
| 401 | + function _PostgresHasOldSequence($sTableName, $preserveValue = False) |
|
| 402 | 402 | { |
| 403 | 403 | if ($this->sType != 'pgsql') return false; |
| 404 | 404 | |
@@ -406,14 +406,14 @@ discard block |
||
| 406 | 406 | $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"); |
| 407 | 407 | |
| 408 | 408 | $matches = null; |
| 409 | - if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches)) |
|
| 409 | + if ($seq && preg_match('/^nextval\(\'(.*)\'/', $seq, $matches)) |
|
| 410 | 410 | { |
| 411 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
| 411 | + if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]); |
|
| 412 | 412 | return $matches[1]; |
| 413 | 413 | } |
| 414 | - if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches)) |
|
| 414 | + if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/', $seq2, $matches)) |
|
| 415 | 415 | { |
| 416 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
| 416 | + if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]); |
|
| 417 | 417 | return $matches[1]; |
| 418 | 418 | } |
| 419 | 419 | return false; |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | // only drop sequence, if there is no dependency on it |
| 433 | 433 | 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'")) |
| 434 | 434 | { |
| 435 | - $this->query('DROP SEQUENCE '.$seq,__LINE__,__FILE__); |
|
| 435 | + $this->query('DROP SEQUENCE '.$seq, __LINE__, __FILE__); |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | } |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $table_def = $this->GetTableDefinition($sTableName); |
| 451 | 451 | |
| 452 | 452 | // PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long |
| 453 | - if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
|
| 453 | + if ($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
|
| 454 | 454 | in_array($aColumnDef['type'], array('varchar', 'ascii')) && |
| 455 | 455 | $table_def['fd'][$sColumnName]['precision'] > $aColumnDef['precision']) |
| 456 | 456 | { |
@@ -465,12 +465,12 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | $table_def['fd'][$sColumnName] = $aColumnDef; |
| 467 | 467 | |
| 468 | - $aSql = $this->dict->AlterColumnSQL($sTableName,$ado_col = $this->_egw2adodb_columndef(array( |
|
| 468 | + $aSql = $this->dict->AlterColumnSQL($sTableName, $ado_col = $this->_egw2adodb_columndef(array( |
|
| 469 | 469 | 'fd' => array($sColumnName => $aColumnDef), |
| 470 | 470 | 'pk' => array(), |
| 471 | - )),$ado_table=$this->_egw2adodb_columndef($table_def)); |
|
| 471 | + )), $ado_table = $this->_egw2adodb_columndef($table_def)); |
|
| 472 | 472 | |
| 473 | - return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$ado_col,$ado_table,$aSql); |
|
| 473 | + return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $ado_col, $ado_table, $aSql); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | } |
| 493 | 493 | else |
| 494 | 494 | { |
| 495 | - foreach($table_def['fd'] as $col => $def) |
|
| 495 | + foreach ($table_def['fd'] as $col => $def) |
|
| 496 | 496 | { |
| 497 | 497 | if (strtolower($col) == strtolower($sOldColumnName)) |
| 498 | 498 | { |
@@ -506,9 +506,9 @@ discard block |
||
| 506 | 506 | 'pk' => array(), |
| 507 | 507 | )); |
| 508 | 508 | |
| 509 | - $aSql = $this->dict->RenameColumnSQL($sTableName,$sOldColumnName,$sNewColumnName,$col_def); |
|
| 509 | + $aSql = $this->dict->RenameColumnSQL($sTableName, $sOldColumnName, $sNewColumnName, $col_def); |
|
| 510 | 510 | |
| 511 | - return $this->ExecuteSQLArray($aSql,2,'RenameColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sOldColumnName, $sNewColumnName,$aSql); |
|
| 511 | + return $this->ExecuteSQLArray($aSql, 2, 'RenameColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sOldColumnName, $sNewColumnName, $aSql); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -521,12 +521,12 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | function AddColumn($sTableName, $sColumnName, $aColumnDef) |
| 523 | 523 | { |
| 524 | - $aSql = $this->dict->AddColumnSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef(array( |
|
| 524 | + $aSql = $this->dict->AddColumnSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef(array( |
|
| 525 | 525 | 'fd' => array($sColumnName => $aColumnDef), |
| 526 | 526 | 'pk' => array(), |
| 527 | 527 | ))); |
| 528 | 528 | |
| 529 | - return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName, $aColumnDef,$aSql); |
|
| 529 | + return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $aColumnDef, $aSql); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /** |
@@ -539,23 +539,23 @@ discard block |
||
| 539 | 539 | * @param string $sIdxName ='' name of the index, if not given (default) its created automaticaly |
| 540 | 540 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
| 541 | 541 | */ |
| 542 | - function CreateIndex($sTableName,$aColumnNames,$bUnique=false,$options='',$sIdxName='') |
|
| 542 | + function CreateIndex($sTableName, $aColumnNames, $bUnique = false, $options = '', $sIdxName = '') |
|
| 543 | 543 | { |
| 544 | 544 | // remove length limits from column names, if DB type is NOT MySQL |
| 545 | 545 | if ($this->sType != 'mysql') |
| 546 | 546 | { |
| 547 | - $aColumnNames = preg_replace('/ *\(\d+\)$/','',$aColumnNames); |
|
| 547 | + $aColumnNames = preg_replace('/ *\(\d+\)$/', '', $aColumnNames); |
|
| 548 | 548 | } |
| 549 | 549 | if (!$sIdxName || is_numeric($sIdxName)) |
| 550 | 550 | { |
| 551 | - $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
|
| 551 | + $sIdxName = $this->_index_name($sTableName, $aColumnNames); |
|
| 552 | 552 | } |
| 553 | 553 | if (!is_array($options)) $options = $options ? array($options) : array(); |
| 554 | 554 | if ($bUnique) $options[] = 'UNIQUE'; |
| 555 | 555 | |
| 556 | - $aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options); |
|
| 556 | + $aSql = $this->dict->CreateIndexSQL($sIdxName, $sTableName, $aColumnNames, $options); |
|
| 557 | 557 | |
| 558 | - return $this->ExecuteSQLArray($aSql,2,'CreateIndexSQL(%1,%2,%3,%4) sql=%5',False,$sTableName,$aColumnNames,$options,$sIdxName,$aSql); |
|
| 558 | + return $this->ExecuteSQLArray($aSql, 2, 'CreateIndexSQL(%1,%2,%3,%4) sql=%5', False, $sTableName, $aColumnNames, $options, $sIdxName, $aSql); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | * @param array|string $aColumnNames columns of the index or the name of the index |
| 566 | 566 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
| 567 | 567 | */ |
| 568 | - function DropIndex($sTableName,$aColumnNames) |
|
| 568 | + function DropIndex($sTableName, $aColumnNames) |
|
| 569 | 569 | { |
| 570 | 570 | if (is_array($aColumnNames)) |
| 571 | 571 | { |
@@ -575,13 +575,13 @@ discard block |
||
| 575 | 575 | { |
| 576 | 576 | // if MetaIndexes is not availible for the DB, we try the name the index was created with |
| 577 | 577 | // this fails if one of the columns have been renamed |
| 578 | - $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
|
| 578 | + $sIdxName = $this->_index_name($sTableName, $aColumnNames); |
|
| 579 | 579 | } |
| 580 | 580 | else |
| 581 | 581 | { |
| 582 | - foreach($indexes as $idx => $idx_data) |
|
| 582 | + foreach ($indexes as $idx => $idx_data) |
|
| 583 | 583 | { |
| 584 | - if (strtolower(implode(':',$idx_data['columns'])) == implode(':',$aColumnNames)) |
|
| 584 | + if (strtolower(implode(':', $idx_data['columns'])) == implode(':', $aColumnNames)) |
|
| 585 | 585 | { |
| 586 | 586 | $sIdxName = $idx; |
| 587 | 587 | break; |
@@ -593,13 +593,13 @@ discard block |
||
| 593 | 593 | { |
| 594 | 594 | $sIdxName = $aColumnNames; |
| 595 | 595 | } |
| 596 | - if(!$sIdxName) |
|
| 596 | + if (!$sIdxName) |
|
| 597 | 597 | { |
| 598 | 598 | return True; |
| 599 | 599 | } |
| 600 | - $aSql = $this->dict->DropIndexSQL($sIdxName,$sTableName); |
|
| 600 | + $aSql = $this->dict->DropIndexSQL($sIdxName, $sTableName); |
|
| 601 | 601 | |
| 602 | - return $this->ExecuteSQLArray($aSql,2,'DropIndexSQL(%1(%2),%3) sql=%4',False,$sIdxName,$aColumnNames,$sTableName,$aSql); |
|
| 602 | + return $this->ExecuteSQLArray($aSql, 2, 'DropIndexSQL(%1(%2),%3) sql=%4', False, $sIdxName, $aColumnNames, $sTableName, $aSql); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -607,22 +607,22 @@ discard block |
||
| 607 | 607 | * @param string $sTableName table-name |
| 608 | 608 | * @param string $sColumnName column-name, which default is set to nextval() |
| 609 | 609 | */ |
| 610 | - function UpdateSequence($sTableName,$sColumnName) |
|
| 610 | + function UpdateSequence($sTableName, $sColumnName) |
|
| 611 | 611 | { |
| 612 | - switch($this->sType) |
|
| 612 | + switch ($this->sType) |
|
| 613 | 613 | { |
| 614 | 614 | case 'pgsql': |
| 615 | 615 | // identify the sequence name, ADOdb uses a different name or it might be renamed |
| 616 | 616 | $columns = $this->dict->MetaColumns($sTableName); |
| 617 | 617 | $seq_name = 'seq_'.$sTableName; |
| 618 | 618 | $matches = null; |
| 619 | - if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$columns[strtoupper($sColumnName)]->default_value,$matches)) |
|
| 619 | + if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $columns[strtoupper($sColumnName)]->default_value, $matches)) |
|
| 620 | 620 | { |
| 621 | 621 | $seq_name = $matches[1]; |
| 622 | 622 | } |
| 623 | 623 | $sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName"; |
| 624 | - if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
| 625 | - return $this->query($sql,__LINE__,__FILE__); |
|
| 624 | + if ($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
| 625 | + return $this->query($sql, __LINE__, __FILE__); |
|
| 626 | 626 | } |
| 627 | 627 | return True; |
| 628 | 628 | } |
@@ -639,9 +639,9 @@ discard block |
||
| 639 | 639 | * @param array $aTableDef eGW table-defintion |
| 640 | 640 | * @param array|boolean $aDefaults array with default for the colums during copying, values are either (old) column-names or quoted string-literals |
| 641 | 641 | */ |
| 642 | - function RefreshTable($sTableName, $aTableDef, $aDefaults=False) |
|
| 642 | + function RefreshTable($sTableName, $aTableDef, $aDefaults = False) |
|
| 643 | 643 | { |
| 644 | - if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
| 644 | + if ($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef, False).")\n"; } |
|
| 645 | 645 | |
| 646 | 646 | $old_table_def = $this->GetTableDefinition($sTableName); |
| 647 | 647 | |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | |
| 651 | 651 | $select = array(); |
| 652 | 652 | $blob_column_included = $auto_column_included = False; |
| 653 | - foreach($aTableDef['fd'] as $name => $data) |
|
| 653 | + foreach ($aTableDef['fd'] as $name => $data) |
|
| 654 | 654 | { |
| 655 | 655 | // new auto column with no default or explicit NULL as default (can be an existing column too!) |
| 656 | 656 | if ($data['type'] == 'auto' && |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | $aDefaults && strtoupper($aDefaults[$name]) == 'NULL')) |
| 659 | 659 | { |
| 660 | 660 | $sequence_name = $sTableName.'_'.$name.'_seq'; |
| 661 | - switch($GLOBALS['egw_setup']->db->Type) |
|
| 661 | + switch ($GLOBALS['egw_setup']->db->Type) |
|
| 662 | 662 | { |
| 663 | 663 | case 'mysql': |
| 664 | 664 | $value = 'NULL'; break; |
@@ -679,25 +679,25 @@ discard block |
||
| 679 | 679 | if ($this->sType == 'pgsql') // some postgres specific code |
| 680 | 680 | { |
| 681 | 681 | // this is eg. necessary to change a varchar into an int column under postgres |
| 682 | - if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) && |
|
| 683 | - in_array($data['type'],array('int','decimal'))) |
|
| 682 | + if (in_array($old_table_def['fd'][$name]['type'], array('char', 'varchar', 'text', 'blob')) && |
|
| 683 | + in_array($data['type'], array('int', 'decimal'))) |
|
| 684 | 684 | { |
| 685 | 685 | $value = "to_number($name,'S9999999999999D99')"; |
| 686 | 686 | } |
| 687 | 687 | // blobs cant be casted to text |
| 688 | - elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
|
| 688 | + elseif ($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
|
| 689 | 689 | { |
| 690 | 690 | $value = "ENCODE($value,'escape')"; |
| 691 | 691 | } |
| 692 | 692 | // varchar or ascii column shortened, use substring to avoid error if current content is to long |
| 693 | - elseif(in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) && |
|
| 693 | + elseif (in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) && |
|
| 694 | 694 | in_array($data['type'], array('varchar', 'ascii')) && |
| 695 | 695 | $old_table_def['fd'][$name]['precision'] > $data['precision']) |
| 696 | 696 | { |
| 697 | 697 | $value = "SUBSTRING($value FROM 1 FOR ".(int)$data['precision'].')'; |
| 698 | 698 | } |
| 699 | 699 | // cast everything which is a different type |
| 700 | - elseif($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type']))) |
|
| 700 | + elseif ($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type']))) |
|
| 701 | 701 | { |
| 702 | 702 | $value = "CAST($value AS $type_translated)"; |
| 703 | 703 | } |
@@ -710,42 +710,42 @@ discard block |
||
| 710 | 710 | $value = 'NULL'; |
| 711 | 711 | } |
| 712 | 712 | // some stuff is NOT to be quoted |
| 713 | - elseif (in_array(strtoupper($data['default']),array('CURRENT_TIMESTAMP','CURRENT_DATE','NULL','NOW()'))) |
|
| 713 | + elseif (in_array(strtoupper($data['default']), array('CURRENT_TIMESTAMP', 'CURRENT_DATE', 'NULL', 'NOW()'))) |
|
| 714 | 714 | { |
| 715 | 715 | $value = $data['default']; |
| 716 | 716 | } |
| 717 | 717 | else |
| 718 | 718 | { |
| 719 | - $value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '',$data['type']); |
|
| 719 | + $value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '', $data['type']); |
|
| 720 | 720 | } |
| 721 | 721 | if ($this->sType == 'pgsql') |
| 722 | 722 | { |
| 723 | 723 | // fix for postgres error "no '<' operator for type 'unknown'" |
| 724 | - if(($type_translated = $this->TranslateType($data['type']))) |
|
| 724 | + if (($type_translated = $this->TranslateType($data['type']))) |
|
| 725 | 725 | { |
| 726 | 726 | $value = "CAST($value AS $type_translated)"; |
| 727 | 727 | } |
| 728 | 728 | } |
| 729 | 729 | } |
| 730 | - $blob_column_included = $blob_column_included || in_array($data['type'],array('blob','text','longtext')); |
|
| 730 | + $blob_column_included = $blob_column_included || in_array($data['type'], array('blob', 'text', 'longtext')); |
|
| 731 | 731 | $auto_column_included = $auto_column_included || $data['type'] == 'auto'; |
| 732 | 732 | $select[] = $value; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | $extra = ''; |
| 736 | 736 | $distinct = 'DISTINCT'; |
| 737 | - switch($this->sType) |
|
| 737 | + switch ($this->sType) |
|
| 738 | 738 | { |
| 739 | 739 | case 'mssql': |
| 740 | 740 | if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
| 741 | - if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
| 741 | + if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
| 742 | 742 | break; |
| 743 | 743 | } |
| 744 | 744 | // because of all the trouble with sequences and indexes in the global namespace, |
| 745 | 745 | // we use an additional temp. table for postgres and not rename the existing one, but drop it. |
| 746 | 746 | if ($this->sType == 'pgsql') |
| 747 | 747 | { |
| 748 | - $Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName",__LINE__,__FILE__) && |
|
| 748 | + $Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName", __LINE__, __FILE__) && |
|
| 749 | 749 | $this->DropTable($sTableName); |
| 750 | 750 | } |
| 751 | 751 | else |
@@ -755,12 +755,12 @@ discard block |
||
| 755 | 755 | { |
| 756 | 756 | $this->DropTable($tmp_name); |
| 757 | 757 | } |
| 758 | - $Ok = $this->RenameTable($sTableName,$tmp_name); |
|
| 758 | + $Ok = $this->RenameTable($sTableName, $tmp_name); |
|
| 759 | 759 | } |
| 760 | - $Ok = $Ok && $this->CreateTable($sTableName,$aTableDef) && |
|
| 761 | - $this->m_odb->query($sql_copy_data="$extra INSERT INTO $sTableName (". |
|
| 762 | - implode(',',array_keys($aTableDef['fd'])). |
|
| 763 | - ") SELEcT $distinct ".implode(',',$select)." FROM $tmp_name",__LINE__,__FILE__) && |
|
| 760 | + $Ok = $Ok && $this->CreateTable($sTableName, $aTableDef) && |
|
| 761 | + $this->m_odb->query($sql_copy_data = "$extra INSERT INTO $sTableName (". |
|
| 762 | + implode(',', array_keys($aTableDef['fd'])). |
|
| 763 | + ") SELEcT $distinct ".implode(',', $select)." FROM $tmp_name", __LINE__, __FILE__) && |
|
| 764 | 764 | $this->DropTable($tmp_name); |
| 765 | 765 | //error_log($sql_copy_data); |
| 766 | 766 | |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | // do we need to update the new sequences value ? |
| 773 | 773 | if (count($aTableDef['pk']) == 1 && $aTableDef['fd'][$aTableDef['pk'][0]]['type'] == 'auto') |
| 774 | 774 | { |
| 775 | - $this->UpdateSequence($sTableName,$aTableDef['pk'][0]); |
|
| 775 | + $this->UpdateSequence($sTableName, $aTableDef['pk'][0]); |
|
| 776 | 776 | } |
| 777 | 777 | $this->m_odb->transaction_commit(); |
| 778 | 778 | |
@@ -795,9 +795,9 @@ discard block |
||
| 795 | 795 | * @param boolean $bOutputHTML =false should we give diagnostics, default False |
| 796 | 796 | * @return boolean True on success, False if an (fatal) error occured |
| 797 | 797 | */ |
| 798 | - function ExecuteScripts($aTables, $bOutputHTML=False) |
|
| 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 | } |
@@ -805,20 +805,20 @@ discard block |
||
| 805 | 805 | if ($this->debug) $bOutputHTML = True; |
| 806 | 806 | if ($bOutputHTML && !$this->debug) $this->debug = 2; |
| 807 | 807 | |
| 808 | - foreach($aTables as $sTableName => $aTableDef) |
|
| 808 | + foreach ($aTables as $sTableName => $aTableDef) |
|
| 809 | 809 | { |
| 810 | - if($this->CreateTable($sTableName, $aTableDef)) |
|
| 810 | + if ($this->CreateTable($sTableName, $aTableDef)) |
|
| 811 | 811 | { |
| 812 | - if($bOutputHTML) |
|
| 812 | + if ($bOutputHTML) |
|
| 813 | 813 | { |
| 814 | - echo '<br>Create Table <b>' . $sTableName . '</b>'; |
|
| 814 | + echo '<br>Create Table <b>'.$sTableName.'</b>'; |
|
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | 817 | else |
| 818 | 818 | { |
| 819 | - if($bOutputHTML) |
|
| 819 | + if ($bOutputHTML) |
|
| 820 | 820 | { |
| 821 | - echo '<br>Create Table Failed For <b>' . $sTableName . '</b>'; |
|
| 821 | + echo '<br>Create Table Failed For <b>'.$sTableName.'</b>'; |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | return False; |
@@ -835,13 +835,13 @@ discard block |
||
| 835 | 835 | * @deprecated use result-set returned by query/select |
| 836 | 836 | * @return string the field value |
| 837 | 837 | */ |
| 838 | - function f($value,$strip_slashes=False) |
|
| 838 | + function f($value, $strip_slashes = False) |
|
| 839 | 839 | { |
| 840 | 840 | if (!($this->m_odb instanceof Deprecated)) |
| 841 | 841 | { |
| 842 | 842 | throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
| 843 | 843 | } |
| 844 | - return $this->m_odb->f($value,$strip_slashes); |
|
| 844 | + return $this->m_odb->f($value, $strip_slashes); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] |
| 885 | 885 | * @return ADORecordSet or false, if the query fails |
| 886 | 886 | */ |
| 887 | - function query($sQuery, $line='', $file='') |
|
| 887 | + function query($sQuery, $line = '', $file = '') |
|
| 888 | 888 | { |
| 889 | 889 | return $this->m_odb->query($sQuery, $line, $file); |
| 890 | 890 | } |
@@ -901,9 +901,9 @@ discard block |
||
| 901 | 901 | * @param string $app=false string with name of app, this need to be set in setup anyway!!! |
| 902 | 902 | * @return ADORecordSet or false, if the query fails |
| 903 | 903 | */ |
| 904 | - function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false) |
|
| 904 | + function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false) |
|
| 905 | 905 | { |
| 906 | - return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement); |
|
| 906 | + return $this->m_odb->insert($table, $data, $where, $line, $file, $app, $use_prepared_statement); |
|
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | /** |
@@ -914,14 +914,14 @@ discard block |
||
| 914 | 914 | * @param string $debug variable number of arguments for the debug_message functions in case of an error |
| 915 | 915 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
| 916 | 916 | */ |
| 917 | - function ExecuteSqlArray($aSql,$debug_level) |
|
| 917 | + function ExecuteSqlArray($aSql, $debug_level) |
|
| 918 | 918 | { |
| 919 | 919 | if ($this->m_odb->query_log) // we use Db::query to log the queries |
| 920 | 920 | { |
| 921 | 921 | $retval = 2; |
| 922 | - foreach($aSql as $sql) |
|
| 922 | + foreach ($aSql as $sql) |
|
| 923 | 923 | { |
| 924 | - if (!$this->m_odb->query($sql,__LINE__,__FILE__)) |
|
| 924 | + if (!$this->m_odb->query($sql, __LINE__, __FILE__)) |
|
| 925 | 925 | { |
| 926 | 926 | $retval = 1; |
| 927 | 927 | } |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | $debug_params = func_get_args(); |
| 937 | 937 | array_shift($debug_params); |
| 938 | 938 | array_shift($debug_params); |
| 939 | - call_user_func_array(array($this,'debug_message'),$debug_params); |
|
| 939 | + call_user_func_array(array($this, 'debug_message'), $debug_params); |
|
| 940 | 940 | if ($retval < 2 && !$this->dict->debug) |
| 941 | 941 | { |
| 942 | 942 | echo '<p><b>'.$this->adodb->ErrorMsg()."</b></p>\n"; |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | * @param $aColumnNames array of column-names or string with a single column-name |
| 958 | 958 | * @return string the index-name |
| 959 | 959 | */ |
| 960 | - function _index_name($sTableName,$aColumnNames) |
|
| 960 | + function _index_name($sTableName, $aColumnNames) |
|
| 961 | 961 | { |
| 962 | 962 | // this code creates extrem short index-names, eg. for MaxDB |
| 963 | 963 | // if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32) |
@@ -982,28 +982,28 @@ discard block |
||
| 982 | 982 | // return $name; |
| 983 | 983 | // } |
| 984 | 984 | // This code creates longer index-names incl. the table-names and the used columns |
| 985 | - $table = str_replace(array('phpgw_','egw_'),'',$sTableName); |
|
| 985 | + $table = str_replace(array('phpgw_', 'egw_'), '', $sTableName); |
|
| 986 | 986 | // if the table-name or a part of it is repeated in the column-name, remove it there |
| 987 | 987 | $remove[] = $table.'_'; |
| 988 | 988 | // also remove 3 or 4 letter shortcuts of the table- or app-name |
| 989 | - $remove[] = substr($table,0,3).'_'; |
|
| 990 | - $remove[] = substr($table,0,4).'_'; |
|
| 989 | + $remove[] = substr($table, 0, 3).'_'; |
|
| 990 | + $remove[] = substr($table, 0, 4).'_'; |
|
| 991 | 991 | // if the table-name consists of '_' limtied parts, remove occurences of these parts too |
| 992 | - foreach (explode('_',$table) as $part) |
|
| 992 | + foreach (explode('_', $table) as $part) |
|
| 993 | 993 | { |
| 994 | 994 | $remove[] = $part.'_'; |
| 995 | 995 | } |
| 996 | - $cols = str_replace($remove,'',$aColumnNames); |
|
| 996 | + $cols = str_replace($remove, '', $aColumnNames); |
|
| 997 | 997 | |
| 998 | - $name = $sTableName.'_'.(is_array($cols) ? implode('_',$cols) : $cols); |
|
| 998 | + $name = $sTableName.'_'.(is_array($cols) ? implode('_', $cols) : $cols); |
|
| 999 | 999 | // remove length limits from column names |
| 1000 | - $name = preg_replace('/ *\(\d+\)/','',$name); |
|
| 1000 | + $name = preg_replace('/ *\(\d+\)/', '', $name); |
|
| 1001 | 1001 | |
| 1002 | 1002 | // this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle |
| 1003 | 1003 | if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 || |
| 1004 | 1004 | strlen($name) >= 64) // even mysql has a limit here ;-) |
| 1005 | 1005 | { |
| 1006 | - $name = "i".substr(md5($name),0,29); |
|
| 1006 | + $name = "i".substr(md5($name), 0, 29); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | return $name; |
| 1009 | 1009 | } |
@@ -1044,19 +1044,19 @@ discard block |
||
| 1044 | 1044 | * @param $param mixed a variable number of parameters, to be inserted in $msg |
| 1045 | 1045 | * arrays get serialized with print_r() ! |
| 1046 | 1046 | */ |
| 1047 | - function debug_message($msg,$backtrace=True) |
|
| 1047 | + function debug_message($msg, $backtrace = True) |
|
| 1048 | 1048 | { |
| 1049 | - for($i = 2; $i < func_num_args(); ++$i) |
|
| 1049 | + for ($i = 2; $i < func_num_args(); ++$i) |
|
| 1050 | 1050 | { |
| 1051 | 1051 | $param = func_get_arg($i); |
| 1052 | 1052 | |
| 1053 | 1053 | if (is_null($param)) |
| 1054 | 1054 | { |
| 1055 | - $param='NULL'; |
|
| 1055 | + $param = 'NULL'; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | else |
| 1058 | 1058 | { |
| 1059 | - switch(gettype($param)) |
|
| 1059 | + switch (gettype($param)) |
|
| 1060 | 1060 | { |
| 1061 | 1061 | case 'string': |
| 1062 | 1062 | $param = "'$param'"; |
@@ -1064,15 +1064,15 @@ discard block |
||
| 1064 | 1064 | case 'array': |
| 1065 | 1065 | case 'object': |
| 1066 | 1066 | list(,$content) = @each($param); |
| 1067 | - $do_pre = is_array($param) ? count($param) > 6 || is_array($content)&&count($content) : True; |
|
| 1068 | - $param = ($do_pre ? '<pre>' : '').print_r($param,True).($do_pre ? '</pre>' : ''); |
|
| 1067 | + $do_pre = is_array($param) ? count($param) > 6 || is_array($content) && count($content) : True; |
|
| 1068 | + $param = ($do_pre ? '<pre>' : '').print_r($param, True).($do_pre ? '</pre>' : ''); |
|
| 1069 | 1069 | break; |
| 1070 | 1070 | case 'boolean': |
| 1071 | 1071 | $param = $param ? 'True' : 'False'; |
| 1072 | 1072 | break; |
| 1073 | 1073 | } |
| 1074 | 1074 | } |
| 1075 | - $msg = str_replace('%'.($i-1),$param,$msg); |
|
| 1075 | + $msg = str_replace('%'.($i - 1), $param, $msg); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | echo '<p>'.$msg."<br>\n".($backtrace ? 'Backtrace: '.function_backtrace(1)."</p>\n" : ''); |
| 1078 | 1078 | } |
@@ -1087,15 +1087,15 @@ discard block |
||
| 1087 | 1087 | function _egw2adodb_columndef($aTableDef) |
| 1088 | 1088 | { |
| 1089 | 1089 | $ado_defs = array(); |
| 1090 | - foreach($aTableDef['fd'] as $col => $col_data) |
|
| 1090 | + foreach ($aTableDef['fd'] as $col => $col_data) |
|
| 1091 | 1091 | { |
| 1092 | 1092 | $ado_col = False; |
| 1093 | 1093 | |
| 1094 | - switch($col_data['type']) |
|
| 1094 | + switch ($col_data['type']) |
|
| 1095 | 1095 | { |
| 1096 | 1096 | case 'auto': |
| 1097 | 1097 | $ado_col = 'I AUTOINCREMENT NOTNULL'; |
| 1098 | - unset($col_data['nullable']); // else we set it twice |
|
| 1098 | + unset($col_data['nullable']); // else we set it twice |
|
| 1099 | 1099 | break; |
| 1100 | 1100 | case 'blob': |
| 1101 | 1101 | $ado_col = 'B'; |
@@ -1108,11 +1108,11 @@ discard block |
||
| 1108 | 1108 | case 'ascii': |
| 1109 | 1109 | case 'varchar': |
| 1110 | 1110 | $ado_col = "C"; |
| 1111 | - if(0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length) |
|
| 1111 | + if (0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length) |
|
| 1112 | 1112 | { |
| 1113 | 1113 | $ado_col .= "($col_data[precision])"; |
| 1114 | 1114 | } |
| 1115 | - if($col_data['precision'] > $this->max_varchar_length) |
|
| 1115 | + if ($col_data['precision'] > $this->max_varchar_length) |
|
| 1116 | 1116 | { |
| 1117 | 1117 | $ado_col = 'X'; |
| 1118 | 1118 | } |
@@ -1124,7 +1124,7 @@ discard block |
||
| 1124 | 1124 | case 'date': |
| 1125 | 1125 | $ado_col = 'D'; |
| 1126 | 1126 | // allow to use now() beside current_date, as Postgres backups contain it and it's easier to remember anyway |
| 1127 | - if (in_array($col_data['default'],array('current_date','now()'))) |
|
| 1127 | + if (in_array($col_data['default'], array('current_date', 'now()'))) |
|
| 1128 | 1128 | { |
| 1129 | 1129 | $ado_col .= ' DEFDATE'; |
| 1130 | 1130 | unset($col_data['default']); |
@@ -1140,7 +1140,7 @@ discard block |
||
| 1140 | 1140 | break; |
| 1141 | 1141 | case 'int': |
| 1142 | 1142 | $ado_col = 'I'; |
| 1143 | - switch($col_data['precision']) |
|
| 1143 | + switch ($col_data['precision']) |
|
| 1144 | 1144 | { |
| 1145 | 1145 | case 1: |
| 1146 | 1146 | case 2: |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | case 'timestamp': |
| 1160 | 1160 | $ado_col = 'T'; |
| 1161 | 1161 | // allow to use now() beside current_timestamp, as Postgres backups contain it and it's easier to remember anyway |
| 1162 | - if (in_array($col_data['default'],array('current_timestamp','now()'))) |
|
| 1162 | + if (in_array($col_data['default'], array('current_timestamp', 'now()'))) |
|
| 1163 | 1163 | { |
| 1164 | 1164 | $ado_col .= ' DEFTIMESTAMP'; |
| 1165 | 1165 | unset($col_data['default']); |
@@ -1177,17 +1177,17 @@ discard block |
||
| 1177 | 1177 | } |
| 1178 | 1178 | if (isset($col_data['default'])) |
| 1179 | 1179 | { |
| 1180 | - $ado_col .= (in_array($col_data['type'],array('bool','int','decimal','float','double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : ''). |
|
| 1181 | - ' DEFAULT '.$this->m_odb->quote($col_data['default'],$col_data['type']); |
|
| 1180 | + $ado_col .= (in_array($col_data['type'], array('bool', 'int', 'decimal', 'float', 'double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : ''). |
|
| 1181 | + ' DEFAULT '.$this->m_odb->quote($col_data['default'], $col_data['type']); |
|
| 1182 | 1182 | } |
| 1183 | - if (in_array($col,$aTableDef['pk'])) |
|
| 1183 | + if (in_array($col, $aTableDef['pk'])) |
|
| 1184 | 1184 | { |
| 1185 | 1185 | $ado_col .= ' PRIMARY'; |
| 1186 | 1186 | } |
| 1187 | - $ado_defs[] = $col . ' ' . $ado_col; |
|
| 1187 | + $ado_defs[] = $col.' '.$ado_col; |
|
| 1188 | 1188 | } |
| 1189 | 1189 | //print_r($aTableDef); echo implode(",\n",$ado_defs)."\n"; |
| 1190 | - return implode(",\n",$ado_defs); |
|
| 1190 | + return implode(",\n", $ado_defs); |
|
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | /** |
@@ -1203,7 +1203,7 @@ discard block |
||
| 1203 | 1203 | 'pk' => array(), |
| 1204 | 1204 | )); |
| 1205 | 1205 | $matches = null; |
| 1206 | - return preg_match('/test ([A-Z0-9]+)/i',$ado_col,$matches) ? $this->dict->ActualType($matches[1]) : false; |
|
| 1206 | + return preg_match('/test ([A-Z0-9]+)/i', $ado_col, $matches) ? $this->dict->ActualType($matches[1]) : false; |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | /** |
@@ -1219,7 +1219,7 @@ discard block |
||
| 1219 | 1219 | // MetaType returns all varchar >= blobSize as blob, it's by default 100, which is wrong |
| 1220 | 1220 | $this->dict->blobSize = $this->max_varchar_length; |
| 1221 | 1221 | |
| 1222 | - if (!method_exists($this->dict,'MetaColumns') || |
|
| 1222 | + if (!method_exists($this->dict, 'MetaColumns') || |
|
| 1223 | 1223 | !($columns = $this->dict->MetaColumns($sTableName))) |
| 1224 | 1224 | { |
| 1225 | 1225 | return False; |
@@ -1232,11 +1232,11 @@ discard block |
||
| 1232 | 1232 | 'uc' => array(), |
| 1233 | 1233 | ); |
| 1234 | 1234 | //echo "$sTableName: <pre>".print_r($columns,true)."</pre>"; |
| 1235 | - foreach($columns as $column) |
|
| 1235 | + foreach ($columns as $column) |
|
| 1236 | 1236 | { |
| 1237 | 1237 | $name = $this->capabilities['name_case'] == 'upper' ? strtolower($column->name) : $column->name; |
| 1238 | 1238 | |
| 1239 | - $type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
|
| 1239 | + $type = method_exists($this->dict, 'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
|
| 1240 | 1240 | |
| 1241 | 1241 | // fix longtext not correctly handled by ADOdb |
| 1242 | 1242 | if ($type == 'X' && $column->type == 'longtext') $type = 'XL'; |
@@ -1258,11 +1258,11 @@ discard block |
||
| 1258 | 1258 | ); |
| 1259 | 1259 | $definition['fd'][$name]['type'] = $ado_type2egw[$type]; |
| 1260 | 1260 | |
| 1261 | - switch($type) |
|
| 1261 | + switch ($type) |
|
| 1262 | 1262 | { |
| 1263 | 1263 | case 'D': case 'T': |
| 1264 | 1264 | // detecting the automatic timestamps again |
| 1265 | - if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i',$column->default_value)) |
|
| 1265 | + if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i', $column->default_value)) |
|
| 1266 | 1266 | { |
| 1267 | 1267 | $column->default_value = $type == 'D' ? 'current_date' : 'current_timestamp'; |
| 1268 | 1268 | } |
@@ -1289,10 +1289,10 @@ discard block |
||
| 1289 | 1289 | $column->auto_increment = true; |
| 1290 | 1290 | // fall-through |
| 1291 | 1291 | case 'I': case 'I1': case 'I2': case 'I4': case 'I8': |
| 1292 | - switch($type) |
|
| 1292 | + switch ($type) |
|
| 1293 | 1293 | { |
| 1294 | 1294 | case 'I1': case 'I2': case 'I4': case 'I8': |
| 1295 | - $definition['fd'][$name]['precision'] = (int) $type[1]; |
|
| 1295 | + $definition['fd'][$name]['precision'] = (int)$type[1]; |
|
| 1296 | 1296 | break; |
| 1297 | 1297 | default: |
| 1298 | 1298 | if ($column->max_length > 11) |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | $definition['fd'][$name]['type'] = 'int'; |
| 1329 | 1329 | // detect postgres type-spec and remove it |
| 1330 | 1330 | $matches = null; |
| 1331 | - if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/',$column->default_value,$matches)) |
|
| 1331 | + if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/', $column->default_value, $matches)) |
|
| 1332 | 1332 | { |
| 1333 | 1333 | $definition['fd'][$name]['default'] = $matches[1]; |
| 1334 | 1334 | $column->has_default = False; |
@@ -1346,7 +1346,7 @@ discard block |
||
| 1346 | 1346 | } |
| 1347 | 1347 | if ($column->has_default) |
| 1348 | 1348 | { |
| 1349 | - if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) // postgres |
|
| 1349 | + if (preg_match("/^'(.*)'::.*$/", $column->default_value, $matches)) // postgres |
|
| 1350 | 1350 | { |
| 1351 | 1351 | $column->default_value = $matches[1]; |
| 1352 | 1352 | } |
@@ -1356,18 +1356,18 @@ discard block |
||
| 1356 | 1356 | { |
| 1357 | 1357 | $definition['fd'][$name]['nullable'] = False; |
| 1358 | 1358 | } |
| 1359 | - if ($column->primary_key && !in_array($name,$definition['pk'])) |
|
| 1359 | + if ($column->primary_key && !in_array($name, $definition['pk'])) |
|
| 1360 | 1360 | { |
| 1361 | 1361 | $definition['pk'][] = $name; |
| 1362 | 1362 | } |
| 1363 | 1363 | } |
| 1364 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
| 1364 | + if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2", False, $sTableName, $columns); |
|
| 1365 | 1365 | |
| 1366 | 1366 | // not all DB's (odbc) return the primary keys via MetaColumns |
| 1367 | - if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') && |
|
| 1367 | + if (!count($definition['pk']) && method_exists($this->dict, 'MetaPrimaryKeys') && |
|
| 1368 | 1368 | is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary)) |
| 1369 | 1369 | { |
| 1370 | - if($this->capabilities['name_case'] == 'upper') |
|
| 1370 | + if ($this->capabilities['name_case'] == 'upper') |
|
| 1371 | 1371 | { |
| 1372 | 1372 | array_walk($primary, function(&$s) |
| 1373 | 1373 | { |
@@ -1376,10 +1376,10 @@ discard block |
||
| 1376 | 1376 | } |
| 1377 | 1377 | $definition['pk'] = $primary; |
| 1378 | 1378 | } |
| 1379 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
| 1379 | + if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2", False, $sTableName, $primary); |
|
| 1380 | 1380 | |
| 1381 | 1381 | $this->GetIndexes($sTableName, $definition); |
| 1382 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
| 1382 | + if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2", False, $sTableName, $definition); |
|
| 1383 | 1383 | |
| 1384 | 1384 | return $definition; |
| 1385 | 1385 | } |
@@ -1391,35 +1391,35 @@ discard block |
||
| 1391 | 1391 | * @param array& $definition=array() |
| 1392 | 1392 | * @return array of arrays with keys 'ix' and 'uc' |
| 1393 | 1393 | */ |
| 1394 | - public function GetIndexes($sTableName, array &$definition=array()) |
|
| 1394 | + public function GetIndexes($sTableName, array &$definition = array()) |
|
| 1395 | 1395 | { |
| 1396 | - if (method_exists($this->dict,'MetaIndexes') && |
|
| 1396 | + if (method_exists($this->dict, 'MetaIndexes') && |
|
| 1397 | 1397 | is_array($indexes = $this->dict->MetaIndexes($sTableName)) && count($indexes)) |
| 1398 | 1398 | { |
| 1399 | - foreach($indexes as $index) |
|
| 1399 | + foreach ($indexes as $index) |
|
| 1400 | 1400 | { |
| 1401 | 1401 | // append (optional) length of index in brackets to column |
| 1402 | - foreach((array)$index['length'] as $col => $length) |
|
| 1402 | + foreach ((array)$index['length'] as $col => $length) |
|
| 1403 | 1403 | { |
| 1404 | 1404 | if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')'; |
| 1405 | 1405 | } |
| 1406 | - if($this->capabilities['name_case'] == 'upper') |
|
| 1406 | + if ($this->capabilities['name_case'] == 'upper') |
|
| 1407 | 1407 | { |
| 1408 | 1408 | array_walk($index['columns'], function(&$s) |
| 1409 | 1409 | { |
| 1410 | 1410 | $s = strtolower($s); |
| 1411 | 1411 | }); |
| 1412 | 1412 | } |
| 1413 | - if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) || |
|
| 1414 | - $index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk']))) |
|
| 1413 | + if (count($definition['pk']) && (implode(':', $definition['pk']) == implode(':', $index['columns']) || |
|
| 1414 | + $index['unique'] && count(array_intersect($definition['pk'], $index['columns'])) == count($definition['pk']))) |
|
| 1415 | 1415 | { |
| 1416 | - continue; // is already the primary key => ignore it |
|
| 1416 | + continue; // is already the primary key => ignore it |
|
| 1417 | 1417 | } |
| 1418 | 1418 | $kind = $index['unique'] ? 'uc' : 'ix'; |
| 1419 | 1419 | |
| 1420 | 1420 | $definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0]; |
| 1421 | 1421 | } |
| 1422 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
| 1422 | + if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2", False, $sTableName, $indexes); |
|
| 1423 | 1423 | } |
| 1424 | 1424 | return $definition; |
| 1425 | 1425 | } |
@@ -1431,7 +1431,7 @@ discard block |
||
| 1431 | 1431 | */ |
| 1432 | 1432 | function CheckCreateIndexes() |
| 1433 | 1433 | { |
| 1434 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
| 1434 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
| 1435 | 1435 | { |
| 1436 | 1436 | if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue; |
| 1437 | 1437 | |
@@ -1439,9 +1439,9 @@ discard block |
||
| 1439 | 1439 | $this->GetIndexes($table, $definition); |
| 1440 | 1440 | |
| 1441 | 1441 | // iterate though indexes we should have according to tables_current |
| 1442 | - foreach(array('uc', 'ix') as $type) |
|
| 1442 | + foreach (array('uc', 'ix') as $type) |
|
| 1443 | 1443 | { |
| 1444 | - foreach($table_def[$type] as $columns) |
|
| 1444 | + foreach ($table_def[$type] as $columns) |
|
| 1445 | 1445 | { |
| 1446 | 1446 | // sometimes primary key is listed as (unique) index too --> ignore it |
| 1447 | 1447 | if ($this->_in_index($columns, array($table_def['pk']), true)) continue; |
@@ -1472,27 +1472,26 @@ discard block |
||
| 1472 | 1472 | * old translator function, use GetTableDefition() instead |
| 1473 | 1473 | * @depricated |
| 1474 | 1474 | */ |
| 1475 | - function _GetColumns($oProc,$sTableName,&$sColumns) |
|
| 1475 | + function _GetColumns($oProc, $sTableName, &$sColumns) |
|
| 1476 | 1476 | { |
| 1477 | - unset($oProc); // unused, but required by function signature |
|
| 1477 | + unset($oProc); // unused, but required by function signature |
|
| 1478 | 1478 | $this->sCol = $this->pk = $this->fk = $this->ix = $this->uc = array(); |
| 1479 | 1479 | |
| 1480 | 1480 | $tabledef = $this->GetTableDefinition($sTableName); |
| 1481 | 1481 | |
| 1482 | - $sColumns = implode(',',array_keys($tabledef['fd'])); |
|
| 1482 | + $sColumns = implode(',', array_keys($tabledef['fd'])); |
|
| 1483 | 1483 | |
| 1484 | - foreach($tabledef['fd'] as $column => $data) |
|
| 1484 | + foreach ($tabledef['fd'] as $column => $data) |
|
| 1485 | 1485 | { |
| 1486 | 1486 | $col_def = "'type' => '$data[type]'"; |
| 1487 | 1487 | unset($data['type']); |
| 1488 | - foreach($data as $key => $val) |
|
| 1488 | + foreach ($data as $key => $val) |
|
| 1489 | 1489 | { |
| 1490 | - $col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : |
|
| 1491 | - (is_int($val) ? $val : "'$val'")); |
|
| 1490 | + $col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : (is_int($val) ? $val : "'$val'")); |
|
| 1492 | 1491 | } |
| 1493 | 1492 | $this->sCol[] = "\t\t\t\t'$column' => array($col_def),\n"; |
| 1494 | 1493 | } |
| 1495 | - foreach(array('pk','fk','ix','uc') as $kind) |
|
| 1494 | + foreach (array('pk', 'fk', 'ix', 'uc') as $kind) |
|
| 1496 | 1495 | { |
| 1497 | 1496 | $this->$kind = $tabledef[$kind]; |
| 1498 | 1497 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | function __construct($dbms=False, Api\Db $db=null) |
| 103 | 103 | { |
| 104 | 104 | if(is_object($db)) |
| 105 | - { |
|
| 105 | + { |
|
| 106 | 106 | $this->m_odb = $db; |
| 107 | 107 | } |
| 108 | 108 | else |
@@ -121,7 +121,10 @@ discard block |
||
| 121 | 121 | $this->dict = NewDataDictionary($this->adodb); |
| 122 | 122 | |
| 123 | 123 | // enable the debuging in ADOdb's datadictionary if the debug-level is greater then 1 |
| 124 | - if ($this->debug > 1) $this->dict->debug = True; |
|
| 124 | + if ($this->debug > 1) |
|
| 125 | + { |
|
| 126 | + $this->dict->debug = True; |
|
| 127 | + } |
|
| 125 | 128 | |
| 126 | 129 | // to allow some of the former translator-functions to be called, we assign ourself as the translator |
| 127 | 130 | $this->m_oTranslator = &$this; |
@@ -164,7 +167,10 @@ discard block |
||
| 164 | 167 | { |
| 165 | 168 | unset($columns['options']); |
| 166 | 169 | $columns = implode('-',$columns); |
| 167 | - if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns); |
|
| 170 | + if ($ignore_length_limit) |
|
| 171 | + { |
|
| 172 | + $columns = preg_replace('/\(\d+\)/', '', $columns); |
|
| 173 | + } |
|
| 168 | 174 | } |
| 169 | 175 | foreach($indexs as $index) |
| 170 | 176 | { |
@@ -173,8 +179,14 @@ discard block |
||
| 173 | 179 | unset($index['options']); |
| 174 | 180 | $index = implode('-',$index); |
| 175 | 181 | } |
| 176 | - if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index); |
|
| 177 | - if ($columns == $index) return true; |
|
| 182 | + if ($ignore_length_limit) |
|
| 183 | + { |
|
| 184 | + $index = preg_replace('/\(\d+\)/', '', $index); |
|
| 185 | + } |
|
| 186 | + if ($columns == $index) |
|
| 187 | + { |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 178 | 190 | } |
| 179 | 191 | return false; |
| 180 | 192 | } |
@@ -236,12 +248,20 @@ discard block |
||
| 236 | 248 | $options = False; |
| 237 | 249 | if (is_array($mFields)) |
| 238 | 250 | { |
| 239 | - if (isset($mFields['options'])) // array sets additional options |
|
| 251 | + if (isset($mFields['options'])) |
|
| 252 | + { |
|
| 253 | + // array sets additional options |
|
| 240 | 254 | { |
| 241 | 255 | if (isset($mFields['options'][$this->sType])) |
| 242 | 256 | { |
| 243 | - $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
| 244 | - if (!$options) continue; // no index for our db-type |
|
| 257 | + $options = $mFields['options'][$this->sType]; |
|
| 258 | + } |
|
| 259 | + // db-specific options, eg. index-type |
|
| 260 | + if (!$options) |
|
| 261 | + { |
|
| 262 | + continue; |
|
| 263 | + } |
|
| 264 | + // no index for our db-type |
|
| 245 | 265 | } |
| 246 | 266 | unset($mFields['options']); |
| 247 | 267 | } |
@@ -252,15 +272,22 @@ discard block |
||
| 252 | 272 | // most DB's cant do them and give errors |
| 253 | 273 | if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext'))) |
| 254 | 274 | { |
| 255 | - if (is_array($mFields)) // index over multiple columns including a text column |
|
| 275 | + if (is_array($mFields)) |
|
| 276 | + { |
|
| 277 | + // index over multiple columns including a text column |
|
| 256 | 278 | { |
| 257 | - $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
| 279 | + $mFields[$k] .= '(32)'; |
|
| 258 | 280 | } |
| 259 | - elseif (!$options) // index over a single text column and no options given |
|
| 281 | + // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
| 282 | + } |
|
| 283 | + elseif (!$options) |
|
| 284 | + { |
|
| 285 | + // index over a single text column and no options given |
|
| 260 | 286 | { |
| 261 | 287 | if ($this->sType == 'mysql') |
| 262 | 288 | { |
| 263 | 289 | $options = 'FULLTEXT'; |
| 290 | + } |
|
| 264 | 291 | } |
| 265 | 292 | else |
| 266 | 293 | { |
@@ -301,8 +328,14 @@ discard block |
||
| 301 | 328 | return False; |
| 302 | 329 | } |
| 303 | 330 | // set our debug-mode or $bOutputHTML is the other one is set |
| 304 | - if ($this->debug) $bOutputHTML = True; |
|
| 305 | - if ($bOutputHTML && !$this->debug) $this->debug = 2; |
|
| 331 | + if ($this->debug) |
|
| 332 | + { |
|
| 333 | + $bOutputHTML = True; |
|
| 334 | + } |
|
| 335 | + if ($bOutputHTML && !$this->debug) |
|
| 336 | + { |
|
| 337 | + $this->debug = 2; |
|
| 338 | + } |
|
| 306 | 339 | |
| 307 | 340 | foreach(array_keys($aTables) as $sTableName) |
| 308 | 341 | { |
@@ -329,7 +362,10 @@ discard block |
||
| 329 | 362 | */ |
| 330 | 363 | function DropTable($sTableName) |
| 331 | 364 | { |
| 332 | - if ($this->sType == 'pgsql') $this->_PostgresTestDropOldSequence($sTableName); |
|
| 365 | + if ($this->sType == 'pgsql') |
|
| 366 | + { |
|
| 367 | + $this->_PostgresTestDropOldSequence($sTableName); |
|
| 368 | + } |
|
| 333 | 369 | |
| 334 | 370 | $aSql = $this->dict->DropTableSql($sTableName); |
| 335 | 371 | |
@@ -400,7 +436,10 @@ discard block |
||
| 400 | 436 | */ |
| 401 | 437 | function _PostgresHasOldSequence($sTableName,$preserveValue=False) |
| 402 | 438 | { |
| 403 | - if ($this->sType != 'pgsql') return false; |
|
| 439 | + if ($this->sType != 'pgsql') |
|
| 440 | + { |
|
| 441 | + return false; |
|
| 442 | + } |
|
| 404 | 443 | |
| 405 | 444 | $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"); |
| 406 | 445 | $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"); |
@@ -408,12 +447,18 @@ discard block |
||
| 408 | 447 | $matches = null; |
| 409 | 448 | if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches)) |
| 410 | 449 | { |
| 411 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
| 450 | + if ($preserveValue) |
|
| 451 | + { |
|
| 452 | + $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
| 453 | + } |
|
| 412 | 454 | return $matches[1]; |
| 413 | 455 | } |
| 414 | 456 | if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches)) |
| 415 | 457 | { |
| 416 | - 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 | + } |
|
| 417 | 462 | return $matches[1]; |
| 418 | 463 | } |
| 419 | 464 | return false; |
@@ -550,8 +595,14 @@ discard block |
||
| 550 | 595 | { |
| 551 | 596 | $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
| 552 | 597 | } |
| 553 | - if (!is_array($options)) $options = $options ? array($options) : array(); |
|
| 554 | - if ($bUnique) $options[] = 'UNIQUE'; |
|
| 598 | + if (!is_array($options)) |
|
| 599 | + { |
|
| 600 | + $options = $options ? array($options) : array(); |
|
| 601 | + } |
|
| 602 | + if ($bUnique) |
|
| 603 | + { |
|
| 604 | + $options[] = 'UNIQUE'; |
|
| 605 | + } |
|
| 555 | 606 | |
| 556 | 607 | $aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options); |
| 557 | 608 | |
@@ -621,7 +672,9 @@ discard block |
||
| 621 | 672 | $seq_name = $matches[1]; |
| 622 | 673 | } |
| 623 | 674 | $sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName"; |
| 624 | - if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
| 675 | + if($this->debug) |
|
| 676 | + { |
|
| 677 | +echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
| 625 | 678 | return $this->query($sql,__LINE__,__FILE__); |
| 626 | 679 | } |
| 627 | 680 | return True; |
@@ -641,7 +694,9 @@ discard block |
||
| 641 | 694 | */ |
| 642 | 695 | function RefreshTable($sTableName, $aTableDef, $aDefaults=False) |
| 643 | 696 | { |
| 644 | - if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
| 697 | + if($this->debug) |
|
| 698 | + { |
|
| 699 | +echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
| 645 | 700 | |
| 646 | 701 | $old_table_def = $this->GetTableDefinition($sTableName); |
| 647 | 702 | |
@@ -668,21 +723,30 @@ discard block |
||
| 668 | 723 | $value = "nextval('$sequence_name')"; break; |
| 669 | 724 | } |
| 670 | 725 | } |
| 671 | - elseif ($aDefaults && isset($aDefaults[$name])) // use given default |
|
| 726 | + elseif ($aDefaults && isset($aDefaults[$name])) |
|
| 727 | + { |
|
| 728 | + // use given default |
|
| 672 | 729 | { |
| 673 | 730 | $value = $aDefaults[$name]; |
| 674 | 731 | } |
| 675 | - elseif (isset($old_table_def['fd'][$name])) // existing column, use its value => column-name in query |
|
| 732 | + } |
|
| 733 | + elseif (isset($old_table_def['fd'][$name])) |
|
| 734 | + { |
|
| 735 | + // existing column, use its value => column-name in query |
|
| 676 | 736 | { |
| 677 | 737 | $value = $name; |
| 738 | + } |
|
| 678 | 739 | |
| 679 | - if ($this->sType == 'pgsql') // some postgres specific code |
|
| 740 | + if ($this->sType == 'pgsql') |
|
| 741 | + { |
|
| 742 | + // some postgres specific code |
|
| 680 | 743 | { |
| 681 | 744 | // this is eg. necessary to change a varchar into an int column under postgres |
| 682 | 745 | if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) && |
| 683 | 746 | in_array($data['type'],array('int','decimal'))) |
| 684 | 747 | { |
| 685 | 748 | $value = "to_number($name,'S9999999999999D99')"; |
| 749 | + } |
|
| 686 | 750 | } |
| 687 | 751 | // blobs cant be casted to text |
| 688 | 752 | elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
@@ -737,8 +801,15 @@ discard block |
||
| 737 | 801 | switch($this->sType) |
| 738 | 802 | { |
| 739 | 803 | case 'mssql': |
| 740 | - if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
|
| 741 | - if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
| 804 | + if ($auto_column_included) |
|
| 805 | + { |
|
| 806 | + $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
|
| 807 | + } |
|
| 808 | + if ($blob_column_included) |
|
| 809 | + { |
|
| 810 | + $distinct = ''; |
|
| 811 | + } |
|
| 812 | + // no distinct on blob-columns |
|
| 742 | 813 | break; |
| 743 | 814 | } |
| 744 | 815 | // because of all the trouble with sequences and indexes in the global namespace, |
@@ -802,8 +873,14 @@ discard block |
||
| 802 | 873 | return False; |
| 803 | 874 | } |
| 804 | 875 | // set our debug-mode or $bOutputHTML is the other one is set |
| 805 | - if ($this->debug) $bOutputHTML = True; |
|
| 806 | - if ($bOutputHTML && !$this->debug) $this->debug = 2; |
|
| 876 | + if ($this->debug) |
|
| 877 | + { |
|
| 878 | + $bOutputHTML = True; |
|
| 879 | + } |
|
| 880 | + if ($bOutputHTML && !$this->debug) |
|
| 881 | + { |
|
| 882 | + $this->debug = 2; |
|
| 883 | + } |
|
| 807 | 884 | |
| 808 | 885 | foreach($aTables as $sTableName => $aTableDef) |
| 809 | 886 | { |
@@ -916,9 +993,12 @@ discard block |
||
| 916 | 993 | */ |
| 917 | 994 | function ExecuteSqlArray($aSql,$debug_level) |
| 918 | 995 | { |
| 919 | - if ($this->m_odb->query_log) // we use Db::query to log the queries |
|
| 996 | + if ($this->m_odb->query_log) |
|
| 997 | + { |
|
| 998 | + // we use Db::query to log the queries |
|
| 920 | 999 | { |
| 921 | 1000 | $retval = 2; |
| 1001 | + } |
|
| 922 | 1002 | foreach($aSql as $sql) |
| 923 | 1003 | { |
| 924 | 1004 | if (!$this->m_odb->query($sql,__LINE__,__FILE__)) |
@@ -1001,10 +1081,13 @@ discard block |
||
| 1001 | 1081 | |
| 1002 | 1082 | // this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle |
| 1003 | 1083 | if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 || |
| 1004 | - strlen($name) >= 64) // even mysql has a limit here ;-) |
|
| 1084 | + strlen($name) >= 64) |
|
| 1085 | + { |
|
| 1086 | + // even mysql has a limit here ;-) |
|
| 1005 | 1087 | { |
| 1006 | 1088 | $name = "i".substr(md5($name),0,29); |
| 1007 | 1089 | } |
| 1090 | + } |
|
| 1008 | 1091 | return $name; |
| 1009 | 1092 | } |
| 1010 | 1093 | |
@@ -1239,7 +1322,10 @@ discard block |
||
| 1239 | 1322 | $type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
| 1240 | 1323 | |
| 1241 | 1324 | // fix longtext not correctly handled by ADOdb |
| 1242 | - if ($type == 'X' && $column->type == 'longtext') $type = 'XL'; |
|
| 1325 | + if ($type == 'X' && $column->type == 'longtext') |
|
| 1326 | + { |
|
| 1327 | + $type = 'XL'; |
|
| 1328 | + } |
|
| 1243 | 1329 | |
| 1244 | 1330 | static $ado_type2egw = array( |
| 1245 | 1331 | 'C' => 'varchar', |
@@ -1346,10 +1432,13 @@ discard block |
||
| 1346 | 1432 | } |
| 1347 | 1433 | if ($column->has_default) |
| 1348 | 1434 | { |
| 1349 | - if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) // postgres |
|
| 1435 | + if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) |
|
| 1436 | + { |
|
| 1437 | + // postgres |
|
| 1350 | 1438 | { |
| 1351 | 1439 | $column->default_value = $matches[1]; |
| 1352 | 1440 | } |
| 1441 | + } |
|
| 1353 | 1442 | $definition['fd'][$name]['default'] = $column->default_value; |
| 1354 | 1443 | } |
| 1355 | 1444 | if ($column->not_null) |
@@ -1361,7 +1450,10 @@ discard block |
||
| 1361 | 1450 | $definition['pk'][] = $name; |
| 1362 | 1451 | } |
| 1363 | 1452 | } |
| 1364 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
| 1453 | + if ($this->debug > 2) |
|
| 1454 | + { |
|
| 1455 | + $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
| 1456 | + } |
|
| 1365 | 1457 | |
| 1366 | 1458 | // not all DB's (odbc) return the primary keys via MetaColumns |
| 1367 | 1459 | if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') && |
@@ -1376,10 +1468,16 @@ discard block |
||
| 1376 | 1468 | } |
| 1377 | 1469 | $definition['pk'] = $primary; |
| 1378 | 1470 | } |
| 1379 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
| 1471 | + if ($this->debug > 1) |
|
| 1472 | + { |
|
| 1473 | + $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
| 1474 | + } |
|
| 1380 | 1475 | |
| 1381 | 1476 | $this->GetIndexes($sTableName, $definition); |
| 1382 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
| 1477 | + if ($this->debug > 1) |
|
| 1478 | + { |
|
| 1479 | + $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
| 1480 | + } |
|
| 1383 | 1481 | |
| 1384 | 1482 | return $definition; |
| 1385 | 1483 | } |
@@ -1401,7 +1499,10 @@ discard block |
||
| 1401 | 1499 | // append (optional) length of index in brackets to column |
| 1402 | 1500 | foreach((array)$index['length'] as $col => $length) |
| 1403 | 1501 | { |
| 1404 | - if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')'; |
|
| 1502 | + if (($key = array_search($col, $index['columns']))) |
|
| 1503 | + { |
|
| 1504 | + $index['columns'][$key] .= '('.$length.')'; |
|
| 1505 | + } |
|
| 1405 | 1506 | } |
| 1406 | 1507 | if($this->capabilities['name_case'] == 'upper') |
| 1407 | 1508 | { |
@@ -1419,7 +1520,10 @@ discard block |
||
| 1419 | 1520 | |
| 1420 | 1521 | $definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0]; |
| 1421 | 1522 | } |
| 1422 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
| 1523 | + if ($this->debug > 2) |
|
| 1524 | + { |
|
| 1525 | + $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
| 1526 | + } |
|
| 1423 | 1527 | } |
| 1424 | 1528 | return $definition; |
| 1425 | 1529 | } |
@@ -1433,7 +1537,10 @@ discard block |
||
| 1433 | 1537 | { |
| 1434 | 1538 | foreach($this->adodb->MetaTables('TABLES') as $table) |
| 1435 | 1539 | { |
| 1436 | - if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue; |
|
| 1540 | + if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) |
|
| 1541 | + { |
|
| 1542 | + continue; |
|
| 1543 | + } |
|
| 1437 | 1544 | |
| 1438 | 1545 | $definition = array(); |
| 1439 | 1546 | $this->GetIndexes($table, $definition); |
@@ -1444,7 +1551,10 @@ discard block |
||
| 1444 | 1551 | foreach($table_def[$type] as $columns) |
| 1445 | 1552 | { |
| 1446 | 1553 | // sometimes primary key is listed as (unique) index too --> ignore it |
| 1447 | - if ($this->_in_index($columns, array($table_def['pk']), true)) continue; |
|
| 1554 | + if ($this->_in_index($columns, array($table_def['pk']), true)) |
|
| 1555 | + { |
|
| 1556 | + continue; |
|
| 1557 | + } |
|
| 1448 | 1558 | |
| 1449 | 1559 | // check if they exist in real table and create them if not |
| 1450 | 1560 | if (!$this->_in_index($columns, $definition[$type]) && |
@@ -1455,7 +1565,10 @@ discard block |
||
| 1455 | 1565 | if ($this->_in_index($columns, $definition[$type], true)) |
| 1456 | 1566 | { |
| 1457 | 1567 | // for PostgreSQL we dont use length-limited indexes --> nothing to do |
| 1458 | - if ($this->m_odb->Type == 'pgsql') continue; |
|
| 1568 | + if ($this->m_odb->Type == 'pgsql') |
|
| 1569 | + { |
|
| 1570 | + continue; |
|
| 1571 | + } |
|
| 1459 | 1572 | // for MySQL we drop current index and create it with correct length |
| 1460 | 1573 | $this->DropIndex($table, $columns); |
| 1461 | 1574 | } |
@@ -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 | } |
@@ -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 | */ |
@@ -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(isset($extras[0]) ? $extras : array($extras) as $extra) |
|
| 116 | + foreach (isset($extras[0]) ? $extras : array($extras) as $extra) |
|
| 117 | 117 | { |
| 118 | 118 | if ($extra['data'] && is_array($extra['data'])) |
| 119 | 119 | { |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $output_mode = 0; |
| 144 | 144 | self::$response = Json\Response::get(); |
| 145 | 145 | } |
| 146 | - self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup |
|
| 146 | + self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup |
|
| 147 | 147 | self::$request->content = self::$cont = $content; |
| 148 | 148 | self::$request->changes = $changes; |
| 149 | 149 | self::$request->sel_options = is_array($sel_options) ? self::fix_sel_options($sel_options) : array(); |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | // compile required translations translations |
| 168 | 168 | $currentapp = $GLOBALS['egw_info']['flags']['currentapp']; |
| 169 | - $langRequire = array('common' => array(), 'etemplate' => array()); // keep that order |
|
| 170 | - foreach(Translation::$loaded_apps as $l_app => $lang) |
|
| 169 | + $langRequire = array('common' => array(), 'etemplate' => array()); // keep that order |
|
| 170 | + foreach (Translation::$loaded_apps as $l_app => $lang) |
|
| 171 | 171 | { |
| 172 | 172 | if (!in_array($l_app, array($currentapp, 'custom'))) |
| 173 | 173 | { |
| 174 | 174 | $langRequire[$l_app] = array('app' => $l_app, 'lang' => $lang, 'etag' => Translation::etag($l_app, $lang)); |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | - foreach(array($currentapp, 'custom') as $l_app) |
|
| 177 | + foreach (array($currentapp, 'custom') as $l_app) |
|
| 178 | 178 | { |
| 179 | 179 | if (isset(Translation::$loaded_apps[$l_app])) |
| 180 | 180 | { |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | ); |
| 196 | 196 | |
| 197 | 197 | // Info required to load the etemplate client-side |
| 198 | - $dom_id = str_replace('.','-',$this->dom_id); |
|
| 198 | + $dom_id = str_replace('.', '-', $this->dom_id); |
|
| 199 | 199 | $load_array = array( |
| 200 | 200 | 'name' => $this->name, |
| 201 | 201 | 'url' => self::rel2url($this->rel_path), |
@@ -205,16 +205,16 @@ discard block |
||
| 205 | 205 | if (self::$response) // call is within an ajax event / form submit |
| 206 | 206 | { |
| 207 | 207 | //error_log("Ajax " . __LINE__); |
| 208 | - self::$response->generic('et2_load', $load_array+Framework::get_extra()); |
|
| 209 | - Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
| 208 | + self::$response->generic('et2_load', $load_array + Framework::get_extra()); |
|
| 209 | + Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
| 210 | 210 | } |
| 211 | 211 | else // first call |
| 212 | 212 | { |
| 213 | 213 | // check if application of template has a app.js file --> load it |
| 214 | - list($app) = explode('.',$this->name); |
|
| 214 | + list($app) = explode('.', $this->name); |
|
| 215 | 215 | if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js')) |
| 216 | 216 | { |
| 217 | - Framework::includeJS('.','app',$app,false); |
|
| 217 | + Framework::includeJS('.', 'app', $app, false); |
|
| 218 | 218 | } |
| 219 | 219 | // Category styles |
| 220 | 220 | Categories::css($app); |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | $content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n". |
| 233 | 233 | '<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>'; |
| 234 | 234 | // add server-side page-generation times |
| 235 | - if($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time']) |
|
| 235 | + if ($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time']) |
|
| 236 | 236 | { |
| 237 | 237 | $vars = $GLOBALS['egw']->framework->_get_footer(); |
| 238 | 238 | $content .= "\n".$vars['page_generation_time']; |
| 239 | 239 | } |
| 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 | } |
@@ -285,10 +285,10 @@ discard block |
||
| 285 | 285 | */ |
| 286 | 286 | static protected function fix_sel_options(array $sel_options) |
| 287 | 287 | { |
| 288 | - foreach($sel_options as &$options) |
|
| 288 | + foreach ($sel_options as &$options) |
|
| 289 | 289 | { |
| 290 | - if (!is_array($options)||empty($options)) continue; |
|
| 291 | - foreach($options as $key => $value) |
|
| 290 | + if (!is_array($options) || empty($options)) continue; |
|
| 291 | + foreach ($options as $key => $value) |
|
| 292 | 292 | { |
| 293 | 293 | if (is_numeric($key) && (!is_array($value) || !isset($value['value']))) |
| 294 | 294 | { |
@@ -324,9 +324,9 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | // Set current app for validation |
| 327 | - list($app) = explode('.',self::$request->method); |
|
| 328 | - if(!$app) list($app) = explode('::',self::$request->method); |
|
| 329 | - if($app) |
|
| 327 | + list($app) = explode('.', self::$request->method); |
|
| 328 | + if (!$app) list($app) = explode('::', self::$request->method); |
|
| 329 | + if ($app) |
|
| 330 | 330 | { |
| 331 | 331 | Translation::add_app($app); |
| 332 | 332 | $GLOBALS['egw_info']['flags']['currentapp'] = $app; |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | $expand = array( |
| 336 | 336 | 'cont' => &self::$request->content, |
| 337 | 337 | ); |
| 338 | - $template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
| 338 | + $template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
| 339 | 339 | |
| 340 | 340 | if ($no_validation) |
| 341 | 341 | { |
@@ -351,14 +351,14 @@ discard block |
||
| 351 | 351 | // tell request call to remove request, if it is not modified eg. by call to exec in callback |
| 352 | 352 | self::$request->remove_if_not_modified(); |
| 353 | 353 | |
| 354 | - foreach(Hooks::process(array( |
|
| 354 | + foreach (Hooks::process(array( |
|
| 355 | 355 | 'hook_location' => 'etemplate2_before_process', |
| 356 | 356 | 'location_name' => $template->id, |
| 357 | 357 | ) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras) |
| 358 | 358 | { |
| 359 | 359 | if (!$extras) continue; |
| 360 | 360 | |
| 361 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
|
| 361 | + foreach (isset($extras[0]) ? $extras : array($extras) as $extra) |
|
| 362 | 362 | { |
| 363 | 363 | if ($extra['data'] && is_array($extra['data'])) |
| 364 | 364 | { |
@@ -371,8 +371,7 @@ discard block |
||
| 371 | 371 | //error_log(' validated='.array2string($validated)); |
| 372 | 372 | $content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated)); |
| 373 | 373 | |
| 374 | - $tcontent = is_array($content) ? $content : |
|
| 375 | - self::complete_array_merge(self::$request->preserv, $validated); |
|
| 374 | + $tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated); |
|
| 376 | 375 | |
| 377 | 376 | $hook_data = Hooks::process( |
| 378 | 377 | array( |
@@ -384,11 +383,11 @@ discard block |
||
| 384 | 383 | |
| 385 | 384 | if (is_array($content)) |
| 386 | 385 | { |
| 387 | - foreach($hook_data as $extras) |
|
| 386 | + foreach ($hook_data as $extras) |
|
| 388 | 387 | { |
| 389 | 388 | if (!$extras) continue; |
| 390 | 389 | |
| 391 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
| 390 | + foreach (isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
| 392 | 391 | if ($extra['data'] && is_array($extra['data'])) { |
| 393 | 392 | $content = array_merge($content, $extra['data']); |
| 394 | 393 | } |
@@ -400,7 +399,7 @@ discard block |
||
| 400 | 399 | if (isset($GLOBALS['egw_info']['flags']['java_script'])) |
| 401 | 400 | { |
| 402 | 401 | // Strip out any script tags |
| 403 | - $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']); |
|
| 402 | + $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']); |
|
| 404 | 403 | self::$response->script($GLOBALS['egw_info']['flags']['java_script']); |
| 405 | 404 | //error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.'); |
| 406 | 405 | } |
@@ -429,7 +428,7 @@ discard block |
||
| 429 | 428 | static public function process_exec() |
| 430 | 429 | { |
| 431 | 430 | if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']); |
| 432 | - $content = json_decode($_POST['value'],true); |
|
| 431 | + $content = json_decode($_POST['value'], true); |
|
| 433 | 432 | //error_log(__METHOD__."(".array2string($content).")"); |
| 434 | 433 | |
| 435 | 434 | self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']); |
@@ -443,7 +442,7 @@ discard block |
||
| 443 | 442 | $expand = array( |
| 444 | 443 | 'cont' => &self::$request->content, |
| 445 | 444 | ); |
| 446 | - $template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
| 445 | + $template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
| 447 | 446 | if (self::validation_errors(self::$request->ignore_validation)) |
| 448 | 447 | { |
| 449 | 448 | error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors)); |
@@ -479,7 +478,7 @@ discard block |
||
| 479 | 478 | * |
| 480 | 479 | * @ToDo supported customized templates stored in DB |
| 481 | 480 | */ |
| 482 | - public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='') |
|
| 481 | + public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '') |
|
| 483 | 482 | { |
| 484 | 483 | |
| 485 | 484 | // For mobile experience try to load custom mobile templates |
@@ -488,9 +487,9 @@ discard block |
||
| 488 | 487 | $template_set = "mobile"; |
| 489 | 488 | } |
| 490 | 489 | |
| 491 | - unset($lang); unset($group); // not used, but in old signature |
|
| 492 | - $this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set, |
|
| 493 | - $this->version=$version, $this->laod_via = $load_via); |
|
| 490 | + unset($lang); unset($group); // not used, but in old signature |
|
| 491 | + $this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set, |
|
| 492 | + $this->version = $version, $this->laod_via = $load_via); |
|
| 494 | 493 | //error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path)); |
| 495 | 494 | |
| 496 | 495 | $this->dom_id = $name; |
@@ -533,7 +532,7 @@ discard block |
||
| 533 | 532 | * @return mixed reference to attribute, usually NULL |
| 534 | 533 | * @deprecated use getElementAttribute($name, $attr) |
| 535 | 534 | */ |
| 536 | - public function &get_cell_attribute($name,$attr) |
|
| 535 | + public function &get_cell_attribute($name, $attr) |
|
| 537 | 536 | { |
| 538 | 537 | return self::getElementAttribute($name, $attr); |
| 539 | 538 | } |
@@ -547,7 +546,7 @@ discard block |
||
| 547 | 546 | * @return reference to attribute |
| 548 | 547 | * @deprecated use setElementAttribute($name, $attr, $val) |
| 549 | 548 | */ |
| 550 | - public function &set_cell_attribute($name,$attr,$val) |
|
| 549 | + public function &set_cell_attribute($name, $attr, $val) |
|
| 551 | 550 | { |
| 552 | 551 | return self::setElementAttribute($name, $attr, $val); |
| 553 | 552 | } |
@@ -560,7 +559,7 @@ discard block |
||
| 560 | 559 | * @return reference to attribute |
| 561 | 560 | * @deprecated use disableElement($name, $disabled=true) |
| 562 | 561 | */ |
| 563 | - public function disable_cells($name,$disabled=True) |
|
| 562 | + public function disable_cells($name, $disabled = True) |
|
| 564 | 563 | { |
| 565 | 564 | return self::disableElement($name, $disabled); |
| 566 | 565 | } |
@@ -576,23 +575,23 @@ discard block |
||
| 576 | 575 | * @param array $new |
| 577 | 576 | * @return array the merged array |
| 578 | 577 | */ |
| 579 | - public static function complete_array_merge($old,$new) |
|
| 578 | + public static function complete_array_merge($old, $new) |
|
| 580 | 579 | { |
| 581 | 580 | if (is_array($new)) |
| 582 | 581 | { |
| 583 | - if (!is_array($old)) $old = (array) $old; |
|
| 582 | + if (!is_array($old)) $old = (array)$old; |
|
| 584 | 583 | |
| 585 | - foreach($new as $k => $v) |
|
| 584 | + foreach ($new as $k => $v) |
|
| 586 | 585 | { |
| 587 | - if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
|
| 588 | - isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1]) || // or no associative array, eg. selecting multiple accounts |
|
| 586 | + if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
|
| 587 | + isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts |
|
| 589 | 588 | is_array($v) && count($v) == 0) // Empty array replacing non-empty |
| 590 | 589 | { |
| 591 | 590 | $old[$k] = $v; |
| 592 | 591 | } |
| 593 | 592 | else |
| 594 | 593 | { |
| 595 | - $old[$k] = self::complete_array_merge($old[$k],$v); |
|
| 594 | + $old[$k] = self::complete_array_merge($old[$k], $v); |
|
| 596 | 595 | } |
| 597 | 596 | } |
| 598 | 597 | } |
@@ -604,7 +603,7 @@ discard block |
||
| 604 | 603 | * |
| 605 | 604 | * @param array $content =null |
| 606 | 605 | */ |
| 607 | - public function debug(array $content=null) |
|
| 606 | + public function debug(array $content = null) |
|
| 608 | 607 | { |
| 609 | 608 | $GLOBALS['egw']->framework->render(print_r($content, true)); |
| 610 | 609 | } |
@@ -618,11 +617,11 @@ discard block |
||
| 618 | 617 | * @param int &$max_upload=null on return max. upload size in byte |
| 619 | 618 | * @return string |
| 620 | 619 | */ |
| 621 | - static function max_upload_size_message(&$max_upload=null) |
|
| 620 | + static function max_upload_size_message(&$max_upload = null) |
|
| 622 | 621 | { |
| 623 | 622 | $upload_max_filesize = ini_get('upload_max_filesize'); |
| 624 | 623 | $post_max_size = ini_get('post_max_size'); |
| 625 | - $max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800); |
|
| 624 | + $max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800); |
|
| 626 | 625 | |
| 627 | 626 | return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload). |
| 628 | 627 | " (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)"; |
@@ -636,9 +635,9 @@ discard block |
||
| 636 | 635 | * @param boolean $readonly =true |
| 637 | 636 | * @return string |
| 638 | 637 | */ |
| 639 | - static public function number_format($number,$num_decimal_places=2,$readonly=true) |
|
| 638 | + static public function number_format($number, $num_decimal_places = 2, $readonly = true) |
|
| 640 | 639 | { |
| 641 | - static $dec_separator=null,$thousands_separator=null; |
|
| 640 | + static $dec_separator = null, $thousands_separator = null; |
|
| 642 | 641 | if (is_null($dec_separator)) |
| 643 | 642 | { |
| 644 | 643 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
@@ -647,7 +646,7 @@ discard block |
||
| 647 | 646 | } |
| 648 | 647 | if ((string)$number === '') return ''; |
| 649 | 648 | |
| 650 | - return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : ''); |
|
| 649 | + return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : ''); |
|
| 651 | 650 | } |
| 652 | 651 | |
| 653 | 652 | /** |
@@ -660,13 +659,13 @@ discard block |
||
| 660 | 659 | { |
| 661 | 660 | if (!is_numeric($size)) |
| 662 | 661 | { |
| 663 | - switch(strtolower(substr($size,-1))) |
|
| 662 | + switch (strtolower(substr($size, -1))) |
|
| 664 | 663 | { |
| 665 | 664 | case 'm': |
| 666 | - $size = 1024*1024*(int)$size; |
|
| 665 | + $size = 1024 * 1024 * (int)$size; |
|
| 667 | 666 | break; |
| 668 | 667 | case 'k': |
| 669 | - $size = 1024*(int)$size; |
|
| 668 | + $size = 1024 * (int)$size; |
|
| 670 | 669 | break; |
| 671 | 670 | } |
| 672 | 671 | } |
@@ -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(isset($extras[0]) ? $extras : array($extras) as $extra) |
| 117 | 130 | { |
@@ -136,7 +149,10 @@ discard block |
||
| 136 | 149 | // Include the etemplate2 javascript code |
| 137 | 150 | Framework::includeJS('etemplate', 'etemplate2', 'api'); |
| 138 | 151 | |
| 139 | - if (!$this->rel_path) throw new Exception\AssertionFailed("No (valid) template '$this->name' found!"); |
|
| 152 | + if (!$this->rel_path) |
|
| 153 | + { |
|
| 154 | + throw new Exception\AssertionFailed("No (valid) template '$this->name' found!"); |
|
| 155 | + } |
|
| 140 | 156 | |
| 141 | 157 | if ($output_mode == 4) |
| 142 | 158 | { |
@@ -151,14 +167,23 @@ discard block |
||
| 151 | 167 | self::$request->preserv = $preserv ? $preserv : array(); |
| 152 | 168 | self::$request->method = $method; |
| 153 | 169 | self::$request->ignore_validation = $ignore_validation; |
| 154 | - if (self::$request->output_mode == -1) self::$request->output_mode = 0; |
|
| 170 | + if (self::$request->output_mode == -1) |
|
| 171 | + { |
|
| 172 | + self::$request->output_mode = 0; |
|
| 173 | + } |
|
| 155 | 174 | self::$request->template = $this->as_array(); |
| 156 | 175 | |
| 157 | - if (empty($this->name)) throw new Exception\AssertionFailed("Template name is not set '$this->name' !"); |
|
| 176 | + if (empty($this->name)) |
|
| 177 | + { |
|
| 178 | + throw new Exception\AssertionFailed("Template name is not set '$this->name' !"); |
|
| 179 | + } |
|
| 158 | 180 | // instanciate template to fill self::$request->sel_options for select-* widgets |
| 159 | 181 | // 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 | 182 | $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."); |
|
| 183 | + if (!$template) |
|
| 184 | + { |
|
| 185 | + throw new Exception\AssertionFailed("Template $this->name not instanciable! Maybe you forgot to rename template id."); |
|
| 186 | + } |
|
| 162 | 187 | $template->run('beforeSendToClient', array('', array('cont'=>$content))); |
| 163 | 188 | |
| 164 | 189 | // some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings |
@@ -202,10 +227,13 @@ discard block |
||
| 202 | 227 | 'data' => $data, |
| 203 | 228 | 'DOMNodeID' => $dom_id, |
| 204 | 229 | ); |
| 205 | - if (self::$response) // call is within an ajax event / form submit |
|
| 230 | + if (self::$response) |
|
| 231 | + { |
|
| 232 | + // call is within an ajax event / form submit |
|
| 206 | 233 | { |
| 207 | 234 | //error_log("Ajax " . __LINE__); |
| 208 | 235 | self::$response->generic('et2_load', $load_array+Framework::get_extra()); |
| 236 | + } |
|
| 209 | 237 | Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
| 210 | 238 | } |
| 211 | 239 | else // first call |
@@ -287,7 +315,10 @@ discard block |
||
| 287 | 315 | { |
| 288 | 316 | foreach($sel_options as &$options) |
| 289 | 317 | { |
| 290 | - if (!is_array($options)||empty($options)) continue; |
|
| 318 | + if (!is_array($options)||empty($options)) |
|
| 319 | + { |
|
| 320 | + continue; |
|
| 321 | + } |
|
| 291 | 322 | foreach($options as $key => $value) |
| 292 | 323 | { |
| 293 | 324 | if (is_numeric($key) && (!is_array($value) || !isset($value['value']))) |
@@ -325,7 +356,10 @@ discard block |
||
| 325 | 356 | |
| 326 | 357 | // Set current app for validation |
| 327 | 358 | list($app) = explode('.',self::$request->method); |
| 328 | - if(!$app) list($app) = explode('::',self::$request->method); |
|
| 359 | + if(!$app) |
|
| 360 | + { |
|
| 361 | + list($app) = explode('::',self::$request->method); |
|
| 362 | + } |
|
| 329 | 363 | if($app) |
| 330 | 364 | { |
| 331 | 365 | Translation::add_app($app); |
@@ -356,7 +390,10 @@ discard block |
||
| 356 | 390 | 'location_name' => $template->id, |
| 357 | 391 | ) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras) |
| 358 | 392 | { |
| 359 | - if (!$extras) continue; |
|
| 393 | + if (!$extras) |
|
| 394 | + { |
|
| 395 | + continue; |
|
| 396 | + } |
|
| 360 | 397 | |
| 361 | 398 | foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
| 362 | 399 | { |
@@ -386,10 +423,15 @@ discard block |
||
| 386 | 423 | { |
| 387 | 424 | foreach($hook_data as $extras) |
| 388 | 425 | { |
| 389 | - if (!$extras) continue; |
|
| 426 | + if (!$extras) |
|
| 427 | + { |
|
| 428 | + continue; |
|
| 429 | + } |
|
| 390 | 430 | |
| 391 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
| 392 | - if ($extra['data'] && is_array($extra['data'])) { |
|
| 431 | + foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
|
| 432 | + { |
|
| 433 | + if ($extra['data'] && is_array($extra['data'])) |
|
| 434 | + { |
|
| 393 | 435 | $content = array_merge($content, $extra['data']); |
| 394 | 436 | } |
| 395 | 437 | } |
@@ -428,7 +470,10 @@ discard block |
||
| 428 | 470 | */ |
| 429 | 471 | static public function process_exec() |
| 430 | 472 | { |
| 431 | - if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']); |
|
| 473 | + if (get_magic_quotes_gpc()) |
|
| 474 | + { |
|
| 475 | + $_POST['value'] = stripslashes($_POST['value']); |
|
| 476 | + } |
|
| 432 | 477 | $content = json_decode($_POST['value'],true); |
| 433 | 478 | //error_log(__METHOD__."(".array2string($content).")"); |
| 434 | 479 | |
@@ -580,16 +625,22 @@ discard block |
||
| 580 | 625 | { |
| 581 | 626 | if (is_array($new)) |
| 582 | 627 | { |
| 583 | - if (!is_array($old)) $old = (array) $old; |
|
| 628 | + if (!is_array($old)) |
|
| 629 | + { |
|
| 630 | + $old = (array) $old; |
|
| 631 | + } |
|
| 584 | 632 | |
| 585 | 633 | foreach($new as $k => $v) |
| 586 | 634 | { |
| 587 | 635 | if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
| 588 | 636 | isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1]) || // or no associative array, eg. selecting multiple accounts |
| 589 | - is_array($v) && count($v) == 0) // Empty array replacing non-empty |
|
| 637 | + is_array($v) && count($v) == 0) |
|
| 638 | + { |
|
| 639 | + // Empty array replacing non-empty |
|
| 590 | 640 | { |
| 591 | 641 | $old[$k] = $v; |
| 592 | 642 | } |
| 643 | + } |
|
| 593 | 644 | else |
| 594 | 645 | { |
| 595 | 646 | $old[$k] = self::complete_array_merge($old[$k],$v); |
@@ -642,10 +693,16 @@ discard block |
||
| 642 | 693 | if (is_null($dec_separator)) |
| 643 | 694 | { |
| 644 | 695 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
| 645 | - if (empty($dec_separator)) $dec_separator = '.'; |
|
| 696 | + if (empty($dec_separator)) |
|
| 697 | + { |
|
| 698 | + $dec_separator = '.'; |
|
| 699 | + } |
|
| 646 | 700 | $thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1]; |
| 647 | 701 | } |
| 648 | - if ((string)$number === '') return ''; |
|
| 702 | + if ((string)$number === '') |
|
| 703 | + { |
|
| 704 | + return ''; |
|
| 705 | + } |
|
| 649 | 706 | |
| 650 | 707 | return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : ''); |
| 651 | 708 | } |
@@ -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 | $template->run('beforeSendToClient', array('', array('cont'=>$content))); |
| 163 | 163 | |
| 164 | 164 | // some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings |
@@ -155,7 +155,7 @@ |
||
| 155 | 155 | * |
| 156 | 156 | * @param string|XMLReader $xml |
| 157 | 157 | * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object |
| 158 | - * @return Template current object or clone, if any attribute was set |
|
| 158 | + * @return Widget current object or clone, if any attribute was set |
|
| 159 | 159 | */ |
| 160 | 160 | public function set_attrs($xml, $cloned=true) |
| 161 | 161 | { |
@@ -903,12 +903,12 @@ |
||
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
| 906 | - * Check if we have not ignored validation errors |
|
| 907 | - * |
|
| 908 | - * @param string $ignore_validation ='' if not empty regular expression for validation-errors to ignore |
|
| 909 | - * @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars |
|
| 910 | - * @return boolean true if there are not ignored validation errors, false otherwise |
|
| 911 | - */ |
|
| 906 | + * Check if we have not ignored validation errors |
|
| 907 | + * |
|
| 908 | + * @param string $ignore_validation ='' if not empty regular expression for validation-errors to ignore |
|
| 909 | + * @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars |
|
| 910 | + * @return boolean true if there are not ignored validation errors, false otherwise |
|
| 911 | + */ |
|
| 912 | 912 | public static function validation_errors($ignore_validation='',$cname='') |
| 913 | 913 | { |
| 914 | 914 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | $this->id = $reader->getAttribute('id'); |
| 100 | 100 | |
| 101 | 101 | // Update content? |
| 102 | - if(self::$cont == null) |
|
| 102 | + if (self::$cont == null) |
|
| 103 | 103 | self::$cont = is_array(self::$request->content) ? self::$request->content : array(); |
| 104 | - if($this->id && is_array(self::$cont[$this->id])) |
|
| 104 | + if ($this->id && is_array(self::$cont[$this->id])) |
|
| 105 | 105 | { |
| 106 | 106 | $old_cont = self::$cont; |
| 107 | 107 | self::$cont = self::$cont[$this->id]; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | // read all attributes |
| 111 | 111 | $this->set_attrs($reader); |
| 112 | 112 | |
| 113 | - while($reader->read() && $reader->depth > $depth) |
|
| 113 | + while ($reader->read() && $reader->depth > $depth) |
|
| 114 | 114 | { |
| 115 | 115 | if ($reader->nodeType == XMLReader::ELEMENT && $reader->depth > $depth) |
| 116 | 116 | { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Reset content as we leave |
| 122 | - if($old_cont) { |
|
| 122 | + if ($old_cont) { |
|
| 123 | 123 | self::$cont = $old_cont; |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object |
| 158 | 158 | * @return Template current object or clone, if any attribute was set |
| 159 | 159 | */ |
| 160 | - public function set_attrs($xml, $cloned=true) |
|
| 160 | + public function set_attrs($xml, $cloned = true) |
|
| 161 | 161 | { |
| 162 | 162 | $reader = self::get_reader($xml); |
| 163 | 163 | |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | // read and set all attributes |
| 176 | 176 | $template = $this; |
| 177 | - while($reader->moveToNextAttribute()) |
|
| 177 | + while ($reader->moveToNextAttribute()) |
|
| 178 | 178 | { |
| 179 | 179 | if ($reader->name != 'id' && $template->attr[$reader->name] != $reader->value) |
| 180 | 180 | { |
| 181 | 181 | if (!$cloned) |
| 182 | 182 | { |
| 183 | 183 | $template = clone($this); |
| 184 | - $cloned = true; // only clone it once, otherwise we loose attributes! |
|
| 184 | + $cloned = true; // only clone it once, otherwise we loose attributes! |
|
| 185 | 185 | } |
| 186 | 186 | // $reader->value is an object and therefore assigned by reference |
| 187 | 187 | // this is important to not loose content when validating dynamic generated tabs as in settings! |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | if ($legacy_options && $reader->name == 'options') |
| 199 | 199 | { |
| 200 | 200 | $legacy_options = explode(',', $legacy_options); |
| 201 | - foreach(self::csv_split($value, count($legacy_options)) as $n => $val) |
|
| 201 | + foreach (self::csv_split($value, count($legacy_options)) as $n => $val) |
|
| 202 | 202 | { |
| 203 | 203 | if ($legacy_options[$n] && (string)$val !== '') $template->attrs[$legacy_options[$n]] = $val; |
| 204 | 204 | } |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | // Add in anything in the modification array |
| 210 | - if(is_array(self::$request->modifications[$this->id])) |
|
| 210 | + if (is_array(self::$request->modifications[$this->id])) |
|
| 211 | 211 | { |
| 212 | - $this->attrs = array_merge($this->attrs,self::$request->modifications[$this->id]); |
|
| 212 | + $this->attrs = array_merge($this->attrs, self::$request->modifications[$this->id]); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | return $template; |
@@ -230,32 +230,32 @@ discard block |
||
| 230 | 230 | * @param string $enclosure ='"' |
| 231 | 231 | * @return array |
| 232 | 232 | */ |
| 233 | - public static function csv_split($str,$num=null,$delimiter=',',$enclosure='"') |
|
| 233 | + public static function csv_split($str, $num = null, $delimiter = ',', $enclosure = '"') |
|
| 234 | 234 | { |
| 235 | - if (strpos($str,$enclosure) === false) |
|
| 235 | + if (strpos($str, $enclosure) === false) |
|
| 236 | 236 | { |
| 237 | - return is_null($num) ? explode($delimiter,$str) : explode($delimiter,$str,$num); // no need to run this more expensive code |
|
| 237 | + return is_null($num) ? explode($delimiter, $str) : explode($delimiter, $str, $num); // no need to run this more expensive code |
|
| 238 | 238 | } |
| 239 | - $parts = explode($delimiter,$str); |
|
| 240 | - for($n = 0; isset($parts[$n]); ++$n) |
|
| 239 | + $parts = explode($delimiter, $str); |
|
| 240 | + for ($n = 0; isset($parts[$n]); ++$n) |
|
| 241 | 241 | { |
| 242 | - $part =& $parts[$n]; |
|
| 242 | + $part = & $parts[$n]; |
|
| 243 | 243 | if ($part[0] === $enclosure) |
| 244 | 244 | { |
| 245 | - while (isset($parts[$n+1]) && substr($part,-1) !== $enclosure) |
|
| 245 | + while (isset($parts[$n + 1]) && substr($part, -1) !== $enclosure) |
|
| 246 | 246 | { |
| 247 | 247 | $part .= $delimiter.$parts[++$n]; |
| 248 | 248 | unset($parts[$n]); |
| 249 | 249 | } |
| 250 | - $part = substr(str_replace($enclosure.$enclosure,$enclosure,$part),1,-1); |
|
| 250 | + $part = substr(str_replace($enclosure.$enclosure, $enclosure, $part), 1, -1); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | - $parts_renum = array_values($parts); // renumber the parts (in case we had to concat them) |
|
| 253 | + $parts_renum = array_values($parts); // renumber the parts (in case we had to concat them) |
|
| 254 | 254 | |
| 255 | 255 | if ($num > 0 && count($parts_renum) > $num) |
| 256 | 256 | { |
| 257 | - $parts_renum[$num-1] = implode($delimiter,array_slice($parts_renum,$num-1,count($parts_renum)-$num+1)); |
|
| 258 | - $parts_renum = array_slice($parts_renum,0,$num); |
|
| 257 | + $parts_renum[$num - 1] = implode($delimiter, array_slice($parts_renum, $num - 1, count($parts_renum) - $num + 1)); |
|
| 258 | + $parts_renum = array_slice($parts_renum, 0, $num); |
|
| 259 | 259 | } |
| 260 | 260 | return $parts_renum; |
| 261 | 261 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | { |
| 283 | 283 | throw new Api\Exception\WrongParameter(__METHOD__."('$class', ".array2string($widgets).") $class is no subclass of ".__CLASS__.'!'); |
| 284 | 284 | } |
| 285 | - foreach((array)$widgets as $widget) |
|
| 285 | + foreach ((array)$widgets as $widget) |
|
| 286 | 286 | { |
| 287 | 287 | self::$widget_registry[$widget] = $class; |
| 288 | 288 | } |
@@ -307,15 +307,15 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | if (!$widget_registry) // not in instance cache --> rescan from filesystem |
| 309 | 309 | { |
| 310 | - foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
|
| 310 | + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
|
| 311 | 311 | { |
| 312 | - if(substr($path, -4) == '.php') |
|
| 312 | + if (substr($path, -4) == '.php') |
|
| 313 | 313 | { |
| 314 | 314 | try |
| 315 | 315 | { |
| 316 | 316 | include_once($path); |
| 317 | 317 | } |
| 318 | - catch(Exception $e) |
|
| 318 | + catch (Exception $e) |
|
| 319 | 319 | { |
| 320 | 320 | error_log($e->getMessage()); |
| 321 | 321 | } |
@@ -323,18 +323,18 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | // Use hook to load custom widgets from other apps |
| 326 | - $widgets = Api\Hooks::process('etemplate2_register_widgets',array(),true); |
|
| 327 | - foreach($widgets as $list) |
|
| 326 | + $widgets = Api\Hooks::process('etemplate2_register_widgets', array(), true); |
|
| 327 | + foreach ($widgets as $list) |
|
| 328 | 328 | { |
| 329 | 329 | if (is_array($list)) |
| 330 | 330 | { |
| 331 | - foreach($list as $class) |
|
| 331 | + foreach ($list as $class) |
|
| 332 | 332 | { |
| 333 | 333 | try |
| 334 | 334 | { |
| 335 | - class_exists($class); // trigger autoloader |
|
| 335 | + class_exists($class); // trigger autoloader |
|
| 336 | 336 | } |
| 337 | - catch(Exception $e) |
|
| 337 | + catch (Exception $e) |
|
| 338 | 338 | { |
| 339 | 339 | error_log($e->getMessage()); |
| 340 | 340 | } |
@@ -357,22 +357,22 @@ discard block |
||
| 357 | 357 | * @param string|XMLReader $xml |
| 358 | 358 | * @param string $id =null |
| 359 | 359 | */ |
| 360 | - public static function factory($type, $xml, $id=null) |
|
| 360 | + public static function factory($type, $xml, $id = null) |
|
| 361 | 361 | { |
| 362 | - $class_name =& self::$widget_registry[$type]; |
|
| 362 | + $class_name = & self::$widget_registry[$type]; |
|
| 363 | 363 | |
| 364 | 364 | if (!isset($class_name)) |
| 365 | 365 | { |
| 366 | - list($basetype) = explode('-',$type); |
|
| 366 | + list($basetype) = explode('-', $type); |
|
| 367 | 367 | if (//dont think this is used: !class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$type)) && |
| 368 | 368 | !class_exists($class_name = __CLASS__.'\\'.ucfirst($basetype)) && |
| 369 | 369 | // widgets supplied by application in class ${app}_widget_etemplate or ${app}_${subtype}_widget_etemplate |
| 370 | 370 | !(isset($GLOBALS['egw_info']['apps'][$basetype]) && |
| 371 | - (class_exists($class_name = str_replace('-','_',$type).'_etemplate_widget') || |
|
| 371 | + (class_exists($class_name = str_replace('-', '_', $type).'_etemplate_widget') || |
|
| 372 | 372 | class_exists($class_name = $basetype.'_etemplate_widget')))) |
| 373 | 373 | { |
| 374 | 374 | // Try for base type, it's probably better than the root |
| 375 | - if(self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
| 375 | + if (self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
| 376 | 376 | { |
| 377 | 377 | $class_name = self::$widget_registry[$basetype]; |
| 378 | 378 | } |
@@ -393,22 +393,22 @@ discard block |
||
| 393 | 393 | { |
| 394 | 394 | // Class in widget registry, but not loaded |
| 395 | 395 | // Try for a base class |
| 396 | - $subtypes = explode('-',$type); |
|
| 396 | + $subtypes = explode('-', $type); |
|
| 397 | 397 | $basetype = $subtypes[0]; |
| 398 | - $class_name = __CLASS__.'\\'.implode('\\',array_map('ucfirst',$subtypes)); |
|
| 399 | - if(!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
| 398 | + $class_name = __CLASS__.'\\'.implode('\\', array_map('ucfirst', $subtypes)); |
|
| 399 | + if (!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
| 400 | 400 | { |
| 401 | 401 | // Try for base type, it's probably better than the root |
| 402 | 402 | $class_name = self::$widget_registry[$basetype]; |
| 403 | 403 | } |
| 404 | - if(!class_exists($class_name)) |
|
| 404 | + if (!class_exists($class_name)) |
|
| 405 | 405 | { |
| 406 | 406 | // Fall back to widget class, we can not ignore it, as the widget may contain other widgets |
| 407 | 407 | $class_name = __CLASS__; |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - if(!$xml) |
|
| 411 | + if (!$xml) |
|
| 412 | 412 | { |
| 413 | 413 | if (empty($type)) $type = 'widget'; |
| 414 | 414 | $xml = "<$type id='$id'/>"; |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | if ($type == 'template' && $id && ($template = Widget\Template::instance($id))) |
| 420 | 420 | { |
| 421 | 421 | // references can set different attributes like: class, span, content (namespace) |
| 422 | - return $template->set_attrs($xml, false); // false = need to clone template, if attributs are set! |
|
| 422 | + return $template->set_attrs($xml, false); // false = need to clone template, if attributs are set! |
|
| 423 | 423 | } |
| 424 | 424 | return new $class_name($xml); |
| 425 | 425 | } |
@@ -431,9 +431,9 @@ discard block |
||
| 431 | 431 | * @param string $type =null |
| 432 | 432 | * @return Widget|NULL |
| 433 | 433 | */ |
| 434 | - public function getElementById($id, $type=null) |
|
| 434 | + public function getElementById($id, $type = null) |
|
| 435 | 435 | { |
| 436 | - foreach($this->children as $child) |
|
| 436 | + foreach ($this->children as $child) |
|
| 437 | 437 | { |
| 438 | 438 | if ($child->id === $id && (is_null($type) || $child->type === $type)) |
| 439 | 439 | { |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | public function getElementsByType($type) |
| 457 | 457 | { |
| 458 | 458 | $elements = array(); |
| 459 | - foreach($this->children as $child) |
|
| 459 | + foreach ($this->children as $child) |
|
| 460 | 460 | { |
| 461 | 461 | if ($child->type === $type) |
| 462 | 462 | { |
@@ -476,14 +476,14 @@ discard block |
||
| 476 | 476 | * @param array $params =array('') parameter(s) first parameter has to be the cname, second $expand! |
| 477 | 477 | * @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children |
| 478 | 478 | */ |
| 479 | - public function run($method_name, $params=array(''), $respect_disabled=false) |
|
| 479 | + public function run($method_name, $params = array(''), $respect_disabled = false) |
|
| 480 | 480 | { |
| 481 | 481 | // maintain $expand array name-expansion |
| 482 | 482 | $cname = $params[0]; |
| 483 | - $expand =& $params[1]; |
|
| 483 | + $expand = & $params[1]; |
|
| 484 | 484 | if ($expand['cname'] && $expand['cname'] !== $cname) |
| 485 | 485 | { |
| 486 | - $expand['cont'] =& self::get_array(self::$request->content, $cname); |
|
| 486 | + $expand['cont'] = & self::get_array(self::$request->content, $cname); |
|
| 487 | 487 | $expand['cname'] = $cname; |
| 488 | 488 | } |
| 489 | 489 | if ($respect_disabled && ($disabled = $this->attrs['disabled'] && self::check_disabled($this->attrs['disabled'], $expand))) |
@@ -496,22 +496,22 @@ discard block |
||
| 496 | 496 | // Some parameter checking to avoid fatal errors |
| 497 | 497 | $call = true; |
| 498 | 498 | $method = new ReflectionMethod($this, $method_name); |
| 499 | - foreach($method->getParameters() as $index => $param) |
|
| 499 | + foreach ($method->getParameters() as $index => $param) |
|
| 500 | 500 | { |
| 501 | - if(!$param->isOptional() && !array_key_exists($index,$params)) |
|
| 501 | + if (!$param->isOptional() && !array_key_exists($index, $params)) |
|
| 502 | 502 | { |
| 503 | 503 | error_log("Missing required parameter {$param->getPosition()}: {$param->getName()}"); |
| 504 | 504 | $call = false; |
| 505 | 505 | } |
| 506 | - if($param->isArray() && !is_array($params[$index])) |
|
| 506 | + if ($param->isArray() && !is_array($params[$index])) |
|
| 507 | 507 | { |
| 508 | 508 | error_log("$method_name expects an array for {$param->getPosition()}: {$param->getName()}"); |
| 509 | 509 | $params[$index] = (array)$params[$index]; |
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | - if($call) call_user_func_array(array($this, $method_name), $params); |
|
| 512 | + if ($call) call_user_func_array(array($this, $method_name), $params); |
|
| 513 | 513 | } |
| 514 | - foreach($this->children as $child) |
|
| 514 | + foreach ($this->children as $child) |
|
| 515 | 515 | { |
| 516 | 516 | // If type has something that can be expanded, we need to expand it so the correct method is run |
| 517 | 517 | $this->expand_widget($child, $expand); |
@@ -526,15 +526,15 @@ discard block |
||
| 526 | 526 | * @param Widget& $child Widget to check & expand if needed |
| 527 | 527 | * @param array& $expand Expansion array |
| 528 | 528 | */ |
| 529 | - protected function expand_widget(Widget &$child, array &$expand) |
|
| 529 | + protected function expand_widget(Widget&$child, array &$expand) |
|
| 530 | 530 | { |
| 531 | - if(strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false) |
|
| 531 | + if (strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false) |
|
| 532 | 532 | { |
| 533 | - $type = self::expand_name($child->attrs['type'],$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
| 534 | - $id = self::expand_name($child->id,$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
| 533 | + $type = self::expand_name($child->attrs['type'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
| 534 | + $id = self::expand_name($child->id, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
| 535 | 535 | $attrs = $child->attrs; |
| 536 | 536 | unset($attrs['type']); |
| 537 | - $expanded_child = self::factory($type, false,$id); |
|
| 537 | + $expanded_child = self::factory($type, false, $id); |
|
| 538 | 538 | $expanded_child->id = $id; |
| 539 | 539 | $expanded_child->type = $type; |
| 540 | 540 | $expanded_child->attrs = $attrs + array('type' => $type); |
@@ -557,14 +557,14 @@ discard block |
||
| 557 | 557 | { |
| 558 | 558 | if (($not = $disabled[0] == '!')) |
| 559 | 559 | { |
| 560 | - $disabled = substr($disabled,1); |
|
| 560 | + $disabled = substr($disabled, 1); |
|
| 561 | 561 | } |
| 562 | - list($value,$check) = $vals = explode('=',$disabled); |
|
| 562 | + list($value, $check) = $vals = explode('=', $disabled); |
|
| 563 | 563 | |
| 564 | 564 | // use expand_name to be able to use @ or $ |
| 565 | 565 | $val = self::expand_name($value, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
| 566 | 566 | $check_val = self::expand_name($check, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
| 567 | - $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val,$val) : $val == $check_val); |
|
| 567 | + $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val, $val) : $val == $check_val); |
|
| 568 | 568 | if ($not) $result = !$result; |
| 569 | 569 | |
| 570 | 570 | //error_log(__METHOD__."('".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')); |
@@ -606,33 +606,33 @@ discard block |
||
| 606 | 606 | * "del[$cont[id]]" expands to "del[123]" if $cont = array('id' => 123) |
| 607 | 607 | * @return string the expanded name |
| 608 | 608 | */ |
| 609 | - protected static function expand_name($name,$c,$row,$c_='',$row_='',$cont='') |
|
| 609 | + protected static function expand_name($name, $c, $row, $c_ = '', $row_ = '', $cont = '') |
|
| 610 | 610 | { |
| 611 | 611 | $is_index_in_content = $name[0] == '@'; |
| 612 | - if (($pos_var=strpos($name,'$')) !== false) |
|
| 612 | + if (($pos_var = strpos($name, '$')) !== false) |
|
| 613 | 613 | { |
| 614 | 614 | if (!$cont) |
| 615 | 615 | { |
| 616 | 616 | $cont = array(); |
| 617 | 617 | } |
| 618 | 618 | if (!is_numeric($c)) $c = self::chrs2num($c); |
| 619 | - $col = self::num2chrs($c-1); // $c-1 to get: 0:'@', 1:'A', ... |
|
| 620 | - $col_ = self::num2chrs($c_-1); |
|
| 619 | + $col = self::num2chrs($c - 1); // $c-1 to get: 0:'@', 1:'A', ... |
|
| 620 | + $col_ = self::num2chrs($c_ - 1); |
|
| 621 | 621 | $row_cont = $cont[$row]; |
| 622 | 622 | $col_row_cont = $cont[$col.$row]; |
| 623 | 623 | |
| 624 | - eval('$name = "'.str_replace('"','\\"',$name).'";'); |
|
| 625 | - unset($col_, $row_, $row_cont, $col_row_cont); // quiten IDE warning about used vars, they might be used in above eval! |
|
| 624 | + eval('$name = "'.str_replace('"', '\\"', $name).'";'); |
|
| 625 | + unset($col_, $row_, $row_cont, $col_row_cont); // quiten IDE warning about used vars, they might be used in above eval! |
|
| 626 | 626 | } |
| 627 | 627 | if ($is_index_in_content) |
| 628 | 628 | { |
| 629 | 629 | if ($name[1] == '@' && is_array(self::$request->content)) |
| 630 | 630 | { |
| 631 | - $name = self::get_array(self::$request->content,substr($name,2)); |
|
| 631 | + $name = self::get_array(self::$request->content, substr($name, 2)); |
|
| 632 | 632 | } |
| 633 | - elseif(is_array($cont)) |
|
| 633 | + elseif (is_array($cont)) |
|
| 634 | 634 | { |
| 635 | - $name = self::get_array($cont,substr($name,1)); |
|
| 635 | + $name = self::get_array($cont, substr($name, 1)); |
|
| 636 | 636 | } |
| 637 | 637 | else |
| 638 | 638 | { |
@@ -654,11 +654,11 @@ discard block |
||
| 654 | 654 | $min = ord('A'); |
| 655 | 655 | $max = ord('Z') - $min + 1; |
| 656 | 656 | |
| 657 | - $num = 1+ord($chrs{0})-$min; |
|
| 657 | + $num = 1 + ord($chrs{0}) - $min; |
|
| 658 | 658 | if (strlen($chrs) > 1) |
| 659 | 659 | { |
| 660 | 660 | $num *= 1 + $max - $min; |
| 661 | - $num += 1+ord($chrs{1})-$min; |
|
| 661 | + $num += 1 + ord($chrs{1}) - $min; |
|
| 662 | 662 | } |
| 663 | 663 | return $num; |
| 664 | 664 | } |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | */ |
| 690 | 690 | public function __toString() |
| 691 | 691 | { |
| 692 | - return '['.get_class($this).'] ' . |
|
| 692 | + return '['.get_class($this).'] '. |
|
| 693 | 693 | $this->type.($this->attrs['type'] && $this->attrs['type'] != $this->type ? '('.$this->attrs['type'].')' : '').'#'.$this->id; |
| 694 | 694 | } |
| 695 | 695 | |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | */ |
| 699 | 699 | public function __clone() |
| 700 | 700 | { |
| 701 | - foreach($this->children as $child_num => $child) { |
|
| 701 | + foreach ($this->children as $child_num => $child) { |
|
| 702 | 702 | $this->children[$child_num] = clone $child; |
| 703 | 703 | } |
| 704 | 704 | } |
@@ -709,16 +709,16 @@ discard block |
||
| 709 | 709 | * @param string $indent ='' |
| 710 | 710 | * @return string |
| 711 | 711 | */ |
| 712 | - public function toXml($indent='') |
|
| 712 | + public function toXml($indent = '') |
|
| 713 | 713 | { |
| 714 | 714 | echo "$indent<$this->type"; |
| 715 | 715 | if ($this->id) echo ' id="'.htmlspecialchars($this->id).'"'; |
| 716 | - foreach($this->attrs as $name => $value) |
|
| 716 | + foreach ($this->attrs as $name => $value) |
|
| 717 | 717 | { |
| 718 | 718 | if ($name == 'options' && $this->legacy_options && (!is_array($this->legacy_options) || |
| 719 | 719 | isset($this->legacy_options[$this->attrs['type'] ? $this->attrs['type'] : $this->type]))) |
| 720 | 720 | { |
| 721 | - continue; // do NOT output already converted legacy options |
|
| 721 | + continue; // do NOT output already converted legacy options |
|
| 722 | 722 | } |
| 723 | 723 | echo ' '.$name.'="'.htmlspecialchars($value).'"'; |
| 724 | 724 | } |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | if ($this->children) |
| 728 | 728 | { |
| 729 | 729 | echo ">\n"; |
| 730 | - foreach($this->children as $child) |
|
| 730 | + foreach ($this->children as $child) |
|
| 731 | 731 | { |
| 732 | 732 | $child->toXml($indent."\t"); |
| 733 | 733 | } |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * @param array $expand =null values for keys 'c', 'row', 'c_', 'row_', 'cont' |
| 751 | 751 | * @return string complete form-name |
| 752 | 752 | */ |
| 753 | - static function form_name($cname,$name,array $expand=null) |
|
| 753 | + static function form_name($cname, $name, array $expand = null) |
|
| 754 | 754 | { |
| 755 | 755 | if ($expand && !empty($name)) |
| 756 | 756 | { |
@@ -758,18 +758,18 @@ discard block |
||
| 758 | 758 | } |
| 759 | 759 | if (count($name_parts = explode('[', $name, 2)) > 1) |
| 760 | 760 | { |
| 761 | - $name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1],0,-1))); |
|
| 761 | + $name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1], 0, -1))); |
|
| 762 | 762 | } |
| 763 | 763 | if (!empty($cname)) |
| 764 | 764 | { |
| 765 | - array_unshift($name_parts,$cname); |
|
| 765 | + array_unshift($name_parts, $cname); |
|
| 766 | 766 | } |
| 767 | 767 | $form_name = array_shift($name_parts); |
| 768 | 768 | if (count($name_parts)) |
| 769 | 769 | { |
| 770 | 770 | // RB: not sure why this business with entity encoding for square brakets, it messes up validation |
| 771 | 771 | //$form_name .= '['.implode('][',$name_parts).']'; |
| 772 | - $form_name .= '['.implode('][',$name_parts).']'; |
|
| 772 | + $form_name .= '['.implode('][', $name_parts).']'; |
|
| 773 | 773 | } |
| 774 | 774 | return $form_name; |
| 775 | 775 | } |
@@ -786,36 +786,36 @@ discard block |
||
| 786 | 786 | * @param bool $skip_empty returns false if $idx is not present in $arr |
| 787 | 787 | * @return mixed reference to $arr[$idx] or null if $idx is not set and not $reference_into |
| 788 | 788 | */ |
| 789 | - static function &get_array(&$arr,$_idx,$reference_into=False,$skip_empty=False) |
|
| 789 | + static function &get_array(&$arr, $_idx, $reference_into = False, $skip_empty = False) |
|
| 790 | 790 | { |
| 791 | 791 | if (!is_array($arr)) |
| 792 | 792 | { |
| 793 | 793 | throw new Api\Exception\AssertionFailed(__METHOD__."(\$arr,'$_idx',$reference_into,$skip_empty) \$arr is no array!"); |
| 794 | 794 | } |
| 795 | - if (is_object($_idx)) return false; // given an error in php5.2 |
|
| 795 | + if (is_object($_idx)) return false; // given an error in php5.2 |
|
| 796 | 796 | |
| 797 | 797 | // Make sure none of these are left |
| 798 | - $idx = str_replace(array('[',']'), array('[',']'), $_idx); |
|
| 798 | + $idx = str_replace(array('[', ']'), array('[', ']'), $_idx); |
|
| 799 | 799 | |
| 800 | 800 | // Handle things expecting arrays - ends in [] |
| 801 | - if(substr($idx,-2) == "[]") |
|
| 801 | + if (substr($idx, -2) == "[]") |
|
| 802 | 802 | { |
| 803 | - $idx = substr($idx,0,-2); |
|
| 803 | + $idx = substr($idx, 0, -2); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | if (count($idxs = explode('[', $idx, 2)) > 1) |
| 807 | 807 | { |
| 808 | - $idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1],0,-1))); |
|
| 808 | + $idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1], 0, -1))); |
|
| 809 | 809 | } |
| 810 | 810 | $pos = &$arr; |
| 811 | - foreach($idxs as $idx) |
|
| 811 | + foreach ($idxs as $idx) |
|
| 812 | 812 | { |
| 813 | 813 | if (!is_array($pos) && (!$reference_into || $reference_into && isset($pos))) |
| 814 | 814 | { |
| 815 | 815 | //if ($reference_into) error_log(__METHOD__."(".(strlen($s=array2string($arr))>512?substr($s,0,512).'...':$s).", '$idx', ".array2string($reference_into).", ".array2string($skip_empty).") ".function_backtrace()); |
| 816 | 816 | return null; |
| 817 | 817 | } |
| 818 | - if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
| 818 | + if ($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
| 819 | 819 | $pos = &$pos[$idx]; |
| 820 | 820 | } |
| 821 | 821 | return $pos; |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | */ |
| 834 | 834 | static function set_array(&$_arr, $_idx, $_value) |
| 835 | 835 | { |
| 836 | - $ref =& self::get_array($_arr, $_idx, true); |
|
| 836 | + $ref = & self::get_array($_arr, $_idx, true); |
|
| 837 | 837 | if (true) $ref = $_value; |
| 838 | 838 | } |
| 839 | 839 | |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | * @param string $form_name =null form_name, to not calculate him again |
| 848 | 848 | * @return boolean |
| 849 | 849 | */ |
| 850 | - public function is_readonly($cname='', $form_name=null) |
|
| 850 | + public function is_readonly($cname = '', $form_name = null) |
|
| 851 | 851 | { |
| 852 | 852 | if (!isset($form_name)) |
| 853 | 853 | { |
@@ -857,11 +857,11 @@ discard block |
||
| 857 | 857 | $form_name = self::form_name($cname, $this->id, $expand); |
| 858 | 858 | } |
| 859 | 859 | $readonly = $this->attrs['readonly'] || self::$request->readonlys[$form_name] || |
| 860 | - self::get_array(self::$request->readonlys,$form_name) === true || |
|
| 860 | + self::get_array(self::$request->readonlys, $form_name) === true || |
|
| 861 | 861 | isset(self::$request->readonlys['__ALL__']) && ( |
| 862 | 862 | // Exceptions to all |
| 863 | 863 | self::$request->readonlys[$form_name] !== false && |
| 864 | - self::get_array(self::$request->readonlys,$form_name) !== false |
|
| 864 | + self::get_array(self::$request->readonlys, $form_name) !== false |
|
| 865 | 865 | ); |
| 866 | 866 | |
| 867 | 867 | //error_log(__METHOD__."('$cname') this->id='$this->id' --> form_name='$form_name': attrs[readonly]=".array2string($this->attrs['readonly']).", readonlys['$form_name']=".array2string(self::$request->readonlys[$form_name]).", readonlys[$form_name]=".array2string(self::get_array(self::$request->readonlys,$form_name)).", readonlys['__ALL__']=".array2string(self::$request->readonlys['__ALL__'])." returning ".array2string($readonly)); |
@@ -881,12 +881,12 @@ discard block |
||
| 881 | 881 | * @param string|boolean $error error-message already translated or false to reset all existing error for given name |
| 882 | 882 | * @param string $cname =null set it to '', if the name is already a form-name, defaults to self::$name_vars |
| 883 | 883 | */ |
| 884 | - public static function set_validation_error($name,$error,$cname=null) |
|
| 884 | + public static function set_validation_error($name, $error, $cname = null) |
|
| 885 | 885 | { |
| 886 | 886 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
| 887 | 887 | error_log(__METHOD__."('$name','$error','$cname') ".function_backtrace()); |
| 888 | 888 | |
| 889 | - if ($cname) $name = self::form_name($cname,$name); |
|
| 889 | + if ($cname) $name = self::form_name($cname, $name); |
|
| 890 | 890 | |
| 891 | 891 | if ($error === false) |
| 892 | 892 | { |
@@ -909,18 +909,18 @@ discard block |
||
| 909 | 909 | * @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars |
| 910 | 910 | * @return boolean true if there are not ignored validation errors, false otherwise |
| 911 | 911 | */ |
| 912 | - public static function validation_errors($ignore_validation='',$cname='') |
|
| 912 | + public static function validation_errors($ignore_validation = '', $cname = '') |
|
| 913 | 913 | { |
| 914 | 914 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
| 915 | 915 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors); |
| 916 | 916 | if (!$ignore_validation) return count(self::$validation_errors) > 0; |
| 917 | 917 | |
| 918 | - foreach(array_values(self::$validation_errors) as $name) |
|
| 918 | + foreach (array_values(self::$validation_errors) as $name) |
|
| 919 | 919 | { |
| 920 | - if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); |
|
| 920 | + if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/', '\\1\\2', $name); |
|
| 921 | 921 | |
| 922 | 922 | // treat $ignoare_validation only as regular expression, if it starts with a slash |
| 923 | - if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) || |
|
| 923 | + if ($ignore_validation[0] == '/' && !preg_match($ignore_validation, $name) || |
|
| 924 | 924 | $ignore_validation[0] != '/' && $ignore_validation != $name) |
| 925 | 925 | { |
| 926 | 926 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') name='$name' ($error) not ignored!!!</p>\n"; |
@@ -957,14 +957,14 @@ discard block |
||
| 957 | 957 | * @param mixed $val if not NULL sets attribute else returns it |
| 958 | 958 | * @return reference to attribute |
| 959 | 959 | */ |
| 960 | - public static function &setElementAttribute($name,$attr,$val) |
|
| 960 | + public static function &setElementAttribute($name, $attr, $val) |
|
| 961 | 961 | { |
| 962 | 962 | //error_log(__METHOD__."('$name', '$attr', ...) request=".get_class(self::$request).", response=".get_class(self::$response).function_backtrace()); |
| 963 | - $ref =& self::$request->modifications[$name][$attr]; |
|
| 964 | - if(self::$request && self::$response && (!isset($this) || $val != $this->attrs[$attr])) |
|
| 963 | + $ref = & self::$request->modifications[$name][$attr]; |
|
| 964 | + if (self::$request && self::$response && (!isset($this) || $val != $this->attrs[$attr])) |
|
| 965 | 965 | { |
| 966 | 966 | // In an AJAX response - automatically add |
| 967 | - self::$response->generic('assign',array( |
|
| 967 | + self::$response->generic('assign', array( |
|
| 968 | 968 | 'etemplate_exec_id' => self::$request->id(), |
| 969 | 969 | 'id' => $name, |
| 970 | 970 | 'key' => $attr, |
@@ -988,7 +988,7 @@ discard block |
||
| 988 | 988 | * @param boolean $disabled =true disable or enable a cell, default true=disable |
| 989 | 989 | * @return reference to attribute |
| 990 | 990 | */ |
| 991 | - public function disableElement($name,$disabled=True) |
|
| 991 | + public function disableElement($name, $disabled = True) |
|
| 992 | 992 | { |
| 993 | 993 | return self::setElementAttribute($name, 'disabled', $disabled); |
| 994 | 994 | } |
@@ -100,7 +100,9 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | // Update content? |
| 102 | 102 | if(self::$cont == null) |
| 103 | - self::$cont = is_array(self::$request->content) ? self::$request->content : array(); |
|
| 103 | + { |
|
| 104 | + self::$cont = is_array(self::$request->content) ? self::$request->content : array(); |
|
| 105 | + } |
|
| 104 | 106 | if($this->id && is_array(self::$cont[$this->id])) |
| 105 | 107 | { |
| 106 | 108 | $old_cont = self::$cont; |
@@ -119,7 +121,8 @@ discard block |
||
| 119 | 121 | } |
| 120 | 122 | |
| 121 | 123 | // Reset content as we leave |
| 122 | - if($old_cont) { |
|
| 124 | + if($old_cont) |
|
| 125 | + { |
|
| 123 | 126 | self::$cont = $old_cont; |
| 124 | 127 | } |
| 125 | 128 | } |
@@ -200,7 +203,10 @@ discard block |
||
| 200 | 203 | $legacy_options = explode(',', $legacy_options); |
| 201 | 204 | foreach(self::csv_split($value, count($legacy_options)) as $n => $val) |
| 202 | 205 | { |
| 203 | - if ($legacy_options[$n] && (string)$val !== '') $template->attrs[$legacy_options[$n]] = $val; |
|
| 206 | + if ($legacy_options[$n] && (string)$val !== '') |
|
| 207 | + { |
|
| 208 | + $template->attrs[$legacy_options[$n]] = $val; |
|
| 209 | + } |
|
| 204 | 210 | } |
| 205 | 211 | } |
| 206 | 212 | } |
@@ -305,7 +311,9 @@ discard block |
||
| 305 | 311 | |
| 306 | 312 | $widget_registry = Api\Cache::getInstance('etemplate', 'widget_registry'); |
| 307 | 313 | |
| 308 | - if (!$widget_registry) // not in instance cache --> rescan from filesystem |
|
| 314 | + if (!$widget_registry) |
|
| 315 | + { |
|
| 316 | + // not in instance cache --> rescan from filesystem |
|
| 309 | 317 | { |
| 310 | 318 | foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
| 311 | 319 | { |
@@ -314,6 +322,7 @@ discard block |
||
| 314 | 322 | try |
| 315 | 323 | { |
| 316 | 324 | include_once($path); |
| 325 | + } |
|
| 317 | 326 | } |
| 318 | 327 | catch(Exception $e) |
| 319 | 328 | { |
@@ -410,7 +419,10 @@ discard block |
||
| 410 | 419 | |
| 411 | 420 | if(!$xml) |
| 412 | 421 | { |
| 413 | - if (empty($type)) $type = 'widget'; |
|
| 422 | + if (empty($type)) |
|
| 423 | + { |
|
| 424 | + $type = 'widget'; |
|
| 425 | + } |
|
| 414 | 426 | $xml = "<$type id='$id'/>"; |
| 415 | 427 | } |
| 416 | 428 | //error_log(__METHOD__."('$type', ..., '$id') using $class_name"); |
@@ -509,7 +521,10 @@ discard block |
||
| 509 | 521 | $params[$index] = (array)$params[$index]; |
| 510 | 522 | } |
| 511 | 523 | } |
| 512 | - if($call) call_user_func_array(array($this, $method_name), $params); |
|
| 524 | + if($call) |
|
| 525 | + { |
|
| 526 | + call_user_func_array(array($this, $method_name), $params); |
|
| 527 | + } |
|
| 513 | 528 | } |
| 514 | 529 | foreach($this->children as $child) |
| 515 | 530 | { |
@@ -565,7 +580,10 @@ discard block |
||
| 565 | 580 | $val = self::expand_name($value, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
| 566 | 581 | $check_val = self::expand_name($check, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
| 567 | 582 | $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val,$val) : $val == $check_val); |
| 568 | - if ($not) $result = !$result; |
|
| 583 | + if ($not) |
|
| 584 | + { |
|
| 585 | + $result = !$result; |
|
| 586 | + } |
|
| 569 | 587 | |
| 570 | 588 | //error_log(__METHOD__."('".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')); |
| 571 | 589 | return $result; |
@@ -615,7 +633,10 @@ discard block |
||
| 615 | 633 | { |
| 616 | 634 | $cont = array(); |
| 617 | 635 | } |
| 618 | - if (!is_numeric($c)) $c = self::chrs2num($c); |
|
| 636 | + if (!is_numeric($c)) |
|
| 637 | + { |
|
| 638 | + $c = self::chrs2num($c); |
|
| 639 | + } |
|
| 619 | 640 | $col = self::num2chrs($c-1); // $c-1 to get: 0:'@', 1:'A', ... |
| 620 | 641 | $col_ = self::num2chrs($c_-1); |
| 621 | 642 | $row_cont = $cont[$row]; |
@@ -698,7 +719,8 @@ discard block |
||
| 698 | 719 | */ |
| 699 | 720 | public function __clone() |
| 700 | 721 | { |
| 701 | - foreach($this->children as $child_num => $child) { |
|
| 722 | + foreach($this->children as $child_num => $child) |
|
| 723 | + { |
|
| 702 | 724 | $this->children[$child_num] = clone $child; |
| 703 | 725 | } |
| 704 | 726 | } |
@@ -712,7 +734,10 @@ discard block |
||
| 712 | 734 | public function toXml($indent='') |
| 713 | 735 | { |
| 714 | 736 | echo "$indent<$this->type"; |
| 715 | - if ($this->id) echo ' id="'.htmlspecialchars($this->id).'"'; |
|
| 737 | + if ($this->id) |
|
| 738 | + { |
|
| 739 | + echo ' id="'.htmlspecialchars($this->id).'"'; |
|
| 740 | + } |
|
| 716 | 741 | foreach($this->attrs as $name => $value) |
| 717 | 742 | { |
| 718 | 743 | if ($name == 'options' && $this->legacy_options && (!is_array($this->legacy_options) || |
@@ -792,7 +817,11 @@ discard block |
||
| 792 | 817 | { |
| 793 | 818 | throw new Api\Exception\AssertionFailed(__METHOD__."(\$arr,'$_idx',$reference_into,$skip_empty) \$arr is no array!"); |
| 794 | 819 | } |
| 795 | - if (is_object($_idx)) return false; // given an error in php5.2 |
|
| 820 | + if (is_object($_idx)) |
|
| 821 | + { |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + // given an error in php5.2 |
|
| 796 | 825 | |
| 797 | 826 | // Make sure none of these are left |
| 798 | 827 | $idx = str_replace(array('[',']'), array('[',']'), $_idx); |
@@ -815,7 +844,10 @@ discard block |
||
| 815 | 844 | //if ($reference_into) error_log(__METHOD__."(".(strlen($s=array2string($arr))>512?substr($s,0,512).'...':$s).", '$idx', ".array2string($reference_into).", ".array2string($skip_empty).") ".function_backtrace()); |
| 816 | 845 | return null; |
| 817 | 846 | } |
| 818 | - if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
| 847 | + if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) |
|
| 848 | + { |
|
| 849 | + return null; |
|
| 850 | + } |
|
| 819 | 851 | $pos = &$pos[$idx]; |
| 820 | 852 | } |
| 821 | 853 | return $pos; |
@@ -834,7 +866,10 @@ discard block |
||
| 834 | 866 | static function set_array(&$_arr, $_idx, $_value) |
| 835 | 867 | { |
| 836 | 868 | $ref =& self::get_array($_arr, $_idx, true); |
| 837 | - if (true) $ref = $_value; |
|
| 869 | + if (true) |
|
| 870 | + { |
|
| 871 | + $ref = $_value; |
|
| 872 | + } |
|
| 838 | 873 | } |
| 839 | 874 | |
| 840 | 875 | /** |
@@ -886,7 +921,10 @@ discard block |
||
| 886 | 921 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
| 887 | 922 | error_log(__METHOD__."('$name','$error','$cname') ".function_backtrace()); |
| 888 | 923 | |
| 889 | - if ($cname) $name = self::form_name($cname,$name); |
|
| 924 | + if ($cname) |
|
| 925 | + { |
|
| 926 | + $name = self::form_name($cname,$name); |
|
| 927 | + } |
|
| 890 | 928 | |
| 891 | 929 | if ($error === false) |
| 892 | 930 | { |
@@ -913,11 +951,17 @@ discard block |
||
| 913 | 951 | { |
| 914 | 952 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
| 915 | 953 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors); |
| 916 | - if (!$ignore_validation) return count(self::$validation_errors) > 0; |
|
| 954 | + if (!$ignore_validation) |
|
| 955 | + { |
|
| 956 | + return count(self::$validation_errors) > 0; |
|
| 957 | + } |
|
| 917 | 958 | |
| 918 | 959 | foreach(array_values(self::$validation_errors) as $name) |
| 919 | 960 | { |
| 920 | - if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); |
|
| 961 | + if ($cname) |
|
| 962 | + { |
|
| 963 | + $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); |
|
| 964 | + } |
|
| 921 | 965 | |
| 922 | 966 | // treat $ignoare_validation only as regular expression, if it starts with a slash |
| 923 | 967 | if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) || |
@@ -974,8 +1018,14 @@ discard block |
||
| 974 | 1018 | self::$request->unset_to_process(''); |
| 975 | 1019 | //error_log(__METHOD__."('$name', '$attr', ...) ".function_backtrace()); |
| 976 | 1020 | } |
| 977 | - if (isset($this)) $this->attrs[$attr] = $val; |
|
| 978 | - if (!is_null($val)) $ref = $val; |
|
| 1021 | + if (isset($this)) |
|
| 1022 | + { |
|
| 1023 | + $this->attrs[$attr] = $val; |
|
| 1024 | + } |
|
| 1025 | + if (!is_null($val)) |
|
| 1026 | + { |
|
| 1027 | + $ref = $val; |
|
| 1028 | + } |
|
| 979 | 1029 | |
| 980 | 1030 | //error_log(__METHOD__."('$name', '$attr', ".array2string($val).')'); |
| 981 | 1031 | return $ref; |