@@ -29,21 +29,21 @@ |
||
29 | 29 | * @param string $cname |
30 | 30 | * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' |
31 | 31 | */ |
32 | - public function beforeSendToClient($cname, array $expand=null) |
|
32 | + public function beforeSendToClient($cname, array $expand = null) |
|
33 | 33 | { |
34 | 34 | $form_name = self::form_name($cname, $this->id, $expand); |
35 | - $value =& self::get_array(self::$request->content, $form_name); |
|
35 | + $value = & self::get_array(self::$request->content, $form_name); |
|
36 | 36 | |
37 | 37 | $image = $value != '' ? $value : $this->attrs['src']; |
38 | 38 | |
39 | - if (is_string($image)) list($app,$img) = explode('/',$image,2); |
|
40 | - if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img,'/')!==false) |
|
39 | + if (is_string($image)) list($app, $img) = explode('/', $image, 2); |
|
40 | + if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img, '/') !== false) |
|
41 | 41 | { |
42 | 42 | $img = $image; |
43 | - list($app) = explode('.',$form_name); |
|
43 | + list($app) = explode('.', $form_name); |
|
44 | 44 | } |
45 | 45 | $src = Api\Image::find($app, $img); |
46 | - if(!$this->id) |
|
46 | + if (!$this->id) |
|
47 | 47 | { |
48 | 48 | // self::setElementAttribute($this->attrs['src'], 'id', $this->attrs['src']); |
49 | 49 | } |
@@ -36,7 +36,10 @@ |
||
36 | 36 | |
37 | 37 | $image = $value != '' ? $value : $this->attrs['src']; |
38 | 38 | |
39 | - if (is_string($image)) list($app,$img) = explode('/',$image,2); |
|
39 | + if (is_string($image)) |
|
40 | + { |
|
41 | + list($app,$img) = explode('/',$image,2); |
|
42 | + } |
|
40 | 43 | if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img,'/')!==false) |
41 | 44 | { |
42 | 45 | $img = $image; |
@@ -32,7 +32,7 @@ |
||
32 | 32 | { |
33 | 33 | $GLOBALS['egw_info']['flags']['currentapp'] = 'etemplate'; |
34 | 34 | $GLOBALS['egw_info']['flags']['app_header'] = 'et2 Widgets'; |
35 | - //'js_link_registry' => True, |
|
35 | + //'js_link_registry' => True, |
|
36 | 36 | |
37 | 37 | // Widget browser code |
38 | 38 | Api\Framework::includeJS('/api/js/etemplate/widget_browser.js'); |
@@ -46,7 +46,7 @@ |
||
46 | 46 | |
47 | 47 | Api\Framework::includeCSS('/api/templates/default/etemplate2.css'); |
48 | 48 | |
49 | - Api\Framework::includeCSS('api','widget_browser',false); |
|
49 | + Api\Framework::includeCSS('api', 'widget_browser', false); |
|
50 | 50 | |
51 | 51 | // load translations |
52 | 52 | Api\Translation::add_app('etemplate'); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | return $mime; |
48 | 48 | } |
49 | - return lang('%1 file',strtoupper($ext)).' ('.$mime.')'; |
|
49 | + return lang('%1 file', strtoupper($ext)).' ('.$mime.')'; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | if (empty($_ext)) |
65 | 65 | { |
66 | - return 'text/plain';//assume no extension is a text file |
|
66 | + return 'text/plain'; //assume no extension is a text file |
|
67 | 67 | } |
68 | 68 | $ext = strtolower($_ext); |
69 | 69 | if (!array_key_exists($ext, self::$mime_extension_map)) |
@@ -188,24 +188,24 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public static function analyze_data($data) |
190 | 190 | { |
191 | - if(!is_writeable(@$GLOBALS['egw_info']['server']['temp_dir'])) |
|
191 | + if (!is_writeable(@$GLOBALS['egw_info']['server']['temp_dir'])) |
|
192 | 192 | { |
193 | 193 | //nothing we can do but bail out |
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | |
197 | 197 | mt_srand(time()); |
198 | - $filename = $GLOBALS['egw_info']['server']['temp_dir'] . '/' |
|
199 | - . md5( time() + mt_rand() ) . '.tmp'; |
|
198 | + $filename = $GLOBALS['egw_info']['server']['temp_dir'].'/' |
|
199 | + . md5(time() + mt_rand()).'.tmp'; |
|
200 | 200 | |
201 | 201 | $fp = @fopen($filename, 'ab'); |
202 | - if(!$fp || !$data) |
|
202 | + if (!$fp || !$data) |
|
203 | 203 | { |
204 | 204 | //houston we have a problem - bail out |
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | - if(!fwrite($fp, $data)) |
|
208 | + if (!fwrite($fp, $data)) |
|
209 | 209 | { |
210 | 210 | //bail out again |
211 | 211 | return false; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | |
216 | 216 | $mime = self::analyze_file($filename); |
217 | 217 | |
218 | - unlink($filename);//remove the temp file |
|
218 | + unlink($filename); //remove the temp file |
|
219 | 219 | |
220 | 220 | return $mime; |
221 | 221 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @var array of extenstion to mime mappings |
234 | 234 | */ |
235 | 235 | static $mime_extension_map = array( |
236 | - 'txt' => 'text/plain', // should be first, so text/plain maps back to .txt |
|
236 | + 'txt' => 'text/plain', // should be first, so text/plain maps back to .txt |
|
237 | 237 | '3dml' => 'text/vnd.in3d.3dml', |
238 | 238 | '3ds' => 'image/x-3ds', |
239 | 239 | '3g2' => 'video/3gpp2', |
@@ -106,7 +106,10 @@ |
||
106 | 106 | public static function mime2ext($_type) |
107 | 107 | { |
108 | 108 | $type = strtolower($_type); |
109 | - if (isset(self::$mime_alias_map[$type])) $type = self::$mime_alias_map[$type]; |
|
109 | + if (isset(self::$mime_alias_map[$type])) |
|
110 | + { |
|
111 | + $type = self::$mime_alias_map[$type]; |
|
112 | + } |
|
110 | 113 | $key = array_search($type, self::$mime_extension_map); |
111 | 114 | if (empty($type) || $key === false) |
112 | 115 | { |
@@ -29,7 +29,7 @@ |
||
29 | 29 | class Exception extends \Exception |
30 | 30 | { |
31 | 31 | // nothing fancy yet |
32 | - function __construct($msg=null,$code=100,\Exception $previous=null) |
|
32 | + function __construct($msg = null, $code = 100, \Exception $previous = null) |
|
33 | 33 | { |
34 | 34 | return parent::__construct($msg, $code, $previous); |
35 | 35 | } |
@@ -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')); |
@@ -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', |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * If no account_id is set in data the account is added and the new id is set in $data. |
190 | 190 | * |
191 | 191 | * @param array $data array with account-data |
192 | - * @return int|boolean the account_id or false on error |
|
192 | + * @return false|string the account_id or false on error |
|
193 | 193 | */ |
194 | 194 | function save(&$data) |
195 | 195 | { |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | * |
989 | 989 | * @param int $account_id numerica account_id |
990 | 990 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
991 | - * @return string|false converted value or false on error ($account_id not found) |
|
991 | + * @return string|boolean converted value or false on error ($account_id not found) |
|
992 | 992 | */ |
993 | 993 | function id2name($account_id,$which='account_lid') |
994 | 994 | { |
@@ -1000,7 +1000,7 @@ discard block |
||
1000 | 1000 | * |
1001 | 1001 | * @param int $_account_id |
1002 | 1002 | * @param string $ip |
1003 | - * @return int lastlogin time |
|
1003 | + * @return boolean lastlogin time |
|
1004 | 1004 | */ |
1005 | 1005 | function update_lastlogin($_account_id, $ip) |
1006 | 1006 | { |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | */ |
89 | 89 | var $requiredObjectClasses = array( |
90 | 90 | 'user' => array( |
91 | - 'top','person','organizationalperson','inetorgperson','posixaccount','shadowaccount' |
|
91 | + 'top', 'person', 'organizationalperson', 'inetorgperson', 'posixaccount', 'shadowaccount' |
|
92 | 92 | ), |
93 | 93 | 'user-if-supported' => array( // these classes get added, if server supports them |
94 | 94 | 'mozillaabpersonalpha', 'mozillaorgperson', 'evolutionperson', |
95 | 95 | 'univentionperson', 'univentionmail', array('univentionobject', 'univentionObjectType' => 'users/user'), |
96 | 96 | ), |
97 | 97 | 'group' => array( |
98 | - 'top','posixgroup','groupofnames' |
|
98 | + 'top', 'posixgroup', 'groupofnames' |
|
99 | 99 | ), |
100 | 100 | 'group-if-supported' => array( // these classes get added, if servers supports them |
101 | 101 | 'univentiongroup', array('univentionobject', 'univentionObjectType' => 'groups/group'), |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | */ |
115 | 115 | var $group_mail_classes = array( |
116 | 116 | 'dbmailforwardingaddress' => 'mailforwardingaddress', |
117 | - 'dbmailuser' => array('mailforwardingaddress','uid'), |
|
118 | - 'qmailuser' => array('mailforwardingaddress','uid'), |
|
117 | + 'dbmailuser' => array('mailforwardingaddress', 'uid'), |
|
118 | + 'qmailuser' => array('mailforwardingaddress', 'uid'), |
|
119 | 119 | 'mailaccount' => 'mailalias', |
120 | 120 | 'univentiongroup' => array(false, false, true), |
121 | 121 | ); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $this->use_session_cache = true; |
158 | 158 | |
159 | 159 | $this->ldap = Api\Ldap::factory(false, $this->frontend->config['ldap_host'], |
160 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
160 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
161 | 161 | $this->ds = $this->ldap->ds; |
162 | 162 | |
163 | 163 | $this->user_context = $this->frontend->config['ldap_context']; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | { |
196 | 196 | $is_group = $data['account_id'] < 0 || $data['account_type'] === 'g'; |
197 | 197 | |
198 | - $data_utf8 = Api\Translation::convert($data,Api\Translation::charset(),'utf-8'); |
|
198 | + $data_utf8 = Api\Translation::convert($data, Api\Translation::charset(), 'utf-8'); |
|
199 | 199 | $members = $data['account_members']; |
200 | 200 | |
201 | 201 | if (!is_object($this->ldapServerInfo)) |
@@ -207,8 +207,7 @@ discard block |
||
207 | 207 | if ($data_utf8['account_id'] && $data_utf8['account_lid']) |
208 | 208 | { |
209 | 209 | // read the entry first, to check if the dn (account_lid) has changed |
210 | - $sri = $is_group ? ldap_search($this->ds,$this->group_context,'gidnumber='.abs($data['account_id'])) : |
|
211 | - ldap_search($this->ds,$this->user_context,'uidnumber='.$data['account_id']); |
|
210 | + $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']); |
|
212 | 211 | $old = ldap_get_entries($this->ds, $sri); |
213 | 212 | |
214 | 213 | if (!$old['count']) |
@@ -220,9 +219,9 @@ discard block |
||
220 | 219 | $old = Api\Ldap::result2array($old[0]); |
221 | 220 | $old['objectclass'] = array_map('strtolower', $old['objectclass']); |
222 | 221 | $key = false; |
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=')) |
|
222 | + if ($is_group && ($key = array_search('namedobject', $old['objectclass'])) !== false || |
|
223 | + $is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 3) != 'cn=') || |
|
224 | + !$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 4) != 'uid=')) |
|
226 | 225 | { |
227 | 226 | // query the memberships to set them again later |
228 | 227 | if (!$is_group) |
@@ -251,7 +250,7 @@ discard block |
||
251 | 250 | } |
252 | 251 | } |
253 | 252 | // check if we need to write the objectclass: new entry or required object classes are missing |
254 | - if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'],$old['objectclass'])) |
|
253 | + if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'], $old['objectclass'])) |
|
255 | 254 | { |
256 | 255 | // additional objectclasse might be already set in $to_write or $old |
257 | 256 | if (!is_array($to_write['objectclass'])) |
@@ -260,7 +259,7 @@ discard block |
||
260 | 259 | } |
261 | 260 | if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
262 | 261 | { // as setting them later might loose eg. password, if we are not allowed to read them |
263 | - foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
|
262 | + foreach ($this->requiredObjectClasses[$is_group ? 'group-if-supported' : 'user-if-supported'] as $additional) |
|
264 | 263 | { |
265 | 264 | $add = array(); |
266 | 265 | if (is_array($additional)) |
@@ -282,8 +281,7 @@ discard block |
||
282 | 281 | { |
283 | 282 | if (!$data['account_lid']) return false; |
284 | 283 | |
285 | - $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
|
286 | - 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
284 | + $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
287 | 285 | } |
288 | 286 | // now we merge the user or group data |
289 | 287 | if ($is_group) |
@@ -292,23 +290,23 @@ discard block |
||
292 | 290 | $data['account_type'] = 'g'; |
293 | 291 | |
294 | 292 | $objectclass = $old ? $old['objectclass'] : $to_write['objectclass']; |
295 | - if ($members || !$old && array_intersect(array('groupofnames','groupofuniquenames','univentiongroup'), $objectclass)) |
|
293 | + if ($members || !$old && array_intersect(array('groupofnames', 'groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
296 | 294 | { |
297 | 295 | $to_write = array_merge($to_write, $this->set_members($members, $data['account_id'], $objectclass, $dn)); |
298 | 296 | } |
299 | 297 | // check if we should set a mail address and forwards for each member |
300 | - foreach($this->group_mail_classes as $objectclass => $forward) |
|
298 | + foreach ($this->group_mail_classes as $objectclass => $forward) |
|
301 | 299 | { |
302 | 300 | $extra_attr = false; |
303 | 301 | $keep_objectclass = false; |
304 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
302 | + if (is_array($forward)) list($forward, $extra_attr, $keep_objectclass) = $forward; |
|
305 | 303 | |
306 | 304 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
307 | - ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
305 | + ($old && in_array($objectclass, $old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
308 | 306 | { |
309 | 307 | if ($data_utf8['account_email']) // setting an email |
310 | 308 | { |
311 | - if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
|
309 | + if (!in_array($objectclass, $old ? $old['objectclass'] : $to_write['objectclass'])) |
|
312 | 310 | { |
313 | 311 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
314 | 312 | $to_write['objectclass'][] = $objectclass; |
@@ -322,19 +320,19 @@ discard block |
||
322 | 320 | $to_write[$forward] = array(); |
323 | 321 | foreach (array_keys($members) as $member) |
324 | 322 | { |
325 | - if (($email = $this->id2name($member,'account_email'))) |
|
323 | + if (($email = $this->id2name($member, 'account_email'))) |
|
326 | 324 | { |
327 | 325 | $to_write[$forward][] = $email; |
328 | 326 | } |
329 | 327 | } |
330 | 328 | } |
331 | 329 | } |
332 | - elseif($old) // remove the mail and forwards only for existing entries |
|
330 | + elseif ($old) // remove the mail and forwards only for existing entries |
|
333 | 331 | { |
334 | 332 | $to_write[static::MAIL_ATTR] = array(); |
335 | 333 | if ($forward) $to_write[$forward] = array(); |
336 | 334 | if ($extra_attr) $to_write[$extra_attr] = array(); |
337 | - if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
|
335 | + if (!$keep_objectclass && ($key = array_search($objectclass, $old['objectclass']))) |
|
338 | 336 | { |
339 | 337 | $to_write['objectclass'] = $old['objectclass']; |
340 | 338 | unset($to_write['objectclass'][$key]); |
@@ -348,7 +346,7 @@ discard block |
||
348 | 346 | } |
349 | 347 | else |
350 | 348 | { |
351 | - $to_write = $this->_merge_user($to_write,$data_utf8,!$old); |
|
349 | + $to_write = $this->_merge_user($to_write, $data_utf8, !$old); |
|
352 | 350 | // make sure multiple email-addresses in the mail attribute "survive" |
353 | 351 | if (isset($to_write[static::MAIL_ATTR]) && count($old[static::MAIL_ATTR]) > 1) |
354 | 352 | { |
@@ -367,21 +365,21 @@ discard block |
||
367 | 365 | } |
368 | 366 | |
369 | 367 | // remove memberuid when adding a group |
370 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
368 | + if (!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
371 | 369 | unset($to_write['memberuid']); |
372 | 370 | } |
373 | 371 | // modifying or adding the entry |
374 | - if ($old && !@ldap_modify($this->ds,$dn,$to_write) || |
|
375 | - !$old && !@ldap_add($this->ds,$dn,$to_write)) |
|
372 | + if ($old && !@ldap_modify($this->ds, $dn, $to_write) || |
|
373 | + !$old && !@ldap_add($this->ds, $dn, $to_write)) |
|
376 | 374 | { |
377 | 375 | $err = true; |
378 | - if ($is_group && ($key = array_search('groupofnames',$to_write['objectclass'])) !== false) |
|
376 | + if ($is_group && ($key = array_search('groupofnames', $to_write['objectclass'])) !== false) |
|
379 | 377 | { |
380 | 378 | // try again with removed groupOfNames stuff, as I cant detect if posixGroup is a structural object |
381 | 379 | unset($to_write['objectclass'][$key]); |
382 | 380 | $to_write['objectclass'] = array_values($to_write['objectclass']); |
383 | 381 | unset($to_write['member']); |
384 | - $err = $old ? !ldap_modify($this->ds,$dn,$to_write) : !ldap_add($this->ds,$dn,$to_write); |
|
382 | + $err = $old ? !ldap_modify($this->ds, $dn, $to_write) : !ldap_add($this->ds, $dn, $to_write); |
|
385 | 383 | } |
386 | 384 | if ($err) |
387 | 385 | { |
@@ -391,7 +389,7 @@ discard block |
||
391 | 389 | } |
392 | 390 | if ($memberships) |
393 | 391 | { |
394 | - $this->set_memberships($memberships,$data['account_id']); |
|
392 | + $this->set_memberships($memberships, $data['account_id']); |
|
395 | 393 | } |
396 | 394 | return $data['account_id']; |
397 | 395 | } |
@@ -408,14 +406,14 @@ discard block |
||
408 | 406 | |
409 | 407 | if ($account_id < 0) |
410 | 408 | { |
411 | - $sri = ldap_search($this->ds, $this->group_context, 'gidnumber=' . abs($account_id)); |
|
409 | + $sri = ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($account_id)); |
|
412 | 410 | } |
413 | 411 | else |
414 | 412 | { |
415 | 413 | // remove the user's memberships |
416 | - $this->set_memberships(array(),$account_id); |
|
414 | + $this->set_memberships(array(), $account_id); |
|
417 | 415 | |
418 | - $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
|
416 | + $sri = ldap_search($this->ds, $this->user_context, 'uidnumber='.$account_id); |
|
419 | 417 | } |
420 | 418 | if (!$sri) return false; |
421 | 419 | |
@@ -439,7 +437,7 @@ discard block |
||
439 | 437 | { |
440 | 438 | $this->ldapServerInfo = $this->ldap->getLDAPServerInfo($this->frontend->config['ldap_host']); |
441 | 439 | } |
442 | - foreach(array_keys($this->group_mail_classes) as $objectclass) |
|
440 | + foreach (array_keys($this->group_mail_classes) as $objectclass) |
|
443 | 441 | { |
444 | 442 | if ($this->ldapServerInfo->supportsObjectClass($objectclass)) |
445 | 443 | { |
@@ -447,15 +445,15 @@ discard block |
||
447 | 445 | break; |
448 | 446 | } |
449 | 447 | } |
450 | - $sri = ldap_search($this->ds, $this->group_context,'(&(objectClass=posixGroup)(gidnumber=' . abs($account_id).'))', |
|
448 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(gidnumber='.abs($account_id).'))', |
|
451 | 449 | array('dn', 'gidnumber', 'cn', 'objectclass', static::MAIL_ATTR, 'memberuid', 'description')); |
452 | 450 | |
453 | 451 | $ldap_data = ldap_get_entries($this->ds, $sri); |
454 | 452 | if (!$ldap_data['count']) |
455 | 453 | { |
456 | - return false; // group not found |
|
454 | + return false; // group not found |
|
457 | 455 | } |
458 | - $data = Api\Translation::convert($ldap_data[0],'utf-8'); |
|
456 | + $data = Api\Translation::convert($ldap_data[0], 'utf-8'); |
|
459 | 457 | unset($data['objectclass']['count']); |
460 | 458 | |
461 | 459 | $group += array( |
@@ -476,7 +474,7 @@ discard block |
||
476 | 474 | { |
477 | 475 | unset($data['memberuid']['count']); |
478 | 476 | |
479 | - foreach($data['memberuid'] as $lid) |
|
477 | + foreach ($data['memberuid'] as $lid) |
|
480 | 478 | { |
481 | 479 | if (($id = $this->name2id($lid, 'account_lid', 'u'))) |
482 | 480 | { |
@@ -497,16 +495,16 @@ discard block |
||
497 | 495 | */ |
498 | 496 | protected function _read_user($account_id) |
499 | 497 | { |
500 | - $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber=' . (int)$account_id.'))', |
|
501 | - array('dn','uidnumber','uid','gidnumber','givenname','sn','cn',static::MAIL_ATTR,'userpassword','telephonenumber', |
|
502 | - 'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp')); |
|
498 | + $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber='.(int)$account_id.'))', |
|
499 | + array('dn', 'uidnumber', 'uid', 'gidnumber', 'givenname', 'sn', 'cn', static::MAIL_ATTR, 'userpassword', 'telephonenumber', |
|
500 | + 'shadowexpire', 'shadowlastchange', 'homedirectory', 'loginshell', 'createtimestamp', 'modifytimestamp')); |
|
503 | 501 | |
504 | 502 | $ldap_data = ldap_get_entries($this->ds, $sri); |
505 | 503 | if (!$ldap_data['count']) |
506 | 504 | { |
507 | - return false; // user not found |
|
505 | + return false; // user not found |
|
508 | 506 | } |
509 | - $data = Api\Translation::convert($ldap_data[0],'utf-8'); |
|
507 | + $data = Api\Translation::convert($ldap_data[0], 'utf-8'); |
|
510 | 508 | |
511 | 509 | $utc_diff = date('Z'); |
512 | 510 | $user = array( |
@@ -526,13 +524,13 @@ discard block |
||
526 | 524 | // - if it's set to 0, the account is disabled |
527 | 525 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
528 | 526 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
529 | - 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0]*24*3600+$utc_diff < time() ? false : 'A', |
|
530 | - 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
531 | - 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0]*24*3600+($data['shadowlastchange'][0]!=0?$utc_diff:0) : null, |
|
527 | + 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0] * 24 * 3600 + $utc_diff < time() ? false : 'A', |
|
528 | + 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
529 | + 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0] * 24 * 3600 + ($data['shadowlastchange'][0] != 0 ? $utc_diff : 0) : null, |
|
532 | 530 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
533 | 531 | // 'account_lastlogin' => $data['phpgwaccountlastlogin'][0], |
534 | 532 | // 'account_lastloginfrom' => $data['phpgwaccountlastloginfrom'][0], |
535 | - 'person_id' => $data['uid'][0], // id of associated contact |
|
533 | + 'person_id' => $data['uid'][0], // id of associated contact |
|
536 | 534 | 'account_created' => isset($data['createtimestamp'][0]) ? self::accounts_ldap2ts($data['createtimestamp'][0]) : null, |
537 | 535 | 'account_modified' => isset($data['modifytimestamp'][0]) ? self::accounts_ldap2ts($data['modifytimestamp'][0]) : null, |
538 | 536 | ); |
@@ -553,7 +551,7 @@ discard block |
||
553 | 551 | * @param array $data array with account-data in utf-8 |
554 | 552 | * @return array merged data |
555 | 553 | */ |
556 | - protected function _merge_group($to_write,$data,$old=null) |
|
554 | + protected function _merge_group($to_write, $data, $old = null) |
|
557 | 555 | { |
558 | 556 | $to_write['gidnumber'] = abs($data['account_id']); |
559 | 557 | $to_write['cn'] = $data['account_lid']; |
@@ -573,7 +571,7 @@ discard block |
||
573 | 571 | * @param boolean $new_entry |
574 | 572 | * @return array merged data |
575 | 573 | */ |
576 | - protected function _merge_user($to_write,$data,$new_entry) |
|
574 | + protected function _merge_user($to_write, $data, $new_entry) |
|
577 | 575 | { |
578 | 576 | $to_write['uidnumber'] = $data['account_id']; |
579 | 577 | $to_write['uid'] = $data['account_lid']; |
@@ -582,12 +580,12 @@ discard block |
||
582 | 580 | { |
583 | 581 | $to_write['givenname'] = $data['account_firstname'] ? $data['account_firstname'] : array(); |
584 | 582 | } |
585 | - $to_write['sn'] = $data['account_lastname']; |
|
583 | + $to_write['sn'] = $data['account_lastname']; |
|
586 | 584 | if (!$new_entry || $data['account_email']) |
587 | 585 | { |
588 | - $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
586 | + $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
589 | 587 | } |
590 | - $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
588 | + $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
591 | 589 | |
592 | 590 | $utc_diff = date('Z'); |
593 | 591 | if (isset($data['account_passwd']) && $data['account_passwd']) |
@@ -596,47 +594,46 @@ discard block |
||
596 | 594 | { |
597 | 595 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
598 | 596 | } |
599 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
597 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd'])) // if it's not already entcrypted, do so now |
|
600 | 598 | { |
601 | 599 | $data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']); |
602 | 600 | } |
603 | 601 | $to_write['userpassword'] = $data['account_passwd']; |
604 | - $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
|
602 | + $to_write['shadowlastchange'] = round((time() - $utc_diff) / (24 * 3600)); |
|
605 | 603 | } |
606 | 604 | // both status and expires are encoded in the single shadowexpire value in LDAP |
607 | 605 | // - if it's unset an account is enabled AND does never expire |
608 | 606 | // - if it's set to 0, the account is disabled |
609 | 607 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
610 | 608 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
611 | - $shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600); |
|
609 | + $shadowexpire = ($data['account_expires'] - $utc_diff) / (24 * 3600); |
|
612 | 610 | |
613 | 611 | $to_write['shadowexpire'] = !$data['account_status'] ? |
614 | - ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : |
|
615 | - ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
612 | + ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
616 | 613 | |
617 | 614 | if ($new_entry && is_array($to_write['shadowexpire']) && !count($to_write['shadowexpire'])) |
618 | 615 | { |
619 | - unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
616 | + unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
620 | 617 | } |
621 | 618 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
622 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
623 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
619 | + if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change'] - $utc_diff) / (24 * 3600)); |
|
620 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change'] == 0) $to_write['shadowlastchange'] = 0; |
|
624 | 621 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
625 | 622 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
626 | 623 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
627 | 624 | |
628 | 625 | if ($this->frontend->config['ldap_extra_attributes']) |
629 | 626 | { |
630 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
627 | + if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
631 | 628 | if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
632 | 629 | } |
633 | 630 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
634 | 631 | { |
635 | - $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
632 | + $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
636 | 633 | } |
637 | 634 | if ($new_entry && empty($to_write['loginshell'])) |
638 | 635 | { |
639 | - unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
636 | + unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
640 | 637 | } |
641 | 638 | return $to_write; |
642 | 639 | } |
@@ -664,7 +661,7 @@ discard block |
||
664 | 661 | function search($param) |
665 | 662 | { |
666 | 663 | //error_log(__METHOD__."(".array2string($param).")"); |
667 | - $account_search =& Api\Accounts::$cache['account_search']; |
|
664 | + $account_search = & Api\Accounts::$cache['account_search']; |
|
668 | 665 | |
669 | 666 | // check if the query is cached |
670 | 667 | $serial = serialize($param); |
@@ -690,12 +687,12 @@ discard block |
||
690 | 687 | $query = Api\Ldap::quote(strtolower($param['query'])); |
691 | 688 | |
692 | 689 | $accounts = array(); |
693 | - if($param['type'] != 'groups') |
|
690 | + if ($param['type'] != 'groups') |
|
694 | 691 | { |
695 | 692 | $filter = "(&(objectclass=posixaccount)"; |
696 | 693 | if (!empty($query) && $query != '*') |
697 | 694 | { |
698 | - switch($param['query_type']) |
|
695 | + switch ($param['query_type']) |
|
699 | 696 | { |
700 | 697 | case 'all': |
701 | 698 | default: |
@@ -724,7 +721,7 @@ discard block |
||
724 | 721 | } |
725 | 722 | } |
726 | 723 | // add account_filter to filter (user has to be '*', as we otherwise only search uid's) |
727 | - $filter .= str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$this->account_filter); |
|
724 | + $filter .= str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $this->account_filter); |
|
728 | 725 | $filter .= ')'; |
729 | 726 | |
730 | 727 | if ($param['type'] != 'both') |
@@ -743,9 +740,9 @@ discard block |
||
743 | 740 | 'account_fullname' => 'cn', |
744 | 741 | 'account_primary_group' => 'gidnumber', |
745 | 742 | ); |
746 | - $orders = explode(',',$param['order']); |
|
743 | + $orders = explode(',', $param['order']); |
|
747 | 744 | $order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid'; |
748 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order)); |
|
745 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', $order)); |
|
749 | 746 | $fullSet = array(); |
750 | 747 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
751 | 748 | { |
@@ -755,7 +752,7 @@ discard block |
||
755 | 752 | if (is_numeric($param['type'])) // return only group-members |
756 | 753 | { |
757 | 754 | $relevantAccounts = array(); |
758 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
|
755 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=".abs($param['type'])."))", array('memberuid')); |
|
759 | 756 | $group = ldap_get_entries($this->ds, $sri); |
760 | 757 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
761 | 758 | } |
@@ -764,26 +761,26 @@ discard block |
||
764 | 761 | $sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort'; |
765 | 762 | $sortFn($fullSet); |
766 | 763 | $relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet); |
767 | - $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')'; |
|
768 | - $filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter); |
|
764 | + $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=', $relevantAccounts).'))'.$this->account_filter.')'; |
|
765 | + $filter = str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $filter); |
|
769 | 766 | } |
770 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn',static::MAIL_ATTR,'shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber')); |
|
767 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', 'uidNumber', 'givenname', 'sn', static::MAIL_ATTR, 'shadowExpire', 'createtimestamp', 'modifytimestamp', 'objectclass', 'gidNumber')); |
|
771 | 768 | |
772 | 769 | $utc_diff = date('Z'); |
773 | - foreach(ldap_get_entries($this->ds, $sri) as $allVals) |
|
770 | + foreach (ldap_get_entries($this->ds, $sri) as $allVals) |
|
774 | 771 | { |
775 | - settype($allVals,'array'); |
|
772 | + settype($allVals, 'array'); |
|
776 | 773 | $test = @$allVals['uid'][0]; |
777 | 774 | if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) |
778 | 775 | { |
779 | 776 | $account = Array( |
780 | 777 | 'account_id' => $allVals['uidnumber'][0], |
781 | - 'account_lid' => Api\Translation::convert($allVals['uid'][0],'utf-8'), |
|
778 | + 'account_lid' => Api\Translation::convert($allVals['uid'][0], 'utf-8'), |
|
782 | 779 | 'account_type' => 'u', |
783 | - 'account_firstname' => Api\Translation::convert($allVals['givenname'][0],'utf-8'), |
|
784 | - 'account_lastname' => Api\Translation::convert($allVals['sn'][0],'utf-8'), |
|
785 | - 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A', |
|
786 | - 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
780 | + 'account_firstname' => Api\Translation::convert($allVals['givenname'][0], 'utf-8'), |
|
781 | + 'account_lastname' => Api\Translation::convert($allVals['sn'][0], 'utf-8'), |
|
782 | + 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0] * 24 * 3600 - $utc_diff < time() ? false : 'A', |
|
783 | + 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
787 | 784 | 'account_email' => $allVals[static::MAIL_ATTR][0], |
788 | 785 | 'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null, |
789 | 786 | 'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null, |
@@ -809,13 +806,13 @@ discard block |
||
809 | 806 | } |
810 | 807 | if ($param['type'] == 'groups' || $param['type'] == 'both') |
811 | 808 | { |
812 | - if(empty($query) || $query == '*') |
|
809 | + if (empty($query) || $query == '*') |
|
813 | 810 | { |
814 | 811 | $filter = '(objectclass=posixgroup)'; |
815 | 812 | } |
816 | 813 | else |
817 | 814 | { |
818 | - switch($param['query_type']) |
|
815 | + switch ($param['query_type']) |
|
819 | 816 | { |
820 | 817 | case 'all': |
821 | 818 | default: |
@@ -829,21 +826,21 @@ discard block |
||
829 | 826 | } |
830 | 827 | $filter = "(&(objectclass=posixgroup)(cn=$query))"; |
831 | 828 | } |
832 | - $sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber')); |
|
833 | - foreach((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
829 | + $sri = ldap_search($this->ds, $this->group_context, $filter, array('cn', 'gidNumber')); |
|
830 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
834 | 831 | { |
835 | - settype($allVals,'array'); |
|
832 | + settype($allVals, 'array'); |
|
836 | 833 | $test = $allVals['cn'][0]; |
837 | 834 | if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0]) |
838 | 835 | { |
839 | 836 | $accounts[(string)-$allVals['gidnumber'][0]] = Array( |
840 | 837 | 'account_id' => -$allVals['gidnumber'][0], |
841 | - 'account_lid' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
838 | + 'account_lid' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
842 | 839 | 'account_type' => 'g', |
843 | - 'account_firstname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
840 | + 'account_firstname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
844 | 841 | 'account_lastname' => lang('Group'), |
845 | 842 | 'account_status' => 'A', |
846 | - 'account_fullname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
843 | + 'account_fullname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
847 | 844 | ); |
848 | 845 | if (isset($totalcount)) ++$totalcount; |
849 | 846 | } |
@@ -851,13 +848,13 @@ discard block |
||
851 | 848 | } |
852 | 849 | // sort the array |
853 | 850 | $this->_callback_sort = strtoupper($param['sort']); |
854 | - $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
|
855 | - foreach($this->_callback_order as &$col) |
|
851 | + $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']); |
|
852 | + foreach ($this->_callback_order as &$col) |
|
856 | 853 | { |
857 | 854 | if (substr($col, 0, 8) !== 'account_') $col = 'account_'.$col; |
858 | 855 | } |
859 | 856 | $sortedAccounts = $accounts; |
860 | - uasort($sortedAccounts,array($this,'_sort_callback')); |
|
857 | + uasort($sortedAccounts, array($this, '_sort_callback')); |
|
861 | 858 | $this->total = isset($totalcount) ? $totalcount : count($accounts); |
862 | 859 | |
863 | 860 | // if totalcount is set, $sortedAccounts is NOT the full set, but already a limited set! |
@@ -869,7 +866,7 @@ discard block |
||
869 | 866 | } |
870 | 867 | // return only the wanted accounts |
871 | 868 | reset($sortedAccounts); |
872 | - if(is_numeric($start) && is_numeric($offset)) |
|
869 | + if (is_numeric($start) && is_numeric($offset)) |
|
873 | 870 | { |
874 | 871 | $account_search[$serial]['total'] = $this->total; |
875 | 872 | return $account_search[$serial]['data'] = isset($totalcount) ? $sortedAccounts : array_slice($sortedAccounts, $start, $offset); |
@@ -897,19 +894,19 @@ discard block |
||
897 | 894 | * @param array $b |
898 | 895 | * @return int |
899 | 896 | */ |
900 | - function _sort_callback($a,$b) |
|
897 | + function _sort_callback($a, $b) |
|
901 | 898 | { |
902 | - foreach($this->_callback_order as $col ) |
|
899 | + foreach ($this->_callback_order as $col) |
|
903 | 900 | { |
904 | - if($this->_callback_sort != 'DESC') |
|
901 | + if ($this->_callback_sort != 'DESC') |
|
905 | 902 | { |
906 | - $cmp = strcasecmp( $a[$col], $b[$col] ); |
|
903 | + $cmp = strcasecmp($a[$col], $b[$col]); |
|
907 | 904 | } |
908 | 905 | else |
909 | 906 | { |
910 | - $cmp = strcasecmp( $b[$col], $a[$col] ); |
|
907 | + $cmp = strcasecmp($b[$col], $a[$col]); |
|
911 | 908 | } |
912 | - if ( $cmp != 0 ) |
|
909 | + if ($cmp != 0) |
|
913 | 910 | { |
914 | 911 | return $cmp; |
915 | 912 | } |
@@ -928,8 +925,8 @@ discard block |
||
928 | 925 | { |
929 | 926 | if (!empty($date)) |
930 | 927 | { |
931 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
932 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
928 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
929 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
933 | 930 | } |
934 | 931 | return NULL; |
935 | 932 | } |
@@ -946,14 +943,14 @@ discard block |
||
946 | 943 | * @param string $account_type u = user, g = group, default null = try both |
947 | 944 | * @return int|false numeric account_id or false on error ($name not found) |
948 | 945 | */ |
949 | - function name2id($_name,$which='account_lid',$account_type=null) |
|
946 | + function name2id($_name, $which = 'account_lid', $account_type = null) |
|
950 | 947 | { |
951 | - $name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8')); |
|
948 | + $name = Api\Ldap::quote(Api\Translation::convert($_name, Api\Translation::charset(), 'utf-8')); |
|
952 | 949 | |
953 | 950 | if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
954 | 951 | { |
955 | 952 | |
956 | - $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
|
953 | + $sri = ldap_search($this->ds, $this->group_context, '(&(cn='.$name.')(objectclass=posixgroup))', array('gidNumber')); |
|
957 | 954 | $allValues = ldap_get_entries($this->ds, $sri); |
958 | 955 | |
959 | 956 | if (@$allValues[0]['gidnumber'][0]) |
@@ -970,7 +967,7 @@ discard block |
||
970 | 967 | return False; |
971 | 968 | } |
972 | 969 | |
973 | - $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber')); |
|
970 | + $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'='.$name.')(objectclass=posixaccount))', array('uidNumber')); |
|
974 | 971 | |
975 | 972 | $allValues = ldap_get_entries($this->ds, $sri); |
976 | 973 | |
@@ -990,9 +987,9 @@ discard block |
||
990 | 987 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
991 | 988 | * @return string|false converted value or false on error ($account_id not found) |
992 | 989 | */ |
993 | - function id2name($account_id,$which='account_lid') |
|
990 | + function id2name($account_id, $which = 'account_lid') |
|
994 | 991 | { |
995 | - return $this->frontend->id2name($account_id,$which); |
|
992 | + return $this->frontend->id2name($account_id, $which); |
|
996 | 993 | } |
997 | 994 | |
998 | 995 | /** |
@@ -1005,7 +1002,7 @@ discard block |
||
1005 | 1002 | function update_lastlogin($_account_id, $ip) |
1006 | 1003 | { |
1007 | 1004 | unset($_account_id, $ip); |
1008 | - return false; // not longer supported |
|
1005 | + return false; // not longer supported |
|
1009 | 1006 | } |
1010 | 1007 | |
1011 | 1008 | /** |
@@ -1016,11 +1013,11 @@ discard block |
||
1016 | 1013 | */ |
1017 | 1014 | function memberships($account_id) |
1018 | 1015 | { |
1019 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1016 | + if (!(int)$account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1020 | 1017 | |
1021 | - $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber')); |
|
1018 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))', array('cn', 'gidnumber')); |
|
1022 | 1019 | $memberships = array(); |
1023 | - foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
1020 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
1024 | 1021 | { |
1025 | 1022 | if ($key === 'count') continue; |
1026 | 1023 | |
@@ -1041,13 +1038,13 @@ discard block |
||
1041 | 1038 | if (!is_numeric($_gid)) |
1042 | 1039 | { |
1043 | 1040 | // try to recover |
1044 | - $_gid = $this->name2id($_gid,'account_lid','g'); |
|
1041 | + $_gid = $this->name2id($_gid, 'account_lid', 'g'); |
|
1045 | 1042 | if (!is_numeric($_gid)) return false; |
1046 | 1043 | } |
1047 | 1044 | |
1048 | - $gid = abs($_gid); // our gid is negative! |
|
1045 | + $gid = abs($_gid); // our gid is negative! |
|
1049 | 1046 | |
1050 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid')); |
|
1047 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=$gid))", array('memberuid')); |
|
1051 | 1048 | $group = ldap_get_entries($this->ds, $sri); |
1052 | 1049 | |
1053 | 1050 | $members = array(); |
@@ -1055,7 +1052,7 @@ discard block |
||
1055 | 1052 | { |
1056 | 1053 | unset($group[0]['memberuid']['count']); |
1057 | 1054 | |
1058 | - foreach($group[0]['memberuid'] as $lid) |
|
1055 | + foreach ($group[0]['memberuid'] as $lid) |
|
1059 | 1056 | { |
1060 | 1057 | if (($id = $this->name2id($lid, 'account_lid'))) // also return groups! |
1061 | 1058 | { |
@@ -1072,27 +1069,27 @@ discard block |
||
1072 | 1069 | * @param array $groups array with gidnumbers |
1073 | 1070 | * @param int $account_id uidnumber |
1074 | 1071 | */ |
1075 | - function set_memberships($groups,$account_id) |
|
1072 | + function set_memberships($groups, $account_id) |
|
1076 | 1073 | { |
1077 | 1074 | // remove not longer existing memberships |
1078 | 1075 | if (($old_memberships = $this->memberships($account_id))) |
1079 | 1076 | { |
1080 | 1077 | $old_memberships = array_keys($old_memberships); |
1081 | - foreach(array_diff($old_memberships,$groups) as $gid) |
|
1078 | + foreach (array_diff($old_memberships, $groups) as $gid) |
|
1082 | 1079 | { |
1083 | 1080 | if (($members = $this->members($gid))) |
1084 | 1081 | { |
1085 | 1082 | unset($members[$account_id]); |
1086 | - $this->set_members($members,$gid); |
|
1083 | + $this->set_members($members, $gid); |
|
1087 | 1084 | } |
1088 | 1085 | } |
1089 | 1086 | } |
1090 | 1087 | // adding new memberships |
1091 | - foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid) |
|
1088 | + foreach ($old_memberships ? array_diff($groups, $old_memberships) : $groups as $gid) |
|
1092 | 1089 | { |
1093 | 1090 | if (!($members = $this->members($gid))) $members = array(); |
1094 | 1091 | $members[$account_id] = $this->id2name($account_id); |
1095 | - $this->set_members($members,$gid); |
|
1092 | + $this->set_members($members, $gid); |
|
1096 | 1093 | } |
1097 | 1094 | } |
1098 | 1095 | |
@@ -1105,7 +1102,7 @@ discard block |
||
1105 | 1102 | * @param string $use_cn =null if set $cn is used instead $gid and the attributes are returned, not written to ldap |
1106 | 1103 | * @return boolean/array false on failure, array or true otherwise |
1107 | 1104 | */ |
1108 | - function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
|
1105 | + function set_members($members, $gid, array $objectclass = null, $use_cn = null) |
|
1109 | 1106 | { |
1110 | 1107 | if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
1111 | 1108 | |
@@ -1126,7 +1123,7 @@ discard block |
||
1126 | 1123 | } |
1127 | 1124 | |
1128 | 1125 | $to_write = array('memberuid' => array()); |
1129 | - foreach((array)$members as $member) |
|
1126 | + foreach ((array)$members as $member) |
|
1130 | 1127 | { |
1131 | 1128 | if (!$member) continue; |
1132 | 1129 | |
@@ -1134,14 +1131,14 @@ discard block |
||
1134 | 1131 | if (is_numeric($member)) $member = $this->id2name($member); |
1135 | 1132 | |
1136 | 1133 | // only add a member, if we have the neccessary info / he already exists in migration |
1137 | - if ($member && ($member_dn || !array_intersect(array('groupofnames','groupofuniquenames','univentiongroup'), $objectclass))) |
|
1134 | + if ($member && ($member_dn || !array_intersect(array('groupofnames', 'groupofuniquenames', 'univentiongroup'), $objectclass))) |
|
1138 | 1135 | { |
1139 | 1136 | $to_write['memberuid'][] = $member; |
1140 | 1137 | if (in_array('groupofnames', $objectclass)) |
1141 | 1138 | { |
1142 | 1139 | $to_write['member'][] = $member_dn; |
1143 | 1140 | } |
1144 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass)) |
|
1141 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
1145 | 1142 | { |
1146 | 1143 | $to_write['uniquemember'][] = $member_dn; |
1147 | 1144 | } |
@@ -1152,29 +1149,29 @@ discard block |
||
1152 | 1149 | { |
1153 | 1150 | $to_write['member'][] = 'uid=dummy'.','.$this->user_context; |
1154 | 1151 | } |
1155 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
1152 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
1156 | 1153 | { |
1157 | 1154 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
1158 | 1155 | } |
1159 | 1156 | if ($use_cn) return $to_write; |
1160 | 1157 | |
1161 | 1158 | // set the member email addresses as forwards |
1162 | - if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
|
1159 | + if ($this->id2name($gid, 'account_email') && ($objectclass = $this->id2name($gid, 'mailAllowed'))) |
|
1163 | 1160 | { |
1164 | 1161 | $forward = $this->group_mail_classes[$objectclass]; |
1165 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
1162 | + if (is_array($forward)) list($forward, $extra_attr) = $forward; |
|
1166 | 1163 | if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
1167 | 1164 | |
1168 | 1165 | if ($forward) |
1169 | 1166 | { |
1170 | 1167 | $to_write[$forward] = array(); |
1171 | - foreach($members as $member) |
|
1168 | + foreach ($members as $member) |
|
1172 | 1169 | { |
1173 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
1170 | + if (($email = $this->id2name($member, 'account_email'))) $to_write[$forward][] = $email; |
|
1174 | 1171 | } |
1175 | 1172 | } |
1176 | 1173 | } |
1177 | - if (!ldap_modify($this->ds,'cn='.Api\Ldap::quote($cn).','.$this->group_context,$to_write)) |
|
1174 | + if (!ldap_modify($this->ds, 'cn='.Api\Ldap::quote($cn).','.$this->group_context, $to_write)) |
|
1178 | 1175 | { |
1179 | 1176 | error_log(__METHOD__."(members=".array2string($members).", gid=$gid, objectclass=".array2string($objectclass).", use_cn=$use_cn) !ldap_modify(,'cn=$cn,$this->group_context', ".array2string($to_write).") --> ldap_error()=".ldap_error($this->ds)); |
1180 | 1177 | return false; |
@@ -1189,7 +1186,7 @@ discard block |
||
1189 | 1186 | * @param string $account_type ='u' (optional, default to 'u') |
1190 | 1187 | * @return int|boolean integer account_id (negative for groups) or false if none is free anymore |
1191 | 1188 | */ |
1192 | - protected function _get_nextid($account_type='u') |
|
1189 | + protected function _get_nextid($account_type = 'u') |
|
1193 | 1190 | { |
1194 | 1191 | $min = $this->frontend->config['account_min_id'] ? $this->frontend->config['account_min_id'] : 0; |
1195 | 1192 | $max = $this->frontend->config['account_max_id'] ? $this->frontend->config['account_max_id'] : 0; |
@@ -1211,16 +1208,16 @@ discard block |
||
1211 | 1208 | /* Loop until we find a free id */ |
1212 | 1209 | do |
1213 | 1210 | { |
1214 | - $account_id = (int) self::next_id($type,$min,$max); |
|
1211 | + $account_id = (int)self::next_id($type, $min, $max); |
|
1215 | 1212 | } |
1216 | - while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
1213 | + while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
1217 | 1214 | $this->frontend->exists(-1 * $sign * $account_id) || |
1218 | 1215 | // if sambaadmin is installed, call it to check there's not yet a relative id (last part of SID) with that number |
1219 | 1216 | // to ease migration to AD or Samba4 |
1220 | 1217 | file_exists(EGW_SERVER_ROOT.'/sambaadmin') && $GLOBALS['egw_info']['apps']['sambaadmin'] && |
1221 | 1218 | ExecMethod2('sambaadmin.sosambaadmin.sidExists', $account_id))); |
1222 | 1219 | |
1223 | - if (!$account_id || $max && $account_id > $max) |
|
1220 | + if (!$account_id || $max && $account_id > $max) |
|
1224 | 1221 | { |
1225 | 1222 | return False; |
1226 | 1223 | } |
@@ -1235,14 +1232,14 @@ discard block |
||
1235 | 1232 | * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false |
1236 | 1233 | * @return int|boolean the next id or false if $max given and exceeded |
1237 | 1234 | */ |
1238 | - static function next_id($location,$min=0,$max=0) |
|
1235 | + static function next_id($location, $min = 0, $max = 0) |
|
1239 | 1236 | { |
1240 | 1237 | if (!$location) |
1241 | 1238 | { |
1242 | 1239 | return -1; |
1243 | 1240 | } |
1244 | 1241 | |
1245 | - $id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location]; |
|
1242 | + $id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location]; |
|
1246 | 1243 | |
1247 | 1244 | if ($max && $id >= $max) |
1248 | 1245 | { |
@@ -1250,10 +1247,10 @@ discard block |
||
1250 | 1247 | } |
1251 | 1248 | ++$id; |
1252 | 1249 | |
1253 | - if($id < $min) $id = $min; |
|
1250 | + if ($id < $min) $id = $min; |
|
1254 | 1251 | |
1255 | 1252 | Api\Config::save_value($key, $id, 'phpgwapi', true); |
1256 | - $GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id; |
|
1253 | + $GLOBALS['egw_info']['server'][$key = 'last_id_'.$location] = $id; |
|
1257 | 1254 | |
1258 | 1255 | return (int)$id; |
1259 | 1256 | } |
@@ -1266,18 +1263,18 @@ discard block |
||
1266 | 1263 | * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false |
1267 | 1264 | * @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. |
1268 | 1265 | */ |
1269 | - static function last_id($location,$min=0,$max=0) |
|
1266 | + static function last_id($location, $min = 0, $max = 0) |
|
1270 | 1267 | { |
1271 | 1268 | if (!$location) |
1272 | 1269 | { |
1273 | 1270 | return -1; |
1274 | 1271 | } |
1275 | 1272 | |
1276 | - $id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location]; |
|
1273 | + $id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location]; |
|
1277 | 1274 | |
1278 | 1275 | if (!$id || $id < $min) |
1279 | 1276 | { |
1280 | - return self::next_id($location,$min,$max); |
|
1277 | + return self::next_id($location, $min, $max); |
|
1281 | 1278 | } |
1282 | 1279 | if ($max && $id > $max) |
1283 | 1280 | { |
@@ -1292,6 +1289,6 @@ discard block |
||
1292 | 1289 | function __wakeup() |
1293 | 1290 | { |
1294 | 1291 | $this->ds = Api\Ldap::factory(true, $this->frontend->config['ldap_host'], |
1295 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
1292 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
1296 | 1293 | } |
1297 | 1294 | } |
@@ -174,7 +174,10 @@ discard block |
||
174 | 174 | */ |
175 | 175 | function read($account_id) |
176 | 176 | { |
177 | - if (!(int)$account_id) return false; |
|
177 | + if (!(int)$account_id) |
|
178 | + { |
|
179 | + return false; |
|
180 | + } |
|
178 | 181 | |
179 | 182 | if ($account_id < 0) |
180 | 183 | { |
@@ -237,17 +240,23 @@ discard block |
||
237 | 240 | $this->delete($data['account_id']); |
238 | 241 | unset($old['dn']); |
239 | 242 | // removing the namedObject object-class, if it's included |
240 | - if ($key !== false) unset($old['objectclass'][$key]); |
|
243 | + if ($key !== false) |
|
244 | + { |
|
245 | + unset($old['objectclass'][$key]); |
|
246 | + } |
|
241 | 247 | $to_write = $old; |
242 | 248 | unset($old); |
243 | 249 | } |
244 | 250 | } |
245 | 251 | } |
246 | - if (!$data['account_id']) // new account |
|
252 | + if (!$data['account_id']) |
|
253 | + { |
|
254 | + // new account |
|
247 | 255 | { |
248 | 256 | if (!($data['account_id'] = $data_utf8['account_id'] = $this->_get_nextid($is_group ? 'g' : 'u'))) |
249 | 257 | { |
250 | 258 | return false; |
259 | + } |
|
251 | 260 | } |
252 | 261 | } |
253 | 262 | // check if we need to write the objectclass: new entry or required object classes are missing |
@@ -258,11 +267,14 @@ discard block |
||
258 | 267 | { |
259 | 268 | $to_write['objectclass'] = $old ? $old['objectclass'] : array(); |
260 | 269 | } |
261 | - if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
|
270 | + if (!$old) |
|
271 | + { |
|
272 | + // for new accounts add additional addressbook object classes, if supported by server |
|
262 | 273 | { // as setting them later might loose eg. password, if we are not allowed to read them |
263 | 274 | foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
264 | 275 | { |
265 | 276 | $add = array(); |
277 | + } |
|
266 | 278 | if (is_array($additional)) |
267 | 279 | { |
268 | 280 | $add = $additional; |
@@ -271,7 +283,10 @@ discard block |
||
271 | 283 | if ($this->ldapServerInfo->supportsObjectClass($additional)) |
272 | 284 | { |
273 | 285 | $to_write['objectclass'][] = $additional; |
274 | - if ($add) $to_write += $add; |
|
286 | + if ($add) |
|
287 | + { |
|
288 | + $to_write += $add; |
|
289 | + } |
|
275 | 290 | } |
276 | 291 | } |
277 | 292 | } |
@@ -280,7 +295,10 @@ discard block |
||
280 | 295 | } |
281 | 296 | if (!($dn = $old['dn'])) |
282 | 297 | { |
283 | - if (!$data['account_lid']) return false; |
|
298 | + if (!$data['account_lid']) |
|
299 | + { |
|
300 | + return false; |
|
301 | + } |
|
284 | 302 | |
285 | 303 | $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
286 | 304 | 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
@@ -301,24 +319,36 @@ discard block |
||
301 | 319 | { |
302 | 320 | $extra_attr = false; |
303 | 321 | $keep_objectclass = false; |
304 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
322 | + if (is_array($forward)) |
|
323 | + { |
|
324 | + list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
325 | + } |
|
305 | 326 | |
306 | 327 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
307 | 328 | ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
308 | 329 | { |
309 | - if ($data_utf8['account_email']) // setting an email |
|
330 | + if ($data_utf8['account_email']) |
|
331 | + { |
|
332 | + // setting an email |
|
310 | 333 | { |
311 | 334 | if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
312 | 335 | { |
313 | 336 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
337 | + } |
|
314 | 338 | $to_write['objectclass'][] = $objectclass; |
315 | 339 | } |
316 | - if ($extra_attr) $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
340 | + if ($extra_attr) |
|
341 | + { |
|
342 | + $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
343 | + } |
|
317 | 344 | $to_write[static::MAIL_ATTR] = $data_utf8['account_email']; |
318 | 345 | |
319 | 346 | if ($forward) |
320 | 347 | { |
321 | - if (!$members) $members = $this->members($data['account_id']); |
|
348 | + if (!$members) |
|
349 | + { |
|
350 | + $members = $this->members($data['account_id']); |
|
351 | + } |
|
322 | 352 | $to_write[$forward] = array(); |
323 | 353 | foreach (array_keys($members) as $member) |
324 | 354 | { |
@@ -329,11 +359,20 @@ discard block |
||
329 | 359 | } |
330 | 360 | } |
331 | 361 | } |
332 | - elseif($old) // remove the mail and forwards only for existing entries |
|
362 | + elseif($old) |
|
363 | + { |
|
364 | + // remove the mail and forwards only for existing entries |
|
333 | 365 | { |
334 | 366 | $to_write[static::MAIL_ATTR] = array(); |
335 | - if ($forward) $to_write[$forward] = array(); |
|
336 | - if ($extra_attr) $to_write[$extra_attr] = array(); |
|
367 | + } |
|
368 | + if ($forward) |
|
369 | + { |
|
370 | + $to_write[$forward] = array(); |
|
371 | + } |
|
372 | + if ($extra_attr) |
|
373 | + { |
|
374 | + $to_write[$extra_attr] = array(); |
|
375 | + } |
|
337 | 376 | if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
338 | 377 | { |
339 | 378 | $to_write['objectclass'] = $old['objectclass']; |
@@ -367,7 +406,8 @@ discard block |
||
367 | 406 | } |
368 | 407 | |
369 | 408 | // remove memberuid when adding a group |
370 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
409 | + if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) |
|
410 | + { |
|
371 | 411 | unset($to_write['memberuid']); |
372 | 412 | } |
373 | 413 | // modifying or adding the entry |
@@ -404,7 +444,10 @@ discard block |
||
404 | 444 | */ |
405 | 445 | function delete($account_id) |
406 | 446 | { |
407 | - if (!(int)$account_id) return false; |
|
447 | + if (!(int)$account_id) |
|
448 | + { |
|
449 | + return false; |
|
450 | + } |
|
408 | 451 | |
409 | 452 | if ($account_id < 0) |
410 | 453 | { |
@@ -417,10 +460,16 @@ discard block |
||
417 | 460 | |
418 | 461 | $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
419 | 462 | } |
420 | - if (!$sri) return false; |
|
463 | + if (!$sri) |
|
464 | + { |
|
465 | + return false; |
|
466 | + } |
|
421 | 467 | |
422 | 468 | $allValues = ldap_get_entries($this->ds, $sri); |
423 | - if (!$allValues['count']) return false; |
|
469 | + if (!$allValues['count']) |
|
470 | + { |
|
471 | + return false; |
|
472 | + } |
|
424 | 473 | |
425 | 474 | return ldap_delete($this->ds, $allValues[0]['dn']); |
426 | 475 | } |
@@ -592,14 +641,20 @@ discard block |
||
592 | 641 | $utc_diff = date('Z'); |
593 | 642 | if (isset($data['account_passwd']) && $data['account_passwd']) |
594 | 643 | { |
595 | - if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) // md5 --> ldap md5 |
|
644 | + if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) |
|
645 | + { |
|
646 | + // md5 --> ldap md5 |
|
596 | 647 | { |
597 | 648 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
598 | 649 | } |
599 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
650 | + } |
|
651 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) |
|
652 | + { |
|
653 | + // if it's not already entcrypted, do so now |
|
600 | 654 | { |
601 | 655 | $data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']); |
602 | 656 | } |
657 | + } |
|
603 | 658 | $to_write['userpassword'] = $data['account_passwd']; |
604 | 659 | $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
605 | 660 | } |
@@ -619,16 +674,28 @@ discard block |
||
619 | 674 | unset($to_write['shadowexpire']); // gives protocoll error otherwise |
620 | 675 | } |
621 | 676 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
622 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
623 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
677 | + if ($data['account_lastpwd_change']) |
|
678 | + { |
|
679 | + $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
680 | + } |
|
681 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) |
|
682 | + { |
|
683 | + $to_write['shadowlastchange'] = 0; |
|
684 | + } |
|
624 | 685 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
625 | 686 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
626 | 687 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
627 | 688 | |
628 | 689 | if ($this->frontend->config['ldap_extra_attributes']) |
629 | 690 | { |
630 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
631 | - if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
691 | + if (isset($data['homedirectory'])) |
|
692 | + { |
|
693 | + $to_write['homedirectory'] = $data['homedirectory']; |
|
694 | + } |
|
695 | + if (isset($data['loginshell'])) |
|
696 | + { |
|
697 | + $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
698 | + } |
|
632 | 699 | } |
633 | 700 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
634 | 701 | { |
@@ -675,8 +742,14 @@ discard block |
||
675 | 742 | } |
676 | 743 | // if it's a limited query, check if the unlimited query is cached |
677 | 744 | $start = $param['start']; |
678 | - if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15; |
|
679 | - if (!($offset = $param['offset'])) $offset = $maxmatchs; |
|
745 | + if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) |
|
746 | + { |
|
747 | + $maxmatchs = 15; |
|
748 | + } |
|
749 | + if (!($offset = $param['offset'])) |
|
750 | + { |
|
751 | + $offset = $maxmatchs; |
|
752 | + } |
|
680 | 753 | unset($param['start']); |
681 | 754 | unset($param['offset']); |
682 | 755 | $unl_serial = serialize($param); |
@@ -749,12 +822,18 @@ discard block |
||
749 | 822 | $fullSet = array(); |
750 | 823 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
751 | 824 | { |
752 | - if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
825 | + if ($key !== 'count') |
|
826 | + { |
|
827 | + $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
828 | + } |
|
753 | 829 | } |
754 | 830 | |
755 | - if (is_numeric($param['type'])) // return only group-members |
|
831 | + if (is_numeric($param['type'])) |
|
832 | + { |
|
833 | + // return only group-members |
|
756 | 834 | { |
757 | 835 | $relevantAccounts = array(); |
836 | + } |
|
758 | 837 | $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
759 | 838 | $group = ldap_get_entries($this->ds, $sri); |
760 | 839 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
@@ -792,7 +871,10 @@ discard block |
||
792 | 871 | //error_log(__METHOD__."() ldap=".array2string($allVals)." --> account=".array2string($account)); |
793 | 872 | if ($param['active'] && !$this->frontend->is_active($account)) |
794 | 873 | { |
795 | - if (isset($totalcount)) --$totalcount; |
|
874 | + if (isset($totalcount)) |
|
875 | + { |
|
876 | + --$totalcount; |
|
877 | + } |
|
796 | 878 | continue; |
797 | 879 | } |
798 | 880 | $account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], |
@@ -845,7 +927,10 @@ discard block |
||
845 | 927 | 'account_status' => 'A', |
846 | 928 | 'account_fullname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
847 | 929 | ); |
848 | - if (isset($totalcount)) ++$totalcount; |
|
930 | + if (isset($totalcount)) |
|
931 | + { |
|
932 | + ++$totalcount; |
|
933 | + } |
|
849 | 934 | } |
850 | 935 | } |
851 | 936 | } |
@@ -854,7 +939,10 @@ discard block |
||
854 | 939 | $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
855 | 940 | foreach($this->_callback_order as &$col) |
856 | 941 | { |
857 | - if (substr($col, 0, 8) !== 'account_') $col = 'account_'.$col; |
|
942 | + if (substr($col, 0, 8) !== 'account_') |
|
943 | + { |
|
944 | + $col = 'account_'.$col; |
|
945 | + } |
|
858 | 946 | } |
859 | 947 | $sortedAccounts = $accounts; |
860 | 948 | uasort($sortedAccounts,array($this,'_sort_callback')); |
@@ -950,10 +1038,13 @@ discard block |
||
950 | 1038 | { |
951 | 1039 | $name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8')); |
952 | 1040 | |
953 | - if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
|
1041 | + if ($which == 'account_lid' && $account_type !== 'u') |
|
1042 | + { |
|
1043 | + // groups only support account_lid |
|
954 | 1044 | { |
955 | 1045 | |
956 | 1046 | $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
1047 | + } |
|
957 | 1048 | $allValues = ldap_get_entries($this->ds, $sri); |
958 | 1049 | |
959 | 1050 | if (@$allValues[0]['gidnumber'][0]) |
@@ -966,7 +1057,8 @@ discard block |
||
966 | 1057 | 'account_email' => static::MAIL_ATTR, |
967 | 1058 | 'account_fullname' => 'cn', |
968 | 1059 | ); |
969 | - if (!isset($to_ldap[$which]) || $account_type === 'g') { |
|
1060 | + if (!isset($to_ldap[$which]) || $account_type === 'g') |
|
1061 | + { |
|
970 | 1062 | return False; |
971 | 1063 | } |
972 | 1064 | |
@@ -1016,13 +1108,19 @@ discard block |
||
1016 | 1108 | */ |
1017 | 1109 | function memberships($account_id) |
1018 | 1110 | { |
1019 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1111 | + if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) |
|
1112 | + { |
|
1113 | + return false; |
|
1114 | + } |
|
1020 | 1115 | |
1021 | 1116 | $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber')); |
1022 | 1117 | $memberships = array(); |
1023 | 1118 | foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
1024 | 1119 | { |
1025 | - if ($key === 'count') continue; |
|
1120 | + if ($key === 'count') |
|
1121 | + { |
|
1122 | + continue; |
|
1123 | + } |
|
1026 | 1124 | |
1027 | 1125 | $memberships[(string) -$data['gidnumber'][0]] = $data['cn'][0]; |
1028 | 1126 | } |
@@ -1042,7 +1140,10 @@ discard block |
||
1042 | 1140 | { |
1043 | 1141 | // try to recover |
1044 | 1142 | $_gid = $this->name2id($_gid,'account_lid','g'); |
1045 | - if (!is_numeric($_gid)) return false; |
|
1143 | + if (!is_numeric($_gid)) |
|
1144 | + { |
|
1145 | + return false; |
|
1146 | + } |
|
1046 | 1147 | } |
1047 | 1148 | |
1048 | 1149 | $gid = abs($_gid); // our gid is negative! |
@@ -1057,10 +1158,13 @@ discard block |
||
1057 | 1158 | |
1058 | 1159 | foreach($group[0]['memberuid'] as $lid) |
1059 | 1160 | { |
1060 | - if (($id = $this->name2id($lid, 'account_lid'))) // also return groups! |
|
1161 | + if (($id = $this->name2id($lid, 'account_lid'))) |
|
1162 | + { |
|
1163 | + // also return groups! |
|
1061 | 1164 | { |
1062 | 1165 | $members[$id] = $lid; |
1063 | 1166 | } |
1167 | + } |
|
1064 | 1168 | } |
1065 | 1169 | } |
1066 | 1170 | return $members; |
@@ -1090,7 +1194,10 @@ discard block |
||
1090 | 1194 | // adding new memberships |
1091 | 1195 | foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid) |
1092 | 1196 | { |
1093 | - if (!($members = $this->members($gid))) $members = array(); |
|
1197 | + if (!($members = $this->members($gid))) |
|
1198 | + { |
|
1199 | + $members = array(); |
|
1200 | + } |
|
1094 | 1201 | $members[$account_id] = $this->id2name($account_id); |
1095 | 1202 | $this->set_members($members,$gid); |
1096 | 1203 | } |
@@ -1107,7 +1214,10 @@ discard block |
||
1107 | 1214 | */ |
1108 | 1215 | function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
1109 | 1216 | { |
1110 | - if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
|
1217 | + if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) |
|
1218 | + { |
|
1219 | + return false; |
|
1220 | + } |
|
1111 | 1221 | |
1112 | 1222 | // do that group is a groupOf(Unique)Names or univentionGroup? |
1113 | 1223 | if (!isset($objectclass)) |
@@ -1128,10 +1238,16 @@ discard block |
||
1128 | 1238 | $to_write = array('memberuid' => array()); |
1129 | 1239 | foreach((array)$members as $member) |
1130 | 1240 | { |
1131 | - if (!$member) continue; |
|
1241 | + if (!$member) |
|
1242 | + { |
|
1243 | + continue; |
|
1244 | + } |
|
1132 | 1245 | |
1133 | 1246 | $member_dn = $this->id2name($member, 'account_dn'); |
1134 | - if (is_numeric($member)) $member = $this->id2name($member); |
|
1247 | + if (is_numeric($member)) |
|
1248 | + { |
|
1249 | + $member = $this->id2name($member); |
|
1250 | + } |
|
1135 | 1251 | |
1136 | 1252 | // only add a member, if we have the neccessary info / he already exists in migration |
1137 | 1253 | if ($member && ($member_dn || !array_intersect(array('groupofnames','groupofuniquenames','univentiongroup'), $objectclass))) |
@@ -1156,21 +1272,33 @@ discard block |
||
1156 | 1272 | { |
1157 | 1273 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
1158 | 1274 | } |
1159 | - if ($use_cn) return $to_write; |
|
1275 | + if ($use_cn) |
|
1276 | + { |
|
1277 | + return $to_write; |
|
1278 | + } |
|
1160 | 1279 | |
1161 | 1280 | // set the member email addresses as forwards |
1162 | 1281 | if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
1163 | 1282 | { |
1164 | 1283 | $forward = $this->group_mail_classes[$objectclass]; |
1165 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
1166 | - if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
|
1284 | + if (is_array($forward)) |
|
1285 | + { |
|
1286 | + list($forward,$extra_attr) = $forward; |
|
1287 | + } |
|
1288 | + if ($extra_attr && ($uid = $this->id2name($gid))) |
|
1289 | + { |
|
1290 | + $to_write[$extra_attr] = $uid; |
|
1291 | + } |
|
1167 | 1292 | |
1168 | 1293 | if ($forward) |
1169 | 1294 | { |
1170 | 1295 | $to_write[$forward] = array(); |
1171 | 1296 | foreach($members as $member) |
1172 | 1297 | { |
1173 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
1298 | + if (($email = $this->id2name($member,'account_email'))) |
|
1299 | + { |
|
1300 | + $to_write[$forward][] = $email; |
|
1301 | + } |
|
1174 | 1302 | } |
1175 | 1303 | } |
1176 | 1304 | } |
@@ -1196,7 +1324,10 @@ discard block |
||
1196 | 1324 | |
1197 | 1325 | // prefer ids above 1000 (below reserved for system users under AD or Linux), |
1198 | 1326 | // if that's possible within what is configured, or nothing is configured |
1199 | - if ($min < 1000 && (!$max || $max > 1000)) $min = 1000; |
|
1327 | + if ($min < 1000 && (!$max || $max > 1000)) |
|
1328 | + { |
|
1329 | + $min = 1000; |
|
1330 | + } |
|
1200 | 1331 | |
1201 | 1332 | if ($account_type == 'g') |
1202 | 1333 | { |
@@ -1250,7 +1381,10 @@ discard block |
||
1250 | 1381 | } |
1251 | 1382 | ++$id; |
1252 | 1383 | |
1253 | - if($id < $min) $id = $min; |
|
1384 | + if($id < $min) |
|
1385 | + { |
|
1386 | + $id = $min; |
|
1387 | + } |
|
1254 | 1388 | |
1255 | 1389 | Api\Config::save_value($key, $id, 'phpgwapi', true); |
1256 | 1390 | $GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id; |
@@ -54,26 +54,26 @@ discard block |
||
54 | 54 | * @throws Exception if connection to backend could not be established |
55 | 55 | * @param array $params eg. array('localhost'[,'localhost:11211',...]) |
56 | 56 | */ |
57 | - function __construct(array $params=null) |
|
57 | + function __construct(array $params = null) |
|
58 | 58 | { |
59 | - check_load_extension('memcache',true); |
|
59 | + check_load_extension('memcache', true); |
|
60 | 60 | $this->memcache = new \Memcache(); |
61 | 61 | |
62 | - if (!$params) $params = array('localhost'); // some reasonable default |
|
62 | + if (!$params) $params = array('localhost'); // some reasonable default |
|
63 | 63 | |
64 | 64 | $ok = false; |
65 | - foreach($params as $host_port) |
|
65 | + foreach ($params as $host_port) |
|
66 | 66 | { |
67 | - $parts = explode(':',$host_port); |
|
67 | + $parts = explode(':', $host_port); |
|
68 | 68 | $host = array_shift($parts); |
69 | - $port = $parts ? array_shift($parts) : 11211; // default port |
|
69 | + $port = $parts ? array_shift($parts) : 11211; // default port |
|
70 | 70 | |
71 | - $ok = $this->memcache->addServer($host,$port) || $ok; |
|
71 | + $ok = $this->memcache->addServer($host, $port) || $ok; |
|
72 | 72 | //error_log(__METHOD__."(".array2string($params).") memcache->addServer('$host',$port) = ".(int)$ok); |
73 | 73 | } |
74 | 74 | if (!$ok) |
75 | 75 | { |
76 | - throw new Exception (__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
76 | + throw new Exception(__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
77 | 77 | } |
78 | 78 | $this->igbinary_available = function_exists('igbinary_serialize') && function_exists('igbinary_unserialize'); |
79 | 79 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param int $expiration =0 |
87 | 87 | * @return boolean true on success, false on error, incl. key already exists in cache |
88 | 88 | */ |
89 | - function add(array $keys,$data,$expiration=0) |
|
89 | + function add(array $keys, $data, $expiration = 0) |
|
90 | 90 | { |
91 | 91 | return $this->memcache->add(self::key($keys), |
92 | 92 | $this->igbinary_available ? igbinary_serialize($data) : serialize($data), |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param int $expiration =0 |
102 | 102 | * @return boolean true on success, false on error |
103 | 103 | */ |
104 | - function set(array $keys,$data,$expiration=0) |
|
104 | + function set(array $keys, $data, $expiration = 0) |
|
105 | 105 | { |
106 | 106 | return $this->memcache->set(self::key($keys), |
107 | 107 | $this->igbinary_available ? igbinary_serialize($data) : serialize($data), |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | function get(array $keys) |
118 | 118 | { |
119 | - if (($data = $this->memcache->get($key=self::key($keys))) === false) |
|
119 | + if (($data = $this->memcache->get($key = self::key($keys))) === false) |
|
120 | 120 | { |
121 | 121 | //error_log(__METHOD__."(".array2string($keys).") key='$key' NOT found!"); |
122 | 122 | return null; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | { |
136 | 136 | $locations = array_pop($keys); |
137 | 137 | $prefix = self::key($keys); |
138 | - foreach($locations as &$location) |
|
138 | + foreach ($locations as &$location) |
|
139 | 139 | { |
140 | 140 | $location = $prefix.'::'.$location; |
141 | 141 | } |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | return array(); |
145 | 145 | } |
146 | 146 | $ret = array(); |
147 | - $prefix_len = strlen($prefix)+2; |
|
148 | - foreach($multiple as $location => $data) |
|
147 | + $prefix_len = strlen($prefix) + 2; |
|
148 | + foreach ($multiple as $location => $data) |
|
149 | 149 | { |
150 | - $key = substr($location,$prefix_len); |
|
150 | + $key = substr($location, $prefix_len); |
|
151 | 151 | //error_log(__METHOD__."(".array2string($locations).") key='$key' found ".bytes($data)." bytes)."); |
152 | 152 | $ret[$key] = $this->igbinary_available && $data[1] !== ':' ? igbinary_unserialize($data) : unserialize($data); |
153 | 153 | } |
@@ -175,6 +175,6 @@ discard block |
||
175 | 175 | */ |
176 | 176 | private function key(array $keys) |
177 | 177 | { |
178 | - return implode('::',$keys); |
|
178 | + return implode('::', $keys); |
|
179 | 179 | } |
180 | 180 | } |
@@ -59,7 +59,11 @@ |
||
59 | 59 | check_load_extension('memcache',true); |
60 | 60 | $this->memcache = new \Memcache(); |
61 | 61 | |
62 | - if (!$params) $params = array('localhost'); // some reasonable default |
|
62 | + if (!$params) |
|
63 | + { |
|
64 | + $params = array('localhost'); |
|
65 | + } |
|
66 | + // some reasonable default |
|
63 | 67 | |
64 | 68 | $ok = false; |
65 | 69 | foreach($params as $host_port) |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param boolean $verbose =false true: echo failed checks |
29 | 29 | * @return int number of failed checks |
30 | 30 | */ |
31 | - function check($verbose=false) |
|
31 | + function check($verbose = false) |
|
32 | 32 | { |
33 | 33 | // set us up as provider for Api\Cache class |
34 | 34 | $GLOBALS['egw_info']['server']['install_id'] = md5(microtime(true)); |
@@ -37,27 +37,27 @@ discard block |
||
37 | 37 | Api\Cache::$default_provider = get_class($this); |
38 | 38 | |
39 | 39 | $failed = 0; |
40 | - foreach(array( |
|
40 | + foreach (array( |
|
41 | 41 | Api\Cache::TREE => 'tree', |
42 | 42 | Api\Cache::INSTANCE => 'instance', |
43 | 43 | ) as $level => $label) |
44 | 44 | { |
45 | 45 | $locations = array(); |
46 | - foreach(array('string',123,true,false,null,array(),array(1,2,3)) as $data) |
|
46 | + foreach (array('string', 123, true, false, null, array(), array(1, 2, 3)) as $data) |
|
47 | 47 | { |
48 | 48 | $location = md5(microtime(true).$label.serialize($data)); |
49 | - $get_before_set = $this->get(array($level,__CLASS__,$location)); |
|
49 | + $get_before_set = $this->get(array($level, __CLASS__, $location)); |
|
50 | 50 | if (!is_null($get_before_set)) |
51 | 51 | { |
52 | 52 | if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
53 | 53 | ++$failed; |
54 | 54 | } |
55 | - if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
|
55 | + if (($set = $this->set(array($level, __CLASS__, $location), $data, 10)) !== true) |
|
56 | 56 | { |
57 | 57 | if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
58 | 58 | ++$failed; |
59 | 59 | } |
60 | - $get_after_set = $this->get(array($level,__CLASS__,$location)); |
|
60 | + $get_after_set = $this->get(array($level, __CLASS__, $location)); |
|
61 | 61 | if ($get_after_set !== $data) |
62 | 62 | { |
63 | 63 | if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | } |
66 | 66 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
67 | 67 | { |
68 | - $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
|
68 | + $mget_after_set = $this->mget(array($level, __CLASS__, array($location))); |
|
69 | 69 | if ($mget_after_set[$location] !== $data) |
70 | 70 | { |
71 | 71 | if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
72 | 72 | ++$failed; |
73 | 73 | } |
74 | 74 | } |
75 | - $add_after_set = $this->add(array($level,__CLASS__,$location), 'other-data'); |
|
75 | + $add_after_set = $this->add(array($level, __CLASS__, $location), 'other-data'); |
|
76 | 76 | if ($add_after_set !== false) |
77 | 77 | { |
78 | 78 | if ($verbose) echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
79 | 79 | ++$failed; |
80 | 80 | } |
81 | - if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
|
81 | + if (($delete = $this->delete(array($level, __CLASS__, $location))) !== true) |
|
82 | 82 | { |
83 | 83 | if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
84 | 84 | ++$failed; |
85 | 85 | } |
86 | - $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
|
86 | + $get_after_delete = $this->get(array($level, __CLASS__, $location)); |
|
87 | 87 | if (!is_null($get_after_delete)) |
88 | 88 | { |
89 | 89 | if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
94 | 94 | { |
95 | 95 | $locations[$location] = $data; |
96 | - $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
|
96 | + $mget_after_delete = $this->mget(array($level, __CLASS__, array($location))); |
|
97 | 97 | if (isset($mget_after_delete[$location])) |
98 | 98 | { |
99 | 99 | if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | $locations[$location] = $data; |
106 | 106 | } |
107 | - $add_after_delete = $this->add(array($level,__CLASS__,$location), $data, 10); |
|
107 | + $add_after_delete = $this->add(array($level, __CLASS__, $location), $data, 10); |
|
108 | 108 | if ($add_after_delete !== true) |
109 | 109 | { |
110 | 110 | if ($verbose) echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | else |
114 | 114 | { |
115 | - $get_after_add = $this->get(array($level,__CLASS__,$location)); |
|
115 | + $get_after_add = $this->get(array($level, __CLASS__, $location)); |
|
116 | 116 | if ($get_after_add !== $data) |
117 | 117 | { |
118 | 118 | if ($verbose) echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | } |
123 | 123 | // get all above in one request |
124 | 124 | $keys = array_keys($locations); |
125 | - $keys_bogus = array_merge(array('not-set'),array_keys($locations),array('not-set-too')); |
|
125 | + $keys_bogus = array_merge(array('not-set'), array_keys($locations), array('not-set-too')); |
|
126 | 126 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
127 | 127 | { |
128 | - $mget = $this->mget(array($level,__CLASS__,$keys)); |
|
129 | - $mget_bogus = $this->mget(array($level,__CLASS__,$keys_bogus)); |
|
128 | + $mget = $this->mget(array($level, __CLASS__, $keys)); |
|
129 | + $mget_bogus = $this->mget(array($level, __CLASS__, $keys_bogus)); |
|
130 | 130 | /* Api\Cache::getCache() gives a different result, as it does NOT use $level direkt |
131 | 131 | } |
132 | 132 | else |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | function flush(array $keys) |
162 | 162 | { |
163 | - unset($keys); // required by function signature |
|
163 | + unset($keys); // required by function signature |
|
164 | 164 | return false; |
165 | 165 | } |
166 | 166 | } |
@@ -49,18 +49,27 @@ discard block |
||
49 | 49 | $get_before_set = $this->get(array($level,__CLASS__,$location)); |
50 | 50 | if (!is_null($get_before_set)) |
51 | 51 | { |
52 | - if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
|
52 | + if ($verbose) |
|
53 | + { |
|
54 | + echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
|
55 | + } |
|
53 | 56 | ++$failed; |
54 | 57 | } |
55 | 58 | if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
56 | 59 | { |
57 | - if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
|
60 | + if ($verbose) |
|
61 | + { |
|
62 | + echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
|
63 | + } |
|
58 | 64 | ++$failed; |
59 | 65 | } |
60 | 66 | $get_after_set = $this->get(array($level,__CLASS__,$location)); |
61 | 67 | if ($get_after_set !== $data) |
62 | 68 | { |
63 | - if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
|
69 | + if ($verbose) |
|
70 | + { |
|
71 | + echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
|
72 | + } |
|
64 | 73 | ++$failed; |
65 | 74 | } |
66 | 75 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
@@ -68,25 +77,37 @@ discard block |
||
68 | 77 | $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
69 | 78 | if ($mget_after_set[$location] !== $data) |
70 | 79 | { |
71 | - if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
|
80 | + if ($verbose) |
|
81 | + { |
|
82 | + echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
|
83 | + } |
|
72 | 84 | ++$failed; |
73 | 85 | } |
74 | 86 | } |
75 | 87 | $add_after_set = $this->add(array($level,__CLASS__,$location), 'other-data'); |
76 | 88 | if ($add_after_set !== false) |
77 | 89 | { |
78 | - if ($verbose) echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
|
90 | + if ($verbose) |
|
91 | + { |
|
92 | + echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
|
93 | + } |
|
79 | 94 | ++$failed; |
80 | 95 | } |
81 | 96 | if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
82 | 97 | { |
83 | - if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
|
98 | + if ($verbose) |
|
99 | + { |
|
100 | + echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
|
101 | + } |
|
84 | 102 | ++$failed; |
85 | 103 | } |
86 | 104 | $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
87 | 105 | if (!is_null($get_after_delete)) |
88 | 106 | { |
89 | - if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
|
107 | + if ($verbose) |
|
108 | + { |
|
109 | + echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
|
110 | + } |
|
90 | 111 | ++$failed; |
91 | 112 | } |
92 | 113 | // prepare for mget of everything |
@@ -96,18 +117,27 @@ discard block |
||
96 | 117 | $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
97 | 118 | if (isset($mget_after_delete[$location])) |
98 | 119 | { |
99 | - if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
|
120 | + if ($verbose) |
|
121 | + { |
|
122 | + echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
|
123 | + } |
|
100 | 124 | ++$failed; |
101 | 125 | } |
102 | 126 | } |
103 | - elseif (!is_null($data)) // emulation can NOT distinquish between null and not set |
|
127 | + elseif (!is_null($data)) |
|
128 | + { |
|
129 | + // emulation can NOT distinquish between null and not set |
|
104 | 130 | { |
105 | 131 | $locations[$location] = $data; |
106 | 132 | } |
133 | + } |
|
107 | 134 | $add_after_delete = $this->add(array($level,__CLASS__,$location), $data, 10); |
108 | 135 | if ($add_after_delete !== true) |
109 | 136 | { |
110 | - if ($verbose) echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
|
137 | + if ($verbose) |
|
138 | + { |
|
139 | + echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
|
140 | + } |
|
111 | 141 | ++$failed; |
112 | 142 | } |
113 | 143 | else |
@@ -115,7 +145,10 @@ discard block |
||
115 | 145 | $get_after_add = $this->get(array($level,__CLASS__,$location)); |
116 | 146 | if ($get_after_add !== $data) |
117 | 147 | { |
118 | - if ($verbose) echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
|
148 | + if ($verbose) |
|
149 | + { |
|
150 | + echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
|
151 | + } |
|
119 | 152 | ++$failed; |
120 | 153 | } |
121 | 154 | } |
@@ -136,12 +169,18 @@ discard block |
||
136 | 169 | }*/ |
137 | 170 | if ($mget !== $locations) |
138 | 171 | { |
139 | - if ($verbose) echo "$label: mget=\n".array2string($mget)." !==\n".array2string($locations)."\n"; |
|
172 | + if ($verbose) |
|
173 | + { |
|
174 | + echo "$label: mget=\n".array2string($mget)." !==\n".array2string($locations)."\n"; |
|
175 | + } |
|
140 | 176 | ++$failed; |
141 | 177 | } |
142 | 178 | if ($mget_bogus !== $locations) |
143 | 179 | { |
144 | - if ($verbose) echo "$label: mget(".array2string($keys_bogus).")=\n".array2string($mget_bogus)." !==\n".array2string($locations)."\n"; |
|
180 | + if ($verbose) |
|
181 | + { |
|
182 | + echo "$label: mget(".array2string($keys_bogus).")=\n".array2string($mget_bogus)." !==\n".array2string($locations)."\n"; |
|
183 | + } |
|
145 | 184 | ++$failed; |
146 | 185 | } |
147 | 186 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param int $expiration =0 |
39 | 39 | * @return boolean true on success, false on error, incl. key already exists in cache |
40 | 40 | */ |
41 | - function add(array $keys,$data,$expiration=0); |
|
41 | + function add(array $keys, $data, $expiration = 0); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Stores some data in the cache |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param int $expiration =0 |
49 | 49 | * @return boolean true on success, false on error |
50 | 50 | */ |
51 | - function set(array $keys,$data,$expiration=0); |
|
51 | + function set(array $keys, $data, $expiration = 0); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Get some data from the cache |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @param boolean $translated =true use translated name or english |
365 | 365 | * @return string |
366 | 366 | */ |
367 | - public static function get_full_name($code,$translated=true) |
|
367 | + public static function get_full_name($code, $translated = true) |
|
368 | 368 | { |
369 | 369 | if ($translated) |
370 | 370 | { |
@@ -383,36 +383,36 @@ discard block |
||
383 | 383 | */ |
384 | 384 | public static function country_code($name) |
385 | 385 | { |
386 | - if (!$name) return ''; // nothing to do |
|
386 | + if (!$name) return ''; // nothing to do |
|
387 | 387 | |
388 | 388 | if (strlen($name) == 2 && isset(self::$country_array[$name])) |
389 | 389 | { |
390 | - return $name; // $name is already a country-code |
|
390 | + return $name; // $name is already a country-code |
|
391 | 391 | } |
392 | 392 | |
393 | - if (($code = array_search(strtoupper($name),self::$country_array)) !== false) |
|
393 | + if (($code = array_search(strtoupper($name), self::$country_array)) !== false) |
|
394 | 394 | { |
395 | 395 | return $code; |
396 | 396 | } |
397 | 397 | if (!self::$countries_translated) self::_translate_countries(); |
398 | 398 | |
399 | - if (($code = array_search(strtoupper($name),self::$countries_translated)) !== false || |
|
400 | - ($code = array_search($name,self::$countries_translated)) !== false) |
|
399 | + if (($code = array_search(strtoupper($name), self::$countries_translated)) !== false || |
|
400 | + ($code = array_search($name, self::$countries_translated)) !== false) |
|
401 | 401 | { |
402 | 402 | return $code; |
403 | 403 | } |
404 | 404 | // search case-insensitive all translations for the english phrase of given country $name |
405 | 405 | // we do that to catch all possible cases of translations |
406 | - static $en_names = array(); // we do some caching to minimize db-accesses |
|
406 | + static $en_names = array(); // we do some caching to minimize db-accesses |
|
407 | 407 | if (isset($en_names[$name])) |
408 | 408 | { |
409 | 409 | $name = $en_names[$name]; |
410 | 410 | } |
411 | - elseif (($name_en = Translation::get_message_id($name,'common'))) |
|
411 | + elseif (($name_en = Translation::get_message_id($name, 'common'))) |
|
412 | 412 | { |
413 | 413 | $name = $en_names[$name] = strtoupper($name_en); |
414 | 414 | } |
415 | - if (($code = array_search(strtoupper($name),self::$country_array)) !== false) |
|
415 | + if (($code = array_search(strtoupper($name), self::$country_array)) !== false) |
|
416 | 416 | { |
417 | 417 | return $code; |
418 | 418 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | * @param boolean $translated =true use translated names or english |
426 | 426 | * @return array with 2-letter code => name pairs |
427 | 427 | */ |
428 | - public static function countries($translated=true) |
|
428 | + public static function countries($translated = true) |
|
429 | 429 | { |
430 | 430 | if ($translated) |
431 | 431 | { |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | |
448 | 448 | self::$countries_translated = self::$country_array; |
449 | 449 | // try to translate them and sort alphabetic |
450 | - foreach(self::$countries_translated as $k => $name) |
|
450 | + foreach (self::$countries_translated as $k => $name) |
|
451 | 451 | { |
452 | 452 | self::$countries_translated[$k] = lang($name); |
453 | 453 | } |
454 | 454 | |
455 | - if(class_exists('Collator') && class_exists('Locale')) |
|
455 | + if (class_exists('Collator') && class_exists('Locale')) |
|
456 | 456 | { |
457 | 457 | $col = new \Collator(Preferences::setlocale()); |
458 | 458 | $col->asort(self::$countries_translated); |
@@ -368,7 +368,10 @@ discard block |
||
368 | 368 | { |
369 | 369 | if ($translated) |
370 | 370 | { |
371 | - if (!self::$countries_translated) self::_translate_countries(); |
|
371 | + if (!self::$countries_translated) |
|
372 | + { |
|
373 | + self::_translate_countries(); |
|
374 | + } |
|
372 | 375 | |
373 | 376 | return self::$countries_translated[strtoupper($code)]; |
374 | 377 | } |
@@ -383,7 +386,11 @@ discard block |
||
383 | 386 | */ |
384 | 387 | public static function country_code($name) |
385 | 388 | { |
386 | - if (!$name) return ''; // nothing to do |
|
389 | + if (!$name) |
|
390 | + { |
|
391 | + return ''; |
|
392 | + } |
|
393 | + // nothing to do |
|
387 | 394 | |
388 | 395 | if (strlen($name) == 2 && isset(self::$country_array[$name])) |
389 | 396 | { |
@@ -394,7 +401,10 @@ discard block |
||
394 | 401 | { |
395 | 402 | return $code; |
396 | 403 | } |
397 | - if (!self::$countries_translated) self::_translate_countries(); |
|
404 | + if (!self::$countries_translated) |
|
405 | + { |
|
406 | + self::_translate_countries(); |
|
407 | + } |
|
398 | 408 | |
399 | 409 | if (($code = array_search(strtoupper($name),self::$countries_translated)) !== false || |
400 | 410 | ($code = array_search($name,self::$countries_translated)) !== false) |
@@ -429,7 +439,10 @@ discard block |
||
429 | 439 | { |
430 | 440 | if ($translated) |
431 | 441 | { |
432 | - if (!self::$countries_translated) self::_translate_countries(); |
|
442 | + if (!self::$countries_translated) |
|
443 | + { |
|
444 | + self::_translate_countries(); |
|
445 | + } |
|
433 | 446 | |
434 | 447 | return self::$countries_translated; |
435 | 448 | } |
@@ -443,7 +456,10 @@ discard block |
||
443 | 456 | */ |
444 | 457 | protected static function _translate_countries() |
445 | 458 | { |
446 | - if (self::$countries_translated) return; |
|
459 | + if (self::$countries_translated) |
|
460 | + { |
|
461 | + return; |
|
462 | + } |
|
447 | 463 | |
448 | 464 | self::$countries_translated = self::$country_array; |
449 | 465 | // try to translate them and sort alphabetic |