Completed
Push — 16.1 ( 7ccc73...046888 )
by Nathan
64:46 queued 51:15
created
api/src/Accounts/Ads.php 4 patches
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -807,11 +807,11 @@  discard block
 block discarded – undo
807 807
 	}
808 808
 
809 809
 	/**
810
-	* Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000
811
-	*
812
-	* @param long $unixTime
813
-	* @return long windowsTime
814
-	*/
810
+	 * Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000
811
+	 *
812
+	 * @param long $unixTime
813
+	 * @return long windowsTime
814
+	 */
815 815
 	public static function convertUnixTimeToWindowsTime($unixTime)
816 816
 	{
817 817
 		return ($unixTime + 11644477200) * 10000000;
@@ -1263,10 +1263,10 @@  discard block
 block discarded – undo
1263 1263
 	}
1264 1264
 
1265 1265
 	/**
1266
-    * Convert 8bit characters e.g. accented characters to UTF8 encoded characters
1267
-    *
1268
-    * Extended to use mbstring to convert from arbitrary charset to utf-8
1269
-	*/
1266
+	 * Convert 8bit characters e.g. accented characters to UTF8 encoded characters
1267
+	 *
1268
+	 * Extended to use mbstring to convert from arbitrary charset to utf-8
1269
+	 */
1270 1270
 	protected function encode8Bit(&$item, $key)
1271 1271
 	{
1272 1272
 		if ($this->charset != 'utf-8' && $key != 'password')
@@ -1294,29 +1294,29 @@  discard block
 block discarded – undo
1294 1294
 		return $this->userClass;
1295 1295
 	}
1296 1296
 
1297
-    /**
1298
-    * Get the group class interface
1299
-    *
1300
-    * @return adLDAPGroups
1301
-    */
1302
-    public function group() {
1303
-        if (!$this->groupClass) {
1304
-            $this->groupClass = new adLDAPGroups($this);
1305
-        }
1306
-        return $this->groupClass;
1307
-    }
1308
-
1309
-    /**
1310
-    * Get the utils class interface
1311
-    *
1312
-    * @return adLDAPUtils
1313
-    */
1314
-    public function utilities() {
1315
-        if (!$this->utilClass) {
1316
-            $this->utilClass = new adLDAPUtils($this);
1317
-        }
1318
-        return $this->utilClass;
1319
-    }
1297
+	/**
1298
+	 * Get the group class interface
1299
+	 *
1300
+	 * @return adLDAPGroups
1301
+	 */
1302
+	public function group() {
1303
+		if (!$this->groupClass) {
1304
+			$this->groupClass = new adLDAPGroups($this);
1305
+		}
1306
+		return $this->groupClass;
1307
+	}
1308
+
1309
+	/**
1310
+	 * Get the utils class interface
1311
+	 *
1312
+	 * @return adLDAPUtils
1313
+	 */
1314
+	public function utilities() {
1315
+		if (!$this->utilClass) {
1316
+			$this->utilClass = new adLDAPUtils($this);
1317
+		}
1318
+		return $this->utilClass;
1319
+	}
1320 1320
 }
1321 1321
 
1322 1322
 /**
@@ -1405,45 +1405,45 @@  discard block
 block discarded – undo
1405 1405
 		return true;
1406 1406
 	}
1407 1407
 
1408
-    /**
1409
-    * Encode a password for transmission over LDAP
1410
-    *
1411
-    * Extended to use mbstring to convert from arbitrary charset to UTF-16LE
1412
-    *
1413
-    * @param string $password The password to encode
1414
-    * @return string
1415
-    */
1416
-    public function encodePassword($password)
1417
-    {
1418
-        $password="\"".$password."\"";
1419
-        if (function_exists('mb_convert_encoding'))
1420
-        {
1421
-            return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422
-        }
1423
-        $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1425
-        return $encoded;
1426
-    }
1427
-
1428
-    /**
1429
-     * Set a password
1430
-     *
1431
-     * Requires "Reset password" priviledges from bind user!
1432
-     *
1408
+	/**
1409
+	 * Encode a password for transmission over LDAP
1410
+	 *
1411
+	 * Extended to use mbstring to convert from arbitrary charset to UTF-16LE
1412
+	 *
1413
+	 * @param string $password The password to encode
1414
+	 * @return string
1415
+	 */
1416
+	public function encodePassword($password)
1417
+	{
1418
+		$password="\"".$password."\"";
1419
+		if (function_exists('mb_convert_encoding'))
1420
+		{
1421
+			return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422
+		}
1423
+		$encoded="";
1424
+		for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1425
+		return $encoded;
1426
+	}
1427
+
1428
+	/**
1429
+	 * Set a password
1430
+	 *
1431
+	 * Requires "Reset password" priviledges from bind user!
1432
+	 *
1433 1433
 	 * We can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2!
1434 1434
 	 *
1435
-     * @param string $dn
1436
-     * @param string $password
1437
-     * @return boolean
1438
-     */
1439
-    public function setPassword($dn, $password)
1440
-    {
1441
-    	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442
-    		'unicodePwd' => $this->encodePassword($password),
1443
-    	));
1444
-    	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1445
-    	return $result;
1446
-    }
1435
+	 * @param string $dn
1436
+	 * @param string $password
1437
+	 * @return boolean
1438
+	 */
1439
+	public function setPassword($dn, $password)
1440
+	{
1441
+		$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442
+			'unicodePwd' => $this->encodePassword($password),
1443
+		));
1444
+		if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1445
+		return $result;
1446
+	}
1447 1447
 
1448 1448
 	/**
1449 1449
 	 * Check if we can to a real password change, not just a password reset
@@ -1457,30 +1457,30 @@  discard block
 block discarded – undo
1457 1457
 		return function_exists('ldap_modify_batch');
1458 1458
 	}
1459 1459
 
1460
-    /**
1461
-    * Set the password of a user - This must be performed over SSL
1462
-    *
1463
-    * @param string $username The username to modify
1464
-    * @param string $password The new password
1465
-    * @param bool $isGUID Is the username passed a GUID or a samAccountName
1466
-	* @param string $old_password old password for password change, if supported
1467
-    * @return bool
1468
-    */
1469
-    public function password($username, $password, $isGUID = false, $old_password=null)
1470
-    {
1471
-        if ($username === NULL) { return false; }
1472
-        if ($password === NULL) { return false; }
1473
-        if (!$this->adldap->getLdapBind()) { return false; }
1474
-        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1475
-            throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476
-        }
1477
-
1478
-        $userDn = $this->dn($username, $isGUID);
1479
-        if ($userDn === false) {
1480
-            return false;
1481
-        }
1482
-
1483
-        $add=array();
1460
+	/**
1461
+	 * Set the password of a user - This must be performed over SSL
1462
+	 *
1463
+	 * @param string $username The username to modify
1464
+	 * @param string $password The new password
1465
+	 * @param bool $isGUID Is the username passed a GUID or a samAccountName
1466
+	 * @param string $old_password old password for password change, if supported
1467
+	 * @return bool
1468
+	 */
1469
+	public function password($username, $password, $isGUID = false, $old_password=null)
1470
+	{
1471
+		if ($username === NULL) { return false; }
1472
+		if ($password === NULL) { return false; }
1473
+		if (!$this->adldap->getLdapBind()) { return false; }
1474
+		if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1475
+			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476
+		}
1477
+
1478
+		$userDn = $this->dn($username, $isGUID);
1479
+		if ($userDn === false) {
1480
+			return false;
1481
+		}
1482
+
1483
+		$add=array();
1484 1484
 
1485 1485
 		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1486 1486
 			$add["unicodePwd"][0] = $this->encodePassword($password);
@@ -1502,76 +1502,76 @@  discard block
 block discarded – undo
1502 1502
 			);
1503 1503
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1504
 		}
1505
-        if ($result === false){
1506
-            $err = ldap_errno($this->adldap->getLdapConnection());
1507
-            if ($err) {
1508
-                $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1510
-                    $msg .= ' Your password might not match the password policy.';
1511
-                }
1512
-                throw new adLDAPException($msg);
1513
-            }
1514
-            else {
1515
-                return false;
1516
-            }
1517
-        }
1518
-
1519
-        return true;
1520
-    }
1521
-
1522
-    /**
1523
-    * Modify a user
1524
-    *
1525
-    * @param string $username The username to query
1526
-    * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527
-    * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
-    * @return bool
1529
-    */
1530
-    public function modify($username, $attributes, $isGUID = false)
1531
-    {
1532
-        if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
-        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1534
-            throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535
-        }
1536
-
1537
-        // Find the dn of the user
1538
-        $userDn = $this->dn($username, $isGUID);
1539
-        if ($userDn === false) {
1540
-            return false;
1541
-        }
1542
-
1543
-        // Translate the update to the LDAP schema
1544
-        $mod = $this->adldap->adldap_schema($attributes);
1545
-
1546
-        // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1548
-            return false;
1549
-        }
1550
-
1551
-        // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1554
-                $controlOptions = array("NORMAL_ACCOUNT");
1555
-            }
1556
-            else {
1557
-                $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558
-            }
1559
-            $mod["userAccountControl"][0] = $this->accountControl($controlOptions);
1560
-        }
1505
+		if ($result === false){
1506
+			$err = ldap_errno($this->adldap->getLdapConnection());
1507
+			if ($err) {
1508
+				$msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
+				if($err == 53) {
1510
+					$msg .= ' Your password might not match the password policy.';
1511
+				}
1512
+				throw new adLDAPException($msg);
1513
+			}
1514
+			else {
1515
+				return false;
1516
+			}
1517
+		}
1518
+
1519
+		return true;
1520
+	}
1521
+
1522
+	/**
1523
+	 * Modify a user
1524
+	 *
1525
+	 * @param string $username The username to query
1526
+	 * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527
+	 * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
+	 * @return bool
1529
+	 */
1530
+	public function modify($username, $attributes, $isGUID = false)
1531
+	{
1532
+		if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
+		if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1534
+			throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535
+		}
1536
+
1537
+		// Find the dn of the user
1538
+		$userDn = $this->dn($username, $isGUID);
1539
+		if ($userDn === false) {
1540
+			return false;
1541
+		}
1542
+
1543
+		// Translate the update to the LDAP schema
1544
+		$mod = $this->adldap->adldap_schema($attributes);
1545
+
1546
+		// Check to see if this is an enabled status update
1547
+		if (!$mod && !array_key_exists("enabled", $attributes)){
1548
+			return false;
1549
+		}
1550
+
1551
+		// Set the account control attribute (only if specified)
1552
+		if (array_key_exists("enabled", $attributes)){
1553
+			if ($attributes["enabled"]){
1554
+				$controlOptions = array("NORMAL_ACCOUNT");
1555
+			}
1556
+			else {
1557
+				$controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558
+			}
1559
+			$mod["userAccountControl"][0] = $this->accountControl($controlOptions);
1560
+		}
1561 1561
 		// we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2
1562 1562
 		unset($mod['unicodePwd']);
1563 1563
 
1564 1564
 		if ($mod)
1565 1565
 		{
1566
-	        // Do the update
1567
-	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
-	        if ($result == false) {
1566
+			// Do the update
1567
+			$result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
+			if ($result == false) {
1569 1569
 				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1570 1570
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571
-	        	return false;
1572
-	        }
1571
+				return false;
1572
+			}
1573 1573
 		}
1574
-        if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1574
+		if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1575 1575
 		{
1576 1576
 			return false;
1577 1577
 		}
@@ -1636,23 +1636,23 @@  discard block
 block discarded – undo
1636 1636
 		return $this->adldap->encode8bit($item, $key);
1637 1637
 	}
1638 1638
 
1639
-    /**
1640
-    * Escape strings for the use in LDAP filters
1641
-    *
1642
-    * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT
1643
-    * Ported from Perl's Net::LDAP::Util escape_filter_value
1644
-    *
1645
-    * @param string $str The string the parse
1646
-    * @author Port by Andreas Gohr <[email protected]>
1647
-    * @return string
1648
-    */
1649
-    public function ldapSlashes($str){
1650
-        return preg_replace_callback(
1651
-      		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1653
-            	return "\\".join("", unpack("H2", $matches[1]));
1654
-        	},
1655
-        	$str
1656
-    	);
1657
-    }
1639
+	/**
1640
+	 * Escape strings for the use in LDAP filters
1641
+	 *
1642
+	 * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT
1643
+	 * Ported from Perl's Net::LDAP::Util escape_filter_value
1644
+	 *
1645
+	 * @param string $str The string the parse
1646
+	 * @author Port by Andreas Gohr <[email protected]>
1647
+	 * @return string
1648
+	 */
1649
+	public function ldapSlashes($str){
1650
+		return preg_replace_callback(
1651
+	  		'/([\x00-\x1F\*\(\)\\\\])/',
1652
+			function ($matches) {
1653
+				return "\\".join("", unpack("H2", $matches[1]));
1654
+			},
1655
+			$str
1656
+		);
1657
+	}
1658 1658
 }
Please login to merge, or discard this patch.
Braces   +234 added lines, -78 removed lines patch added patch discarded remove patch
@@ -136,12 +136,21 @@  discard block
 block discarded – undo
136 136
 	public static function get_adldap(array &$config=null)
137 137
 	{
138 138
 		static $adldap = array();
139
-		if (!$config) $config =& $GLOBALS['egw_info']['server'];
139
+		if (!$config)
140
+		{
141
+			$config =& $GLOBALS['egw_info']['server'];
142
+		}
140 143
 
141 144
 		if (!isset($adldap[$config['ads_domain']]))
142 145
 		{
143
-			if (empty($config['ads_host'])) throw new Api\Exception("Required ADS host name(s) missing!");
144
-			if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!");
146
+			if (empty($config['ads_host']))
147
+			{
148
+				throw new Api\Exception("Required ADS host name(s) missing!");
149
+			}
150
+			if (empty($config['ads_domain']))
151
+			{
152
+				throw new Api\Exception("Required ADS domain missing!");
153
+			}
145 154
 
146 155
 			$base_dn_parts = array();
147 156
 			foreach(explode('.', $config['ads_domain']) as $dc)
@@ -160,7 +169,10 @@  discard block
 block discarded – undo
160 169
 				'charset' => Api\Translation::charset(),
161 170
 			);
162 171
 			$adldap[$config['ads_domain']] = new adLDAP($options);
163
-			if (self::$debug) error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
172
+			if (self::$debug)
173
+			{
174
+				error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
175
+			}
164 176
 		}
165 177
 		//else error_log(__METHOD__."() returning cached adLDAP ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
166 178
 		return $adldap[$config['ads_domain']];
@@ -241,7 +253,10 @@  discard block
 block discarded – undo
241 253
 			throw new Api\Exception\WrongUserinput("Wrong or not configured ADS context '$context' (baseDN='$base')!");
242 254
 		}
243 255
 		$container = $matches[1];
244
-		if (self::$debug) error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container));
256
+		if (self::$debug)
257
+		{
258
+			error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container));
259
+		}
245 260
 		return $container;
246 261
 	}
247 262
 
@@ -334,10 +349,16 @@  discard block
 block discarded – undo
334 349
 	 */
335 350
 	public function read($account_id)
336 351
 	{
337
-		if (!(int)$account_id) return false;
352
+		if (!(int)$account_id)
353
+		{
354
+			return false;
355
+		}
338 356
 
339 357
 		$ret = $account_id < 0 ? $this->_read_group($account_id) : $this->_read_user($account_id);
340
-		if (self::$debug) error_log(__METHOD__."($account_id) returning ".array2string($ret));
358
+		if (self::$debug)
359
+		{
360
+			error_log(__METHOD__."($account_id) returning ".array2string($ret));
361
+		}
341 362
 		return $ret;
342 363
 	}
343 364
 
@@ -370,7 +391,10 @@  discard block
 block discarded – undo
370 391
 		}
371 392
 		$ret = $is_group ? $this->_save_group($data, $old) : $this->_save_user($data, $old);
372 393
 
373
-		if (self::$debug) error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret));
394
+		if (self::$debug)
395
+		{
396
+			error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret));
397
+		}
374 398
 		return $ret;
375 399
 	}
376 400
 
@@ -400,7 +424,10 @@  discard block
 block discarded – undo
400 424
 		{
401 425
 			$ret = $this->adldap->user()->delete($account_lid);
402 426
 		}
403
-		if (self::$debug) error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret));
427
+		if (self::$debug)
428
+		{
429
+			error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret));
430
+		}
404 431
 		return $ret;
405 432
 	}
406 433
 
@@ -562,11 +589,17 @@  discard block
 block discarded – undo
562 589
 	protected static function _when2ts($_when)
563 590
 	{
564 591
 		static $utc=null;
565
-		if (!isset($utc)) $utc = new \DateTimeZone('UTC');
592
+		if (!isset($utc))
593
+		{
594
+			$utc = new \DateTimeZone('UTC');
595
+		}
566 596
 
567 597
 		list($when) = explode('.', $_when);	// remove .0Z not understood by createFromFormat
568 598
 		$datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
569
-		if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
599
+		if (Api\DateTime::$server_timezone)
600
+		{
601
+			$datetime->setTimezone(Api\DateTime::$server_timezone);
602
+		}
570 603
 
571 604
 		return $datetime->getTimestamp();
572 605
 	}
@@ -583,12 +616,15 @@  discard block
 block discarded – undo
583 616
 	{
584 617
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
585 618
 
586
-		if (!$old)	// new entry
619
+		if (!$old)
620
+		{
621
+			// new entry
587 622
 		{
588 623
 			static $new2adldap = array(
589 624
 				'account_lid'       => 'group_name',
590 625
 				'account_description' => 'description',
591 626
 			);
627
+		}
592 628
 			$attributes = array();
593 629
 			foreach($new2adldap as $egw => $adldap)
594 630
 			{
@@ -668,7 +704,9 @@  discard block
 block discarded – undo
668 704
 			$data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname'];
669 705
 		}
670 706
 
671
-		if (($new_entry = !$old))	// new entry
707
+		if (($new_entry = !$old))
708
+		{
709
+			// new entry
672 710
 		{
673 711
 			static $new2adldap = array(
674 712
 				'account_lid'       => 'username',
@@ -679,6 +717,7 @@  discard block
 block discarded – undo
679 717
 				'account_passwd'    => 'password',
680 718
 				'account_status'    => 'enabled',
681 719
 			);
720
+		}
682 721
 			$attributes = array();
683 722
 			foreach($new2adldap as $egw => $adldap)
684 723
 			{
@@ -687,7 +726,10 @@  discard block
 block discarded – undo
687 726
 				{
688 727
 					continue;	// do not try to set password, if no SSL or TLS, whole user creation will fail
689 728
 				}
690
-				if (isset($data[$egw])) $attributes[$adldap] = $data[$egw];
729
+				if (isset($data[$egw]))
730
+				{
731
+					$attributes[$adldap] = $data[$egw];
732
+				}
691 733
 			}
692 734
 			$attributes['enabled'] = !isset($data['account_status']) || $data['account_status'] === 'A';
693 735
 			$attributes['container'] = $this->_get_container();
@@ -773,7 +815,11 @@  discard block
 block discarded – undo
773 815
 							self::convertUnixTimeToWindowsTime($data[$egw]);
774 816
 						break;
775 817
 					case 'account_status':
776
-						if ($new_entry && empty($data['account_passwd'])) continue;	// cant active new account without passwd!
818
+						if ($new_entry && empty($data['account_passwd']))
819
+						{
820
+							continue;
821
+						}
822
+						// cant active new account without passwd!
777 823
 						$attributes[$adldap] = $data[$egw] == 'A';
778 824
 						break;
779 825
 					case 'account_lastpwd_change':
@@ -853,8 +899,14 @@  discard block
 block discarded – undo
853 899
 		}
854 900
 		// if it's a limited query, check if the unlimited query is cached
855 901
 		$start = $param['start'];
856
-		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15;
857
-		if (!($offset = $param['offset'])) $offset = $maxmatchs;
902
+		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']))
903
+		{
904
+			$maxmatchs = 15;
905
+		}
906
+		if (!($offset = $param['offset']))
907
+		{
908
+			$offset = $maxmatchs;
909
+		}
858 910
 		unset($param['start']);
859 911
 		unset($param['offset']);
860 912
 		$unl_serial = serialize($param);
@@ -1051,7 +1103,10 @@  discard block
 block discarded – undo
1051 1103
 			$attrs ? $attrs : self::$default_attributes);
1052 1104
 		if (!$sri)
1053 1105
 		{
1054
-			if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1106
+			if (self::$debug)
1107
+			{
1108
+				error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1109
+			}
1055 1110
 			$sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter,
1056 1111
 				$attrs ? $attrs : self::$default_attributes);
1057 1112
 		}
@@ -1060,7 +1115,10 @@  discard block
 block discarded – undo
1060 1115
 		{
1061 1116
 			foreach($allValues as $key => $data)
1062 1117
 			{
1063
-				if ($key === 'count') continue;
1118
+				if ($key === 'count')
1119
+				{
1120
+					continue;
1121
+				}
1064 1122
 
1065 1123
 				if ($account_type && !($account_type == 'u' && $data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT ||
1066 1124
 					$account_type == 'g' && $data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP))
@@ -1078,7 +1136,10 @@  discard block
 block discarded – undo
1078 1136
 					$attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
1079 1137
 			}
1080 1138
 		}
1081
-		else if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues));
1139
+		else if (self::$debug)
1140
+		{
1141
+			error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues));
1142
+		}
1082 1143
 
1083 1144
 		//error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returning ".array2string($accounts).' '.function_backtrace());
1084 1145
 		return $accounts;
@@ -1115,7 +1176,10 @@  discard block
 block discarded – undo
1115 1176
 				break;
1116 1177
 			}
1117 1178
 		}
1118
-		if (self::$debug) error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret));
1179
+		if (self::$debug)
1180
+		{
1181
+			error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret));
1182
+		}
1119 1183
 		return $ret;
1120 1184
 	}
1121 1185
 
@@ -1157,7 +1221,10 @@  discard block
 block discarded – undo
1157 1221
 	 */
1158 1222
 	function memberships($account_id)
1159 1223
 	{
1160
-		if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0) return false;
1224
+		if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0)
1225
+		{
1226
+			return false;
1227
+		}
1161 1228
 
1162 1229
 		return $data['memberships'];
1163 1230
 	}
@@ -1172,7 +1239,10 @@  discard block
 block discarded – undo
1172 1239
 	 */
1173 1240
 	function members($gid)
1174 1241
 	{
1175
-		if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0) return false;
1242
+		if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0)
1243
+		{
1244
+			return false;
1245
+		}
1176 1246
 
1177 1247
 		return $data['members'];
1178 1248
 	}
@@ -1186,7 +1256,10 @@  discard block
 block discarded – undo
1186 1256
 	 */
1187 1257
 	function set_memberships($groups,$account_id)
1188 1258
 	{
1189
-		if (!($account = $this->id2name($account_id))) return;
1259
+		if (!($account = $this->id2name($account_id)))
1260
+		{
1261
+			return;
1262
+		}
1190 1263
 		$current = array_keys($this->memberships($account_id));
1191 1264
 
1192 1265
 		$changed = 0;
@@ -1203,7 +1276,10 @@  discard block
 block discarded – undo
1203 1276
 				$changed += (int)$ok;
1204 1277
 			}
1205 1278
 		}
1206
-		if (self::$debug) error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed");
1279
+		if (self::$debug)
1280
+		{
1281
+			error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed");
1282
+		}
1207 1283
 		return $changed;
1208 1284
 	}
1209 1285
 
@@ -1216,7 +1292,10 @@  discard block
 block discarded – undo
1216 1292
 	 */
1217 1293
 	function set_members($users, $gid)
1218 1294
 	{
1219
-		if (!($group = $this->id2name($gid))) return;
1295
+		if (!($group = $this->id2name($gid)))
1296
+		{
1297
+			return;
1298
+		}
1220 1299
 		$current = array_keys($this->members($gid));
1221 1300
 
1222 1301
 		$changed = 0;
@@ -1233,7 +1312,10 @@  discard block
 block discarded – undo
1233 1312
 				$changed += (int)$ok;
1234 1313
 			}
1235 1314
 		}
1236
-		if (self::$debug) error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed");
1315
+		if (self::$debug)
1316
+		{
1317
+			error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed");
1318
+		}
1237 1319
 		return $changed;
1238 1320
 	}
1239 1321
 }
@@ -1287,8 +1369,10 @@  discard block
 block discarded – undo
1287 1369
 	 *
1288 1370
 	 * @return adLDAPUsers
1289 1371
 	 */
1290
-	public function user() {
1291
-		if (!$this->userClass) {
1372
+	public function user()
1373
+	{
1374
+		if (!$this->userClass)
1375
+		{
1292 1376
 			$this->userClass = new adLDAPUsers($this);
1293 1377
 		}
1294 1378
 		return $this->userClass;
@@ -1299,8 +1383,10 @@  discard block
 block discarded – undo
1299 1383
     *
1300 1384
     * @return adLDAPGroups
1301 1385
     */
1302
-    public function group() {
1303
-        if (!$this->groupClass) {
1386
+    public function group()
1387
+    {
1388
+        if (!$this->groupClass)
1389
+        {
1304 1390
             $this->groupClass = new adLDAPGroups($this);
1305 1391
         }
1306 1392
         return $this->groupClass;
@@ -1311,8 +1397,10 @@  discard block
 block discarded – undo
1311 1397
     *
1312 1398
     * @return adLDAPUtils
1313 1399
     */
1314
-    public function utilities() {
1315
-        if (!$this->utilClass) {
1400
+    public function utilities()
1401
+    {
1402
+        if (!$this->utilClass)
1403
+        {
1316 1404
             $this->utilClass = new adLDAPUtils($this);
1317 1405
         }
1318 1406
         return $this->utilClass;
@@ -1340,18 +1428,32 @@  discard block
 block discarded – undo
1340 1428
 	public function create($attributes)
1341 1429
 	{
1342 1430
 		// Check for compulsory fields
1343
-		if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; }
1344
-		if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; }
1345
-		if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; }
1346
-		if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; }
1347
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1348
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1349
-
1350
-		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){
1431
+		if (!array_key_exists("username", $attributes))
1432
+		{
1433
+return "Missing compulsory field [username]"; }
1434
+		if (!array_key_exists("firstname", $attributes))
1435
+		{
1436
+return "Missing compulsory field [firstname]"; }
1437
+		if (!array_key_exists("surname", $attributes))
1438
+		{
1439
+return "Missing compulsory field [surname]"; }
1440
+		if (!array_key_exists("email", $attributes))
1441
+		{
1442
+return "Missing compulsory field [email]"; }
1443
+		if (!array_key_exists("container", $attributes))
1444
+		{
1445
+return "Missing compulsory field [container]"; }
1446
+		if (empty($attributes["container"]))
1447
+		{
1448
+return "Container attribute must be an array or string."; }
1449
+
1450
+		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()))
1451
+		{
1351 1452
 			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1352 1453
 		}
1353 1454
 
1354
-		if (!array_key_exists("display_name", $attributes)) {
1455
+		if (!array_key_exists("display_name", $attributes))
1456
+		{
1355 1457
 			$attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"];
1356 1458
 		}
1357 1459
 
@@ -1373,7 +1475,8 @@  discard block
 block discarded – undo
1373 1475
 		$add["userAccountControl"][0] = $this->accountControl($control_options);
1374 1476
 
1375 1477
 		// Determine the container
1376
-		if (is_array($attributes['container'])) {
1478
+		if (is_array($attributes['container']))
1479
+		{
1377 1480
 			$attributes["container"] = array_reverse($attributes["container"]);
1378 1481
 			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1379 1482
 		}
@@ -1382,7 +1485,8 @@  discard block
 block discarded – undo
1382 1485
 
1383 1486
 		// Add the entry
1384 1487
 		$result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1385
-		if ($result != true) {
1488
+		if ($result != true)
1489
+		{
1386 1490
 			error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1387 1491
 			return false;
1388 1492
 		}
@@ -1390,7 +1494,10 @@  discard block
 block discarded – undo
1390 1494
 		// now password can be added to still disabled account
1391 1495
 		if (array_key_exists("password",$attributes))
1392 1496
 		{
1393
-			if (!$this->setPassword($dn, $attributes['password'])) return false;
1497
+			if (!$this->setPassword($dn, $attributes['password']))
1498
+			{
1499
+				return false;
1500
+			}
1394 1501
 
1395 1502
 			// now account can be enabled
1396 1503
 			if ($attributes["enabled"])
@@ -1398,7 +1505,10 @@  discard block
 block discarded – undo
1398 1505
 				$control_options = array("NORMAL_ACCOUNT");
1399 1506
 				$mod = array("userAccountControl" => $this->accountControl($control_options));
1400 1507
 				$result = ldap_modify($ds, $dn, $mod);
1401
-				if (!$result) error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1508
+				if (!$result)
1509
+				{
1510
+					error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1511
+				}
1402 1512
 			}
1403 1513
 		}
1404 1514
 
@@ -1421,7 +1531,9 @@  discard block
 block discarded – undo
1421 1531
             return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422 1532
         }
1423 1533
         $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1534
+        for ($i=0; $i <strlen($password); $i++)
1535
+        {
1536
+$encoded.="{$password{$i}}\000"; }
1425 1537
         return $encoded;
1426 1538
     }
1427 1539
 
@@ -1441,7 +1553,10 @@  discard block
 block discarded – undo
1441 1553
     	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442 1554
     		'unicodePwd' => $this->encodePassword($password),
1443 1555
     	));
1444
-    	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1556
+    	if (!$result)
1557
+    	{
1558
+    		error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1559
+    	}
1445 1560
     	return $result;
1446 1561
     }
1447 1562
 
@@ -1468,26 +1583,36 @@  discard block
 block discarded – undo
1468 1583
     */
1469 1584
     public function password($username, $password, $isGUID = false, $old_password=null)
1470 1585
     {
1471
-        if ($username === NULL) { return false; }
1472
-        if ($password === NULL) { return false; }
1473
-        if (!$this->adldap->getLdapBind()) { return false; }
1474
-        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1586
+        if ($username === NULL)
1587
+        {
1588
+return false; }
1589
+        if ($password === NULL)
1590
+        {
1591
+return false; }
1592
+        if (!$this->adldap->getLdapBind())
1593
+        {
1594
+return false; }
1595
+        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())
1596
+        {
1475 1597
             throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476 1598
         }
1477 1599
 
1478 1600
         $userDn = $this->dn($username, $isGUID);
1479
-        if ($userDn === false) {
1601
+        if ($userDn === false)
1602
+        {
1480 1603
             return false;
1481 1604
         }
1482 1605
 
1483 1606
         $add=array();
1484 1607
 
1485
-		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1608
+		if (empty($old_password) || !function_exists('ldap_modify_batch'))
1609
+		{
1486 1610
 			$add["unicodePwd"][0] = $this->encodePassword($password);
1487 1611
 
1488 1612
 			$result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $add);
1489 1613
 		}
1490
-		else {
1614
+		else
1615
+		{
1491 1616
 			$mods = array(
1492 1617
 				array(
1493 1618
 					"attrib"  => "unicodePwd",
@@ -1502,16 +1627,20 @@  discard block
 block discarded – undo
1502 1627
 			);
1503 1628
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1629
 		}
1505
-        if ($result === false){
1630
+        if ($result === false)
1631
+        {
1506 1632
             $err = ldap_errno($this->adldap->getLdapConnection());
1507
-            if ($err) {
1633
+            if ($err)
1634
+            {
1508 1635
                 $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1636
+                if($err == 53)
1637
+                {
1510 1638
                     $msg .= ' Your password might not match the password policy.';
1511 1639
                 }
1512 1640
                 throw new adLDAPException($msg);
1513 1641
             }
1514
-            else {
1642
+            else
1643
+            {
1515 1644
                 return false;
1516 1645
             }
1517 1646
         }
@@ -1529,14 +1658,18 @@  discard block
 block discarded – undo
1529 1658
     */
1530 1659
     public function modify($username, $attributes, $isGUID = false)
1531 1660
     {
1532
-        if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
-        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1661
+        if ($username === NULL)
1662
+        {
1663
+return "Missing compulsory field [username]"; }
1664
+        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())
1665
+        {
1534 1666
             throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535 1667
         }
1536 1668
 
1537 1669
         // Find the dn of the user
1538 1670
         $userDn = $this->dn($username, $isGUID);
1539
-        if ($userDn === false) {
1671
+        if ($userDn === false)
1672
+        {
1540 1673
             return false;
1541 1674
         }
1542 1675
 
@@ -1544,16 +1677,20 @@  discard block
 block discarded – undo
1544 1677
         $mod = $this->adldap->adldap_schema($attributes);
1545 1678
 
1546 1679
         // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1680
+        if (!$mod && !array_key_exists("enabled", $attributes))
1681
+        {
1548 1682
             return false;
1549 1683
         }
1550 1684
 
1551 1685
         // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1686
+        if (array_key_exists("enabled", $attributes))
1687
+        {
1688
+            if ($attributes["enabled"])
1689
+            {
1554 1690
                 $controlOptions = array("NORMAL_ACCOUNT");
1555 1691
             }
1556
-            else {
1692
+            else
1693
+            {
1557 1694
                 $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558 1695
             }
1559 1696
             $mod["userAccountControl"][0] = $this->accountControl($controlOptions);
@@ -1565,14 +1702,18 @@  discard block
 block discarded – undo
1565 1702
 		{
1566 1703
 	        // Do the update
1567 1704
 	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
-	        if ($result == false) {
1569
-				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1705
+	        if ($result == false)
1706
+	        {
1707
+				if (isset($mod['unicodePwd']))
1708
+				{
1709
+					$mod['unicodePwd'] = '***';
1710
+				}
1570 1711
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571 1712
 	        	return false;
1572 1713
 	        }
1573 1714
 		}
1574 1715
         if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1575
-		{
1716
+        {
1576 1717
 			return false;
1577 1718
 		}
1578 1719
 		return true;
@@ -1594,10 +1735,18 @@  discard block
 block discarded – undo
1594 1735
 	 */
1595 1736
 	public function create($attributes)
1596 1737
 	{
1597
-		if (!is_array($attributes)){ return "Attributes must be an array"; }
1598
-		if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; }
1599
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1600
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1738
+		if (!is_array($attributes))
1739
+		{
1740
+return "Attributes must be an array"; }
1741
+		if (!array_key_exists("group_name", $attributes))
1742
+		{
1743
+return "Missing compulsory field [group_name]"; }
1744
+		if (!array_key_exists("container", $attributes))
1745
+		{
1746
+return "Missing compulsory field [container]"; }
1747
+		if (empty($attributes["container"]))
1748
+		{
1749
+return "Container attribute must be an array or string."; }
1601 1750
 
1602 1751
 		//$member_array = array();
1603 1752
 		//$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com";
@@ -1607,16 +1756,21 @@  discard block
 block discarded – undo
1607 1756
 		$add["cn"] = $attributes["group_name"];
1608 1757
 		$add["samaccountname"] = $attributes["group_name"];
1609 1758
 		$add["objectClass"] = "Group";
1610
-		if (!empty($attributes["description"])) $add["description"] = $attributes["description"];
1759
+		if (!empty($attributes["description"]))
1760
+		{
1761
+			$add["description"] = $attributes["description"];
1762
+		}
1611 1763
 		//$add["member"] = $member_array; UNTESTED
1612 1764
 
1613 1765
 		// Determine the container
1614
-		if (is_array($attributes['container'])) {
1766
+		if (is_array($attributes['container']))
1767
+		{
1615 1768
 			$attributes["container"] = array_reverse($attributes["container"]);
1616 1769
 			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1617 1770
 		}
1618 1771
 		$result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1619
-		if ($result != true) {
1772
+		if ($result != true)
1773
+		{
1620 1774
 			return false;
1621 1775
 		}
1622 1776
 		return true;
@@ -1646,10 +1800,12 @@  discard block
 block discarded – undo
1646 1800
     * @author Port by Andreas Gohr <[email protected]>
1647 1801
     * @return string
1648 1802
     */
1649
-    public function ldapSlashes($str){
1803
+    public function ldapSlashes($str)
1804
+    {
1650 1805
         return preg_replace_callback(
1651 1806
       		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1807
+        	function ($matches)
1808
+        	{
1653 1809
             	return "\\".join("", unpack("H2", $matches[1]));
1654 1810
         	},
1655 1811
         	$str
Please login to merge, or discard this patch.
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	/**
130 130
 	 * Factory method and singelton to get adLDAP object for given configuration or default server config
131 131
 	 *
132
-	 * @param array $config=null values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection'
132
+	 * @param array $config values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection'
133 133
 	 * @return adLDAP
134 134
 	 * @throws adLDAPException
135 135
 	 */
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 * Convert binary GUID to string
309 309
 	 *
310 310
 	 * @param string $objectguid
311
-	 * @return int
311
+	 * @return string
312 312
 	 */
313 313
 	public function objectguid2str($objectguid)
314 314
 	{
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * Convert a string GUID to hex string used in filter
320 320
 	 *
321 321
 	 * @param string $strGUID
322
-	 * @return int
322
+	 * @return string
323 323
 	 */
324 324
 	public function objectguid2hex($strGUID)
325 325
 	{
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * Delete one account, deletes also all acl-entries for that account
379 379
 	 *
380 380
 	 * @param int $account_id numeric account_id
381
-	 * @return boolean true on success, false otherwise
381
+	 * @return string|boolean true on success, false otherwise
382 382
 	 */
383 383
 	function delete($account_id)
384 384
 	{
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 	 *
1139 1139
 	 * @param int $_account_id
1140 1140
 	 * @param string $ip
1141
-	 * @return int lastlogin time
1141
+	 * @return boolean lastlogin time
1142 1142
 	 */
1143 1143
 	function update_lastlogin($_account_id, $ip)
1144 1144
 	{
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 	 * - activate user
1336 1336
 	 *
1337 1337
 	 * @param array $attributes The attributes to set to the user account
1338
-	 * @return bool
1338
+	 * @return string|boolean
1339 1339
 	 */
1340 1340
 	public function create($attributes)
1341 1341
 	{
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
     * @param string $username The username to query
1526 1526
     * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527 1527
     * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
-    * @return bool
1528
+    * @return string|boolean
1529 1529
     */
1530 1530
     public function modify($username, $attributes, $isGUID = false)
1531 1531
     {
@@ -1590,7 +1590,7 @@  discard block
 block discarded – undo
1590 1590
 	 * Extended to allow to specify $attribute["container"] as string, because array hardcodes "OU=", while Samba4 and win2008r2 uses "CN=Users"
1591 1591
 	 *
1592 1592
 	 * @param array $attributes Default attributes of the group
1593
-	 * @return bool
1593
+	 * @return string|boolean
1594 1594
 	 */
1595 1595
 	public function create($attributes)
1596 1596
 	{
Please login to merge, or discard this patch.
Spacing   +109 added lines, -114 removed lines patch added patch discarded remove patch
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 * @return adLDAP
134 134
 	 * @throws adLDAPException
135 135
 	 */
136
-	public static function get_adldap(array &$config=null)
136
+	public static function get_adldap(array &$config = null)
137 137
 	{
138 138
 		static $adldap = array();
139
-		if (!$config) $config =& $GLOBALS['egw_info']['server'];
139
+		if (!$config) $config = & $GLOBALS['egw_info']['server'];
140 140
 
141 141
 		if (!isset($adldap[$config['ads_domain']]))
142 142
 		{
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!");
145 145
 
146 146
 			$base_dn_parts = array();
147
-			foreach(explode('.', $config['ads_domain']) as $dc)
147
+			foreach (explode('.', $config['ads_domain']) as $dc)
148 148
 			{
149 149
 				$base_dn_parts[] = 'DC='.$dc;
150 150
 			}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @param int $account_id
173 173
 	 * @return string|NULL
174 174
 	 */
175
-	protected function get_sid($account_id=null)
175
+	protected function get_sid($account_id = null)
176 176
 	{
177 177
 		static $domain_sid = null;
178 178
 		if (!isset($domain_sid))
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
 	 * @param boolean $set_if_empty =false true set from DN of "Domain Users" group #
208 208
 	 * @return string
209 209
 	 */
210
-	public function ads_context($set_if_empty=false)
210
+	public function ads_context($set_if_empty = false)
211 211
 	{
212 212
 		if (empty($this->frontend->config[self::ADS_CONTEXT]))
213 213
 		{
214 214
 			if ($set_if_empty && ($dn = $this->id2name(-self::DOMAIN_USERS_GROUP, 'account_dn')))
215 215
 			{
216 216
 				$dn = preg_replace('/^CN=.*?,(CN|OU)=/i', '$1=', $dn);
217
-				Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT]=$dn, 'phpgwapi');
217
+				Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT] = $dn, 'phpgwapi');
218 218
 			}
219 219
 			else
220 220
 			{
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @param boolean $reconnect =false true: reconnect even if already connected
252 252
 	 * @return resource
253 253
 	 */
254
-	public function ldap_connection($reconnect=false)
254
+	public function ldap_connection($reconnect = false)
255 255
 	{
256 256
 		if (($reconnect || !($ds = $this->adldap->getLdapConnection())) &&
257 257
 			// call connect, thought I dont know how it can be not connected ...
@@ -415,8 +415,7 @@  discard block
 block discarded – undo
415 415
 		$data = Api\Translation::convert($_data, 'utf-8');
416 416
 
417 417
 		// no need to calculate sid, if already calculated
418
-		$sid = is_string($data['objectsid']) ? $data['objectsid'] :
419
-			$this->adldap->utilities()->getTextSID($data['objectsid'][0]);
418
+		$sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]);
420 419
 		$account_id = -self::sid2account_id($sid);
421 420
 
422 421
 		$group = array(
@@ -453,7 +452,7 @@  discard block
 block discarded – undo
453 452
 	{
454 453
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'g', self::$group_attributes)))
455 454
 		{
456
-			return false;	// group not found
455
+			return false; // group not found
457 456
 		}
458 457
 		$group = $this->_ldap2group(array_shift($data));
459 458
 
@@ -476,8 +475,7 @@  discard block
 block discarded – undo
476 475
 		$data = Api\Translation::convert($_data, 'utf-8');
477 476
 
478 477
 		// no need to calculate sid, if already calculated
479
-		$sid = is_string($data['objectsid']) ? $data['objectsid'] :
480
-			$this->adldap->utilities()->getTextSID($data['objectsid'][0]);
478
+		$sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]);
481 479
 		$account_id = self::sid2account_id($sid);
482 480
 
483 481
 		$user = array(
@@ -493,11 +491,9 @@  discard block
 block discarded – undo
493 491
 			'account_email'     => $data['mail'][0],
494 492
 			'account_fullname'  => $data['displayname'][0],
495 493
 			'account_phone'     => $data['telephonenumber'][0],
496
-			'account_status'    => $data['useraccountcontrol'][0] & 2 ? false : 'A',
497
-			'account_expires'   => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 :
498
-				$this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]),
499
-			'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 :
500
-				$this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])),
494
+			'account_status'    => $data['useraccountcontrol'][0]&2 ? false : 'A',
495
+			'account_expires'   => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]),
496
+			'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])),
501 497
 			'account_created' => !isset($data['whencreated'][0]) ? null :
502 498
 				self::_when2ts($data['whencreated'][0]),
503 499
 			'account_modified' => !isset($data['whenchanged'][0]) ? null :
@@ -508,7 +504,7 @@  discard block
 block discarded – undo
508 504
 		{
509 505
 			$user['account_status'] = false;
510 506
 		}
511
-		$user['person_id'] = $user['account_guid'];	// id of contact
507
+		$user['person_id'] = $user['account_guid']; // id of contact
512 508
 		//error_log(__METHOD__."(".array2string($data).") returning ".array2string($user));
513 509
 		return $user;
514 510
 	}
@@ -538,7 +534,7 @@  discard block
 block discarded – undo
538 534
 	{
539 535
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'u', self::$user_attributes)))
540 536
 		{
541
-			return false;	// user not found
537
+			return false; // user not found
542 538
 		}
543 539
 		$user = $this->_ldap2user(array_shift($data));
544 540
 
@@ -561,10 +557,10 @@  discard block
 block discarded – undo
561 557
 	 */
562 558
 	protected static function _when2ts($_when)
563 559
 	{
564
-		static $utc=null;
560
+		static $utc = null;
565 561
 		if (!isset($utc)) $utc = new \DateTimeZone('UTC');
566 562
 
567
-		list($when) = explode('.', $_when);	// remove .0Z not understood by createFromFormat
563
+		list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat
568 564
 		$datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
569 565
 		if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
570 566
 
@@ -579,7 +575,7 @@  discard block
 block discarded – undo
579 575
 	 * @param array $old =null current data
580 576
 	 * @return int|false account_id or false on error
581 577
 	 */
582
-	protected function _save_group(array &$data, array $old=null)
578
+	protected function _save_group(array &$data, array $old = null)
583 579
 	{
584 580
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
585 581
 
@@ -590,7 +586,7 @@  discard block
 block discarded – undo
590 586
 				'account_description' => 'description',
591 587
 			);
592 588
 			$attributes = array();
593
-			foreach($new2adldap as $egw => $adldap)
589
+			foreach ($new2adldap as $egw => $adldap)
594 590
 			{
595 591
 				$attributes[$adldap] = (string)$data[$egw];
596 592
 			}
@@ -627,11 +623,11 @@  discard block
 block discarded – undo
627 623
 			'account_description' => 'description',
628 624
 		);
629 625
 		$ldap = array();
630
-		foreach($egw2adldap as $egw => $adldap)
626
+		foreach ($egw2adldap as $egw => $adldap)
631 627
 		{
632 628
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
633 629
 			{
634
-				switch($egw)
630
+				switch ($egw)
635 631
 				{
636 632
 					case 'account_description':
637 633
 						$ldap[$adldap] = !empty($data[$egw]) ? $data[$egw] : array();
@@ -644,7 +640,7 @@  discard block
 block discarded – undo
644 640
 			}
645 641
 		}
646 642
 		// attributes not (yet) suppored by adldap
647
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
643
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
648 644
 		{
649 645
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret));
650 646
 			return false;
@@ -660,7 +656,7 @@  discard block
 block discarded – undo
660 656
 	 * @param array $old =null current data
661 657
 	 * @return int|false account_id or false on error
662 658
 	 */
663
-	protected function _save_user(array &$data, array $old=null)
659
+	protected function _save_user(array &$data, array $old = null)
664 660
 	{
665 661
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
666 662
 		if (!isset($data['account_fullname']) && !empty($data['account_firstname']) && !empty($data['account_lastname']))
@@ -680,12 +676,12 @@  discard block
 block discarded – undo
680 676
 				'account_status'    => 'enabled',
681 677
 			);
682 678
 			$attributes = array();
683
-			foreach($new2adldap as $egw => $adldap)
679
+			foreach ($new2adldap as $egw => $adldap)
684 680
 			{
685 681
 				if ($egw == 'account_passwd' && (empty($data[$egw]) ||
686 682
 					!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()))
687 683
 				{
688
-					continue;	// do not try to set password, if no SSL or TLS, whole user creation will fail
684
+					continue; // do not try to set password, if no SSL or TLS, whole user creation will fail
689 685
 				}
690 686
 				if (isset($data[$egw])) $attributes[$adldap] = $data[$egw];
691 687
 			}
@@ -722,7 +718,7 @@  discard block
 block discarded – undo
722 718
 			'account_firstname' => 'firstname',
723 719
 			'account_lastname'  => 'surname',
724 720
 			'account_email'     => 'email',
725
-			'account_fullname'  => 'display_name',	// handeled currently in rename above, as not supported by adLDAP
721
+			'account_fullname'  => 'display_name', // handeled currently in rename above, as not supported by adLDAP
726 722
 			'account_passwd'    => 'password',
727 723
 			'account_status'    => 'enabled',
728 724
 			'account_primary_group' => 'primarygroupid',
@@ -735,7 +731,7 @@  discard block
 block discarded – undo
735 731
 		// for a new entry set certain values (eg. profilePath) to in setup configured value
736 732
 		if ($new_entry)
737 733
 		{
738
-			foreach($this->frontend->config as $name => $value)
734
+			foreach ($this->frontend->config as $name => $value)
739 735
 			{
740 736
 				if (substr($name, 0, 8) == 'ads_new_')
741 737
 				{
@@ -743,22 +739,22 @@  discard block
 block discarded – undo
743 739
 				}
744 740
 			}
745 741
 		}
746
-		foreach($egw2adldap as $egw => $adldap)
742
+		foreach ($egw2adldap as $egw => $adldap)
747 743
 		{
748 744
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
749 745
 			{
750
-				switch($egw)
746
+				switch ($egw)
751 747
 				{
752 748
 					case 'account_passwd':
753 749
 						if (!empty($data[$egw]) && ($this->adldap->getUseSSL() || $this->adldap->getUseTLS()))
754 750
 						{
755
-							$attributes[$adldap] = $data[$egw];	// only try to set password, if no SSL or TLS
751
+							$attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS
756 752
 						}
757 753
 						break;
758 754
 					case 'account_primary_group':
759 755
 						// setting a primary group seems to fail, if user is no member of that group
760 756
 						if (isset($old['memberships'][$data[$egw]]) ||
761
-							$this->adldap->group()->addUser($group=$this->id2name($data[$egw]), $data['account_id']))
757
+							$this->adldap->group()->addUser($group = $this->id2name($data[$egw]), $data['account_id']))
762 758
 						{
763 759
 							$old['memberships'][$data[$egw]] = $group;
764 760
 							$ldap[$adldap] = abs($data[$egw]);
@@ -769,11 +765,10 @@  discard block
 block discarded – undo
769 765
 						$ldap['userPrincipalName'] = $data[$egw].'@'.$this->frontend->config['ads_domain'];
770 766
 						break;
771 767
 					case 'account_expires':
772
-						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER :
773
-							self::convertUnixTimeToWindowsTime($data[$egw]);
768
+						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : self::convertUnixTimeToWindowsTime($data[$egw]);
774 769
 						break;
775 770
 					case 'account_status':
776
-						if ($new_entry && empty($data['account_passwd'])) continue;	// cant active new account without passwd!
771
+						if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd!
777 772
 						$attributes[$adldap] = $data[$egw] == 'A';
778 773
 						break;
779 774
 					case 'account_lastpwd_change':
@@ -795,7 +790,7 @@  discard block
 block discarded – undo
795 790
 		}
796 791
 		//elseif ($attributes) error_log(__METHOD__."(".array2string($data).") adldap->user()->modify('$data[account_lid]', ".array2string($attributes).') returned '.array2string($ret).' '.function_backtrace());
797 792
 		// attributes not (yet) suppored by adldap
798
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
793
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
799 794
 		{
800 795
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret).' ('.ldap_error($ds).') '.function_backtrace());
801 796
 			return false;
@@ -868,11 +863,11 @@  discard block
 block discarded – undo
868 863
 			$query = Api\Ldap::quote(strtolower($param['query']));
869 864
 
870 865
 			$accounts = array();
871
-			if($param['type'] !== 'groups')
866
+			if ($param['type'] !== 'groups')
872 867
 			{
873 868
 				if (!empty($query) && $query != '*')
874 869
 				{
875
-					switch($param['query_type'])
870
+					switch ($param['query_type'])
876 871
 					{
877 872
 						case 'all':
878 873
 						default:
@@ -903,14 +898,14 @@  discard block
 block discarded – undo
903 898
 					$membership_filter = '(|(memberOf='.$this->id2name((int)$param['type'], 'account_dn').')(PrimaryGroupId='.abs($param['type']).'))';
904 899
 					$filter = $filter ? "(&$membership_filter$filter)" : $membership_filter;
905 900
 				}
906
-				foreach($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
901
+				foreach ($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
907 902
 				{
908 903
 					$account = $this->_ldap2user($data);
909 904
 					if ($param['active'] && !$this->frontend->is_active($account))
910 905
 					{
911 906
 						continue;
912 907
 					}
913
-					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$account['account_id']);
908
+					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $account['account_id']);
914 909
 					$accounts[$account_id] = $account;
915 910
 				}
916 911
 			}
@@ -919,9 +914,9 @@  discard block
 block discarded – undo
919 914
 				$query = Api\Ldap::quote(strtolower($param['query']));
920 915
 
921 916
 				$filter = null;
922
-				if(!empty($query) && $query != '*')
917
+				if (!empty($query) && $query != '*')
923 918
 				{
924
-					switch($param['query_type'])
919
+					switch ($param['query_type'])
925 920
 					{
926 921
 						case 'all':
927 922
 						default:
@@ -935,23 +930,23 @@  discard block
 block discarded – undo
935 930
 					}
936 931
 					$filter = "(|(cn=$query)(description=$query))";
937 932
 				}
938
-				foreach($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
933
+				foreach ($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
939 934
 				{
940 935
 					$accounts[$account_id] = $this->_ldap2group($data);
941 936
 				}
942 937
 			}
943 938
 			// sort the array
944 939
 			$this->_callback_sort = strtoupper($param['sort']);
945
-			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
940
+			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']);
946 941
 			$sortedAccounts = $accounts;
947
-			uasort($sortedAccounts,array($this,'_sort_callback'));
942
+			uasort($sortedAccounts, array($this, '_sort_callback'));
948 943
 			$account_search[$unl_serial]['data'] = $sortedAccounts;
949 944
 
950 945
 			$account_search[$unl_serial]['total'] = $this->total = count($accounts);
951 946
 		}
952 947
 		// return only the wanted accounts
953 948
 		reset($sortedAccounts);
954
-		if(is_numeric($start) && is_numeric($offset))
949
+		if (is_numeric($start) && is_numeric($offset))
955 950
 		{
956 951
 			$account_search[$serial]['data'] = array_slice($sortedAccounts, $start, $offset);
957 952
 			$account_search[$serial]['total'] = $this->total;
@@ -982,19 +977,19 @@  discard block
 block discarded – undo
982 977
 	 * @param array $b
983 978
 	 * @return int
984 979
 	 */
985
-	protected function _sort_callback($a,$b)
980
+	protected function _sort_callback($a, $b)
986 981
 	{
987
-		foreach($this->_callback_order as $col )
982
+		foreach ($this->_callback_order as $col)
988 983
 		{
989
-			if($this->_callback_sort != 'DESC')
984
+			if ($this->_callback_sort != 'DESC')
990 985
 			{
991
-				$cmp = strcasecmp( $a[$col], $b[$col] );
986
+				$cmp = strcasecmp($a[$col], $b[$col]);
992 987
 			}
993 988
 			else
994 989
 			{
995
-				$cmp = strcasecmp( $b[$col], $a[$col] );
990
+				$cmp = strcasecmp($b[$col], $a[$col]);
996 991
 			}
997
-			if ( $cmp != 0 )
992
+			if ($cmp != 0)
998 993
 			{
999 994
 				return $cmp;
1000 995
 			}
@@ -1013,9 +1008,9 @@  discard block
 block discarded – undo
1013 1008
 	 * @param array $accounts =array() array to add filtered accounts too, default empty array
1014 1009
 	 * @return array account_id => account_lid or values for $attrs pairs
1015 1010
 	 */
1016
-	protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array())
1011
+	protected function filter($attr_filter, $account_type = null, array $attrs = null, array $accounts = array())
1017 1012
 	{
1018
-		switch($account_type)
1013
+		switch ($account_type)
1019 1014
 		{
1020 1015
 			case 'u':
1021 1016
 				$type_filter = '(samaccounttype='.adLDAP::ADLDAP_NORMAL_ACCOUNT.')';
@@ -1040,25 +1035,25 @@  discard block
 block discarded – undo
1040 1035
 			}
1041 1036
 			else
1042 1037
 			{
1043
-				foreach($attr_filter as $attr => $value)
1038
+				foreach ($attr_filter as $attr => $value)
1044 1039
 				{
1045 1040
 					$filter .= '('.$attr.'='.$this->adldap->utilities()->ldapSlashes($value).')';
1046 1041
 				}
1047 1042
 			}
1048 1043
 			$filter .= $type_filter.')';
1049 1044
 		}
1050
-		$sri = ldap_search($ds=$this->ldap_connection(), $context=$this->ads_context(), $filter,
1045
+		$sri = ldap_search($ds = $this->ldap_connection(), $context = $this->ads_context(), $filter,
1051 1046
 			$attrs ? $attrs : self::$default_attributes);
1052 1047
 		if (!$sri)
1053 1048
 		{
1054 1049
 			if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1055
-			$sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter,
1050
+			$sri = ldap_search($ds = $this->ldap_connection(true), $context = $this->ads_context(), $filter,
1056 1051
 				$attrs ? $attrs : self::$default_attributes);
1057 1052
 		}
1058 1053
 
1059 1054
 		if ($sri && ($allValues = ldap_get_entries($ds, $sri)))
1060 1055
 		{
1061
-			foreach($allValues as $key => $data)
1056
+			foreach ($allValues as $key => $data)
1062 1057
 			{
1063 1058
 				if ($key === 'count') continue;
1064 1059
 
@@ -1072,7 +1067,7 @@  discard block
 block discarded – undo
1072 1067
 
1073 1068
 				if ($data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT && $rid < self::MIN_ACCOUNT_ID)
1074 1069
 				{
1075
-					continue;	// ignore system accounts incl. "Administrator"
1070
+					continue; // ignore system accounts incl. "Administrator"
1076 1071
 				}
1077 1072
 				$accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] =
1078 1073
 					$attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
@@ -1096,7 +1091,7 @@  discard block
 block discarded – undo
1096 1091
 	 * @param string $account_type u = user, g = group, default null = try both
1097 1092
 	 * @return int|false numeric account_id or false on error ($name not found)
1098 1093
 	 */
1099
-	public function name2id($name, $which='account_lid', $account_type=null)
1094
+	public function name2id($name, $which = 'account_lid', $account_type = null)
1100 1095
 	{
1101 1096
 		static $to_ldap = array(
1102 1097
 			'account_lid'   => 'samaccountname',
@@ -1108,7 +1103,7 @@  discard block
 block discarded – undo
1108 1103
 		$ret = false;
1109 1104
 		if (isset($to_ldap[$which]))
1110 1105
 		{
1111
-			foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1106
+			foreach ($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1112 1107
 			{
1113 1108
 				unset($account_lid);
1114 1109
 				$ret = $account_id;
@@ -1128,9 +1123,9 @@  discard block
 block discarded – undo
1128 1123
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
1129 1124
 	 * @return string/false converted value or false on error ($account_id not found)
1130 1125
 	 */
1131
-	public function id2name($account_id, $which='account_lid')
1126
+	public function id2name($account_id, $which = 'account_lid')
1132 1127
 	{
1133
-		return $this->frontend->id2name($account_id,$which);
1128
+		return $this->frontend->id2name($account_id, $which);
1134 1129
 	}
1135 1130
 
1136 1131
 	/**
@@ -1142,9 +1137,9 @@  discard block
 block discarded – undo
1142 1137
 	 */
1143 1138
 	function update_lastlogin($_account_id, $ip)
1144 1139
 	{
1145
-		unset($_account_id, $ip);	// not used, but required by function signature
1140
+		unset($_account_id, $ip); // not used, but required by function signature
1146 1141
 
1147
-		return false;	// not longer supported
1142
+		return false; // not longer supported
1148 1143
 	}
1149 1144
 
1150 1145
 	/**
@@ -1184,21 +1179,21 @@  discard block
 block discarded – undo
1184 1179
 	 * @param int $account_id uidnumber
1185 1180
 	 * @return int number of added or removed memberships
1186 1181
 	 */
1187
-	function set_memberships($groups,$account_id)
1182
+	function set_memberships($groups, $account_id)
1188 1183
 	{
1189 1184
 		if (!($account = $this->id2name($account_id))) return;
1190 1185
 		$current = array_keys($this->memberships($account_id));
1191 1186
 
1192 1187
 		$changed = 0;
1193
-		foreach(array(
1194
-			'add' => array_diff($groups, $current),		// add account to all groups he is currently not in
1195
-			'remove' => array_diff($current, $groups),	// remove account from all groups he is only currently in
1188
+		foreach (array(
1189
+			'add' => array_diff($groups, $current), // add account to all groups he is currently not in
1190
+			'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in
1196 1191
 		) as $op => $memberships)
1197 1192
 		{
1198 1193
 			$func = $op.($account_id > 0 ? 'User' : 'Group');
1199
-			foreach($memberships as $gid)
1194
+			foreach ($memberships as $gid)
1200 1195
 			{
1201
-				$ok = $this->adldap->group()->$func($group=$this->id2name($gid), $account);
1196
+				$ok = $this->adldap->group()->$func($group = $this->id2name($gid), $account);
1202 1197
 				//error_log(__METHOD__.'('.array2string($groups).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1203 1198
 				$changed += (int)$ok;
1204 1199
 			}
@@ -1220,15 +1215,15 @@  discard block
 block discarded – undo
1220 1215
 		$current = array_keys($this->members($gid));
1221 1216
 
1222 1217
 		$changed = 0;
1223
-		foreach(array(
1224
-			'add' => array_diff($users, $current),	// add members currently not in
1225
-			'remove' => array_diff($current, $users),	// remove members only currently in
1218
+		foreach (array(
1219
+			'add' => array_diff($users, $current), // add members currently not in
1220
+			'remove' => array_diff($current, $users), // remove members only currently in
1226 1221
 		) as $op => $members)
1227 1222
 		{
1228
-			foreach($members as $account_id)
1223
+			foreach ($members as $account_id)
1229 1224
 			{
1230 1225
 				$func = $op.($account_id > 0 ? 'User' : 'Group');
1231
-				$ok = $this->adldap->group()->$func($group, $account=$this->id2name($account_id));
1226
+				$ok = $this->adldap->group()->$func($group, $account = $this->id2name($account_id));
1232 1227
 				//error_log(__METHOD__.'('.array2string($users).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1233 1228
 				$changed += (int)$ok;
1234 1229
 			}
@@ -1253,7 +1248,7 @@  discard block
 block discarded – undo
1253 1248
 	 */
1254 1249
 	public $charset = 'iso-8859-1';
1255 1250
 
1256
-	function __construct(array $options=array())
1251
+	function __construct(array $options = array())
1257 1252
 	{
1258 1253
 		if (isset($options['charset']))
1259 1254
 		{
@@ -1340,19 +1335,19 @@  discard block
 block discarded – undo
1340 1335
 	public function create($attributes)
1341 1336
 	{
1342 1337
 		// Check for compulsory fields
1343
-		if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; }
1344
-		if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; }
1345
-		if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; }
1346
-		if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; }
1347
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1348
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1349
-
1350
-		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){
1338
+		if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; }
1339
+		if (!array_key_exists("firstname", $attributes)) { return "Missing compulsory field [firstname]"; }
1340
+		if (!array_key_exists("surname", $attributes)) { return "Missing compulsory field [surname]"; }
1341
+		if (!array_key_exists("email", $attributes)) { return "Missing compulsory field [email]"; }
1342
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1343
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1344
+
1345
+		if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) {
1351 1346
 			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1352 1347
 		}
1353 1348
 
1354 1349
 		if (!array_key_exists("display_name", $attributes)) {
1355
-			$attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"];
1350
+			$attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"];
1356 1351
 		}
1357 1352
 
1358 1353
 		// Translate the schema
@@ -1375,20 +1370,20 @@  discard block
 block discarded – undo
1375 1370
 		// Determine the container
1376 1371
 		if (is_array($attributes['container'])) {
1377 1372
 			$attributes["container"] = array_reverse($attributes["container"]);
1378
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1373
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1379 1374
 		}
1380 1375
 		// we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2
1381 1376
 		unset($add['unicodePwd']);
1382 1377
 
1383 1378
 		// Add the entry
1384
-		$result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1379
+		$result = ldap_add($ds = $this->adldap->getLdapConnection(), $dn = "CN=".$add["cn"][0].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1385 1380
 		if ($result != true) {
1386 1381
 			error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1387 1382
 			return false;
1388 1383
 		}
1389 1384
 
1390 1385
 		// now password can be added to still disabled account
1391
-		if (array_key_exists("password",$attributes))
1386
+		if (array_key_exists("password", $attributes))
1392 1387
 		{
1393 1388
 			if (!$this->setPassword($dn, $attributes['password'])) return false;
1394 1389
 
@@ -1415,13 +1410,13 @@  discard block
 block discarded – undo
1415 1410
     */
1416 1411
     public function encodePassword($password)
1417 1412
     {
1418
-        $password="\"".$password."\"";
1413
+        $password = "\"".$password."\"";
1419 1414
         if (function_exists('mb_convert_encoding'))
1420 1415
         {
1421 1416
             return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422 1417
         }
1423
-        $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1418
+        $encoded = "";
1419
+        for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; }
1425 1420
         return $encoded;
1426 1421
     }
1427 1422
 
@@ -1438,7 +1433,7 @@  discard block
 block discarded – undo
1438 1433
      */
1439 1434
     public function setPassword($dn, $password)
1440 1435
     {
1441
-    	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1436
+    	$result = ldap_mod_replace($ds = $this->adldap->getLdapConnection(), $dn, array(
1442 1437
     		'unicodePwd' => $this->encodePassword($password),
1443 1438
     	));
1444 1439
     	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
@@ -1466,7 +1461,7 @@  discard block
 block discarded – undo
1466 1461
 	* @param string $old_password old password for password change, if supported
1467 1462
     * @return bool
1468 1463
     */
1469
-    public function password($username, $password, $isGUID = false, $old_password=null)
1464
+    public function password($username, $password, $isGUID = false, $old_password = null)
1470 1465
     {
1471 1466
         if ($username === NULL) { return false; }
1472 1467
         if ($password === NULL) { return false; }
@@ -1480,7 +1475,7 @@  discard block
 block discarded – undo
1480 1475
             return false;
1481 1476
         }
1482 1477
 
1483
-        $add=array();
1478
+        $add = array();
1484 1479
 
1485 1480
 		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1486 1481
 			$add["unicodePwd"][0] = $this->encodePassword($password);
@@ -1502,11 +1497,11 @@  discard block
 block discarded – undo
1502 1497
 			);
1503 1498
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1499
 		}
1505
-        if ($result === false){
1500
+        if ($result === false) {
1506 1501
             $err = ldap_errno($this->adldap->getLdapConnection());
1507 1502
             if ($err) {
1508
-                $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1503
+                $msg = 'Error '.$err.': '.ldap_err2str($err).'.';
1504
+                if ($err == 53) {
1510 1505
                     $msg .= ' Your password might not match the password policy.';
1511 1506
                 }
1512 1507
                 throw new adLDAPException($msg);
@@ -1544,13 +1539,13 @@  discard block
 block discarded – undo
1544 1539
         $mod = $this->adldap->adldap_schema($attributes);
1545 1540
 
1546 1541
         // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1542
+        if (!$mod && !array_key_exists("enabled", $attributes)) {
1548 1543
             return false;
1549 1544
         }
1550 1545
 
1551 1546
         // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1547
+        if (array_key_exists("enabled", $attributes)) {
1548
+            if ($attributes["enabled"]) {
1554 1549
                 $controlOptions = array("NORMAL_ACCOUNT");
1555 1550
             }
1556 1551
             else {
@@ -1564,14 +1559,14 @@  discard block
 block discarded – undo
1564 1559
 		if ($mod)
1565 1560
 		{
1566 1561
 	        // Do the update
1567
-	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1562
+	        $result = @ldap_modify($ds = $this->adldap->getLdapConnection(), $userDn, $mod);
1568 1563
 	        if ($result == false) {
1569 1564
 				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1570 1565
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571 1566
 	        	return false;
1572 1567
 	        }
1573 1568
 		}
1574
-        if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1569
+        if (array_key_exists("password", $attributes) && !$this->setPassword($userDn, $attributes['password']))
1575 1570
 		{
1576 1571
 			return false;
1577 1572
 		}
@@ -1594,10 +1589,10 @@  discard block
 block discarded – undo
1594 1589
 	 */
1595 1590
 	public function create($attributes)
1596 1591
 	{
1597
-		if (!is_array($attributes)){ return "Attributes must be an array"; }
1598
-		if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; }
1599
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1600
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1592
+		if (!is_array($attributes)) { return "Attributes must be an array"; }
1593
+		if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; }
1594
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1595
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1601 1596
 
1602 1597
 		//$member_array = array();
1603 1598
 		//$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com";
@@ -1613,9 +1608,9 @@  discard block
 block discarded – undo
1613 1608
 		// Determine the container
1614 1609
 		if (is_array($attributes['container'])) {
1615 1610
 			$attributes["container"] = array_reverse($attributes["container"]);
1616
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1611
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1617 1612
 		}
1618
-		$result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1613
+		$result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1619 1614
 		if ($result != true) {
1620 1615
 			return false;
1621 1616
 		}
@@ -1646,10 +1641,10 @@  discard block
 block discarded – undo
1646 1641
     * @author Port by Andreas Gohr <[email protected]>
1647 1642
     * @return string
1648 1643
     */
1649
-    public function ldapSlashes($str){
1644
+    public function ldapSlashes($str) {
1650 1645
         return preg_replace_callback(
1651 1646
       		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1647
+        	function($matches) {
1653 1648
             	return "\\".join("", unpack("H2", $matches[1]));
1654 1649
         	},
1655 1650
         	$str
Please login to merge, or discard this patch.
api/src/Accounts/Sql.php 2 patches
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -198,38 +198,38 @@  discard block
 block discarded – undo
198 198
 		if ($data['account_passwd'])
199 199
 		{
200 200
 			// if password it's not already entcrypted, do so now
201
-			if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']) &&
202
-				!preg_match('/^[0-9a-f]{32}$/',$data['account_passwd']))	// md5 hash
201
+			if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd']) &&
202
+				!preg_match('/^[0-9a-f]{32}$/', $data['account_passwd']))	// md5 hash
203 203
 			{
204 204
 				$data['account_passwd'] = Api\Auth::encrypt_sql($data['account_passwd']);
205 205
 			}
206 206
 			$to_write['account_pwd'] = $data['account_passwd'];
207 207
 			$to_write['account_lastpwd_change'] = time();
208 208
 		}
209
-		if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change']=0;
209
+		if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change'] = 0;
210 210
 		if (!(int)$data['account_id'] || !$this->id2name($data['account_id']))
211 211
 		{
212 212
 			if ($to_write['account_id'] < 0) $to_write['account_id'] *= -1;
213 213
 
214
-			if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = '';	// is NOT NULL!
215
-			if (!isset($to_write['account_status'])) $to_write['account_status'] = '';	// is NOT NULL!
214
+			if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = ''; // is NOT NULL!
215
+			if (!isset($to_write['account_status'])) $to_write['account_status'] = ''; // is NOT NULL!
216 216
 
217 217
 			// postgres requires the auto-id field to be unset!
218 218
 			if (isset($to_write['account_id']) && !$to_write['account_id']) unset($to_write['account_id']);
219 219
 
220
-			if (!in_array($to_write['account_type'],array('u','g')) ||
221
-				!$this->db->insert($this->table,$to_write,false,__LINE__,__FILE__)) return false;
220
+			if (!in_array($to_write['account_type'], array('u', 'g')) ||
221
+				!$this->db->insert($this->table, $to_write, false, __LINE__, __FILE__)) return false;
222 222
 
223 223
 			if (!(int)$data['account_id'])
224 224
 			{
225
-				$data['account_id'] = $this->db->get_last_insert_id($this->table,'account_id');
225
+				$data['account_id'] = $this->db->get_last_insert_id($this->table, 'account_id');
226 226
 				if ($data['account_type'] == 'g') $data['account_id'] *= -1;
227 227
 			}
228 228
 		}
229 229
 		else	// update of existing account
230 230
 		{
231 231
 			unset($to_write['account_id']);
232
-			if (!$this->db->update($this->table,$to_write,array('account_id' => abs($data['account_id'])),__LINE__,__FILE__))
232
+			if (!$this->db->update($this->table, $to_write, array('account_id' => abs($data['account_id'])), __LINE__, __FILE__))
233 233
 			{
234 234
 				return false;
235 235
 			}
@@ -278,16 +278,16 @@  discard block
 block discarded – undo
278 278
 	{
279 279
 		if (!(int)$account_id) return false;
280 280
 
281
-		$contact_id = $this->id2name($account_id,'person_id');
281
+		$contact_id = $this->id2name($account_id, 'person_id');
282 282
 
283
-		if (!$this->db->delete($this->table,array('account_id' => abs($account_id)),__LINE__,__FILE__))
283
+		if (!$this->db->delete($this->table, array('account_id' => abs($account_id)), __LINE__, __FILE__))
284 284
 		{
285 285
 			return false;
286 286
 		}
287 287
 		if ($contact_id)
288 288
 		{
289 289
 			if (!isset($this->contacts)) $this->contacts = new Api\Contacts();
290
-			$this->contacts->delete($contact_id,false);	// false = allow to delete accounts (!)
290
+			$this->contacts->delete($contact_id, false); // false = allow to delete accounts (!)
291 291
 		}
292 292
 		return true;
293 293
 	}
@@ -303,11 +303,11 @@  discard block
 block discarded – undo
303 303
 		if (!(int)$account_id) return false;
304 304
 
305 305
 		$memberships = array();
306
-		if(($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id)))
306
+		if (($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id)))
307 307
 		{
308
-			foreach($gids as $gid)
308
+			foreach ($gids as $gid)
309 309
 			{
310
-				$memberships[(string) $gid] = $this->id2name($gid);
310
+				$memberships[(string)$gid] = $this->id2name($gid);
311 311
 			}
312 312
 		}
313 313
 		return $memberships;
@@ -319,17 +319,17 @@  discard block
 block discarded – undo
319 319
 	 * @param array $groups array with gidnumbers
320 320
 	 * @param int $account_id numerical account-id
321 321
 	 */
322
-	function set_memberships($groups,$account_id)
322
+	function set_memberships($groups, $account_id)
323 323
 	{
324 324
 		if (!(int)$account_id) return;
325 325
 
326 326
 		$acl = new Api\Acl($account_id);
327 327
 		$acl->read_repository();
328
-		$acl->delete('phpgw_group',false);
328
+		$acl->delete('phpgw_group', false);
329 329
 
330
-		foreach($groups as $group)
330
+		foreach ($groups as $group)
331 331
 		{
332
-			$acl->add('phpgw_group',$group,1);
332
+			$acl->add('phpgw_group', $group, 1);
333 333
 		}
334 334
 		$acl->save_repository();
335 335
 	}
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 		if (!is_numeric($account_id)) $account_id = $this->name2id($account_id);
346 346
 
347 347
 		$members = array();
348
-		foreach($this->db->select($this->table, 'account_id,account_lid',
348
+		foreach ($this->db->select($this->table, 'account_id,account_lid',
349 349
 			$this->db->expression(Api\Acl::TABLE, array(
350 350
 				'acl_appname'  => 'phpgw_group',
351 351
 				'acl_location' => $account_id,
@@ -364,15 +364,15 @@  discard block
 block discarded – undo
364 364
 	 * @param array $members array with uidnumber or uid's
365 365
 	 * @param int $gid gidnumber of group to set
366 366
 	 */
367
-	function set_members($members,$gid)
367
+	function set_members($members, $gid)
368 368
 	{
369
-		$GLOBALS['egw']->acl->delete_repository('phpgw_group',$gid,false);
369
+		$GLOBALS['egw']->acl->delete_repository('phpgw_group', $gid, false);
370 370
 
371 371
 		if (is_array($members))
372 372
 		{
373
-			foreach($members as $id)
373
+			foreach ($members as $id)
374 374
 			{
375
-				$GLOBALS['egw']->acl->add_repository('phpgw_group',$gid,$id,1);
375
+				$GLOBALS['egw']->acl->add_repository('phpgw_group', $gid, $id, 1);
376 376
 			}
377 377
 		}
378 378
 	}
@@ -407,20 +407,20 @@  discard block
 block discarded – undo
407 407
 		);
408 408
 
409 409
 		// fetch order of account_fullname from Api\Accounts::format_username
410
-		if (strpos($param['order'],'account_fullname') !== false)
410
+		if (strpos($param['order'], 'account_fullname') !== false)
411 411
 		{
412
-			$param['order'] = str_replace('account_fullname', preg_replace('/[ ,]+/',',',str_replace(array('[',']'),'',
413
-				Api\Accounts::format_username('account_lid','account_firstname','account_lastname'))), $param['order']);
412
+			$param['order'] = str_replace('account_fullname', preg_replace('/[ ,]+/', ',', str_replace(array('[', ']'), '',
413
+				Api\Accounts::format_username('account_lid', 'account_firstname', 'account_lastname'))), $param['order']);
414 414
 		}
415
-		$order = str_replace(array_keys($order2contact),array_values($order2contact),$param['order']);
415
+		$order = str_replace(array_keys($order2contact), array_values($order2contact), $param['order']);
416 416
 		// allways add 'account_lid', as it is only valid one for groups
417 417
 		if (strpos($order, 'account_lid') === false)
418 418
 		{
419
-			$order .= ($order?',':'').'account_lid';
419
+			$order .= ($order ? ',' : '').'account_lid';
420 420
 		}
421 421
 		if ($param['sort']) $order = implode(' '.$param['sort'].',', explode(',', $order)).' '.$param['sort'];
422 422
 
423
-		$search_cols = array('account_lid','n_family','n_given','email');
423
+		$search_cols = array('account_lid', 'n_family', 'n_given', 'email');
424 424
 		$join = $this->contacts_join;
425 425
 		$email_cols = array('email');
426 426
 
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 		}
437 437
 
438 438
 		$filter = array();
439
-		switch($param['type'])
439
+		switch ($param['type'])
440 440
 		{
441 441
 			case 'accounts':
442 442
 				$filter['owner'] = 0;
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 			case 'groupmembers':
452 452
 			case 'groupmembers+memberships':
453 453
 				$members = array();
454
-				foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp => $name)
454
+				foreach ((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp => $name)
455 455
 				{
456 456
 					unset($name);
457 457
 					$members = array_unique(array_merge($members, array_keys((array)$this->members($grp))));
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
 		}
487 487
 		if ($param['active'])
488 488
 		{
489
-			$filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),Api\Contacts\Sql::ACOUNT_ACTIVE_FILTER);
489
+			$filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), Api\Contacts\Sql::ACOUNT_ACTIVE_FILTER);
490 490
 		}
491 491
 		$criteria = array();
492 492
 		$wildcard = $param['query_type'] == 'start' || $param['query_type'] == 'exact' ? '' : '%';
493 493
 		if (($query = $param['query']))
494 494
 		{
495
-			switch($param['query_type'])
495
+			switch ($param['query_type'])
496 496
 			{
497 497
 				case 'start':
498 498
 					$query .= '*';
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 				case 'all':
501 501
 				default:
502 502
 				case 'exact':
503
-					foreach($search_cols as $col)
503
+					foreach ($search_cols as $col)
504 504
 					{
505 505
 						$criteria[$col] = $query;
506 506
 					}
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 				case 'email':
522 522
 					$criteria['email'] = $query;
523 523
 					// Group email
524
-					if(in_array(Api\Mail\Smtp\Sql::TABLE, $this->db->table_names(true)))
524
+					if (in_array(Api\Mail\Smtp\Sql::TABLE, $this->db->table_names(true)))
525 525
 					{
526 526
 						$criteria[Api\Mail\Smtp\Sql::TABLE.'.mail_value'] = $query;
527 527
 					}
@@ -531,12 +531,12 @@  discard block
 block discarded – undo
531 531
 		if (!isset($this->contacts)) $this->contacts = new Api\Contacts();
532 532
 
533 533
 		$accounts = array();
534
-		foreach((array) $this->contacts->search($criteria,
535
-			array_merge(array(1,'n_given','n_family','id','created','modified',$this->table.'.account_id AS account_id'),$email_cols),
536
-			$order,"account_lid,account_type,account_status,account_expires,account_primary_group,account_description",
537
-			$wildcard,false,$query[0] == '!' ? 'AND' : 'OR',
534
+		foreach ((array)$this->contacts->search($criteria,
535
+			array_merge(array(1, 'n_given', 'n_family', 'id', 'created', 'modified', $this->table.'.account_id AS account_id'), $email_cols),
536
+			$order, "account_lid,account_type,account_status,account_expires,account_primary_group,account_description",
537
+			$wildcard, false, $query[0] == '!' ? 'AND' : 'OR',
538 538
 			$param['offset'] ? array($param['start'], $param['offset']) : (is_null($param['start']) ? false : $param['start']),
539
-			$filter,$join) as $contact)
539
+			$filter, $join) as $contact)
540 540
 		{
541 541
 			if ($contact)
542 542
 			{
@@ -576,13 +576,13 @@  discard block
 block discarded – undo
576 576
 	 * @param string $account_type u = user, g = group, default null = try both
577 577
 	 * @return int/false numeric account_id or false on error ($name not found)
578 578
 	 */
579
-	function name2id($name,$which='account_lid',$account_type=null)
579
+	function name2id($name, $which = 'account_lid', $account_type = null)
580 580
 	{
581 581
 		if ($account_type === 'g' && $which != 'account_lid') return false;
582 582
 
583 583
 		$where = array();
584 584
 		$cols = 'account_id';
585
-		switch($which)
585
+		switch ($which)
586 586
 		{
587 587
 			case 'account_fullname':
588 588
 				$table = $this->contacts_table;
@@ -613,11 +613,11 @@  discard block
 block discarded – undo
613 613
 		}
614 614
 		else
615 615
 		{
616
-			$where[] = 'account_id IS NOT NULL'.	// otherwise contacts with eg. the same email hide the accounts!
617
-				($table == $this->contacts_table ? " AND contact_tid != 'D'" : '');	// ignore deleted accounts contact-data
616
+			$where[] = 'account_id IS NOT NULL'.// otherwise contacts with eg. the same email hide the accounts!
617
+				($table == $this->contacts_table ? " AND contact_tid != 'D'" : ''); // ignore deleted accounts contact-data
618 618
 
619 619
 		}
620
-		if (!($rs = $this->db->select($table,$cols,$where,__LINE__,__FILE__)) || !($row = $rs->fetch()))
620
+		if (!($rs = $this->db->select($table, $cols, $where, __LINE__, __FILE__)) || !($row = $rs->fetch()))
621 621
 		{
622 622
 			//error_log(__METHOD__."('$name', '$which', ".array2string($account_type).") db->select('$table', '$cols', ".array2string($where).") returned ".array2string($rs).' '.function_backtrace());
623 623
 			return false;
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
635 635
 	 * @return string/false converted value or false on error ($account_id not found)
636 636
 	 */
637
-	function id2name($account_id,$which='account_lid')
637
+	function id2name($account_id, $which = 'account_lid')
638 638
 	{
639
-		return $this->frontend->id2name($account_id,$which);
639
+		return $this->frontend->id2name($account_id, $which);
640 640
 	}
641 641
 
642 642
 	/**
@@ -648,14 +648,14 @@  discard block
 block discarded – undo
648 648
 	 */
649 649
 	function update_lastlogin($account_id, $ip)
650 650
 	{
651
-		$previous_login = $this->db->select($this->table,'account_lastlogin',array('account_id'=>abs($account_id)),__LINE__,__FILE__)->fetchColumn();
651
+		$previous_login = $this->db->select($this->table, 'account_lastlogin', array('account_id'=>abs($account_id)), __LINE__, __FILE__)->fetchColumn();
652 652
 
653
-		$this->db->update($this->table,array(
653
+		$this->db->update($this->table, array(
654 654
 			'account_lastloginfrom' => $ip,
655 655
 			'account_lastlogin'     => time(),
656
-		),array(
656
+		), array(
657 657
 			'account_id' => abs($account_id),
658
-		),__LINE__,__FILE__);
658
+		), __LINE__, __FILE__);
659 659
 
660 660
 		return $previous_login;
661 661
 	}
Please login to merge, or discard this patch.
Braces   +94 added lines, -23 removed lines patch added patch discarded remove patch
@@ -122,7 +122,10 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	function read($account_id)
124 124
 	{
125
-		if (!(int)$account_id) return false;
125
+		if (!(int)$account_id)
126
+		{
127
+			return false;
128
+		}
126 129
 
127 130
 		if ($account_id > 0)
128 131
 		{
@@ -152,11 +155,14 @@  discard block
 block discarded – undo
152 155
 			unset($e);
153 156
 		}
154 157
 
155
-		if (!$rs)	// handle not (yet) existing mailaccounts table
158
+		if (!$rs)
159
+		{
160
+			// handle not (yet) existing mailaccounts table
156 161
 		{
157 162
 			$rs = $this->db->select($this->table, $this->table.'.*',
158 163
 				$this->table.'.account_id='.abs($account_id), __LINE__, __FILE__);
159 164
 		}
165
+		}
160 166
 		if (!$rs || !($data = $rs->fetch()))
161 167
 		{
162 168
 			return false;
@@ -166,7 +172,10 @@  discard block
 block discarded – undo
166 172
 			$data['account_id'] = -$data['account_id'];
167 173
 			$data['mailAllowed'] = true;
168 174
 		}
169
-		if (!$data['account_firstname']) $data['account_firstname'] = $data['account_lid'];
175
+		if (!$data['account_firstname'])
176
+		{
177
+			$data['account_firstname'] = $data['account_lid'];
178
+		}
170 179
 		if (!$data['account_lastname'])
171 180
 		{
172 181
 			$data['account_lastname'] = $data['account_type'] == 'g' ? 'Group' : 'User';
@@ -177,7 +186,10 @@  discard block
 block discarded – undo
177 186
 				$data['account_lastname'] = lang($data['account_lastname']);
178 187
 			}
179 188
 		}
180
-		if (!$data['account_fullname']) $data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname'];
189
+		if (!$data['account_fullname'])
190
+		{
191
+			$data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname'];
192
+		}
181 193
 
182 194
 		return $data;
183 195
 	}
@@ -199,31 +211,57 @@  discard block
 block discarded – undo
199 211
 		{
200 212
 			// if password it's not already entcrypted, do so now
201 213
 			if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']) &&
202
-				!preg_match('/^[0-9a-f]{32}$/',$data['account_passwd']))	// md5 hash
214
+				!preg_match('/^[0-9a-f]{32}$/',$data['account_passwd']))
215
+			{
216
+				// md5 hash
203 217
 			{
204 218
 				$data['account_passwd'] = Api\Auth::encrypt_sql($data['account_passwd']);
205 219
 			}
220
+			}
206 221
 			$to_write['account_pwd'] = $data['account_passwd'];
207 222
 			$to_write['account_lastpwd_change'] = time();
208 223
 		}
209
-		if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change']=0;
224
+		if ($data['mustchangepassword'] == 1)
225
+		{
226
+			$to_write['account_lastpwd_change']=0;
227
+		}
210 228
 		if (!(int)$data['account_id'] || !$this->id2name($data['account_id']))
211 229
 		{
212
-			if ($to_write['account_id'] < 0) $to_write['account_id'] *= -1;
230
+			if ($to_write['account_id'] < 0)
231
+			{
232
+				$to_write['account_id'] *= -1;
233
+			}
213 234
 
214
-			if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = '';	// is NOT NULL!
215
-			if (!isset($to_write['account_status'])) $to_write['account_status'] = '';	// is NOT NULL!
235
+			if (!isset($to_write['account_pwd']))
236
+			{
237
+				$to_write['account_pwd'] = '';
238
+			}
239
+			// is NOT NULL!
240
+			if (!isset($to_write['account_status']))
241
+			{
242
+				$to_write['account_status'] = '';
243
+			}
244
+			// is NOT NULL!
216 245
 
217 246
 			// postgres requires the auto-id field to be unset!
218
-			if (isset($to_write['account_id']) && !$to_write['account_id']) unset($to_write['account_id']);
247
+			if (isset($to_write['account_id']) && !$to_write['account_id'])
248
+			{
249
+				unset($to_write['account_id']);
250
+			}
219 251
 
220 252
 			if (!in_array($to_write['account_type'],array('u','g')) ||
221
-				!$this->db->insert($this->table,$to_write,false,__LINE__,__FILE__)) return false;
253
+				!$this->db->insert($this->table,$to_write,false,__LINE__,__FILE__))
254
+			{
255
+				return false;
256
+			}
222 257
 
223 258
 			if (!(int)$data['account_id'])
224 259
 			{
225 260
 				$data['account_id'] = $this->db->get_last_insert_id($this->table,'account_id');
226
-				if ($data['account_type'] == 'g') $data['account_id'] *= -1;
261
+				if ($data['account_type'] == 'g')
262
+				{
263
+					$data['account_id'] *= -1;
264
+				}
227 265
 			}
228 266
 		}
229 267
 		else	// update of existing account
@@ -276,7 +314,10 @@  discard block
 block discarded – undo
276 314
 	 */
277 315
 	function delete($account_id)
278 316
 	{
279
-		if (!(int)$account_id) return false;
317
+		if (!(int)$account_id)
318
+		{
319
+			return false;
320
+		}
280 321
 
281 322
 		$contact_id = $this->id2name($account_id,'person_id');
282 323
 
@@ -286,7 +327,10 @@  discard block
 block discarded – undo
286 327
 		}
287 328
 		if ($contact_id)
288 329
 		{
289
-			if (!isset($this->contacts)) $this->contacts = new Api\Contacts();
330
+			if (!isset($this->contacts))
331
+			{
332
+				$this->contacts = new Api\Contacts();
333
+			}
290 334
 			$this->contacts->delete($contact_id,false);	// false = allow to delete accounts (!)
291 335
 		}
292 336
 		return true;
@@ -300,7 +344,10 @@  discard block
 block discarded – undo
300 344
 	 */
301 345
 	function memberships($account_id)
302 346
 	{
303
-		if (!(int)$account_id) return false;
347
+		if (!(int)$account_id)
348
+		{
349
+			return false;
350
+		}
304 351
 
305 352
 		$memberships = array();
306 353
 		if(($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id)))
@@ -321,7 +368,10 @@  discard block
 block discarded – undo
321 368
 	 */
322 369
 	function set_memberships($groups,$account_id)
323 370
 	{
324
-		if (!(int)$account_id) return;
371
+		if (!(int)$account_id)
372
+		{
373
+			return;
374
+		}
325 375
 
326 376
 		$acl = new Api\Acl($account_id);
327 377
 		$acl->read_repository();
@@ -342,7 +392,10 @@  discard block
 block discarded – undo
342 392
 	 */
343 393
 	function members($account_id)
344 394
 	{
345
-		if (!is_numeric($account_id)) $account_id = $this->name2id($account_id);
395
+		if (!is_numeric($account_id))
396
+		{
397
+			$account_id = $this->name2id($account_id);
398
+		}
346 399
 
347 400
 		$members = array();
348 401
 		foreach($this->db->select($this->table, 'account_id,account_lid',
@@ -418,7 +471,10 @@  discard block
 block discarded – undo
418 471
 		{
419 472
 			$order .= ($order?',':'').'account_lid';
420 473
 		}
421
-		if ($param['sort']) $order = implode(' '.$param['sort'].',', explode(',', $order)).' '.$param['sort'];
474
+		if ($param['sort'])
475
+		{
476
+			$order = implode(' '.$param['sort'].',', explode(',', $order)).' '.$param['sort'];
477
+		}
422 478
 
423 479
 		$search_cols = array('account_lid','n_family','n_given','email');
424 480
 		$join = $this->contacts_join;
@@ -455,7 +511,10 @@  discard block
 block discarded – undo
455 511
 				{
456 512
 					unset($name);
457 513
 					$members = array_unique(array_merge($members, array_keys((array)$this->members($grp))));
458
-					if ($param['type'] == 'groupmembers+memberships') $members[] = abs($grp);
514
+					if ($param['type'] == 'groupmembers+memberships')
515
+					{
516
+						$members[] = abs($grp);
517
+					}
459 518
 				}
460 519
 				$filter['account_id'] = $members;
461 520
 				break;
@@ -474,9 +533,12 @@  discard block
 block discarded – undo
474 533
 		// fix ambigous account_id (used in accounts and contacts table)
475 534
 		if (array_key_exists('account_id', $filter))
476 535
 		{
477
-			if (!$filter['account_id'])	// eg. group without members (would give SQL error)
536
+			if (!$filter['account_id'])
537
+			{
538
+				// eg. group without members (would give SQL error)
478 539
 			{
479 540
 				$this->total = 0;
541
+			}
480 542
 				return array();
481 543
 			}
482 544
 			$filter[] = $this->db->expression($this->table, $this->table.'.', array(
@@ -528,7 +590,10 @@  discard block
 block discarded – undo
528 590
 					break;
529 591
 			}
530 592
 		}
531
-		if (!isset($this->contacts)) $this->contacts = new Api\Contacts();
593
+		if (!isset($this->contacts))
594
+		{
595
+			$this->contacts = new Api\Contacts();
596
+		}
532 597
 
533 598
 		$accounts = array();
534 599
 		foreach((array) $this->contacts->search($criteria,
@@ -578,7 +643,10 @@  discard block
 block discarded – undo
578 643
 	 */
579 644
 	function name2id($name,$which='account_lid',$account_type=null)
580 645
 	{
581
-		if ($account_type === 'g' && $which != 'account_lid') return false;
646
+		if ($account_type === 'g' && $which != 'account_lid')
647
+		{
648
+			return false;
649
+		}
582 650
 
583 651
 		$where = array();
584 652
 		$cols = 'account_id';
@@ -601,9 +669,12 @@  discard block
 block discarded – undo
601 669
 				$cols .= ',account_type';
602 670
 				$where[$which] = $name;
603 671
 				// check if we need to treat username case-insensitive
604
-				if ($which == 'account_lid' && !$GLOBALS['egw_info']['server']['case_sensitive_username'])	// = is case sensitiv eg. on postgres, but not on mysql!
672
+				if ($which == 'account_lid' && !$GLOBALS['egw_info']['server']['case_sensitive_username'])
673
+				{
674
+					// = is case sensitiv eg. on postgres, but not on mysql!
605 675
 				{
606 676
 					$where[] = 'account_lid '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($where['account_lid']);
677
+				}
607 678
 					unset($where['account_lid']);
608 679
 				}
609 680
 		}
Please login to merge, or discard this patch.
api/src/Cache/Memcache.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -54,26 +54,26 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
175 175
 	 */
176 176
 	private function key(array $keys)
177 177
 	{
178
-		return implode('::',$keys);
178
+		return implode('::', $keys);
179 179
 	}
180 180
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,11 @@
 block discarded – undo
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)
Please login to merge, or discard this patch.
api/src/Cache/Base.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +52 added lines, -13 removed lines patch added patch discarded remove patch
@@ -49,18 +49,27 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 			}
Please login to merge, or discard this patch.
api/src/Cache/Provider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
api/src/Country.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
Braces   +21 added lines, -5 removed lines patch added patch discarded remove patch
@@ -368,7 +368,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
api/src/Auth/Fallbackmail2sql.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 	/**
23 23
 	 * Constructor
24 24
 	 */
25
-	function __construct($primary='mail', $fallback='sql')
25
+	function __construct($primary = 'mail', $fallback = 'sql')
26 26
 	{
27 27
 		parent::__construct($primary, $fallback);
28 28
 	}
Please login to merge, or discard this patch.
api/src/Auth/Nis.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,22 +26,22 @@  discard block
 block discarded – undo
26 26
 	 * @param string $passwd_type ='text' 'text' for cleartext passwords (default)
27 27
 	 * @return boolean true if successful authenticated, false otherwise
28 28
 	 */
29
-	function authenticate($username, $passwd, $passwd_type='text')
29
+	function authenticate($username, $passwd, $passwd_type = 'text')
30 30
 	{
31
-		unset($passwd_type);	// not used but required by interface
31
+		unset($passwd_type); // not used but required by interface
32 32
 
33 33
 		$domain = yp_get_default_domain();
34
-		if(!empty($GLOBALS['egw_info']['server']['nis_domain']))
34
+		if (!empty($GLOBALS['egw_info']['server']['nis_domain']))
35 35
 		{
36 36
 			$domain = $GLOBALS['egw_info']['server']['nis_domain'];
37 37
 		}
38 38
 
39 39
 		$map = "passwd.byname";
40
-		if(!empty($GLOBALS['egw_info']['server']['nis_map']))
40
+		if (!empty($GLOBALS['egw_info']['server']['nis_map']))
41 41
 		{
42 42
 			$map = $GLOBALS['egw_info']['server']['nis_map'];
43 43
 		}
44
-		$entry = yp_match( $domain, $map, $username );
44
+		$entry = yp_match($domain, $map, $username);
45 45
 
46 46
 		/*
47 47
 		 * we assume that the map is structured in the usual
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 	 * @param int $account_id =0 account id of user whose passwd should be changed
64 64
 	 * @return boolean true if password successful changed, false otherwise
65 65
 	 */
66
-	function change_password($old_passwd, $new_passwd, $account_id=0)
66
+	function change_password($old_passwd, $new_passwd, $account_id = 0)
67 67
 	{
68
-		unset($old_passwd, $new_passwd, $account_id);	// not used but required by interface
68
+		unset($old_passwd, $new_passwd, $account_id); // not used but required by interface
69 69
 
70 70
 		// can't change passwords unless server runs as root (bad idea)
71
-		return( False );
71
+		return(False);
72 72
 	}
73 73
 }
Please login to merge, or discard this patch.
api/src/Auth/Sqlssl.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,21 +29,21 @@  discard block
 block discarded – undo
29 29
 	 * @param string $passwd_type ='text' 'text' for cleartext passwords (default)
30 30
 	 * @return boolean true if successful authenticated, false otherwise
31 31
 	 */
32
-	function authenticate($username, $passwd, $passwd_type='text')
32
+	function authenticate($username, $passwd, $passwd_type = 'text')
33 33
 	{
34
-		unset($passwd_type);	// not used but required by interface
34
+		unset($passwd_type); // not used but required by interface
35 35
 
36 36
 		$local_debug = False;
37 37
 
38
-		if($local_debug)
38
+		if ($local_debug)
39 39
 		{
40 40
 			echo "<b>Debug SQL: uid - $username passwd - $passwd</b>";
41 41
 		}
42
-		if (!($row = $this->db->select($this->table,'account_lid,account_pwd',array(
42
+		if (!($row = $this->db->select($this->table, 'account_lid,account_pwd', array(
43 43
 			'account_lid' => $username,
44 44
 			'account_status' => 'A',
45 45
 			'account_type'   => 'u',
46
-		),__LINE__,__FILE__)->fetch()) || $GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username)
46
+		), __LINE__, __FILE__)->fetch()) || $GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username)
47 47
 		{
48 48
 			return false;
49 49
 		}
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		# Apache + mod_ssl provide the data in the environment
52 52
 		# Certificate (chain) verification occurs inside mod_ssl
53 53
 		# see http://www.modssl.org/docs/2.8/ssl_howto.html#ToC6
54
-		if(!isset($_SERVER['SSL_CLIENT_S_DN']))
54
+		if (!isset($_SERVER['SSL_CLIENT_S_DN']))
55 55
 		{
56 56
 			# if we're not doing SSL authentication, behave like auth_sql
57 57
 			return Api\Auth::compare_password($passwd, $row['account_pwd'], 'md5', strtolower($username));
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 * @param int $account_id =0 account id of user whose passwd should be changed
68 68
 	 * @return boolean true if password successful changed, false otherwise
69 69
 	 */
70
-	function change_password($old_passwd, $new_passwd, $account_id=0)
70
+	function change_password($old_passwd, $new_passwd, $account_id = 0)
71 71
 	{
72
-		unset($old_passwd, $new_passwd, $account_id);	// not used but required by interface
72
+		unset($old_passwd, $new_passwd, $account_id); // not used but required by interface
73 73
 
74 74
 		// deny password changes.
75 75
 		return False;
Please login to merge, or discard this patch.