@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @var string |
| 46 | 46 | */ |
| 47 | - var $contacts_id='id'; |
|
| 47 | + var $contacts_id = 'id'; |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Name of the table for distribution lists |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param Api\Db $db =null |
| 69 | 69 | */ |
| 70 | - function __construct(Api\Db $db=null) |
|
| 70 | + function __construct(Api\Db $db = null) |
|
| 71 | 71 | { |
| 72 | 72 | parent::__construct('api', 'egw_addressbook', self::EXTRA_TABLE, |
| 73 | 73 | 'contact_', '_name', '_value', '_id', $db); |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
| 116 | 116 | $advanced_search = false; |
| 117 | 117 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
| 118 | - $wildcard ='%'; |
|
| 119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 118 | + $wildcard = '%'; |
|
| 119 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
| 120 | 120 | |
| 121 | 121 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 122 | 122 | if ($filter['cat_id']) |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 135 | 135 | if ($param['owner']) |
| 136 | 136 | { |
| 137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
| 137 | + if (!$this->grants[(int)$filter['owner']]) return false; // we have no access to that addressbook |
|
| 138 | 138 | |
| 139 | 139 | $filter['owner'] = $param['owner']; |
| 140 | 140 | $filter['private'] = 0; |
@@ -143,18 +143,18 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
| 145 | 145 | { |
| 146 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 146 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 147 | 147 | } |
| 148 | 148 | $filter[] = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 149 | 149 | " OR contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
| 150 | - implode(',',array_keys($this->grants))."))"; |
|
| 150 | + implode(',', array_keys($this->grants))."))"; |
|
| 151 | 151 | } |
| 152 | 152 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
| 153 | 153 | { |
| 154 | 154 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
| 155 | 155 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
| 156 | 156 | { |
| 157 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
| 157 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
| 158 | 158 | } |
| 159 | 159 | else |
| 160 | 160 | { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | else |
| 170 | 170 | { |
| 171 | - $filter[] = "org_name != ''";// AND org_name IS NOT NULL"; |
|
| 171 | + $filter[] = "org_name != ''"; // AND org_name IS NOT NULL"; |
|
| 172 | 172 | } |
| 173 | 173 | if (isset($filter['list'])) |
| 174 | 174 | { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
| 188 | 188 | |
| 189 | - list(,$by) = explode(',',$param['org_view']); |
|
| 189 | + list(,$by) = explode(',', $param['org_view']); |
|
| 190 | 190 | if (!$by) |
| 191 | 191 | { |
| 192 | 192 | $extra = array( |
@@ -199,41 +199,40 @@ discard block |
||
| 199 | 199 | else // by adr_one_location or org_unit |
| 200 | 200 | { |
| 201 | 201 | // org total for more then one $by |
| 202 | - $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : |
|
| 203 | - "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
| 204 | - parent::search($param['search'],array('org_name'), |
|
| 202 | + $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
| 203 | + parent::search($param['search'], array('org_name'), |
|
| 205 | 204 | "GROUP BY org_name HAVING $by_expr > 1 ORDER BY org_name $sort", array( |
| 206 | 205 | "NULL AS $by", |
| 207 | 206 | '1 AS is_main', |
| 208 | 207 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
| 209 | 208 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
| 210 | 209 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
| 211 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
| 210 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
| 212 | 211 | // org by location |
| 213 | - parent::search($param['search'],array('org_name'), |
|
| 212 | + parent::search($param['search'], array('org_name'), |
|
| 214 | 213 | "GROUP BY org_name,$by ORDER BY org_name $sort,$by $sort", array( |
| 215 | 214 | "CASE WHEN $by IS NULL THEN '' ELSE $by END AS $by", |
| 216 | 215 | '0 AS is_main', |
| 217 | 216 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
| 218 | 217 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
| 219 | 218 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
| 220 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
| 219 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
| 221 | 220 | $append = "ORDER BY org_name $sort,is_main DESC,$by $sort"; |
| 222 | 221 | } |
| 223 | - $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
|
| 224 | - array($param['start'],$param['num_rows']),$filter,$join); |
|
| 222 | + $rows = parent::search($param['search'], array('org_name'), $append, $extra, $wildcard, false, $op/*'OR'*/, |
|
| 223 | + array($param['start'], $param['num_rows']), $filter, $join); |
|
| 225 | 224 | |
| 226 | 225 | if (!$rows) return false; |
| 227 | 226 | |
| 228 | 227 | // query the values for *_count == 1, to display them instead |
| 229 | 228 | $filter['org_name'] = $orgs = array(); |
| 230 | - foreach($rows as $row) |
|
| 229 | + foreach ($rows as $row) |
|
| 231 | 230 | { |
| 232 | 231 | if ($row['org_unit_count'] == 1 || $row['adr_one_locality_count'] == 1) |
| 233 | 232 | { |
| 234 | - $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
| 233 | + $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
| 235 | 234 | } |
| 236 | - $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count']==1 ? $row[$by] : '|||') : ''); |
|
| 235 | + $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count'] == 1 ? $row[$by] : '|||') : ''); |
|
| 237 | 236 | $row['group_count'] = $row['org_count']; |
| 238 | 237 | $orgs[$org_key] = $row; |
| 239 | 238 | } |
@@ -241,9 +240,9 @@ discard block |
||
| 241 | 240 | |
| 242 | 241 | if (count($filter['org_name'])) |
| 243 | 242 | { |
| 244 | - foreach((array) parent::search(null, array('org_name','org_unit','adr_one_locality'), |
|
| 243 | + foreach ((array)parent::search(null, array('org_name', 'org_unit', 'adr_one_locality'), |
|
| 245 | 244 | 'GROUP BY org_name,org_unit,adr_one_locality', |
| 246 | - '',$wildcard,false,$op/*'AND'*/,false,$filter,$join) as $row) |
|
| 245 | + '', $wildcard, false, $op/*'AND'*/, false, $filter, $join) as $row) |
|
| 247 | 246 | { |
| 248 | 247 | $org_key = $row['org_name'].($by ? '|||'.$row[$by] : ''); |
| 249 | 248 | if ($orgs[$org_key]['org_unit_count'] == 1) |
@@ -295,27 +294,27 @@ discard block |
||
| 295 | 294 | */ |
| 296 | 295 | function duplicates($param) |
| 297 | 296 | { |
| 298 | - $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
|
| 297 | + $join = 'JOIN '.$this->table_name.' AS a2 ON '; |
|
| 299 | 298 | $filter = $param['col_filter']; |
| 300 | 299 | $op = 'OR'; |
| 301 | 300 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
| 302 | 301 | $advanced_search = false; |
| 303 | 302 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
| 304 | - $wildcard ='%'; |
|
| 305 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 303 | + $wildcard = '%'; |
|
| 304 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
| 306 | 305 | |
| 307 | 306 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 308 | 307 | if ($param['cat_id']) |
| 309 | 308 | { |
| 310 | 309 | $cat_filter = $this->_cat_filter($filter['cat_id']); |
| 311 | - $filter[] = str_replace('cat_id', $this->table_name . '.cat_id', $cat_filter); |
|
| 312 | - $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter) . ' AND '; |
|
| 310 | + $filter[] = str_replace('cat_id', $this->table_name.'.cat_id', $cat_filter); |
|
| 311 | + $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter).' AND '; |
|
| 313 | 312 | unset($filter['cat_id']); |
| 314 | 313 | } |
| 315 | 314 | if ($filter['tid']) |
| 316 | 315 | { |
| 317 | - $filter[$this->table_name . '.contact_tid'] = $param['col_filter']['tid']; |
|
| 318 | - $join .= 'a2.contact_tid = ' . $this->db->quote($filter['tid']) . ' AND '; |
|
| 316 | + $filter[$this->table_name.'.contact_tid'] = $param['col_filter']['tid']; |
|
| 317 | + $join .= 'a2.contact_tid = '.$this->db->quote($filter['tid']).' AND '; |
|
| 319 | 318 | unset($filter['tid']); |
| 320 | 319 | } |
| 321 | 320 | else |
@@ -323,33 +322,33 @@ discard block |
||
| 323 | 322 | $join .= 'a2.contact_tid != \'D\' AND '; |
| 324 | 323 | } |
| 325 | 324 | // add filter for read ACL in sql, if user is NOT the owner of the addressbook |
| 326 | - if (array_key_exists('owner',$param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
| 325 | + if (array_key_exists('owner', $param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
| 327 | 326 | { |
| 328 | 327 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
| 329 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
| 328 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
| 330 | 329 | } |
| 331 | 330 | else |
| 332 | 331 | { |
| 333 | 332 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 334 | 333 | if (array_key_exists('owner', $param)) |
| 335 | 334 | { |
| 336 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
| 335 | + if (!$this->grants[(int)$param['owner']]) return false; // we have no access to that addressbook |
|
| 337 | 336 | |
| 338 | 337 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
| 339 | 338 | $filter[$this->table_name.'.private'] = 0; |
| 340 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
| 341 | - $join .= 'a2.contact_private = ' . $this->db->quote($filter['private']) . ' AND '; |
|
| 339 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
| 340 | + $join .= 'a2.contact_private = '.$this->db->quote($filter['private']).' AND '; |
|
| 342 | 341 | } |
| 343 | 342 | else // search all addressbooks, incl. accounts |
| 344 | 343 | { |
| 345 | 344 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
| 346 | 345 | { |
| 347 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 346 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 348 | 347 | } |
| 349 | 348 | $filter[] = $access = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 350 | 349 | " OR {$this->table_name}.contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
| 351 | - implode(',',array_keys($this->grants))."))"; |
|
| 352 | - $join .= str_replace($this->table_name, 'a2', $access) . ' AND '; |
|
| 350 | + implode(',', array_keys($this->grants))."))"; |
|
| 351 | + $join .= str_replace($this->table_name, 'a2', $access).' AND '; |
|
| 353 | 352 | } |
| 354 | 353 | } |
| 355 | 354 | if ($param['searchletter']) |
@@ -358,34 +357,33 @@ discard block |
||
| 358 | 357 | } |
| 359 | 358 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
| 360 | 359 | $group = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields'] ? |
| 361 | - explode(',',$GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']): |
|
| 362 | - array('n_family', 'org_name', 'contact_email'); |
|
| 360 | + explode(',', $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']) : array('n_family', 'org_name', 'contact_email'); |
|
| 363 | 361 | $match_count = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] ? |
| 364 | 362 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] : 3; |
| 365 | 363 | |
| 366 | 364 | $columns = Array(); |
| 367 | 365 | $extra = Array(); |
| 368 | 366 | $order = in_array($param['order'], $group) ? $param['order'] : $group[0]; |
| 369 | - $join .= $this->table_name .'.contact_id != a2.contact_id AND ('; |
|
| 367 | + $join .= $this->table_name.'.contact_id != a2.contact_id AND ('; |
|
| 370 | 368 | $join_fields = Array(); |
| 371 | - foreach($group as $field) |
|
| 369 | + foreach ($group as $field) |
|
| 372 | 370 | { |
| 373 | 371 | $extra[] = "IF({$this->table_name}.$field = a2.$field, 1, 0)"; |
| 374 | - $join_fields[] = $this->table_name . ".$field = a2.$field"; |
|
| 372 | + $join_fields[] = $this->table_name.".$field = a2.$field"; |
|
| 375 | 373 | $columns[] = "IF({$this->table_name}.$field = a2.$field, {$this->table_name}.$field, '') AS $field"; |
| 376 | 374 | } |
| 377 | 375 | $extra = Array( |
| 378 | - implode('+', $extra) . ' AS match_count' |
|
| 376 | + implode('+', $extra).' AS match_count' |
|
| 379 | 377 | ); |
| 380 | - $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; |
|
| 378 | + $join .= $this->db->column_data_implode(' OR ', $join_fields).')'; |
|
| 381 | 379 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
| 382 | 380 | { |
| 383 | 381 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
| 384 | 382 | { |
| 385 | - $join .=' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
| 386 | - $join .=' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
| 387 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_1.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
| 388 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_2.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
| 383 | + $join .= ' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
| 384 | + $join .= ' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
| 385 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_1.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
| 386 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_2.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
| 389 | 387 | } |
| 390 | 388 | else |
| 391 | 389 | { |
@@ -399,17 +397,17 @@ discard block |
||
| 399 | 397 | if ($param['search'] && !is_array($param['search'])) |
| 400 | 398 | { |
| 401 | 399 | $search_cols = array(); |
| 402 | - foreach($group as $col) |
|
| 400 | + foreach ($group as $col) |
|
| 403 | 401 | { |
| 404 | - $search_cols[] = $this->table_name . '.' . $col; |
|
| 402 | + $search_cols[] = $this->table_name.'.'.$col; |
|
| 405 | 403 | } |
| 406 | - $search = $this->search2criteria($param['search'],$wildcard,$op, null, $search_cols); |
|
| 404 | + $search = $this->search2criteria($param['search'], $wildcard, $op, null, $search_cols); |
|
| 407 | 405 | $criteria = array($search); |
| 408 | 406 | } |
| 409 | 407 | $query = $this->parse_search(array_merge($criteria, $filter), $wildcard, false, ' AND '); |
| 410 | 408 | |
| 411 | 409 | $sub_query = $this->db->select($this->table_name, |
| 412 | - 'DISTINCT ' . implode(', ',array_merge($columns, $extra)), |
|
| 410 | + 'DISTINCT '.implode(', ', array_merge($columns, $extra)), |
|
| 413 | 411 | $query, |
| 414 | 412 | False, False, 0, $append, False, -1, |
| 415 | 413 | $join |
@@ -422,15 +420,15 @@ discard block |
||
| 422 | 420 | } |
| 423 | 421 | |
| 424 | 422 | $rows = $this->db->query( |
| 425 | - "SELECT $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
| 426 | - ' FROM (' . $sub_query . ') AS matches GROUP BY ' . implode(',',$group) . |
|
| 427 | - ' HAVING group_count > 1 ORDER BY ' . $order, |
|
| 428 | - __LINE__, __FILE__, (int)$param['start'],$mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
| 423 | + "SELECT $mysql_calc_rows ".$columns.', COUNT(contact_id) AS group_count'. |
|
| 424 | + ' FROM ('.$sub_query.') AS matches GROUP BY '.implode(',', $group). |
|
| 425 | + ' HAVING group_count > 1 ORDER BY '.$order, |
|
| 426 | + __LINE__, __FILE__, (int)$param['start'], $mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
| 429 | 427 | ); |
| 430 | 428 | |
| 431 | 429 | // Go through rows and only return one for each pair/triplet/etc. of matches |
| 432 | 430 | $dupes = array(); |
| 433 | - foreach($rows as $key => $row) |
|
| 431 | + foreach ($rows as $key => $row) |
|
| 434 | 432 | { |
| 435 | 433 | $row['email'] = $row['contact_email']; |
| 436 | 434 | $row['email_home'] = $row['contact_email_home']; |
@@ -471,9 +469,9 @@ discard block |
||
| 471 | 469 | * @param boolean $ignore_acl =false true: no acl check |
| 472 | 470 | * @return boolean/array of matching rows (the row is an array of the cols) or False |
| 473 | 471 | */ |
| 474 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false) |
|
| 472 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false, $ignore_acl = false) |
|
| 475 | 473 | { |
| 476 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 474 | + if ((int)$this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 477 | 475 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
| 478 | 476 | |
| 479 | 477 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -489,10 +487,10 @@ discard block |
||
| 489 | 487 | { |
| 490 | 488 | if ($filter['cat_id'][0] == '!') |
| 491 | 489 | { |
| 492 | - $filter['cat_id'] = substr($filter['cat_id'],1); |
|
| 490 | + $filter['cat_id'] = substr($filter['cat_id'], 1); |
|
| 493 | 491 | $not = 'NOT'; |
| 494 | 492 | } |
| 495 | - $filter[] = $this->_cat_filter($filter['cat_id'],$not); |
|
| 493 | + $filter[] = $this->_cat_filter($filter['cat_id'], $not); |
|
| 496 | 494 | unset($filter['cat_id']); |
| 497 | 495 | } |
| 498 | 496 | |
@@ -502,17 +500,17 @@ discard block |
||
| 502 | 500 | { |
| 503 | 501 | // add read ACL for groupmembers (they have no |
| 504 | 502 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
| 505 | - (!isset($filter['owner']) || in_array('0',(array)$filter['owner']))) |
|
| 503 | + (!isset($filter['owner']) || in_array('0', (array)$filter['owner']))) |
|
| 506 | 504 | { |
| 507 | 505 | $groupmembers = array(); |
| 508 | - foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $group_id) |
|
| 506 | + foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $group_id) |
|
| 509 | 507 | { |
| 510 | - if (($members = $GLOBALS['egw']->accounts->members($group_id,true))) |
|
| 508 | + if (($members = $GLOBALS['egw']->accounts->members($group_id, true))) |
|
| 511 | 509 | { |
| 512 | - $groupmembers = array_merge($groupmembers,$members); |
|
| 510 | + $groupmembers = array_merge($groupmembers, $members); |
|
| 513 | 511 | } |
| 514 | 512 | } |
| 515 | - $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.',array( |
|
| 513 | + $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.', array( |
|
| 516 | 514 | 'account_id' => array_unique($groupmembers), |
| 517 | 515 | )); |
| 518 | 516 | } |
@@ -520,34 +518,34 @@ discard block |
||
| 520 | 518 | if (isset($filter['owner'])) |
| 521 | 519 | { |
| 522 | 520 | // no grants for selected owner/addressbook |
| 523 | - if (!array_intersect((array)$filter['owner'],array_keys($this->grants))) |
|
| 521 | + if (!array_intersect((array)$filter['owner'], array_keys($this->grants))) |
|
| 524 | 522 | { |
| 525 | 523 | if (!isset($groupmember_sql)) return false; |
| 526 | - $filter[] = substr($groupmember_sql,4); |
|
| 524 | + $filter[] = substr($groupmember_sql, 4); |
|
| 527 | 525 | unset($filter['owner']); |
| 528 | 526 | } |
| 529 | 527 | // for an owner filter, which does NOT include current user, filter out private entries |
| 530 | - elseif (!in_array($GLOBALS['egw_info']['user']['account_id'],$filter['owner'])) |
|
| 528 | + elseif (!in_array($GLOBALS['egw_info']['user']['account_id'], $filter['owner'])) |
|
| 531 | 529 | { |
| 532 | 530 | $filter['private'] = 0; |
| 533 | 531 | } |
| 534 | 532 | // if multiple addressbooks (incl. current owner) are searched, we need full acl filter |
| 535 | - elseif(count($filter['owner']) > 1) |
|
| 533 | + elseif (count($filter['owner']) > 1) |
|
| 536 | 534 | { |
| 537 | 535 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 538 | 536 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
| 539 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 537 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 540 | 538 | } |
| 541 | 539 | } |
| 542 | 540 | else // search all addressbooks, incl. accounts |
| 543 | 541 | { |
| 544 | 542 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
| 545 | 543 | { |
| 546 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 544 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 547 | 545 | } |
| 548 | 546 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 549 | 547 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
| 550 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 548 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 551 | 549 | } |
| 552 | 550 | } |
| 553 | 551 | if (isset($filter['list'])) |
@@ -565,24 +563,24 @@ discard block |
||
| 565 | 563 | unset($filter['list']); |
| 566 | 564 | } |
| 567 | 565 | // add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin) |
| 568 | - if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' && |
|
| 569 | - strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter)) |
|
| 566 | + if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository, 0, 3) == 'sql' && |
|
| 567 | + strpos($join, $GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id', $filter)) |
|
| 570 | 568 | { |
| 571 | 569 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
| 572 | 570 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
| 573 | 571 | { |
| 574 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
| 572 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
| 575 | 573 | } |
| 576 | 574 | } |
| 577 | 575 | if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
| 578 | 576 | { |
| 579 | - switch(gettype($only_keys)) |
|
| 577 | + switch (gettype($only_keys)) |
|
| 580 | 578 | { |
| 581 | 579 | case 'boolean': |
| 582 | 580 | // Correctly handled by parent class |
| 583 | 581 | break; |
| 584 | 582 | case 'string': |
| 585 | - $only_keys = explode(',',$only_keys); |
|
| 583 | + $only_keys = explode(',', $only_keys); |
|
| 586 | 584 | // fall through |
| 587 | 585 | } |
| 588 | 586 | // postgres requires that expressions in order by appear in the columns of a distinct select |
@@ -590,14 +588,14 @@ discard block |
||
| 590 | 588 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
| 591 | 589 | $order_by, $all_matches, PREG_SET_ORDER)) |
| 592 | 590 | { |
| 593 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
| 594 | - foreach($all_matches as $matches) |
|
| 591 | + if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',', $extra_cols) : array(); |
|
| 592 | + foreach ($all_matches as $matches) |
|
| 595 | 593 | { |
| 596 | 594 | $table = ''; |
| 597 | 595 | $column = $matches[1]; |
| 598 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
| 596 | + if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
| 599 | 597 | if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
| 600 | - if (strpos($column,'.') === false) |
|
| 598 | + if (strpos($column, '.') === false) |
|
| 601 | 599 | { |
| 602 | 600 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
| 603 | 601 | if (isset($this->db_cols[$column])) |
@@ -613,34 +611,34 @@ discard block |
||
| 613 | 611 | //_debug_array($matches); |
| 614 | 612 | if (!empty($order_by) && $table) // postgres requires explizit order by |
| 615 | 613 | { |
| 616 | - $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
|
| 614 | + $order_by = str_replace($matches[0], $table.$column.' '.$matches[2].' '.$matches[3].$matches[4], $order_by); |
|
| 617 | 615 | } |
| 618 | 616 | } |
| 619 | 617 | //_debug_array($order_by); _debug_array($extra_cols); |
| 620 | 618 | } |
| 621 | 619 | |
| 622 | 620 | // Understand search by date with wildcard (????.10.??) according to user date preference |
| 623 | - if(is_string($criteria) && strpos($criteria, '?') !== false) |
|
| 621 | + if (is_string($criteria) && strpos($criteria, '?') !== false) |
|
| 624 | 622 | { |
| 625 | 623 | // First, check for a 'date', with wildcards, in the user's format |
| 626 | - $date_regex = str_replace('Q','d', |
|
| 627 | - str_replace(array('Y','m','d','.','-'), |
|
| 628 | - array('(?P<Y>(?:\?|\Q){4})','(?P<m>(?:\?|\Q){2})','(?P<d>(?:\?|\Q){2})','\.','\-'), |
|
| 624 | + $date_regex = str_replace('Q', 'd', |
|
| 625 | + str_replace(array('Y', 'm', 'd', '.', '-'), |
|
| 626 | + array('(?P<Y>(?:\?|\Q){4})', '(?P<m>(?:\?|\Q){2})', '(?P<d>(?:\?|\Q){2})', '\.', '\-'), |
|
| 629 | 627 | $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); |
| 630 | 628 | |
| 631 | - if(preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
| 629 | + if (preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
| 632 | 630 | { |
| 633 | - foreach($matches[0] as $m_id => $match) |
|
| 631 | + foreach ($matches[0] as $m_id => $match) |
|
| 634 | 632 | { |
| 635 | 633 | // Birthday is Y-m-d |
| 636 | - $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*",$criteria); |
|
| 634 | + $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*", $criteria); |
|
| 637 | 635 | } |
| 638 | 636 | } |
| 639 | 637 | } |
| 640 | 638 | } |
| 641 | - $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
| 639 | + $rows = & parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
| 642 | 640 | |
| 643 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
| 641 | + if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
| 644 | 642 | |
| 645 | 643 | return $rows; |
| 646 | 644 | } |
@@ -652,18 +650,18 @@ discard block |
||
| 652 | 650 | * @param int|array $cat_id |
| 653 | 651 | * @return string sql to filter by given cat |
| 654 | 652 | */ |
| 655 | - function _cat_filter($cat_id, $not='') |
|
| 653 | + function _cat_filter($cat_id, $not = '') |
|
| 656 | 654 | { |
| 657 | 655 | if (!is_object($GLOBALS['egw']->categories)) |
| 658 | 656 | { |
| 659 | 657 | $GLOBALS['egw']->categories = new Api\Categories; |
| 660 | 658 | } |
| 661 | - foreach($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
| 659 | + foreach ($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
| 662 | 660 | { |
| 663 | - $cat_filter[] = $this->db->concat("','",cat_id,"','")." $not LIKE '%,$cat,%'"; |
|
| 661 | + $cat_filter[] = $this->db->concat("','", cat_id, "','")." $not LIKE '%,$cat,%'"; |
|
| 664 | 662 | } |
| 665 | - $cfilter = '('.implode(' OR ',$cat_filter).')'; |
|
| 666 | - if(!empty($not)) |
|
| 663 | + $cfilter = '('.implode(' OR ', $cat_filter).')'; |
|
| 664 | + if (!empty($not)) |
|
| 667 | 665 | { |
| 668 | 666 | $cfilter = "( $cfilter OR cat_id IS NULL )"; |
| 669 | 667 | } |
@@ -680,9 +678,9 @@ discard block |
||
| 680 | 678 | function _cat_search($cats) |
| 681 | 679 | { |
| 682 | 680 | $cat_filter = array(); |
| 683 | - foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
|
| 681 | + foreach (is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',', $cats)) as $cat) |
|
| 684 | 682 | { |
| 685 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
| 683 | + if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','", cat_id, "','")." LIKE '%,$cat,%'"; |
|
| 686 | 684 | } |
| 687 | 685 | return $cat_filter; |
| 688 | 686 | } |
@@ -693,32 +691,32 @@ discard block |
||
| 693 | 691 | * @param int $account_id account-id of the old owner |
| 694 | 692 | * @param int $new_owner account-id of the new owner |
| 695 | 693 | */ |
| 696 | - function change_owner($account_id,$new_owner) |
|
| 694 | + function change_owner($account_id, $new_owner) |
|
| 697 | 695 | { |
| 698 | 696 | if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
| 699 | 697 | { |
| 700 | 698 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
| 701 | 699 | } |
| 702 | 700 | // contacts |
| 703 | - $this->db->update($this->table_name,array( |
|
| 701 | + $this->db->update($this->table_name, array( |
|
| 704 | 702 | 'contact_owner' => $new_owner, |
| 705 | - ),array( |
|
| 703 | + ), array( |
|
| 706 | 704 | 'contact_owner' => $account_id, |
| 707 | - ),__LINE__,__FILE__); |
|
| 705 | + ), __LINE__, __FILE__); |
|
| 708 | 706 | |
| 709 | 707 | // cfs |
| 710 | 708 | $this->db->update(self::EXTRA_TABLE, array( |
| 711 | 709 | 'contact_owner' => $new_owner |
| 712 | - ),array( |
|
| 710 | + ), array( |
|
| 713 | 711 | 'contact_owner' => $account_id |
| 714 | 712 | ), __LINE__, __FILE__); |
| 715 | 713 | |
| 716 | 714 | // lists |
| 717 | 715 | $this->db->update($this->lists_table, array( |
| 718 | 716 | 'list_owner' => $new_owner, |
| 719 | - ),array( |
|
| 717 | + ), array( |
|
| 720 | 718 | 'list_owner' => $account_id, |
| 721 | - ),__LINE__,__FILE__); |
|
| 719 | + ), __LINE__, __FILE__); |
|
| 722 | 720 | } |
| 723 | 721 | |
| 724 | 722 | /** |
@@ -732,21 +730,21 @@ discard block |
||
| 732 | 730 | * if int|array only return members from the given owners addressbook(s) |
| 733 | 731 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
| 734 | 732 | */ |
| 735 | - function get_lists($uids,$uid_column='list_owner',$member_attr=null,$limit_in_ab=false) |
|
| 733 | + function get_lists($uids, $uid_column = 'list_owner', $member_attr = null, $limit_in_ab = false) |
|
| 736 | 734 | { |
| 737 | 735 | if (is_array($uids) && array_key_exists('list_id', $uids)) |
| 738 | 736 | { |
| 739 | - $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.',array('list_id' => $uids['list_id'])); |
|
| 737 | + $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.', array('list_id' => $uids['list_id'])); |
|
| 740 | 738 | unset($uids['list_id']); |
| 741 | 739 | } |
| 742 | 740 | $lists = array(); |
| 743 | - foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
|
| 744 | - false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
| 741 | + foreach ($this->db->select($this->lists_table, '*', $uid_column ? array($uid_column=>$uids) : $uids, __LINE__, __FILE__, |
|
| 742 | + false, 'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
| 745 | 743 | { |
| 746 | 744 | if ($member_attr) $row['members'] = array(); |
| 747 | 745 | $lists[$row['list_id']] = $row; |
| 748 | 746 | } |
| 749 | - if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
|
| 747 | + if ($lists && $member_attr && in_array($member_attr, array('contact_id', 'contact_uid', 'caldav_name'))) |
|
| 750 | 748 | { |
| 751 | 749 | if ($limit_in_ab) |
| 752 | 750 | { |
@@ -760,10 +758,9 @@ discard block |
||
| 760 | 758 | $in_ab_join .= "list_owner=$this->table_name.contact_owner"; |
| 761 | 759 | } |
| 762 | 760 | } |
| 763 | - foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
| 761 | + foreach ($this->db->select($this->ab2list_table, "$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
| 764 | 762 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
| 765 | - __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
|
| 766 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
| 763 | + __LINE__, __FILE__, false, $member_attr == 'contact_id' ? '' : '', false, 0, "JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
| 767 | 764 | { |
| 768 | 765 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
| 769 | 766 | } |
@@ -803,7 +800,7 @@ discard block |
||
| 803 | 800 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
| 804 | 801 | * @return int|boolean integer list_id or false on error |
| 805 | 802 | */ |
| 806 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
| 803 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
| 807 | 804 | { |
| 808 | 805 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
| 809 | 806 | if (!$keys && !$data || !(int)$owner) return false; |
@@ -817,7 +814,7 @@ discard block |
||
| 817 | 814 | { |
| 818 | 815 | $data['list_owner'] = $owner; |
| 819 | 816 | } |
| 820 | - if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys,__LINE__,__FILE__)->fetchColumn())) |
|
| 817 | + if (!$keys || !($list_id = $this->db->select($this->lists_table, 'list_id', $keys, __LINE__, __FILE__)->fetchColumn())) |
|
| 821 | 818 | { |
| 822 | 819 | $data['list_created'] = time(); |
| 823 | 820 | $data['list_creator'] = $GLOBALS['egw_info']['user']['account_id']; |
@@ -830,9 +827,9 @@ discard block |
||
| 830 | 827 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
| 831 | 828 | if (!$data['list_id']) unset($data['list_id']); |
| 832 | 829 | |
| 833 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
| 830 | + if (!$this->db->insert($this->lists_table, $data, $keys, __LINE__, __FILE__)) return false; |
|
| 834 | 831 | |
| 835 | - if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
|
| 832 | + if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table, 'list_id')) && |
|
| 836 | 833 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
| 837 | 834 | { |
| 838 | 835 | $update = array(); |
@@ -844,9 +841,9 @@ discard block |
||
| 844 | 841 | { |
| 845 | 842 | $update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf'; |
| 846 | 843 | } |
| 847 | - $this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__); |
|
| 844 | + $this->db->update($this->lists_table, $update, array('list_id'=>$list_id), __LINE__, __FILE__); |
|
| 848 | 845 | |
| 849 | - $this->add2list($list_id,$contacts,array()); |
|
| 846 | + $this->add2list($list_id, $contacts, array()); |
|
| 850 | 847 | } |
| 851 | 848 | if ($keys) $data += $keys; |
| 852 | 849 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
@@ -861,39 +858,39 @@ discard block |
||
| 861 | 858 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
| 862 | 859 | * @return false on error |
| 863 | 860 | */ |
| 864 | - function add2list($contact,$list,array $existing=null) |
|
| 861 | + function add2list($contact, $list, array $existing = null) |
|
| 865 | 862 | { |
| 866 | 863 | if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
| 867 | 864 | |
| 868 | 865 | if (!is_array($existing)) |
| 869 | 866 | { |
| 870 | 867 | $existing = array(); |
| 871 | - foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row) |
|
| 868 | + foreach ($this->db->select($this->ab2list_table, 'contact_id', array('list_id'=>$list), __LINE__, __FILE__) as $row) |
|
| 872 | 869 | { |
| 873 | 870 | $existing[] = $row['contact_id']; |
| 874 | 871 | } |
| 875 | 872 | } |
| 876 | - if (!($to_add = array_diff((array)$contact,$existing))) |
|
| 873 | + if (!($to_add = array_diff((array)$contact, $existing))) |
|
| 877 | 874 | { |
| 878 | - return true; // no need to insert it, would give sql error |
|
| 875 | + return true; // no need to insert it, would give sql error |
|
| 879 | 876 | } |
| 880 | - foreach($to_add as $contact) |
|
| 877 | + foreach ($to_add as $contact) |
|
| 881 | 878 | { |
| 882 | - $this->db->insert($this->ab2list_table,array( |
|
| 879 | + $this->db->insert($this->ab2list_table, array( |
|
| 883 | 880 | 'contact_id' => $contact, |
| 884 | 881 | 'list_id' => $list, |
| 885 | 882 | 'list_added' => time(), |
| 886 | 883 | 'list_added_by' => $GLOBALS['egw_info']['user']['account_id'], |
| 887 | - ),array(),__LINE__,__FILE__); |
|
| 884 | + ), array(), __LINE__, __FILE__); |
|
| 888 | 885 | } |
| 889 | 886 | // update etag |
| 890 | - return $this->db->update($this->lists_table,array( |
|
| 887 | + return $this->db->update($this->lists_table, array( |
|
| 891 | 888 | 'list_etag=list_etag+1', |
| 892 | 889 | 'list_modified' => time(), |
| 893 | 890 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
| 894 | - ),array( |
|
| 891 | + ), array( |
|
| 895 | 892 | 'list_id' => $list, |
| 896 | - ),__LINE__,__FILE__); |
|
| 893 | + ), __LINE__, __FILE__); |
|
| 897 | 894 | } |
| 898 | 895 | |
| 899 | 896 | /** |
@@ -903,7 +900,7 @@ discard block |
||
| 903 | 900 | * @param int $list =null list-id or null to remove from all lists |
| 904 | 901 | * @return false on error |
| 905 | 902 | */ |
| 906 | - function remove_from_list($contact,$list=null) |
|
| 903 | + function remove_from_list($contact, $list = null) |
|
| 907 | 904 | { |
| 908 | 905 | if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
| 909 | 906 | |
@@ -917,24 +914,24 @@ discard block |
||
| 917 | 914 | else |
| 918 | 915 | { |
| 919 | 916 | $list = array(); |
| 920 | - foreach($this->db->select($this->ab2list_table,'list_id',$where,__LINE__,__FILE__) as $row) |
|
| 917 | + foreach ($this->db->select($this->ab2list_table, 'list_id', $where, __LINE__, __FILE__) as $row) |
|
| 921 | 918 | { |
| 922 | 919 | $list[] = $row['list_id']; |
| 923 | 920 | } |
| 924 | 921 | } |
| 925 | - if (!$this->db->delete($this->ab2list_table,$where,__LINE__,__FILE__)) |
|
| 922 | + if (!$this->db->delete($this->ab2list_table, $where, __LINE__, __FILE__)) |
|
| 926 | 923 | { |
| 927 | 924 | return false; |
| 928 | 925 | } |
| 929 | - foreach((array)$list as $list_id) |
|
| 926 | + foreach ((array)$list as $list_id) |
|
| 930 | 927 | { |
| 931 | - $this->db->update($this->lists_table,array( |
|
| 928 | + $this->db->update($this->lists_table, array( |
|
| 932 | 929 | 'list_etag=list_etag+1', |
| 933 | 930 | 'list_modified' => time(), |
| 934 | 931 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
| 935 | - ),array( |
|
| 932 | + ), array( |
|
| 936 | 933 | 'list_id' => $list_id, |
| 937 | - ),__LINE__,__FILE__); |
|
| 934 | + ), __LINE__, __FILE__); |
|
| 938 | 935 | } |
| 939 | 936 | return true; |
| 940 | 937 | } |
@@ -947,9 +944,9 @@ discard block |
||
| 947 | 944 | */ |
| 948 | 945 | function delete_list($list) |
| 949 | 946 | { |
| 950 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
| 947 | + if (!$this->db->delete($this->lists_table, array('list_id' => $list), __LINE__, __FILE__)) return false; |
|
| 951 | 948 | |
| 952 | - $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
|
| 949 | + $this->db->delete($this->ab2list_table, array('list_id' => $list), __LINE__, __FILE__); |
|
| 953 | 950 | |
| 954 | 951 | return $this->db->affected_rows(); |
| 955 | 952 | } |
@@ -960,12 +957,12 @@ discard block |
||
| 960 | 957 | * @param int|array $owner =null null for all lists user has access too |
| 961 | 958 | * @return int |
| 962 | 959 | */ |
| 963 | - function lists_ctag($owner=null) |
|
| 960 | + function lists_ctag($owner = null) |
|
| 964 | 961 | { |
| 965 | 962 | if (is_null($owner)) $owner = array_keys($this->grants); |
| 966 | 963 | |
| 967 | - if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
|
| 968 | - __LINE__,__FILE__)->fetchColumn())) |
|
| 964 | + if (!($modified = $this->db->select($this->lists_table, 'MAX(list_modified)', array('list_owner'=>$owner), |
|
| 965 | + __LINE__, __FILE__)->fetchColumn())) |
|
| 969 | 966 | { |
| 970 | 967 | return 0; |
| 971 | 968 | } |
@@ -980,7 +977,7 @@ discard block |
||
| 980 | 977 | * @param string $join |
| 981 | 978 | * @return array|boolean |
| 982 | 979 | */ |
| 983 | - function read($keys,$extra_cols='',$join='') |
|
| 980 | + function read($keys, $extra_cols = '', $join = '') |
|
| 984 | 981 | { |
| 985 | 982 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
| 986 | 983 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -993,11 +990,11 @@ discard block |
||
| 993 | 990 | $keys = array('uid' => $keys); |
| 994 | 991 | } |
| 995 | 992 | try { |
| 996 | - $contact = parent::read($keys,$extra_cols,$join); |
|
| 993 | + $contact = parent::read($keys, $extra_cols, $join); |
|
| 997 | 994 | } |
| 998 | 995 | // catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267) |
| 999 | 996 | // caused by non-ascii chars compared with ascii field uid |
| 1000 | - catch(Api\Db\Exception $e) { |
|
| 997 | + catch (Api\Db\Exception $e) { |
|
| 1001 | 998 | _egw_log_exception($e); |
| 1002 | 999 | return false; |
| 1003 | 1000 | } |
@@ -1005,7 +1002,7 @@ discard block |
||
| 1005 | 1002 | // enforce a minium uid strength |
| 1006 | 1003 | if (is_array($contact) && (!isset($contact['uid']) |
| 1007 | 1004 | || strlen($contact['uid']) < $minimum_uid_length)) { |
| 1008 | - parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
|
| 1005 | + parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook', $contact['id']))); |
|
| 1009 | 1006 | } |
| 1010 | 1007 | return $contact; |
| 1011 | 1008 | } |
@@ -1019,7 +1016,7 @@ discard block |
||
| 1019 | 1016 | */ |
| 1020 | 1017 | function save($keys = NULL, $extra_where = NULL) |
| 1021 | 1018 | { |
| 1022 | - unset($extra_where); // not used, but required by function signature |
|
| 1019 | + unset($extra_where); // not used, but required by function signature |
|
| 1023 | 1020 | |
| 1024 | 1021 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
| 1025 | 1022 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -1035,9 +1032,9 @@ discard block |
||
| 1035 | 1032 | { |
| 1036 | 1033 | $etag = $this->data['etag']; |
| 1037 | 1034 | unset($this->data['etag']); |
| 1038 | - if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
|
| 1035 | + if (!($err = parent::save(array('contact_etag=contact_etag+1'), array('contact_etag' => $etag)))) |
|
| 1039 | 1036 | { |
| 1040 | - $this->data['etag'] = $etag+1; |
|
| 1037 | + $this->data['etag'] = $etag + 1; |
|
| 1041 | 1038 | } |
| 1042 | 1039 | else |
| 1043 | 1040 | { |
@@ -1057,7 +1054,7 @@ discard block |
||
| 1057 | 1054 | // enforce a minium uid strength |
| 1058 | 1055 | if (!isset($this->data['uid']) || strlen($this->data['uid']) < $minimum_uid_length) |
| 1059 | 1056 | { |
| 1060 | - $update['uid'] = Api\CalDAV::generate_uid('addressbook',$this->data['id']); |
|
| 1057 | + $update['uid'] = Api\CalDAV::generate_uid('addressbook', $this->data['id']); |
|
| 1061 | 1058 | //echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>"; |
| 1062 | 1059 | } |
| 1063 | 1060 | // set carddav_name, if not given by caller |
@@ -1075,17 +1072,17 @@ discard block |
||
| 1075 | 1072 | 'contact_id' => $this->data['id'], |
| 1076 | 1073 | ), __LINE__, __FILE__)->fetchColumn(); |
| 1077 | 1074 | } |
| 1078 | - $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
| 1075 | + $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
| 1079 | 1076 | $backup = Api\Vfs::$is_root; Api\Vfs::$is_root = true; |
| 1080 | 1077 | if (empty($this->data['jpegphoto'])) |
| 1081 | 1078 | { |
| 1082 | 1079 | unlink($path); |
| 1083 | - $update['files'] = $this->data['files'] & ~Api\Contacts::FILES_BIT_PHOTO; |
|
| 1080 | + $update['files'] = $this->data['files']&~Api\Contacts::FILES_BIT_PHOTO; |
|
| 1084 | 1081 | } |
| 1085 | 1082 | else |
| 1086 | 1083 | { |
| 1087 | 1084 | file_put_contents($path, $this->data['jpegphoto']); |
| 1088 | - $update['files'] = $this->data['files'] | Api\Contacts::FILES_BIT_PHOTO; |
|
| 1085 | + $update['files'] = $this->data['files']|Api\Contacts::FILES_BIT_PHOTO; |
|
| 1089 | 1086 | } |
| 1090 | 1087 | Api\Vfs::$is_root = $backup; |
| 1091 | 1088 | } |
@@ -1107,7 +1104,7 @@ discard block |
||
| 1107 | 1104 | { |
| 1108 | 1105 | if (!$list) return false; |
| 1109 | 1106 | |
| 1110 | - return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
|
| 1107 | + return $this->db->select($this->lists_table, '*', array('list_id'=>$list), __LINE__, __FILE__)->fetch(); |
|
| 1111 | 1108 | } |
| 1112 | 1109 | |
| 1113 | 1110 | /** |
@@ -1118,9 +1115,9 @@ discard block |
||
| 1118 | 1115 | * @param array $extra_cols =array() extra-data to be saved |
| 1119 | 1116 | * @return bool false on success, errornumber on failure |
| 1120 | 1117 | */ |
| 1121 | - function save_customfields(&$data, array $extra_cols=array()) |
|
| 1118 | + function save_customfields(&$data, array $extra_cols = array()) |
|
| 1122 | 1119 | { |
| 1123 | - return parent::save_customfields($data, array('contact_owner' => $data['owner'])+$extra_cols); |
|
| 1120 | + return parent::save_customfields($data, array('contact_owner' => $data['owner']) + $extra_cols); |
|
| 1124 | 1121 | } |
| 1125 | 1122 | |
| 1126 | 1123 | /** |
@@ -1129,6 +1126,6 @@ discard block |
||
| 1129 | 1126 | */ |
| 1130 | 1127 | function delete_customfields($data) |
| 1131 | 1128 | { |
| 1132 | - $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
|
| 1129 | + $this->db->delete($this->extra_table, $data, __LINE__, __FILE__); |
|
| 1133 | 1130 | } |
| 1134 | 1131 | } |
@@ -112,11 +112,20 @@ discard block |
||
| 112 | 112 | $filter = is_array($param['col_filter']) ? $param['col_filter'] : array(); |
| 113 | 113 | $join = ''; |
| 114 | 114 | $op = 'OR'; |
| 115 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
| 115 | + if (isset($param['op']) && !empty($param['op'])) |
|
| 116 | + { |
|
| 117 | + $op = $param['op']; |
|
| 118 | + } |
|
| 116 | 119 | $advanced_search = false; |
| 117 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
| 120 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
| 121 | + { |
|
| 122 | + $advanced_search = true; |
|
| 123 | + } |
|
| 118 | 124 | $wildcard ='%'; |
| 119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 125 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
| 126 | + { |
|
| 127 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 128 | + } |
|
| 120 | 129 | |
| 121 | 130 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 122 | 131 | if ($filter['cat_id']) |
@@ -134,7 +143,11 @@ discard block |
||
| 134 | 143 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 135 | 144 | if ($param['owner']) |
| 136 | 145 | { |
| 137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
| 146 | + if (!$this->grants[(int) $filter['owner']]) |
|
| 147 | + { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 150 | + // we have no access to that addressbook |
|
| 138 | 151 | |
| 139 | 152 | $filter['owner'] = $param['owner']; |
| 140 | 153 | $filter['private'] = 0; |
@@ -223,7 +236,10 @@ discard block |
||
| 223 | 236 | $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
| 224 | 237 | array($param['start'],$param['num_rows']),$filter,$join); |
| 225 | 238 | |
| 226 | - if (!$rows) return false; |
|
| 239 | + if (!$rows) |
|
| 240 | + { |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 227 | 243 | |
| 228 | 244 | // query the values for *_count == 1, to display them instead |
| 229 | 245 | $filter['org_name'] = $orgs = array(); |
@@ -298,11 +314,20 @@ discard block |
||
| 298 | 314 | $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
| 299 | 315 | $filter = $param['col_filter']; |
| 300 | 316 | $op = 'OR'; |
| 301 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
| 317 | + if (isset($param['op']) && !empty($param['op'])) |
|
| 318 | + { |
|
| 319 | + $op = $param['op']; |
|
| 320 | + } |
|
| 302 | 321 | $advanced_search = false; |
| 303 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
| 322 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
| 323 | + { |
|
| 324 | + $advanced_search = true; |
|
| 325 | + } |
|
| 304 | 326 | $wildcard ='%'; |
| 305 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 327 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
| 328 | + { |
|
| 329 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 330 | + } |
|
| 306 | 331 | |
| 307 | 332 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 308 | 333 | if ($param['cat_id']) |
@@ -333,7 +358,11 @@ discard block |
||
| 333 | 358 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 334 | 359 | if (array_key_exists('owner', $param)) |
| 335 | 360 | { |
| 336 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
| 361 | + if (!$this->grants[(int) $param['owner']]) |
|
| 362 | + { |
|
| 363 | + return false; |
|
| 364 | + } |
|
| 365 | + // we have no access to that addressbook |
|
| 337 | 366 | |
| 338 | 367 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
| 339 | 368 | $filter[$this->table_name.'.private'] = 0; |
@@ -473,7 +502,10 @@ discard block |
||
| 473 | 502 | */ |
| 474 | 503 | function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false) |
| 475 | 504 | { |
| 476 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 505 | + if ((int) $this->debug >= 4) |
|
| 506 | + { |
|
| 507 | + echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 508 | + } |
|
| 477 | 509 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
| 478 | 510 | |
| 479 | 511 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -522,7 +554,10 @@ discard block |
||
| 522 | 554 | // no grants for selected owner/addressbook |
| 523 | 555 | if (!array_intersect((array)$filter['owner'],array_keys($this->grants))) |
| 524 | 556 | { |
| 525 | - if (!isset($groupmember_sql)) return false; |
|
| 557 | + if (!isset($groupmember_sql)) |
|
| 558 | + { |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 526 | 561 | $filter[] = substr($groupmember_sql,4); |
| 527 | 562 | unset($filter['owner']); |
| 528 | 563 | } |
@@ -574,13 +609,16 @@ discard block |
||
| 574 | 609 | $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
| 575 | 610 | } |
| 576 | 611 | } |
| 577 | - if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
|
| 612 | + if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) |
|
| 613 | + { |
|
| 614 | + // search also adds a join for custom fields! |
|
| 578 | 615 | { |
| 579 | 616 | switch(gettype($only_keys)) |
| 580 | 617 | { |
| 581 | 618 | case 'boolean': |
| 582 | 619 | // Correctly handled by parent class |
| 583 | 620 | break; |
| 621 | + } |
|
| 584 | 622 | case 'string': |
| 585 | 623 | $only_keys = explode(',',$only_keys); |
| 586 | 624 | // fall through |
@@ -590,13 +628,23 @@ discard block |
||
| 590 | 628 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
| 591 | 629 | $order_by, $all_matches, PREG_SET_ORDER)) |
| 592 | 630 | { |
| 593 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
| 631 | + if (!is_array($extra_cols)) |
|
| 632 | + { |
|
| 633 | + $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
| 634 | + } |
|
| 594 | 635 | foreach($all_matches as $matches) |
| 595 | 636 | { |
| 596 | 637 | $table = ''; |
| 597 | 638 | $column = $matches[1]; |
| 598 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
| 599 | - if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
|
| 639 | + if ($column[0] == '#') |
|
| 640 | + { |
|
| 641 | + continue; |
|
| 642 | + } |
|
| 643 | + // order by custom field is handeled in so_sql_cf anyway |
|
| 644 | + if (($key = array_search($column, $this->db_cols)) !== false) |
|
| 645 | + { |
|
| 646 | + $column = $key; |
|
| 647 | + } |
|
| 600 | 648 | if (strpos($column,'.') === false) |
| 601 | 649 | { |
| 602 | 650 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
@@ -611,10 +659,13 @@ discard block |
||
| 611 | 659 | } |
| 612 | 660 | $extra_cols[] = $table.$column.' '.$matches[2]; |
| 613 | 661 | //_debug_array($matches); |
| 614 | - if (!empty($order_by) && $table) // postgres requires explizit order by |
|
| 662 | + if (!empty($order_by) && $table) |
|
| 663 | + { |
|
| 664 | + // postgres requires explizit order by |
|
| 615 | 665 | { |
| 616 | 666 | $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
| 617 | 667 | } |
| 668 | + } |
|
| 618 | 669 | } |
| 619 | 670 | //_debug_array($order_by); _debug_array($extra_cols); |
| 620 | 671 | } |
@@ -640,7 +691,11 @@ discard block |
||
| 640 | 691 | } |
| 641 | 692 | $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
| 642 | 693 | |
| 643 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
| 694 | + if ($start === false) |
|
| 695 | + { |
|
| 696 | + $this->total = is_array($rows) ? count($rows) : 0; |
|
| 697 | + } |
|
| 698 | + // so_sql sets total only for $start !== false! |
|
| 644 | 699 | |
| 645 | 700 | return $rows; |
| 646 | 701 | } |
@@ -682,7 +737,10 @@ discard block |
||
| 682 | 737 | $cat_filter = array(); |
| 683 | 738 | foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
| 684 | 739 | { |
| 685 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
| 740 | + if (is_numeric($cat)) |
|
| 741 | + { |
|
| 742 | + $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
| 743 | + } |
|
| 686 | 744 | } |
| 687 | 745 | return $cat_filter; |
| 688 | 746 | } |
@@ -695,10 +753,13 @@ discard block |
||
| 695 | 753 | */ |
| 696 | 754 | function change_owner($account_id,$new_owner) |
| 697 | 755 | { |
| 698 | - if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
|
| 756 | + if (!$new_owner) |
|
| 757 | + { |
|
| 758 | + // otherwise we would create an account (contact_owner==0) |
|
| 699 | 759 | { |
| 700 | 760 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
| 701 | 761 | } |
| 762 | + } |
|
| 702 | 763 | // contacts |
| 703 | 764 | $this->db->update($this->table_name,array( |
| 704 | 765 | 'contact_owner' => $new_owner, |
@@ -743,7 +804,10 @@ discard block |
||
| 743 | 804 | foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
| 744 | 805 | false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
| 745 | 806 | { |
| 746 | - if ($member_attr) $row['members'] = array(); |
|
| 807 | + if ($member_attr) |
|
| 808 | + { |
|
| 809 | + $row['members'] = array(); |
|
| 810 | + } |
|
| 747 | 811 | $lists[$row['list_id']] = $row; |
| 748 | 812 | } |
| 749 | 813 | if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
@@ -806,9 +870,15 @@ discard block |
||
| 806 | 870 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
| 807 | 871 | { |
| 808 | 872 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
| 809 | - if (!$keys && !$data || !(int)$owner) return false; |
|
| 873 | + if (!$keys && !$data || !(int)$owner) |
|
| 874 | + { |
|
| 875 | + return false; |
|
| 876 | + } |
|
| 810 | 877 | |
| 811 | - if ($keys && !is_array($keys)) $keys = array('list_name' => $keys); |
|
| 878 | + if ($keys && !is_array($keys)) |
|
| 879 | + { |
|
| 880 | + $keys = array('list_name' => $keys); |
|
| 881 | + } |
|
| 812 | 882 | if ($keys) |
| 813 | 883 | { |
| 814 | 884 | $keys['list_owner'] = $owner; |
@@ -828,9 +898,15 @@ discard block |
||
| 828 | 898 | } |
| 829 | 899 | $data['list_modified'] = time(); |
| 830 | 900 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
| 831 | - if (!$data['list_id']) unset($data['list_id']); |
|
| 901 | + if (!$data['list_id']) |
|
| 902 | + { |
|
| 903 | + unset($data['list_id']); |
|
| 904 | + } |
|
| 832 | 905 | |
| 833 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
| 906 | + if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) |
|
| 907 | + { |
|
| 908 | + return false; |
|
| 909 | + } |
|
| 834 | 910 | |
| 835 | 911 | if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
| 836 | 912 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
@@ -848,7 +924,10 @@ discard block |
||
| 848 | 924 | |
| 849 | 925 | $this->add2list($list_id,$contacts,array()); |
| 850 | 926 | } |
| 851 | - if ($keys) $data += $keys; |
|
| 927 | + if ($keys) |
|
| 928 | + { |
|
| 929 | + $data += $keys; |
|
| 930 | + } |
|
| 852 | 931 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
| 853 | 932 | return $list_id; |
| 854 | 933 | } |
@@ -863,7 +942,10 @@ discard block |
||
| 863 | 942 | */ |
| 864 | 943 | function add2list($contact,$list,array $existing=null) |
| 865 | 944 | { |
| 866 | - if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
|
| 945 | + if (!(int)$list || !is_array($contact) && !(int)$contact) |
|
| 946 | + { |
|
| 947 | + return false; |
|
| 948 | + } |
|
| 867 | 949 | |
| 868 | 950 | if (!is_array($existing)) |
| 869 | 951 | { |
@@ -905,7 +987,10 @@ discard block |
||
| 905 | 987 | */ |
| 906 | 988 | function remove_from_list($contact,$list=null) |
| 907 | 989 | { |
| 908 | - if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
|
| 990 | + if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) |
|
| 991 | + { |
|
| 992 | + return false; |
|
| 993 | + } |
|
| 909 | 994 | |
| 910 | 995 | $where = array( |
| 911 | 996 | 'contact_id' => $contact, |
@@ -947,7 +1032,10 @@ discard block |
||
| 947 | 1032 | */ |
| 948 | 1033 | function delete_list($list) |
| 949 | 1034 | { |
| 950 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
| 1035 | + if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) |
|
| 1036 | + { |
|
| 1037 | + return false; |
|
| 1038 | + } |
|
| 951 | 1039 | |
| 952 | 1040 | $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
| 953 | 1041 | |
@@ -962,7 +1050,10 @@ discard block |
||
| 962 | 1050 | */ |
| 963 | 1051 | function lists_ctag($owner=null) |
| 964 | 1052 | { |
| 965 | - if (is_null($owner)) $owner = array_keys($this->grants); |
|
| 1053 | + if (is_null($owner)) |
|
| 1054 | + { |
|
| 1055 | + $owner = array_keys($this->grants); |
|
| 1056 | + } |
|
| 966 | 1057 | |
| 967 | 1058 | if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
| 968 | 1059 | __LINE__,__FILE__)->fetchColumn())) |
@@ -982,9 +1073,12 @@ discard block |
||
| 982 | 1073 | */ |
| 983 | 1074 | function read($keys,$extra_cols='',$join='') |
| 984 | 1075 | { |
| 985 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
| 1076 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
| 1077 | + { |
|
| 986 | 1078 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
| 987 | - } else { |
|
| 1079 | + } |
|
| 1080 | + else |
|
| 1081 | + { |
|
| 988 | 1082 | $minimum_uid_length = 8; |
| 989 | 1083 | } |
| 990 | 1084 | |
@@ -1004,7 +1098,8 @@ discard block |
||
| 1004 | 1098 | |
| 1005 | 1099 | // enforce a minium uid strength |
| 1006 | 1100 | if (is_array($contact) && (!isset($contact['uid']) |
| 1007 | - || strlen($contact['uid']) < $minimum_uid_length)) { |
|
| 1101 | + || strlen($contact['uid']) < $minimum_uid_length)) |
|
| 1102 | + { |
|
| 1008 | 1103 | parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
| 1009 | 1104 | } |
| 1010 | 1105 | return $contact; |
@@ -1021,19 +1116,28 @@ discard block |
||
| 1021 | 1116 | { |
| 1022 | 1117 | unset($extra_where); // not used, but required by function signature |
| 1023 | 1118 | |
| 1024 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
| 1119 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
| 1120 | + { |
|
| 1025 | 1121 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
| 1026 | - } else { |
|
| 1122 | + } |
|
| 1123 | + else |
|
| 1124 | + { |
|
| 1027 | 1125 | $minimum_uid_length = 8; |
| 1028 | 1126 | } |
| 1029 | 1127 | |
| 1030 | - if (is_array($keys) && count($keys)) $this->data_merge($keys); |
|
| 1128 | + if (is_array($keys) && count($keys)) |
|
| 1129 | + { |
|
| 1130 | + $this->data_merge($keys); |
|
| 1131 | + } |
|
| 1031 | 1132 | |
| 1032 | 1133 | $new_entry = !$this->data['id']; |
| 1033 | 1134 | |
| 1034 | - if (isset($this->data['etag'])) // do we have an etag in the data to write |
|
| 1135 | + if (isset($this->data['etag'])) |
|
| 1136 | + { |
|
| 1137 | + // do we have an etag in the data to write |
|
| 1035 | 1138 | { |
| 1036 | 1139 | $etag = $this->data['etag']; |
| 1140 | + } |
|
| 1037 | 1141 | unset($this->data['etag']); |
| 1038 | 1142 | if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
| 1039 | 1143 | { |
@@ -1105,7 +1209,10 @@ discard block |
||
| 1105 | 1209 | */ |
| 1106 | 1210 | function read_list($list) |
| 1107 | 1211 | { |
| 1108 | - if (!$list) return false; |
|
| 1212 | + if (!$list) |
|
| 1213 | + { |
|
| 1214 | + return false; |
|
| 1215 | + } |
|
| 1109 | 1216 | |
| 1110 | 1217 | return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
| 1111 | 1218 | } |