@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * If no account_id is set in data the account is added and the new id is set in $data. |
191 | 191 | * |
192 | 192 | * @param array $data array with account-data |
193 | - * @return int|boolean the account_id or false on error |
|
193 | + * @return false|string the account_id or false on error |
|
194 | 194 | */ |
195 | 195 | function save(&$data) |
196 | 196 | { |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | * |
996 | 996 | * @param int $_account_id |
997 | 997 | * @param string $ip |
998 | - * @return int lastlogin time |
|
998 | + * @return boolean lastlogin time |
|
999 | 999 | */ |
1000 | 1000 | function update_lastlogin($_account_id, $ip) |
1001 | 1001 | { |
@@ -1097,7 +1097,6 @@ discard block |
||
1097 | 1097 | * @param int $gid gidnumber of group to set |
1098 | 1098 | * @param array $objectclass =null should we set the member and uniqueMember attributes (groupOf(Unique)Names|univentionGroup) (default detect it) |
1099 | 1099 | * @param string $use_cn =null if set $cn is used instead $gid and the attributes are returned, not written to ldap |
1100 | - * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it) |
|
1101 | 1100 | * @return boolean/array false on failure, array or true otherwise |
1102 | 1101 | */ |
1103 | 1102 | function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
@@ -962,7 +962,7 @@ |
||
962 | 962 | 'account_fullname' => 'cn', |
963 | 963 | ); |
964 | 964 | if (!isset($to_ldap[$which]) || $account_type === 'g') { |
965 | - return False; |
|
965 | + return False; |
|
966 | 966 | } |
967 | 967 | |
968 | 968 | $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber')); |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | */ |
90 | 90 | var $requiredObjectClasses = array( |
91 | 91 | 'user' => array( |
92 | - 'top','person','organizationalperson','inetorgperson','posixaccount','shadowaccount' |
|
92 | + 'top', 'person', 'organizationalperson', 'inetorgperson', 'posixaccount', 'shadowaccount' |
|
93 | 93 | ), |
94 | 94 | 'user-if-supported' => array( // these classes get added, if server supports them |
95 | 95 | 'mozillaabpersonalpha', 'mozillaorgperson', 'evolutionperson', |
96 | 96 | 'univentionperson', 'univentionmail', array('univentionobject', 'univentionObjectType' => 'users/user'), |
97 | 97 | ), |
98 | 98 | 'group' => array( |
99 | - 'top','posixgroup','groupofnames' |
|
99 | + 'top', 'posixgroup', 'groupofnames' |
|
100 | 100 | ), |
101 | 101 | 'group-if-supported' => array( // these classes get added, if servers supports them |
102 | 102 | 'univentiongroup', array('univentionobject', 'univentionObjectType' => 'groups/group'), |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | */ |
116 | 116 | var $group_mail_classes = array( |
117 | 117 | 'dbmailforwardingaddress' => 'mailforwardingaddress', |
118 | - 'dbmailuser' => array('mailforwardingaddress','uid'), |
|
119 | - 'qmailuser' => array('mailforwardingaddress','uid'), |
|
118 | + 'dbmailuser' => array('mailforwardingaddress', 'uid'), |
|
119 | + 'qmailuser' => array('mailforwardingaddress', 'uid'), |
|
120 | 120 | 'mailaccount' => 'mailalias', |
121 | 121 | 'univentiongroup' => array(false, false, true), |
122 | 122 | ); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $this->use_session_cache = true; |
159 | 159 | |
160 | 160 | $this->ldap = Api\Ldap::factory(false, $this->frontend->config['ldap_host'], |
161 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
161 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
162 | 162 | $this->ds = $this->ldap->ds; |
163 | 163 | |
164 | 164 | $this->user_context = $this->frontend->config['ldap_context']; |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | { |
197 | 197 | $is_group = $data['account_id'] < 0 || $data['account_type'] === 'g'; |
198 | 198 | |
199 | - $data_utf8 = Api\Translation::convert($data,Api\Translation::charset(),'utf-8'); |
|
199 | + $data_utf8 = Api\Translation::convert($data, Api\Translation::charset(), 'utf-8'); |
|
200 | 200 | $members = $data['account_members']; |
201 | 201 | |
202 | 202 | if (!is_object($this->ldapServerInfo)) |
@@ -208,8 +208,7 @@ discard block |
||
208 | 208 | if ($data_utf8['account_id'] && $data_utf8['account_lid']) |
209 | 209 | { |
210 | 210 | // read the entry first, to check if the dn (account_lid) has changed |
211 | - $sri = $is_group ? ldap_search($this->ds,$this->group_context,'gidnumber='.abs($data['account_id'])) : |
|
212 | - ldap_search($this->ds,$this->user_context,'uidnumber='.$data['account_id']); |
|
211 | + $sri = $is_group ? ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($data['account_id'])) : ldap_search($this->ds, $this->user_context, 'uidnumber='.$data['account_id']); |
|
213 | 212 | $old = ldap_get_entries($this->ds, $sri); |
214 | 213 | |
215 | 214 | if (!$old['count']) |
@@ -221,9 +220,9 @@ discard block |
||
221 | 220 | $old = Api\Ldap::result2array($old[0]); |
222 | 221 | $old['objectclass'] = array_map('strtolower', $old['objectclass']); |
223 | 222 | $key = false; |
224 | - if ($is_group && ($key = array_search('namedobject',$old['objectclass'])) !== false || |
|
225 | - $is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'],0,3) != 'cn=') || |
|
226 | - !$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'],0,4) != 'uid=')) |
|
223 | + if ($is_group && ($key = array_search('namedobject', $old['objectclass'])) !== false || |
|
224 | + $is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 3) != 'cn=') || |
|
225 | + !$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 4) != 'uid=')) |
|
227 | 226 | { |
228 | 227 | // query the memberships to set them again later |
229 | 228 | if (!$is_group) |
@@ -252,7 +251,7 @@ discard block |
||
252 | 251 | } |
253 | 252 | } |
254 | 253 | // check if we need to write the objectclass: new entry or required object classes are missing |
255 | - if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'],$old['objectclass'])) |
|
254 | + if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'], $old['objectclass'])) |
|
256 | 255 | { |
257 | 256 | // additional objectclasse might be already set in $to_write or $old |
258 | 257 | if (!is_array($to_write['objectclass'])) |
@@ -261,7 +260,7 @@ discard block |
||
261 | 260 | } |
262 | 261 | if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
263 | 262 | { // as setting them later might loose eg. password, if we are not allowed to read them |
264 | - foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
|
263 | + foreach ($this->requiredObjectClasses[$is_group ? 'group-if-supported' : 'user-if-supported'] as $additional) |
|
265 | 264 | { |
266 | 265 | $add = array(); |
267 | 266 | if (is_array($additional)) |
@@ -283,8 +282,7 @@ discard block |
||
283 | 282 | { |
284 | 283 | if (!$data['account_lid']) return false; |
285 | 284 | |
286 | - $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
|
287 | - 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
285 | + $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
288 | 286 | } |
289 | 287 | // now we merge the user or group data |
290 | 288 | if ($is_group) |
@@ -293,23 +291,23 @@ discard block |
||
293 | 291 | $data['account_type'] = 'g'; |
294 | 292 | |
295 | 293 | $objectclass = $old ? $old['objectclass'] : $to_write['objectclass']; |
296 | - if ($members || !$old && array_intersect(array('groupofnames','groupofuniquenames','univentiongroup'), $objectclass)) |
|
294 | + if ($members || !$old && array_intersect(array('groupofnames', 'groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
297 | 295 | { |
298 | 296 | $to_write = array_merge($to_write, $this->set_members($members, $data['account_id'], $objectclass, $dn)); |
299 | 297 | } |
300 | 298 | // check if we should set a mail address and forwards for each member |
301 | - foreach($this->group_mail_classes as $objectclass => $forward) |
|
299 | + foreach ($this->group_mail_classes as $objectclass => $forward) |
|
302 | 300 | { |
303 | 301 | $extra_attr = false; |
304 | 302 | $keep_objectclass = false; |
305 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
303 | + if (is_array($forward)) list($forward, $extra_attr, $keep_objectclass) = $forward; |
|
306 | 304 | |
307 | 305 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
308 | - ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
306 | + ($old && in_array($objectclass, $old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
309 | 307 | { |
310 | 308 | if ($data_utf8['account_email']) // setting an email |
311 | 309 | { |
312 | - if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
|
310 | + if (!in_array($objectclass, $old ? $old['objectclass'] : $to_write['objectclass'])) |
|
313 | 311 | { |
314 | 312 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
315 | 313 | $to_write['objectclass'][] = $objectclass; |
@@ -323,19 +321,19 @@ discard block |
||
323 | 321 | $to_write[$forward] = array(); |
324 | 322 | foreach (array_keys($members) as $member) |
325 | 323 | { |
326 | - if (($email = $this->id2name($member,'account_email'))) |
|
324 | + if (($email = $this->id2name($member, 'account_email'))) |
|
327 | 325 | { |
328 | 326 | $to_write[$forward][] = $email; |
329 | 327 | } |
330 | 328 | } |
331 | 329 | } |
332 | 330 | } |
333 | - elseif($old) // remove the mail and forwards only for existing entries |
|
331 | + elseif ($old) // remove the mail and forwards only for existing entries |
|
334 | 332 | { |
335 | 333 | $to_write[static::MAIL_ATTR] = array(); |
336 | 334 | if ($forward) $to_write[$forward] = array(); |
337 | 335 | if ($extra_attr) $to_write[$extra_attr] = array(); |
338 | - if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
|
336 | + if (!$keep_objectclass && ($key = array_search($objectclass, $old['objectclass']))) |
|
339 | 337 | { |
340 | 338 | $to_write['objectclass'] = $old['objectclass']; |
341 | 339 | unset($to_write['objectclass'][$key]); |
@@ -349,7 +347,7 @@ discard block |
||
349 | 347 | } |
350 | 348 | else |
351 | 349 | { |
352 | - $to_write = $this->_merge_user($to_write,$data_utf8,!$old); |
|
350 | + $to_write = $this->_merge_user($to_write, $data_utf8, !$old); |
|
353 | 351 | // make sure multiple email-addresses in the mail attribute "survive" |
354 | 352 | if (isset($to_write[static::MAIL_ATTR]) && count($old[static::MAIL_ATTR]) > 1) |
355 | 353 | { |
@@ -368,21 +366,21 @@ discard block |
||
368 | 366 | } |
369 | 367 | |
370 | 368 | // remove memberuid when adding a group |
371 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
369 | + if (!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
372 | 370 | unset($to_write['memberuid']); |
373 | 371 | } |
374 | 372 | // modifying or adding the entry |
375 | - if ($old && !@ldap_modify($this->ds,$dn,$to_write) || |
|
376 | - !$old && !@ldap_add($this->ds,$dn,$to_write)) |
|
373 | + if ($old && !@ldap_modify($this->ds, $dn, $to_write) || |
|
374 | + !$old && !@ldap_add($this->ds, $dn, $to_write)) |
|
377 | 375 | { |
378 | 376 | $err = true; |
379 | - if ($is_group && ($key = array_search('groupofnames',$to_write['objectclass'])) !== false) |
|
377 | + if ($is_group && ($key = array_search('groupofnames', $to_write['objectclass'])) !== false) |
|
380 | 378 | { |
381 | 379 | // try again with removed groupOfNames stuff, as I cant detect if posixGroup is a structural object |
382 | 380 | unset($to_write['objectclass'][$key]); |
383 | 381 | $to_write['objectclass'] = array_values($to_write['objectclass']); |
384 | 382 | unset($to_write['member']); |
385 | - $err = $old ? !ldap_modify($this->ds,$dn,$to_write) : !ldap_add($this->ds,$dn,$to_write); |
|
383 | + $err = $old ? !ldap_modify($this->ds, $dn, $to_write) : !ldap_add($this->ds, $dn, $to_write); |
|
386 | 384 | } |
387 | 385 | if ($err) |
388 | 386 | { |
@@ -392,7 +390,7 @@ discard block |
||
392 | 390 | } |
393 | 391 | if ($memberships) |
394 | 392 | { |
395 | - $this->set_memberships($memberships,$data['account_id']); |
|
393 | + $this->set_memberships($memberships, $data['account_id']); |
|
396 | 394 | } |
397 | 395 | return $data['account_id']; |
398 | 396 | } |
@@ -409,14 +407,14 @@ discard block |
||
409 | 407 | |
410 | 408 | if ($account_id < 0) |
411 | 409 | { |
412 | - $sri = ldap_search($this->ds, $this->group_context, 'gidnumber=' . abs($account_id)); |
|
410 | + $sri = ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($account_id)); |
|
413 | 411 | } |
414 | 412 | else |
415 | 413 | { |
416 | 414 | // remove the user's memberships |
417 | - $this->set_memberships(array(),$account_id); |
|
415 | + $this->set_memberships(array(), $account_id); |
|
418 | 416 | |
419 | - $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
|
417 | + $sri = ldap_search($this->ds, $this->user_context, 'uidnumber='.$account_id); |
|
420 | 418 | } |
421 | 419 | if (!$sri) return false; |
422 | 420 | |
@@ -440,7 +438,7 @@ discard block |
||
440 | 438 | { |
441 | 439 | $this->ldapServerInfo = $this->ldap->getLDAPServerInfo($this->frontend->config['ldap_host']); |
442 | 440 | } |
443 | - foreach(array_keys($this->group_mail_classes) as $objectclass) |
|
441 | + foreach (array_keys($this->group_mail_classes) as $objectclass) |
|
444 | 442 | { |
445 | 443 | if ($this->ldapServerInfo->supportsObjectClass($objectclass)) |
446 | 444 | { |
@@ -448,15 +446,15 @@ discard block |
||
448 | 446 | break; |
449 | 447 | } |
450 | 448 | } |
451 | - $sri = ldap_search($this->ds, $this->group_context,'(&(objectClass=posixGroup)(gidnumber=' . abs($account_id).'))', |
|
449 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(gidnumber='.abs($account_id).'))', |
|
452 | 450 | array('dn', 'gidnumber', 'cn', 'objectclass', static::MAIL_ATTR, 'memberuid', 'description')); |
453 | 451 | |
454 | 452 | $ldap_data = ldap_get_entries($this->ds, $sri); |
455 | 453 | if (!$ldap_data['count']) |
456 | 454 | { |
457 | - return false; // group not found |
|
455 | + return false; // group not found |
|
458 | 456 | } |
459 | - $data = Api\Translation::convert($ldap_data[0],'utf-8'); |
|
457 | + $data = Api\Translation::convert($ldap_data[0], 'utf-8'); |
|
460 | 458 | unset($data['objectclass']['count']); |
461 | 459 | |
462 | 460 | $group += array( |
@@ -477,7 +475,7 @@ discard block |
||
477 | 475 | { |
478 | 476 | unset($data['memberuid']['count']); |
479 | 477 | |
480 | - foreach($data['memberuid'] as $lid) |
|
478 | + foreach ($data['memberuid'] as $lid) |
|
481 | 479 | { |
482 | 480 | if (($id = $this->name2id($lid, 'account_lid', 'u'))) |
483 | 481 | { |
@@ -498,16 +496,16 @@ discard block |
||
498 | 496 | */ |
499 | 497 | protected function _read_user($account_id) |
500 | 498 | { |
501 | - $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber=' . (int)$account_id.'))', |
|
502 | - array('dn','uidnumber','uid','gidnumber','givenname','sn','cn',static::MAIL_ATTR,'userpassword','telephonenumber', |
|
503 | - 'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp')); |
|
499 | + $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber='.(int)$account_id.'))', |
|
500 | + array('dn', 'uidnumber', 'uid', 'gidnumber', 'givenname', 'sn', 'cn', static::MAIL_ATTR, 'userpassword', 'telephonenumber', |
|
501 | + 'shadowexpire', 'shadowlastchange', 'homedirectory', 'loginshell', 'createtimestamp', 'modifytimestamp')); |
|
504 | 502 | |
505 | 503 | $ldap_data = ldap_get_entries($this->ds, $sri); |
506 | 504 | if (!$ldap_data['count']) |
507 | 505 | { |
508 | - return false; // user not found |
|
506 | + return false; // user not found |
|
509 | 507 | } |
510 | - $data = Api\Translation::convert($ldap_data[0],'utf-8'); |
|
508 | + $data = Api\Translation::convert($ldap_data[0], 'utf-8'); |
|
511 | 509 | |
512 | 510 | $utc_diff = date('Z'); |
513 | 511 | $user = array( |
@@ -527,13 +525,13 @@ discard block |
||
527 | 525 | // - if it's set to 0, the account is disabled |
528 | 526 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
529 | 527 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
530 | - 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0]*24*3600+$utc_diff < time() ? false : 'A', |
|
531 | - 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
532 | - 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0]*24*3600+($data['shadowlastchange'][0]!=0?$utc_diff:0) : null, |
|
528 | + 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0] * 24 * 3600 + $utc_diff < time() ? false : 'A', |
|
529 | + 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
530 | + 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0] * 24 * 3600 + ($data['shadowlastchange'][0] != 0 ? $utc_diff : 0) : null, |
|
533 | 531 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
534 | 532 | // 'account_lastlogin' => $data['phpgwaccountlastlogin'][0], |
535 | 533 | // 'account_lastloginfrom' => $data['phpgwaccountlastloginfrom'][0], |
536 | - 'person_id' => $data['uid'][0], // id of associated contact |
|
534 | + 'person_id' => $data['uid'][0], // id of associated contact |
|
537 | 535 | 'account_created' => isset($data['createtimestamp'][0]) ? self::accounts_ldap2ts($data['createtimestamp'][0]) : null, |
538 | 536 | 'account_modified' => isset($data['modifytimestamp'][0]) ? self::accounts_ldap2ts($data['modifytimestamp'][0]) : null, |
539 | 537 | ); |
@@ -554,7 +552,7 @@ discard block |
||
554 | 552 | * @param array $data array with account-data in utf-8 |
555 | 553 | * @return array merged data |
556 | 554 | */ |
557 | - protected function _merge_group($to_write,$data,$old=null) |
|
555 | + protected function _merge_group($to_write, $data, $old = null) |
|
558 | 556 | { |
559 | 557 | $to_write['gidnumber'] = abs($data['account_id']); |
560 | 558 | $to_write['cn'] = $data['account_lid']; |
@@ -574,7 +572,7 @@ discard block |
||
574 | 572 | * @param boolean $new_entry |
575 | 573 | * @return array merged data |
576 | 574 | */ |
577 | - protected function _merge_user($to_write,$data,$new_entry) |
|
575 | + protected function _merge_user($to_write, $data, $new_entry) |
|
578 | 576 | { |
579 | 577 | $to_write['uidnumber'] = $data['account_id']; |
580 | 578 | $to_write['uid'] = $data['account_lid']; |
@@ -583,12 +581,12 @@ discard block |
||
583 | 581 | { |
584 | 582 | $to_write['givenname'] = $data['account_firstname'] ? $data['account_firstname'] : array(); |
585 | 583 | } |
586 | - $to_write['sn'] = $data['account_lastname']; |
|
584 | + $to_write['sn'] = $data['account_lastname']; |
|
587 | 585 | if (!$new_entry || $data['account_email']) |
588 | 586 | { |
589 | - $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
587 | + $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
590 | 588 | } |
591 | - $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
589 | + $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
592 | 590 | |
593 | 591 | $utc_diff = date('Z'); |
594 | 592 | if (isset($data['account_passwd']) && $data['account_passwd']) |
@@ -597,47 +595,46 @@ discard block |
||
597 | 595 | { |
598 | 596 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
599 | 597 | } |
600 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
598 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd'])) // if it's not already entcrypted, do so now |
|
601 | 599 | { |
602 | 600 | $data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']); |
603 | 601 | } |
604 | 602 | $to_write['userpassword'] = $data['account_passwd']; |
605 | - $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
|
603 | + $to_write['shadowlastchange'] = round((time() - $utc_diff) / (24 * 3600)); |
|
606 | 604 | } |
607 | 605 | // both status and expires are encoded in the single shadowexpire value in LDAP |
608 | 606 | // - if it's unset an account is enabled AND does never expire |
609 | 607 | // - if it's set to 0, the account is disabled |
610 | 608 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
611 | 609 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
612 | - $shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600); |
|
610 | + $shadowexpire = ($data['account_expires'] - $utc_diff) / (24 * 3600); |
|
613 | 611 | |
614 | 612 | $to_write['shadowexpire'] = !$data['account_status'] ? |
615 | - ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : |
|
616 | - ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
613 | + ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
617 | 614 | |
618 | 615 | if ($new_entry && is_array($to_write['shadowexpire']) && !count($to_write['shadowexpire'])) |
619 | 616 | { |
620 | - unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
617 | + unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
621 | 618 | } |
622 | 619 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
623 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
624 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
620 | + if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change'] - $utc_diff) / (24 * 3600)); |
|
621 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change'] == 0) $to_write['shadowlastchange'] = 0; |
|
625 | 622 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
626 | 623 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
627 | 624 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
628 | 625 | |
629 | 626 | if ($this->frontend->config['ldap_extra_attributes']) |
630 | 627 | { |
631 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
628 | + if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
632 | 629 | if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
633 | 630 | } |
634 | 631 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
635 | 632 | { |
636 | - $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
633 | + $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
637 | 634 | } |
638 | 635 | if ($new_entry && empty($to_write['loginshell'])) |
639 | 636 | { |
640 | - unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
637 | + unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
641 | 638 | } |
642 | 639 | return $to_write; |
643 | 640 | } |
@@ -665,7 +662,7 @@ discard block |
||
665 | 662 | function search($param) |
666 | 663 | { |
667 | 664 | //error_log(__METHOD__."(".array2string($param).")"); |
668 | - $account_search =& Api\Accounts::$cache['account_search']; |
|
665 | + $account_search = & Api\Accounts::$cache['account_search']; |
|
669 | 666 | |
670 | 667 | // check if the query is cached |
671 | 668 | $serial = serialize($param); |
@@ -691,12 +688,12 @@ discard block |
||
691 | 688 | $query = Api\Ldap::quote(strtolower($param['query'])); |
692 | 689 | |
693 | 690 | $accounts = array(); |
694 | - if($param['type'] != 'groups') |
|
691 | + if ($param['type'] != 'groups') |
|
695 | 692 | { |
696 | 693 | $filter = "(&(objectclass=posixaccount)"; |
697 | 694 | if (!empty($query) && $query != '*') |
698 | 695 | { |
699 | - switch($param['query_type']) |
|
696 | + switch ($param['query_type']) |
|
700 | 697 | { |
701 | 698 | case 'all': |
702 | 699 | default: |
@@ -723,7 +720,7 @@ discard block |
||
723 | 720 | } |
724 | 721 | } |
725 | 722 | // add account_filter to filter (user has to be '*', as we otherwise only search uid's) |
726 | - $filter .= str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$this->account_filter); |
|
723 | + $filter .= str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $this->account_filter); |
|
727 | 724 | $filter .= ')'; |
728 | 725 | |
729 | 726 | if ($param['type'] != 'both') |
@@ -742,9 +739,9 @@ discard block |
||
742 | 739 | 'account_fullname' => 'cn', |
743 | 740 | 'account_primary_group' => 'gidnumber', |
744 | 741 | ); |
745 | - $orders = explode(',',$param['order']); |
|
742 | + $orders = explode(',', $param['order']); |
|
746 | 743 | $order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid'; |
747 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order)); |
|
744 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', $order)); |
|
748 | 745 | $fullSet = array(); |
749 | 746 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
750 | 747 | { |
@@ -754,7 +751,7 @@ discard block |
||
754 | 751 | if (is_numeric($param['type'])) // return only group-members |
755 | 752 | { |
756 | 753 | $relevantAccounts = array(); |
757 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
|
754 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=".abs($param['type'])."))", array('memberuid')); |
|
758 | 755 | $group = ldap_get_entries($this->ds, $sri); |
759 | 756 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
760 | 757 | } |
@@ -763,26 +760,26 @@ discard block |
||
763 | 760 | $sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort'; |
764 | 761 | $sortFn($fullSet); |
765 | 762 | $relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet); |
766 | - $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')'; |
|
767 | - $filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter); |
|
763 | + $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=', $relevantAccounts).'))'.$this->account_filter.')'; |
|
764 | + $filter = str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $filter); |
|
768 | 765 | } |
769 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn',static::MAIL_ATTR,'shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber')); |
|
766 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', 'uidNumber', 'givenname', 'sn', static::MAIL_ATTR, 'shadowExpire', 'createtimestamp', 'modifytimestamp', 'objectclass', 'gidNumber')); |
|
770 | 767 | |
771 | 768 | $utc_diff = date('Z'); |
772 | - foreach(ldap_get_entries($this->ds, $sri) as $allVals) |
|
769 | + foreach (ldap_get_entries($this->ds, $sri) as $allVals) |
|
773 | 770 | { |
774 | - settype($allVals,'array'); |
|
771 | + settype($allVals, 'array'); |
|
775 | 772 | $test = @$allVals['uid'][0]; |
776 | 773 | if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) |
777 | 774 | { |
778 | 775 | $account = Array( |
779 | 776 | 'account_id' => $allVals['uidnumber'][0], |
780 | - 'account_lid' => Api\Translation::convert($allVals['uid'][0],'utf-8'), |
|
777 | + 'account_lid' => Api\Translation::convert($allVals['uid'][0], 'utf-8'), |
|
781 | 778 | 'account_type' => 'u', |
782 | - 'account_firstname' => Api\Translation::convert($allVals['givenname'][0],'utf-8'), |
|
783 | - 'account_lastname' => Api\Translation::convert($allVals['sn'][0],'utf-8'), |
|
784 | - 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A', |
|
785 | - 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
779 | + 'account_firstname' => Api\Translation::convert($allVals['givenname'][0], 'utf-8'), |
|
780 | + 'account_lastname' => Api\Translation::convert($allVals['sn'][0], 'utf-8'), |
|
781 | + 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0] * 24 * 3600 - $utc_diff < time() ? false : 'A', |
|
782 | + 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
786 | 783 | 'account_email' => $allVals[static::MAIL_ATTR][0], |
787 | 784 | 'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null, |
788 | 785 | 'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null, |
@@ -808,13 +805,13 @@ discard block |
||
808 | 805 | } |
809 | 806 | if ($param['type'] == 'groups' || $param['type'] == 'both') |
810 | 807 | { |
811 | - if(empty($query) || $query == '*') |
|
808 | + if (empty($query) || $query == '*') |
|
812 | 809 | { |
813 | 810 | $filter = '(objectclass=posixgroup)'; |
814 | 811 | } |
815 | 812 | else |
816 | 813 | { |
817 | - switch($param['query_type']) |
|
814 | + switch ($param['query_type']) |
|
818 | 815 | { |
819 | 816 | case 'all': |
820 | 817 | default: |
@@ -828,21 +825,21 @@ discard block |
||
828 | 825 | } |
829 | 826 | $filter = "(&(objectclass=posixgroup)(cn=$query))"; |
830 | 827 | } |
831 | - $sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber')); |
|
832 | - foreach((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
828 | + $sri = ldap_search($this->ds, $this->group_context, $filter, array('cn', 'gidNumber')); |
|
829 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
833 | 830 | { |
834 | - settype($allVals,'array'); |
|
831 | + settype($allVals, 'array'); |
|
835 | 832 | $test = $allVals['cn'][0]; |
836 | 833 | if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0]) |
837 | 834 | { |
838 | 835 | $accounts[(string)-$allVals['gidnumber'][0]] = Array( |
839 | 836 | 'account_id' => -$allVals['gidnumber'][0], |
840 | - 'account_lid' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
837 | + 'account_lid' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
841 | 838 | 'account_type' => 'g', |
842 | - 'account_firstname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
839 | + 'account_firstname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
843 | 840 | 'account_lastname' => lang('Group'), |
844 | 841 | 'account_status' => 'A', |
845 | - 'account_fullname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
842 | + 'account_fullname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
846 | 843 | ); |
847 | 844 | if (isset($totalcount)) ++$totalcount; |
848 | 845 | } |
@@ -850,9 +847,9 @@ discard block |
||
850 | 847 | } |
851 | 848 | // sort the array |
852 | 849 | $this->_callback_sort = strtoupper($param['sort']); |
853 | - $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
|
850 | + $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']); |
|
854 | 851 | $sortedAccounts = $accounts; |
855 | - uasort($sortedAccounts,array($this,'_sort_callback')); |
|
852 | + uasort($sortedAccounts, array($this, '_sort_callback')); |
|
856 | 853 | $this->total = isset($totalcount) ? $totalcount : count($accounts); |
857 | 854 | |
858 | 855 | // if totalcount is set, $sortedAccounts is NOT the full set, but already a limited set! |
@@ -864,7 +861,7 @@ discard block |
||
864 | 861 | } |
865 | 862 | // return only the wanted accounts |
866 | 863 | reset($sortedAccounts); |
867 | - if(is_numeric($start) && is_numeric($offset)) |
|
864 | + if (is_numeric($start) && is_numeric($offset)) |
|
868 | 865 | { |
869 | 866 | $account_search[$serial]['total'] = $this->total; |
870 | 867 | return $account_search[$serial]['data'] = isset($totalcount) ? $sortedAccounts : array_slice($sortedAccounts, $start, $offset); |
@@ -892,19 +889,19 @@ discard block |
||
892 | 889 | * @param array $b |
893 | 890 | * @return int |
894 | 891 | */ |
895 | - function _sort_callback($a,$b) |
|
892 | + function _sort_callback($a, $b) |
|
896 | 893 | { |
897 | - foreach($this->_callback_order as $col ) |
|
894 | + foreach ($this->_callback_order as $col) |
|
898 | 895 | { |
899 | - if($this->_callback_sort != 'DESC') |
|
896 | + if ($this->_callback_sort != 'DESC') |
|
900 | 897 | { |
901 | - $cmp = strcasecmp( $a[$col], $b[$col] ); |
|
898 | + $cmp = strcasecmp($a[$col], $b[$col]); |
|
902 | 899 | } |
903 | 900 | else |
904 | 901 | { |
905 | - $cmp = strcasecmp( $b[$col], $a[$col] ); |
|
902 | + $cmp = strcasecmp($b[$col], $a[$col]); |
|
906 | 903 | } |
907 | - if ( $cmp != 0 ) |
|
904 | + if ($cmp != 0) |
|
908 | 905 | { |
909 | 906 | return $cmp; |
910 | 907 | } |
@@ -923,8 +920,8 @@ discard block |
||
923 | 920 | { |
924 | 921 | if (!empty($date)) |
925 | 922 | { |
926 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
927 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
923 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
924 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
928 | 925 | } |
929 | 926 | return NULL; |
930 | 927 | } |
@@ -941,14 +938,14 @@ discard block |
||
941 | 938 | * @param string $account_type u = user, g = group, default null = try both |
942 | 939 | * @return int|false numeric account_id or false on error ($name not found) |
943 | 940 | */ |
944 | - function name2id($_name,$which='account_lid',$account_type=null) |
|
941 | + function name2id($_name, $which = 'account_lid', $account_type = null) |
|
945 | 942 | { |
946 | - $name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8')); |
|
943 | + $name = Api\Ldap::quote(Api\Translation::convert($_name, Api\Translation::charset(), 'utf-8')); |
|
947 | 944 | |
948 | 945 | if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
949 | 946 | { |
950 | 947 | |
951 | - $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
|
948 | + $sri = ldap_search($this->ds, $this->group_context, '(&(cn='.$name.')(objectclass=posixgroup))', array('gidNumber')); |
|
952 | 949 | $allValues = ldap_get_entries($this->ds, $sri); |
953 | 950 | |
954 | 951 | if (@$allValues[0]['gidnumber'][0]) |
@@ -965,7 +962,7 @@ discard block |
||
965 | 962 | return False; |
966 | 963 | } |
967 | 964 | |
968 | - $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber')); |
|
965 | + $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'='.$name.')(objectclass=posixaccount))', array('uidNumber')); |
|
969 | 966 | |
970 | 967 | $allValues = ldap_get_entries($this->ds, $sri); |
971 | 968 | |
@@ -985,9 +982,9 @@ discard block |
||
985 | 982 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
986 | 983 | * @return string/false converted value or false on error ($account_id not found) |
987 | 984 | */ |
988 | - function id2name($account_id,$which='account_lid') |
|
985 | + function id2name($account_id, $which = 'account_lid') |
|
989 | 986 | { |
990 | - return $this->frontend->id2name($account_id,$which); |
|
987 | + return $this->frontend->id2name($account_id, $which); |
|
991 | 988 | } |
992 | 989 | |
993 | 990 | /** |
@@ -1000,7 +997,7 @@ discard block |
||
1000 | 997 | function update_lastlogin($_account_id, $ip) |
1001 | 998 | { |
1002 | 999 | unset($_account_id, $ip); |
1003 | - return false; // not longer supported |
|
1000 | + return false; // not longer supported |
|
1004 | 1001 | } |
1005 | 1002 | |
1006 | 1003 | /** |
@@ -1011,11 +1008,11 @@ discard block |
||
1011 | 1008 | */ |
1012 | 1009 | function memberships($account_id) |
1013 | 1010 | { |
1014 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1011 | + if (!(int)$account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1015 | 1012 | |
1016 | - $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber')); |
|
1013 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))', array('cn', 'gidnumber')); |
|
1017 | 1014 | $memberships = array(); |
1018 | - foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
1015 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
1019 | 1016 | { |
1020 | 1017 | if ($key === 'count') continue; |
1021 | 1018 | |
@@ -1035,13 +1032,13 @@ discard block |
||
1035 | 1032 | if (!is_numeric($_gid)) |
1036 | 1033 | { |
1037 | 1034 | // try to recover |
1038 | - $_gid = $this->name2id($_gid,'account_lid','g'); |
|
1035 | + $_gid = $this->name2id($_gid, 'account_lid', 'g'); |
|
1039 | 1036 | if (!is_numeric($_gid)) return false; |
1040 | 1037 | } |
1041 | 1038 | |
1042 | - $gid = abs($_gid); // our gid is negative! |
|
1039 | + $gid = abs($_gid); // our gid is negative! |
|
1043 | 1040 | |
1044 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid')); |
|
1041 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=$gid))", array('memberuid')); |
|
1045 | 1042 | $group = ldap_get_entries($this->ds, $sri); |
1046 | 1043 | |
1047 | 1044 | $members = array(); |
@@ -1049,7 +1046,7 @@ discard block |
||
1049 | 1046 | { |
1050 | 1047 | unset($group[0]['memberuid']['count']); |
1051 | 1048 | |
1052 | - foreach($group[0]['memberuid'] as $lid) |
|
1049 | + foreach ($group[0]['memberuid'] as $lid) |
|
1053 | 1050 | { |
1054 | 1051 | if (($id = $this->name2id($lid, 'account_lid', 'u'))) |
1055 | 1052 | { |
@@ -1066,27 +1063,27 @@ discard block |
||
1066 | 1063 | * @param array $groups array with gidnumbers |
1067 | 1064 | * @param int $account_id uidnumber |
1068 | 1065 | */ |
1069 | - function set_memberships($groups,$account_id) |
|
1066 | + function set_memberships($groups, $account_id) |
|
1070 | 1067 | { |
1071 | 1068 | // remove not longer existing memberships |
1072 | 1069 | if (($old_memberships = $this->memberships($account_id))) |
1073 | 1070 | { |
1074 | 1071 | $old_memberships = array_keys($old_memberships); |
1075 | - foreach(array_diff($old_memberships,$groups) as $gid) |
|
1072 | + foreach (array_diff($old_memberships, $groups) as $gid) |
|
1076 | 1073 | { |
1077 | 1074 | if (($members = $this->members($gid))) |
1078 | 1075 | { |
1079 | 1076 | unset($members[$account_id]); |
1080 | - $this->set_members($members,$gid); |
|
1077 | + $this->set_members($members, $gid); |
|
1081 | 1078 | } |
1082 | 1079 | } |
1083 | 1080 | } |
1084 | 1081 | // adding new memberships |
1085 | - foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid) |
|
1082 | + foreach ($old_memberships ? array_diff($groups, $old_memberships) : $groups as $gid) |
|
1086 | 1083 | { |
1087 | 1084 | $members = $this->members($gid); |
1088 | 1085 | $members[$account_id] = $this->id2name($account_id); |
1089 | - $this->set_members($members,$gid); |
|
1086 | + $this->set_members($members, $gid); |
|
1090 | 1087 | } |
1091 | 1088 | } |
1092 | 1089 | |
@@ -1100,15 +1097,15 @@ discard block |
||
1100 | 1097 | * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it) |
1101 | 1098 | * @return boolean/array false on failure, array or true otherwise |
1102 | 1099 | */ |
1103 | - function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
|
1100 | + function set_members($members, $gid, array $objectclass = null, $use_cn = null) |
|
1104 | 1101 | { |
1105 | 1102 | if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
1106 | 1103 | |
1107 | 1104 | // do that group is a groupOf(Unique)Names or univentionGroup? |
1108 | - if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass'); |
|
1105 | + if (is_null($objectclass)) $objectclass = $this->id2name($gid, 'objectclass'); |
|
1109 | 1106 | |
1110 | 1107 | $to_write = array('memberuid' => array()); |
1111 | - foreach((array)$members as $key => $member) |
|
1108 | + foreach ((array)$members as $key => $member) |
|
1112 | 1109 | { |
1113 | 1110 | $member_dn = $this->id2name($member, 'account_dn'); |
1114 | 1111 | if (is_numeric($member)) $member = $this->id2name($member); |
@@ -1120,7 +1117,7 @@ discard block |
||
1120 | 1117 | { |
1121 | 1118 | $to_write['member'][] = $member_dn; |
1122 | 1119 | } |
1123 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass)) |
|
1120 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
1124 | 1121 | { |
1125 | 1122 | $to_write['uniquemember'][] = $member_dn; |
1126 | 1123 | } |
@@ -1131,31 +1128,31 @@ discard block |
||
1131 | 1128 | { |
1132 | 1129 | $to_write['member'][] = 'uid=dummy'.','.$this->user_context; |
1133 | 1130 | } |
1134 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
1131 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
1135 | 1132 | { |
1136 | 1133 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
1137 | 1134 | } |
1138 | 1135 | if ($use_cn) return $to_write; |
1139 | 1136 | |
1140 | 1137 | // set the member email addresses as forwards |
1141 | - if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
|
1138 | + if ($this->id2name($gid, 'account_email') && ($objectclass = $this->id2name($gid, 'mailAllowed'))) |
|
1142 | 1139 | { |
1143 | 1140 | $forward = $this->group_mail_classes[$objectclass]; |
1144 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
1141 | + if (is_array($forward)) list($forward, $extra_attr) = $forward; |
|
1145 | 1142 | if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
1146 | 1143 | |
1147 | 1144 | if ($forward) |
1148 | 1145 | { |
1149 | 1146 | $to_write[$forward] = array(); |
1150 | - foreach($members as $key => $member) |
|
1147 | + foreach ($members as $key => $member) |
|
1151 | 1148 | { |
1152 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
1149 | + if (($email = $this->id2name($member, 'account_email'))) $to_write[$forward][] = $email; |
|
1153 | 1150 | } |
1154 | 1151 | } |
1155 | 1152 | } |
1156 | - if (!ldap_modify($this->ds,'cn='.Api\Ldap::quote($cn).','.$this->group_context,$to_write)) |
|
1153 | + if (!ldap_modify($this->ds, 'cn='.Api\Ldap::quote($cn).','.$this->group_context, $to_write)) |
|
1157 | 1154 | { |
1158 | - echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write,true)."))\n"; |
|
1155 | + echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write, true)."))\n"; |
|
1159 | 1156 | return false; |
1160 | 1157 | } |
1161 | 1158 | return true; |
@@ -1168,7 +1165,7 @@ discard block |
||
1168 | 1165 | * @param string $account_type ='u' (optional, default to 'u') |
1169 | 1166 | * @return int|boolean integer account_id (negative for groups) or false if none is free anymore |
1170 | 1167 | */ |
1171 | - protected function _get_nextid($account_type='u') |
|
1168 | + protected function _get_nextid($account_type = 'u') |
|
1172 | 1169 | { |
1173 | 1170 | $min = $this->frontend->config['account_min_id'] ? $this->frontend->config['account_min_id'] : 0; |
1174 | 1171 | $max = $this->frontend->config['account_max_id'] ? $this->frontend->config['account_max_id'] : 0; |
@@ -1190,15 +1187,15 @@ discard block |
||
1190 | 1187 | /* Loop until we find a free id */ |
1191 | 1188 | do |
1192 | 1189 | { |
1193 | - $account_id = (int) self::next_id($type,$min,$max); |
|
1190 | + $account_id = (int)self::next_id($type, $min, $max); |
|
1194 | 1191 | } |
1195 | - while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
1192 | + while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
1196 | 1193 | $this->frontend->exists(-1 * $sign * $account_id) || |
1197 | 1194 | // if sambaadmin is installed, call it to check there's not yet a relative id (last part of SID) with that number |
1198 | 1195 | // to ease migration to AD or Samba4 |
1199 | 1196 | $GLOBALS['egw_info']['apps']['sambaadmin'] && ExecMethod2('sambaadmin.sosambaadmin.sidExists', $account_id))); |
1200 | 1197 | |
1201 | - if (!$account_id || $max && $account_id > $max) |
|
1198 | + if (!$account_id || $max && $account_id > $max) |
|
1202 | 1199 | { |
1203 | 1200 | return False; |
1204 | 1201 | } |
@@ -1213,14 +1210,14 @@ discard block |
||
1213 | 1210 | * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false |
1214 | 1211 | * @return int|boolean the next id or false if $max given and exceeded |
1215 | 1212 | */ |
1216 | - static function next_id($location,$min=0,$max=0) |
|
1213 | + static function next_id($location, $min = 0, $max = 0) |
|
1217 | 1214 | { |
1218 | 1215 | if (!$location) |
1219 | 1216 | { |
1220 | 1217 | return -1; |
1221 | 1218 | } |
1222 | 1219 | |
1223 | - $id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location]; |
|
1220 | + $id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location]; |
|
1224 | 1221 | |
1225 | 1222 | if ($max && $id >= $max) |
1226 | 1223 | { |
@@ -1228,10 +1225,10 @@ discard block |
||
1228 | 1225 | } |
1229 | 1226 | ++$id; |
1230 | 1227 | |
1231 | - if($id < $min) $id = $min; |
|
1228 | + if ($id < $min) $id = $min; |
|
1232 | 1229 | |
1233 | 1230 | Api\Config::save_value($key, $id, 'phpgwapi', true); |
1234 | - $GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id; |
|
1231 | + $GLOBALS['egw_info']['server'][$key = 'last_id_'.$location] = $id; |
|
1235 | 1232 | |
1236 | 1233 | return (int)$id; |
1237 | 1234 | } |
@@ -1244,18 +1241,18 @@ discard block |
||
1244 | 1241 | * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false |
1245 | 1242 | * @return int|boolean current id in the next_id table for a particular app/class or -1 for no app and false if $max is exceeded. |
1246 | 1243 | */ |
1247 | - static function last_id($location,$min=0,$max=0) |
|
1244 | + static function last_id($location, $min = 0, $max = 0) |
|
1248 | 1245 | { |
1249 | 1246 | if (!$location) |
1250 | 1247 | { |
1251 | 1248 | return -1; |
1252 | 1249 | } |
1253 | 1250 | |
1254 | - $id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location]; |
|
1251 | + $id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location]; |
|
1255 | 1252 | |
1256 | 1253 | if (!$id || $id < $min) |
1257 | 1254 | { |
1258 | - return self::next_id($location,$min,$max); |
|
1255 | + return self::next_id($location, $min, $max); |
|
1259 | 1256 | } |
1260 | 1257 | if ($max && $id > $max) |
1261 | 1258 | { |
@@ -1270,6 +1267,6 @@ discard block |
||
1270 | 1267 | function __wakeup() |
1271 | 1268 | { |
1272 | 1269 | $this->ds = Api\Ldap::factory(true, $this->frontend->config['ldap_host'], |
1273 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
1270 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
1274 | 1271 | } |
1275 | 1272 | } |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | $test = @$allVals['uid'][0]; |
776 | 776 | if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) |
777 | 777 | { |
778 | - $account = Array( |
|
778 | + $account = array( |
|
779 | 779 | 'account_id' => $allVals['uidnumber'][0], |
780 | 780 | 'account_lid' => Api\Translation::convert($allVals['uid'][0],'utf-8'), |
781 | 781 | 'account_type' => 'u', |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | $test = $allVals['cn'][0]; |
836 | 836 | if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0]) |
837 | 837 | { |
838 | - $accounts[(string)-$allVals['gidnumber'][0]] = Array( |
|
838 | + $accounts[(string)-$allVals['gidnumber'][0]] = array( |
|
839 | 839 | 'account_id' => -$allVals['gidnumber'][0], |
840 | 840 | 'account_lid' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
841 | 841 | 'account_type' => 'g', |
@@ -175,7 +175,10 @@ discard block |
||
175 | 175 | */ |
176 | 176 | function read($account_id) |
177 | 177 | { |
178 | - if (!(int)$account_id) return false; |
|
178 | + if (!(int)$account_id) |
|
179 | + { |
|
180 | + return false; |
|
181 | + } |
|
179 | 182 | |
180 | 183 | if ($account_id < 0) |
181 | 184 | { |
@@ -238,17 +241,23 @@ discard block |
||
238 | 241 | $this->delete($data['account_id']); |
239 | 242 | unset($old['dn']); |
240 | 243 | // removing the namedObject object-class, if it's included |
241 | - if ($key !== false) unset($old['objectclass'][$key]); |
|
244 | + if ($key !== false) |
|
245 | + { |
|
246 | + unset($old['objectclass'][$key]); |
|
247 | + } |
|
242 | 248 | $to_write = $old; |
243 | 249 | unset($old); |
244 | 250 | } |
245 | 251 | } |
246 | 252 | } |
247 | - if (!$data['account_id']) // new account |
|
253 | + if (!$data['account_id']) |
|
254 | + { |
|
255 | + // new account |
|
248 | 256 | { |
249 | 257 | if (!($data['account_id'] = $data_utf8['account_id'] = $this->_get_nextid($is_group ? 'g' : 'u'))) |
250 | 258 | { |
251 | 259 | return false; |
260 | + } |
|
252 | 261 | } |
253 | 262 | } |
254 | 263 | // check if we need to write the objectclass: new entry or required object classes are missing |
@@ -259,11 +268,14 @@ discard block |
||
259 | 268 | { |
260 | 269 | $to_write['objectclass'] = $old ? $old['objectclass'] : array(); |
261 | 270 | } |
262 | - if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
|
271 | + if (!$old) |
|
272 | + { |
|
273 | + // for new accounts add additional addressbook object classes, if supported by server |
|
263 | 274 | { // as setting them later might loose eg. password, if we are not allowed to read them |
264 | 275 | foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
265 | 276 | { |
266 | 277 | $add = array(); |
278 | + } |
|
267 | 279 | if (is_array($additional)) |
268 | 280 | { |
269 | 281 | $add = $additional; |
@@ -272,7 +284,10 @@ discard block |
||
272 | 284 | if ($this->ldapServerInfo->supportsObjectClass($additional)) |
273 | 285 | { |
274 | 286 | $to_write['objectclass'][] = $additional; |
275 | - if ($add) $to_write += $add; |
|
287 | + if ($add) |
|
288 | + { |
|
289 | + $to_write += $add; |
|
290 | + } |
|
276 | 291 | } |
277 | 292 | } |
278 | 293 | } |
@@ -281,7 +296,10 @@ discard block |
||
281 | 296 | } |
282 | 297 | if (!($dn = $old['dn'])) |
283 | 298 | { |
284 | - if (!$data['account_lid']) return false; |
|
299 | + if (!$data['account_lid']) |
|
300 | + { |
|
301 | + return false; |
|
302 | + } |
|
285 | 303 | |
286 | 304 | $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
287 | 305 | 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
@@ -302,24 +320,36 @@ discard block |
||
302 | 320 | { |
303 | 321 | $extra_attr = false; |
304 | 322 | $keep_objectclass = false; |
305 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
323 | + if (is_array($forward)) |
|
324 | + { |
|
325 | + list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
326 | + } |
|
306 | 327 | |
307 | 328 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
308 | 329 | ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
309 | 330 | { |
310 | - if ($data_utf8['account_email']) // setting an email |
|
331 | + if ($data_utf8['account_email']) |
|
332 | + { |
|
333 | + // setting an email |
|
311 | 334 | { |
312 | 335 | if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
313 | 336 | { |
314 | 337 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
338 | + } |
|
315 | 339 | $to_write['objectclass'][] = $objectclass; |
316 | 340 | } |
317 | - if ($extra_attr) $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
341 | + if ($extra_attr) |
|
342 | + { |
|
343 | + $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
344 | + } |
|
318 | 345 | $to_write[static::MAIL_ATTR] = $data_utf8['account_email']; |
319 | 346 | |
320 | 347 | if ($forward) |
321 | 348 | { |
322 | - if (!$members) $members = $this->members($data['account_id']); |
|
349 | + if (!$members) |
|
350 | + { |
|
351 | + $members = $this->members($data['account_id']); |
|
352 | + } |
|
323 | 353 | $to_write[$forward] = array(); |
324 | 354 | foreach (array_keys($members) as $member) |
325 | 355 | { |
@@ -330,11 +360,20 @@ discard block |
||
330 | 360 | } |
331 | 361 | } |
332 | 362 | } |
333 | - elseif($old) // remove the mail and forwards only for existing entries |
|
363 | + elseif($old) |
|
364 | + { |
|
365 | + // remove the mail and forwards only for existing entries |
|
334 | 366 | { |
335 | 367 | $to_write[static::MAIL_ATTR] = array(); |
336 | - if ($forward) $to_write[$forward] = array(); |
|
337 | - if ($extra_attr) $to_write[$extra_attr] = array(); |
|
368 | + } |
|
369 | + if ($forward) |
|
370 | + { |
|
371 | + $to_write[$forward] = array(); |
|
372 | + } |
|
373 | + if ($extra_attr) |
|
374 | + { |
|
375 | + $to_write[$extra_attr] = array(); |
|
376 | + } |
|
338 | 377 | if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
339 | 378 | { |
340 | 379 | $to_write['objectclass'] = $old['objectclass']; |
@@ -368,7 +407,8 @@ discard block |
||
368 | 407 | } |
369 | 408 | |
370 | 409 | // remove memberuid when adding a group |
371 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
410 | + if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) |
|
411 | + { |
|
372 | 412 | unset($to_write['memberuid']); |
373 | 413 | } |
374 | 414 | // modifying or adding the entry |
@@ -405,7 +445,10 @@ discard block |
||
405 | 445 | */ |
406 | 446 | function delete($account_id) |
407 | 447 | { |
408 | - if (!(int)$account_id) return false; |
|
448 | + if (!(int)$account_id) |
|
449 | + { |
|
450 | + return false; |
|
451 | + } |
|
409 | 452 | |
410 | 453 | if ($account_id < 0) |
411 | 454 | { |
@@ -418,10 +461,16 @@ discard block |
||
418 | 461 | |
419 | 462 | $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
420 | 463 | } |
421 | - if (!$sri) return false; |
|
464 | + if (!$sri) |
|
465 | + { |
|
466 | + return false; |
|
467 | + } |
|
422 | 468 | |
423 | 469 | $allValues = ldap_get_entries($this->ds, $sri); |
424 | - if (!$allValues['count']) return false; |
|
470 | + if (!$allValues['count']) |
|
471 | + { |
|
472 | + return false; |
|
473 | + } |
|
425 | 474 | |
426 | 475 | return ldap_delete($this->ds, $allValues[0]['dn']); |
427 | 476 | } |
@@ -593,14 +642,20 @@ discard block |
||
593 | 642 | $utc_diff = date('Z'); |
594 | 643 | if (isset($data['account_passwd']) && $data['account_passwd']) |
595 | 644 | { |
596 | - if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) // md5 --> ldap md5 |
|
645 | + if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) |
|
646 | + { |
|
647 | + // md5 --> ldap md5 |
|
597 | 648 | { |
598 | 649 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
599 | 650 | } |
600 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
651 | + } |
|
652 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) |
|
653 | + { |
|
654 | + // if it's not already entcrypted, do so now |
|
601 | 655 | { |
602 | 656 | $data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']); |
603 | 657 | } |
658 | + } |
|
604 | 659 | $to_write['userpassword'] = $data['account_passwd']; |
605 | 660 | $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
606 | 661 | } |
@@ -620,16 +675,28 @@ discard block |
||
620 | 675 | unset($to_write['shadowexpire']); // gives protocoll error otherwise |
621 | 676 | } |
622 | 677 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
623 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
624 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
678 | + if ($data['account_lastpwd_change']) |
|
679 | + { |
|
680 | + $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
681 | + } |
|
682 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) |
|
683 | + { |
|
684 | + $to_write['shadowlastchange'] = 0; |
|
685 | + } |
|
625 | 686 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
626 | 687 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
627 | 688 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
628 | 689 | |
629 | 690 | if ($this->frontend->config['ldap_extra_attributes']) |
630 | 691 | { |
631 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
632 | - if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
692 | + if (isset($data['homedirectory'])) |
|
693 | + { |
|
694 | + $to_write['homedirectory'] = $data['homedirectory']; |
|
695 | + } |
|
696 | + if (isset($data['loginshell'])) |
|
697 | + { |
|
698 | + $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
699 | + } |
|
633 | 700 | } |
634 | 701 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
635 | 702 | { |
@@ -676,8 +743,14 @@ discard block |
||
676 | 743 | } |
677 | 744 | // if it's a limited query, check if the unlimited query is cached |
678 | 745 | $start = $param['start']; |
679 | - if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15; |
|
680 | - if (!($offset = $param['offset'])) $offset = $maxmatchs; |
|
746 | + if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) |
|
747 | + { |
|
748 | + $maxmatchs = 15; |
|
749 | + } |
|
750 | + if (!($offset = $param['offset'])) |
|
751 | + { |
|
752 | + $offset = $maxmatchs; |
|
753 | + } |
|
681 | 754 | unset($param['start']); |
682 | 755 | unset($param['offset']); |
683 | 756 | $unl_serial = serialize($param); |
@@ -748,12 +821,18 @@ discard block |
||
748 | 821 | $fullSet = array(); |
749 | 822 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
750 | 823 | { |
751 | - if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
824 | + if ($key !== 'count') |
|
825 | + { |
|
826 | + $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
827 | + } |
|
752 | 828 | } |
753 | 829 | |
754 | - if (is_numeric($param['type'])) // return only group-members |
|
830 | + if (is_numeric($param['type'])) |
|
831 | + { |
|
832 | + // return only group-members |
|
755 | 833 | { |
756 | 834 | $relevantAccounts = array(); |
835 | + } |
|
757 | 836 | $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
758 | 837 | $group = ldap_get_entries($this->ds, $sri); |
759 | 838 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
@@ -791,7 +870,10 @@ discard block |
||
791 | 870 | //error_log(__METHOD__."() ldap=".array2string($allVals)." --> account=".array2string($account)); |
792 | 871 | if ($param['active'] && !$this->frontend->is_active($account)) |
793 | 872 | { |
794 | - if (isset($totalcount)) --$totalcount; |
|
873 | + if (isset($totalcount)) |
|
874 | + { |
|
875 | + --$totalcount; |
|
876 | + } |
|
795 | 877 | continue; |
796 | 878 | } |
797 | 879 | $account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], |
@@ -844,7 +926,10 @@ discard block |
||
844 | 926 | 'account_status' => 'A', |
845 | 927 | 'account_fullname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
846 | 928 | ); |
847 | - if (isset($totalcount)) ++$totalcount; |
|
929 | + if (isset($totalcount)) |
|
930 | + { |
|
931 | + ++$totalcount; |
|
932 | + } |
|
848 | 933 | } |
849 | 934 | } |
850 | 935 | } |
@@ -945,10 +1030,13 @@ discard block |
||
945 | 1030 | { |
946 | 1031 | $name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8')); |
947 | 1032 | |
948 | - if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
|
1033 | + if ($which == 'account_lid' && $account_type !== 'u') |
|
1034 | + { |
|
1035 | + // groups only support account_lid |
|
949 | 1036 | { |
950 | 1037 | |
951 | 1038 | $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
1039 | + } |
|
952 | 1040 | $allValues = ldap_get_entries($this->ds, $sri); |
953 | 1041 | |
954 | 1042 | if (@$allValues[0]['gidnumber'][0]) |
@@ -961,7 +1049,8 @@ discard block |
||
961 | 1049 | 'account_email' => static::MAIL_ATTR, |
962 | 1050 | 'account_fullname' => 'cn', |
963 | 1051 | ); |
964 | - if (!isset($to_ldap[$which]) || $account_type === 'g') { |
|
1052 | + if (!isset($to_ldap[$which]) || $account_type === 'g') |
|
1053 | + { |
|
965 | 1054 | return False; |
966 | 1055 | } |
967 | 1056 | |
@@ -1011,13 +1100,19 @@ discard block |
||
1011 | 1100 | */ |
1012 | 1101 | function memberships($account_id) |
1013 | 1102 | { |
1014 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1103 | + if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) |
|
1104 | + { |
|
1105 | + return false; |
|
1106 | + } |
|
1015 | 1107 | |
1016 | 1108 | $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber')); |
1017 | 1109 | $memberships = array(); |
1018 | 1110 | foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
1019 | 1111 | { |
1020 | - if ($key === 'count') continue; |
|
1112 | + if ($key === 'count') |
|
1113 | + { |
|
1114 | + continue; |
|
1115 | + } |
|
1021 | 1116 | |
1022 | 1117 | $memberships[(string) -$data['gidnumber'][0]] = $data['cn'][0]; |
1023 | 1118 | } |
@@ -1037,7 +1132,10 @@ discard block |
||
1037 | 1132 | { |
1038 | 1133 | // try to recover |
1039 | 1134 | $_gid = $this->name2id($_gid,'account_lid','g'); |
1040 | - if (!is_numeric($_gid)) return false; |
|
1135 | + if (!is_numeric($_gid)) |
|
1136 | + { |
|
1137 | + return false; |
|
1138 | + } |
|
1041 | 1139 | } |
1042 | 1140 | |
1043 | 1141 | $gid = abs($_gid); // our gid is negative! |
@@ -1085,7 +1183,10 @@ discard block |
||
1085 | 1183 | // adding new memberships |
1086 | 1184 | foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid) |
1087 | 1185 | { |
1088 | - if (!($members = $this->members($gid))) $members = array(); |
|
1186 | + if (!($members = $this->members($gid))) |
|
1187 | + { |
|
1188 | + $members = array(); |
|
1189 | + } |
|
1089 | 1190 | $members[$account_id] = $this->id2name($account_id); |
1090 | 1191 | $this->set_members($members,$gid); |
1091 | 1192 | } |
@@ -1103,16 +1204,25 @@ discard block |
||
1103 | 1204 | */ |
1104 | 1205 | function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
1105 | 1206 | { |
1106 | - if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
|
1207 | + if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) |
|
1208 | + { |
|
1209 | + return false; |
|
1210 | + } |
|
1107 | 1211 | |
1108 | 1212 | // do that group is a groupOf(Unique)Names or univentionGroup? |
1109 | - if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass'); |
|
1213 | + if (is_null($objectclass)) |
|
1214 | + { |
|
1215 | + $objectclass = $this->id2name($gid,'objectclass'); |
|
1216 | + } |
|
1110 | 1217 | |
1111 | 1218 | $to_write = array('memberuid' => array()); |
1112 | 1219 | foreach((array)$members as $key => $member) |
1113 | 1220 | { |
1114 | 1221 | $member_dn = $this->id2name($member, 'account_dn'); |
1115 | - if (is_numeric($member)) $member = $this->id2name($member); |
|
1222 | + if (is_numeric($member)) |
|
1223 | + { |
|
1224 | + $member = $this->id2name($member); |
|
1225 | + } |
|
1116 | 1226 | |
1117 | 1227 | if ($member) |
1118 | 1228 | { |
@@ -1136,21 +1246,33 @@ discard block |
||
1136 | 1246 | { |
1137 | 1247 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
1138 | 1248 | } |
1139 | - if ($use_cn) return $to_write; |
|
1249 | + if ($use_cn) |
|
1250 | + { |
|
1251 | + return $to_write; |
|
1252 | + } |
|
1140 | 1253 | |
1141 | 1254 | // set the member email addresses as forwards |
1142 | 1255 | if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
1143 | 1256 | { |
1144 | 1257 | $forward = $this->group_mail_classes[$objectclass]; |
1145 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
1146 | - if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
|
1258 | + if (is_array($forward)) |
|
1259 | + { |
|
1260 | + list($forward,$extra_attr) = $forward; |
|
1261 | + } |
|
1262 | + if ($extra_attr && ($uid = $this->id2name($gid))) |
|
1263 | + { |
|
1264 | + $to_write[$extra_attr] = $uid; |
|
1265 | + } |
|
1147 | 1266 | |
1148 | 1267 | if ($forward) |
1149 | 1268 | { |
1150 | 1269 | $to_write[$forward] = array(); |
1151 | 1270 | foreach($members as $key => $member) |
1152 | 1271 | { |
1153 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
1272 | + if (($email = $this->id2name($member,'account_email'))) |
|
1273 | + { |
|
1274 | + $to_write[$forward][] = $email; |
|
1275 | + } |
|
1154 | 1276 | } |
1155 | 1277 | } |
1156 | 1278 | } |
@@ -1176,7 +1298,10 @@ discard block |
||
1176 | 1298 | |
1177 | 1299 | // prefer ids above 1000 (below reserved for system users under AD or Linux), |
1178 | 1300 | // if that's possible within what is configured, or nothing is configured |
1179 | - if ($min < 1000 && (!$max || $max > 1000)) $min = 1000; |
|
1301 | + if ($min < 1000 && (!$max || $max > 1000)) |
|
1302 | + { |
|
1303 | + $min = 1000; |
|
1304 | + } |
|
1180 | 1305 | |
1181 | 1306 | if ($account_type == 'g') |
1182 | 1307 | { |
@@ -1229,7 +1354,10 @@ discard block |
||
1229 | 1354 | } |
1230 | 1355 | ++$id; |
1231 | 1356 | |
1232 | - if($id < $min) $id = $min; |
|
1357 | + if($id < $min) |
|
1358 | + { |
|
1359 | + $id = $min; |
|
1360 | + } |
|
1233 | 1361 | |
1234 | 1362 | Api\Config::save_value($key, $id, 'phpgwapi', true); |
1235 | 1363 | $GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id; |
@@ -47,7 +47,7 @@ |
||
47 | 47 | * If no account_id is set in data the account is added and the new id is set in $data. |
48 | 48 | * |
49 | 49 | * @param array $data array with account-data |
50 | - * @return int|boolean the account_id or false on error |
|
50 | + * @return false|string the account_id or false on error |
|
51 | 51 | */ |
52 | 52 | function save(&$data) |
53 | 53 | { |
@@ -90,7 +90,10 @@ |
||
90 | 90 | catch(Exception $e) { |
91 | 91 | unset($e); |
92 | 92 | } |
93 | - if (empty($hostname)) $hostname = trim(system('hostname -f')); |
|
93 | + if (empty($hostname)) |
|
94 | + { |
|
95 | + $hostname = trim(system('hostname -f')); |
|
96 | + } |
|
94 | 97 | $params[] = '--set'; $params[] = 'mailHomeServer='.$hostname; |
95 | 98 | } |
96 | 99 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | if (!$data['account_id'] && $data['account_type'] !== 'g') |
63 | 63 | { |
64 | 64 | $params = array( |
65 | - 'users/user','create', |
|
65 | + 'users/user', 'create', |
|
66 | 66 | '--binddn', $config['ldap_root_dn'], |
67 | 67 | '--bindpwd', 5=>$config['ldap_root_pw'], |
68 | 68 | '--position', $config['ldap_context'], |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | $hostname = $account->acc_imap_host; |
89 | 89 | } |
90 | - catch(\Exception $e) { |
|
90 | + catch (\Exception $e) { |
|
91 | 91 | unset($e); |
92 | 92 | } |
93 | 93 | if (empty($hostname)) $hostname = trim(system('hostname -f')); |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | $output = implode("\n", $output_arr); |
100 | 100 | if ($ret || !preg_match('/^Object created: (uid=.*)$/mui', $output, $matches)) |
101 | 101 | { |
102 | - $params[5] = '********'; // mask out password! |
|
102 | + $params[5] = '********'; // mask out password! |
|
103 | 103 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
104 | 104 | throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output); |
105 | 105 | } |
106 | 106 | $data['account_dn'] = $matches[1]; |
107 | 107 | $data['account_id'] = $this->name2id($data['account_lid'], 'account_lid', 'u'); |
108 | 108 | } |
109 | - elseif($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) && |
|
109 | + elseif ($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) && |
|
110 | 110 | $data['account_lid'] != $data['old_loginid'] && |
111 | 111 | ($data['account_dn'] = $this->id2name($data['account_id'], 'account_dn'))) |
112 | 112 | { |
@@ -123,12 +123,11 @@ discard block |
||
123 | 123 | $output = implode("\n", $output_arr); |
124 | 124 | if ($ret || !preg_match('/^Object modified: ((uid|cn)=.*)$/mui', $output, $matches)) |
125 | 125 | { |
126 | - $params[5] = '********'; // mask out password! |
|
126 | + $params[5] = '********'; // mask out password! |
|
127 | 127 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
128 | 128 | throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output); |
129 | 129 | } |
130 | - $data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] : |
|
131 | - // duno why but directory-manager returns old dn for groups ... |
|
130 | + $data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] : // duno why but directory-manager returns old dn for groups ... |
|
132 | 131 | preg_replace('/^cn=[^,]+,/', 'cn='.$data['account_lid'].',', $data['account_dn']); |
133 | 132 | } |
134 | 133 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * Delete ACL record in the repository of the class |
167 | 167 | * |
168 | 168 | * @param string $appname appname or '' for $GLOBALS['egw_info']['flags']['currentapp'] |
169 | - * @param string/boolean $location location or false for all locations |
|
169 | + * @param boolean $location location or false for all locations |
|
170 | 170 | * @return array all ACL records from $this->data. |
171 | 171 | */ |
172 | 172 | function delete($appname,$location) |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | /** |
268 | 268 | * check required rights agains the internal repository (included rights of $this->account_id and all it's memberships) |
269 | 269 | * |
270 | - * @param $location app location |
|
271 | - * @param $required required right to check against |
|
270 | + * @param string $location app location |
|
271 | + * @param integer $required required right to check against |
|
272 | 272 | * @param $appname optional defaults to currentapp |
273 | 273 | * @return boolean |
274 | 274 | */ |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * Constants for acl rights, like old EGW_ACL_* defines |
53 | 53 | */ |
54 | - const READ = 1; // EGW_ACL_READ |
|
55 | - const ADD = 2; // EGW_ACL_ADD |
|
56 | - const EDIT = 4; // EGW_ACL_EDIT |
|
57 | - const DELETE = 8; // EGW_ACL_DELETE |
|
58 | - const PRIVAT = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead! |
|
59 | - const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS |
|
60 | - const CUSTOM1 = 64; // EGW_ACL_CUSTOM_1 |
|
61 | - const CUSTOM2 = 128; // EGW_ACL_CUSTOM_2 |
|
62 | - const CUSTOM3 = 256; // EGW_ACL_CUSTOM_3 |
|
54 | + const READ = 1; // EGW_ACL_READ |
|
55 | + const ADD = 2; // EGW_ACL_ADD |
|
56 | + const EDIT = 4; // EGW_ACL_EDIT |
|
57 | + const DELETE = 8; // EGW_ACL_DELETE |
|
58 | + const PRIVAT = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead! |
|
59 | + const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS |
|
60 | + const CUSTOM1 = 64; // EGW_ACL_CUSTOM_1 |
|
61 | + const CUSTOM2 = 128; // EGW_ACL_CUSTOM_2 |
|
62 | + const CUSTOM3 = 256; // EGW_ACL_CUSTOM_3 |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * ACL constructor for setting account id |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | if ((int)$this->account_id != (int)$account_id) |
84 | 84 | { |
85 | - $this->account_id = get_account_id((int)$account_id,@$GLOBALS['egw_info']['user']['account_id']); |
|
85 | + $this->account_id = get_account_id((int)$account_id, @$GLOBALS['egw_info']['user']['account_id']); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param boolean|array $no_groups = false if true, do not use memberships, if array do not use given groups |
97 | 97 | * @return array along with storing it in $acl->data. <br> |
98 | 98 | */ |
99 | - function read_repository($no_groups=false) |
|
99 | + function read_repository($no_groups = false) |
|
100 | 100 | { |
101 | 101 | // For some reason, calling this via XML-RPC doesn't call the constructor. |
102 | 102 | // Here is yet another work around(tm) (jengo) |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | else |
112 | 112 | { |
113 | 113 | $acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true); |
114 | - if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
115 | - array_unshift($acl_acc_list,$this->account_id); |
|
114 | + if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list, $no_groups); |
|
115 | + array_unshift($acl_acc_list, $this->account_id); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $this->data = Array(); |
119 | - foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row) |
|
119 | + foreach ($this->db->select(self::TABLE, '*', array('acl_account' => $acl_acc_list), __LINE__, __FILE__) as $row) |
|
120 | 120 | { |
121 | - $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_'); |
|
121 | + $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row, 'acl_'); |
|
122 | 122 | } |
123 | 123 | return $this->data; |
124 | 124 | } |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | * @param int $rights rights |
148 | 148 | * @return array all ACL records from $this->data. |
149 | 149 | */ |
150 | - function add($appname,$location,$rights) |
|
150 | + function add($appname, $location, $rights) |
|
151 | 151 | { |
152 | 152 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
153 | 153 | |
154 | 154 | $row = array( |
155 | 155 | 'appname' => $appname, |
156 | 156 | 'location' => $location, |
157 | - 'account' => (int) $this->account_id, |
|
158 | - 'rights' => (int) $rights |
|
157 | + 'account' => (int)$this->account_id, |
|
158 | + 'rights' => (int)$rights |
|
159 | 159 | ); |
160 | 160 | $this->data[$row['appname'].'-'.$row['location'].'-'.$row['account']] = $row; |
161 | 161 | |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string/boolean $location location or false for all locations |
170 | 170 | * @return array all ACL records from $this->data. |
171 | 171 | */ |
172 | - function delete($appname,$location) |
|
172 | + function delete($appname, $location) |
|
173 | 173 | { |
174 | 174 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
175 | 175 | |
176 | - foreach($this->data as $idx => $value) |
|
176 | + foreach ($this->data as $idx => $value) |
|
177 | 177 | { |
178 | 178 | if ($value['appname'] == $appname && |
179 | 179 | ($location === false || $value['location'] == $location) && |
@@ -192,24 +192,24 @@ discard block |
||
192 | 192 | */ |
193 | 193 | function save_repository() |
194 | 194 | { |
195 | - $this->db->delete(self::TABLE,array( |
|
195 | + $this->db->delete(self::TABLE, array( |
|
196 | 196 | 'acl_account' => $this->account_id, |
197 | - ),__LINE__,__FILE__); |
|
197 | + ), __LINE__, __FILE__); |
|
198 | 198 | |
199 | - foreach($this->data as $value) |
|
199 | + foreach ($this->data as $value) |
|
200 | 200 | { |
201 | 201 | if ($value['account'] == $this->account_id) |
202 | 202 | { |
203 | - $this->db->insert(self::TABLE,array( |
|
203 | + $this->db->insert(self::TABLE, array( |
|
204 | 204 | 'acl_appname' => $value['appname'], |
205 | 205 | 'acl_location' => $value['location'], |
206 | 206 | 'acl_account' => $this->account_id, |
207 | 207 | 'acl_rights' => $value['rights'], |
208 | - ),false,__LINE__,__FILE__); |
|
208 | + ), false, __LINE__, __FILE__); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] && |
212 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
212 | + method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
213 | 213 | { |
214 | 214 | $GLOBALS['egw']->invalidate_session_cache(); |
215 | 215 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param string $appname optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
228 | 228 | * @return int all rights or'ed together |
229 | 229 | */ |
230 | - function get_rights($location,$appname = '') |
|
230 | + function get_rights($location, $appname = '') |
|
231 | 231 | { |
232 | 232 | // For XML-RPC, change this once its working correctly for passing parameters (jengo) |
233 | 233 | if (is_array($location)) |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | return True; |
248 | 248 | } |
249 | 249 | $rights = 0; |
250 | - foreach($this->data as $value) |
|
250 | + foreach ($this->data as $value) |
|
251 | 251 | { |
252 | 252 | if ($value['appname'] == $appname) |
253 | 253 | { |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | */ |
275 | 275 | function check($location, $required, $appname = False) |
276 | 276 | { |
277 | - $rights = $this->get_rights($location,$appname); |
|
277 | + $rights = $this->get_rights($location, $appname); |
|
278 | 278 | |
279 | - return !!($rights & $required); |
|
279 | + return !!($rights&$required); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @param array $memberships = array() additional account_id, eg. memberships to match beside $this->account_id, default none |
288 | 288 | * @return int $rights |
289 | 289 | */ |
290 | - function get_specific_rights($location, $appname = '', $memberships=array()) |
|
290 | + function get_specific_rights($location, $appname = '', $memberships = array()) |
|
291 | 291 | { |
292 | 292 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
293 | 293 | |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | } |
298 | 298 | $rights = 0; |
299 | 299 | |
300 | - foreach($this->data as $value) |
|
300 | + foreach ($this->data as $value) |
|
301 | 301 | { |
302 | 302 | if ($value['appname'] == $appname && |
303 | - ($value['location'] == $location || $value['location'] == 'everywhere') && |
|
303 | + ($value['location'] == $location || $value['location'] == 'everywhere') && |
|
304 | 304 | ($value['account'] == $this->account_id || $memberships && in_array($value['account'], $memberships))) |
305 | 305 | { |
306 | 306 | if ($value['rights'] == 0) |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | */ |
324 | 324 | function check_specific($location, $required, $appname = '') |
325 | 325 | { |
326 | - $rights = $this->get_specific_rights($location,$appname); |
|
326 | + $rights = $this->get_specific_rights($location, $appname); |
|
327 | 327 | |
328 | - return !!($rights & $required); |
|
328 | + return !!($rights&$required); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /**************************************************************************\ |
@@ -344,16 +344,16 @@ discard block |
||
344 | 344 | function add_repository($app, $location, $account_id, $rights) |
345 | 345 | { |
346 | 346 | //echo "<p>self::add_repository('$app','$location',$account_id,$rights);</p>\n"; |
347 | - $this->db->insert(self::TABLE,array( |
|
347 | + $this->db->insert(self::TABLE, array( |
|
348 | 348 | 'acl_rights' => $rights, |
349 | - ),array( |
|
349 | + ), array( |
|
350 | 350 | 'acl_appname' => $app, |
351 | 351 | 'acl_location' => $location, |
352 | 352 | 'acl_account' => $account_id, |
353 | - ),__LINE__,__FILE__); |
|
353 | + ), __LINE__, __FILE__); |
|
354 | 354 | |
355 | 355 | if ($account_id == $GLOBALS['egw_info']['user']['account_id'] && |
356 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
356 | + method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
357 | 357 | { |
358 | 358 | $GLOBALS['egw']->invalidate_session_cache(); |
359 | 359 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @param int/boolean $accountid = '' account id, default 0=$this->account_id, or false to delete all entries for $app/$location |
369 | 369 | * @return int number of rows deleted |
370 | 370 | */ |
371 | - function delete_repository($app, $location, $accountid='') |
|
371 | + function delete_repository($app, $location, $accountid = '') |
|
372 | 372 | { |
373 | 373 | static $cache_accountid = array(); |
374 | 374 | |
@@ -378,22 +378,22 @@ discard block |
||
378 | 378 | ); |
379 | 379 | if ($accountid !== false) |
380 | 380 | { |
381 | - if(isset($cache_accountid[$accountid]) && $cache_accountid[$accountid]) |
|
381 | + if (isset($cache_accountid[$accountid]) && $cache_accountid[$accountid]) |
|
382 | 382 | { |
383 | 383 | $where['acl_account'] = $cache_accountid[$accountid]; |
384 | 384 | } |
385 | 385 | else |
386 | 386 | { |
387 | - $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
|
387 | + $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id); |
|
388 | 388 | } |
389 | 389 | } |
390 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
390 | + if (method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
391 | 391 | { |
392 | 392 | $GLOBALS['egw']->invalidate_session_cache(); |
393 | 393 | } |
394 | 394 | if ($app == '%' || $app == '%%') unset($where['acl_appname']); |
395 | 395 | |
396 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
396 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
397 | 397 | |
398 | 398 | return $this->db->affected_rows(); |
399 | 399 | } |
@@ -406,15 +406,15 @@ discard block |
||
406 | 406 | * @param string $appname = '' defaults to current app |
407 | 407 | * @return int/boolean rights or false if none exist |
408 | 408 | */ |
409 | - function get_specific_rights_for_account($account_id,$location,$appname='') |
|
409 | + function get_specific_rights_for_account($account_id, $location, $appname = '') |
|
410 | 410 | { |
411 | 411 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
412 | 412 | |
413 | - return $this->db->select(self::TABLE,'acl_rights',array( |
|
413 | + return $this->db->select(self::TABLE, 'acl_rights', array( |
|
414 | 414 | 'acl_location' => $location, |
415 | 415 | 'acl_account' => $account_id, |
416 | 416 | 'acl_appname' => $appname, |
417 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
417 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
@@ -424,15 +424,15 @@ discard block |
||
424 | 424 | * @param string $appname = '' defaults to current app |
425 | 425 | * @return array with account => rights pairs |
426 | 426 | */ |
427 | - function get_all_rights($location,$appname='') |
|
427 | + function get_all_rights($location, $appname = '') |
|
428 | 428 | { |
429 | 429 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
430 | 430 | |
431 | 431 | $rights = array(); |
432 | - foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array( |
|
432 | + foreach ($this->db->select(self::TABLE, 'acl_account,acl_rights', array( |
|
433 | 433 | 'acl_location' => $location, |
434 | 434 | 'acl_appname' => $appname, |
435 | - ),__LINE__,__FILE__) as $row) |
|
435 | + ), __LINE__, __FILE__) as $row) |
|
436 | 436 | { |
437 | 437 | $rights[$row['acl_account']] = $row['acl_rights']; |
438 | 438 | } |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @param boolean $use_memberships = true |
448 | 448 | * @return array with location => rights pairs |
449 | 449 | */ |
450 | - function get_all_location_rights($account_id,$appname='',$use_memberships=true) |
|
450 | + function get_all_location_rights($account_id, $appname = '', $use_memberships = true) |
|
451 | 451 | { |
452 | 452 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
453 | 453 | |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | $accounts[] = $account_id; |
459 | 459 | } |
460 | 460 | $rights = array(); |
461 | - foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array( |
|
461 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array( |
|
462 | 462 | 'acl_account' => $accounts, |
463 | 463 | 'acl_appname' => $appname, |
464 | - ),__LINE__,__FILE__) as $row) |
|
464 | + ), __LINE__, __FILE__) as $row) |
|
465 | 465 | { |
466 | 466 | $rights[$row['acl_location']] |= $row['acl_rights']; |
467 | 467 | } |
@@ -480,28 +480,28 @@ discard block |
||
480 | 480 | { |
481 | 481 | static $cache_accountid = array(); |
482 | 482 | |
483 | - if(isset($cache_accountid[$accountid])) |
|
483 | + if (isset($cache_accountid[$accountid])) |
|
484 | 484 | { |
485 | 485 | $account_id = $cache_accountid[$accountid]; |
486 | 486 | } |
487 | 487 | else |
488 | 488 | { |
489 | - $account_id = get_account_id($accountid,$this->account_id); |
|
489 | + $account_id = get_account_id($accountid, $this->account_id); |
|
490 | 490 | $cache_accountid[$accountid] = $account_id; |
491 | 491 | } |
492 | 492 | $rights = 0; |
493 | 493 | $apps = false; |
494 | - foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array( |
|
494 | + foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array( |
|
495 | 495 | 'acl_location' => $location, |
496 | 496 | 'acl_account' => $account_id, |
497 | - ),__LINE__,__FILE__) as $row) |
|
497 | + ), __LINE__, __FILE__) as $row) |
|
498 | 498 | { |
499 | 499 | if ($row['acl_rights'] == 0) |
500 | 500 | { |
501 | 501 | return False; |
502 | 502 | } |
503 | 503 | $rights |= $row['acl_rights']; |
504 | - if (!!($rights & $required)) |
|
504 | + if (!!($rights&$required)) |
|
505 | 505 | { |
506 | 506 | $apps[] = $row['acl_appname']; |
507 | 507 | } |
@@ -521,21 +521,21 @@ discard block |
||
521 | 521 | { |
522 | 522 | static $cache_accountid = array(); |
523 | 523 | |
524 | - if(isset($cache_accountid[$accountid])) |
|
524 | + if (isset($cache_accountid[$accountid])) |
|
525 | 525 | { |
526 | 526 | $accountid = $cache_accountid[$accountid]; |
527 | 527 | } |
528 | 528 | else |
529 | 529 | { |
530 | - $accountid = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
|
530 | + $accountid = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id); |
|
531 | 531 | } |
532 | 532 | $locations = false; |
533 | - foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array( |
|
533 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array( |
|
534 | 534 | 'acl_appname' => $app, |
535 | 535 | 'acl_account' => $accountid, |
536 | - ),__LINE__,__FILE__) as $row) |
|
536 | + ), __LINE__, __FILE__) as $row) |
|
537 | 537 | { |
538 | - if ($row['acl_rights'] & $required) |
|
538 | + if ($row['acl_rights']&$required) |
|
539 | 539 | { |
540 | 540 | $locations[] = $row['acl_location']; |
541 | 541 | } |
@@ -556,14 +556,14 @@ discard block |
||
556 | 556 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
557 | 557 | |
558 | 558 | $accounts = false; |
559 | - foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array( |
|
559 | + foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights'), array( |
|
560 | 560 | 'acl_appname' => $app, |
561 | 561 | 'acl_location' => $location, |
562 | - ),__LINE__,__FILE__) as $row) |
|
562 | + ), __LINE__, __FILE__) as $row) |
|
563 | 563 | { |
564 | - if (!!($row['acl_rights'] & $required)) |
|
564 | + if (!!($row['acl_rights']&$required)) |
|
565 | 565 | { |
566 | - $accounts[] = (int) $row['acl_account']; |
|
566 | + $accounts[] = (int)$row['acl_account']; |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | return $accounts; |
@@ -575,14 +575,14 @@ discard block |
||
575 | 575 | * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
576 | 576 | * @return boolean/array false if there are no matching location in the db or array of locations |
577 | 577 | */ |
578 | - function get_locations_for_app($app='') |
|
578 | + function get_locations_for_app($app = '') |
|
579 | 579 | { |
580 | 580 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
581 | 581 | |
582 | 582 | $locations = false; |
583 | - foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array( |
|
583 | + foreach ($this->db->select(self::TABLE, 'DISTINCT '.'acl_location', array( |
|
584 | 584 | 'acl_appname' => $app, |
585 | - ),__LINE__,__FILE__) as $row) |
|
585 | + ), __LINE__, __FILE__) as $row) |
|
586 | 586 | { |
587 | 587 | if (($location = $row['acl_location']) != 'run') |
588 | 588 | { |
@@ -600,38 +600,38 @@ discard block |
||
600 | 600 | * @param boolean $add_implicit_apps = true true: add apps every user has implicit rights |
601 | 601 | * @return array containing list of apps |
602 | 602 | */ |
603 | - function get_user_applications($accountid = '', $use_memberships=true, $add_implicit_apps=true) |
|
603 | + function get_user_applications($accountid = '', $use_memberships = true, $add_implicit_apps = true) |
|
604 | 604 | { |
605 | 605 | static $cache_accountid = array(); |
606 | 606 | |
607 | - if(isset($cache_accountid[$accountid])) |
|
607 | + if (isset($cache_accountid[$accountid])) |
|
608 | 608 | { |
609 | 609 | $account_id = $cache_accountid[$accountid]; |
610 | 610 | } |
611 | 611 | else |
612 | 612 | { |
613 | - $account_id = get_account_id($accountid,$this->account_id); |
|
613 | + $account_id = get_account_id($accountid, $this->account_id); |
|
614 | 614 | $cache_accountid[$accountid] = $account_id; |
615 | 615 | } |
616 | 616 | if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
617 | 617 | $memberships[] = (int)$account_id; |
618 | 618 | |
619 | 619 | $apps = array(); |
620 | - foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array( |
|
620 | + foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array( |
|
621 | 621 | 'acl_location' => 'run', |
622 | 622 | 'acl_account' => $memberships, |
623 | - ),__LINE__,__FILE__) as $row) |
|
623 | + ), __LINE__, __FILE__) as $row) |
|
624 | 624 | { |
625 | 625 | $app = $row['acl_appname']; |
626 | - if(!isset($apps[$app])) |
|
626 | + if (!isset($apps[$app])) |
|
627 | 627 | { |
628 | 628 | $apps[$app] = 0; |
629 | 629 | } |
630 | - $apps[$app] |= (int) $row['acl_rights']; |
|
630 | + $apps[$app] |= (int)$row['acl_rights']; |
|
631 | 631 | } |
632 | 632 | if ($add_implicit_apps) |
633 | 633 | { |
634 | - $apps['api'] = 1; // give everyone implicit rights for the home app |
|
634 | + $apps['api'] = 1; // give everyone implicit rights for the home app |
|
635 | 635 | } |
636 | 636 | return $apps; |
637 | 637 | } |
@@ -645,29 +645,29 @@ discard block |
||
645 | 645 | * @param int $user = null user whos grants to return, default current user |
646 | 646 | * @return array with account-ids (of owners) and granted rights as values |
647 | 647 | */ |
648 | - function get_grants($app='',$enum_group_acls=true,$user=null) |
|
648 | + function get_grants($app = '', $enum_group_acls = true, $user = null) |
|
649 | 649 | { |
650 | 650 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
651 | 651 | if (!$user) $user = $this->account_id; |
652 | 652 | |
653 | - static $cache = array(); // some caching withing the request |
|
653 | + static $cache = array(); // some caching withing the request |
|
654 | 654 | |
655 | - $grants =& $cache[$app][$user]; |
|
655 | + $grants = & $cache[$app][$user]; |
|
656 | 656 | if (!isset($grants)) |
657 | 657 | { |
658 | 658 | if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
659 | 659 | $memberships[] = $user; |
660 | 660 | |
661 | 661 | $grants = $accounts = Array(); |
662 | - foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array( |
|
662 | + foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights', 'acl_location'), array( |
|
663 | 663 | 'acl_appname' => $app, |
664 | 664 | 'acl_location' => $memberships, |
665 | - ),__LINE__,__FILE__) as $row) |
|
665 | + ), __LINE__, __FILE__) as $row) |
|
666 | 666 | { |
667 | 667 | $grantor = $row['acl_account']; |
668 | 668 | $rights = $row['acl_rights']; |
669 | 669 | |
670 | - if(!isset($grants[$grantor])) |
|
670 | + if (!isset($grants[$grantor])) |
|
671 | 671 | { |
672 | 672 | $grants[$grantor] = 0; |
673 | 673 | } |
@@ -675,17 +675,17 @@ discard block |
||
675 | 675 | |
676 | 676 | // if the right is granted from a group and we enummerated group ACL's |
677 | 677 | if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls && |
678 | - (!is_array($enum_group_acls) || !in_array($grantor,$enum_group_acls))) |
|
678 | + (!is_array($enum_group_acls) || !in_array($grantor, $enum_group_acls))) |
|
679 | 679 | { |
680 | 680 | // return the grant for each member of the group (false = also for no longer active users) |
681 | - foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
|
681 | + foreach ((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
|
682 | 682 | { |
683 | - if (!$grantor) continue; // can happen if group has no members |
|
683 | + if (!$grantor) continue; // can happen if group has no members |
|
684 | 684 | |
685 | 685 | // Don't allow to override private with group ACL's! |
686 | 686 | $rights &= ~self::PRIVAT; |
687 | 687 | |
688 | - if(!isset($grants[$grantor])) |
|
688 | + if (!isset($grants[$grantor])) |
|
689 | 689 | { |
690 | 690 | $grants[$grantor] = 0; |
691 | 691 | } |
@@ -707,21 +707,21 @@ discard block |
||
707 | 707 | */ |
708 | 708 | function delete_account($account_id) |
709 | 709 | { |
710 | - if ((int) $account_id) |
|
710 | + if ((int)$account_id) |
|
711 | 711 | { |
712 | 712 | // Delete all grants from this account |
713 | - $this->db->delete(self::TABLE,array( |
|
713 | + $this->db->delete(self::TABLE, array( |
|
714 | 714 | 'acl_account' => $account_id |
715 | - ),__LINE__,__FILE__); |
|
715 | + ), __LINE__, __FILE__); |
|
716 | 716 | // Delete all grants to this account |
717 | - $this->db->delete(self::TABLE,array( |
|
717 | + $this->db->delete(self::TABLE, array( |
|
718 | 718 | 'acl_location' => $account_id |
719 | - ),__LINE__, __FILE__); |
|
719 | + ), __LINE__, __FILE__); |
|
720 | 720 | // delete all memberships in account_id (if it is a group) |
721 | - $this->db->delete(self::TABLE,array( |
|
721 | + $this->db->delete(self::TABLE, array( |
|
722 | 722 | 'acl_appname' => 'phpgw_group', |
723 | 723 | 'acl_location' => $account_id, |
724 | - ),__LINE__,__FILE__); |
|
724 | + ), __LINE__, __FILE__); |
|
725 | 725 | } |
726 | 726 | } |
727 | 727 | |
@@ -732,15 +732,15 @@ discard block |
||
732 | 732 | * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
733 | 733 | * @return array with location => array(account => rights) pairs |
734 | 734 | */ |
735 | - function get_location_grants($location,$app='') |
|
735 | + function get_location_grants($location, $app = '') |
|
736 | 736 | { |
737 | 737 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
738 | 738 | |
739 | 739 | $locations = array(); |
740 | - foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array( |
|
740 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_account,acl_rights', array( |
|
741 | 741 | 'acl_appname' => $app, |
742 | 742 | 'acl_location LIKE '.$this->db->quote($location), |
743 | - ),__LINE__,__FILE__) as $row) |
|
743 | + ), __LINE__, __FILE__) as $row) |
|
744 | 744 | { |
745 | 745 | if (($location = $row['acl_location']) != 'run') |
746 | 746 | { |
@@ -111,7 +111,10 @@ discard block |
||
111 | 111 | else |
112 | 112 | { |
113 | 113 | $acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true); |
114 | - if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
114 | + if (is_array($no_groups)) |
|
115 | + { |
|
116 | + $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
117 | + } |
|
115 | 118 | array_unshift($acl_acc_list,$this->account_id); |
116 | 119 | } |
117 | 120 | |
@@ -149,7 +152,10 @@ discard block |
||
149 | 152 | */ |
150 | 153 | function add($appname,$location,$rights) |
151 | 154 | { |
152 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
155 | + if (!$appname) |
|
156 | + { |
|
157 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
158 | + } |
|
153 | 159 | |
154 | 160 | $row = array( |
155 | 161 | 'appname' => $appname, |
@@ -171,7 +177,10 @@ discard block |
||
171 | 177 | */ |
172 | 178 | function delete($appname,$location) |
173 | 179 | { |
174 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
180 | + if (!$appname) |
|
181 | + { |
|
182 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
183 | + } |
|
175 | 184 | |
176 | 185 | foreach($this->data as $idx => $value) |
177 | 186 | { |
@@ -209,10 +218,13 @@ discard block |
||
209 | 218 | } |
210 | 219 | } |
211 | 220 | if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] && |
212 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
221 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
222 | + { |
|
223 | + // egw object in setup is limited |
|
213 | 224 | { |
214 | 225 | $GLOBALS['egw']->invalidate_session_cache(); |
215 | 226 | } |
227 | + } |
|
216 | 228 | return $this->data; |
217 | 229 | } |
218 | 230 | |
@@ -240,7 +252,10 @@ discard block |
||
240 | 252 | { |
241 | 253 | $this->read_repository(); |
242 | 254 | } |
243 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
255 | + if (!$appname) |
|
256 | + { |
|
257 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
258 | + } |
|
244 | 259 | |
245 | 260 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
246 | 261 | { |
@@ -289,7 +304,10 @@ discard block |
||
289 | 304 | */ |
290 | 305 | function get_specific_rights($location, $appname = '', $memberships=array()) |
291 | 306 | { |
292 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
307 | + if (!$appname) |
|
308 | + { |
|
309 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
310 | + } |
|
293 | 311 | |
294 | 312 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
295 | 313 | { |
@@ -353,10 +371,13 @@ discard block |
||
353 | 371 | ),__LINE__,__FILE__); |
354 | 372 | |
355 | 373 | if ($account_id == $GLOBALS['egw_info']['user']['account_id'] && |
356 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
374 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
375 | + { |
|
376 | + // egw object in setup is limited |
|
357 | 377 | { |
358 | 378 | $GLOBALS['egw']->invalidate_session_cache(); |
359 | 379 | } |
380 | + } |
|
360 | 381 | return True; |
361 | 382 | } |
362 | 383 | |
@@ -387,11 +408,17 @@ discard block |
||
387 | 408 | $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
388 | 409 | } |
389 | 410 | } |
390 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
411 | + if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
412 | + { |
|
413 | + // egw object in setup is limited |
|
391 | 414 | { |
392 | 415 | $GLOBALS['egw']->invalidate_session_cache(); |
393 | 416 | } |
394 | - if ($app == '%' || $app == '%%') unset($where['acl_appname']); |
|
417 | + } |
|
418 | + if ($app == '%' || $app == '%%') |
|
419 | + { |
|
420 | + unset($where['acl_appname']); |
|
421 | + } |
|
395 | 422 | |
396 | 423 | $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
397 | 424 | |
@@ -408,7 +435,10 @@ discard block |
||
408 | 435 | */ |
409 | 436 | function get_specific_rights_for_account($account_id,$location,$appname='') |
410 | 437 | { |
411 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
438 | + if (!$appname) |
|
439 | + { |
|
440 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
441 | + } |
|
412 | 442 | |
413 | 443 | return $this->db->select(self::TABLE,'acl_rights',array( |
414 | 444 | 'acl_location' => $location, |
@@ -426,7 +456,10 @@ discard block |
||
426 | 456 | */ |
427 | 457 | function get_all_rights($location,$appname='') |
428 | 458 | { |
429 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
459 | + if (!$appname) |
|
460 | + { |
|
461 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
462 | + } |
|
430 | 463 | |
431 | 464 | $rights = array(); |
432 | 465 | foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array( |
@@ -449,7 +482,10 @@ discard block |
||
449 | 482 | */ |
450 | 483 | function get_all_location_rights($account_id,$appname='',$use_memberships=true) |
451 | 484 | { |
452 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
485 | + if (!$appname) |
|
486 | + { |
|
487 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
488 | + } |
|
453 | 489 | |
454 | 490 | $accounts = array($account_id); |
455 | 491 | if ($use_memberships && (int)$account_id > 0) |
@@ -553,7 +589,10 @@ discard block |
||
553 | 589 | */ |
554 | 590 | function get_ids_for_location($location, $required, $app = '') |
555 | 591 | { |
556 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
592 | + if (!$app) |
|
593 | + { |
|
594 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
595 | + } |
|
557 | 596 | |
558 | 597 | $accounts = false; |
559 | 598 | foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array( |
@@ -577,7 +616,10 @@ discard block |
||
577 | 616 | */ |
578 | 617 | function get_locations_for_app($app='') |
579 | 618 | { |
580 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
619 | + if (!$app) |
|
620 | + { |
|
621 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
622 | + } |
|
581 | 623 | |
582 | 624 | $locations = false; |
583 | 625 | foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array( |
@@ -613,7 +655,10 @@ discard block |
||
613 | 655 | $account_id = get_account_id($accountid,$this->account_id); |
614 | 656 | $cache_accountid[$accountid] = $account_id; |
615 | 657 | } |
616 | - if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
658 | + if ($use_memberships && (int)$account_id > 0) |
|
659 | + { |
|
660 | + $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
661 | + } |
|
617 | 662 | $memberships[] = (int)$account_id; |
618 | 663 | |
619 | 664 | $apps = array(); |
@@ -647,15 +692,24 @@ discard block |
||
647 | 692 | */ |
648 | 693 | function get_grants($app='',$enum_group_acls=true,$user=null) |
649 | 694 | { |
650 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
651 | - if (!$user) $user = $this->account_id; |
|
695 | + if (!$app) |
|
696 | + { |
|
697 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
698 | + } |
|
699 | + if (!$user) |
|
700 | + { |
|
701 | + $user = $this->account_id; |
|
702 | + } |
|
652 | 703 | |
653 | 704 | static $cache = array(); // some caching withing the request |
654 | 705 | |
655 | 706 | $grants =& $cache[$app][$user]; |
656 | 707 | if (!isset($grants)) |
657 | 708 | { |
658 | - if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
709 | + if ((int)$user > 0) |
|
710 | + { |
|
711 | + $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
712 | + } |
|
659 | 713 | $memberships[] = $user; |
660 | 714 | |
661 | 715 | $grants = $accounts = Array(); |
@@ -680,7 +734,11 @@ discard block |
||
680 | 734 | // return the grant for each member of the group (false = also for no longer active users) |
681 | 735 | foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
682 | 736 | { |
683 | - if (!$grantor) continue; // can happen if group has no members |
|
737 | + if (!$grantor) |
|
738 | + { |
|
739 | + continue; |
|
740 | + } |
|
741 | + // can happen if group has no members |
|
684 | 742 | |
685 | 743 | // Don't allow to override private with group ACL's! |
686 | 744 | $rights &= ~self::PRIVAT; |
@@ -734,7 +792,10 @@ discard block |
||
734 | 792 | */ |
735 | 793 | function get_location_grants($location,$app='') |
736 | 794 | { |
737 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
795 | + if (!$app) |
|
796 | + { |
|
797 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
798 | + } |
|
738 | 799 | |
739 | 800 | $locations = array(); |
740 | 801 | foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array( |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @var array $data internal repository with acl rows for the given app and account-id (incl. memberships) |
38 | 38 | */ |
39 | - var $data = Array(); |
|
39 | + var $data = array(); |
|
40 | 40 | /** |
41 | 41 | * internal copy of the db-object |
42 | 42 | * |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | array_unshift($acl_acc_list,$this->account_id); |
116 | 116 | } |
117 | 117 | |
118 | - $this->data = Array(); |
|
118 | + $this->data = array(); |
|
119 | 119 | foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row) |
120 | 120 | { |
121 | 121 | $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_'); |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
659 | 659 | $memberships[] = $user; |
660 | 660 | |
661 | - $grants = $accounts = Array(); |
|
661 | + $grants = $accounts = array(); |
|
662 | 662 | foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array( |
663 | 663 | 'acl_appname' => $app, |
664 | 664 | 'acl_location' => $memberships, |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * cancels a timer |
325 | 325 | * |
326 | 326 | * @param string $id has to be the one used to set it. |
327 | - * @return boolean True if the timer exists and is not expired. |
|
327 | + * @return integer True if the timer exists and is not expired. |
|
328 | 328 | */ |
329 | 329 | function cancel_timer($id) |
330 | 330 | { |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | /** |
471 | 471 | * reads all matching db-rows / jobs |
472 | 472 | * |
473 | - * @param string $id =0 reads all expired rows / jobs ready to run\ |
|
473 | + * @param integer $id =0 reads all expired rows / jobs ready to run\ |
|
474 | 474 | * != 0 reads all rows/jobs matching $id (sql-wildcards '%' and '_' can be used) |
475 | 475 | * @param array|string $cols ='*' string or array of column-names / select-expressions |
476 | 476 | * @param int|bool $offset =False offset for a limited query or False (default) |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | /** |
559 | 559 | * delete db-row / job with $id |
560 | 560 | * |
561 | - * @return boolean False if $id not found else True |
|
561 | + * @return integer False if $id not found else True |
|
562 | 562 | */ |
563 | 563 | function delete($id) |
564 | 564 | { |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | { |
50 | 50 | $this->db = $GLOBALS['egw_setup']->db; |
51 | 51 | } |
52 | - $this->cronline = EGW_SERVER_ROOT . '/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
52 | + $this->cronline = EGW_SERVER_ROOT.'/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
53 | 53 | |
54 | - $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
54 | + $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | * @param boolean $debug =false |
72 | 72 | * @return boolean False if $id already exists, else True |
73 | 73 | */ |
74 | - function set_timer($times,$id,$method,$data=null,$account_id=False,$debug=false) |
|
74 | + function set_timer($times, $id, $method, $data = null, $account_id = False, $debug = false) |
|
75 | 75 | { |
76 | 76 | if (empty($id) || empty($method) || $this->read($id) || |
77 | - !($next = $this->next_run($times,$debug))) |
|
77 | + !($next = $this->next_run($times, $debug))) |
|
78 | 78 | { |
79 | 79 | return False; |
80 | 80 | } |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | * @param int $now Use this time to calculate then next run from. Defaults to time(). |
108 | 108 | * @return int a unix timestamp of the next execution time or False if no more executions |
109 | 109 | */ |
110 | - function next_run($times,$debug=False, $now = null) |
|
110 | + function next_run($times, $debug = False, $now = null) |
|
111 | 111 | { |
112 | 112 | if ($this->debug) |
113 | 113 | { |
114 | - echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n"; |
|
115 | - $debug = True; // enable syntax-error messages too |
|
114 | + echo "<p>next_run("; print_r($times); echo ",'$debug', ".date('Y-m-d H:i', $now).")</p>\n"; |
|
115 | + $debug = True; // enable syntax-error messages too |
|
116 | 116 | } |
117 | - if(is_null($now)) { |
|
117 | + if (is_null($now)) { |
|
118 | 118 | $now = time(); |
119 | 119 | } |
120 | 120 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | 'dow' => 6, |
143 | 143 | 'day' => 31, |
144 | 144 | 'month' => 12, |
145 | - 'year' => date('Y')+10 // else */[0-9] would never stop returning numbers |
|
145 | + 'year' => date('Y') + 10 // else */[0-9] would never stop returning numbers |
|
146 | 146 | ); |
147 | 147 | $min_unit = array( |
148 | 148 | 'min' => 0, |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | // get set to the minimum after |
159 | 159 | // |
160 | 160 | $i = $first_set = $last_set = 0; |
161 | - foreach($units as $u => $date_pattern) |
|
161 | + foreach ($units as $u => $date_pattern) |
|
162 | 162 | { |
163 | 163 | ++$i; |
164 | 164 | if (isset($times[$u])) |
@@ -176,24 +176,24 @@ discard block |
||
176 | 176 | // (as descript above), enumerations are arrays with unit-values as keys |
177 | 177 | // |
178 | 178 | $n = 0; |
179 | - foreach($units as $u => $date_pattern) |
|
179 | + foreach ($units as $u => $date_pattern) |
|
180 | 180 | { |
181 | 181 | ++$n; |
182 | - if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
182 | + if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u]) ? 'True' : 'False')."</p>\n"; } |
|
183 | 183 | if (isset($times[$u])) |
184 | 184 | { |
185 | - if(is_array($times[$u])) { |
|
185 | + if (is_array($times[$u])) { |
|
186 | 186 | $time = array_keys($times[$u]); |
187 | 187 | } else { |
188 | - $time = explode(',',$times[$u]); |
|
188 | + $time = explode(',', $times[$u]); |
|
189 | 189 | } |
190 | 190 | $times[$u] = array(); |
191 | 191 | |
192 | - foreach($time as $t) |
|
192 | + foreach ($time as $t) |
|
193 | 193 | { |
194 | - if (strpos($t,'-') !== False && strpos($t,'/') === False) |
|
194 | + if (strpos($t, '-') !== False && strpos($t, '/') === False) |
|
195 | 195 | { |
196 | - list($min,$max) = $arr = explode('-',$t); |
|
196 | + list($min, $max) = $arr = explode('-', $t); |
|
197 | 197 | |
198 | 198 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
199 | 199 | { |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | { |
211 | 211 | if ((string)$t == '*') $t = '*/1'; |
212 | 212 | |
213 | - list($one,$inc) = $arr = explode('/',$t); |
|
213 | + list($one, $inc) = $arr = explode('/', $t); |
|
214 | 214 | |
215 | 215 | if (!(is_numeric($one) && count($arr) == 1 || |
216 | 216 | count($arr) == 2 && is_numeric($inc))) |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | } |
226 | 226 | else |
227 | 227 | { |
228 | - list($min,$max) = $arr = explode('-',$one); |
|
228 | + list($min, $max) = $arr = explode('-', $one); |
|
229 | 229 | if (empty($one) || $one == '*') |
230 | 230 | { |
231 | 231 | $min = $min_unit[$u]; |
@@ -266,20 +266,19 @@ discard block |
||
266 | 266 | { |
267 | 267 | $future = False; |
268 | 268 | |
269 | - foreach($units as $u => $date_pattern) |
|
269 | + foreach ($units as $u => $date_pattern) |
|
270 | 270 | { |
271 | - $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : |
|
272 | - (int)date($date_pattern,mktime(12,0,0,$found['month'],$found['day'],$found['year'])); |
|
271 | + $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : (int)date($date_pattern, mktime(12, 0, 0, $found['month'], $found['day'], $found['year'])); |
|
273 | 272 | |
274 | 273 | if (isset($found[$u])) |
275 | 274 | { |
276 | 275 | $future = $future || $found[$u] > $unit_now; |
277 | 276 | if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
278 | - continue; // already set |
|
277 | + continue; // already set |
|
279 | 278 | } |
280 | - foreach(array_keys($times[$u]) as $unit_value) |
|
279 | + foreach (array_keys($times[$u]) as $unit_value) |
|
281 | 280 | { |
282 | - switch($u) |
|
281 | + switch ($u) |
|
283 | 282 | { |
284 | 283 | case 'dow': |
285 | 284 | $valid = $unit_value == $unit_now; |
@@ -302,12 +301,12 @@ discard block |
||
302 | 301 | if (!isset($found[$u])) // we have to try the next one, if it exists |
303 | 302 | { |
304 | 303 | $nexts = array_keys($units); |
305 | - if (!isset($nexts[count($found)-1])) |
|
304 | + if (!isset($nexts[count($found) - 1])) |
|
306 | 305 | { |
307 | 306 | if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n"; |
308 | 307 | return False; |
309 | 308 | } |
310 | - $next = $nexts[count($found)-1]; |
|
309 | + $next = $nexts[count($found) - 1]; |
|
311 | 310 | $over = $found[$next]; |
312 | 311 | unset($found[$next]); |
313 | 312 | if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
@@ -317,7 +316,7 @@ discard block |
||
317 | 316 | } |
318 | 317 | if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; } |
319 | 318 | |
320 | - return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
|
319 | + return mktime($found['hour'], $found['min'], 0, $found['month'], $found['day'], $found['year']); |
|
321 | 320 | } |
322 | 321 | |
323 | 322 | /** |
@@ -339,7 +338,7 @@ discard block |
||
339 | 338 | * @return mixed if !$set array('start' => $start,'end' => $end) with timestamps of last check_run start and end, \ |
340 | 339 | * !$end means check_run is just running. If $set returns True if it was able to get the semaphore, else False |
341 | 340 | */ |
342 | - function last_check_run($semaphore=False,$release=False,$run_by='') |
|
341 | + function last_check_run($semaphore = False, $release = False, $run_by = '') |
|
343 | 342 | { |
344 | 343 | //echo "<p>last_check_run(semaphore=".($semaphore?'True':'False').",release=".($release?'True':'False').")</p>\n"; |
345 | 344 | if (($exists = $this->read('##last-check-run##'))) |
@@ -361,7 +360,7 @@ discard block |
||
361 | 360 | } |
362 | 361 | else |
363 | 362 | { |
364 | - @set_time_limit(0); // dont stop for an execution-time-limit |
|
363 | + @set_time_limit(0); // dont stop for an execution-time-limit |
|
365 | 364 | ignore_user_abort(True); |
366 | 365 | |
367 | 366 | $last_run = array( |
@@ -377,7 +376,7 @@ discard block |
||
377 | 376 | ); |
378 | 377 | // as the async_next column is used as a semaphore we only update it, |
379 | 378 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
380 | - if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
379 | + if ($exists) $where = array('async_next=0 OR async_next<'.(time() - 600)); |
|
381 | 380 | } |
382 | 381 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
383 | 382 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -386,20 +385,20 @@ discard block |
||
386 | 385 | /** |
387 | 386 | * checks if there are any jobs ready to run (timer expired) and executes them |
388 | 387 | */ |
389 | - function check_run($run_by='') |
|
388 | + function check_run($run_by = '') |
|
390 | 389 | { |
391 | 390 | if ($run_by === 'fallback') flush(); |
392 | 391 | |
393 | - if (!$this->last_check_run(True,False,$run_by)) |
|
392 | + if (!$this->last_check_run(True, False, $run_by)) |
|
394 | 393 | { |
395 | - return False; // cant obtain semaphore |
|
394 | + return False; // cant obtain semaphore |
|
396 | 395 | } |
397 | 396 | // mark enviroment as async-service, check with isset()! |
398 | 397 | $GLOBALS['egw_info']['flags']['async-service'] = $run_by; |
399 | 398 | |
400 | 399 | if (($jobs = $this->read())) |
401 | 400 | { |
402 | - foreach($jobs as $job) |
|
401 | + foreach ($jobs as $job) |
|
403 | 402 | { |
404 | 403 | // checking / setting up egw_info/user |
405 | 404 | // |
@@ -408,7 +407,7 @@ discard block |
||
408 | 407 | // run notifications, before changing account_id of enviroment |
409 | 408 | Link::run_notifies(); |
410 | 409 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
411 | - foreach($GLOBALS as $name => $value) |
|
410 | + foreach ($GLOBALS as $name => $value) |
|
412 | 411 | { |
413 | 412 | if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
414 | 413 | } |
@@ -420,7 +419,7 @@ discard block |
||
420 | 419 | { |
421 | 420 | $GLOBALS['egw']->session->account_lid = $GLOBALS['egw']->accounts->id2name($job['account_id']); |
422 | 421 | $GLOBALS['egw']->session->account_domain = $domain; |
423 | - $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
422 | + $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
424 | 423 | |
425 | 424 | if ($lang != $GLOBALS['egw_info']['user']['preferences']['common']['lang']) |
426 | 425 | { |
@@ -435,12 +434,11 @@ discard block |
||
435 | 434 | $GLOBALS['egw_info']['user']['domain'] = $domain; |
436 | 435 | } |
437 | 436 | } |
438 | - list($app) = strpos($job['method'],'::') !== false ? explode('_',$job['method']) : |
|
439 | - explode('.',$job['method']); |
|
437 | + list($app) = strpos($job['method'], '::') !== false ? explode('_', $job['method']) : explode('.', $job['method']); |
|
440 | 438 | Translation::add_app($app); |
441 | 439 | if (is_array($job['data'])) |
442 | 440 | { |
443 | - $job['data'] += array_diff_key($job,array('data' => false)); |
|
441 | + $job['data'] += array_diff_key($job, array('data' => false)); |
|
444 | 442 | } |
445 | 443 | // update job before running it, to cope with jobs taking longer then async-frequency |
446 | 444 | if (($job['next'] = $this->next_run($job['times']))) |
@@ -453,16 +451,16 @@ discard block |
||
453 | 451 | } |
454 | 452 | try |
455 | 453 | { |
456 | - ExecMethod($job['method'],$job['data']); |
|
454 | + ExecMethod($job['method'], $job['data']); |
|
457 | 455 | } |
458 | - catch(Exception $e) |
|
456 | + catch (Exception $e) |
|
459 | 457 | { |
460 | 458 | // log the exception to error_log, but continue running other async jobs |
461 | 459 | _egw_log_exception($e); |
462 | 460 | } |
463 | 461 | } |
464 | 462 | } |
465 | - $this->last_check_run(True,True,$run_by); // release semaphore |
|
463 | + $this->last_check_run(True, True, $run_by); // release semaphore |
|
466 | 464 | |
467 | 465 | return $jobs ? count($jobs) : 0; |
468 | 466 | } |
@@ -478,7 +476,7 @@ discard block |
||
478 | 476 | * @param int $num_rows =0 number of rows to return if offset set, default 0 = use default in user prefs |
479 | 477 | * @return array/boolean db-rows / jobs as array or False if no matches |
480 | 478 | */ |
481 | - function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
|
479 | + function read($id = 0, $cols = '*', $offset = False, $append = 'ORDER BY async_next', $num_rows = 0) |
|
482 | 480 | { |
483 | 481 | if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false; |
484 | 482 | |
@@ -486,7 +484,7 @@ discard block |
||
486 | 484 | { |
487 | 485 | $where = "async_id != '##last-check-run##'"; |
488 | 486 | } |
489 | - elseif (!is_array($id) && (strpos($id,'%') !== False || strpos($id,'_') !== False)) |
|
487 | + elseif (!is_array($id) && (strpos($id, '%') !== False || strpos($id, '_') !== False)) |
|
490 | 488 | { |
491 | 489 | $id = $this->db->quote($id); |
492 | 490 | $where = "async_id LIKE $id AND async_id != '##last-check-run##'"; |
@@ -500,21 +498,21 @@ discard block |
||
500 | 498 | $where = array('async_id' => $id); |
501 | 499 | } |
502 | 500 | $jobs = array(); |
503 | - foreach($this->db->select($this->db_table,$cols,$where,__LINE__,__FILE__,$offset,$append,False,$num_rows) as $row) |
|
501 | + foreach ($this->db->select($this->db_table, $cols, $where, __LINE__, __FILE__, $offset, $append, False, $num_rows) as $row) |
|
504 | 502 | { |
505 | 503 | $row['async_times'] = json_php_unserialize($row['async_times']); |
506 | 504 | // check for broken value during migration |
507 | 505 | if ($row['async_data'][0] == '"' && substr($row['async_data'], 0, 7) == '"\\"\\\\\\"') |
508 | 506 | { |
509 | 507 | $row['async_data'] = null; |
510 | - $this->write(Db::strip_array_keys($row,'async_'), true); |
|
508 | + $this->write(Db::strip_array_keys($row, 'async_'), true); |
|
511 | 509 | } |
512 | 510 | else |
513 | 511 | { |
514 | 512 | $row['async_data'] = !empty($row['async_data']) ? |
515 | - json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
513 | + json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
516 | 514 | } |
517 | - $jobs[$row['async_id']] = Db::strip_array_keys($row,'async_'); |
|
515 | + $jobs[$row['async_id']] = Db::strip_array_keys($row, 'async_'); |
|
518 | 516 | } |
519 | 517 | if (!count($jobs)) |
520 | 518 | { |
@@ -531,7 +529,7 @@ discard block |
||
531 | 529 | * @param array $where additional where statemetn to update only if a certain condition is met, used for the semaphore |
532 | 530 | * @return int affected rows, can be 0 if an additional where statement is given |
533 | 531 | */ |
534 | - function write($job, $exists = False, $where=array()) |
|
532 | + function write($job, $exists = False, $where = array()) |
|
535 | 533 | { |
536 | 534 | if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0; |
537 | 535 | |
@@ -562,7 +560,7 @@ discard block |
||
562 | 560 | */ |
563 | 561 | function delete($id) |
564 | 562 | { |
565 | - $this->db->delete($this->db_table,array('async_id' => $id),__LINE__,__FILE__); |
|
563 | + $this->db->delete($this->db_table, array('async_id' => $id), __LINE__, __FILE__); |
|
566 | 564 | |
567 | 565 | return $this->db->affected_rows(); |
568 | 566 | } |
@@ -587,38 +585,38 @@ discard block |
||
587 | 585 | { |
588 | 586 | $binarys = array( |
589 | 587 | 'php' => '/usr/bin/php', |
590 | - 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
588 | + 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
591 | 589 | 'crontab' => '/usr/bin/crontab' |
592 | 590 | ); |
593 | 591 | foreach ($binarys as $name => $path) |
594 | 592 | { |
595 | - $this->$name = $path; // a reasonable default for *nix |
|
593 | + $this->$name = $path; // a reasonable default for *nix |
|
596 | 594 | |
597 | 595 | if (!($Ok = @is_executable($this->$name))) |
598 | 596 | { |
599 | 597 | if (file_exists($this->$name)) |
600 | 598 | { |
601 | - echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
|
599 | + echo '<p>'.lang('%1 is not executable by the webserver !!!', $this->$name)."</p>\n"; |
|
602 | 600 | $perms = fileperms($this->$name); |
603 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
601 | + if (!($perms&0x0001) && ($perms&0x0008) && function_exists('posix_getuid')) // only executable by group |
|
604 | 602 | { |
605 | 603 | $group = posix_getgrgid(filegroup($this->$name)); |
606 | - $webserver = posix_getpwuid(posix_getuid ()); |
|
607 | - echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
|
604 | + $webserver = posix_getpwuid(posix_getuid()); |
|
605 | + echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.", $webserver['name'], $group['name'])."</p>\n"; } |
|
608 | 606 | } |
609 | - if (($fd = popen('/bin/sh -c "type -p '.$name.'"','r'))) |
|
607 | + if (($fd = popen('/bin/sh -c "type -p '.$name.'"', 'r'))) |
|
610 | 608 | { |
611 | - $this->$name = fgets($fd,256); |
|
609 | + $this->$name = fgets($fd, 256); |
|
612 | 610 | @pclose($fd); |
613 | 611 | } |
614 | - if (($pos = strpos($this->$name,"\n"))) |
|
612 | + if (($pos = strpos($this->$name, "\n"))) |
|
615 | 613 | { |
616 | - $this->$name = substr($this->$name,0,$pos); |
|
614 | + $this->$name = substr($this->$name, 0, $pos); |
|
617 | 615 | } |
618 | 616 | } |
619 | 617 | if (!$Ok && !@is_executable($this->$name)) |
620 | 618 | { |
621 | - $this->$name = $name; // hopefully its in the path |
|
619 | + $this->$name = $name; // hopefully its in the path |
|
622 | 620 | } |
623 | 621 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
624 | 622 | } |
@@ -649,15 +647,15 @@ discard block |
||
649 | 647 | } |
650 | 648 | $times = False; |
651 | 649 | $this->other_cronlines = array(); |
652 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1','r')) !== False) |
|
650 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1', 'r')) !== False) |
|
653 | 651 | { |
654 | 652 | $n = 0; |
655 | - while ($line = fgets($crontab,256)) |
|
653 | + while ($line = fgets($crontab, 256)) |
|
656 | 654 | { |
657 | 655 | if ($this->debug) echo 'line '.++$n.": $line<br>\n"; |
658 | - $parts = explode(' ',$line,6); |
|
656 | + $parts = explode(' ', $line, 6); |
|
659 | 657 | |
660 | - if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
|
658 | + if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5], 0, 3) != 'php')) |
|
661 | 659 | { |
662 | 660 | // ignore comments |
663 | 661 | if ($line{0} != '#') |
@@ -665,12 +663,12 @@ discard block |
||
665 | 663 | $times['error'] .= $line; |
666 | 664 | } |
667 | 665 | } |
668 | - elseif (strpos($line,$this->cronline) !== False || |
|
666 | + elseif (strpos($line, $this->cronline) !== False || |
|
669 | 667 | // also check of old phpgwapi/cron path |
670 | 668 | strpos($line, str_replace('/api/', '/phpgwapi/cron/', $this->cronline)) !== False) |
671 | 669 | { |
672 | - $cron_units = array('min','hour','day','month','dow'); |
|
673 | - foreach($cron_units as $n => $u) |
|
670 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
671 | + foreach ($cron_units as $n => $u) |
|
674 | 672 | { |
675 | 673 | $times[$u] = $parts[$n]; |
676 | 674 | } |
@@ -701,29 +699,29 @@ discard block |
||
701 | 699 | if ($this->only_fallback && $times !== False) { |
702 | 700 | return 0; |
703 | 701 | } |
704 | - $this->installed(); // find other installed cronlines |
|
702 | + $this->installed(); // find other installed cronlines |
|
705 | 703 | |
706 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1','w')) !== False) |
|
704 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1', 'w')) !== False) |
|
707 | 705 | { |
708 | 706 | if (is_array($this->other_cronlines)) |
709 | 707 | { |
710 | 708 | foreach ($this->other_cronlines as $cronline) |
711 | 709 | { |
712 | - fwrite($crontab,$cronline); // preserv the other lines on install |
|
710 | + fwrite($crontab, $cronline); // preserv the other lines on install |
|
713 | 711 | } |
714 | 712 | } |
715 | 713 | if ($times !== False) |
716 | 714 | { |
717 | - $cron_units = array('min','hour','day','month','dow'); |
|
715 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
718 | 716 | $cronline = ''; |
719 | - foreach($cron_units as $cu) |
|
717 | + foreach ($cron_units as $cu) |
|
720 | 718 | { |
721 | - $cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' '; |
|
719 | + $cronline .= (isset($times[$cu]) ? $times[$cu] : '*').' '; |
|
722 | 720 | } |
723 | 721 | // -d memory_limit=-1 --> no memory limit |
724 | 722 | $cronline .= $this->php.' -q -d memory_limit=-1 '.$this->cronline."\n"; |
725 | 723 | //echo "<p>Installing: '$cronline'</p>\n"; |
726 | - fwrite($crontab,$cronline); |
|
724 | + fwrite($crontab, $cronline); |
|
727 | 725 | } |
728 | 726 | @pclose($crontab); |
729 | 727 | } |
@@ -114,7 +114,8 @@ discard block |
||
114 | 114 | echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n"; |
115 | 115 | $debug = True; // enable syntax-error messages too |
116 | 116 | } |
117 | - if(is_null($now)) { |
|
117 | + if(is_null($now)) |
|
118 | + { |
|
118 | 119 | $now = time(); |
119 | 120 | } |
120 | 121 | |
@@ -179,12 +180,17 @@ discard block |
||
179 | 180 | foreach($units as $u => $date_pattern) |
180 | 181 | { |
181 | 182 | ++$n; |
182 | - if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
183 | + if ($this->debug) |
|
184 | + { |
|
185 | +echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
183 | 186 | if (isset($times[$u])) |
184 | 187 | { |
185 | - if(is_array($times[$u])) { |
|
188 | + if(is_array($times[$u])) |
|
189 | + { |
|
186 | 190 | $time = array_keys($times[$u]); |
187 | - } else { |
|
191 | + } |
|
192 | + else |
|
193 | + { |
|
188 | 194 | $time = explode(',',$times[$u]); |
189 | 195 | } |
190 | 196 | $times[$u] = array(); |
@@ -197,7 +203,10 @@ discard block |
||
197 | 203 | |
198 | 204 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
199 | 205 | { |
200 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
206 | + if ($debug) |
|
207 | + { |
|
208 | + echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
209 | + } |
|
201 | 210 | |
202 | 211 | return False; |
203 | 212 | } |
@@ -208,14 +217,20 @@ discard block |
||
208 | 217 | } |
209 | 218 | else |
210 | 219 | { |
211 | - if ((string)$t == '*') $t = '*/1'; |
|
220 | + if ((string)$t == '*') |
|
221 | + { |
|
222 | + $t = '*/1'; |
|
223 | + } |
|
212 | 224 | |
213 | 225 | list($one,$inc) = $arr = explode('/',$t); |
214 | 226 | |
215 | 227 | if (!(is_numeric($one) && count($arr) == 1 || |
216 | 228 | count($arr) == 2 && is_numeric($inc))) |
217 | 229 | { |
218 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
230 | + if ($debug) |
|
231 | + { |
|
232 | + echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
233 | + } |
|
219 | 234 | |
220 | 235 | return False; |
221 | 236 | } |
@@ -233,7 +248,10 @@ discard block |
||
233 | 248 | } |
234 | 249 | elseif (count($arr) != 2 || $min > $max) |
235 | 250 | { |
236 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
251 | + if ($debug) |
|
252 | + { |
|
253 | + echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
254 | + } |
|
237 | 255 | return False; |
238 | 256 | } |
239 | 257 | for ($i = $min; $i <= $max; $i += $inc) |
@@ -244,9 +262,13 @@ discard block |
||
244 | 262 | } |
245 | 263 | } |
246 | 264 | } |
247 | - elseif ($n < $last_set || $u == 'dow') // before last value set (or dow) => empty gets enumerated |
|
265 | + elseif ($n < $last_set || $u == 'dow') |
|
266 | + { |
|
267 | + // before last value set (or dow) => empty gets enumerated |
|
248 | 268 | { |
249 | - for ($i = $min_unit[$u]; $i <= $max_unit[$u]; ++$i) |
|
269 | + for ($i = $min_unit[$u]; |
|
270 | + } |
|
271 | + $i <= $max_unit[$u]; ++$i) |
|
250 | 272 | { |
251 | 273 | $times[$u][$i] = True; |
252 | 274 | } |
@@ -256,7 +278,9 @@ discard block |
||
256 | 278 | $times[$u][$min_unit[$u]] = True; |
257 | 279 | } |
258 | 280 | } |
259 | - if ($this->debug) { echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
281 | + if ($this->debug) |
|
282 | + { |
|
283 | +echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
260 | 284 | |
261 | 285 | // now we have the times enumerated, lets find the first not expired one |
262 | 286 | // |
@@ -274,7 +298,10 @@ discard block |
||
274 | 298 | if (isset($found[$u])) |
275 | 299 | { |
276 | 300 | $future = $future || $found[$u] > $unit_now; |
277 | - if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
301 | + if ($this->debug) |
|
302 | + { |
|
303 | + echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
304 | + } |
|
278 | 305 | continue; // already set |
279 | 306 | } |
280 | 307 | foreach(array_keys($times[$u]) as $unit_value) |
@@ -292,30 +319,44 @@ discard block |
||
292 | 319 | break; |
293 | 320 | |
294 | 321 | } |
295 | - if ($valid && ($u != $next || $unit_value > $over)) // valid and not over |
|
322 | + if ($valid && ($u != $next || $unit_value > $over)) |
|
323 | + { |
|
324 | + // valid and not over |
|
296 | 325 | { |
297 | 326 | $found[$u] = $unit_value; |
327 | + } |
|
298 | 328 | $future = $future || $unit_value > $unit_now; |
299 | 329 | break; |
300 | 330 | } |
301 | 331 | } |
302 | - if (!isset($found[$u])) // we have to try the next one, if it exists |
|
332 | + if (!isset($found[$u])) |
|
333 | + { |
|
334 | + // we have to try the next one, if it exists |
|
303 | 335 | { |
304 | 336 | $nexts = array_keys($units); |
337 | + } |
|
305 | 338 | if (!isset($nexts[count($found)-1])) |
306 | 339 | { |
307 | - if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n"; |
|
340 | + if ($this->debug) |
|
341 | + { |
|
342 | + echo "<p>Nothing found, exiting !!!</p>\n"; |
|
343 | + } |
|
308 | 344 | return False; |
309 | 345 | } |
310 | 346 | $next = $nexts[count($found)-1]; |
311 | 347 | $over = $found[$next]; |
312 | 348 | unset($found[$next]); |
313 | - if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
349 | + if ($this->debug) |
|
350 | + { |
|
351 | + echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
352 | + } |
|
314 | 353 | break; |
315 | 354 | } |
316 | 355 | } |
317 | 356 | } |
318 | - if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
357 | + if ($this->debug) |
|
358 | + { |
|
359 | +echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
319 | 360 | |
320 | 361 | return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
321 | 362 | } |
@@ -377,7 +418,10 @@ discard block |
||
377 | 418 | ); |
378 | 419 | // as the async_next column is used as a semaphore we only update it, |
379 | 420 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
380 | - if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
421 | + if ($exists) |
|
422 | + { |
|
423 | + $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
424 | + } |
|
381 | 425 | } |
382 | 426 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
383 | 427 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -388,7 +432,10 @@ discard block |
||
388 | 432 | */ |
389 | 433 | function check_run($run_by='') |
390 | 434 | { |
391 | - if ($run_by === 'fallback') flush(); |
|
435 | + if ($run_by === 'fallback') |
|
436 | + { |
|
437 | + flush(); |
|
438 | + } |
|
392 | 439 | |
393 | 440 | if (!$this->last_check_run(True,False,$run_by)) |
394 | 441 | { |
@@ -410,7 +457,10 @@ discard block |
||
410 | 457 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
411 | 458 | foreach($GLOBALS as $name => $value) |
412 | 459 | { |
413 | - if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
|
460 | + if ($name !== 'egw' && is_object($value)) |
|
461 | + { |
|
462 | + unset($GLOBALS[$name]); |
|
463 | + } |
|
414 | 464 | } |
415 | 465 | $domain = $GLOBALS['egw_info']['user']['domain']; |
416 | 466 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
@@ -480,7 +530,10 @@ discard block |
||
480 | 530 | */ |
481 | 531 | function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
482 | 532 | { |
483 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false; |
|
533 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
534 | + { |
|
535 | + return false; |
|
536 | + } |
|
484 | 537 | |
485 | 538 | if ($id === '%') |
486 | 539 | { |
@@ -533,9 +586,15 @@ discard block |
||
533 | 586 | */ |
534 | 587 | function write($job, $exists = False, $where=array()) |
535 | 588 | { |
536 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0; |
|
589 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
590 | + { |
|
591 | + return 0; |
|
592 | + } |
|
537 | 593 | |
538 | - if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) $job['data']['next'] = $job['next']; |
|
594 | + if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) |
|
595 | + { |
|
596 | + $job['data']['next'] = $job['next']; |
|
597 | + } |
|
539 | 598 | $data = array( |
540 | 599 | 'async_next' => $job['next'], |
541 | 600 | 'async_times' => json_encode($job['times']), |
@@ -600,9 +659,12 @@ discard block |
||
600 | 659 | { |
601 | 660 | echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
602 | 661 | $perms = fileperms($this->$name); |
603 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
662 | + if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) |
|
663 | + { |
|
664 | + // only executable by group |
|
604 | 665 | { |
605 | 666 | $group = posix_getgrgid(filegroup($this->$name)); |
667 | + } |
|
606 | 668 | $webserver = posix_getpwuid(posix_getuid ()); |
607 | 669 | echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
608 | 670 | } |
@@ -622,10 +684,13 @@ discard block |
||
622 | 684 | } |
623 | 685 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
624 | 686 | } |
625 | - if ($this->php5[0] == '/') // we found a php5 binary |
|
687 | + if ($this->php5[0] == '/') |
|
688 | + { |
|
689 | + // we found a php5 binary |
|
626 | 690 | { |
627 | 691 | $this->php = $this->php5; |
628 | 692 | } |
693 | + } |
|
629 | 694 | } |
630 | 695 | } |
631 | 696 | |
@@ -637,7 +702,8 @@ discard block |
||
637 | 702 | */ |
638 | 703 | function installed() |
639 | 704 | { |
640 | - if ($this->only_fallback) { |
|
705 | + if ($this->only_fallback) |
|
706 | + { |
|
641 | 707 | return 0; |
642 | 708 | } |
643 | 709 | $this->find_binarys(); |
@@ -654,7 +720,10 @@ discard block |
||
654 | 720 | $n = 0; |
655 | 721 | while ($line = fgets($crontab,256)) |
656 | 722 | { |
657 | - if ($this->debug) echo 'line '.++$n.": $line<br>\n"; |
|
723 | + if ($this->debug) |
|
724 | + { |
|
725 | + echo 'line '.++$n.": $line<br>\n"; |
|
726 | + } |
|
658 | 727 | $parts = explode(' ',$line,6); |
659 | 728 | |
660 | 729 | if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
@@ -698,7 +767,8 @@ discard block |
||
698 | 767 | */ |
699 | 768 | function install($times) |
700 | 769 | { |
701 | - if ($this->only_fallback && $times !== False) { |
|
770 | + if ($this->only_fallback && $times !== False) |
|
771 | + { |
|
702 | 772 | return 0; |
703 | 773 | } |
704 | 774 | $this->installed(); // find other installed cronlines |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * check if users are supposed to change their password every x sdays, then check if password is of old age |
85 | 85 | * or the devil-admin reset the users password and forced the user to change his password on next login. |
86 | 86 | * |
87 | - * @param string& $message =null on return false: message why password needs to be changed |
|
88 | - * @return boolean true: all good, false: password change required, null: password expires in N days |
|
87 | + * @param string $message =null on return false: message why password needs to be changed |
|
88 | + * @return boolean|null true: all good, false: password change required, null: password expires in N days |
|
89 | 89 | */ |
90 | 90 | static function check_password_change(&$message=null) |
91 | 91 | { |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * |
295 | 295 | * uses the encryption type set in setup and calls the appropriate encryption functions |
296 | 296 | * |
297 | - * @param $password password to encrypt |
|
297 | + * @param string $password password to encrypt |
|
298 | 298 | */ |
299 | 299 | static function encrypt_password($password,$sql=False) |
300 | 300 | { |
@@ -406,6 +406,7 @@ discard block |
||
406 | 406 | * @param string $form_val user input value for comparison |
407 | 407 | * @param string $db_val stored value / hash (from database) |
408 | 408 | * @param string &$type detected crypt type on return |
409 | + * @param string $type |
|
409 | 410 | * @return boolean True on successful comparison |
410 | 411 | */ |
411 | 412 | static function crypt_compare($form_val, $db_val, &$type) |
@@ -618,7 +619,7 @@ discard block |
||
618 | 619 | * @param string $forbid_name =null if "yes" username or full-name split by delimiters AND longer then 3 chars are |
619 | 620 | * forbidden to be included in password, default to whatever set in config for "passwd_forbid_name" |
620 | 621 | * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check |
621 | - * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
|
622 | + * @return string|false false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
|
622 | 623 | */ |
623 | 624 | static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
624 | 625 | { |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * @param string $db_val stored value / hash (from database) |
408 | 408 | * @param string &$type detected crypt type on return |
409 | 409 | * @return boolean True on successful comparison |
410 | - */ |
|
410 | + */ |
|
411 | 411 | static function crypt_compare($form_val, $db_val, &$type) |
412 | 412 | { |
413 | 413 | // detect type of hash by salt part of $db_val |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | * @param string $form_val user input value for comparison |
707 | 707 | * @param string $db_val stored value (from database) |
708 | 708 | * @return boolean True on successful comparison |
709 | - */ |
|
709 | + */ |
|
710 | 710 | static function smd5_compare($form_val,$db_val) |
711 | 711 | { |
712 | 712 | /* Start with the first char after {SMD5} */ |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | * @param string $form_val user input value for comparison |
729 | 729 | * @param string $db_val stored value (from database) |
730 | 730 | * @return boolean True on successful comparison |
731 | - */ |
|
731 | + */ |
|
732 | 732 | static function sha_compare($form_val,$db_val) |
733 | 733 | { |
734 | 734 | /* Start with the first char after {SHA} */ |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | * @param string $form_val user input value for comparison |
746 | 746 | * @param string $db_val stored value (from database) |
747 | 747 | * @return boolean True on successful comparison |
748 | - */ |
|
748 | + */ |
|
749 | 749 | static function ssha_compare($form_val,$db_val) |
750 | 750 | { |
751 | 751 | /* Start with the first char after {SSHA} */ |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | { |
21 | 21 | $GLOBALS['egw_info']['server']['auth_type'] = $GLOBALS['egw_info']['server']['auth_type_'.$GLOBALS['egw_info']['flags']['currentapp']]; |
22 | 22 | } |
23 | -if(empty($GLOBALS['egw_info']['server']['auth_type'])) |
|
23 | +if (empty($GLOBALS['egw_info']['server']['auth_type'])) |
|
24 | 24 | { |
25 | 25 | $GLOBALS['egw_info']['server']['auth_type'] = 'sql'; |
26 | 26 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @param Backend $type =null |
62 | 62 | */ |
63 | - static function backend($type=null) |
|
63 | + static function backend($type = null) |
|
64 | 64 | { |
65 | 65 | if (is_null($type)) $type = $GLOBALS['egw_info']['server']['auth_type']; |
66 | 66 | |
@@ -87,29 +87,29 @@ discard block |
||
87 | 87 | * @param string& $message =null on return false: message why password needs to be changed |
88 | 88 | * @return boolean true: all good, false: password change required, null: password expires in N days |
89 | 89 | */ |
90 | - static function check_password_change(&$message=null) |
|
90 | + static function check_password_change(&$message = null) |
|
91 | 91 | { |
92 | 92 | // dont check anything for anonymous sessions/ users that are flagged as anonymous |
93 | 93 | if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true; |
94 | 94 | |
95 | 95 | // some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request |
96 | 96 | // if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed |
97 | - static $UserKnowsAboutPwdChange=null; |
|
98 | - if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
97 | + static $UserKnowsAboutPwdChange = null; |
|
98 | + if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange = & Cache::getSession('phpgwapi', 'auth_UserKnowsAboutPwdChange'); |
|
99 | 99 | |
100 | 100 | // retrieve the timestamp regarding the last change of the password from auth system and store it with the session |
101 | - static $alpwchange_val=null; |
|
102 | - static $pwdTsChecked=null; |
|
101 | + static $alpwchange_val = null; |
|
102 | + static $pwdTsChecked = null; |
|
103 | 103 | if (is_null($pwdTsChecked) && is_null($alpwchange_val) || (string)$alpwchange_val === '0') |
104 | 104 | { |
105 | - $alpwchange_val =& Cache::getSession('phpgwapi','auth_alpwchange_val'); // set that one with the session stored value |
|
105 | + $alpwchange_val = & Cache::getSession('phpgwapi', 'auth_alpwchange_val'); // set that one with the session stored value |
|
106 | 106 | // initalize statics - better readability of conditions |
107 | 107 | if (is_null($alpwchange_val) || (string)$alpwchange_val === '0') |
108 | 108 | { |
109 | 109 | $backend = self::backend(); |
110 | 110 | // this may change behavior, as it should detect forced PasswordChanges from your Authentication System too. |
111 | 111 | // on the other side, if your auth system does not require an forcedPasswordChange, you will not be asked. |
112 | - if (method_exists($backend,'getLastPwdChange')) |
|
112 | + if (method_exists($backend, 'getLastPwdChange')) |
|
113 | 113 | { |
114 | 114 | $alpwchange_val = $backend->getLastPwdChange($GLOBALS['egw']->session->account_lid); |
115 | 115 | $pwdTsChecked = true; |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | //error_log(__METHOD__.__LINE__.'#'.$alpwchange_val.'# is null:'.is_null($alpwchange_val).'# is empty:'.empty($alpwchange_val).'# is set:'.isset($alpwchange_val)); |
124 | 124 | } |
125 | 125 | } |
126 | - static $passwordAgeBorder=null; |
|
127 | - static $daysLeftUntilChangeReq=null; |
|
126 | + static $passwordAgeBorder = null; |
|
127 | + static $daysLeftUntilChangeReq = null; |
|
128 | 128 | |
129 | 129 | // if neither timestamp isset return true, nothing to do (exept this means the password is too old) |
130 | 130 | if (is_null($alpwchange_val) && |
@@ -134,15 +134,15 @@ discard block |
||
134 | 134 | } |
135 | 135 | if (is_null($passwordAgeBorder) && $GLOBALS['egw_info']['server']['change_pwd_every_x_days']) |
136 | 136 | { |
137 | - $passwordAgeBorder = (DateTime::to('now','ts')-($GLOBALS['egw_info']['server']['change_pwd_every_x_days']*86400)); |
|
137 | + $passwordAgeBorder = (DateTime::to('now', 'ts') - ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] * 86400)); |
|
138 | 138 | } |
139 | 139 | if (is_null($daysLeftUntilChangeReq) && $GLOBALS['egw_info']['server']['warn_about_upcoming_pwd_change']) |
140 | 140 | { |
141 | 141 | // maxage - passwordage = days left until change is required |
142 | - $daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((DateTime::to('now','ts')-($alpwchange_val?$alpwchange_val:0))/86400)); |
|
142 | + $daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((DateTime::to('now', 'ts') - ($alpwchange_val ? $alpwchange_val : 0)) / 86400)); |
|
143 | 143 | } |
144 | - if ($alpwchange_val == 0 || // admin requested password change |
|
145 | - $passwordAgeBorder > $alpwchange_val || // change password every N days policy requests change |
|
144 | + if ($alpwchange_val == 0 || // admin requested password change |
|
145 | + $passwordAgeBorder > $alpwchange_val || // change password every N days policy requests change |
|
146 | 146 | // user should be warned N days in advance about change and is not yet |
147 | 147 | $GLOBALS['egw_info']['server']['change_pwd_every_x_days'] && |
148 | 148 | $GLOBALS['egw_info']['user']['apps']['preferences'] && |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | error_log(__METHOD__.' Password of '.$GLOBALS['egw_info']['user']['account_lid'].' ('.$GLOBALS['egw_info']['user']['account_fullname'].') is of old age.'.array2string(array( |
160 | 160 | 'ts'=> $alpwchange_val, |
161 | 161 | 'date'=>DateTime::to($alpwchange_val)))); |
162 | - $message = lang('It has been more then %1 days since you changed your password',$GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
162 | + $message = lang('It has been more then %1 days since you changed your password', $GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
163 | 163 | } |
164 | 164 | else |
165 | 165 | { |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | { |
171 | 171 | $UserKnowsAboutPwdChange = true; |
172 | 172 | } |
173 | - $message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq)); |
|
173 | + $message = lang('Your password is about to expire in %1 days, you may change your password now', round($daysLeftUntilChangeReq)); |
|
174 | 174 | // user has no rights to change password --> do NOT warn, as only forced check ignores rights |
175 | 175 | if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true; |
176 | 176 | return null; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | function getLastPwdChange($username) |
190 | 190 | { |
191 | - if (method_exists($this->backend,'getLastPwdChange')) |
|
191 | + if (method_exists($this->backend, 'getLastPwdChange')) |
|
192 | 192 | { |
193 | 193 | return $this->backend->getLastPwdChange($username); |
194 | 194 | } |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | * @param int $lastpwdchange must be a unixtimestamp |
204 | 204 | * @return boolean true if account_lastpwd_change successful changed, false otherwise |
205 | 205 | */ |
206 | - function setLastPwdChange($account_id=0, $passwd=NULL, $lastpwdchange=NULL) |
|
206 | + function setLastPwdChange($account_id = 0, $passwd = NULL, $lastpwdchange = NULL) |
|
207 | 207 | { |
208 | - if (method_exists($this->backend,'setLastPwdChange')) |
|
208 | + if (method_exists($this->backend, 'setLastPwdChange')) |
|
209 | 209 | { |
210 | 210 | return $this->backend->setLastPwdChange($account_id, $passwd, $lastpwdchange); |
211 | 211 | } |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param string $passwd_type ='text' 'text' for cleartext passwords (default) |
221 | 221 | * @return boolean true if successful authenticated, false otherwise |
222 | 222 | */ |
223 | - function authenticate($username, $passwd, $passwd_type='text') |
|
223 | + function authenticate($username, $passwd, $passwd_type = 'text') |
|
224 | 224 | { |
225 | 225 | return $this->backend->authenticate($username, $passwd, $passwd_type); |
226 | 226 | } |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | * @throws Exception from backends having extra requirements |
236 | 236 | * @return boolean true if password successful changed, false otherwise |
237 | 237 | */ |
238 | - function change_password($old_passwd, $new_passwd, $account_id=0) |
|
238 | + function change_password($old_passwd, $new_passwd, $account_id = 0) |
|
239 | 239 | { |
240 | - if (($err = self::crackcheck($new_passwd,null,null,null,$account_id))) |
|
240 | + if (($err = self::crackcheck($new_passwd, null, null, null, $account_id))) |
|
241 | 241 | { |
242 | 242 | throw new Exception\WrongUserinput($err); |
243 | 243 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | // need to change current users password in session |
249 | 249 | Cache::setSession('phpgwapi', 'password', base64_encode($new_passwd)); |
250 | 250 | $GLOBALS['egw_info']['user']['passwd'] = $new_passwd; |
251 | - $GLOBALS['egw_info']['user']['account_lastpwd_change'] = DateTime::to('now','ts'); |
|
251 | + $GLOBALS['egw_info']['user']['account_lastpwd_change'] = DateTime::to('now', 'ts'); |
|
252 | 252 | // invalidate EGroupware session, as password is stored in egw_info in session |
253 | 253 | Egw::invalidate_session_cache(); |
254 | 254 | } |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | 'old_passwd' => $old_passwd, |
261 | 261 | 'new_passwd' => $new_passwd, |
262 | 262 | ); |
263 | - Hooks::process($GLOBALS['hook_values']+array( |
|
263 | + Hooks::process($GLOBALS['hook_values'] + array( |
|
264 | 264 | 'location' => 'changepassword' |
265 | - ),False,True); // called for every app now, not only enabled ones) |
|
265 | + ), False, True); // called for every app now, not only enabled ones) |
|
266 | 266 | } |
267 | 267 | return $ret; |
268 | 268 | } |
@@ -275,16 +275,16 @@ discard block |
||
275 | 275 | static function randomstring($size) |
276 | 276 | { |
277 | 277 | static $random_char = array( |
278 | - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', |
|
279 | - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', |
|
280 | - 'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L', |
|
281 | - 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' |
|
278 | + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', |
|
279 | + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', |
|
280 | + 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', |
|
281 | + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' |
|
282 | 282 | ); |
283 | 283 | |
284 | 284 | $s = ''; |
285 | - for ($i=0; $i<$size; $i++) |
|
285 | + for ($i = 0; $i < $size; $i++) |
|
286 | 286 | { |
287 | - $s .= $random_char[mt_rand(1,61)]; |
|
287 | + $s .= $random_char[mt_rand(1, 61)]; |
|
288 | 288 | } |
289 | 289 | return $s; |
290 | 290 | } |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @param $password password to encrypt |
298 | 298 | */ |
299 | - static function encrypt_password($password,$sql=False) |
|
299 | + static function encrypt_password($password, $sql = False) |
|
300 | 300 | { |
301 | - if($sql) |
|
301 | + if ($sql) |
|
302 | 302 | { |
303 | 303 | return self::encrypt_sql($password); |
304 | 304 | } |
@@ -317,21 +317,21 @@ discard block |
||
317 | 317 | * @param string &$type =null on return detected type of hash |
318 | 318 | * @return boolean |
319 | 319 | */ |
320 | - static function compare_password($cleartext, $encrypted, $type_in, $username='', &$type=null) |
|
320 | + static function compare_password($cleartext, $encrypted, $type_in, $username = '', &$type = null) |
|
321 | 321 | { |
322 | 322 | // allow to specify the hash type to prefix the hash, to easy migrate passwords from ldap |
323 | 323 | $type = $type_in; |
324 | 324 | $saved_enc = $encrypted; |
325 | 325 | $matches = null; |
326 | - if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i',$encrypted,$matches)) |
|
326 | + if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i', $encrypted, $matches)) |
|
327 | 327 | { |
328 | 328 | $type = strtolower($matches[1]); |
329 | 329 | $encrypted = $matches[2]; |
330 | 330 | |
331 | - switch($type) // some hashs are specially "packed" in ldap |
|
331 | + switch ($type) // some hashs are specially "packed" in ldap |
|
332 | 332 | { |
333 | 333 | case 'md5': |
334 | - $encrypted = implode('',unpack('H*',base64_decode($encrypted))); |
|
334 | + $encrypted = implode('', unpack('H*', base64_decode($encrypted))); |
|
335 | 335 | break; |
336 | 336 | case 'plain': |
337 | 337 | case 'crypt': |
@@ -342,24 +342,24 @@ discard block |
||
342 | 342 | break; |
343 | 343 | } |
344 | 344 | } |
345 | - elseif($encrypted[0] == '$') |
|
345 | + elseif ($encrypted[0] == '$') |
|
346 | 346 | { |
347 | 347 | $type = 'crypt'; |
348 | 348 | } |
349 | 349 | |
350 | - switch($type) |
|
350 | + switch ($type) |
|
351 | 351 | { |
352 | 352 | case 'plain': |
353 | 353 | $ret = $cleartext === $encrypted; |
354 | 354 | break; |
355 | 355 | case 'smd5': |
356 | - $ret = self::smd5_compare($cleartext,$encrypted); |
|
356 | + $ret = self::smd5_compare($cleartext, $encrypted); |
|
357 | 357 | break; |
358 | 358 | case 'sha': |
359 | - $ret = self::sha_compare($cleartext,$encrypted); |
|
359 | + $ret = self::sha_compare($cleartext, $encrypted); |
|
360 | 360 | break; |
361 | 361 | case 'ssha': |
362 | - $ret = self::ssha_compare($cleartext,$encrypted); |
|
362 | + $ret = self::ssha_compare($cleartext, $encrypted); |
|
363 | 363 | break; |
364 | 364 | case 'crypt': |
365 | 365 | case 'des': |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | $ret = self::crypt_compare($cleartext, $encrypted, $type); |
373 | 373 | break; |
374 | 374 | case 'md5_hmac': |
375 | - $ret = self::md5_hmac_compare($cleartext,$encrypted,$username); |
|
375 | + $ret = self::md5_hmac_compare($cleartext, $encrypted, $username); |
|
376 | 376 | break; |
377 | 377 | default: |
378 | 378 | $type = 'md5'; |
@@ -395,9 +395,9 @@ discard block |
||
395 | 395 | 'ext_crypt' => array('CRYPT_EXT_DES', '_J9..', 4, ''), |
396 | 396 | 'md5_crypt' => array('CRYPT_MD5', '$1$', 8, '$'), |
397 | 397 | //'old_blowfish_crypt' => array('CRYPT_BLOWFISH', '$2$', 13, ''), // old blowfish hash not in line with php.net docu, but could be in use |
398 | - 'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''), // $2a$12$ = 2^12 = 4096 rounds |
|
399 | - 'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
400 | - 'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
398 | + 'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''), // $2a$12$ = 2^12 = 4096 rounds |
|
399 | + 'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
400 | + 'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
401 | 401 | ); |
402 | 402 | |
403 | 403 | /** |
@@ -412,17 +412,17 @@ discard block |
||
412 | 412 | { |
413 | 413 | // detect type of hash by salt part of $db_val |
414 | 414 | list($first, $dollar, $salt, $salt2) = explode('$', $db_val); |
415 | - foreach(self::$crypt_params as $type => $params) |
|
415 | + foreach (self::$crypt_params as $type => $params) |
|
416 | 416 | { |
417 | 417 | list(,$prefix, $random, $postfix) = $params; |
418 | 418 | list(,$d) = explode('$', $prefix); |
419 | 419 | if ($dollar === $d || !$dollar && ($first[0] === $prefix[0] || $first[0] !== '_' && !$prefix)) |
420 | 420 | { |
421 | - $len = !$postfix ? strlen($prefix)+$random : strlen($prefix.$salt.$postfix); |
|
421 | + $len = !$postfix ? strlen($prefix) + $random : strlen($prefix.$salt.$postfix); |
|
422 | 422 | // sha(256|512) might contain options, explicit $rounds=N$ prefix in salt |
423 | 423 | if (($type == 'sha256_crypt' || $type == 'sha512_crypt') && substr($salt, 0, 7) === 'rounds=') |
424 | 424 | { |
425 | - $len += strlen($salt2)+1; |
|
425 | + $len += strlen($salt2) + 1; |
|
426 | 426 | } |
427 | 427 | break; |
428 | 428 | } |
@@ -444,12 +444,12 @@ discard block |
||
444 | 444 | * @param string $type =null default to $GLOBALS['egw_info']['server']['ldap_encryption_type'] |
445 | 445 | * @return string |
446 | 446 | */ |
447 | - static function encrypt_ldap($password, $type=null) |
|
447 | + static function encrypt_ldap($password, $type = null) |
|
448 | 448 | { |
449 | 449 | if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
450 | 450 | |
451 | 451 | $salt = ''; |
452 | - switch(strtolower($type)) |
|
452 | + switch (strtolower($type)) |
|
453 | 453 | { |
454 | 454 | default: // eg. setup >> config never saved |
455 | 455 | case 'des': |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | case 'md5_crypt': |
464 | 464 | case 'ext_crypt': |
465 | 465 | list($const, $prefix, $len, $postfix) = self::$crypt_params[$type]; |
466 | - if(defined($const) && constant($const) == 1) |
|
466 | + if (defined($const) && constant($const) == 1) |
|
467 | 467 | { |
468 | 468 | $salt = $prefix.self::randomstring($len).$postfix; |
469 | 469 | $e_password = '{crypt}'.crypt($password, $salt); |
@@ -476,20 +476,20 @@ discard block |
||
476 | 476 | /* New method taken from the openldap-software list as recommended by |
477 | 477 | * Kervin L. Pierre" <[email protected]> |
478 | 478 | */ |
479 | - $e_password = '{md5}' . base64_encode(pack("H*",md5($password))); |
|
479 | + $e_password = '{md5}'.base64_encode(pack("H*", md5($password))); |
|
480 | 480 | break; |
481 | 481 | case 'smd5': |
482 | 482 | $salt = self::randomstring(16); |
483 | - $hash = md5($password . $salt, true); |
|
484 | - $e_password = '{SMD5}' . base64_encode($hash . $salt); |
|
483 | + $hash = md5($password.$salt, true); |
|
484 | + $e_password = '{SMD5}'.base64_encode($hash.$salt); |
|
485 | 485 | break; |
486 | 486 | case 'sha': |
487 | - $e_password = '{SHA}' . base64_encode(sha1($password,true)); |
|
487 | + $e_password = '{SHA}'.base64_encode(sha1($password, true)); |
|
488 | 488 | break; |
489 | 489 | case 'ssha': |
490 | 490 | $salt = self::randomstring(16); |
491 | - $hash = sha1($password . $salt, true); |
|
492 | - $e_password = '{SSHA}' . base64_encode($hash . $salt); |
|
491 | + $hash = sha1($password.$salt, true); |
|
492 | + $e_password = '{SSHA}'.base64_encode($hash.$salt); |
|
493 | 493 | break; |
494 | 494 | case 'plain': |
495 | 495 | // if plain no type is prepended |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @param string $type =null default $GLOBALS['egw_info']['server']['sql_encryption_type'] |
508 | 508 | * @return string hash |
509 | 509 | */ |
510 | - static function encrypt_sql($password, $type=null) |
|
510 | + static function encrypt_sql($password, $type = null) |
|
511 | 511 | { |
512 | 512 | /* Grab configured type, or default to md5() (old method) */ |
513 | 513 | if (is_null($type)) |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | $type = @$GLOBALS['egw_info']['server']['sql_encryption_type'] ? |
516 | 516 | strtolower($GLOBALS['egw_info']['server']['sql_encryption_type']) : 'md5'; |
517 | 517 | } |
518 | - switch($type) |
|
518 | + switch ($type) |
|
519 | 519 | { |
520 | 520 | case 'plain': |
521 | 521 | // since md5 is the default, type plain must be prepended, for eGroupware to understand |
@@ -557,28 +557,28 @@ discard block |
||
557 | 557 | * @param string &$securest =null on return securest available hash |
558 | 558 | * @return array hash => label |
559 | 559 | */ |
560 | - public static function passwdhashes(&$securest=null) |
|
560 | + public static function passwdhashes(&$securest = null) |
|
561 | 561 | { |
562 | 562 | $hashes = array(); |
563 | 563 | |
564 | 564 | /* Check for available crypt methods based on what is defined by php */ |
565 | - if(defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) |
|
565 | + if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) |
|
566 | 566 | { |
567 | 567 | $hashes['blowfish_crypt'] = 'blowfish_crypt'; |
568 | 568 | } |
569 | - if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) |
|
569 | + if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) |
|
570 | 570 | { |
571 | 571 | $hashes['sha512_crypt'] = 'sha512_crypt'; |
572 | 572 | } |
573 | - if(defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) |
|
573 | + if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) |
|
574 | 574 | { |
575 | 575 | $hashes['sha256_crypt'] = 'sha256_crypt'; |
576 | 576 | } |
577 | - if(defined('CRYPT_MD5') && CRYPT_MD5 == 1) |
|
577 | + if (defined('CRYPT_MD5') && CRYPT_MD5 == 1) |
|
578 | 578 | { |
579 | 579 | $hashes['md5_crypt'] = 'md5_crypt'; |
580 | 580 | } |
581 | - if(defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1) |
|
581 | + if (defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1) |
|
582 | 582 | { |
583 | 583 | $hashes['ext_crypt'] = 'ext_crypt'; |
584 | 584 | } |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | 'smd5' => 'smd5', |
588 | 588 | 'sha' => 'sha', |
589 | 589 | ); |
590 | - if(@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1) |
|
590 | + if (@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1) |
|
591 | 591 | { |
592 | 592 | $hashes['crypt'] = 'crypt'; |
593 | 593 | } |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check |
621 | 621 | * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
622 | 622 | */ |
623 | - static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
|
623 | + static function crackcheck($passwd, $reqstrength = null, $minlength = null, $forbid_name = null, $account = null) |
|
624 | 624 | { |
625 | 625 | if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
626 | 626 | if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
@@ -634,11 +634,11 @@ discard block |
||
634 | 634 | { |
635 | 635 | if (!isset($reqstrength) || $reqstrength == 5) |
636 | 636 | { |
637 | - Config::save_value('force_pwd_strength', $reqstrength=4, 'phpgwapi'); |
|
637 | + Config::save_value('force_pwd_strength', $reqstrength = 4, 'phpgwapi'); |
|
638 | 638 | } |
639 | 639 | if (!isset($minlength)) |
640 | 640 | { |
641 | - Config::save_value('force_pwd_length', $minlength=7, 'phpgwapi'); |
|
641 | + Config::save_value('force_pwd_length', $minlength = 7, 'phpgwapi'); |
|
642 | 642 | } |
643 | 643 | Config::save_value('check_save_passwd', null, 'phpgwapi'); |
644 | 644 | } |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | throw new Exception\WrongParameter('crackcheck(..., forbid_name=true, account) requires account-data!'); |
658 | 658 | } |
659 | 659 | $parts = preg_split("/[,._ \t0-9-]+/", $account['account_fullname'].','.$account['account_lid']); |
660 | - foreach($parts as $part) |
|
660 | + foreach ($parts as $part) |
|
661 | 661 | { |
662 | 662 | if (strlen($part) > 2 && stripos($passwd, $part) !== false) |
663 | 663 | { |
@@ -670,15 +670,15 @@ discard block |
||
670 | 670 | if ($reqstrength) |
671 | 671 | { |
672 | 672 | $missing = array(); |
673 | - if (!preg_match('/(.*\d.*){'. ($non=1). ',}/',$passwd)) |
|
673 | + if (!preg_match('/(.*\d.*){'.($non = 1).',}/', $passwd)) |
|
674 | 674 | { |
675 | 675 | $missing[] = lang('numbers'); |
676 | 676 | } |
677 | - if (!preg_match('/(.*[[:upper:]].*){'. ($nou=1). ',}/',$passwd)) |
|
677 | + if (!preg_match('/(.*[[:upper:]].*){'.($nou = 1).',}/', $passwd)) |
|
678 | 678 | { |
679 | 679 | $missing[] = lang('uppercase letters'); |
680 | 680 | } |
681 | - if (!preg_match('/(.*[[:lower:]].*){'. ($nol=1). ',}/',$passwd)) |
|
681 | + if (!preg_match('/(.*[[:lower:]].*){'.($nol = 1).',}/', $passwd)) |
|
682 | 682 | { |
683 | 683 | $missing[] = lang('lowercase letters'); |
684 | 684 | } |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | if (4 - count($missing) < $reqstrength) |
690 | 690 | { |
691 | 691 | $errors[] = lang('password contains only %1 of required %2 character classes: no %3', |
692 | - 4-count($missing), $reqstrength, implode(', ', $missing)); |
|
692 | + 4 - count($missing), $reqstrength, implode(', ', $missing)); |
|
693 | 693 | } |
694 | 694 | } |
695 | 695 | if ($errors) |
@@ -707,19 +707,19 @@ discard block |
||
707 | 707 | * @param string $db_val stored value (from database) |
708 | 708 | * @return boolean True on successful comparison |
709 | 709 | */ |
710 | - static function smd5_compare($form_val,$db_val) |
|
710 | + static function smd5_compare($form_val, $db_val) |
|
711 | 711 | { |
712 | 712 | /* Start with the first char after {SMD5} */ |
713 | - $hash = base64_decode(substr($db_val,6)); |
|
713 | + $hash = base64_decode(substr($db_val, 6)); |
|
714 | 714 | |
715 | 715 | /* SMD5 hashes are 16 bytes long */ |
716 | - $orig_hash = cut_bytes($hash, 0, 16); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
716 | + $orig_hash = cut_bytes($hash, 0, 16); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
717 | 717 | $salt = cut_bytes($hash, 16); |
718 | 718 | |
719 | - $new_hash = md5($form_val . $salt,true); |
|
719 | + $new_hash = md5($form_val.$salt, true); |
|
720 | 720 | //echo '<br> DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash); |
721 | 721 | |
722 | - return strcmp($orig_hash,$new_hash) == 0; |
|
722 | + return strcmp($orig_hash, $new_hash) == 0; |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -729,14 +729,14 @@ discard block |
||
729 | 729 | * @param string $db_val stored value (from database) |
730 | 730 | * @return boolean True on successful comparison |
731 | 731 | */ |
732 | - static function sha_compare($form_val,$db_val) |
|
732 | + static function sha_compare($form_val, $db_val) |
|
733 | 733 | { |
734 | 734 | /* Start with the first char after {SHA} */ |
735 | - $hash = base64_decode(substr($db_val,5)); |
|
736 | - $new_hash = sha1($form_val,true); |
|
735 | + $hash = base64_decode(substr($db_val, 5)); |
|
736 | + $new_hash = sha1($form_val, true); |
|
737 | 737 | //echo '<br> DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash); |
738 | 738 | |
739 | - return strcmp($hash,$new_hash) == 0; |
|
739 | + return strcmp($hash, $new_hash) == 0; |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | /** |
@@ -746,18 +746,18 @@ discard block |
||
746 | 746 | * @param string $db_val stored value (from database) |
747 | 747 | * @return boolean True on successful comparison |
748 | 748 | */ |
749 | - static function ssha_compare($form_val,$db_val) |
|
749 | + static function ssha_compare($form_val, $db_val) |
|
750 | 750 | { |
751 | 751 | /* Start with the first char after {SSHA} */ |
752 | 752 | $hash = base64_decode(substr($db_val, 6)); |
753 | 753 | |
754 | 754 | // SHA-1 hashes are 160 bits long |
755 | - $orig_hash = cut_bytes($hash, 0, 20); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
755 | + $orig_hash = cut_bytes($hash, 0, 20); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
756 | 756 | $salt = cut_bytes($hash, 20); |
757 | - $new_hash = sha1($form_val . $salt,true); |
|
757 | + $new_hash = sha1($form_val.$salt, true); |
|
758 | 758 | |
759 | 759 | //error_log(__METHOD__."('$form_val', '$db_val') hash='$hash', orig_hash='$orig_hash', salt='$salt', new_hash='$new_hash' returning ".array2string(strcmp($orig_hash,$new_hash) == 0)); |
760 | - return strcmp($orig_hash,$new_hash) == 0; |
|
760 | + return strcmp($orig_hash, $new_hash) == 0; |
|
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
@@ -768,11 +768,11 @@ discard block |
||
768 | 768 | * @param string $_key key for md5_hmac-encryption (username for imported smf users) |
769 | 769 | * @return boolean True on successful comparison |
770 | 770 | */ |
771 | - static function md5_hmac_compare($form_val,$db_val,$_key) |
|
771 | + static function md5_hmac_compare($form_val, $db_val, $_key) |
|
772 | 772 | { |
773 | 773 | $key = str_pad(strlen($_key) <= 64 ? $_key : pack('H*', md5($_key)), 64, chr(0x00)); |
774 | - $md5_hmac = md5(($key ^ str_repeat(chr(0x5c), 64)) . pack('H*', md5(($key ^ str_repeat(chr(0x36), 64)). $form_val))); |
|
774 | + $md5_hmac = md5(($key^str_repeat(chr(0x5c), 64)).pack('H*', md5(($key^str_repeat(chr(0x36), 64)).$form_val))); |
|
775 | 775 | |
776 | - return strcmp($md5_hmac,$db_val) == 0; |
|
776 | + return strcmp($md5_hmac, $db_val) == 0; |
|
777 | 777 | } |
778 | 778 | } |
@@ -62,7 +62,10 @@ discard block |
||
62 | 62 | */ |
63 | 63 | static function backend($type=null) |
64 | 64 | { |
65 | - if (is_null($type)) $type = $GLOBALS['egw_info']['server']['auth_type']; |
|
65 | + if (is_null($type)) |
|
66 | + { |
|
67 | + $type = $GLOBALS['egw_info']['server']['auth_type']; |
|
68 | + } |
|
66 | 69 | |
67 | 70 | $backend_class = __CLASS__.'\\'.ucfirst($type); |
68 | 71 | |
@@ -90,12 +93,18 @@ discard block |
||
90 | 93 | static function check_password_change(&$message=null) |
91 | 94 | { |
92 | 95 | // dont check anything for anonymous sessions/ users that are flagged as anonymous |
93 | - if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true; |
|
96 | + if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') |
|
97 | + { |
|
98 | + return true; |
|
99 | + } |
|
94 | 100 | |
95 | 101 | // some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request |
96 | 102 | // if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed |
97 | 103 | static $UserKnowsAboutPwdChange=null; |
98 | - if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
104 | + if (is_null($UserKnowsAboutPwdChange)) |
|
105 | + { |
|
106 | + $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
107 | + } |
|
99 | 108 | |
100 | 109 | // retrieve the timestamp regarding the last change of the password from auth system and store it with the session |
101 | 110 | static $alpwchange_val=null; |
@@ -172,7 +181,10 @@ discard block |
||
172 | 181 | } |
173 | 182 | $message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq)); |
174 | 183 | // user has no rights to change password --> do NOT warn, as only forced check ignores rights |
175 | - if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true; |
|
184 | + if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) |
|
185 | + { |
|
186 | + return true; |
|
187 | + } |
|
176 | 188 | return null; |
177 | 189 | } |
178 | 190 | return false; |
@@ -446,7 +458,10 @@ discard block |
||
446 | 458 | */ |
447 | 459 | static function encrypt_ldap($password, $type=null) |
448 | 460 | { |
449 | - if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
|
461 | + if (is_null($type)) |
|
462 | + { |
|
463 | + $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
|
464 | + } |
|
450 | 465 | |
451 | 466 | $salt = ''; |
452 | 467 | switch(strtolower($type)) |
@@ -622,9 +637,18 @@ discard block |
||
622 | 637 | */ |
623 | 638 | static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
624 | 639 | { |
625 | - if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
|
626 | - if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
|
627 | - if (!isset($forbid_name)) $forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name']; |
|
640 | + if (!isset($reqstrength)) |
|
641 | + { |
|
642 | + $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
|
643 | + } |
|
644 | + if (!isset($minlength)) |
|
645 | + { |
|
646 | + $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
|
647 | + } |
|
648 | + if (!isset($forbid_name)) |
|
649 | + { |
|
650 | + $forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name']; |
|
651 | + } |
|
628 | 652 | |
629 | 653 | // load preferences translations, as changepassword get's called from admin too |
630 | 654 | Translation::add_app('preferences'); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @param string $path |
153 | 153 | * @param array $filter |
154 | - * @param array|boolean $start false=return all or array(start,num) |
|
154 | + * @param integer[] $start false=return all or array(start,num) |
|
155 | 155 | * @param int &$total |
156 | 156 | * @return array with "files" array with values for keys path and props |
157 | 157 | */ |
@@ -193,7 +193,6 @@ discard block |
||
193 | 193 | * Read an entry |
194 | 194 | * |
195 | 195 | * @param string|int $id |
196 | - * @param string $path =null implementation can use it, used in call from _common_get_put_delete |
|
197 | 196 | * @return array|boolean array with entry, false if no read rights, null if $id does not exist |
198 | 197 | */ |
199 | 198 | abstract function read($id /*,$path=null*/); |
@@ -238,7 +237,7 @@ discard block |
||
238 | 237 | * Get the etag for an entry, can be reimplemented for other algorithm or field names |
239 | 238 | * |
240 | 239 | * @param array|int $entry array with event or cal_id |
241 | - * @return string|boolean string with etag or false |
|
240 | + * @return false|string string with etag or false |
|
242 | 241 | */ |
243 | 242 | function get_etag($entry) |
244 | 243 | { |
@@ -423,7 +422,7 @@ discard block |
||
423 | 422 | /** |
424 | 423 | * Identify know GroupDAV agents by HTTP_USER_AGENT header |
425 | 424 | * |
426 | - * @return string|boolean agent name or false |
|
425 | + * @return string|false agent name or false |
|
427 | 426 | */ |
428 | 427 | static function get_agent() |
429 | 428 | { |
@@ -123,7 +123,10 @@ discard block |
||
123 | 123 | function __construct($app, Api\CalDAV $caldav) |
124 | 124 | { |
125 | 125 | $this->app = $app; |
126 | - if (!is_null($caldav->debug)) $this->debug = $caldav->debug; |
|
126 | + if (!is_null($caldav->debug)) |
|
127 | + { |
|
128 | + $this->debug = $caldav->debug; |
|
129 | + } |
|
127 | 130 | $this->base_uri = $caldav->base_uri; |
128 | 131 | $this->caldav = $caldav; |
129 | 132 | |
@@ -282,11 +285,17 @@ discard block |
||
282 | 285 | */ |
283 | 286 | function _common_get_put_delete($method,&$options,&$id,&$return_no_access=false,$ignore_if_match=false) |
284 | 287 | { |
285 | - if (self::$path_extension) $id = basename($id,self::$path_extension); |
|
288 | + if (self::$path_extension) |
|
289 | + { |
|
290 | + $id = basename($id,self::$path_extension); |
|
291 | + } |
|
286 | 292 | |
287 | 293 | if ($this->app != 'principals' && !$GLOBALS['egw_info']['user']['apps'][$this->app]) |
288 | 294 | { |
289 | - if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden: no app rights for '$this->app'"); |
|
295 | + if ($this->debug) |
|
296 | + { |
|
297 | + error_log(__METHOD__."($method,,$id) 403 Forbidden: no app rights for '$this->app'"); |
|
298 | + } |
|
290 | 299 | return '403 Forbidden'; // no app rights |
291 | 300 | } |
292 | 301 | $extra_acl = $this->method2acl[$method]; |
@@ -295,12 +304,18 @@ discard block |
||
295 | 304 | { |
296 | 305 | if ($return_no_access && !is_null($entry)) |
297 | 306 | { |
298 | - if ($this->debug) error_log(__METHOD__."($method,,$id,$return_no_access) \$entry=".array2string($entry).", \$return_no_access set to false"); |
|
307 | + if ($this->debug) |
|
308 | + { |
|
309 | + error_log(__METHOD__."($method,,$id,$return_no_access) \$entry=".array2string($entry).", \$return_no_access set to false"); |
|
310 | + } |
|
299 | 311 | $return_no_access = false; |
300 | 312 | } |
301 | 313 | else |
302 | 314 | { |
303 | - if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null')); |
|
315 | + if ($this->debug) |
|
316 | + { |
|
317 | + error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null')); |
|
318 | + } |
|
304 | 319 | return !is_null($entry) ? '403 Forbidden' : '404 Not Found'; |
305 | 320 | } |
306 | 321 | } |
@@ -313,11 +328,17 @@ discard block |
||
313 | 328 | { |
314 | 329 | $this->http_if_match = $_SERVER['HTTP_IF_MATCH']; |
315 | 330 | // strip of quotes around etag, if they exist, that way we allow etag with and without quotes |
316 | - if ($this->http_if_match[0] == '"') $this->http_if_match = substr($this->http_if_match, 1, -1); |
|
331 | + if ($this->http_if_match[0] == '"') |
|
332 | + { |
|
333 | + $this->http_if_match = substr($this->http_if_match, 1, -1); |
|
334 | + } |
|
317 | 335 | |
318 | 336 | if ($this->http_if_match !== $etag) |
319 | 337 | { |
320 | - if ($this->debug) error_log(__METHOD__."($method,path=$options[path],$id) HTTP_IF_MATCH='$_SERVER[HTTP_IF_MATCH]', etag='$etag': 412 Precondition failed".array2string($entry)); |
|
338 | + if ($this->debug) |
|
339 | + { |
|
340 | + error_log(__METHOD__."($method,path=$options[path],$id) HTTP_IF_MATCH='$_SERVER[HTTP_IF_MATCH]', etag='$etag': 412 Precondition failed".array2string($entry)); |
|
341 | + } |
|
321 | 342 | // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) |
322 | 343 | $this->check_return_representation($options, $id); |
323 | 344 | return '412 Precondition Failed'; |
@@ -327,17 +348,26 @@ discard block |
||
327 | 348 | { |
328 | 349 | $if_none_match = $_SERVER['HTTP_IF_NONE_MATCH']; |
329 | 350 | // strip of quotes around etag, if they exist, that way we allow etag with and without quotes |
330 | - if ($if_none_match[0] == '"') $if_none_match = substr($if_none_match, 1, -1); |
|
351 | + if ($if_none_match[0] == '"') |
|
352 | + { |
|
353 | + $if_none_match = substr($if_none_match, 1, -1); |
|
354 | + } |
|
331 | 355 | |
332 | 356 | // if an IF_NONE_MATCH is given, check if we need to send a new export, or the current one is still up-to-date |
333 | 357 | if (in_array($method, array('GET','HEAD')) && $etag === $if_none_match) |
334 | 358 | { |
335 | - if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified"); |
|
359 | + if ($this->debug) |
|
360 | + { |
|
361 | + error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified"); |
|
362 | + } |
|
336 | 363 | return '304 Not Modified'; |
337 | 364 | } |
338 | 365 | if ($method == 'PUT' && ($if_none_match == '*' || $if_none_match == $etag)) |
339 | 366 | { |
340 | - if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 412 Precondition failed"); |
|
367 | + if ($this->debug) |
|
368 | + { |
|
369 | + error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 412 Precondition failed"); |
|
370 | + } |
|
341 | 371 | // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) |
342 | 372 | $this->check_return_representation($options, $id); |
343 | 373 | return '412 Precondition Failed'; |
@@ -376,7 +406,10 @@ discard block |
||
376 | 406 | |
377 | 407 | if (($ret = $this->get($options, $id ? $id : $this->new_id, $user)) && !empty($options['data'])) |
378 | 408 | { |
379 | - if (!$this->caldav->use_compression()) header('Content-Length: '.$this->caldav->bytes($options['data'])); |
|
409 | + if (!$this->caldav->use_compression()) |
|
410 | + { |
|
411 | + header('Content-Length: '.$this->caldav->bytes($options['data'])); |
|
412 | + } |
|
380 | 413 | header('Content-Type: '.$options['mimetype']); |
381 | 414 | echo $options['data']; |
382 | 415 | } |
@@ -412,7 +445,10 @@ discard block |
||
412 | 445 | if (!array_key_exists($app,$handler_cache)) |
413 | 446 | { |
414 | 447 | $class = $app.'_groupdav'; |
415 | - if (!class_exists($class) && !class_exists($class = __NAMESPACE__.'\\'.ucfirst($app))) return null; |
|
448 | + if (!class_exists($class) && !class_exists($class = __NAMESPACE__.'\\'.ucfirst($app))) |
|
449 | + { |
|
450 | + return null; |
|
451 | + } |
|
416 | 452 | |
417 | 453 | $handler_cache[$app] = new $class($app, $groupdav); |
418 | 454 | } |
@@ -474,7 +510,10 @@ discard block |
||
474 | 510 | $matches = null; |
475 | 511 | if (preg_match('/address%20book\/([0-9.]+)/', $user_agent, $matches)) |
476 | 512 | { |
477 | - if ((int)$matches[1] < 868) $agent .= '_old'; |
|
513 | + if ((int)$matches[1] < 868) |
|
514 | + { |
|
515 | + $agent .= '_old'; |
|
516 | + } |
|
478 | 517 | } |
479 | 518 | break; |
480 | 519 | case 'kde': |
@@ -575,7 +614,10 @@ discard block |
||
575 | 614 | // --> as all clients dislike not getting an ETag for a PUT, we sending it again even not storing byte-by-byte |
576 | 615 | //if (get_class($this) == 'addressbook_groupdav' && in_array(self::get_agent(),array('thunderbird','lightning'))) |
577 | 616 | { |
578 | - if (is_null($etag)) $etag = $this->get_etag($entry); |
|
617 | + if (is_null($etag)) |
|
618 | + { |
|
619 | + $etag = $this->get_etag($entry); |
|
620 | + } |
|
579 | 621 | header('ETag: "'.$etag.'"'); |
580 | 622 | } |
581 | 623 | |
@@ -741,7 +783,10 @@ discard block |
||
741 | 783 | */ |
742 | 784 | public function get_sync_token($path, $user, $token=null) |
743 | 785 | { |
744 | - if (!isset($token)) $token = $this->getctag($path, $user); |
|
786 | + if (!isset($token)) |
|
787 | + { |
|
788 | + $token = $this->getctag($path, $user); |
|
789 | + } |
|
745 | 790 | |
746 | 791 | // never return current time, as more modifications might happen due to second granularity --> return 1sec less |
747 | 792 | if ($token >= (int)$GLOBALS['egw_info']['flags']['page_start_time']) |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param int $user account_id |
145 | 145 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
146 | 146 | */ |
147 | - abstract function propfind($path,&$options,&$files,$user); |
|
147 | + abstract function propfind($path, &$options, &$files, $user); |
|
148 | 148 | |
149 | 149 | /** |
150 | 150 | * Propfind callback, if interator is used |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | function &propfind_callback($path, array $filter, $start) |
158 | 158 | { |
159 | - unset($path, $filter, $start); // not used, but required by function signature |
|
159 | + unset($path, $filter, $start); // not used, but required by function signature |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param int $user =null account_id |
168 | 168 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
169 | 169 | */ |
170 | - abstract function get(&$options,$id,$user=null); |
|
170 | + abstract function get(&$options, $id, $user = null); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Handle get request for an applications entry |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param int $user =null account_id of owner, default null |
178 | 178 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
179 | 179 | */ |
180 | - abstract function put(&$options,$id,$user=null); |
|
180 | + abstract function put(&$options, $id, $user = null); |
|
181 | 181 | |
182 | 182 | /** |
183 | 183 | * Handle get request for an applications entry |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param int $id |
187 | 187 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
188 | 188 | */ |
189 | - abstract function delete(&$options,$id); |
|
189 | + abstract function delete(&$options, $id); |
|
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Read an entry |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param array|int $entry entry-array or id |
216 | 216 | * @return boolean null if entry does not exist, false if no access, true if access permitted |
217 | 217 | */ |
218 | - abstract function check_access($acl,$entry); |
|
218 | + abstract function check_access($acl, $entry); |
|
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Add extra properties for collections |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | * @param int $user =null account_id of owner of collection |
227 | 227 | * @return array |
228 | 228 | */ |
229 | - public function extra_properties(array $props, $displayname, $base_uri=null, $user=null) |
|
229 | + public function extra_properties(array $props, $displayname, $base_uri = null, $user = null) |
|
230 | 230 | { |
231 | - unset($displayname, $base_uri, $user); // not used, but required by function signature |
|
231 | + unset($displayname, $base_uri, $user); // not used, but required by function signature |
|
232 | 232 | |
233 | 233 | return $props; |
234 | 234 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | static function etag2value($etag) |
263 | 263 | { |
264 | - list(,$val) = explode(':',$etag,2); |
|
264 | + list(,$val) = explode(':', $etag, 2); |
|
265 | 265 | |
266 | 266 | return $val; |
267 | 267 | } |
@@ -279,18 +279,18 @@ discard block |
||
279 | 279 | * @param boolean $ignore_if_match =false if true, ignore If-Match precondition |
280 | 280 | * @return array|string entry on success, string with http-error-code on failure, null for PUT on an unknown id |
281 | 281 | */ |
282 | - function _common_get_put_delete($method,&$options,&$id,&$return_no_access=false,$ignore_if_match=false) |
|
282 | + function _common_get_put_delete($method, &$options, &$id, &$return_no_access = false, $ignore_if_match = false) |
|
283 | 283 | { |
284 | - if (self::$path_extension) $id = basename($id,self::$path_extension); |
|
284 | + if (self::$path_extension) $id = basename($id, self::$path_extension); |
|
285 | 285 | |
286 | 286 | if ($this->app != 'principals' && !$GLOBALS['egw_info']['user']['apps'][$this->app]) |
287 | 287 | { |
288 | 288 | if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden: no app rights for '$this->app'"); |
289 | - return '403 Forbidden'; // no app rights |
|
289 | + return '403 Forbidden'; // no app rights |
|
290 | 290 | } |
291 | 291 | $extra_acl = $this->method2acl[$method]; |
292 | 292 | if ($id && !($entry = $this->read($id, $options['path'])) && ($method != 'PUT' || $entry === false) || |
293 | - ($extra_acl != Api\Acl::READ && $this->check_access($extra_acl,$entry) === false)) |
|
293 | + ($extra_acl != Api\Acl::READ && $this->check_access($extra_acl, $entry) === false)) |
|
294 | 294 | { |
295 | 295 | if ($return_no_access && !is_null($entry)) |
296 | 296 | { |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | } |
300 | 300 | else |
301 | 301 | { |
302 | - if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null')); |
|
302 | + if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry === false ? 'false' : 'null')); |
|
303 | 303 | return !is_null($entry) ? '403 Forbidden' : '404 Not Found'; |
304 | 304 | } |
305 | 305 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | if ($if_none_match[0] == '"') $if_none_match = substr($if_none_match, 1, -1); |
330 | 330 | |
331 | 331 | // if an IF_NONE_MATCH is given, check if we need to send a new export, or the current one is still up-to-date |
332 | - if (in_array($method, array('GET','HEAD')) && $etag === $if_none_match) |
|
332 | + if (in_array($method, array('GET', 'HEAD')) && $etag === $if_none_match) |
|
333 | 333 | { |
334 | 334 | if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified"); |
335 | 335 | return '304 Not Modified'; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * @param int $user =null account_id |
355 | 355 | * @return string|boolean http status of get or null if no representation was requested |
356 | 356 | */ |
357 | - public function check_return_representation($options, $id, $user=null) |
|
357 | + public function check_return_representation($options, $id, $user = null) |
|
358 | 358 | { |
359 | 359 | //error_log(__METHOD__."(, $id, $user) start ".function_backtrace()); |
360 | 360 | if (isset($_SERVER['HTTP_PREFER']) && in_array('return=representation', preg_split('/, ?/', $_SERVER['HTTP_PREFER']))) |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | */ |
394 | 394 | public function update_tags($entry) |
395 | 395 | { |
396 | - unset($entry); // not used, but required by function signature |
|
396 | + unset($entry); // not used, but required by function signature |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | { |
409 | 409 | static $handler_cache = array(); |
410 | 410 | |
411 | - if (!array_key_exists($app,$handler_cache)) |
|
411 | + if (!array_key_exists($app, $handler_cache)) |
|
412 | 412 | { |
413 | 413 | $class = $app.'_groupdav'; |
414 | 414 | if (!class_exists($class) && !class_exists($class = __NAMESPACE__.'\\'.ucfirst($app))) return null; |
@@ -426,36 +426,36 @@ discard block |
||
426 | 426 | */ |
427 | 427 | static function get_agent() |
428 | 428 | { |
429 | - static $agent=null; |
|
429 | + static $agent = null; |
|
430 | 430 | |
431 | 431 | if (is_null($agent)) |
432 | 432 | { |
433 | 433 | $agent = false; |
434 | 434 | // identify the agent (GroupDAV client) from the HTTP_USER_AGENT header |
435 | 435 | $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); |
436 | - foreach(array( |
|
437 | - 'carddav-sync' => 'carddav-sync', // dmfs.org CardDAV client for Android: CardDAV-Sync (Android) (like iOS/5.0.1 (9A405) dataaccessd/1.0) gzip |
|
438 | - 'iphone' => 'iphone', // Apple iPhone iCal |
|
439 | - 'davkit' => 'davkit', // Apple iCal 10.6 |
|
440 | - 'coredav' => 'coredav', // Apple iCal 10.7 |
|
441 | - 'calendarstore' => 'calendarstore', // Apple iCal 5.0.1 under OS X 10.7.2 |
|
442 | - 'calendaragent/' => 'calendaragent', // Apple iCal OS X 10.8*: Mac OS X/10.8.2 (12C54) CalendarAgent/55 |
|
443 | - 'dataaccess' => 'dataaccess', // Apple addressbook iPhone |
|
444 | - 'cfnetwork' => 'cfnetwork', // Apple Addressbook 10.6/7 |
|
445 | - 'addressbook/' => 'cfnetwork', // Apple Addressbook OS X 10.8*: Mac OS X/10.8.2 (12C54) AddressBook/1167 |
|
446 | - 'bionicmessage.net' => 'funambol', // funambol GroupDAV connector from bionicmessage.net |
|
447 | - 'zideone' => 'zideone', // zideone outlook plugin |
|
448 | - 'lightning' => 'lightning', // Lighting (incl. SOGo connector for addressbook) |
|
449 | - 'webkit' => 'webkit', // Webkit Browser (also reports KHTML!) |
|
450 | - 'akonadi' => 'akonadi', // new KDE PIM framework (also reports KHTML!) |
|
451 | - 'khtml' => 'kde', // KDE clients |
|
436 | + foreach (array( |
|
437 | + 'carddav-sync' => 'carddav-sync', // dmfs.org CardDAV client for Android: CardDAV-Sync (Android) (like iOS/5.0.1 (9A405) dataaccessd/1.0) gzip |
|
438 | + 'iphone' => 'iphone', // Apple iPhone iCal |
|
439 | + 'davkit' => 'davkit', // Apple iCal 10.6 |
|
440 | + 'coredav' => 'coredav', // Apple iCal 10.7 |
|
441 | + 'calendarstore' => 'calendarstore', // Apple iCal 5.0.1 under OS X 10.7.2 |
|
442 | + 'calendaragent/' => 'calendaragent', // Apple iCal OS X 10.8*: Mac OS X/10.8.2 (12C54) CalendarAgent/55 |
|
443 | + 'dataaccess' => 'dataaccess', // Apple addressbook iPhone |
|
444 | + 'cfnetwork' => 'cfnetwork', // Apple Addressbook 10.6/7 |
|
445 | + 'addressbook/' => 'cfnetwork', // Apple Addressbook OS X 10.8*: Mac OS X/10.8.2 (12C54) AddressBook/1167 |
|
446 | + 'bionicmessage.net' => 'funambol', // funambol GroupDAV connector from bionicmessage.net |
|
447 | + 'zideone' => 'zideone', // zideone outlook plugin |
|
448 | + 'lightning' => 'lightning', // Lighting (incl. SOGo connector for addressbook) |
|
449 | + 'webkit' => 'webkit', // Webkit Browser (also reports KHTML!) |
|
450 | + 'akonadi' => 'akonadi', // new KDE PIM framework (also reports KHTML!) |
|
451 | + 'khtml' => 'kde', // KDE clients |
|
452 | 452 | 'neon' => 'neon', |
453 | - 'ical4ol' => 'ical4ol', // iCal4OL client |
|
454 | - 'evolution' => 'evolution', // Evolution |
|
455 | - 'thunderbird' => 'thunderbird', // SOGo connector for addressbook, no Lightning installed |
|
453 | + 'ical4ol' => 'ical4ol', // iCal4OL client |
|
454 | + 'evolution' => 'evolution', // Evolution |
|
455 | + 'thunderbird' => 'thunderbird', // SOGo connector for addressbook, no Lightning installed |
|
456 | 456 | ) as $pattern => $name) |
457 | 457 | { |
458 | - if (strpos($user_agent,$pattern) !== false) |
|
458 | + if (strpos($user_agent, $pattern) !== false) |
|
459 | 459 | { |
460 | 460 | $agent = $name; |
461 | 461 | break; |
@@ -511,35 +511,35 @@ discard block |
||
511 | 511 | * @param int $user =null owner of the collection, default current user |
512 | 512 | * @return array with privileges |
513 | 513 | */ |
514 | - public function current_user_privileges($path, $user=null) |
|
514 | + public function current_user_privileges($path, $user = null) |
|
515 | 515 | { |
516 | - unset($path); // not used, but required by function signature |
|
516 | + unset($path); // not used, but required by function signature |
|
517 | 517 | |
518 | - static $grants=null; |
|
518 | + static $grants = null; |
|
519 | 519 | if (is_null($grants)) |
520 | 520 | { |
521 | 521 | $grants = $this->get_grants(); |
522 | 522 | } |
523 | 523 | $priviledes = array('read-current-user-privilege-set' => 'read-current-user-privilege-set'); |
524 | 524 | |
525 | - if (is_null($user) || $grants[$user] & Api\Acl::READ) |
|
525 | + if (is_null($user) || $grants[$user]&Api\Acl::READ) |
|
526 | 526 | { |
527 | 527 | $priviledes['read'] = 'read'; |
528 | 528 | // allows on all calendars/addressbooks to write properties, as we store them on a per-user basis |
529 | 529 | // and only allow to modify explicit named properties in CalDAV, CardDAV or Calendarserver name-space |
530 | 530 | $priviledes['write-properties'] = 'write-properties'; |
531 | 531 | } |
532 | - if (is_null($user) || $grants[$user] & Api\Acl::ADD) |
|
532 | + if (is_null($user) || $grants[$user]&Api\Acl::ADD) |
|
533 | 533 | { |
534 | - $priviledes['bind'] = 'bind'; // PUT for new resources |
|
534 | + $priviledes['bind'] = 'bind'; // PUT for new resources |
|
535 | 535 | } |
536 | - if (is_null($user) || $grants[$user] & Api\Acl::EDIT) |
|
536 | + if (is_null($user) || $grants[$user]&Api\Acl::EDIT) |
|
537 | 537 | { |
538 | - $priviledes['write-content'] = 'write-content'; // otherwise iOS calendar does not allow to add events |
|
538 | + $priviledes['write-content'] = 'write-content'; // otherwise iOS calendar does not allow to add events |
|
539 | 539 | } |
540 | - if (is_null($user) || $grants[$user] & Api\Acl::DELETE) |
|
540 | + if (is_null($user) || $grants[$user]&Api\Acl::DELETE) |
|
541 | 541 | { |
542 | - $priviledes['unbind'] = 'unbind'; // DELETE |
|
542 | + $priviledes['unbind'] = 'unbind'; // DELETE |
|
543 | 543 | } |
544 | 544 | // copy/move of existing resources might require write-properties, thought we do not support an explicit PROPATCH |
545 | 545 | //error_log(__METHOD__."('$path', ".array2string($user).') returning '.array2string($priviledes).' '.function_backtrace()); |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * @param boolean $path_attr_is_name =true true: path_attr is ca(l|rd)dav_name, false: id (GroupDAV needs Location header) |
567 | 567 | * @param string $etag =null etag, to not calculate it again (if != null) |
568 | 568 | */ |
569 | - function put_response_headers($entry, $path, $retval, $path_attr_is_name=true, $etag=null) |
|
569 | + function put_response_headers($entry, $path, $retval, $path_attr_is_name = true, $etag = null) |
|
570 | 570 | { |
571 | 571 | //error_log(__METHOD__."(".array2string($entry).", '$path', ".array2string($retval).", path_attr_is_name=$path_attr_is_name, etag=".array2string($etag).")"); |
572 | 572 | // we should not return an etag here, as EGroupware never stores ical/vcard byte-by-byte |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | */ |
610 | 610 | static function get_settings($hook_data) |
611 | 611 | { |
612 | - unset($hook_data); // not used, but required by function signature |
|
612 | + unset($hook_data); // not used, but required by function signature |
|
613 | 613 | |
614 | 614 | return array(); |
615 | 615 | } |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | { |
630 | 630 | $props['getetag'] = $this->get_etag($entry); |
631 | 631 | } |
632 | - foreach(array( |
|
632 | + foreach (array( |
|
633 | 633 | 'getcontenttype' => 'text/calendar', |
634 | 634 | 'getlastmodified' => $entry['modified'], |
635 | 635 | 'displayname' => $entry['title'], |
@@ -667,17 +667,17 @@ discard block |
||
667 | 667 | * @param boolean $full_uri =true |
668 | 668 | * @return string eg. https://domain.com/egroupware/groupdav.php |
669 | 669 | */ |
670 | - public function base_uri($full_uri=true) |
|
670 | + public function base_uri($full_uri = true) |
|
671 | 671 | { |
672 | - static $uri=null; |
|
673 | - static $path=null; |
|
672 | + static $uri = null; |
|
673 | + static $path = null; |
|
674 | 674 | |
675 | 675 | if (!isset($uri)) |
676 | 676 | { |
677 | 677 | $uri = $path = $this->caldav->base_uri; |
678 | 678 | if ($uri[0] == '/') |
679 | 679 | { |
680 | - $uri = ($_SERVER["HTTPS"] === "on" ? "https:" : "http:") .'//' . $_SERVER['HTTP_HOST'] . $uri; |
|
680 | + $uri = ($_SERVER["HTTPS"] === "on" ? "https:" : "http:").'//'.$_SERVER['HTTP_HOST'].$uri; |
|
681 | 681 | } |
682 | 682 | else |
683 | 683 | { |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | * @param int $user parameter necessary to call getctag, if no $token specified |
702 | 702 | * @return string |
703 | 703 | */ |
704 | - public function get_sync_collection_token($path, $user=null, $more_results=null) |
|
704 | + public function get_sync_collection_token($path, $user = null, $more_results = null) |
|
705 | 705 | { |
706 | 706 | //error_log(__METHOD__."('$path', $user, more_results=$more_results) this->sync_collection_token=".$this->sync_collection_token); |
707 | 707 | if ($more_results) |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | '; |
716 | 716 | if ($this->caldav->crrnd) |
717 | 717 | { |
718 | - $error = str_replace(array('<D:', '</D:'), array('<', '</'), $error); |
|
718 | + $error = str_replace(array('<D:', '</D:'), array('<', '</'), $error); |
|
719 | 719 | } |
720 | 720 | echo $error; |
721 | 721 | } |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | * @param int $token =null modification time, default call getctag($path, $user) to fetch it |
739 | 739 | * @return string |
740 | 740 | */ |
741 | - public function get_sync_token($path, $user, $token=null) |
|
741 | + public function get_sync_token($path, $user, $token = null) |
|
742 | 742 | { |
743 | 743 | if (!isset($token)) $token = $this->getctag($path, $user); |
744 | 744 |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @param array &$options |
257 | 257 | * @param array &$files |
258 | 258 | * @param int $user account_id |
259 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
259 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
260 | 260 | */ |
261 | 261 | function expand_property_report($path,&$options,&$files,$user) |
262 | 262 | { |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | * Check if resource is a location |
1192 | 1192 | * |
1193 | 1193 | * @param array|int $resource |
1194 | - * @return boolean |
|
1194 | + * @return null|boolean |
|
1195 | 1195 | */ |
1196 | 1196 | public static function resource_is_location($resource) |
1197 | 1197 | { |
@@ -1470,7 +1470,6 @@ discard block |
||
1470 | 1470 | * Get proxy-groups for given user $account: users or groups who GRANT proxy rights to $account |
1471 | 1471 | * |
1472 | 1472 | * @param int $account who is the proxy |
1473 | - * @param string|array $app_proxys =null applications for which proxys should be added |
|
1474 | 1473 | * @return array with href props |
1475 | 1474 | */ |
1476 | 1475 | protected function get_resource_proxy_groups($account) |
@@ -1608,8 +1607,6 @@ discard block |
||
1608 | 1607 | /** |
1609 | 1608 | * Do propfind of /principals/ |
1610 | 1609 | * |
1611 | - * @param string $name name of group or empty |
|
1612 | - * @param string $rest name of rest of path behind group-name |
|
1613 | 1610 | * @param array $options |
1614 | 1611 | * @return array|string array with files or HTTP error code |
1615 | 1612 | */ |
@@ -1640,7 +1637,7 @@ discard block |
||
1640 | 1637 | * @param array &$options |
1641 | 1638 | * @param int $id |
1642 | 1639 | * @param int $user =null account_id |
1643 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1640 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1644 | 1641 | */ |
1645 | 1642 | function get(&$options,$id,$user=null) |
1646 | 1643 | { |
@@ -1655,7 +1652,7 @@ discard block |
||
1655 | 1652 | * @param array &$options |
1656 | 1653 | * @param int $id |
1657 | 1654 | * @param int $user =null account_id of owner, default null |
1658 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1655 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1659 | 1656 | */ |
1660 | 1657 | function put(&$options,$id,$user=null) |
1661 | 1658 | { |
@@ -1669,7 +1666,7 @@ discard block |
||
1669 | 1666 | * |
1670 | 1667 | * @param array &$options |
1671 | 1668 | * @param int $id |
1672 | - * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1669 | + * @return boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
|
1673 | 1670 | */ |
1674 | 1671 | function delete(&$options,$id) |
1675 | 1672 | { |
@@ -1681,7 +1678,7 @@ discard block |
||
1681 | 1678 | /** |
1682 | 1679 | * Read an entry |
1683 | 1680 | * |
1684 | - * @param string|int $id |
|
1681 | + * @param integer $id |
|
1685 | 1682 | * @return array/boolean array with entry, false if no read rights, null if $id does not exist |
1686 | 1683 | */ |
1687 | 1684 | function read($id) |
@@ -1696,7 +1693,7 @@ discard block |
||
1696 | 1693 | * |
1697 | 1694 | * @param int $acl Api\Acl::READ, Api\Acl::EDIT or Api\Acl::DELETE |
1698 | 1695 | * @param array|int $entry entry-array or id |
1699 | - * @return boolean null if entry does not exist, false if no access, true if access permitted |
|
1696 | + * @return null|boolean null if entry does not exist, false if no access, true if access permitted |
|
1700 | 1697 | */ |
1701 | 1698 | function check_access($acl,$entry) |
1702 | 1699 | { |
@@ -1739,7 +1736,7 @@ discard block |
||
1739 | 1736 | * |
1740 | 1737 | * @param string $path path of collection |
1741 | 1738 | * @param int $user =null owner of the collection, default current user |
1742 | - * @return array with privileges |
|
1739 | + * @return string[] with privileges |
|
1743 | 1740 | */ |
1744 | 1741 | public function current_user_privileges($path, $user=null) |
1745 | 1742 | { |
@@ -89,19 +89,18 @@ discard block |
||
89 | 89 | * @param array $reports =null |
90 | 90 | * @return array Api\CalDAV::mkprop('supported-report-set', ...) |
91 | 91 | */ |
92 | - protected function supported_report_set($path, array $reports=null) |
|
92 | + protected function supported_report_set($path, array $reports = null) |
|
93 | 93 | { |
94 | - unset($path); // not used, but required by function signature |
|
94 | + unset($path); // not used, but required by function signature |
|
95 | 95 | |
96 | 96 | if (is_null($reports)) $reports = $this->supported_reports; |
97 | 97 | |
98 | 98 | $supported = array(); |
99 | - foreach($reports as $name => $data) |
|
99 | + foreach ($reports as $name => $data) |
|
100 | 100 | { |
101 | - $supported[$name] = Api\CalDAV::mkprop('supported-report',array( |
|
102 | - Api\CalDAV::mkprop('report',array( |
|
103 | - !$data['ns'] ? Api\CalDAV::mkprop($name, '') : |
|
104 | - Api\CalDAV::mkprop($data['ns'], $name, ''))))); |
|
101 | + $supported[$name] = Api\CalDAV::mkprop('supported-report', array( |
|
102 | + Api\CalDAV::mkprop('report', array( |
|
103 | + !$data['ns'] ? Api\CalDAV::mkprop($name, '') : Api\CalDAV::mkprop($data['ns'], $name, ''))))); |
|
105 | 104 | } |
106 | 105 | return $supported; |
107 | 106 | } |
@@ -115,7 +114,7 @@ discard block |
||
115 | 114 | * @param int $user account_id |
116 | 115 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
117 | 116 | */ |
118 | - function propfind($path,&$options,&$files,$user) |
|
117 | + function propfind($path, &$options, &$files, $user) |
|
119 | 118 | { |
120 | 119 | if (($report = isset($_GET['report']) ? $_GET['report'] : $options['root']['name']) && $report != 'propfind') |
121 | 120 | { |
@@ -127,7 +126,7 @@ discard block |
||
127 | 126 | $this->caldav->log(__METHOD__."('$path', ".array2string($options).",, $user) not implemented report, returning 501 Not Implemented"); |
128 | 127 | return '501 Not Implemented'; |
129 | 128 | } |
130 | - list(,,$type,$name,$rest) = explode('/',$path,5); |
|
129 | + list(,, $type, $name, $rest) = explode('/', $path, 5); |
|
131 | 130 | // /principals/users/$name/ |
132 | 131 | // /users/$name/calendar-proxy-read/ |
133 | 132 | // /users/$name/calendar-proxy-write/ |
@@ -136,19 +135,19 @@ discard block |
||
136 | 135 | // /locations/$resource/ |
137 | 136 | // /__uids__/$uid/.../ |
138 | 137 | |
139 | - switch($type) |
|
138 | + switch ($type) |
|
140 | 139 | { |
141 | 140 | case 'users': |
142 | - $files['files'] = $this->propfind_users($name,$rest,$options); |
|
141 | + $files['files'] = $this->propfind_users($name, $rest, $options); |
|
143 | 142 | break; |
144 | 143 | case 'groups': |
145 | - $files['files'] = $this->propfind_groups($name,$rest,$options); |
|
144 | + $files['files'] = $this->propfind_groups($name, $rest, $options); |
|
146 | 145 | break; |
147 | 146 | case 'resources': |
148 | - $files['files'] = $this->propfind_resources($name,$rest,$options,false); |
|
147 | + $files['files'] = $this->propfind_resources($name, $rest, $options, false); |
|
149 | 148 | break; |
150 | 149 | case 'locations': |
151 | - $files['files'] = $this->propfind_resources($name,$rest,$options,true); |
|
150 | + $files['files'] = $this->propfind_resources($name, $rest, $options, true); |
|
152 | 151 | break; |
153 | 152 | /*case '__uids__': |
154 | 153 | $files['files'] = $this->propfind_uids($name,$rest,$options); |
@@ -258,11 +257,11 @@ discard block |
||
258 | 257 | * @param int $user account_id |
259 | 258 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
260 | 259 | */ |
261 | - function expand_property_report($path,&$options,&$files,$user) |
|
260 | + function expand_property_report($path, &$options, &$files, $user) |
|
262 | 261 | { |
263 | 262 | //error_log(__METHOD__."('$path', ".array2string($options).",, $user)"); |
264 | 263 | $requested_props = $options['other']; |
265 | - while(($requested_prop = array_shift($requested_props))) |
|
264 | + while (($requested_prop = array_shift($requested_props))) |
|
266 | 265 | { |
267 | 266 | if ($requested_prop['name'] != 'property' || $requested_prop['depth'] != 1) continue; |
268 | 267 | |
@@ -270,11 +269,11 @@ discard block |
||
270 | 269 | $prop_name = $requested_prop['attrs']['name']; |
271 | 270 | $prop_path = $path; |
272 | 271 | // calendarserver has some special property-names for expansion |
273 | - switch($prop_name) |
|
272 | + switch ($prop_name) |
|
274 | 273 | { |
275 | 274 | case 'calendar-proxy-read-for': |
276 | 275 | case 'calendar-proxy-write-for': |
277 | - $prop_path = $path . substr($prop_name, 0, -4).'/'; |
|
276 | + $prop_path = $path.substr($prop_name, 0, -4).'/'; |
|
278 | 277 | $prop_name = 'group-member-set'; |
279 | 278 | $prop_ns = Api\CalDAV::DAV; |
280 | 279 | break; |
@@ -294,14 +293,14 @@ discard block |
||
294 | 293 | 'xmlns' => $prop_ns, |
295 | 294 | )); |
296 | 295 | $prop_files = array(); |
297 | - $this->caldav->options = $options; // also modify global variable |
|
296 | + $this->caldav->options = $options; // also modify global variable |
|
298 | 297 | if (empty($prop_name) || $this->propfind($prop_path, $options, $prop_files, $user) !== true) |
299 | 298 | { |
300 | 299 | $this->caldav->log('### NO expand-property report for '.$requested_prop['attrs']['name']); |
301 | 300 | continue; |
302 | 301 | } |
303 | 302 | // find prop to expand |
304 | - foreach($prop_files['files'][0]['props'] as $expand_prop) |
|
303 | + foreach ($prop_files['files'][0]['props'] as $expand_prop) |
|
305 | 304 | { |
306 | 305 | if ($expand_prop['name'] === $prop_name) break; |
307 | 306 | } |
@@ -315,7 +314,7 @@ discard block |
||
315 | 314 | // requested properties of each href are in depth=2 properties |
316 | 315 | // set them as regular propfind properties to $options['props'] |
317 | 316 | $options2 = array('props' => 'all'); |
318 | - while(($prop = array_shift($requested_props)) && $prop['depth'] >= 2) |
|
317 | + while (($prop = array_shift($requested_props)) && $prop['depth'] >= 2) |
|
319 | 318 | { |
320 | 319 | if ($prop['name'] == 'property' && $prop['depth'] == 2) |
321 | 320 | { |
@@ -331,10 +330,10 @@ discard block |
||
331 | 330 | } |
332 | 331 | // put back evtl. read top-level property |
333 | 332 | if ($prop && $prop['depth'] == 1) array_unshift($requested_props, $prop); |
334 | - $this->caldav->options = $options2; // also modify global variable |
|
333 | + $this->caldav->options = $options2; // also modify global variable |
|
335 | 334 | |
336 | 335 | // run regular profind to get requested 2.-level properties for each href |
337 | - foreach($expand_prop['val'] as $key => &$prop_val) |
|
336 | + foreach ($expand_prop['val'] as $key => &$prop_val) |
|
338 | 337 | { |
339 | 338 | list(,$expand_path) = explode($this->caldav->base_uri, $prop_val['val']); |
340 | 339 | //error_log(__METHOD__."('$path', ..., $user) calling propfind('$expand_path', ".array2string($options2).', '.array2string($prop_val).", $user)"); |
@@ -429,23 +428,23 @@ discard block |
||
429 | 428 | * @param int $user account_id |
430 | 429 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
431 | 430 | */ |
432 | - function principal_property_search_report($path,&$options,&$files,$user) |
|
431 | + function principal_property_search_report($path, &$options, &$files, $user) |
|
433 | 432 | { |
434 | 433 | //error_log(__METHOD__."('$path', ".array2string($options).",, $user)"); |
435 | 434 | |
436 | 435 | // cant find the test attribute to root principal-property-search element in WebDAV rfc, but iPhones use it ... |
437 | - $anyof = !empty($options['root']['attrs']['test']) && $options['root']['attrs']['test'] == 'anyof'; // "allof" (default) or "anyof" |
|
436 | + $anyof = !empty($options['root']['attrs']['test']) && $options['root']['attrs']['test'] == 'anyof'; // "allof" (default) or "anyof" |
|
438 | 437 | |
439 | 438 | // parse property-search prop(s) contained in $options['other'] |
440 | - foreach($options['other'] as $n => $prop) |
|
439 | + foreach ($options['other'] as $n => $prop) |
|
441 | 440 | { |
442 | - switch($prop['name']) |
|
441 | + switch ($prop['name']) |
|
443 | 442 | { |
444 | 443 | case 'apply-to-principal-collection-set': // optinal prop to apply search on principal-collection-set == '/principals/' |
445 | 444 | $path = '/principals/'; |
446 | 445 | break; |
447 | 446 | case 'property-search': |
448 | - $property_search = $n; // should be 1 |
|
447 | + $property_search = $n; // should be 1 |
|
449 | 448 | break; |
450 | 449 | case 'prop': |
451 | 450 | if (isset($property_search)) |
@@ -475,7 +474,7 @@ discard block |
||
475 | 474 | return '400 Bad Request'; |
476 | 475 | } |
477 | 476 | // make sure search property is included in toplevel props (can be missing and defaults to property-search/prop's) |
478 | - foreach($search_props as $prop) |
|
477 | + foreach ($search_props as $prop) |
|
479 | 478 | { |
480 | 479 | if (!$this->caldav->prop_requested($prop['name'], $prop['xmlns'])) |
481 | 480 | { |
@@ -488,7 +487,7 @@ discard block |
||
488 | 487 | // but interprets returning all principals (all have a matching calendar-home-set) as NOT supporting CalDAV scheduling |
489 | 488 | // --> search only current user's principal |
490 | 489 | if ($prop['name'] == 'calendar-home-set' && stripos($_SERVER['HTTP_USER_AGENT'], 'Lightning') !== false && |
491 | - substr($search_props[0]['match'],-13) == '/groupdav.php') |
|
490 | + substr($search_props[0]['match'], -13) == '/groupdav.php') |
|
492 | 491 | { |
493 | 492 | $path = '/principals/users/'.$GLOBALS['egw_info']['user']['account_lid'].'/'; |
494 | 493 | $this->caldav->log('Enabling hack for Lightning prior 1.1.1 for searching calendar-home-set matching "/groupdav.php": limiting search to '.$path); |
@@ -497,7 +496,7 @@ discard block |
||
497 | 496 | // check type attribute to limit search on a certain tree |
498 | 497 | if (isset($options['root']['attrs']['type'])) |
499 | 498 | { |
500 | - switch($options['root']['attrs']['type']) |
|
499 | + switch ($options['root']['attrs']['type']) |
|
501 | 500 | { |
502 | 501 | case 'INDIVIDUAL': |
503 | 502 | $path = '/principals/users/'; |
@@ -524,7 +523,7 @@ discard block |
||
524 | 523 | return $ret; |
525 | 524 | } |
526 | 525 | // now filter out not matching "files" |
527 | - foreach($files['files'] as $n => $resource) |
|
526 | + foreach ($files['files'] as $n => $resource) |
|
528 | 527 | { |
529 | 528 | if (count(explode('/', $resource['path'])) < 5) // hack to only return principals, not the collections itself |
530 | 529 | { |
@@ -533,18 +532,18 @@ discard block |
||
533 | 532 | } |
534 | 533 | // match with $search_props |
535 | 534 | $matches = 0; |
536 | - foreach($search_props as $search_prop) |
|
535 | + foreach ($search_props as $search_prop) |
|
537 | 536 | { |
538 | 537 | // search resource for $search_prop |
539 | - foreach($resource['props'] as $prop) |
|
538 | + foreach ($resource['props'] as $prop) |
|
540 | 539 | { |
541 | 540 | if ($prop['name'] === $search_prop['name']) break; |
542 | 541 | } |
543 | 542 | if ($prop['name'] === $search_prop['name']) // search_prop NOT found |
544 | 543 | { |
545 | - foreach((array)$prop['val'] as $value) |
|
544 | + foreach ((array)$prop['val'] as $value) |
|
546 | 545 | { |
547 | - if (is_array($value)) $value = $value['val']; // eg. href prop |
|
546 | + if (is_array($value)) $value = $value['val']; // eg. href prop |
|
548 | 547 | if (self::match($value, $search_prop['match'], $search_prop['match-type']) !== false) // prop does match |
549 | 548 | { |
550 | 549 | ++$matches; |
@@ -556,7 +555,7 @@ discard block |
||
556 | 555 | if ($anyof && $matches || $matches == count($search_props)) |
557 | 556 | { |
558 | 557 | //error_log("$resource[path]: anyof=$anyof, $matches matches --> keep"); |
559 | - continue 2; // enough matches --> keep |
|
558 | + continue 2; // enough matches --> keep |
|
560 | 559 | } |
561 | 560 | } |
562 | 561 | //error_log("$resource[path]: anyof=$anyof, $matches matches --> skip"); |
@@ -574,9 +573,9 @@ discard block |
||
574 | 573 | * @param string $match criteria/sub-string |
575 | 574 | * @param string $match_type ='contains' 'starts-with', 'ends-with' or 'equals' |
576 | 575 | */ |
577 | - private static function match($value, $match, $match_type='contains') |
|
576 | + private static function match($value, $match, $match_type = 'contains') |
|
578 | 577 | { |
579 | - switch($match_type) |
|
578 | + switch ($match_type) |
|
580 | 579 | { |
581 | 580 | case 'equals': |
582 | 581 | return $value === $match; |
@@ -646,9 +645,9 @@ discard block |
||
646 | 645 | * @param int $user account_id |
647 | 646 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
648 | 647 | */ |
649 | - function principal_search_property_set_report($path,&$options,&$files,$user) |
|
648 | + function principal_search_property_set_report($path, &$options, &$files, $user) |
|
650 | 649 | { |
651 | - unset($path, $options, $files, $user); // not used, but required by function signature |
|
650 | + unset($path, $options, $files, $user); // not used, but required by function signature |
|
652 | 651 | |
653 | 652 | static $search_props = array( |
654 | 653 | // from iOS iCal |
@@ -670,7 +669,7 @@ discard block |
||
670 | 669 | $xml->startDocument('1.0', 'UTF-8'); |
671 | 670 | $xml->startElementNs(null, 'principal-search-property-set', 'DAV:'); |
672 | 671 | |
673 | - foreach($search_props as $name => $data) |
|
672 | + foreach ($search_props as $name => $data) |
|
674 | 673 | { |
675 | 674 | $xml->startElement('principal-search-property'); |
676 | 675 | $xml->startElement('prop'); |
@@ -682,16 +681,16 @@ discard block |
||
682 | 681 | { |
683 | 682 | $xml->writeElement($name); |
684 | 683 | } |
685 | - $xml->endElement(); // prop |
|
684 | + $xml->endElement(); // prop |
|
686 | 685 | |
687 | 686 | $xml->startElement('description'); |
688 | 687 | $xml->writeAttribute('xml:lang', 'en'); |
689 | 688 | $xml->text(is_array($data) ? $data['description'] : $data); |
690 | - $xml->endElement(); // description |
|
689 | + $xml->endElement(); // description |
|
691 | 690 | |
692 | - $xml->endElement(); // principal-search-property |
|
691 | + $xml->endElement(); // principal-search-property |
|
693 | 692 | } |
694 | - $xml->endElement(); // principal-search-property-set |
|
693 | + $xml->endElement(); // principal-search-property-set |
|
695 | 694 | $xml->endDocument(); |
696 | 695 | echo $xml->outputMemory(); |
697 | 696 | |
@@ -726,7 +725,7 @@ discard block |
||
726 | 725 | * @param int $user account_id |
727 | 726 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
728 | 727 | */ |
729 | - function acl_principal_prop_set_report($path,&$options,&$files,$user) |
|
728 | + function acl_principal_prop_set_report($path, &$options, &$files, $user) |
|
730 | 729 | { |
731 | 730 | //error_log(__METHOD__."('$path', ".array2string($options).",, $user)"); |
732 | 731 | |
@@ -745,13 +744,13 @@ discard block |
||
745 | 744 | return $ret; |
746 | 745 | } |
747 | 746 | // now filter out not matching "files" |
748 | - foreach($files['files'] as $n => $resource) |
|
747 | + foreach ($files['files'] as $n => $resource) |
|
749 | 748 | { |
750 | - foreach($resource['props']['resourcetype']['val'] as $prop) |
|
749 | + foreach ($resource['props']['resourcetype']['val'] as $prop) |
|
751 | 750 | { |
752 | 751 | if ($prop['name'] == 'principal') continue 2; |
753 | 752 | } |
754 | - unset($files['files'][$n]); // not a principal --> do not return |
|
753 | + unset($files['files'][$n]); // not a principal --> do not return |
|
755 | 754 | } |
756 | 755 | // we should not return it |
757 | 756 | unset($options['props']['resourcetype']); |
@@ -767,7 +766,7 @@ discard block |
||
767 | 766 | * @param array $options |
768 | 767 | * @return array|string array with files or HTTP error code |
769 | 768 | */ |
770 | - protected function propfind_users($name,$rest,array $options) |
|
769 | + protected function propfind_users($name, $rest, array $options) |
|
771 | 770 | { |
772 | 771 | //error_log(__METHOD__."($name,$rest,".array2string($options).')'); |
773 | 772 | if (empty($name)) |
@@ -786,7 +785,7 @@ discard block |
||
786 | 785 | else |
787 | 786 | { |
788 | 787 | // add all users (account_selection == groupmembers is handled by accounts->search()) |
789 | - foreach($this->accounts->search(array('type' => 'accounts','order' => 'account_lid')) as $account) |
|
788 | + foreach ($this->accounts->search(array('type' => 'accounts', 'order' => 'account_lid')) as $account) |
|
790 | 789 | { |
791 | 790 | $files[] = $this->add_account($account); |
792 | 791 | } |
@@ -795,18 +794,18 @@ discard block |
||
795 | 794 | } |
796 | 795 | else |
797 | 796 | { |
798 | - if (!($id = $this->accounts->name2id($name,'account_lid','u')) || |
|
797 | + if (!($id = $this->accounts->name2id($name, 'account_lid', 'u')) || |
|
799 | 798 | !($account = $this->accounts->read($id)) || |
800 | 799 | !$this->accounts->visible($name)) |
801 | 800 | { |
802 | 801 | $this->caldav->log(__METHOD__."('$name', ...) account '$name' NOT found OR not visible to you (check account-selection preference)!"); |
803 | 802 | return '404 Not Found'; |
804 | 803 | } |
805 | - while (substr($rest,-1) == '/') |
|
804 | + while (substr($rest, -1) == '/') |
|
806 | 805 | { |
807 | - $rest = substr($rest,0,-1); |
|
806 | + $rest = substr($rest, 0, -1); |
|
808 | 807 | } |
809 | - switch((string)$rest) |
|
808 | + switch ((string)$rest) |
|
810 | 809 | { |
811 | 810 | case '': |
812 | 811 | $files[] = $this->add_account($account); |
@@ -836,7 +835,7 @@ discard block |
||
836 | 835 | * @param array $options |
837 | 836 | * @return array|string array with files or HTTP error code |
838 | 837 | */ |
839 | - protected function propfind_groups($name,$rest,array $options) |
|
838 | + protected function propfind_groups($name, $rest, array $options) |
|
840 | 839 | { |
841 | 840 | //echo "<p>".__METHOD__."($name,$rest,".array2string($options).")</p>\n"; |
842 | 841 | if (empty($name)) |
@@ -848,11 +847,11 @@ discard block |
||
848 | 847 | if ($options['depth']) |
849 | 848 | { |
850 | 849 | // only show own groups, if account-selection is groupmembers or none |
851 | - $type = in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers','none')) ? |
|
850 | + $type = in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers', 'none')) ? |
|
852 | 851 | 'owngroups' : 'groups'; |
853 | 852 | |
854 | 853 | // add all groups or only membergroups |
855 | - foreach($this->accounts->search(array('type' => $type,'order' => 'account_lid')) as $account) |
|
854 | + foreach ($this->accounts->search(array('type' => $type, 'order' => 'account_lid')) as $account) |
|
856 | 855 | { |
857 | 856 | $files[] = $this->add_group($account); |
858 | 857 | } |
@@ -860,19 +859,19 @@ discard block |
||
860 | 859 | } |
861 | 860 | else |
862 | 861 | { |
863 | - if (!($id = $this->accounts->name2id($name,'account_lid','g')) || |
|
862 | + if (!($id = $this->accounts->name2id($name, 'account_lid', 'g')) || |
|
864 | 863 | !($account = $this->accounts->read($id)) || |
865 | 864 | // do NOT allow other groups, if account-selection is groupmembers or none |
866 | - in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers','none')) && |
|
867 | - !in_array($account['account_id'], $this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true))) |
|
865 | + in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('groupmembers', 'none')) && |
|
866 | + !in_array($account['account_id'], $this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true))) |
|
868 | 867 | { |
869 | 868 | return '404 Not Found'; |
870 | 869 | } |
871 | - while (substr($rest,-1) == '/') |
|
870 | + while (substr($rest, -1) == '/') |
|
872 | 871 | { |
873 | - $rest = substr($rest,0,-1); |
|
872 | + $rest = substr($rest, 0, -1); |
|
874 | 873 | } |
875 | - switch((string)$rest) |
|
874 | + switch ((string)$rest) |
|
876 | 875 | { |
877 | 876 | case '': |
878 | 877 | $files[] = $this->add_group($account); |
@@ -903,10 +902,10 @@ discard block |
||
903 | 902 | { |
904 | 903 | $addressbooks = array(); |
905 | 904 | $ab_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set']; |
906 | - if (empty($ab_home_set)) $ab_home_set = 'P'; // personal addressbook |
|
905 | + if (empty($ab_home_set)) $ab_home_set = 'P'; // personal addressbook |
|
907 | 906 | $addressbook_home_set = explode(',', $ab_home_set); |
908 | 907 | // replace symbolic id's with real nummeric id's |
909 | - foreach(array( |
|
908 | + foreach (array( |
|
910 | 909 | 'P' => $GLOBALS['egw_info']['user']['account_id'], |
911 | 910 | 'G' => $GLOBALS['egw_info']['user']['account_primary_group'], |
912 | 911 | 'U' => '0', |
@@ -917,13 +916,13 @@ discard block |
||
917 | 916 | $addressbook_home_set[$key] = $id; |
918 | 917 | } |
919 | 918 | } |
920 | - if (in_array('O',$addressbook_home_set)) // "all in one" from groupdav.php/addressbook/ |
|
919 | + if (in_array('O', $addressbook_home_set)) // "all in one" from groupdav.php/addressbook/ |
|
921 | 920 | { |
922 | 921 | $addressbooks[] = '/'; |
923 | 922 | } |
924 | - foreach(array_keys($GLOBALS['egw']->contacts->get_addressbooks(Api\Acl::READ)) as $id) |
|
923 | + foreach (array_keys($GLOBALS['egw']->contacts->get_addressbooks(Api\Acl::READ)) as $id) |
|
925 | 924 | { |
926 | - if ((in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) && |
|
925 | + if ((in_array('A', $addressbook_home_set) || in_array((string)$id, $addressbook_home_set)) && |
|
927 | 926 | is_numeric($id) && ($owner = $this->accounts->id2name($id))) |
928 | 927 | { |
929 | 928 | $addressbooks[] = '/'.$owner.'/'; |
@@ -947,45 +946,45 @@ discard block |
||
947 | 946 | $calendars[] = Api\CalDAV::mkprop('href', |
948 | 947 | $this->base_uri.'/'.$account['account_lid'].'/'); |
949 | 948 | |
950 | - $displayname = Api\Translation::convert($account['account_fullname'], Api\Translation::charset(),'utf-8'); |
|
949 | + $displayname = Api\Translation::convert($account['account_fullname'], Api\Translation::charset(), 'utf-8'); |
|
951 | 950 | |
952 | 951 | return $this->add_principal('users/'.$account['account_lid'], array( |
953 | 952 | 'getetag' => $this->get_etag($account), |
954 | 953 | 'displayname' => $displayname, |
955 | 954 | // CalDAV |
956 | - 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-home-set',$calendars), |
|
955 | + 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-home-set', $calendars), |
|
957 | 956 | // CalDAV scheduling |
958 | - 'schedule-outbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'schedule-outbox-URL',array( |
|
959 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/outbox/'))), |
|
960 | - 'schedule-inbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'schedule-inbox-URL',array( |
|
961 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/inbox/'))), |
|
962 | - 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-address-set',array( |
|
963 | - Api\CalDAV::mkprop('href','mailto:'.$account['account_email']), |
|
964 | - Api\CalDAV::mkprop('href',$this->base_uri(true).'/principals/users/'.$account['account_lid'].'/'), |
|
965 | - Api\CalDAV::mkprop('href',$this->base_uri(false).'/principals/users/'.$account['account_lid'].'/'), |
|
966 | - Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
957 | + 'schedule-outbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'schedule-outbox-URL', array( |
|
958 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/outbox/'))), |
|
959 | + 'schedule-inbox-URL' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'schedule-inbox-URL', array( |
|
960 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/inbox/'))), |
|
961 | + 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-address-set', array( |
|
962 | + Api\CalDAV::mkprop('href', 'mailto:'.$account['account_email']), |
|
963 | + Api\CalDAV::mkprop('href', $this->base_uri(true).'/principals/users/'.$account['account_lid'].'/'), |
|
964 | + Api\CalDAV::mkprop('href', $this->base_uri(false).'/principals/users/'.$account['account_lid'].'/'), |
|
965 | + Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
967 | 966 | )), |
968 | - 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-type','INDIVIDUAL'), |
|
967 | + 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-type', 'INDIVIDUAL'), |
|
969 | 968 | // Calendarserver |
970 | - 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'email-address-set',array( |
|
971 | - Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'email-address',$account['account_email']))), |
|
972 | - 'last-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'last-name',$account['account_lastname']), |
|
973 | - 'first-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'first-name',$account['account_firstname']), |
|
974 | - 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'record-type','users'), |
|
969 | + 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'email-address-set', array( |
|
970 | + Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'email-address', $account['account_email']))), |
|
971 | + 'last-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'last-name', $account['account_lastname']), |
|
972 | + 'first-name' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'first-name', $account['account_firstname']), |
|
973 | + 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'record-type', 'users'), |
|
975 | 974 | // WebDAV ACL and CalDAV proxy |
976 | 975 | 'group-membership' => $this->principal_set('group-membership', $this->accounts->memberships($account['account_id']), |
977 | - array('calendar', 'resources'), $account['account_id']), // add proxy-rights |
|
976 | + array('calendar', 'resources'), $account['account_id']), // add proxy-rights |
|
978 | 977 | 'alternate-URI-set' => array( |
979 | - Api\CalDAV::mkprop('href','mailto:'.$account['account_email'])), |
|
978 | + Api\CalDAV::mkprop('href', 'mailto:'.$account['account_email'])), |
|
980 | 979 | // CardDAV |
981 | - 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV,'addressbook-home-set',$addressbooks), |
|
982 | - 'principal-address' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV,'principal-address', |
|
980 | + 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'addressbook-home-set', $addressbooks), |
|
981 | + 'principal-address' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'principal-address', |
|
983 | 982 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] ? '' : array( |
984 | - Api\CalDAV::mkprop('href',$this->base_uri.'/addressbook-accounts/'.$account['person_id'].'.vcf'))), |
|
983 | + Api\CalDAV::mkprop('href', $this->base_uri.'/addressbook-accounts/'.$account['person_id'].'.vcf'))), |
|
985 | 984 | // CardDAV directory |
986 | - 'directory-gateway' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'directory-gateway',array( |
|
985 | + 'directory-gateway' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'directory-gateway', array( |
|
987 | 986 | Api\CalDAV::mkprop('href', $this->base_uri.'/addressbook/'))), |
988 | - 'resource-id' => array(Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
987 | + 'resource-id' => array(Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
989 | 988 | )); |
990 | 989 | } |
991 | 990 | |
@@ -997,7 +996,7 @@ discard block |
||
997 | 996 | * @param string $cn =null common name to be stored in case of an "e" uid |
998 | 997 | * @return int|string|boolean integer account_id, string calendar uid or false if not a supported uid |
999 | 998 | */ |
1000 | - static public function url2uid($url, $only_type=null, $cn=null) |
|
999 | + static public function url2uid($url, $only_type = null, $cn = null) |
|
1001 | 1000 | { |
1002 | 1001 | if (!$only_type) $only_type = array('users', 'groups', 'resources', 'locations', 'mailto'); |
1003 | 1002 | |
@@ -1011,17 +1010,17 @@ discard block |
||
1011 | 1010 | } |
1012 | 1011 | if (empty($rest)) return false; |
1013 | 1012 | |
1014 | - switch(strtolower($schema)) |
|
1013 | + switch (strtolower($schema)) |
|
1015 | 1014 | { |
1016 | 1015 | case 'http': |
1017 | 1016 | case 'https': |
1018 | 1017 | list(,$rest) = explode('/groupdav.php/principals/', $url); |
1019 | 1018 | list($type, $name) = explode('/', $rest); |
1020 | - switch($type) |
|
1019 | + switch ($type) |
|
1021 | 1020 | { |
1022 | 1021 | case 'users': |
1023 | 1022 | case 'groups': |
1024 | - $uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid', $type[0]); // u=users, g=groups |
|
1023 | + $uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid', $type[0]); // u=users, g=groups |
|
1025 | 1024 | break; |
1026 | 1025 | case 'resources': |
1027 | 1026 | case 'locations': |
@@ -1038,9 +1037,9 @@ discard block |
||
1038 | 1037 | } |
1039 | 1038 | // search contacts for email |
1040 | 1039 | if ((list($data) = $GLOBALS['egw']->contacts->search(array('email' => $rest, 'email_home' => $rest), |
1041 | - array('id','egw_addressbook.account_id as account_id','n_fn'), |
|
1040 | + array('id', 'egw_addressbook.account_id as account_id', 'n_fn'), |
|
1042 | 1041 | 'egw_addressbook.account_id IS NOT NULL DESC, n_fn IS NOT NULL DESC', |
1043 | - '','',false,'OR'))) |
|
1042 | + '', '', false, 'OR'))) |
|
1044 | 1043 | { |
1045 | 1044 | // found an addressbook entry |
1046 | 1045 | $uid = $data['account_id'] ? (int)$data['account_id'] : 'c'.$data['id']; |
@@ -1058,7 +1057,7 @@ discard block |
||
1058 | 1057 | list($type, $id, $install_id) = explode('-', $uid); |
1059 | 1058 | if ($type == 'accounts' && empty($id)) // groups have a negative id, eg. "urn:uuid:accounts--1-..." |
1060 | 1059 | { |
1061 | - list($type, , $id_abs, $install_id) = explode('-', $uid); |
|
1060 | + list($type,, $id_abs, $install_id) = explode('-', $uid); |
|
1062 | 1061 | $id = -$id_abs; |
1063 | 1062 | } |
1064 | 1063 | // own urn |
@@ -1071,9 +1070,9 @@ discard block |
||
1071 | 1070 | } |
1072 | 1071 | else |
1073 | 1072 | { |
1074 | - static $calendar_bo=null; |
|
1073 | + static $calendar_bo = null; |
|
1075 | 1074 | if (is_null($calendar_bo)) $calendar_bo = new calendar_bo(); |
1076 | - foreach($calendar_bo->resources as $letter => $info) |
|
1075 | + foreach ($calendar_bo->resources as $letter => $info) |
|
1077 | 1076 | { |
1078 | 1077 | if ($info['app'] == $type || $info['app'] == 'resources' && $type == 'location') |
1079 | 1078 | { |
@@ -1086,7 +1085,7 @@ discard block |
||
1086 | 1085 | break; |
1087 | 1086 | |
1088 | 1087 | default: |
1089 | - if (isset($GLOBALS['groupdav']) && is_a($GLOBALS['groupdav'],'groupdav')) |
|
1088 | + if (isset($GLOBALS['groupdav']) && is_a($GLOBALS['groupdav'], 'groupdav')) |
|
1090 | 1089 | { |
1091 | 1090 | $GLOBALS['groupdav']->log(__METHOD__."('$url') unsupported principal URL '$url'!"); |
1092 | 1091 | } |
@@ -1104,7 +1103,7 @@ discard block |
||
1104 | 1103 | */ |
1105 | 1104 | protected function add_group(array $account) |
1106 | 1105 | { |
1107 | - $displayname = Api\Translation::convert(lang('Group').' '.$account['account_lid'], Api\Translation::charset(), 'utf-8'); |
|
1106 | + $displayname = Api\Translation::convert(lang('Group').' '.$account['account_lid'], Api\Translation::charset(), 'utf-8'); |
|
1108 | 1107 | |
1109 | 1108 | // only return current user, if account-selection == 'none' |
1110 | 1109 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none') |
@@ -1119,19 +1118,19 @@ discard block |
||
1119 | 1118 | return $this->add_principal('groups/'.$account['account_lid'], array( |
1120 | 1119 | 'getetag' => $this->get_etag($account), |
1121 | 1120 | 'displayname' => $displayname, |
1122 | - 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-home-set',array( |
|
1123 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1124 | - 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV,'addressbook-home-set',array( |
|
1125 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1126 | - 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-address-set',array( |
|
1127 | - Api\CalDAV::mkprop('href',$this->base_uri(true).'/principals/groups/'.$account['account_lid'].'/'), |
|
1128 | - Api\CalDAV::mkprop('href',$this->base_uri(false).'/principals/groups/'.$account['account_lid'].'/'), |
|
1129 | - Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
1121 | + 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-home-set', array( |
|
1122 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1123 | + 'addressbook-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CARDDAV, 'addressbook-home-set', array( |
|
1124 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/'))), |
|
1125 | + 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-address-set', array( |
|
1126 | + Api\CalDAV::mkprop('href', $this->base_uri(true).'/principals/groups/'.$account['account_lid'].'/'), |
|
1127 | + Api\CalDAV::mkprop('href', $this->base_uri(false).'/principals/groups/'.$account['account_lid'].'/'), |
|
1128 | + Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id'])), |
|
1130 | 1129 | )), |
1131 | - 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'record-type','groups'), |
|
1132 | - 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-type','GROUP'), |
|
1130 | + 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'record-type', 'groups'), |
|
1131 | + 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-type', 'GROUP'), |
|
1133 | 1132 | 'group-member-set' => $this->principal_set('group-member-set', $groupmembers), |
1134 | - 'resource-id' => array(Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
1133 | + 'resource-id' => array(Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $account['account_id']))), |
|
1135 | 1134 | )); |
1136 | 1135 | } |
1137 | 1136 | |
@@ -1142,7 +1141,7 @@ discard block |
||
1142 | 1141 | * @param boolean $is_location =null |
1143 | 1142 | * @return array with values for keys 'path' and 'props' |
1144 | 1143 | */ |
1145 | - protected function add_principal_resource(array $resource, $is_location=null) |
|
1144 | + protected function add_principal_resource(array $resource, $is_location = null) |
|
1146 | 1145 | { |
1147 | 1146 | $displayname = null; |
1148 | 1147 | $name = $this->resource2name($resource, $is_location, $displayname); |
@@ -1150,18 +1149,18 @@ discard block |
||
1150 | 1149 | return $this->add_principal($name, array( |
1151 | 1150 | 'getetag' => $this->get_resource_etag($resource), |
1152 | 1151 | 'displayname' => $displayname, |
1153 | - 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-address-set',array( |
|
1154 | - Api\CalDAV::mkprop('href',$this->base_uri(true).'/principals/'.$name.'/'), |
|
1155 | - Api\CalDAV::mkprop('href',$this->base_uri(false).'/principals/'.$name.'/'), |
|
1156 | - Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id'])), |
|
1152 | + 'calendar-user-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-address-set', array( |
|
1153 | + Api\CalDAV::mkprop('href', $this->base_uri(true).'/principals/'.$name.'/'), |
|
1154 | + Api\CalDAV::mkprop('href', $this->base_uri(false).'/principals/'.$name.'/'), |
|
1155 | + Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id'])), |
|
1157 | 1156 | )), |
1158 | - 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'record-type',$is_location ? 'locations' : 'resources'), |
|
1159 | - 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-user-type',$is_location ? 'ROOM' : 'RESOURCE'), |
|
1160 | - 'resource-id' => array(Api\CalDAV::mkprop('href','urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id']))), |
|
1157 | + 'record-type' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'record-type', $is_location ? 'locations' : 'resources'), |
|
1158 | + 'calendar-user-type' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-user-type', $is_location ? 'ROOM' : 'RESOURCE'), |
|
1159 | + 'resource-id' => array(Api\CalDAV::mkprop('href', 'urn:uuid:'.Api\CalDAV::generate_uid('resources', $resource['res_id']))), |
|
1161 | 1160 | // Calendarserver also reports empty email-address-set, thought iCal still does not show resources (only locations) |
1162 | - 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER,'email-address-set',''), |
|
1163 | - 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-home-set',array( |
|
1164 | - Api\CalDAV::mkprop('href',$this->base_uri.'/'.$name.'/'))), |
|
1161 | + 'email-address-set' => Api\CalDAV::mkprop(Api\CalDAV::CALENDARSERVER, 'email-address-set', ''), |
|
1162 | + 'calendar-home-set' => Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-home-set', array( |
|
1163 | + Api\CalDAV::mkprop('href', $this->base_uri.'/'.$name.'/'))), |
|
1165 | 1164 | )); |
1166 | 1165 | } |
1167 | 1166 | |
@@ -1173,7 +1172,7 @@ discard block |
||
1173 | 1172 | * @param string &$displayname=null on return displayname of resource |
1174 | 1173 | * @return string eg. "locations/123-some-room" or "resouces/345-some-device" |
1175 | 1174 | */ |
1176 | - public static function resource2name($resource, &$is_location=null, &$displayname=null) |
|
1175 | + public static function resource2name($resource, &$is_location = null, &$displayname = null) |
|
1177 | 1176 | { |
1178 | 1177 | if (!is_array($resource) && !($resource = self::read_resource($resource))) |
1179 | 1178 | { |
@@ -1181,10 +1180,10 @@ discard block |
||
1181 | 1180 | } |
1182 | 1181 | if (is_null($is_location)) $is_location = self::resource_is_location($resource); |
1183 | 1182 | |
1184 | - $displayname = Api\Translation::convert($resource['name'], Api\Translation::charset(), 'utf-8'); |
|
1183 | + $displayname = Api\Translation::convert($resource['name'], Api\Translation::charset(), 'utf-8'); |
|
1185 | 1184 | |
1186 | 1185 | return ($is_location ? 'locations/' : 'resources/').$resource['res_id'].'-'. |
1187 | - preg_replace('/[^a-z0-9]+/i','-', Api\Translation::to_ascii($resource['name'])); |
|
1186 | + preg_replace('/[^a-z0-9]+/i', '-', Api\Translation::to_ascii($resource['name'])); |
|
1188 | 1187 | } |
1189 | 1188 | |
1190 | 1189 | /** |
@@ -1195,7 +1194,7 @@ discard block |
||
1195 | 1194 | */ |
1196 | 1195 | public static function resource_is_location($resource) |
1197 | 1196 | { |
1198 | - static $location_cats=null; |
|
1197 | + static $location_cats = null; |
|
1199 | 1198 | if (is_null($location_cats)) |
1200 | 1199 | { |
1201 | 1200 | $config = Api\Config::read('resources'); |
@@ -1216,7 +1215,7 @@ discard block |
||
1216 | 1215 | */ |
1217 | 1216 | public static function read_resource($res_id) |
1218 | 1217 | { |
1219 | - static $cache=null; // some per-request caching |
|
1218 | + static $cache = null; // some per-request caching |
|
1220 | 1219 | |
1221 | 1220 | if (isset(self::$all_resources) && isset(self::$all_resources[$res_id])) |
1222 | 1221 | { |
@@ -1258,7 +1257,7 @@ discard block |
||
1258 | 1257 | * @param int $user =null account_if of user, or null for current user |
1259 | 1258 | * @return array of array with values for res_id, cat_id and name (no other values1) |
1260 | 1259 | */ |
1261 | - public static function get_resources($user=null) |
|
1260 | + public static function get_resources($user = null) |
|
1262 | 1261 | { |
1263 | 1262 | if (!isset(self::$all_resources)) |
1264 | 1263 | { |
@@ -1266,18 +1265,18 @@ discard block |
||
1266 | 1265 | |
1267 | 1266 | self::$all_resources = array(); |
1268 | 1267 | $query = array( |
1269 | - 'show_bookable' => true, // ignore non-bookable resources |
|
1268 | + 'show_bookable' => true, // ignore non-bookable resources |
|
1270 | 1269 | 'filter2' => -3, |
1271 | 1270 | 'start' => 0, |
1272 | - 'num_rows' => 10000, // return all aka first 10000 entries |
|
1271 | + 'num_rows' => 10000, // return all aka first 10000 entries |
|
1273 | 1272 | ); |
1274 | 1273 | $rows = $readonlys = null; |
1275 | 1274 | if (self::$resources->get_rows($query, $rows, $readonlys)) |
1276 | 1275 | { |
1277 | 1276 | //_debug_array($rows); |
1278 | - foreach($rows as $resource) |
|
1277 | + foreach ($rows as $resource) |
|
1279 | 1278 | { |
1280 | - self::$all_resources[$resource['res_id']] = array_intersect_key($resource, array('res_id'=>true,'cat_id'=>true,'name'=>true)); |
|
1279 | + self::$all_resources[$resource['res_id']] = array_intersect_key($resource, array('res_id'=>true, 'cat_id'=>true, 'name'=>true)); |
|
1281 | 1280 | } |
1282 | 1281 | } |
1283 | 1282 | } |
@@ -1293,7 +1292,7 @@ discard block |
||
1293 | 1292 | */ |
1294 | 1293 | protected function get_resource_rights() |
1295 | 1294 | { |
1296 | - static $grants=null; |
|
1295 | + static $grants = null; |
|
1297 | 1296 | |
1298 | 1297 | if (is_null($grants)) |
1299 | 1298 | { |
@@ -1326,19 +1325,19 @@ discard block |
||
1326 | 1325 | * @param string $principal_url =null include given principal url, relative to principal-collection-set, default $principal |
1327 | 1326 | * @return array with values for keys 'path' and 'props' |
1328 | 1327 | */ |
1329 | - protected function add_principal($principal, array $props = array(), $principal_url=null) |
|
1328 | + protected function add_principal($principal, array $props = array(), $principal_url = null) |
|
1330 | 1329 | { |
1331 | 1330 | $props['resourcetype'][] = Api\CalDAV::mkprop('principal', ''); |
1332 | 1331 | |
1333 | 1332 | // required props per WebDAV ACL |
1334 | - foreach(array('alternate-URI-set', 'group-membership') as $name) |
|
1333 | + foreach (array('alternate-URI-set', 'group-membership') as $name) |
|
1335 | 1334 | { |
1336 | - if (!isset($props[$name])) $props[$name] = Api\CalDAV::mkprop($name,''); |
|
1335 | + if (!isset($props[$name])) $props[$name] = Api\CalDAV::mkprop($name, ''); |
|
1337 | 1336 | } |
1338 | 1337 | if (!$principal_url) $principal_url = $principal; |
1339 | 1338 | |
1340 | 1339 | $props['principal-URL'] = array( |
1341 | - Api\CalDAV::mkprop('href',$this->base_uri.'/principals/'.$principal.'/')); |
|
1340 | + Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'.$principal.'/')); |
|
1342 | 1341 | |
1343 | 1342 | return $this->add_collection('/principals/'.$principal.'/', $props); |
1344 | 1343 | } |
@@ -1354,20 +1353,20 @@ discard block |
||
1354 | 1353 | * @param array $resource =null resource to use (to not query it multiple times from the database) |
1355 | 1354 | * @return array with values for 'path' and 'props' |
1356 | 1355 | */ |
1357 | - protected function add_proxys($principal, $type, array $proxys=array(), array $resource=null) |
|
1356 | + protected function add_proxys($principal, $type, array $proxys = array(), array $resource = null) |
|
1358 | 1357 | { |
1359 | 1358 | list($app,,$what) = explode('-', $type); |
1360 | 1359 | |
1361 | - if (true) $proxys = array(); // ignore parameter! |
|
1362 | - list($account_type,$account) = explode('/', $principal); |
|
1360 | + if (true) $proxys = array(); // ignore parameter! |
|
1361 | + list($account_type, $account) = explode('/', $principal); |
|
1363 | 1362 | |
1364 | - switch($account_type) |
|
1363 | + switch ($account_type) |
|
1365 | 1364 | { |
1366 | 1365 | case 'users': |
1367 | 1366 | case 'groups': |
1368 | 1367 | $account = $location = $this->accounts->name2id($account, 'account_lid', $account_type[0]); |
1369 | 1368 | $right = $what == 'write' ? Api\Acl::EDIT : Api\Acl::READ; |
1370 | - $mask = $what == 'write' ? Api\Acl::EDIT : Api\Acl::EDIT|Api\Acl::READ; // do NOT report write+read in read |
|
1369 | + $mask = $what == 'write' ? Api\Acl::EDIT : Api\Acl::EDIT|Api\Acl::READ; // do NOT report write+read in read |
|
1371 | 1370 | break; |
1372 | 1371 | |
1373 | 1372 | case 'locations': |
@@ -1379,18 +1378,18 @@ discard block |
||
1379 | 1378 | } |
1380 | 1379 | $location = 'L'.$resource['cat_id']; |
1381 | 1380 | $right = $what == 'write' ? EGW_ACL_DIRECT_BOOKING : EGW_ACL_CALREAD; |
1382 | - $mask = $what == 'write' ? EGW_ACL_DIRECT_BOOKING : EGW_ACL_DIRECT_BOOKING|EGW_ACL_CALREAD; // do NOT report write+read in read |
|
1381 | + $mask = $what == 'write' ? EGW_ACL_DIRECT_BOOKING : EGW_ACL_DIRECT_BOOKING|EGW_ACL_CALREAD; // do NOT report write+read in read |
|
1383 | 1382 | break; |
1384 | 1383 | } |
1385 | 1384 | static $principal2grants = array(); |
1386 | - $grants =& $principal2grants[$principal]; |
|
1385 | + $grants = & $principal2grants[$principal]; |
|
1387 | 1386 | if (!isset($grants)) |
1388 | 1387 | { |
1389 | - switch($app) |
|
1388 | + switch ($app) |
|
1390 | 1389 | { |
1391 | 1390 | case 'resources': |
1392 | 1391 | $res_grants = $this->get_resource_rights(); |
1393 | - $grants = (array)$res_grants[$location]; // returns array($location => $grants) |
|
1392 | + $grants = (array)$res_grants[$location]; // returns array($location => $grants) |
|
1394 | 1393 | break; |
1395 | 1394 | |
1396 | 1395 | case 'calendar': |
@@ -1400,9 +1399,9 @@ discard block |
||
1400 | 1399 | } |
1401 | 1400 | //echo "<p>type=$type --> app=$app, what=$what --> right=$right, mask=$mask, account=$account, location=$location --> grants=".array2string($grants)."</p>\n"; |
1402 | 1401 | } |
1403 | - foreach($grants as $account_id => $rights) |
|
1402 | + foreach ($grants as $account_id => $rights) |
|
1404 | 1403 | { |
1405 | - if ($account_id !== 'run' && $account_id != $account && ($rights & $mask) == $right && |
|
1404 | + if ($account_id !== 'run' && $account_id != $account && ($rights&$mask) == $right && |
|
1406 | 1405 | ($account_lid = $this->accounts->id2name($account_id))) |
1407 | 1406 | { |
1408 | 1407 | // ignore "broken" grants (eg. negative account_id for a user), as they lead to further errors (no members) |
@@ -1433,12 +1432,12 @@ discard block |
||
1433 | 1432 | * @param int $account who is the proxy |
1434 | 1433 | * @return array with href props |
1435 | 1434 | */ |
1436 | - protected function principal_set($prop, array $accounts=array(), $app_proxys=null, $account=null) |
|
1435 | + protected function principal_set($prop, array $accounts = array(), $app_proxys = null, $account = null) |
|
1437 | 1436 | { |
1438 | - unset($prop); // not used, but required by function signature |
|
1437 | + unset($prop); // not used, but required by function signature |
|
1439 | 1438 | |
1440 | 1439 | $set = array(); |
1441 | - foreach($accounts as $account_id => $account_lid) |
|
1440 | + foreach ($accounts as $account_id => $account_lid) |
|
1442 | 1441 | { |
1443 | 1442 | if ($this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
1444 | 1443 | { |
@@ -1447,11 +1446,11 @@ discard block |
||
1447 | 1446 | } |
1448 | 1447 | if ($app_proxys) |
1449 | 1448 | { |
1450 | - foreach((array)$app_proxys as $app) |
|
1449 | + foreach ((array)$app_proxys as $app) |
|
1451 | 1450 | { |
1452 | 1451 | if (!isset($GLOBALS['egw_info']['user']['apps'][$app])) continue; |
1453 | 1452 | |
1454 | - switch($app) |
|
1453 | + switch ($app) |
|
1455 | 1454 | { |
1456 | 1455 | case 'resources': |
1457 | 1456 | $proxy_groups = $this->get_resource_proxy_groups($account); |
@@ -1483,11 +1482,11 @@ discard block |
||
1483 | 1482 | // get location grants for $account (incl. his memberships) |
1484 | 1483 | $memberships = $GLOBALS['egw']->accounts->memberships($account, true); |
1485 | 1484 | $location_grants = array(); |
1486 | - foreach($all_location_grants as $location => $grants) |
|
1485 | + foreach ($all_location_grants as $location => $grants) |
|
1487 | 1486 | { |
1488 | - foreach($grants as $account_id => $rights) |
|
1487 | + foreach ($grants as $account_id => $rights) |
|
1489 | 1488 | { |
1490 | - if (($rights & (EGW_ACL_CALREAD|EGW_ACL_DIRECT_BOOKING)) && // we only care for these rights |
|
1489 | + if (($rights&(EGW_ACL_CALREAD|EGW_ACL_DIRECT_BOOKING)) && // we only care for these rights |
|
1491 | 1490 | ($account_id == $account || in_array($account_id, $memberships))) |
1492 | 1491 | { |
1493 | 1492 | if (!isset($location_grants[$location])) $location_grants[$location] = 0; |
@@ -1496,13 +1495,13 @@ discard block |
||
1496 | 1495 | } |
1497 | 1496 | } |
1498 | 1497 | // now add proxy-groups for all resources user has rights to |
1499 | - foreach($resources as $resource) |
|
1498 | + foreach ($resources as $resource) |
|
1500 | 1499 | { |
1501 | 1500 | $rights = $location_grants['L'.$resource['cat_id']]; |
1502 | 1501 | if (isset($rights)) |
1503 | 1502 | { |
1504 | 1503 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'.$this->resource2name($resource). |
1505 | - '/calendar-proxy-'.($rights & EGW_ACL_DIRECT_BOOKING ? 'write' : 'read').'/'); |
|
1504 | + '/calendar-proxy-'.($rights&EGW_ACL_DIRECT_BOOKING ? 'write' : 'read').'/'); |
|
1506 | 1505 | } |
1507 | 1506 | } |
1508 | 1507 | } |
@@ -1517,18 +1516,18 @@ discard block |
||
1517 | 1516 | * @param string|array $app ='calendar' applications for which proxys should be added |
1518 | 1517 | * @return array with href props |
1519 | 1518 | */ |
1520 | - protected function get_calendar_proxy_groups($account, $app='calendar') |
|
1519 | + protected function get_calendar_proxy_groups($account, $app = 'calendar') |
|
1521 | 1520 | { |
1522 | 1521 | $set = array(); |
1523 | - foreach($this->acl->get_grants($app, $app != 'addressbook', $account) as $account_id => $rights) |
|
1522 | + foreach ($this->acl->get_grants($app, $app != 'addressbook', $account) as $account_id => $rights) |
|
1524 | 1523 | { |
1525 | - if ($account_id != $account && ($rights & Api\Acl::READ) && |
|
1524 | + if ($account_id != $account && ($rights&Api\Acl::READ) && |
|
1526 | 1525 | ($account_lid = $this->accounts->id2name($account_id)) && |
1527 | 1526 | $this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
1528 | 1527 | { |
1529 | 1528 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'. |
1530 | 1529 | ($account_id < 0 ? 'groups/' : 'users/'). |
1531 | - $account_lid.'/'.$app.'-proxy-'.($rights & Api\Acl::EDIT ? 'write' : 'read').'/'); |
|
1530 | + $account_lid.'/'.$app.'-proxy-'.($rights&Api\Acl::EDIT ? 'write' : 'read').'/'); |
|
1532 | 1531 | } |
1533 | 1532 | } |
1534 | 1533 | return $set; |
@@ -1543,7 +1542,7 @@ discard block |
||
1543 | 1542 | * @param boolean $do_locations =false false: /principal/resources, true: /principals/locations |
1544 | 1543 | * @return array|string array with files or HTTP error code |
1545 | 1544 | */ |
1546 | - protected function propfind_resources($name,$rest,array $options,$do_locations=false) |
|
1545 | + protected function propfind_resources($name, $rest, array $options, $do_locations = false) |
|
1547 | 1546 | { |
1548 | 1547 | if (!isset($GLOBALS['egw_info']['user']['apps']['resources'])) |
1549 | 1548 | { |
@@ -1562,7 +1561,7 @@ discard block |
||
1562 | 1561 | if (($resources = $this->get_resources())) |
1563 | 1562 | { |
1564 | 1563 | //_debug_array($resources); |
1565 | - foreach($resources as $resource) |
|
1564 | + foreach ($resources as $resource) |
|
1566 | 1565 | { |
1567 | 1566 | if (($is_location = self::resource_is_location($resource)) == $do_locations) |
1568 | 1567 | { |
@@ -1579,11 +1578,11 @@ discard block |
||
1579 | 1578 | return '404 Not Found'; |
1580 | 1579 | } |
1581 | 1580 | $path = ($is_location ? 'locations/' : 'resources/').$name; |
1582 | - while (substr($rest,-1) == '/') |
|
1581 | + while (substr($rest, -1) == '/') |
|
1583 | 1582 | { |
1584 | - $rest = substr($rest,0,-1); |
|
1583 | + $rest = substr($rest, 0, -1); |
|
1585 | 1584 | } |
1586 | - switch((string)$rest) |
|
1585 | + switch ((string)$rest) |
|
1587 | 1586 | { |
1588 | 1587 | case '': |
1589 | 1588 | $files[] = $this->add_principal_resource($resource); |
@@ -1622,12 +1621,12 @@ discard block |
||
1622 | 1621 | if ($options['depth']) |
1623 | 1622 | { |
1624 | 1623 | if (is_numeric($options['depth'])) --$options['depth']; |
1625 | - $files = array_merge($files, $this->propfind_users('','',$options), |
|
1626 | - $this->propfind_groups('','',$options)); |
|
1624 | + $files = array_merge($files, $this->propfind_users('', '', $options), |
|
1625 | + $this->propfind_groups('', '', $options)); |
|
1627 | 1626 | if ($GLOBALS['egw_info']['user']['apps']['resources']) |
1628 | 1627 | { |
1629 | - $files = array_merge($files, $this->propfind_resources('','',$options,false), // resources |
|
1630 | - $this->propfind_resources('','',$options,true)); // locations |
|
1628 | + $files = array_merge($files, $this->propfind_resources('', '', $options, false), // resources |
|
1629 | + $this->propfind_resources('', '', $options, true)); // locations |
|
1631 | 1630 | } |
1632 | 1631 | //$files = array_merge($files,$this->propfind_uids('','',$options)); |
1633 | 1632 | } |
@@ -1642,9 +1641,9 @@ discard block |
||
1642 | 1641 | * @param int $user =null account_id |
1643 | 1642 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
1644 | 1643 | */ |
1645 | - function get(&$options,$id,$user=null) |
|
1644 | + function get(&$options, $id, $user = null) |
|
1646 | 1645 | { |
1647 | - unset($options, $id, $user); // not used, but required by function signature |
|
1646 | + unset($options, $id, $user); // not used, but required by function signature |
|
1648 | 1647 | |
1649 | 1648 | return false; |
1650 | 1649 | } |
@@ -1657,9 +1656,9 @@ discard block |
||
1657 | 1656 | * @param int $user =null account_id of owner, default null |
1658 | 1657 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
1659 | 1658 | */ |
1660 | - function put(&$options,$id,$user=null) |
|
1659 | + function put(&$options, $id, $user = null) |
|
1661 | 1660 | { |
1662 | - unset($options, $id, $user); // not used, but required by function signature |
|
1661 | + unset($options, $id, $user); // not used, but required by function signature |
|
1663 | 1662 | |
1664 | 1663 | return false; |
1665 | 1664 | } |
@@ -1671,9 +1670,9 @@ discard block |
||
1671 | 1670 | * @param int $id |
1672 | 1671 | * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') |
1673 | 1672 | */ |
1674 | - function delete(&$options,$id) |
|
1673 | + function delete(&$options, $id) |
|
1675 | 1674 | { |
1676 | - unset($options, $id); // not used, but required by function signature |
|
1675 | + unset($options, $id); // not used, but required by function signature |
|
1677 | 1676 | |
1678 | 1677 | return false; |
1679 | 1678 | } |
@@ -1686,7 +1685,7 @@ discard block |
||
1686 | 1685 | */ |
1687 | 1686 | function read($id) |
1688 | 1687 | { |
1689 | - unset($id); // not used, but required by function signature |
|
1688 | + unset($id); // not used, but required by function signature |
|
1690 | 1689 | |
1691 | 1690 | return false; |
1692 | 1691 | } |
@@ -1698,13 +1697,13 @@ discard block |
||
1698 | 1697 | * @param array|int $entry entry-array or id |
1699 | 1698 | * @return boolean null if entry does not exist, false if no access, true if access permitted |
1700 | 1699 | */ |
1701 | - function check_access($acl,$entry) |
|
1700 | + function check_access($acl, $entry) |
|
1702 | 1701 | { |
1703 | 1702 | if ($acl != Api\Acl::READ) |
1704 | 1703 | { |
1705 | 1704 | return false; |
1706 | 1705 | } |
1707 | - if (!is_array($entry) && !$this->accounts->name2id($entry,'account_lid','u')) |
|
1706 | + if (!is_array($entry) && !$this->accounts->name2id($entry, 'account_lid', 'u')) |
|
1708 | 1707 | { |
1709 | 1708 | return null; |
1710 | 1709 | } |
@@ -1741,9 +1740,9 @@ discard block |
||
1741 | 1740 | * @param int $user =null owner of the collection, default current user |
1742 | 1741 | * @return array with privileges |
1743 | 1742 | */ |
1744 | - public function current_user_privileges($path, $user=null) |
|
1743 | + public function current_user_privileges($path, $user = null) |
|
1745 | 1744 | { |
1746 | - unset($path, $user); // not used, but required by function signature |
|
1745 | + unset($path, $user); // not used, but required by function signature |
|
1747 | 1746 | |
1748 | 1747 | return array('read', 'read-current-user-privilege-set'); |
1749 | 1748 | } |
@@ -49,7 +49,10 @@ discard block |
||
49 | 49 | { |
50 | 50 | parent::__construct($app, $caldav); |
51 | 51 | |
52 | - if (!isset(self::$resources)) self::$resources = new resources_bo(); |
|
52 | + if (!isset(self::$resources)) |
|
53 | + { |
|
54 | + self::$resources = new resources_bo(); |
|
55 | + } |
|
53 | 56 | } |
54 | 57 | |
55 | 58 | /** |
@@ -93,7 +96,10 @@ discard block |
||
93 | 96 | { |
94 | 97 | unset($path); // not used, but required by function signature |
95 | 98 | |
96 | - if (is_null($reports)) $reports = $this->supported_reports; |
|
99 | + if (is_null($reports)) |
|
100 | + { |
|
101 | + $reports = $this->supported_reports; |
|
102 | + } |
|
97 | 103 | |
98 | 104 | $supported = array(); |
99 | 105 | foreach($reports as $name => $data) |
@@ -264,7 +270,10 @@ discard block |
||
264 | 270 | $requested_props = $options['other']; |
265 | 271 | while(($requested_prop = array_shift($requested_props))) |
266 | 272 | { |
267 | - if ($requested_prop['name'] != 'property' || $requested_prop['depth'] != 1) continue; |
|
273 | + if ($requested_prop['name'] != 'property' || $requested_prop['depth'] != 1) |
|
274 | + { |
|
275 | + continue; |
|
276 | + } |
|
268 | 277 | |
269 | 278 | $prop_ns = $requested_prop['attrs']['namespace']; |
270 | 279 | $prop_name = $requested_prop['attrs']['name']; |
@@ -303,7 +312,10 @@ discard block |
||
303 | 312 | // find prop to expand |
304 | 313 | foreach($prop_files['files'][0]['props'] as $expand_prop) |
305 | 314 | { |
306 | - if ($expand_prop['name'] === $prop_name) break; |
|
315 | + if ($expand_prop['name'] === $prop_name) |
|
316 | + { |
|
317 | + break; |
|
318 | + } |
|
307 | 319 | } |
308 | 320 | if ($expand_prop['name'] !== $prop_name || !is_array($expand_prop['val']) || |
309 | 321 | $expand_prop['val'] && $expand_prop['val'][0]['name'] !== 'href') |
@@ -319,10 +331,13 @@ discard block |
||
319 | 331 | { |
320 | 332 | if ($prop['name'] == 'property' && $prop['depth'] == 2) |
321 | 333 | { |
322 | - if (!is_array($options2['props'])) // is "all" initially |
|
334 | + if (!is_array($options2['props'])) |
|
335 | + { |
|
336 | + // is "all" initially |
|
323 | 337 | { |
324 | 338 | $options2['props'] = array(); |
325 | 339 | } |
340 | + } |
|
326 | 341 | $options2['props'][] = array( |
327 | 342 | 'name' => $prop['attrs']['name'], |
328 | 343 | 'xmlns' => isset($prop['attrs']['namespace']) ? $prop['attrs']['namespace'] : $prop['xmlns'], |
@@ -330,7 +345,10 @@ discard block |
||
330 | 345 | } |
331 | 346 | } |
332 | 347 | // put back evtl. read top-level property |
333 | - if ($prop && $prop['depth'] == 1) array_unshift($requested_props, $prop); |
|
348 | + if ($prop && $prop['depth'] == 1) |
|
349 | + { |
|
350 | + array_unshift($requested_props, $prop); |
|
351 | + } |
|
334 | 352 | $this->caldav->options = $options2; // also modify global variable |
335 | 353 | |
336 | 354 | // run regular profind to get requested 2.-level properties for each href |
@@ -526,9 +544,12 @@ discard block |
||
526 | 544 | // now filter out not matching "files" |
527 | 545 | foreach($files['files'] as $n => $resource) |
528 | 546 | { |
529 | - if (count(explode('/', $resource['path'])) < 5) // hack to only return principals, not the collections itself |
|
547 | + if (count(explode('/', $resource['path'])) < 5) |
|
548 | + { |
|
549 | + // hack to only return principals, not the collections itself |
|
530 | 550 | { |
531 | 551 | unset($files['files'][$n]); |
552 | + } |
|
532 | 553 | continue; |
533 | 554 | } |
534 | 555 | // match with $search_props |
@@ -538,16 +559,26 @@ discard block |
||
538 | 559 | // search resource for $search_prop |
539 | 560 | foreach($resource['props'] as $prop) |
540 | 561 | { |
541 | - if ($prop['name'] === $search_prop['name']) break; |
|
562 | + if ($prop['name'] === $search_prop['name']) |
|
563 | + { |
|
564 | + break; |
|
565 | + } |
|
542 | 566 | } |
543 | - if ($prop['name'] === $search_prop['name']) // search_prop NOT found |
|
567 | + if ($prop['name'] === $search_prop['name']) |
|
568 | + { |
|
569 | + // search_prop NOT found |
|
544 | 570 | { |
545 | 571 | foreach((array)$prop['val'] as $value) |
546 | 572 | { |
547 | - if (is_array($value)) $value = $value['val']; // eg. href prop |
|
548 | - if (self::match($value, $search_prop['match'], $search_prop['match-type']) !== false) // prop does match |
|
573 | + if (is_array($value)) $value = $value['val']; |
|
574 | + } |
|
575 | + // eg. href prop |
|
576 | + if (self::match($value, $search_prop['match'], $search_prop['match-type']) !== false) |
|
577 | + { |
|
578 | + // prop does match |
|
549 | 579 | { |
550 | 580 | ++$matches; |
581 | + } |
|
551 | 582 | //error_log("$matches: $resource[path]: $search_prop[name]=".array2string($prop['name'] !== $search_prop['name'] ? null : $prop['val'])." does match '$search_prop[match]'"); |
552 | 583 | break; |
553 | 584 | } |
@@ -749,7 +780,10 @@ discard block |
||
749 | 780 | { |
750 | 781 | foreach($resource['props']['resourcetype']['val'] as $prop) |
751 | 782 | { |
752 | - if ($prop['name'] == 'principal') continue 2; |
|
783 | + if ($prop['name'] == 'principal') |
|
784 | + { |
|
785 | + continue 2; |
|
786 | + } |
|
753 | 787 | } |
754 | 788 | unset($files['files'][$n]); // not a principal --> do not return |
755 | 789 | } |
@@ -903,7 +937,11 @@ discard block |
||
903 | 937 | { |
904 | 938 | $addressbooks = array(); |
905 | 939 | $ab_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set']; |
906 | - if (empty($ab_home_set)) $ab_home_set = 'P'; // personal addressbook |
|
940 | + if (empty($ab_home_set)) |
|
941 | + { |
|
942 | + $ab_home_set = 'P'; |
|
943 | + } |
|
944 | + // personal addressbook |
|
907 | 945 | $addressbook_home_set = explode(',', $ab_home_set); |
908 | 946 | // replace symbolic id's with real nummeric id's |
909 | 947 | foreach(array( |
@@ -917,10 +955,13 @@ discard block |
||
917 | 955 | $addressbook_home_set[$key] = $id; |
918 | 956 | } |
919 | 957 | } |
920 | - if (in_array('O',$addressbook_home_set)) // "all in one" from groupdav.php/addressbook/ |
|
958 | + if (in_array('O',$addressbook_home_set)) |
|
959 | + { |
|
960 | + // "all in one" from groupdav.php/addressbook/ |
|
921 | 961 | { |
922 | 962 | $addressbooks[] = '/'; |
923 | 963 | } |
964 | + } |
|
924 | 965 | foreach(array_keys($GLOBALS['egw']->contacts->get_addressbooks(Api\Acl::READ)) as $id) |
925 | 966 | { |
926 | 967 | if ((in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) && |
@@ -999,7 +1040,10 @@ discard block |
||
999 | 1040 | */ |
1000 | 1041 | static public function url2uid($url, $only_type=null, $cn=null) |
1001 | 1042 | { |
1002 | - if (!$only_type) $only_type = array('users', 'groups', 'resources', 'locations', 'mailto'); |
|
1043 | + if (!$only_type) |
|
1044 | + { |
|
1045 | + $only_type = array('users', 'groups', 'resources', 'locations', 'mailto'); |
|
1046 | + } |
|
1003 | 1047 | |
1004 | 1048 | if ($url[0] == '/') |
1005 | 1049 | { |
@@ -1009,7 +1053,10 @@ discard block |
||
1009 | 1053 | { |
1010 | 1054 | list($schema, $rest) = explode(':', $url, 2); |
1011 | 1055 | } |
1012 | - if (empty($rest)) return false; |
|
1056 | + if (empty($rest)) |
|
1057 | + { |
|
1058 | + return false; |
|
1059 | + } |
|
1013 | 1060 | |
1014 | 1061 | switch(strtolower($schema)) |
1015 | 1062 | { |
@@ -1056,9 +1103,12 @@ discard block |
||
1056 | 1103 | case 'urn': |
1057 | 1104 | list($urn_type, $uid) = explode(':', $rest, 2); |
1058 | 1105 | list($type, $id, $install_id) = explode('-', $uid); |
1059 | - if ($type == 'accounts' && empty($id)) // groups have a negative id, eg. "urn:uuid:accounts--1-..." |
|
1106 | + if ($type == 'accounts' && empty($id)) |
|
1107 | + { |
|
1108 | + // groups have a negative id, eg. "urn:uuid:accounts--1-..." |
|
1060 | 1109 | { |
1061 | 1110 | list($type, , $id_abs, $install_id) = explode('-', $uid); |
1111 | + } |
|
1062 | 1112 | $id = -$id_abs; |
1063 | 1113 | } |
1064 | 1114 | // own urn |
@@ -1072,7 +1122,10 @@ discard block |
||
1072 | 1122 | else |
1073 | 1123 | { |
1074 | 1124 | static $calendar_bo=null; |
1075 | - if (is_null($calendar_bo)) $calendar_bo = new calendar_bo(); |
|
1125 | + if (is_null($calendar_bo)) |
|
1126 | + { |
|
1127 | + $calendar_bo = new calendar_bo(); |
|
1128 | + } |
|
1076 | 1129 | foreach($calendar_bo->resources as $letter => $info) |
1077 | 1130 | { |
1078 | 1131 | if ($info['app'] == $type || $info['app'] == 'resources' && $type == 'location') |
@@ -1179,7 +1232,10 @@ discard block |
||
1179 | 1232 | { |
1180 | 1233 | return null; |
1181 | 1234 | } |
1182 | - if (is_null($is_location)) $is_location = self::resource_is_location($resource); |
|
1235 | + if (is_null($is_location)) |
|
1236 | + { |
|
1237 | + $is_location = self::resource_is_location($resource); |
|
1238 | + } |
|
1183 | 1239 | |
1184 | 1240 | $displayname = Api\Translation::convert($resource['name'], Api\Translation::charset(), 'utf-8'); |
1185 | 1241 | |
@@ -1225,7 +1281,10 @@ discard block |
||
1225 | 1281 | |
1226 | 1282 | if (!isset($cache[$res_id])) |
1227 | 1283 | { |
1228 | - if (!isset(self::$resources)) self::$resources = new resources_bo(); |
|
1284 | + if (!isset(self::$resources)) |
|
1285 | + { |
|
1286 | + self::$resources = new resources_bo(); |
|
1287 | + } |
|
1229 | 1288 | |
1230 | 1289 | if (!($cache[$res_id] = self::$resources->read($res_id))) |
1231 | 1290 | { |
@@ -1262,7 +1321,10 @@ discard block |
||
1262 | 1321 | { |
1263 | 1322 | if (!isset(self::$all_resources)) |
1264 | 1323 | { |
1265 | - if (!isset(self::$resources)) self::$resources = new resources_bo($user); |
|
1324 | + if (!isset(self::$resources)) |
|
1325 | + { |
|
1326 | + self::$resources = new resources_bo($user); |
|
1327 | + } |
|
1266 | 1328 | |
1267 | 1329 | self::$all_resources = array(); |
1268 | 1330 | $query = array( |
@@ -1333,9 +1395,15 @@ discard block |
||
1333 | 1395 | // required props per WebDAV ACL |
1334 | 1396 | foreach(array('alternate-URI-set', 'group-membership') as $name) |
1335 | 1397 | { |
1336 | - if (!isset($props[$name])) $props[$name] = Api\CalDAV::mkprop($name,''); |
|
1398 | + if (!isset($props[$name])) |
|
1399 | + { |
|
1400 | + $props[$name] = Api\CalDAV::mkprop($name,''); |
|
1401 | + } |
|
1402 | + } |
|
1403 | + if (!$principal_url) |
|
1404 | + { |
|
1405 | + $principal_url = $principal; |
|
1337 | 1406 | } |
1338 | - if (!$principal_url) $principal_url = $principal; |
|
1339 | 1407 | |
1340 | 1408 | $props['principal-URL'] = array( |
1341 | 1409 | Api\CalDAV::mkprop('href',$this->base_uri.'/principals/'.$principal.'/')); |
@@ -1358,7 +1426,11 @@ discard block |
||
1358 | 1426 | { |
1359 | 1427 | list($app,,$what) = explode('-', $type); |
1360 | 1428 | |
1361 | - if (true) $proxys = array(); // ignore parameter! |
|
1429 | + if (true) |
|
1430 | + { |
|
1431 | + $proxys = array(); |
|
1432 | + } |
|
1433 | + // ignore parameter! |
|
1362 | 1434 | list($account_type,$account) = explode('/', $principal); |
1363 | 1435 | |
1364 | 1436 | switch($account_type) |
@@ -1440,16 +1512,22 @@ discard block |
||
1440 | 1512 | $set = array(); |
1441 | 1513 | foreach($accounts as $account_id => $account_lid) |
1442 | 1514 | { |
1443 | - if ($this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
|
1515 | + if ($this->accounts->visible($account_lid)) |
|
1516 | + { |
|
1517 | + // only add visible accounts, gives error in iCal otherwise |
|
1444 | 1518 | { |
1445 | 1519 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'.($account_id < 0 ? 'groups/' : 'users/').$account_lid.'/'); |
1446 | 1520 | } |
1521 | + } |
|
1447 | 1522 | } |
1448 | 1523 | if ($app_proxys) |
1449 | 1524 | { |
1450 | 1525 | foreach((array)$app_proxys as $app) |
1451 | 1526 | { |
1452 | - if (!isset($GLOBALS['egw_info']['user']['apps'][$app])) continue; |
|
1527 | + if (!isset($GLOBALS['egw_info']['user']['apps'][$app])) |
|
1528 | + { |
|
1529 | + continue; |
|
1530 | + } |
|
1453 | 1531 | |
1454 | 1532 | switch($app) |
1455 | 1533 | { |
@@ -1490,7 +1568,10 @@ discard block |
||
1490 | 1568 | if (($rights & (EGW_ACL_CALREAD|EGW_ACL_DIRECT_BOOKING)) && // we only care for these rights |
1491 | 1569 | ($account_id == $account || in_array($account_id, $memberships))) |
1492 | 1570 | { |
1493 | - if (!isset($location_grants[$location])) $location_grants[$location] = 0; |
|
1571 | + if (!isset($location_grants[$location])) |
|
1572 | + { |
|
1573 | + $location_grants[$location] = 0; |
|
1574 | + } |
|
1494 | 1575 | $location_grants[$location] |= $rights; |
1495 | 1576 | } |
1496 | 1577 | } |
@@ -1524,12 +1605,15 @@ discard block |
||
1524 | 1605 | { |
1525 | 1606 | if ($account_id != $account && ($rights & Api\Acl::READ) && |
1526 | 1607 | ($account_lid = $this->accounts->id2name($account_id)) && |
1527 | - $this->accounts->visible($account_lid)) // only add visible accounts, gives error in iCal otherwise |
|
1608 | + $this->accounts->visible($account_lid)) |
|
1609 | + { |
|
1610 | + // only add visible accounts, gives error in iCal otherwise |
|
1528 | 1611 | { |
1529 | 1612 | $set[] = Api\CalDAV::mkprop('href', $this->base_uri.'/principals/'. |
1530 | 1613 | ($account_id < 0 ? 'groups/' : 'users/'). |
1531 | 1614 | $account_lid.'/'.$app.'-proxy-'.($rights & Api\Acl::EDIT ? 'write' : 'read').'/'); |
1532 | 1615 | } |
1616 | + } |
|
1533 | 1617 | } |
1534 | 1618 | return $set; |
1535 | 1619 | } |
@@ -1621,7 +1705,10 @@ discard block |
||
1621 | 1705 | |
1622 | 1706 | if ($options['depth']) |
1623 | 1707 | { |
1624 | - if (is_numeric($options['depth'])) --$options['depth']; |
|
1708 | + if (is_numeric($options['depth'])) |
|
1709 | + { |
|
1710 | + --$options['depth']; |
|
1711 | + } |
|
1625 | 1712 | $files = array_merge($files, $this->propfind_users('','',$options), |
1626 | 1713 | $this->propfind_groups('','',$options)); |
1627 | 1714 | if ($GLOBALS['egw_info']['user']['apps']['resources']) |
@@ -94,6 +94,7 @@ |
||
94 | 94 | * @param Handler $handler |
95 | 95 | * @param array $filter filter for propfind call |
96 | 96 | * @param array $files =array() extra files/responses to return too |
97 | + * @param string $path |
|
97 | 98 | */ |
98 | 99 | public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
99 | 100 | { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @var int |
73 | 73 | */ |
74 | - protected $start=0; |
|
74 | + protected $start = 0; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Number of entries queried from callback in one call |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param array $filter filter for propfind call |
96 | 96 | * @param array $files =array() extra files/responses to return too |
97 | 97 | */ |
98 | - public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
|
98 | + public function __construct(Handler $handler, $path, array $filter, array &$files = array()) |
|
99 | 99 | { |
100 | 100 | if ($this->debug) error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
101 | 101 | $this->path = $path; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $current = current($this->files); |
127 | 127 | |
128 | 128 | if ($this->debug) error_log(__METHOD__."() returning ".array2string($current['path'])); |
129 | - return $current['path']; // we return path as key |
|
129 | + return $current['path']; // we return path as key |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | // try query further files via propfind callback of handler and store result in $this->files |
149 | - $this->files = $this->handler->propfind_callback($this->path,$this->filter,array($this->start,self::CHUNK_SIZE)); |
|
149 | + $this->files = $this->handler->propfind_callback($this->path, $this->filter, array($this->start, self::CHUNK_SIZE)); |
|
150 | 150 | if (!is_array($this->files) || !($entries = count($this->files))) |
151 | 151 | { |
152 | 152 | if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
153 | - return false; // no further entries |
|
153 | + return false; // no further entries |
|
154 | 154 | } |
155 | 155 | $this->start += self::CHUNK_SIZE; |
156 | 156 | reset($this->files); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | $this->start = 0; |
171 | 171 | $this->files = $this->common_files; |
172 | - if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
172 | + if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
173 | 173 | reset($this->files); |
174 | 174 | } |
175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return boolean |
180 | 180 | */ |
181 | - public function valid () |
|
181 | + public function valid() |
|
182 | 182 | { |
183 | 183 | if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
184 | 184 | return current($this->files) !== false; |
@@ -97,7 +97,10 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
99 | 99 | { |
100 | - if ($this->debug) error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
|
100 | + if ($this->debug) |
|
101 | + { |
|
102 | + error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
|
103 | + } |
|
101 | 104 | $this->path = $path; |
102 | 105 | $this->handler = $handler; |
103 | 106 | $this->filter = $filter; |
@@ -112,7 +115,10 @@ discard block |
||
112 | 115 | */ |
113 | 116 | public function current() |
114 | 117 | { |
115 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files))); |
|
118 | + if ($this->debug) |
|
119 | + { |
|
120 | + error_log(__METHOD__."() returning ".array2string(current($this->files))); |
|
121 | + } |
|
116 | 122 | return current($this->files); |
117 | 123 | } |
118 | 124 | |
@@ -125,7 +131,10 @@ discard block |
||
125 | 131 | { |
126 | 132 | $current = current($this->files); |
127 | 133 | |
128 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string($current['path'])); |
|
134 | + if ($this->debug) |
|
135 | + { |
|
136 | + error_log(__METHOD__."() returning ".array2string($current['path'])); |
|
137 | + } |
|
129 | 138 | return $current['path']; // we return path as key |
130 | 139 | } |
131 | 140 | |
@@ -136,26 +145,38 @@ discard block |
||
136 | 145 | { |
137 | 146 | if (next($this->files) !== false) |
138 | 147 | { |
139 | - if ($this->debug) error_log(__METHOD__."() returning TRUE"); |
|
148 | + if ($this->debug) |
|
149 | + { |
|
150 | + error_log(__METHOD__."() returning TRUE"); |
|
151 | + } |
|
140 | 152 | return true; |
141 | 153 | } |
142 | 154 | // check if previous query gave less then CHUNK_SIZE entries --> we're done |
143 | 155 | if ($this->start && count($this->files) < self::CHUNK_SIZE) |
144 | 156 | { |
145 | - if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
157 | + if ($this->debug) |
|
158 | + { |
|
159 | + error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
160 | + } |
|
146 | 161 | return false; |
147 | 162 | } |
148 | 163 | // try query further files via propfind callback of handler and store result in $this->files |
149 | 164 | $this->files = $this->handler->propfind_callback($this->path,$this->filter,array($this->start,self::CHUNK_SIZE)); |
150 | 165 | if (!is_array($this->files) || !($entries = count($this->files))) |
151 | 166 | { |
152 | - if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
167 | + if ($this->debug) |
|
168 | + { |
|
169 | + error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
170 | + } |
|
153 | 171 | return false; // no further entries |
154 | 172 | } |
155 | 173 | $this->start += self::CHUNK_SIZE; |
156 | 174 | reset($this->files); |
157 | 175 | |
158 | - if ($this->debug) error_log(__METHOD__."() this->start=$this->start, entries=$entries, count(this->files)=".count($this->files)." returning ".array2string(current($this->files) !== false)); |
|
176 | + if ($this->debug) |
|
177 | + { |
|
178 | + error_log(__METHOD__."() this->start=$this->start, entries=$entries, count(this->files)=".count($this->files)." returning ".array2string(current($this->files) !== false)); |
|
179 | + } |
|
159 | 180 | |
160 | 181 | return current($this->files) !== false; |
161 | 182 | } |
@@ -165,11 +186,18 @@ discard block |
||
165 | 186 | */ |
166 | 187 | public function rewind() |
167 | 188 | { |
168 | - if ($this->debug) error_log(__METHOD__."()"); |
|
189 | + if ($this->debug) |
|
190 | + { |
|
191 | + error_log(__METHOD__."()"); |
|
192 | + } |
|
169 | 193 | |
170 | 194 | $this->start = 0; |
171 | 195 | $this->files = $this->common_files; |
172 | - if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
196 | + if (!$this->files) |
|
197 | + { |
|
198 | + $this->next(); |
|
199 | + } |
|
200 | + // otherwise valid will return false and nothing get returned |
|
173 | 201 | reset($this->files); |
174 | 202 | } |
175 | 203 | |
@@ -180,7 +208,10 @@ discard block |
||
180 | 208 | */ |
181 | 209 | public function valid () |
182 | 210 | { |
183 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
|
211 | + if ($this->debug) |
|
212 | + { |
|
213 | + error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
|
214 | + } |
|
184 | 215 | return current($this->files) !== false; |
185 | 216 | } |
186 | 217 | } |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | * return a sorted array populated with categories (main sorting criteria is hierachy!) |
323 | 323 | * |
324 | 324 | * @param int $start =0 see $limit |
325 | - * @param boolean|int $limit if true limited query to maxmatches rows (starting with $start) |
|
325 | + * @param boolean $limit if true limited query to maxmatches rows (starting with $start) |
|
326 | 326 | * @param string $query ='' query-pattern |
327 | 327 | * @param string $sort ='ASC' sort order, either defaults to 'ASC' |
328 | 328 | * @param string $order ='cat_name' order by |
329 | 329 | * @param boolean|string $globals includes the global egroupware categories or not, |
330 | 330 | * 'all_no_acl' to return global and all non-private user categories independent of ACL |
331 | - * @param array|int $parent_id =0 return only subcats of $parent_id(s) |
|
331 | + * @param integer $parent_id =0 return only subcats of $parent_id(s) |
|
332 | 332 | * @param boolean $unserialize_data =true return $cat['data'] as array (not serialized array) |
333 | 333 | * @return array with cats |
334 | 334 | */ |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @param mixed $category category as array or the category_id |
508 | 508 | * @param boolean $no_acl_check =false if true, grants are NOT checked, gives access to all non-private categories of all users |
509 | 509 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
510 | - * @return boolean true permission granted, false for permission denied, null for category does not exist |
|
510 | + * @return null|boolean true permission granted, false for permission denied, null for category does not exist |
|
511 | 511 | */ |
512 | 512 | public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
513 | 513 | { |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | * check_consistency4update - for edit |
676 | 676 | * |
677 | 677 | * @param array $values array with cat-data (it need to be complete, as everything get's written) |
678 | - * @return mixed string/boolean errorstring if consitency check failed / true if the consistency check did not fail |
|
678 | + * @return string|boolean string/boolean errorstring if consitency check failed / true if the consistency check did not fail |
|
679 | 679 | */ |
680 | 680 | function check_consistency4update($values) |
681 | 681 | { |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | * |
823 | 823 | * @param int|array $cat |
824 | 824 | * @param boolean $application_global =false true check for application global categories only (appname == 'phpgw') |
825 | - * @return boolean |
|
825 | + * @return null|boolean |
|
826 | 826 | */ |
827 | 827 | static function is_global($cat,$application_global=false) |
828 | 828 | { |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | * |
1031 | 1031 | * @param string appname |
1032 | 1032 | * |
1033 | - * @return Returns the URL, but you do not need to do anything with it. |
|
1033 | + * @return string the URL, but you do not need to do anything with it. |
|
1034 | 1034 | */ |
1035 | 1035 | public static function css($appname) |
1036 | 1036 | { |
@@ -1044,13 +1044,13 @@ |
||
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | /** |
1047 | - * Get the color of a category |
|
1048 | - * |
|
1049 | - * For multiple cats, the first with a color is used |
|
1050 | - * |
|
1051 | - * @param int|string $_cats multiple comma-separated cat_id's |
|
1052 | - * @return string |
|
1053 | - */ |
|
1047 | + * Get the color of a category |
|
1048 | + * |
|
1049 | + * For multiple cats, the first with a color is used |
|
1050 | + * |
|
1051 | + * @param int|string $_cats multiple comma-separated cat_id's |
|
1052 | + * @return string |
|
1053 | + */ |
|
1054 | 1054 | static function cats2color($_cats) |
1055 | 1055 | { |
1056 | 1056 | static $cat2color = array(); |
@@ -122,7 +122,10 @@ discard block |
||
122 | 122 | */ |
123 | 123 | function __construct($accountid='',$app_name = '') |
124 | 124 | { |
125 | - if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
125 | + if (!$app_name) |
|
126 | + { |
|
127 | + $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
128 | + } |
|
126 | 129 | |
127 | 130 | if ($accountid === self::GLOBAL_ACCOUNT || |
128 | 131 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
@@ -138,10 +141,13 @@ discard block |
||
138 | 141 | $this->app_name = $app_name; |
139 | 142 | $this->db = $GLOBALS['egw']->db; |
140 | 143 | |
141 | - if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
|
144 | + if (is_null(self::$cache)) |
|
145 | + { |
|
146 | + // should not be necessary, as cache is load and restored by egw object |
|
142 | 147 | { |
143 | 148 | self::init_cache(); |
144 | 149 | } |
150 | + } |
|
145 | 151 | if (is_null(self::$global_marker)) |
146 | 152 | { |
147 | 153 | // as et2 adds options with .text(), it can't be entities, but php knows no string literals with utf-8 |
@@ -189,7 +195,9 @@ discard block |
||
189 | 195 | $cats = array(); |
190 | 196 | foreach(self::$cache as $cat) |
191 | 197 | { |
192 | - if ($filter) foreach($filter as $col => $val) |
|
198 | + if ($filter) |
|
199 | + { |
|
200 | + foreach($filter as $col => $val) |
|
193 | 201 | { |
194 | 202 | if (!is_array($val) && $val[0] === '!') |
195 | 203 | { |
@@ -197,10 +205,14 @@ discard block |
||
197 | 205 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
198 | 206 | { |
199 | 207 | if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
208 | + } |
|
200 | 209 | } |
201 | 210 | else |
202 | 211 | { |
203 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
212 | + if ($cat[$col] == substr($val,1)) |
|
213 | + { |
|
214 | + continue 2; |
|
215 | + } |
|
204 | 216 | } |
205 | 217 | } |
206 | 218 | elseif (is_array($val)) |
@@ -208,11 +220,17 @@ discard block |
||
208 | 220 | // also match against trimmed database entry on name and description fields |
209 | 221 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
210 | 222 | { |
211 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
223 | + if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) |
|
224 | + { |
|
225 | + continue 2; |
|
226 | + } |
|
212 | 227 | } |
213 | 228 | else |
214 | 229 | { |
215 | - if (!in_array($cat[$col],$val)) continue 2; |
|
230 | + if (!in_array($cat[$col],$val)) |
|
231 | + { |
|
232 | + continue 2; |
|
233 | + } |
|
216 | 234 | } |
217 | 235 | } |
218 | 236 | else |
@@ -220,16 +238,25 @@ discard block |
||
220 | 238 | // also match against trimmed database entry on name and description fields |
221 | 239 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
222 | 240 | { |
223 | - if ($cat[$col] != $val && trim($cat[$col]) != $val) continue 2; |
|
241 | + if ($cat[$col] != $val && trim($cat[$col]) != $val) |
|
242 | + { |
|
243 | + continue 2; |
|
244 | + } |
|
224 | 245 | } |
225 | 246 | else |
226 | 247 | { |
227 | - if ($cat[$col] != $val) continue 2; |
|
248 | + if ($cat[$col] != $val) |
|
249 | + { |
|
250 | + continue 2; |
|
251 | + } |
|
228 | 252 | } |
229 | 253 | } |
230 | 254 | } |
231 | 255 | // check if certain parent required |
232 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
256 | + if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) |
|
257 | + { |
|
258 | + continue; |
|
259 | + } |
|
233 | 260 | |
234 | 261 | // return global categories just if $globals is set |
235 | 262 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -247,30 +274,55 @@ discard block |
||
247 | 274 | switch ($type) |
248 | 275 | { |
249 | 276 | case 'subs': |
250 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
277 | + if (!$cat['parent']) |
|
278 | + { |
|
279 | + continue 2; |
|
280 | + } |
|
281 | + // 2 for switch AND foreach! |
|
251 | 282 | break; |
252 | 283 | case 'mains': |
253 | - if ($cat['parent']) continue 2; |
|
284 | + if ($cat['parent']) |
|
285 | + { |
|
286 | + continue 2; |
|
287 | + } |
|
254 | 288 | break; |
255 | 289 | case 'appandmains': |
256 | - if ($cat['appname'] != $this->app_name || $cat['parent']) continue 2; |
|
290 | + if ($cat['appname'] != $this->app_name || $cat['parent']) |
|
291 | + { |
|
292 | + continue 2; |
|
293 | + } |
|
257 | 294 | break; |
258 | 295 | case 'appandsubs': |
259 | - if ($cat['appname'] != $this->app_name || !$cat['parent']) continue 2; |
|
296 | + if ($cat['appname'] != $this->app_name || !$cat['parent']) |
|
297 | + { |
|
298 | + continue 2; |
|
299 | + } |
|
260 | 300 | break; |
261 | 301 | case 'noglobal': |
262 | - if ($cat['appname'] == $this->app_name) continue 2; |
|
302 | + if ($cat['appname'] == $this->app_name) |
|
303 | + { |
|
304 | + continue 2; |
|
305 | + } |
|
263 | 306 | break; |
264 | 307 | case 'noglobalapp': |
265 | - if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) continue 2; |
|
308 | + if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) |
|
309 | + { |
|
310 | + continue 2; |
|
311 | + } |
|
266 | 312 | break; |
267 | 313 | } |
268 | 314 | |
269 | 315 | // check name and description for $query |
270 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
316 | + if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) |
|
317 | + { |
|
318 | + continue; |
|
319 | + } |
|
271 | 320 | |
272 | 321 | // check if last modified since |
273 | - if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
|
322 | + if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) |
|
323 | + { |
|
324 | + continue; |
|
325 | + } |
|
274 | 326 | |
275 | 327 | $cat['data'] = $cat['data'] ? json_php_unserialize($cat['data'], true) : array(); |
276 | 328 | |
@@ -281,13 +333,23 @@ discard block |
||
281 | 333 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=$parent_id,$lastmod,$column) account_id=$this->account_id, appname=$this->app_name = FALSE"); |
282 | 334 | return array(); |
283 | 335 | } |
284 | - if (!$sort) $sort = 'ASC'; |
|
336 | + if (!$sort) |
|
337 | + { |
|
338 | + $sort = 'ASC'; |
|
339 | + } |
|
285 | 340 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
286 | 341 | if ($this->total_records > 1 && !empty($order) && |
287 | 342 | preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
288 | 343 | { |
289 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
290 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
344 | + if (strstr($order,'cat_data') !== false) |
|
345 | + { |
|
346 | + $order = 'cat_data'; |
|
347 | + } |
|
348 | + // sitemgr orders by round(cat_data)! |
|
349 | + if (substr($order,0,4) == 'cat_') |
|
350 | + { |
|
351 | + $order = substr($order,4); |
|
352 | + } |
|
291 | 353 | $sign = strtoupper($sort) == 'DESC' ? -1 : 1; |
292 | 354 | usort($cats, function($a, $b) use ($order, $sign) |
293 | 355 | { |
@@ -301,7 +363,10 @@ discard block |
||
301 | 363 | // limit the number of returned rows |
302 | 364 | if ($limit) |
303 | 365 | { |
304 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
366 | + if (!is_int($limit)) |
|
367 | + { |
|
368 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
369 | + } |
|
305 | 370 | $cats = array_slice($cats,(int)$start,$limit); |
306 | 371 | } |
307 | 372 | // return only a certain column (why not return is as value?) |
@@ -334,15 +399,24 @@ discard block |
||
334 | 399 | */ |
335 | 400 | function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
336 | 401 | { |
337 | - if (!$sort) $sort = 'ASC'; |
|
338 | - if (!$order) $order = 'cat_name'; |
|
402 | + if (!$sort) |
|
403 | + { |
|
404 | + $sort = 'ASC'; |
|
405 | + } |
|
406 | + if (!$order) |
|
407 | + { |
|
408 | + $order = 'cat_name'; |
|
409 | + } |
|
339 | 410 | |
340 | 411 | //error_log(__METHOD__."($start,$limit,$query,$sort,$order,globals=$globals,parent=$parent_id,$unserialize_data) account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
341 | 412 | |
342 | 413 | $parents = $cats = array(); |
343 | 414 | |
344 | 415 | // Cast parent_id to array, but only if there is one |
345 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
416 | + if($parent_id !== false && $parent_id !== null) |
|
417 | + { |
|
418 | + $parent_id = (array)$parent_id; |
|
419 | + } |
|
346 | 420 | if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
347 | 421 | { |
348 | 422 | $cats = array(); |
@@ -352,7 +426,9 @@ discard block |
||
352 | 426 | $parents[] = $cat['id']; |
353 | 427 | } |
354 | 428 | |
355 | - if($parent_id || !$cats) // Avoid wiping search results |
|
429 | + if($parent_id || !$cats) |
|
430 | + { |
|
431 | + // Avoid wiping search results |
|
356 | 432 | { |
357 | 433 | // Go find the children |
358 | 434 | while (count($parents)) |
@@ -360,6 +436,7 @@ discard block |
||
360 | 436 | if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
361 | 437 | { |
362 | 438 | break; |
439 | + } |
|
363 | 440 | } |
364 | 441 | $parents = $children = array(); |
365 | 442 | foreach($subs as $cat) |
@@ -391,7 +468,10 @@ discard block |
||
391 | 468 | // limit the number of returned rows |
392 | 469 | if ($limit) |
393 | 470 | { |
394 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
471 | + if (!is_int($limit)) |
|
472 | + { |
|
473 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
474 | + } |
|
395 | 475 | $cats = array_slice($cats,(int)$start,$limit); |
396 | 476 | } |
397 | 477 | reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
@@ -410,9 +490,15 @@ discard block |
||
410 | 490 | */ |
411 | 491 | static function read($id) |
412 | 492 | { |
413 | - if (is_null(self::$cache)) self::init_cache(); |
|
493 | + if (is_null(self::$cache)) |
|
494 | + { |
|
495 | + self::init_cache(); |
|
496 | + } |
|
414 | 497 | |
415 | - if (!isset(self::$cache[$id])) return false; |
|
498 | + if (!isset(self::$cache[$id])) |
|
499 | + { |
|
500 | + return false; |
|
501 | + } |
|
416 | 502 | |
417 | 503 | $cat = self::$cache[$id]; |
418 | 504 | $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
@@ -475,8 +561,11 @@ discard block |
||
475 | 561 | * @return string truncated commaseparated list of category ids |
476 | 562 | */ |
477 | 563 | function check_list($needed, $cat_list) |
478 | - { |
|
479 | - if (empty($cat_list)) return $cat_list; |
|
564 | + { |
|
565 | + if (empty($cat_list)) |
|
566 | + { |
|
567 | + return $cat_list; |
|
568 | + } |
|
480 | 569 | if (is_array($cat_list)) |
481 | 570 | { |
482 | 571 | $cat_list = implode(',',$cat_list); |
@@ -487,10 +576,13 @@ discard block |
||
487 | 576 | { |
488 | 577 | foreach($cat_arr as $id=>$cat_id) |
489 | 578 | { |
490 | - if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) // allow reading all global cats |
|
579 | + if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) |
|
580 | + { |
|
581 | + // allow reading all global cats |
|
491 | 582 | { |
492 | 583 | unset($cat_arr[$id]); |
493 | 584 | } |
585 | + } |
|
494 | 586 | } |
495 | 587 | $cat_list = implode(',',$cat_arr); |
496 | 588 | } |
@@ -596,9 +688,15 @@ discard block |
||
596 | 688 | { |
597 | 689 | $update = array('cat_level' => $cat['level']-1); |
598 | 690 | |
599 | - if ($new_main) $update['cat_main'] = $new_main; |
|
691 | + if ($new_main) |
|
692 | + { |
|
693 | + $update['cat_main'] = $new_main; |
|
694 | + } |
|
600 | 695 | |
601 | - if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
|
696 | + if ($cat['parent'] == $cat_id) |
|
697 | + { |
|
698 | + $update['cat_parent'] = $new_parent; |
|
699 | + } |
|
602 | 700 | |
603 | 701 | $this->db->update(self::TABLE,$update,array( |
604 | 702 | 'cat_id' => $cat['id'], |
@@ -624,9 +722,13 @@ discard block |
||
624 | 722 | 'modify_subs' => $modify_subs, |
625 | 723 | 'location' => 'delete_category' |
626 | 724 | ); |
627 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
725 | + if($this->is_global($cat_id, true)) |
|
726 | + { |
|
727 | + // true = application global (otherwise eg. global addressbook categories call all apps) |
|
628 | 728 | { |
629 | - Hooks::process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
729 | + Hooks::process($GLOBALS['hook_values'],False,True); |
|
730 | + } |
|
731 | + // called for every app now, not only enabled ones) |
|
630 | 732 | } |
631 | 733 | else |
632 | 734 | { |
@@ -682,12 +784,22 @@ discard block |
||
682 | 784 | // check if we try to move an element down its own subtree, which will fail |
683 | 785 | foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
684 | 786 | { |
685 | - if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
787 | + if ($cat['id'] == $values['parent']) |
|
788 | + { |
|
789 | + return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
790 | + } |
|
686 | 791 | } |
687 | 792 | // check if we try to be our own parent |
688 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
793 | + if ($values['parent']==$values['id']) |
|
794 | + { |
|
795 | + return lang('Cannot set this cat as its own parent!'); |
|
796 | + } |
|
797 | + // deny to be our own parent |
|
689 | 798 | // check if parent still exists |
690 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
799 | + if ((int)$values['parent']>0 && !$this->read($values['parent'])) |
|
800 | + { |
|
801 | + return lang('Chosen parent category no longer exists'); |
|
802 | + } |
|
691 | 803 | return true; |
692 | 804 | } |
693 | 805 | |
@@ -704,7 +816,10 @@ discard block |
||
704 | 816 | if (isset($values['old_parent']) && (int)$values['old_parent'] != (int)$values['parent']) |
705 | 817 | { |
706 | 818 | $ret = $this->check_consistency4update($values); |
707 | - if ($ret !== true) throw new Exception\WrongUserinput($ret); |
|
819 | + if ($ret !== true) |
|
820 | + { |
|
821 | + throw new Exception\WrongUserinput($ret); |
|
822 | + } |
|
708 | 823 | // everything seems in order -> proceed |
709 | 824 | $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
710 | 825 | $this->adapt_level_in_subtree($values); |
@@ -717,7 +832,10 @@ discard block |
||
717 | 832 | if ($values['parent'] > 0) |
718 | 833 | { |
719 | 834 | $ret = $this->check_consistency4update($values); |
720 | - if ($ret !== true) throw new Exception\WrongUserinput($ret); |
|
835 | + if ($ret !== true) |
|
836 | + { |
|
837 | + throw new Exception\WrongUserinput($ret); |
|
838 | + } |
|
721 | 839 | |
722 | 840 | // everything seems in order -> proceed |
723 | 841 | $values['main'] = $this->id2name($values['parent'],'main'); |
@@ -773,7 +891,10 @@ discard block |
||
773 | 891 | { |
774 | 892 | static $cache = array(); // a litle bit of caching |
775 | 893 | |
776 | - if (isset($cache[$cat_name])) return $cache[$cat_name]; |
|
894 | + if (isset($cache[$cat_name])) |
|
895 | + { |
|
896 | + return $cache[$cat_name]; |
|
897 | + } |
|
777 | 898 | |
778 | 899 | if ($strip === true) |
779 | 900 | { |
@@ -826,7 +947,11 @@ discard block |
||
826 | 947 | */ |
827 | 948 | static function is_global($cat,$application_global=false) |
828 | 949 | { |
829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
950 | + if (!is_array($cat) && !($cat = self::read($cat))) |
|
951 | + { |
|
952 | + return null; |
|
953 | + } |
|
954 | + // cat not found |
|
830 | 955 | |
831 | 956 | $global_owner = false; |
832 | 957 | foreach(explode(',',$cat['owner']) as $owner) |
@@ -848,10 +973,19 @@ discard block |
||
848 | 973 | */ |
849 | 974 | static function id2name($cat_id=0, $item='name') |
850 | 975 | { |
851 | - if(!$cat_id) return '--'; |
|
852 | - if (!$item) $item = 'parent'; |
|
976 | + if(!$cat_id) |
|
977 | + { |
|
978 | + return '--'; |
|
979 | + } |
|
980 | + if (!$item) |
|
981 | + { |
|
982 | + $item = 'parent'; |
|
983 | + } |
|
853 | 984 | |
854 | - if (is_null(self::$cache)) self::init_cache(); |
|
985 | + if (is_null(self::$cache)) |
|
986 | + { |
|
987 | + self::init_cache(); |
|
988 | + } |
|
855 | 989 | |
856 | 990 | $cat = self::$cache[$cat_id]; |
857 | 991 | if ($item == 'path') |
@@ -892,7 +1026,10 @@ discard block |
||
892 | 1026 | if ($cat_name) |
893 | 1027 | { |
894 | 1028 | $filter['name'] = $cat_name; |
895 | - if ($cat_id) $filter['id'] = '!'.(int)$cat_id; |
|
1029 | + if ($cat_id) |
|
1030 | + { |
|
1031 | + $filter['id'] = '!'.(int)$cat_id; |
|
1032 | + } |
|
896 | 1033 | } |
897 | 1034 | elseif ($cat_id) |
898 | 1035 | { |
@@ -921,7 +1058,10 @@ discard block |
||
921 | 1058 | { |
922 | 1059 | $where = array('cat_owner' => $owner); |
923 | 1060 | |
924 | - if ($app) $where['cat_appname'] = $app; |
|
1061 | + if ($app) |
|
1062 | + { |
|
1063 | + $where['cat_appname'] = $app; |
|
1064 | + } |
|
925 | 1065 | |
926 | 1066 | if ((int)$to) |
927 | 1067 | { |
@@ -967,7 +1107,11 @@ discard block |
||
967 | 1107 | false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
968 | 1108 | { |
969 | 1109 | $cat = Db::strip_array_keys($cat,'cat_'); |
970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
1110 | + if ($cat['appname'] == '*update*') |
|
1111 | + { |
|
1112 | + continue; |
|
1113 | + } |
|
1114 | + // --> ignore update marker |
|
971 | 1115 | $cat['app_name'] = $cat['appname']; |
972 | 1116 | // backlink children to their parent |
973 | 1117 | if ($cat['parent']) |
@@ -1058,7 +1202,10 @@ discard block |
||
1058 | 1202 | // ACL check |
1059 | 1203 | $cats = $GLOBALS['egw']->categories->check_list(Acl::READ, $_cats); |
1060 | 1204 | |
1061 | - if (!$cats) return null; |
|
1205 | + if (!$cats) |
|
1206 | + { |
|
1207 | + return null; |
|
1208 | + } |
|
1062 | 1209 | |
1063 | 1210 | if (isset($cat2color[$cats])) |
1064 | 1211 | { |
@@ -1090,7 +1237,10 @@ discard block |
||
1090 | 1237 | */ |
1091 | 1238 | public static function delete_account($account_id, $new_owner=null) |
1092 | 1239 | { |
1093 | - if (is_null(self::$cache)) self::init_cache(); |
|
1240 | + if (is_null(self::$cache)) |
|
1241 | + { |
|
1242 | + self::init_cache(); |
|
1243 | + } |
|
1094 | 1244 | |
1095 | 1245 | $deleted = 0; |
1096 | 1246 | $cat = null; |
@@ -1110,7 +1260,10 @@ discard block |
||
1110 | 1260 | else |
1111 | 1261 | { |
1112 | 1262 | unset($owners[$owner_key]); |
1113 | - if ($new_owner && $account_id > 0) $owners[] = $new_owner; |
|
1263 | + if ($new_owner && $account_id > 0) |
|
1264 | + { |
|
1265 | + $owners[] = $new_owner; |
|
1266 | + } |
|
1114 | 1267 | $data['owner'] = implode(',', $owners); |
1115 | 1268 | // app_name have to match cat to update! |
1116 | 1269 | if (!isset($cat) || $cat->app_name != $data['appname']) |
@@ -1132,7 +1285,10 @@ discard block |
||
1132 | 1285 | */ |
1133 | 1286 | public static function delete_orphans() |
1134 | 1287 | { |
1135 | - if (is_null(self::$cache)) self::init_cache(); |
|
1288 | + if (is_null(self::$cache)) |
|
1289 | + { |
|
1290 | + self::init_cache(); |
|
1291 | + } |
|
1136 | 1292 | |
1137 | 1293 | $checked = array(); |
1138 | 1294 | $deleted = 0; |
@@ -120,23 +120,23 @@ discard block |
||
120 | 120 | * @param int|string $accountid ='' account id or lid, default to current user |
121 | 121 | * @param string $app_name ='' app name defaults to current app |
122 | 122 | */ |
123 | - function __construct($accountid='',$app_name = '') |
|
123 | + function __construct($accountid = '', $app_name = '') |
|
124 | 124 | { |
125 | 125 | if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
126 | 126 | |
127 | 127 | if ($accountid === self::GLOBAL_ACCOUNT || |
128 | 128 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
129 | 129 | { |
130 | - $this->account_id = (int) $accountid; |
|
130 | + $this->account_id = (int)$accountid; |
|
131 | 131 | } |
132 | 132 | else |
133 | 133 | { |
134 | - $this->account_id = (int) get_account_id($accountid); |
|
134 | + $this->account_id = (int)get_account_id($accountid); |
|
135 | 135 | $this->global_owners = $this->account_id ? $GLOBALS['egw']->accounts->memberships($this->account_id, true) : array(); |
136 | 136 | $this->global_owners[] = self::GLOBAL_ACCOUNT; |
137 | 137 | } |
138 | - $this->app_name = $app_name; |
|
139 | - $this->db = $GLOBALS['egw']->db; |
|
138 | + $this->app_name = $app_name; |
|
139 | + $this->db = $GLOBALS['egw']->db; |
|
140 | 140 | |
141 | 141 | if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
142 | 142 | { |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | { |
159 | 159 | $all_children = array_map('intval', (array)$cat_id); |
160 | 160 | |
161 | - $children = $this->return_array('subs',0,False,'','','',True,$cat_id,-1,'id'); |
|
161 | + $children = $this->return_array('subs', 0, False, '', '', '', True, $cat_id, -1, 'id'); |
|
162 | 162 | if (is_array($children) && count($children)) |
163 | 163 | { |
164 | - $all_children = array_merge($all_children,$this->return_all_children($children)); |
|
164 | + $all_children = array_merge($all_children, $this->return_all_children($children)); |
|
165 | 165 | } |
166 | 166 | return $all_children; |
167 | 167 | } |
@@ -183,24 +183,24 @@ discard block |
||
183 | 183 | * @param array $filter =null array with column-name (without cat_-prefix) => value pairs (! negates the value) |
184 | 184 | * @return array of cat-arrays or $column values |
185 | 185 | */ |
186 | - function return_array($type='all', $start=0, $limit=true, $query='', $sort='ASC',$order='',$globals=false, $parent_id=null, $lastmod=-1, $column='', $filter=null) |
|
186 | + function return_array($type = 'all', $start = 0, $limit = true, $query = '', $sort = 'ASC', $order = '', $globals = false, $parent_id = null, $lastmod = -1, $column = '', $filter = null) |
|
187 | 187 | { |
188 | 188 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,globals=$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).") account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
189 | 189 | $cats = array(); |
190 | - foreach(self::$cache as $cat) |
|
190 | + foreach (self::$cache as $cat) |
|
191 | 191 | { |
192 | - if ($filter) foreach($filter as $col => $val) |
|
192 | + if ($filter) foreach ($filter as $col => $val) |
|
193 | 193 | { |
194 | 194 | if (!is_array($val) && $val[0] === '!') |
195 | 195 | { |
196 | 196 | // also match against trimmed database entry on name and description fields |
197 | 197 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
198 | 198 | { |
199 | - if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
|
199 | + if ($cat[$col] == substr($val, 1) || trim($cat[$col]) == substr($val, 1)) continue 2; |
|
200 | 200 | } |
201 | 201 | else |
202 | 202 | { |
203 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
203 | + if ($cat[$col] == substr($val, 1)) continue 2; |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | elseif (is_array($val)) |
@@ -208,11 +208,11 @@ discard block |
||
208 | 208 | // also match against trimmed database entry on name and description fields |
209 | 209 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
210 | 210 | { |
211 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
211 | + if (!in_array($cat[$col], $val) && !in_array(trim($cat[$col]), $val)) continue 2; |
|
212 | 212 | } |
213 | 213 | else |
214 | 214 | { |
215 | - if (!in_array($cat[$col],$val)) continue 2; |
|
215 | + if (!in_array($cat[$col], $val)) continue 2; |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | else |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | } |
230 | 230 | } |
231 | 231 | // check if certain parent required |
232 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
232 | + if ($parent_id && !in_array($cat['parent'], (array)$parent_id)) continue; |
|
233 | 233 | |
234 | 234 | // return global categories just if $globals is set |
235 | 235 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | } |
239 | 239 | |
240 | 240 | // check for read permission |
241 | - if(!$this->check_perms(Acl::READ, $cat, $globals === 'all_no_acl')) |
|
241 | + if (!$this->check_perms(Acl::READ, $cat, $globals === 'all_no_acl')) |
|
242 | 242 | { |
243 | 243 | continue; |
244 | 244 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | switch ($type) |
248 | 248 | { |
249 | 249 | case 'subs': |
250 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
250 | + if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
251 | 251 | break; |
252 | 252 | case 'mains': |
253 | 253 | if ($cat['parent']) continue 2; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | // check name and description for $query |
270 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
270 | + if ($query && stristr($cat['name'], $query) === false && stristr($cat['description'], $query) === false) continue; |
|
271 | 271 | |
272 | 272 | // check if last modified since |
273 | 273 | if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
@@ -284,37 +284,37 @@ discard block |
||
284 | 284 | if (!$sort) $sort = 'ASC'; |
285 | 285 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
286 | 286 | if ($this->total_records > 1 && !empty($order) && |
287 | - preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
|
287 | + preg_match('/^[a-zA-Z_(), ]+$/', $order) && preg_match('/^(ASC|DESC|asc|desc)$/', $sort)) |
|
288 | 288 | { |
289 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
290 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
289 | + if (strstr($order, 'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
290 | + if (substr($order, 0, 4) == 'cat_') $order = substr($order, 4); |
|
291 | 291 | $sign = strtoupper($sort) == 'DESC' ? -1 : 1; |
292 | 292 | usort($cats, function($a, $b) use ($order, $sign) |
293 | 293 | { |
294 | - if (in_array($order, array('name','description','appname','app_name'))) |
|
294 | + if (in_array($order, array('name', 'description', 'appname', 'app_name'))) |
|
295 | 295 | { |
296 | 296 | return $sign * strcasecmp($a[$order], $b[$order]); |
297 | 297 | } |
298 | - return $sign*(int)$a[$order] - $sign*(int)$b[$order]; |
|
298 | + return $sign * (int)$a[$order] - $sign * (int)$b[$order]; |
|
299 | 299 | }); |
300 | 300 | } |
301 | 301 | // limit the number of returned rows |
302 | 302 | if ($limit) |
303 | 303 | { |
304 | 304 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
305 | - $cats = array_slice($cats,(int)$start,$limit); |
|
305 | + $cats = array_slice($cats, (int)$start, $limit); |
|
306 | 306 | } |
307 | 307 | // return only a certain column (why not return is as value?) |
308 | 308 | if ($column) |
309 | 309 | { |
310 | - foreach($cats as $k => $cat) |
|
310 | + foreach ($cats as $k => $cat) |
|
311 | 311 | { |
312 | 312 | $cats[$k] = $cat[$column]; |
313 | 313 | } |
314 | 314 | } |
315 | 315 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).",$unserialize_data) account_id=$this->account_id, appname=$this->app_name = ".array2string($cats)); |
316 | 316 | |
317 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
317 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
318 | 318 | return $cats; |
319 | 319 | } |
320 | 320 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param boolean $unserialize_data =true return $cat['data'] as array (not serialized array) |
333 | 333 | * @return array with cats |
334 | 334 | */ |
335 | - function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
|
335 | + function return_sorted_array($start = 0, $limit = True, $query = '', $sort = 'ASC', $order = 'cat_name', $globals = False, $parent_id = 0, $unserialize_data = true, $filter = null) |
|
336 | 336 | { |
337 | 337 | if (!$sort) $sort = 'ASC'; |
338 | 338 | if (!$order) $order = 'cat_name'; |
@@ -342,27 +342,27 @@ discard block |
||
342 | 342 | $parents = $cats = array(); |
343 | 343 | |
344 | 344 | // Cast parent_id to array, but only if there is one |
345 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
346 | - if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
|
345 | + if ($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
346 | + if (!($cats = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parent_id, -1, '', $filter, $unserialize_data))) |
|
347 | 347 | { |
348 | 348 | $cats = array(); |
349 | 349 | } |
350 | - foreach($cats as $cat) |
|
350 | + foreach ($cats as $cat) |
|
351 | 351 | { |
352 | 352 | $parents[] = $cat['id']; |
353 | 353 | } |
354 | 354 | |
355 | - if($parent_id || !$cats) // Avoid wiping search results |
|
355 | + if ($parent_id || !$cats) // Avoid wiping search results |
|
356 | 356 | { |
357 | 357 | // Go find the children |
358 | 358 | while (count($parents)) |
359 | 359 | { |
360 | - if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
|
360 | + if (!($subs = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parents, -1, '', $filter, $unserialize_data))) |
|
361 | 361 | { |
362 | 362 | break; |
363 | 363 | } |
364 | 364 | $parents = $children = array(); |
365 | - foreach($subs as $cat) |
|
365 | + foreach ($subs as $cat) |
|
366 | 366 | { |
367 | 367 | $parents[] = $cat['id']; |
368 | 368 | $children[$cat['parent']][] = $cat; |
@@ -372,12 +372,12 @@ discard block |
||
372 | 372 | { |
373 | 373 | $cats2 = $cats; |
374 | 374 | $cats = array(); |
375 | - foreach($cats2 as $cat) |
|
375 | + foreach ($cats2 as $cat) |
|
376 | 376 | { |
377 | 377 | $cats[] = $cat; |
378 | 378 | if (isset($children[$cat['id']])) |
379 | 379 | { |
380 | - foreach($children[$cat['id']] as $child) |
|
380 | + foreach ($children[$cat['id']] as $child) |
|
381 | 381 | { |
382 | 382 | $cats[] = $child; |
383 | 383 | } |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | if ($limit) |
393 | 393 | { |
394 | 394 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
395 | - $cats = array_slice($cats,(int)$start,$limit); |
|
395 | + $cats = array_slice($cats, (int)$start, $limit); |
|
396 | 396 | } |
397 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
397 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
398 | 398 | return $cats; |
399 | 399 | } |
400 | 400 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | if (!isset(self::$cache[$id])) return false; |
416 | 416 | |
417 | 417 | $cat = self::$cache[$id]; |
418 | - $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
418 | + $cat['data'] = $cat['data'] ? ((($arr = json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
419 | 419 | $arr : $cat['data']) : array(); |
420 | 420 | |
421 | 421 | return $cat; |
@@ -433,31 +433,31 @@ discard block |
||
433 | 433 | { |
434 | 434 | if ((int)$values['parent'] > 0) |
435 | 435 | { |
436 | - $values['level'] = $this->id2name($values['parent'],'level')+1; |
|
437 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
436 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
437 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
438 | 438 | } |
439 | 439 | else |
440 | 440 | { |
441 | 441 | $values['level'] = 0; |
442 | 442 | } |
443 | - $this->db->insert(self::TABLE,$cat=array( |
|
443 | + $this->db->insert(self::TABLE, $cat = array( |
|
444 | 444 | 'cat_parent' => $values['parent'], |
445 | 445 | 'cat_owner' => isset($values['owner']) ? $values['owner'] : $this->account_id, |
446 | 446 | 'cat_access' => isset($values['access']) ? $values['access'] : 'public', |
447 | 447 | 'cat_appname' => $this->app_name, |
448 | 448 | 'cat_name' => $values['name'], |
449 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
449 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
450 | 450 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
451 | 451 | 'cat_main' => $values['main'], |
452 | 452 | 'cat_level' => $values['level'], |
453 | 453 | 'last_mod' => time(), |
454 | - ),(int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(),__LINE__,__FILE__); |
|
454 | + ), (int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(), __LINE__, __FILE__); |
|
455 | 455 | |
456 | - $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE,'cat_id'); |
|
456 | + $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE, 'cat_id'); |
|
457 | 457 | |
458 | 458 | if (!(int)$values['parent'] && $id != $values['main']) |
459 | 459 | { |
460 | - $this->db->update(self::TABLE,array('cat_main' => $id),array('cat_id' => $id),__LINE__,__FILE__); |
|
460 | + $this->db->update(self::TABLE, array('cat_main' => $id), array('cat_id' => $id), __LINE__, __FILE__); |
|
461 | 461 | $cat['cat_main'] = $id; |
462 | 462 | } |
463 | 463 | // update cache accordingly |
@@ -479,20 +479,20 @@ discard block |
||
479 | 479 | if (empty($cat_list)) return $cat_list; |
480 | 480 | if (is_array($cat_list)) |
481 | 481 | { |
482 | - $cat_list = implode(',',$cat_list); |
|
482 | + $cat_list = implode(',', $cat_list); |
|
483 | 483 | //error_log(__METHOD__.__LINE__.' string expected, array found for cat_list. Converted to:'.$cat_list); |
484 | 484 | } |
485 | - $cat_arr = explode(',',$cat_list); |
|
485 | + $cat_arr = explode(',', $cat_list); |
|
486 | 486 | if (!empty($cat_arr) && is_array($cat_arr) && count($cat_arr) > 0) |
487 | 487 | { |
488 | - foreach($cat_arr as $id=>$cat_id) |
|
488 | + foreach ($cat_arr as $id=>$cat_id) |
|
489 | 489 | { |
490 | 490 | if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) // allow reading all global cats |
491 | 491 | { |
492 | 492 | unset($cat_arr[$id]); |
493 | 493 | } |
494 | 494 | } |
495 | - $cat_list = implode(',',$cat_arr); |
|
495 | + $cat_list = implode(',', $cat_arr); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | return $cat_list; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
510 | 510 | * @return boolean true permission granted, false for permission denied, null for category does not exist |
511 | 511 | */ |
512 | - public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
|
512 | + public function check_perms($needed, $category, $no_acl_check = false, $allow_global_read = false) |
|
513 | 513 | { |
514 | 514 | if (!is_array($category) && !($category = self::read($category))) |
515 | 515 | { |
@@ -525,8 +525,8 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | // Read access to global categories |
528 | - if ($needed == Acl::READ && (($is_global=array_intersect(explode(',',$category['owner']),$this->global_owners)) || |
|
529 | - $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
528 | + if ($needed == Acl::READ && (($is_global = array_intersect(explode(',', $category['owner']), $this->global_owners)) || |
|
529 | + $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
530 | 530 | ($category['appname'] == self::GLOBAL_APPNAME || $category['appname'] == $this->app_name || |
531 | 531 | $is_global && $allow_global_read)) |
532 | 532 | { |
@@ -549,16 +549,16 @@ discard block |
||
549 | 549 | // Load the application grants |
550 | 550 | if ($category['appname'] == $this->app_name && is_null($this->grants)) |
551 | 551 | { |
552 | - $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name,true); |
|
552 | + $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name, true); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | // Check for ACL granted access, the self::GLOBAL_ACCOUNT user must not get access by ACL to keep old behaviour |
556 | 556 | $acl_grant = $this->account_id != self::GLOBAL_ACCOUNT && $category['appname'] == $this->app_name; |
557 | 557 | $owner_grant = false; |
558 | - foreach(explode(',',$category['owner']) as $owner) |
|
558 | + foreach (explode(',', $category['owner']) as $owner) |
|
559 | 559 | { |
560 | - $owner_grant = $owner_grant || (($this->grants[$owner] & $needed) && |
|
561 | - ($category['access'] == 'public' || ($this->grants[$owner] & Acl::PRIVAT))); |
|
560 | + $owner_grant = $owner_grant || (($this->grants[$owner]&$needed) && |
|
561 | + ($category['access'] == 'public' || ($this->grants[$owner]&Acl::PRIVAT))); |
|
562 | 562 | } |
563 | 563 | return $acl_grant && $owner_grant; |
564 | 564 | } |
@@ -575,35 +575,35 @@ discard block |
||
575 | 575 | //error_log(__METHOD__."(".array2string($cat_id).', drop_subs='.array2string($drop_subs).', modify_subs='.array2string($modify_subs).') '.function_backtrace()); |
576 | 576 | if ($modify_subs) |
577 | 577 | { |
578 | - $new_parent = $this->id2name($cat_id,'parent'); |
|
578 | + $new_parent = $this->id2name($cat_id, 'parent'); |
|
579 | 579 | |
580 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $cat_id) as $cat) |
|
580 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $cat_id) as $cat) |
|
581 | 581 | { |
582 | 582 | if ($cat['level'] == 1) |
583 | 583 | { |
584 | - $this->db->update(self::TABLE,array( |
|
584 | + $this->db->update(self::TABLE, array( |
|
585 | 585 | 'cat_level' => 0, |
586 | 586 | 'cat_parent' => 0, |
587 | 587 | 'cat_main' => $cat['id'], |
588 | - ),array( |
|
588 | + ), array( |
|
589 | 589 | 'cat_id' => $cat['id'], |
590 | 590 | 'cat_appname' => $this->app_name, |
591 | - ),__LINE__,__FILE__); |
|
591 | + ), __LINE__, __FILE__); |
|
592 | 592 | |
593 | 593 | $new_main = $cat['id']; |
594 | 594 | } |
595 | 595 | else |
596 | 596 | { |
597 | - $update = array('cat_level' => $cat['level']-1); |
|
597 | + $update = array('cat_level' => $cat['level'] - 1); |
|
598 | 598 | |
599 | 599 | if ($new_main) $update['cat_main'] = $new_main; |
600 | 600 | |
601 | 601 | if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
602 | 602 | |
603 | - $this->db->update(self::TABLE,$update,array( |
|
603 | + $this->db->update(self::TABLE, $update, array( |
|
604 | 604 | 'cat_id' => $cat['id'], |
605 | 605 | 'cat_appname' => $this->app_name, |
606 | - ),__LINE__,__FILE__); |
|
606 | + ), __LINE__, __FILE__); |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | } |
@@ -624,16 +624,16 @@ discard block |
||
624 | 624 | 'modify_subs' => $modify_subs, |
625 | 625 | 'location' => 'delete_category' |
626 | 626 | ); |
627 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
627 | + if ($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
628 | 628 | { |
629 | - Hooks::process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
629 | + Hooks::process($GLOBALS['hook_values'], False, True); // called for every app now, not only enabled ones) |
|
630 | 630 | } |
631 | 631 | else |
632 | 632 | { |
633 | - Hooks::single($GLOBALS['hook_values'], self::id2name($cat_id,'appname')); |
|
633 | + Hooks::single($GLOBALS['hook_values'], self::id2name($cat_id, 'appname')); |
|
634 | 634 | } |
635 | 635 | |
636 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
636 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
637 | 637 | |
638 | 638 | // update cache accordingly |
639 | 639 | self::invalidate_cache($modify_subs ? null : $where['cat_id']); |
@@ -649,17 +649,17 @@ discard block |
||
649 | 649 | */ |
650 | 650 | function adapt_level_in_subtree($values) |
651 | 651 | { |
652 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
652 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
653 | 653 | { |
654 | 654 | if ($cat['parent'] == $values['id']) |
655 | 655 | { |
656 | - $this->db->update(self::TABLE,array( |
|
657 | - 'cat_level' => $values['level']+1, |
|
656 | + $this->db->update(self::TABLE, array( |
|
657 | + 'cat_level' => $values['level'] + 1, |
|
658 | 658 | 'last_mod' => time(), |
659 | - ),array( |
|
659 | + ), array( |
|
660 | 660 | 'cat_id' => $cat['id'], |
661 | 661 | 'cat_appname' => $this->app_name, |
662 | - ),__LINE__,__FILE__); |
|
662 | + ), __LINE__, __FILE__); |
|
663 | 663 | $cat['level'] = $values['level'] + 1; |
664 | 664 | self::invalidate_cache($cat['id']); |
665 | 665 | $this->adapt_level_in_subtree($cat); |
@@ -680,14 +680,14 @@ discard block |
||
680 | 680 | function check_consistency4update($values) |
681 | 681 | { |
682 | 682 | // check if we try to move an element down its own subtree, which will fail |
683 | - foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
683 | + foreach ($this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
684 | 684 | { |
685 | 685 | if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
686 | 686 | } |
687 | 687 | // check if we try to be our own parent |
688 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
688 | + if ($values['parent'] == $values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
689 | 689 | // check if parent still exists |
690 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
690 | + if ((int)$values['parent'] > 0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
691 | 691 | return true; |
692 | 692 | } |
693 | 693 | |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | $ret = $this->check_consistency4update($values); |
707 | 707 | if ($ret !== true) throw new Exception\WrongUserinput($ret); |
708 | 708 | // everything seems in order -> proceed |
709 | - $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
|
709 | + $values['level'] = ($values['parent'] ? $this->id2name($values['parent'], 'level') + 1 : 0); |
|
710 | 710 | $this->adapt_level_in_subtree($values); |
711 | 711 | |
712 | 712 | return $this->add($values); |
@@ -720,8 +720,8 @@ discard block |
||
720 | 720 | if ($ret !== true) throw new Exception\WrongUserinput($ret); |
721 | 721 | |
722 | 722 | // everything seems in order -> proceed |
723 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
724 | - $values['level'] = $this->id2name($values['parent'],'level') + 1; |
|
723 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
724 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
725 | 725 | } |
726 | 726 | else |
727 | 727 | { |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | // adapt the level info in each child |
733 | 733 | $this->adapt_level_in_subtree($values); |
734 | 734 | } |
735 | - $this->db->update(self::TABLE,$cat=array( |
|
735 | + $this->db->update(self::TABLE, $cat = array( |
|
736 | 736 | 'cat_name' => $values['name'], |
737 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
737 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
738 | 738 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
739 | 739 | 'cat_parent' => $values['parent'], |
740 | 740 | 'cat_access' => $values['access'], |
@@ -742,10 +742,10 @@ discard block |
||
742 | 742 | 'cat_main' => $values['main'], |
743 | 743 | 'cat_level' => $values['level'], |
744 | 744 | 'last_mod' => time(), |
745 | - ),array( |
|
745 | + ), array( |
|
746 | 746 | 'cat_id' => $values['id'], |
747 | 747 | 'cat_appname' => $this->app_name, |
748 | - ),__LINE__,__FILE__); |
|
748 | + ), __LINE__, __FILE__); |
|
749 | 749 | |
750 | 750 | $cat['cat_id'] = $values['id']; |
751 | 751 | $cat['cat_appname'] = $this->app_name; |
@@ -769,9 +769,9 @@ discard block |
||
769 | 769 | * @param boolean|string $strip =false if true, strips 'X-' ($strip) from category names added by some SyncML clients |
770 | 770 | * @return int cat-id or 0 if not found |
771 | 771 | */ |
772 | - function name2id($cat_name, $strip=false) |
|
772 | + function name2id($cat_name, $strip = false) |
|
773 | 773 | { |
774 | - static $cache = array(); // a litle bit of caching |
|
774 | + static $cache = array(); // a litle bit of caching |
|
775 | 775 | |
776 | 776 | if (isset($cache[$cat_name])) return $cache[$cat_name]; |
777 | 777 | |
@@ -792,17 +792,17 @@ discard block |
||
792 | 792 | $cats[] = $stripped_cat_name; |
793 | 793 | } |
794 | 794 | |
795 | - if (!($cats = $this->return_array('all',0,false,'','','',true,null,-1,'',array( |
|
795 | + if (!($cats = $this->return_array('all', 0, false, '', '', '', true, null, -1, '', array( |
|
796 | 796 | 'name' => $cats, |
797 | 797 | 'appname' => array($this->app_name, self::GLOBAL_APPNAME), |
798 | 798 | )))) |
799 | 799 | { |
800 | - return 0; // cat not found, dont cache it, as it might be created in this request |
|
800 | + return 0; // cat not found, dont cache it, as it might be created in this request |
|
801 | 801 | } |
802 | 802 | if (count($cats) > 1) |
803 | 803 | { |
804 | 804 | // if more the one cat matches we weight them by: exact name match; own, global, other users cat; appplication cats |
805 | - foreach($cats as $k => $cat) |
|
805 | + foreach ($cats as $k => $cat) |
|
806 | 806 | { |
807 | 807 | $cats[$k]['weight'] = 100 * ($cat['name'] == $cat_name) + |
808 | 808 | 10 * ($cat['owner'] == $this->account_id ? 3 : ($cat['owner'] <= self::GLOBAL_ACCOUNT ? 2 : 1)) + |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | return $b['weight'] - $a['weight']; |
815 | 815 | }); |
816 | 816 | } |
817 | - return $cache[$cat['cat_name']] = (int) $cats[0]['id']; |
|
817 | + return $cache[$cat['cat_name']] = (int)$cats[0]['id']; |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
@@ -824,12 +824,12 @@ discard block |
||
824 | 824 | * @param boolean $application_global =false true check for application global categories only (appname == 'phpgw') |
825 | 825 | * @return boolean |
826 | 826 | */ |
827 | - static function is_global($cat,$application_global=false) |
|
827 | + static function is_global($cat, $application_global = false) |
|
828 | 828 | { |
829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
829 | + if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
830 | 830 | |
831 | 831 | $global_owner = false; |
832 | - foreach(explode(',',$cat['owner']) as $owner) |
|
832 | + foreach (explode(',', $cat['owner']) as $owner) |
|
833 | 833 | { |
834 | 834 | $global_owner = $global_owner || $owner <= self::GLOBAL_ACCOUNT; |
835 | 835 | } |
@@ -846,9 +846,9 @@ discard block |
||
846 | 846 | * @param string $item ='name' requested information, 'path' = / delimited path of category names (incl. parents) |
847 | 847 | * @return string information or '--' if not found or !$cat_id |
848 | 848 | */ |
849 | - static function id2name($cat_id=0, $item='name') |
|
849 | + static function id2name($cat_id = 0, $item = 'name') |
|
850 | 850 | { |
851 | - if(!$cat_id) return '--'; |
|
851 | + if (!$cat_id) return '--'; |
|
852 | 852 | if (!$item) $item = 'parent'; |
853 | 853 | |
854 | 854 | if (is_null(self::$cache)) self::init_cache(); |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | { |
859 | 859 | if ($cat['parent']) |
860 | 860 | { |
861 | - return self::id2name($cat['parent'],'path').' / '.$cat['name']; |
|
861 | + return self::id2name($cat['parent'], 'path').' / '.$cat['name']; |
|
862 | 862 | } |
863 | 863 | $item = 'name'; |
864 | 864 | } |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @param int $parent =0 category id of parent |
888 | 888 | * @return int/boolean cat_id or false if cat not exists |
889 | 889 | */ |
890 | - function exists($type,$cat_name = '',$cat_id = 0,$parent = 0) |
|
890 | + function exists($type, $cat_name = '', $cat_id = 0, $parent = 0) |
|
891 | 891 | { |
892 | 892 | if ($cat_name) |
893 | 893 | { |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | { |
899 | 899 | $filter['id'] = $cat_id; |
900 | 900 | } |
901 | - if (!($cats = $this->return_array($type,0,false,'','','',true,$parent,-1,'id',$filter))) |
|
901 | + if (!($cats = $this->return_array($type, 0, false, '', '', '', true, $parent, -1, 'id', $filter))) |
|
902 | 902 | { |
903 | 903 | $ret = false; |
904 | 904 | } |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | * @param int $to =0 new owner or 0 to delete the cats |
918 | 918 | * @param string $app ='' if given only cats matching $app are modifed/deleted |
919 | 919 | */ |
920 | - function change_owner($owner,$to=0,$app='') |
|
920 | + function change_owner($owner, $to = 0, $app = '') |
|
921 | 921 | { |
922 | 922 | $where = array('cat_owner' => $owner); |
923 | 923 | |
@@ -925,11 +925,11 @@ discard block |
||
925 | 925 | |
926 | 926 | if ((int)$to) |
927 | 927 | { |
928 | - $this->db->update(self::TABLE,array('cat_owner' => $to),$where,__LINE__,__FILE__); |
|
928 | + $this->db->update(self::TABLE, array('cat_owner' => $to), $where, __LINE__, __FILE__); |
|
929 | 929 | } |
930 | 930 | else |
931 | 931 | { |
932 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
932 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
933 | 933 | } |
934 | 934 | // update cache accordingly |
935 | 935 | self::invalidate_cache(); |
@@ -947,10 +947,10 @@ discard block |
||
947 | 947 | if (is_null(self::$cache)) |
948 | 948 | { |
949 | 949 | // check if we are already updated to global owner == 0, if not do it now |
950 | - if (!$GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',array('cat_owner'=>'0'),__LINE__,__FILE__)->fetchColumn()) |
|
950 | + if (!$GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', array('cat_owner'=>'0'), __LINE__, __FILE__)->fetchColumn()) |
|
951 | 951 | { |
952 | - $GLOBALS['egw']->db->update(self::TABLE,array('cat_owner'=>'0'),"(cat_owner='-1' OR cat_appname='phpgw')",__LINE__,__FILE__); |
|
953 | - $GLOBALS['egw']->db->insert(self::TABLE,array( |
|
952 | + $GLOBALS['egw']->db->update(self::TABLE, array('cat_owner'=>'0'), "(cat_owner='-1' OR cat_appname='phpgw')", __LINE__, __FILE__); |
|
953 | + $GLOBALS['egw']->db->insert(self::TABLE, array( |
|
954 | 954 | 'cat_main' => 0, |
955 | 955 | 'cat_parent' => 0, |
956 | 956 | 'cat_level' => 0, |
@@ -959,15 +959,15 @@ discard block |
||
959 | 959 | 'cat_name' => 'global=0', |
960 | 960 | 'cat_description' => 'global=0', |
961 | 961 | 'last_mod' => time(), |
962 | - ),false,__LINE__,__FILE__); |
|
962 | + ), false, __LINE__, __FILE__); |
|
963 | 963 | } |
964 | 964 | self::$cache = array(); |
965 | 965 | // read all cats (cant use $this->db!) |
966 | - foreach($GLOBALS['egw']->db->select(self::TABLE,'*',false,__LINE__,__FILE__, |
|
967 | - false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
966 | + foreach ($GLOBALS['egw']->db->select(self::TABLE, '*', false, __LINE__, __FILE__, |
|
967 | + false, 'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
968 | 968 | { |
969 | - $cat = Db::strip_array_keys($cat,'cat_'); |
|
970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
969 | + $cat = Db::strip_array_keys($cat, 'cat_'); |
|
970 | + if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
971 | 971 | $cat['app_name'] = $cat['appname']; |
972 | 972 | // backlink children to their parent |
973 | 973 | if ($cat['parent']) |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | if (isset(self::$cache[$cat['id']])) |
978 | 978 | { |
979 | 979 | $cat['children'] = self::$cache[$cat['id']]['children']; |
980 | - unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
980 | + unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
981 | 981 | } |
982 | 982 | self::$cache[$cat['id']] = $cat; |
983 | 983 | } |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | * |
995 | 995 | * @param int|array $cat concerned id(s) or array with cat-data or null for all cats |
996 | 996 | */ |
997 | - public static function invalidate_cache($cat=null) |
|
997 | + public static function invalidate_cache($cat = null) |
|
998 | 998 | { |
999 | 999 | //error_log(__METHOD__."(".array2string($cat).') '.function_backtrace()); |
1000 | 1000 | |
@@ -1006,12 +1006,12 @@ discard block |
||
1006 | 1006 | { |
1007 | 1007 | if (!is_array($cat) || isset($cat[0])) |
1008 | 1008 | { |
1009 | - foreach((array)$cat as $cat_id) |
|
1009 | + foreach ((array)$cat as $cat_id) |
|
1010 | 1010 | { |
1011 | 1011 | unset(self::$cache[$cat_id]); |
1012 | 1012 | } |
1013 | 1013 | } |
1014 | - elseif($cat['id']) |
|
1014 | + elseif ($cat['id']) |
|
1015 | 1015 | { |
1016 | 1016 | self::$cache[$cat['id']] = $cat; |
1017 | 1017 | } |
@@ -1034,8 +1034,8 @@ discard block |
||
1034 | 1034 | */ |
1035 | 1035 | public static function css($appname) |
1036 | 1036 | { |
1037 | - $cats = new Categories('',$appname); |
|
1038 | - $last_mod = $cats->return_array('all',0,1,'','DESC','last_mod', $appname == self::GLOBAL_APPNAME); |
|
1037 | + $cats = new Categories('', $appname); |
|
1038 | + $last_mod = $cats->return_array('all', 0, 1, '', 'DESC', 'last_mod', $appname == self::GLOBAL_APPNAME); |
|
1039 | 1039 | $time = count($last_mod) ? $last_mod[0]['last_mod'] : time(); |
1040 | 1040 | $path = '/api/categories.php?app='.$appname.'&'.$time; |
1041 | 1041 | Framework::includeCSS($path); |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | return $cat2color[$cats]; |
1066 | 1066 | } |
1067 | 1067 | |
1068 | - foreach(explode(',', $cats) as $cat) |
|
1068 | + foreach (explode(',', $cats) as $cat) |
|
1069 | 1069 | { |
1070 | 1070 | if (isset($cat2color[$cat])) |
1071 | 1071 | { |
@@ -1088,13 +1088,13 @@ discard block |
||
1088 | 1088 | * @param int $new_owner =null for users data can be transfered to new owner |
1089 | 1089 | * @return int number of deleted or modified categories |
1090 | 1090 | */ |
1091 | - public static function delete_account($account_id, $new_owner=null) |
|
1091 | + public static function delete_account($account_id, $new_owner = null) |
|
1092 | 1092 | { |
1093 | 1093 | if (is_null(self::$cache)) self::init_cache(); |
1094 | 1094 | |
1095 | 1095 | $deleted = 0; |
1096 | 1096 | $cat = null; |
1097 | - foreach(self::$cache as $cat_id => $data) |
|
1097 | + foreach (self::$cache as $cat_id => $data) |
|
1098 | 1098 | { |
1099 | 1099 | if ($data['owner'] && ($owners = explode(',', $data['owner'])) && ($owner_key = array_search($account_id, $owners)) !== false) |
1100 | 1100 | { |
@@ -1136,9 +1136,9 @@ discard block |
||
1136 | 1136 | |
1137 | 1137 | $checked = array(); |
1138 | 1138 | $deleted = 0; |
1139 | - foreach(self::$cache as $data) |
|
1139 | + foreach (self::$cache as $data) |
|
1140 | 1140 | { |
1141 | - foreach(explode(',', $data['owner']) as $owner) |
|
1141 | + foreach (explode(',', $data['owner']) as $owner) |
|
1142 | 1142 | { |
1143 | 1143 | if ($owner && !in_array($owner, $checked)) |
1144 | 1144 | { |