@@ -129,7 +129,7 @@ discard block |
||
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 | */ |
@@ -1138,7 +1138,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | { |
@@ -803,11 +803,11 @@ discard block |
||
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
806 | - * Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000 |
|
807 | - * |
|
808 | - * @param long $unixTime |
|
809 | - * @return long windowsTime |
|
810 | - */ |
|
806 | + * Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000 |
|
807 | + * |
|
808 | + * @param long $unixTime |
|
809 | + * @return long windowsTime |
|
810 | + */ |
|
811 | 811 | public static function convertUnixTimeToWindowsTime($unixTime) |
812 | 812 | { |
813 | 813 | return ($unixTime + 11644477200) * 10000000; |
@@ -1260,10 +1260,10 @@ discard block |
||
1260 | 1260 | } |
1261 | 1261 | |
1262 | 1262 | /** |
1263 | - * Convert 8bit characters e.g. accented characters to UTF8 encoded characters |
|
1264 | - * |
|
1265 | - * Extended to use mbstring to convert from arbitrary charset to utf-8 |
|
1266 | - */ |
|
1263 | + * Convert 8bit characters e.g. accented characters to UTF8 encoded characters |
|
1264 | + * |
|
1265 | + * Extended to use mbstring to convert from arbitrary charset to utf-8 |
|
1266 | + */ |
|
1267 | 1267 | protected function encode8Bit(&$item, $key) |
1268 | 1268 | { |
1269 | 1269 | if ($this->charset != 'utf-8' && $key != 'password') |
@@ -1291,29 +1291,29 @@ discard block |
||
1291 | 1291 | return $this->userClass; |
1292 | 1292 | } |
1293 | 1293 | |
1294 | - /** |
|
1295 | - * Get the group class interface |
|
1296 | - * |
|
1297 | - * @return adLDAPGroups |
|
1298 | - */ |
|
1299 | - public function group() { |
|
1300 | - if (!$this->groupClass) { |
|
1301 | - $this->groupClass = new adLDAPGroups_egw($this); |
|
1302 | - } |
|
1303 | - return $this->groupClass; |
|
1304 | - } |
|
1305 | - |
|
1306 | - /** |
|
1307 | - * Get the utils class interface |
|
1308 | - * |
|
1309 | - * @return adLDAPUtils |
|
1310 | - */ |
|
1311 | - public function utilities() { |
|
1312 | - if (!$this->utilClass) { |
|
1313 | - $this->utilClass = new adLDAPUtils_egw($this); |
|
1314 | - } |
|
1315 | - return $this->utilClass; |
|
1316 | - } |
|
1294 | + /** |
|
1295 | + * Get the group class interface |
|
1296 | + * |
|
1297 | + * @return adLDAPGroups |
|
1298 | + */ |
|
1299 | + public function group() { |
|
1300 | + if (!$this->groupClass) { |
|
1301 | + $this->groupClass = new adLDAPGroups_egw($this); |
|
1302 | + } |
|
1303 | + return $this->groupClass; |
|
1304 | + } |
|
1305 | + |
|
1306 | + /** |
|
1307 | + * Get the utils class interface |
|
1308 | + * |
|
1309 | + * @return adLDAPUtils |
|
1310 | + */ |
|
1311 | + public function utilities() { |
|
1312 | + if (!$this->utilClass) { |
|
1313 | + $this->utilClass = new adLDAPUtils_egw($this); |
|
1314 | + } |
|
1315 | + return $this->utilClass; |
|
1316 | + } |
|
1317 | 1317 | } |
1318 | 1318 | |
1319 | 1319 | /** |
@@ -1402,45 +1402,45 @@ discard block |
||
1402 | 1402 | return true; |
1403 | 1403 | } |
1404 | 1404 | |
1405 | - /** |
|
1406 | - * Encode a password for transmission over LDAP |
|
1407 | - * |
|
1408 | - * Extended to use mbstring to convert from arbitrary charset to UTF-16LE |
|
1409 | - * |
|
1410 | - * @param string $password The password to encode |
|
1411 | - * @return string |
|
1412 | - */ |
|
1413 | - public function encodePassword($password) |
|
1414 | - { |
|
1415 | - $password="\"".$password."\""; |
|
1416 | - if (function_exists('mb_convert_encoding')) |
|
1417 | - { |
|
1418 | - return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
|
1419 | - } |
|
1420 | - $encoded=""; |
|
1421 | - for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
1422 | - return $encoded; |
|
1423 | - } |
|
1424 | - |
|
1425 | - /** |
|
1426 | - * Set a password |
|
1427 | - * |
|
1428 | - * Requires "Reset password" priviledges from bind user! |
|
1429 | - * |
|
1405 | + /** |
|
1406 | + * Encode a password for transmission over LDAP |
|
1407 | + * |
|
1408 | + * Extended to use mbstring to convert from arbitrary charset to UTF-16LE |
|
1409 | + * |
|
1410 | + * @param string $password The password to encode |
|
1411 | + * @return string |
|
1412 | + */ |
|
1413 | + public function encodePassword($password) |
|
1414 | + { |
|
1415 | + $password="\"".$password."\""; |
|
1416 | + if (function_exists('mb_convert_encoding')) |
|
1417 | + { |
|
1418 | + return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
|
1419 | + } |
|
1420 | + $encoded=""; |
|
1421 | + for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
1422 | + return $encoded; |
|
1423 | + } |
|
1424 | + |
|
1425 | + /** |
|
1426 | + * Set a password |
|
1427 | + * |
|
1428 | + * Requires "Reset password" priviledges from bind user! |
|
1429 | + * |
|
1430 | 1430 | * We can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2! |
1431 | 1431 | * |
1432 | - * @param string $dn |
|
1433 | - * @param string $password |
|
1434 | - * @return boolean |
|
1435 | - */ |
|
1436 | - public function setPassword($dn, $password) |
|
1437 | - { |
|
1438 | - $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
|
1439 | - 'unicodePwd' => $this->encodePassword($password), |
|
1440 | - )); |
|
1441 | - if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
1442 | - return $result; |
|
1443 | - } |
|
1432 | + * @param string $dn |
|
1433 | + * @param string $password |
|
1434 | + * @return boolean |
|
1435 | + */ |
|
1436 | + public function setPassword($dn, $password) |
|
1437 | + { |
|
1438 | + $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
|
1439 | + 'unicodePwd' => $this->encodePassword($password), |
|
1440 | + )); |
|
1441 | + if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
1442 | + return $result; |
|
1443 | + } |
|
1444 | 1444 | |
1445 | 1445 | /** |
1446 | 1446 | * Check if we can to a real password change, not just a password reset |
@@ -1454,30 +1454,30 @@ discard block |
||
1454 | 1454 | return function_exists('ldap_modify_batch'); |
1455 | 1455 | } |
1456 | 1456 | |
1457 | - /** |
|
1458 | - * Set the password of a user - This must be performed over SSL |
|
1459 | - * |
|
1460 | - * @param string $username The username to modify |
|
1461 | - * @param string $password The new password |
|
1462 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
1463 | - * @param string $old_password old password for password change, if supported |
|
1464 | - * @return bool |
|
1465 | - */ |
|
1466 | - public function password($username, $password, $isGUID = false, $old_password=null) |
|
1467 | - { |
|
1468 | - if ($username === NULL) { return false; } |
|
1469 | - if ($password === NULL) { return false; } |
|
1470 | - if (!$this->adldap->getLdapBind()) { return false; } |
|
1471 | - if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
1472 | - throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
|
1473 | - } |
|
1474 | - |
|
1475 | - $userDn = $this->dn($username, $isGUID); |
|
1476 | - if ($userDn === false) { |
|
1477 | - return false; |
|
1478 | - } |
|
1479 | - |
|
1480 | - $add=array(); |
|
1457 | + /** |
|
1458 | + * Set the password of a user - This must be performed over SSL |
|
1459 | + * |
|
1460 | + * @param string $username The username to modify |
|
1461 | + * @param string $password The new password |
|
1462 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
1463 | + * @param string $old_password old password for password change, if supported |
|
1464 | + * @return bool |
|
1465 | + */ |
|
1466 | + public function password($username, $password, $isGUID = false, $old_password=null) |
|
1467 | + { |
|
1468 | + if ($username === NULL) { return false; } |
|
1469 | + if ($password === NULL) { return false; } |
|
1470 | + if (!$this->adldap->getLdapBind()) { return false; } |
|
1471 | + if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
1472 | + throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
|
1473 | + } |
|
1474 | + |
|
1475 | + $userDn = $this->dn($username, $isGUID); |
|
1476 | + if ($userDn === false) { |
|
1477 | + return false; |
|
1478 | + } |
|
1479 | + |
|
1480 | + $add=array(); |
|
1481 | 1481 | |
1482 | 1482 | if (empty($old_password) || !function_exists('ldap_modify_batch')) { |
1483 | 1483 | $add["unicodePwd"][0] = $this->encodePassword($password); |
@@ -1499,76 +1499,76 @@ discard block |
||
1499 | 1499 | ); |
1500 | 1500 | $result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods); |
1501 | 1501 | } |
1502 | - if ($result === false){ |
|
1503 | - $err = ldap_errno($this->adldap->getLdapConnection()); |
|
1504 | - if ($err) { |
|
1505 | - $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
1506 | - if($err == 53) { |
|
1507 | - $msg .= ' Your password might not match the password policy.'; |
|
1508 | - } |
|
1509 | - throw new adLDAPException($msg); |
|
1510 | - } |
|
1511 | - else { |
|
1512 | - return false; |
|
1513 | - } |
|
1514 | - } |
|
1515 | - |
|
1516 | - return true; |
|
1517 | - } |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * Modify a user |
|
1521 | - * |
|
1522 | - * @param string $username The username to query |
|
1523 | - * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
1524 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
1525 | - * @return bool |
|
1526 | - */ |
|
1527 | - public function modify($username, $attributes, $isGUID = false) |
|
1528 | - { |
|
1529 | - if ($username === NULL) { return "Missing compulsory field [username]"; } |
|
1530 | - if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
1531 | - throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.'); |
|
1532 | - } |
|
1533 | - |
|
1534 | - // Find the dn of the user |
|
1535 | - $userDn = $this->dn($username, $isGUID); |
|
1536 | - if ($userDn === false) { |
|
1537 | - return false; |
|
1538 | - } |
|
1539 | - |
|
1540 | - // Translate the update to the LDAP schema |
|
1541 | - $mod = $this->adldap->adldap_schema($attributes); |
|
1542 | - |
|
1543 | - // Check to see if this is an enabled status update |
|
1544 | - if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
1545 | - return false; |
|
1546 | - } |
|
1547 | - |
|
1548 | - // Set the account control attribute (only if specified) |
|
1549 | - if (array_key_exists("enabled", $attributes)){ |
|
1550 | - if ($attributes["enabled"]){ |
|
1551 | - $controlOptions = array("NORMAL_ACCOUNT"); |
|
1552 | - } |
|
1553 | - else { |
|
1554 | - $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE"); |
|
1555 | - } |
|
1556 | - $mod["userAccountControl"][0] = $this->accountControl($controlOptions); |
|
1557 | - } |
|
1502 | + if ($result === false){ |
|
1503 | + $err = ldap_errno($this->adldap->getLdapConnection()); |
|
1504 | + if ($err) { |
|
1505 | + $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
1506 | + if($err == 53) { |
|
1507 | + $msg .= ' Your password might not match the password policy.'; |
|
1508 | + } |
|
1509 | + throw new adLDAPException($msg); |
|
1510 | + } |
|
1511 | + else { |
|
1512 | + return false; |
|
1513 | + } |
|
1514 | + } |
|
1515 | + |
|
1516 | + return true; |
|
1517 | + } |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * Modify a user |
|
1521 | + * |
|
1522 | + * @param string $username The username to query |
|
1523 | + * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
1524 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
1525 | + * @return bool |
|
1526 | + */ |
|
1527 | + public function modify($username, $attributes, $isGUID = false) |
|
1528 | + { |
|
1529 | + if ($username === NULL) { return "Missing compulsory field [username]"; } |
|
1530 | + if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
1531 | + throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.'); |
|
1532 | + } |
|
1533 | + |
|
1534 | + // Find the dn of the user |
|
1535 | + $userDn = $this->dn($username, $isGUID); |
|
1536 | + if ($userDn === false) { |
|
1537 | + return false; |
|
1538 | + } |
|
1539 | + |
|
1540 | + // Translate the update to the LDAP schema |
|
1541 | + $mod = $this->adldap->adldap_schema($attributes); |
|
1542 | + |
|
1543 | + // Check to see if this is an enabled status update |
|
1544 | + if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
1545 | + return false; |
|
1546 | + } |
|
1547 | + |
|
1548 | + // Set the account control attribute (only if specified) |
|
1549 | + if (array_key_exists("enabled", $attributes)){ |
|
1550 | + if ($attributes["enabled"]){ |
|
1551 | + $controlOptions = array("NORMAL_ACCOUNT"); |
|
1552 | + } |
|
1553 | + else { |
|
1554 | + $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE"); |
|
1555 | + } |
|
1556 | + $mod["userAccountControl"][0] = $this->accountControl($controlOptions); |
|
1557 | + } |
|
1558 | 1558 | // we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2 |
1559 | 1559 | unset($mod['unicodePwd']); |
1560 | 1560 | |
1561 | 1561 | if ($mod) |
1562 | 1562 | { |
1563 | - // Do the update |
|
1564 | - $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
|
1565 | - if ($result == false) { |
|
1563 | + // Do the update |
|
1564 | + $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
|
1565 | + if ($result == false) { |
|
1566 | 1566 | if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***'; |
1567 | 1567 | error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
1568 | - return false; |
|
1569 | - } |
|
1568 | + return false; |
|
1569 | + } |
|
1570 | 1570 | } |
1571 | - if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
1571 | + if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
1572 | 1572 | { |
1573 | 1573 | return false; |
1574 | 1574 | } |
@@ -1633,23 +1633,23 @@ discard block |
||
1633 | 1633 | return $this->adldap->encode8bit($item, $key); |
1634 | 1634 | } |
1635 | 1635 | |
1636 | - /** |
|
1637 | - * Escape strings for the use in LDAP filters |
|
1638 | - * |
|
1639 | - * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT |
|
1640 | - * Ported from Perl's Net::LDAP::Util escape_filter_value |
|
1641 | - * |
|
1642 | - * @param string $str The string the parse |
|
1643 | - * @author Port by Andreas Gohr <[email protected]> |
|
1644 | - * @return string |
|
1645 | - */ |
|
1646 | - public function ldapSlashes($str){ |
|
1647 | - return preg_replace_callback( |
|
1648 | - '/([\x00-\x1F\*\(\)\\\\])/', |
|
1649 | - function ($matches) { |
|
1650 | - return "\\".join("", unpack("H2", $matches[1])); |
|
1651 | - }, |
|
1652 | - $str |
|
1653 | - ); |
|
1654 | - } |
|
1636 | + /** |
|
1637 | + * Escape strings for the use in LDAP filters |
|
1638 | + * |
|
1639 | + * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT |
|
1640 | + * Ported from Perl's Net::LDAP::Util escape_filter_value |
|
1641 | + * |
|
1642 | + * @param string $str The string the parse |
|
1643 | + * @author Port by Andreas Gohr <[email protected]> |
|
1644 | + * @return string |
|
1645 | + */ |
|
1646 | + public function ldapSlashes($str){ |
|
1647 | + return preg_replace_callback( |
|
1648 | + '/([\x00-\x1F\*\(\)\\\\])/', |
|
1649 | + function ($matches) { |
|
1650 | + return "\\".join("", unpack("H2", $matches[1])); |
|
1651 | + }, |
|
1652 | + $str |
|
1653 | + ); |
|
1654 | + } |
|
1655 | 1655 | } |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | * @return adLDAP |
130 | 130 | * @throws adLDAPException |
131 | 131 | */ |
132 | - public static function get_adldap(array &$config=null) |
|
132 | + public static function get_adldap(array &$config = null) |
|
133 | 133 | { |
134 | 134 | static $adldap = array(); |
135 | - if (!$config) $config =& $GLOBALS['egw_info']['server']; |
|
135 | + if (!$config) $config = & $GLOBALS['egw_info']['server']; |
|
136 | 136 | |
137 | 137 | if (!isset($adldap[$config['ads_domain']])) |
138 | 138 | { |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | if (empty($config['ads_domain'])) throw new Exception("Required ADS domain missing!"); |
141 | 141 | |
142 | 142 | $base_dn_parts = array(); |
143 | - foreach(explode('.', $config['ads_domain']) as $dc) |
|
143 | + foreach (explode('.', $config['ads_domain']) as $dc) |
|
144 | 144 | { |
145 | 145 | $base_dn_parts[] = 'DC='.$dc; |
146 | 146 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param int $account_id |
169 | 169 | * @return string|NULL |
170 | 170 | */ |
171 | - protected function get_sid($account_id=null) |
|
171 | + protected function get_sid($account_id = null) |
|
172 | 172 | { |
173 | 173 | static $domain_sid = null; |
174 | 174 | if (!isset($domain_sid)) |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | * @param boolean $set_if_empty =false true set from DN of "Domain Users" group # |
204 | 204 | * @return string |
205 | 205 | */ |
206 | - public function ads_context($set_if_empty=false) |
|
206 | + public function ads_context($set_if_empty = false) |
|
207 | 207 | { |
208 | 208 | if (empty($this->frontend->config[self::ADS_CONTEXT])) |
209 | 209 | { |
210 | 210 | if ($set_if_empty && ($dn = $this->id2name(-self::DOMAIN_USERS_GROUP, 'account_dn'))) |
211 | 211 | { |
212 | 212 | $dn = preg_replace('/^CN=.*?,(CN|OU)=/i', '$1=', $dn); |
213 | - config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT]=$dn, 'phpgwapi'); |
|
213 | + config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT] = $dn, 'phpgwapi'); |
|
214 | 214 | } |
215 | 215 | else |
216 | 216 | { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @param boolean $reconnect =false true: reconnect even if already connected |
248 | 248 | * @return resource |
249 | 249 | */ |
250 | - public function ldap_connection($reconnect=false) |
|
250 | + public function ldap_connection($reconnect = false) |
|
251 | 251 | { |
252 | 252 | if (($reconnect || !($ds = $this->adldap->getLdapConnection())) && |
253 | 253 | // call connect, thought I dont know how it can be not connected ... |
@@ -411,8 +411,7 @@ discard block |
||
411 | 411 | $data = translation::convert($_data, 'utf-8'); |
412 | 412 | |
413 | 413 | // no need to calculate sid, if already calculated |
414 | - $sid = is_string($data['objectsid']) ? $data['objectsid'] : |
|
415 | - $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
414 | + $sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
416 | 415 | $account_id = -self::sid2account_id($sid); |
417 | 416 | |
418 | 417 | $group = array( |
@@ -426,10 +425,8 @@ discard block |
||
426 | 425 | 'account_lastname' => lang('Group'), |
427 | 426 | 'account_fullname' => lang('Group').' '.$data['samaccountname'][0], |
428 | 427 | 'account_email' => $data['mail'][0], |
429 | - 'account_created' => !isset($data['whencreated'][0]) ? null : |
|
430 | - self::_when2ts($data['whencreated'][0]), |
|
431 | - 'account_modified' => !isset($data['whenchanged'][0]) ? null : |
|
432 | - self::_when2ts($data['whenchanged'][0]), |
|
428 | + 'account_created' => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]), |
|
429 | + 'account_modified' => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]), |
|
433 | 430 | 'account_description' => $data['description'][0], |
434 | 431 | 'mailAllowed' => true, |
435 | 432 | ); |
@@ -449,7 +446,7 @@ discard block |
||
449 | 446 | { |
450 | 447 | if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'g', self::$group_attributes))) |
451 | 448 | { |
452 | - return false; // group not found |
|
449 | + return false; // group not found |
|
453 | 450 | } |
454 | 451 | $group = $this->_ldap2group(array_shift($data)); |
455 | 452 | |
@@ -472,8 +469,7 @@ discard block |
||
472 | 469 | $data = translation::convert($_data, 'utf-8'); |
473 | 470 | |
474 | 471 | // no need to calculate sid, if already calculated |
475 | - $sid = is_string($data['objectsid']) ? $data['objectsid'] : |
|
476 | - $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
472 | + $sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
477 | 473 | $account_id = self::sid2account_id($sid); |
478 | 474 | |
479 | 475 | $user = array( |
@@ -489,22 +485,18 @@ discard block |
||
489 | 485 | 'account_email' => $data['mail'][0], |
490 | 486 | 'account_fullname' => $data['displayname'][0], |
491 | 487 | 'account_phone' => $data['telephonenumber'][0], |
492 | - 'account_status' => $data['useraccountcontrol'][0] & 2 ? false : 'A', |
|
493 | - 'account_expires' => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : |
|
494 | - $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]), |
|
495 | - 'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : |
|
496 | - $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])), |
|
497 | - 'account_created' => !isset($data['whencreated'][0]) ? null : |
|
498 | - self::_when2ts($data['whencreated'][0]), |
|
499 | - 'account_modified' => !isset($data['whenchanged'][0]) ? null : |
|
500 | - self::_when2ts($data['whenchanged'][0]), |
|
488 | + 'account_status' => $data['useraccountcontrol'][0]&2 ? false : 'A', |
|
489 | + 'account_expires' => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]), |
|
490 | + 'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])), |
|
491 | + 'account_created' => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]), |
|
492 | + 'account_modified' => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]), |
|
501 | 493 | ); |
502 | 494 | // expired accounts are NOT active |
503 | 495 | if ($user['account_expires'] !== -1 && $user['account_expires'] < time()) |
504 | 496 | { |
505 | 497 | $user['account_status'] = false; |
506 | 498 | } |
507 | - $user['person_id'] = $user['account_guid']; // id of contact |
|
499 | + $user['person_id'] = $user['account_guid']; // id of contact |
|
508 | 500 | //error_log(__METHOD__."(".array2string($data).") returning ".array2string($user)); |
509 | 501 | return $user; |
510 | 502 | } |
@@ -534,7 +526,7 @@ discard block |
||
534 | 526 | { |
535 | 527 | if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'u', self::$user_attributes))) |
536 | 528 | { |
537 | - return false; // user not found |
|
529 | + return false; // user not found |
|
538 | 530 | } |
539 | 531 | $user = $this->_ldap2user(array_shift($data)); |
540 | 532 | |
@@ -557,10 +549,10 @@ discard block |
||
557 | 549 | */ |
558 | 550 | protected static function _when2ts($_when) |
559 | 551 | { |
560 | - static $utc=null; |
|
552 | + static $utc = null; |
|
561 | 553 | if (!isset($utc)) $utc = new DateTimeZone('UTC'); |
562 | 554 | |
563 | - list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
|
555 | + list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
|
564 | 556 | $datetime = egw_time::createFromFormat(self::WHEN_FORMAT, $when, $utc); |
565 | 557 | if (egw_time::$server_timezone) $datetime->setTimezone(egw_time::$server_timezone); |
566 | 558 | |
@@ -575,7 +567,7 @@ discard block |
||
575 | 567 | * @param array $old =null current data |
576 | 568 | * @return int|false account_id or false on error |
577 | 569 | */ |
578 | - protected function _save_group(array &$data, array $old=null) |
|
570 | + protected function _save_group(array &$data, array $old = null) |
|
579 | 571 | { |
580 | 572 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
581 | 573 | |
@@ -586,7 +578,7 @@ discard block |
||
586 | 578 | 'account_description' => 'description', |
587 | 579 | ); |
588 | 580 | $attributes = array(); |
589 | - foreach($new2adldap as $egw => $adldap) |
|
581 | + foreach ($new2adldap as $egw => $adldap) |
|
590 | 582 | { |
591 | 583 | $attributes[$adldap] = (string)$data[$egw]; |
592 | 584 | } |
@@ -623,11 +615,11 @@ discard block |
||
623 | 615 | 'account_description' => 'description', |
624 | 616 | ); |
625 | 617 | $ldap = array(); |
626 | - foreach($egw2adldap as $egw => $adldap) |
|
618 | + foreach ($egw2adldap as $egw => $adldap) |
|
627 | 619 | { |
628 | 620 | if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw]) |
629 | 621 | { |
630 | - switch($egw) |
|
622 | + switch ($egw) |
|
631 | 623 | { |
632 | 624 | case 'account_description': |
633 | 625 | $ldap[$adldap] = !empty($data[$egw]) ? $data[$egw] : array(); |
@@ -640,7 +632,7 @@ discard block |
||
640 | 632 | } |
641 | 633 | } |
642 | 634 | // attributes not (yet) suppored by adldap |
643 | - if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap))) |
|
635 | + if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap))) |
|
644 | 636 | { |
645 | 637 | error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret)); |
646 | 638 | return false; |
@@ -656,7 +648,7 @@ discard block |
||
656 | 648 | * @param array $old =null current data |
657 | 649 | * @return int|false account_id or false on error |
658 | 650 | */ |
659 | - protected function _save_user(array &$data, array $old=null) |
|
651 | + protected function _save_user(array &$data, array $old = null) |
|
660 | 652 | { |
661 | 653 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
662 | 654 | if (!isset($data['account_fullname']) && !empty($data['account_firstname']) && !empty($data['account_lastname'])) |
@@ -676,12 +668,12 @@ discard block |
||
676 | 668 | 'account_status' => 'enabled', |
677 | 669 | ); |
678 | 670 | $attributes = array(); |
679 | - foreach($new2adldap as $egw => $adldap) |
|
671 | + foreach ($new2adldap as $egw => $adldap) |
|
680 | 672 | { |
681 | 673 | if ($egw == 'account_passwd' && (empty($data[$egw]) || |
682 | 674 | !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) |
683 | 675 | { |
684 | - continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
|
676 | + continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
|
685 | 677 | } |
686 | 678 | if (isset($data[$egw])) $attributes[$adldap] = $data[$egw]; |
687 | 679 | } |
@@ -718,7 +710,7 @@ discard block |
||
718 | 710 | 'account_firstname' => 'firstname', |
719 | 711 | 'account_lastname' => 'surname', |
720 | 712 | 'account_email' => 'email', |
721 | - 'account_fullname' => 'display_name', // handeled currently in rename above, as not supported by adLDAP |
|
713 | + 'account_fullname' => 'display_name', // handeled currently in rename above, as not supported by adLDAP |
|
722 | 714 | 'account_passwd' => 'password', |
723 | 715 | 'account_status' => 'enabled', |
724 | 716 | 'account_primary_group' => 'primarygroupid', |
@@ -731,7 +723,7 @@ discard block |
||
731 | 723 | // for a new entry set certain values (eg. profilePath) to in setup configured value |
732 | 724 | if ($new_entry) |
733 | 725 | { |
734 | - foreach($this->frontend->config as $name => $value) |
|
726 | + foreach ($this->frontend->config as $name => $value) |
|
735 | 727 | { |
736 | 728 | if (substr($name, 0, 8) == 'ads_new_') |
737 | 729 | { |
@@ -739,22 +731,22 @@ discard block |
||
739 | 731 | } |
740 | 732 | } |
741 | 733 | } |
742 | - foreach($egw2adldap as $egw => $adldap) |
|
734 | + foreach ($egw2adldap as $egw => $adldap) |
|
743 | 735 | { |
744 | 736 | if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw]) |
745 | 737 | { |
746 | - switch($egw) |
|
738 | + switch ($egw) |
|
747 | 739 | { |
748 | 740 | case 'account_passwd': |
749 | 741 | if (!empty($data[$egw]) && ($this->adldap->getUseSSL() || $this->adldap->getUseTLS())) |
750 | 742 | { |
751 | - $attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS |
|
743 | + $attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS |
|
752 | 744 | } |
753 | 745 | break; |
754 | 746 | case 'account_primary_group': |
755 | 747 | // setting a primary group seems to fail, if user is no member of that group |
756 | 748 | if (isset($old['memberships'][$data[$egw]]) || |
757 | - $this->adldap->group()->addUser($group=$this->id2name($data[$egw]), $data['account_id'])) |
|
749 | + $this->adldap->group()->addUser($group = $this->id2name($data[$egw]), $data['account_id'])) |
|
758 | 750 | { |
759 | 751 | $old['memberships'][$data[$egw]] = $group; |
760 | 752 | $ldap[$adldap] = abs($data[$egw]); |
@@ -765,11 +757,10 @@ discard block |
||
765 | 757 | $ldap['userPrincipalName'] = $data[$egw].'@'.$this->frontend->config['ads_domain']; |
766 | 758 | break; |
767 | 759 | case 'account_expires': |
768 | - $attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : |
|
769 | - self::convertUnixTimeToWindowsTime($data[$egw]); |
|
760 | + $attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : self::convertUnixTimeToWindowsTime($data[$egw]); |
|
770 | 761 | break; |
771 | 762 | case 'account_status': |
772 | - if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
763 | + if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
773 | 764 | $attributes[$adldap] = $data[$egw] == 'A'; |
774 | 765 | break; |
775 | 766 | case 'account_lastpwd_change': |
@@ -791,7 +782,7 @@ discard block |
||
791 | 782 | } |
792 | 783 | //elseif ($attributes) error_log(__METHOD__."(".array2string($data).") adldap->user()->modify('$data[account_lid]', ".array2string($attributes).') returned '.array2string($ret).' '.function_backtrace()); |
793 | 784 | // attributes not (yet) suppored by adldap |
794 | - if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap))) |
|
785 | + if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap))) |
|
795 | 786 | { |
796 | 787 | error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret).' ('.ldap_error($ds).') '.function_backtrace()); |
797 | 788 | return false; |
@@ -864,11 +855,11 @@ discard block |
||
864 | 855 | $query = ldap::quote(strtolower($param['query'])); |
865 | 856 | |
866 | 857 | $accounts = array(); |
867 | - if($param['type'] !== 'groups') |
|
858 | + if ($param['type'] !== 'groups') |
|
868 | 859 | { |
869 | 860 | if (!empty($query) && $query != '*') |
870 | 861 | { |
871 | - switch($param['query_type']) |
|
862 | + switch ($param['query_type']) |
|
872 | 863 | { |
873 | 864 | case 'all': |
874 | 865 | default: |
@@ -899,14 +890,14 @@ discard block |
||
899 | 890 | $membership_filter = '(|(memberOf='.$this->id2name((int)$param['type'], 'account_dn').')(PrimaryGroupId='.abs($param['type']).'))'; |
900 | 891 | $filter = $filter ? "(&$membership_filter$filter)" : $membership_filter; |
901 | 892 | } |
902 | - foreach($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data) |
|
893 | + foreach ($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data) |
|
903 | 894 | { |
904 | 895 | $account = $this->_ldap2user($data); |
905 | 896 | if ($param['active'] && !$this->frontend->is_active($account)) |
906 | 897 | { |
907 | 898 | continue; |
908 | 899 | } |
909 | - $account['account_fullname'] = common::display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$account['account_id']); |
|
900 | + $account['account_fullname'] = common::display_fullname($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $account['account_id']); |
|
910 | 901 | $accounts[$account_id] = $account; |
911 | 902 | } |
912 | 903 | } |
@@ -915,9 +906,9 @@ discard block |
||
915 | 906 | $query = ldap::quote(strtolower($param['query'])); |
916 | 907 | |
917 | 908 | $filter = null; |
918 | - if(!empty($query) && $query != '*') |
|
909 | + if (!empty($query) && $query != '*') |
|
919 | 910 | { |
920 | - switch($param['query_type']) |
|
911 | + switch ($param['query_type']) |
|
921 | 912 | { |
922 | 913 | case 'all': |
923 | 914 | default: |
@@ -931,16 +922,16 @@ discard block |
||
931 | 922 | } |
932 | 923 | $filter = "(|(cn=$query)(description=$query))"; |
933 | 924 | } |
934 | - foreach($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data) |
|
925 | + foreach ($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data) |
|
935 | 926 | { |
936 | 927 | $accounts[$account_id] = $this->_ldap2group($data); |
937 | 928 | } |
938 | 929 | } |
939 | 930 | // sort the array |
940 | 931 | $this->_callback_sort = strtoupper($param['sort']); |
941 | - $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
|
932 | + $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']); |
|
942 | 933 | $sortedAccounts = $accounts; |
943 | - uasort($sortedAccounts,array($this,'_sort_callback')); |
|
934 | + uasort($sortedAccounts, array($this, '_sort_callback')); |
|
944 | 935 | $account_search[$unl_serial]['data'] = $sortedAccounts; |
945 | 936 | |
946 | 937 | $account_search[$unl_serial]['total'] = $this->total = count($accounts); |
@@ -948,7 +939,7 @@ discard block |
||
948 | 939 | //echo "<p>accounts_ldap::search() found $this->total: ".microtime()."</p>\n"; |
949 | 940 | // return only the wanted accounts |
950 | 941 | reset($sortedAccounts); |
951 | - if(is_numeric($start) && is_numeric($offset)) |
|
942 | + if (is_numeric($start) && is_numeric($offset)) |
|
952 | 943 | { |
953 | 944 | $account_search[$serial]['data'] = array_slice($sortedAccounts, $start, $offset); |
954 | 945 | $account_search[$serial]['total'] = $this->total; |
@@ -979,19 +970,19 @@ discard block |
||
979 | 970 | * @param array $b |
980 | 971 | * @return int |
981 | 972 | */ |
982 | - protected function _sort_callback($a,$b) |
|
973 | + protected function _sort_callback($a, $b) |
|
983 | 974 | { |
984 | - foreach($this->_callback_order as $col ) |
|
975 | + foreach ($this->_callback_order as $col) |
|
985 | 976 | { |
986 | - if($this->_callback_sort != 'DESC') |
|
977 | + if ($this->_callback_sort != 'DESC') |
|
987 | 978 | { |
988 | - $cmp = strcasecmp( $a[$col], $b[$col] ); |
|
979 | + $cmp = strcasecmp($a[$col], $b[$col]); |
|
989 | 980 | } |
990 | 981 | else |
991 | 982 | { |
992 | - $cmp = strcasecmp( $b[$col], $a[$col] ); |
|
983 | + $cmp = strcasecmp($b[$col], $a[$col]); |
|
993 | 984 | } |
994 | - if ( $cmp != 0 ) |
|
985 | + if ($cmp != 0) |
|
995 | 986 | { |
996 | 987 | return $cmp; |
997 | 988 | } |
@@ -1010,9 +1001,9 @@ discard block |
||
1010 | 1001 | * @param array $accounts =array() array to add filtered accounts too, default empty array |
1011 | 1002 | * @return array account_id => account_lid or values for $attrs pairs |
1012 | 1003 | */ |
1013 | - protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array()) |
|
1004 | + protected function filter($attr_filter, $account_type = null, array $attrs = null, array $accounts = array()) |
|
1014 | 1005 | { |
1015 | - switch($account_type) |
|
1006 | + switch ($account_type) |
|
1016 | 1007 | { |
1017 | 1008 | case 'u': |
1018 | 1009 | $type_filter = '(samaccounttype='.adLDAP::ADLDAP_NORMAL_ACCOUNT.')'; |
@@ -1037,25 +1028,25 @@ discard block |
||
1037 | 1028 | } |
1038 | 1029 | else |
1039 | 1030 | { |
1040 | - foreach($attr_filter as $attr => $value) |
|
1031 | + foreach ($attr_filter as $attr => $value) |
|
1041 | 1032 | { |
1042 | 1033 | $filter .= '('.$attr.'='.$this->adldap->utilities()->ldapSlashes($value).')'; |
1043 | 1034 | } |
1044 | 1035 | } |
1045 | 1036 | $filter .= $type_filter.')'; |
1046 | 1037 | } |
1047 | - $sri = ldap_search($ds=$this->ldap_connection(), $context=$this->ads_context(), $filter, |
|
1038 | + $sri = ldap_search($ds = $this->ldap_connection(), $context = $this->ads_context(), $filter, |
|
1048 | 1039 | $attrs ? $attrs : self::$default_attributes); |
1049 | 1040 | if (!$sri) |
1050 | 1041 | { |
1051 | 1042 | if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...'); |
1052 | - $sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter, |
|
1043 | + $sri = ldap_search($ds = $this->ldap_connection(true), $context = $this->ads_context(), $filter, |
|
1053 | 1044 | $attrs ? $attrs : self::$default_attributes); |
1054 | 1045 | } |
1055 | 1046 | |
1056 | 1047 | if ($sri && ($allValues = ldap_get_entries($ds, $sri))) |
1057 | 1048 | { |
1058 | - foreach($allValues as $key => $data) |
|
1049 | + foreach ($allValues as $key => $data) |
|
1059 | 1050 | { |
1060 | 1051 | if ($key === 'count') continue; |
1061 | 1052 | |
@@ -1069,7 +1060,7 @@ discard block |
||
1069 | 1060 | |
1070 | 1061 | if ($data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT && $rid < self::MIN_ACCOUNT_ID) |
1071 | 1062 | { |
1072 | - continue; // ignore system accounts incl. "Administrator" |
|
1063 | + continue; // ignore system accounts incl. "Administrator" |
|
1073 | 1064 | } |
1074 | 1065 | $accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] = |
1075 | 1066 | $attrs ? $data : translation::convert($data['samaccountname'][0], 'utf-8'); |
@@ -1093,7 +1084,7 @@ discard block |
||
1093 | 1084 | * @param string $account_type u = user, g = group, default null = try both |
1094 | 1085 | * @return int|false numeric account_id or false on error ($name not found) |
1095 | 1086 | */ |
1096 | - public function name2id($name, $which='account_lid', $account_type=null) |
|
1087 | + public function name2id($name, $which = 'account_lid', $account_type = null) |
|
1097 | 1088 | { |
1098 | 1089 | static $to_ldap = array( |
1099 | 1090 | 'account_lid' => 'samaccountname', |
@@ -1105,7 +1096,7 @@ discard block |
||
1105 | 1096 | $ret = false; |
1106 | 1097 | if (isset($to_ldap[$which])) |
1107 | 1098 | { |
1108 | - foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid) |
|
1099 | + foreach ($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid) |
|
1109 | 1100 | { |
1110 | 1101 | unset($account_lid); |
1111 | 1102 | $ret = $account_id; |
@@ -1125,9 +1116,9 @@ discard block |
||
1125 | 1116 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
1126 | 1117 | * @return string/false converted value or false on error ($account_id not found) |
1127 | 1118 | */ |
1128 | - public function id2name($account_id, $which='account_lid') |
|
1119 | + public function id2name($account_id, $which = 'account_lid') |
|
1129 | 1120 | { |
1130 | - return $this->frontend->id2name($account_id,$which); |
|
1121 | + return $this->frontend->id2name($account_id, $which); |
|
1131 | 1122 | } |
1132 | 1123 | |
1133 | 1124 | /** |
@@ -1139,9 +1130,9 @@ discard block |
||
1139 | 1130 | */ |
1140 | 1131 | function update_lastlogin($_account_id, $ip) |
1141 | 1132 | { |
1142 | - unset($_account_id, $ip); // not used, but required by function signature |
|
1133 | + unset($_account_id, $ip); // not used, but required by function signature |
|
1143 | 1134 | |
1144 | - return false; // not longer supported |
|
1135 | + return false; // not longer supported |
|
1145 | 1136 | } |
1146 | 1137 | |
1147 | 1138 | /** |
@@ -1181,21 +1172,21 @@ discard block |
||
1181 | 1172 | * @param int $account_id uidnumber |
1182 | 1173 | * @return int number of added or removed memberships |
1183 | 1174 | */ |
1184 | - function set_memberships($groups,$account_id) |
|
1175 | + function set_memberships($groups, $account_id) |
|
1185 | 1176 | { |
1186 | 1177 | if (!($account = $this->id2name($account_id))) return; |
1187 | 1178 | $current = array_keys($this->memberships($account_id)); |
1188 | 1179 | |
1189 | 1180 | $changed = 0; |
1190 | - foreach(array( |
|
1191 | - 'add' => array_diff($groups, $current), // add account to all groups he is currently not in |
|
1192 | - 'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in |
|
1181 | + foreach (array( |
|
1182 | + 'add' => array_diff($groups, $current), // add account to all groups he is currently not in |
|
1183 | + 'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in |
|
1193 | 1184 | ) as $op => $memberships) |
1194 | 1185 | { |
1195 | 1186 | $func = $op.($account_id > 0 ? 'User' : 'Group'); |
1196 | - foreach($memberships as $gid) |
|
1187 | + foreach ($memberships as $gid) |
|
1197 | 1188 | { |
1198 | - $ok = $this->adldap->group()->$func($group=$this->id2name($gid), $account); |
|
1189 | + $ok = $this->adldap->group()->$func($group = $this->id2name($gid), $account); |
|
1199 | 1190 | //error_log(__METHOD__.'('.array2string($groups).", $account_id) $func('$group', '$account') returned ".array2string($ok)); |
1200 | 1191 | $changed += (int)$ok; |
1201 | 1192 | } |
@@ -1217,15 +1208,15 @@ discard block |
||
1217 | 1208 | $current = array_keys($this->members($gid)); |
1218 | 1209 | |
1219 | 1210 | $changed = 0; |
1220 | - foreach(array( |
|
1221 | - 'add' => array_diff($users, $current), // add members currently not in |
|
1222 | - 'remove' => array_diff($current, $users), // remove members only currently in |
|
1211 | + foreach (array( |
|
1212 | + 'add' => array_diff($users, $current), // add members currently not in |
|
1213 | + 'remove' => array_diff($current, $users), // remove members only currently in |
|
1223 | 1214 | ) as $op => $members) |
1224 | 1215 | { |
1225 | - foreach($members as $account_id) |
|
1216 | + foreach ($members as $account_id) |
|
1226 | 1217 | { |
1227 | 1218 | $func = $op.($account_id > 0 ? 'User' : 'Group'); |
1228 | - $ok = $this->adldap->group()->$func($group, $account=$this->id2name($account_id)); |
|
1219 | + $ok = $this->adldap->group()->$func($group, $account = $this->id2name($account_id)); |
|
1229 | 1220 | //error_log(__METHOD__.'('.array2string($users).", $account_id) $func('$group', '$account') returned ".array2string($ok)); |
1230 | 1221 | $changed += (int)$ok; |
1231 | 1222 | } |
@@ -1250,7 +1241,7 @@ discard block |
||
1250 | 1241 | */ |
1251 | 1242 | public $charset = 'iso-8859-1'; |
1252 | 1243 | |
1253 | - function __construct(array $options=array()) |
|
1244 | + function __construct(array $options = array()) |
|
1254 | 1245 | { |
1255 | 1246 | if (isset($options['charset'])) |
1256 | 1247 | { |
@@ -1337,19 +1328,19 @@ discard block |
||
1337 | 1328 | public function create($attributes) |
1338 | 1329 | { |
1339 | 1330 | // Check for compulsory fields |
1340 | - if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; } |
|
1341 | - if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; } |
|
1342 | - if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; } |
|
1343 | - if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; } |
|
1344 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
1345 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
1346 | - |
|
1347 | - if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){ |
|
1331 | + if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; } |
|
1332 | + if (!array_key_exists("firstname", $attributes)) { return "Missing compulsory field [firstname]"; } |
|
1333 | + if (!array_key_exists("surname", $attributes)) { return "Missing compulsory field [surname]"; } |
|
1334 | + if (!array_key_exists("email", $attributes)) { return "Missing compulsory field [email]"; } |
|
1335 | + if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
|
1336 | + if (empty($attributes["container"])) { return "Container attribute must be an array or string."; } |
|
1337 | + |
|
1338 | + if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) { |
|
1348 | 1339 | throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
1349 | 1340 | } |
1350 | 1341 | |
1351 | 1342 | if (!array_key_exists("display_name", $attributes)) { |
1352 | - $attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"]; |
|
1343 | + $attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"]; |
|
1353 | 1344 | } |
1354 | 1345 | |
1355 | 1346 | // Translate the schema |
@@ -1372,20 +1363,20 @@ discard block |
||
1372 | 1363 | // Determine the container |
1373 | 1364 | if (is_array($attributes['container'])) { |
1374 | 1365 | $attributes["container"] = array_reverse($attributes["container"]); |
1375 | - $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
|
1366 | + $attributes["container"] = "OU=".implode(",OU=", $attributes["container"]); |
|
1376 | 1367 | } |
1377 | 1368 | // we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2 |
1378 | 1369 | unset($add['unicodePwd']); |
1379 | 1370 | |
1380 | 1371 | // Add the entry |
1381 | - $result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
|
1372 | + $result = ldap_add($ds = $this->adldap->getLdapConnection(), $dn = "CN=".$add["cn"][0].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add); |
|
1382 | 1373 | if ($result != true) { |
1383 | 1374 | error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
1384 | 1375 | return false; |
1385 | 1376 | } |
1386 | 1377 | |
1387 | 1378 | // now password can be added to still disabled account |
1388 | - if (array_key_exists("password",$attributes)) |
|
1379 | + if (array_key_exists("password", $attributes)) |
|
1389 | 1380 | { |
1390 | 1381 | if (!$this->setPassword($dn, $attributes['password'])) return false; |
1391 | 1382 | |
@@ -1412,13 +1403,13 @@ discard block |
||
1412 | 1403 | */ |
1413 | 1404 | public function encodePassword($password) |
1414 | 1405 | { |
1415 | - $password="\"".$password."\""; |
|
1406 | + $password = "\"".$password."\""; |
|
1416 | 1407 | if (function_exists('mb_convert_encoding')) |
1417 | 1408 | { |
1418 | 1409 | return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
1419 | 1410 | } |
1420 | - $encoded=""; |
|
1421 | - for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
1411 | + $encoded = ""; |
|
1412 | + for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; } |
|
1422 | 1413 | return $encoded; |
1423 | 1414 | } |
1424 | 1415 | |
@@ -1435,7 +1426,7 @@ discard block |
||
1435 | 1426 | */ |
1436 | 1427 | public function setPassword($dn, $password) |
1437 | 1428 | { |
1438 | - $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
|
1429 | + $result = ldap_mod_replace($ds = $this->adldap->getLdapConnection(), $dn, array( |
|
1439 | 1430 | 'unicodePwd' => $this->encodePassword($password), |
1440 | 1431 | )); |
1441 | 1432 | if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
@@ -1463,7 +1454,7 @@ discard block |
||
1463 | 1454 | * @param string $old_password old password for password change, if supported |
1464 | 1455 | * @return bool |
1465 | 1456 | */ |
1466 | - public function password($username, $password, $isGUID = false, $old_password=null) |
|
1457 | + public function password($username, $password, $isGUID = false, $old_password = null) |
|
1467 | 1458 | { |
1468 | 1459 | if ($username === NULL) { return false; } |
1469 | 1460 | if ($password === NULL) { return false; } |
@@ -1477,7 +1468,7 @@ discard block |
||
1477 | 1468 | return false; |
1478 | 1469 | } |
1479 | 1470 | |
1480 | - $add=array(); |
|
1471 | + $add = array(); |
|
1481 | 1472 | |
1482 | 1473 | if (empty($old_password) || !function_exists('ldap_modify_batch')) { |
1483 | 1474 | $add["unicodePwd"][0] = $this->encodePassword($password); |
@@ -1499,11 +1490,11 @@ discard block |
||
1499 | 1490 | ); |
1500 | 1491 | $result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods); |
1501 | 1492 | } |
1502 | - if ($result === false){ |
|
1493 | + if ($result === false) { |
|
1503 | 1494 | $err = ldap_errno($this->adldap->getLdapConnection()); |
1504 | 1495 | if ($err) { |
1505 | - $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
1506 | - if($err == 53) { |
|
1496 | + $msg = 'Error '.$err.': '.ldap_err2str($err).'.'; |
|
1497 | + if ($err == 53) { |
|
1507 | 1498 | $msg .= ' Your password might not match the password policy.'; |
1508 | 1499 | } |
1509 | 1500 | throw new adLDAPException($msg); |
@@ -1541,13 +1532,13 @@ discard block |
||
1541 | 1532 | $mod = $this->adldap->adldap_schema($attributes); |
1542 | 1533 | |
1543 | 1534 | // Check to see if this is an enabled status update |
1544 | - if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
1535 | + if (!$mod && !array_key_exists("enabled", $attributes)) { |
|
1545 | 1536 | return false; |
1546 | 1537 | } |
1547 | 1538 | |
1548 | 1539 | // Set the account control attribute (only if specified) |
1549 | - if (array_key_exists("enabled", $attributes)){ |
|
1550 | - if ($attributes["enabled"]){ |
|
1540 | + if (array_key_exists("enabled", $attributes)) { |
|
1541 | + if ($attributes["enabled"]) { |
|
1551 | 1542 | $controlOptions = array("NORMAL_ACCOUNT"); |
1552 | 1543 | } |
1553 | 1544 | else { |
@@ -1561,14 +1552,14 @@ discard block |
||
1561 | 1552 | if ($mod) |
1562 | 1553 | { |
1563 | 1554 | // Do the update |
1564 | - $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
|
1555 | + $result = @ldap_modify($ds = $this->adldap->getLdapConnection(), $userDn, $mod); |
|
1565 | 1556 | if ($result == false) { |
1566 | 1557 | if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***'; |
1567 | 1558 | error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
1568 | 1559 | return false; |
1569 | 1560 | } |
1570 | 1561 | } |
1571 | - if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
1562 | + if (array_key_exists("password", $attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
1572 | 1563 | { |
1573 | 1564 | return false; |
1574 | 1565 | } |
@@ -1591,10 +1582,10 @@ discard block |
||
1591 | 1582 | */ |
1592 | 1583 | public function create($attributes) |
1593 | 1584 | { |
1594 | - if (!is_array($attributes)){ return "Attributes must be an array"; } |
|
1595 | - if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; } |
|
1596 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
1597 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
1585 | + if (!is_array($attributes)) { return "Attributes must be an array"; } |
|
1586 | + if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; } |
|
1587 | + if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
|
1588 | + if (empty($attributes["container"])) { return "Container attribute must be an array or string."; } |
|
1598 | 1589 | |
1599 | 1590 | //$member_array = array(); |
1600 | 1591 | //$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com"; |
@@ -1610,9 +1601,9 @@ discard block |
||
1610 | 1601 | // Determine the container |
1611 | 1602 | if (is_array($attributes['container'])) { |
1612 | 1603 | $attributes["container"] = array_reverse($attributes["container"]); |
1613 | - $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
|
1604 | + $attributes["container"] = "OU=".implode(",OU=", $attributes["container"]); |
|
1614 | 1605 | } |
1615 | - $result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
|
1606 | + $result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add); |
|
1616 | 1607 | if ($result != true) { |
1617 | 1608 | return false; |
1618 | 1609 | } |
@@ -1643,10 +1634,10 @@ discard block |
||
1643 | 1634 | * @author Port by Andreas Gohr <[email protected]> |
1644 | 1635 | * @return string |
1645 | 1636 | */ |
1646 | - public function ldapSlashes($str){ |
|
1637 | + public function ldapSlashes($str) { |
|
1647 | 1638 | return preg_replace_callback( |
1648 | 1639 | '/([\x00-\x1F\*\(\)\\\\])/', |
1649 | - function ($matches) { |
|
1640 | + function($matches) { |
|
1650 | 1641 | return "\\".join("", unpack("H2", $matches[1])); |
1651 | 1642 | }, |
1652 | 1643 | $str |
@@ -132,12 +132,21 @@ discard block |
||
132 | 132 | public static function get_adldap(array &$config=null) |
133 | 133 | { |
134 | 134 | static $adldap = array(); |
135 | - if (!$config) $config =& $GLOBALS['egw_info']['server']; |
|
135 | + if (!$config) |
|
136 | + { |
|
137 | + $config =& $GLOBALS['egw_info']['server']; |
|
138 | + } |
|
136 | 139 | |
137 | 140 | if (!isset($adldap[$config['ads_domain']])) |
138 | 141 | { |
139 | - if (empty($config['ads_host'])) throw new Exception("Required ADS host name(s) missing!"); |
|
140 | - if (empty($config['ads_domain'])) throw new Exception("Required ADS domain missing!"); |
|
142 | + if (empty($config['ads_host'])) |
|
143 | + { |
|
144 | + throw new Exception("Required ADS host name(s) missing!"); |
|
145 | + } |
|
146 | + if (empty($config['ads_domain'])) |
|
147 | + { |
|
148 | + throw new Exception("Required ADS domain missing!"); |
|
149 | + } |
|
141 | 150 | |
142 | 151 | $base_dn_parts = array(); |
143 | 152 | foreach(explode('.', $config['ads_domain']) as $dc) |
@@ -156,7 +165,10 @@ discard block |
||
156 | 165 | 'charset' => translation::charset(), |
157 | 166 | ); |
158 | 167 | $adldap[$config['ads_domain']] = new adLDAP_egw($options); |
159 | - if (self::$debug) error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace()); |
|
168 | + if (self::$debug) |
|
169 | + { |
|
170 | + error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace()); |
|
171 | + } |
|
160 | 172 | } |
161 | 173 | //else error_log(__METHOD__."() returning cached adLDAP ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace()); |
162 | 174 | return $adldap[$config['ads_domain']]; |
@@ -237,7 +249,10 @@ discard block |
||
237 | 249 | throw new egw_exception_wrong_userinput("Wrong or not configured ADS context '$context' (baseDN='$base')!"); |
238 | 250 | } |
239 | 251 | $container = $matches[1]; |
240 | - if (self::$debug) error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container)); |
|
252 | + if (self::$debug) |
|
253 | + { |
|
254 | + error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container)); |
|
255 | + } |
|
241 | 256 | return $container; |
242 | 257 | } |
243 | 258 | |
@@ -330,10 +345,16 @@ discard block |
||
330 | 345 | */ |
331 | 346 | public function read($account_id) |
332 | 347 | { |
333 | - if (!(int)$account_id) return false; |
|
348 | + if (!(int)$account_id) |
|
349 | + { |
|
350 | + return false; |
|
351 | + } |
|
334 | 352 | |
335 | 353 | $ret = $account_id < 0 ? $this->_read_group($account_id) : $this->_read_user($account_id); |
336 | - if (self::$debug) error_log(__METHOD__."($account_id) returning ".array2string($ret)); |
|
354 | + if (self::$debug) |
|
355 | + { |
|
356 | + error_log(__METHOD__."($account_id) returning ".array2string($ret)); |
|
357 | + } |
|
337 | 358 | return $ret; |
338 | 359 | } |
339 | 360 | |
@@ -366,7 +387,10 @@ discard block |
||
366 | 387 | } |
367 | 388 | $ret = $is_group ? $this->_save_group($data, $old) : $this->_save_user($data, $old); |
368 | 389 | |
369 | - if (self::$debug) error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret)); |
|
390 | + if (self::$debug) |
|
391 | + { |
|
392 | + error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret)); |
|
393 | + } |
|
370 | 394 | return $ret; |
371 | 395 | } |
372 | 396 | |
@@ -396,7 +420,10 @@ discard block |
||
396 | 420 | { |
397 | 421 | $ret = $this->adldap->user()->delete($account_lid); |
398 | 422 | } |
399 | - if (self::$debug) error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret)); |
|
423 | + if (self::$debug) |
|
424 | + { |
|
425 | + error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret)); |
|
426 | + } |
|
400 | 427 | return $ret; |
401 | 428 | } |
402 | 429 | |
@@ -558,11 +585,17 @@ discard block |
||
558 | 585 | protected static function _when2ts($_when) |
559 | 586 | { |
560 | 587 | static $utc=null; |
561 | - if (!isset($utc)) $utc = new DateTimeZone('UTC'); |
|
588 | + if (!isset($utc)) |
|
589 | + { |
|
590 | + $utc = new DateTimeZone('UTC'); |
|
591 | + } |
|
562 | 592 | |
563 | 593 | list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
564 | 594 | $datetime = egw_time::createFromFormat(self::WHEN_FORMAT, $when, $utc); |
565 | - if (egw_time::$server_timezone) $datetime->setTimezone(egw_time::$server_timezone); |
|
595 | + if (egw_time::$server_timezone) |
|
596 | + { |
|
597 | + $datetime->setTimezone(egw_time::$server_timezone); |
|
598 | + } |
|
566 | 599 | |
567 | 600 | return $datetime->getTimestamp(); |
568 | 601 | } |
@@ -579,12 +612,15 @@ discard block |
||
579 | 612 | { |
580 | 613 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
581 | 614 | |
582 | - if (!$old) // new entry |
|
615 | + if (!$old) |
|
616 | + { |
|
617 | + // new entry |
|
583 | 618 | { |
584 | 619 | static $new2adldap = array( |
585 | 620 | 'account_lid' => 'group_name', |
586 | 621 | 'account_description' => 'description', |
587 | 622 | ); |
623 | + } |
|
588 | 624 | $attributes = array(); |
589 | 625 | foreach($new2adldap as $egw => $adldap) |
590 | 626 | { |
@@ -664,7 +700,9 @@ discard block |
||
664 | 700 | $data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname']; |
665 | 701 | } |
666 | 702 | |
667 | - if (($new_entry = !$old)) // new entry |
|
703 | + if (($new_entry = !$old)) |
|
704 | + { |
|
705 | + // new entry |
|
668 | 706 | { |
669 | 707 | static $new2adldap = array( |
670 | 708 | 'account_lid' => 'username', |
@@ -675,6 +713,7 @@ discard block |
||
675 | 713 | 'account_passwd' => 'password', |
676 | 714 | 'account_status' => 'enabled', |
677 | 715 | ); |
716 | + } |
|
678 | 717 | $attributes = array(); |
679 | 718 | foreach($new2adldap as $egw => $adldap) |
680 | 719 | { |
@@ -683,7 +722,10 @@ discard block |
||
683 | 722 | { |
684 | 723 | continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
685 | 724 | } |
686 | - if (isset($data[$egw])) $attributes[$adldap] = $data[$egw]; |
|
725 | + if (isset($data[$egw])) |
|
726 | + { |
|
727 | + $attributes[$adldap] = $data[$egw]; |
|
728 | + } |
|
687 | 729 | } |
688 | 730 | $attributes['enabled'] = !isset($data['account_status']) || $data['account_status'] === 'A'; |
689 | 731 | $attributes['container'] = $this->_get_container(); |
@@ -769,7 +811,11 @@ discard block |
||
769 | 811 | self::convertUnixTimeToWindowsTime($data[$egw]); |
770 | 812 | break; |
771 | 813 | case 'account_status': |
772 | - if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
814 | + if ($new_entry && empty($data['account_passwd'])) |
|
815 | + { |
|
816 | + continue; |
|
817 | + } |
|
818 | + // cant active new account without passwd! |
|
773 | 819 | $attributes[$adldap] = $data[$egw] == 'A'; |
774 | 820 | break; |
775 | 821 | case 'account_lastpwd_change': |
@@ -849,8 +895,14 @@ discard block |
||
849 | 895 | } |
850 | 896 | // if it's a limited query, check if the unlimited query is cached |
851 | 897 | $start = $param['start']; |
852 | - if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15; |
|
853 | - if (!($offset = $param['offset'])) $offset = $maxmatchs; |
|
898 | + if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) |
|
899 | + { |
|
900 | + $maxmatchs = 15; |
|
901 | + } |
|
902 | + if (!($offset = $param['offset'])) |
|
903 | + { |
|
904 | + $offset = $maxmatchs; |
|
905 | + } |
|
854 | 906 | unset($param['start']); |
855 | 907 | unset($param['offset']); |
856 | 908 | $unl_serial = serialize($param); |
@@ -1048,7 +1100,10 @@ discard block |
||
1048 | 1100 | $attrs ? $attrs : self::$default_attributes); |
1049 | 1101 | if (!$sri) |
1050 | 1102 | { |
1051 | - if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...'); |
|
1103 | + if (self::$debug) |
|
1104 | + { |
|
1105 | + error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...'); |
|
1106 | + } |
|
1052 | 1107 | $sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter, |
1053 | 1108 | $attrs ? $attrs : self::$default_attributes); |
1054 | 1109 | } |
@@ -1057,7 +1112,10 @@ discard block |
||
1057 | 1112 | { |
1058 | 1113 | foreach($allValues as $key => $data) |
1059 | 1114 | { |
1060 | - if ($key === 'count') continue; |
|
1115 | + if ($key === 'count') |
|
1116 | + { |
|
1117 | + continue; |
|
1118 | + } |
|
1061 | 1119 | |
1062 | 1120 | if ($account_type && !($account_type == 'u' && $data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT || |
1063 | 1121 | $account_type == 'g' && $data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP)) |
@@ -1075,7 +1133,10 @@ discard block |
||
1075 | 1133 | $attrs ? $data : translation::convert($data['samaccountname'][0], 'utf-8'); |
1076 | 1134 | } |
1077 | 1135 | } |
1078 | - else if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues)); |
|
1136 | + else if (self::$debug) |
|
1137 | + { |
|
1138 | + error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues)); |
|
1139 | + } |
|
1079 | 1140 | |
1080 | 1141 | //error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returning ".array2string($accounts).' '.function_backtrace()); |
1081 | 1142 | return $accounts; |
@@ -1112,7 +1173,10 @@ discard block |
||
1112 | 1173 | break; |
1113 | 1174 | } |
1114 | 1175 | } |
1115 | - if (self::$debug) error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret)); |
|
1176 | + if (self::$debug) |
|
1177 | + { |
|
1178 | + error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret)); |
|
1179 | + } |
|
1116 | 1180 | return $ret; |
1117 | 1181 | } |
1118 | 1182 | |
@@ -1154,7 +1218,10 @@ discard block |
||
1154 | 1218 | */ |
1155 | 1219 | function memberships($account_id) |
1156 | 1220 | { |
1157 | - if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0) return false; |
|
1221 | + if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0) |
|
1222 | + { |
|
1223 | + return false; |
|
1224 | + } |
|
1158 | 1225 | |
1159 | 1226 | return $data['memberships']; |
1160 | 1227 | } |
@@ -1169,7 +1236,10 @@ discard block |
||
1169 | 1236 | */ |
1170 | 1237 | function members($gid) |
1171 | 1238 | { |
1172 | - if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0) return false; |
|
1239 | + if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0) |
|
1240 | + { |
|
1241 | + return false; |
|
1242 | + } |
|
1173 | 1243 | |
1174 | 1244 | return $data['members']; |
1175 | 1245 | } |
@@ -1183,7 +1253,10 @@ discard block |
||
1183 | 1253 | */ |
1184 | 1254 | function set_memberships($groups,$account_id) |
1185 | 1255 | { |
1186 | - if (!($account = $this->id2name($account_id))) return; |
|
1256 | + if (!($account = $this->id2name($account_id))) |
|
1257 | + { |
|
1258 | + return; |
|
1259 | + } |
|
1187 | 1260 | $current = array_keys($this->memberships($account_id)); |
1188 | 1261 | |
1189 | 1262 | $changed = 0; |
@@ -1200,7 +1273,10 @@ discard block |
||
1200 | 1273 | $changed += (int)$ok; |
1201 | 1274 | } |
1202 | 1275 | } |
1203 | - if (self::$debug) error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed"); |
|
1276 | + if (self::$debug) |
|
1277 | + { |
|
1278 | + error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed"); |
|
1279 | + } |
|
1204 | 1280 | return $changed; |
1205 | 1281 | } |
1206 | 1282 | |
@@ -1213,7 +1289,10 @@ discard block |
||
1213 | 1289 | */ |
1214 | 1290 | function set_members($users, $gid) |
1215 | 1291 | { |
1216 | - if (!($group = $this->id2name($gid))) return; |
|
1292 | + if (!($group = $this->id2name($gid))) |
|
1293 | + { |
|
1294 | + return; |
|
1295 | + } |
|
1217 | 1296 | $current = array_keys($this->members($gid)); |
1218 | 1297 | |
1219 | 1298 | $changed = 0; |
@@ -1230,7 +1309,10 @@ discard block |
||
1230 | 1309 | $changed += (int)$ok; |
1231 | 1310 | } |
1232 | 1311 | } |
1233 | - if (self::$debug) error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed"); |
|
1312 | + if (self::$debug) |
|
1313 | + { |
|
1314 | + error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed"); |
|
1315 | + } |
|
1234 | 1316 | return $changed; |
1235 | 1317 | } |
1236 | 1318 | } |
@@ -1284,8 +1366,10 @@ discard block |
||
1284 | 1366 | * |
1285 | 1367 | * @return adLDAPUsers |
1286 | 1368 | */ |
1287 | - public function user() { |
|
1288 | - if (!$this->userClass) { |
|
1369 | + public function user() |
|
1370 | + { |
|
1371 | + if (!$this->userClass) |
|
1372 | + { |
|
1289 | 1373 | $this->userClass = new adLDAPUsers_egw($this); |
1290 | 1374 | } |
1291 | 1375 | return $this->userClass; |
@@ -1296,8 +1380,10 @@ discard block |
||
1296 | 1380 | * |
1297 | 1381 | * @return adLDAPGroups |
1298 | 1382 | */ |
1299 | - public function group() { |
|
1300 | - if (!$this->groupClass) { |
|
1383 | + public function group() |
|
1384 | + { |
|
1385 | + if (!$this->groupClass) |
|
1386 | + { |
|
1301 | 1387 | $this->groupClass = new adLDAPGroups_egw($this); |
1302 | 1388 | } |
1303 | 1389 | return $this->groupClass; |
@@ -1308,8 +1394,10 @@ discard block |
||
1308 | 1394 | * |
1309 | 1395 | * @return adLDAPUtils |
1310 | 1396 | */ |
1311 | - public function utilities() { |
|
1312 | - if (!$this->utilClass) { |
|
1397 | + public function utilities() |
|
1398 | + { |
|
1399 | + if (!$this->utilClass) |
|
1400 | + { |
|
1313 | 1401 | $this->utilClass = new adLDAPUtils_egw($this); |
1314 | 1402 | } |
1315 | 1403 | return $this->utilClass; |
@@ -1337,18 +1425,32 @@ discard block |
||
1337 | 1425 | public function create($attributes) |
1338 | 1426 | { |
1339 | 1427 | // Check for compulsory fields |
1340 | - if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; } |
|
1341 | - if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; } |
|
1342 | - if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; } |
|
1343 | - if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; } |
|
1344 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
1345 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
1346 | - |
|
1347 | - if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){ |
|
1428 | + if (!array_key_exists("username", $attributes)) |
|
1429 | + { |
|
1430 | +return "Missing compulsory field [username]"; } |
|
1431 | + if (!array_key_exists("firstname", $attributes)) |
|
1432 | + { |
|
1433 | +return "Missing compulsory field [firstname]"; } |
|
1434 | + if (!array_key_exists("surname", $attributes)) |
|
1435 | + { |
|
1436 | +return "Missing compulsory field [surname]"; } |
|
1437 | + if (!array_key_exists("email", $attributes)) |
|
1438 | + { |
|
1439 | +return "Missing compulsory field [email]"; } |
|
1440 | + if (!array_key_exists("container", $attributes)) |
|
1441 | + { |
|
1442 | +return "Missing compulsory field [container]"; } |
|
1443 | + if (empty($attributes["container"])) |
|
1444 | + { |
|
1445 | +return "Container attribute must be an array or string."; } |
|
1446 | + |
|
1447 | + if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) |
|
1448 | + { |
|
1348 | 1449 | throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
1349 | 1450 | } |
1350 | 1451 | |
1351 | - if (!array_key_exists("display_name", $attributes)) { |
|
1452 | + if (!array_key_exists("display_name", $attributes)) |
|
1453 | + { |
|
1352 | 1454 | $attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"]; |
1353 | 1455 | } |
1354 | 1456 | |
@@ -1370,7 +1472,8 @@ discard block |
||
1370 | 1472 | $add["userAccountControl"][0] = $this->accountControl($control_options); |
1371 | 1473 | |
1372 | 1474 | // Determine the container |
1373 | - if (is_array($attributes['container'])) { |
|
1475 | + if (is_array($attributes['container'])) |
|
1476 | + { |
|
1374 | 1477 | $attributes["container"] = array_reverse($attributes["container"]); |
1375 | 1478 | $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
1376 | 1479 | } |
@@ -1379,7 +1482,8 @@ discard block |
||
1379 | 1482 | |
1380 | 1483 | // Add the entry |
1381 | 1484 | $result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
1382 | - if ($result != true) { |
|
1485 | + if ($result != true) |
|
1486 | + { |
|
1383 | 1487 | error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
1384 | 1488 | return false; |
1385 | 1489 | } |
@@ -1387,7 +1491,10 @@ discard block |
||
1387 | 1491 | // now password can be added to still disabled account |
1388 | 1492 | if (array_key_exists("password",$attributes)) |
1389 | 1493 | { |
1390 | - if (!$this->setPassword($dn, $attributes['password'])) return false; |
|
1494 | + if (!$this->setPassword($dn, $attributes['password'])) |
|
1495 | + { |
|
1496 | + return false; |
|
1497 | + } |
|
1391 | 1498 | |
1392 | 1499 | // now account can be enabled |
1393 | 1500 | if ($attributes["enabled"]) |
@@ -1395,7 +1502,10 @@ discard block |
||
1395 | 1502 | $control_options = array("NORMAL_ACCOUNT"); |
1396 | 1503 | $mod = array("userAccountControl" => $this->accountControl($control_options)); |
1397 | 1504 | $result = ldap_modify($ds, $dn, $mod); |
1398 | - if (!$result) error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
|
1505 | + if (!$result) |
|
1506 | + { |
|
1507 | + error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
|
1508 | + } |
|
1399 | 1509 | } |
1400 | 1510 | } |
1401 | 1511 | |
@@ -1418,7 +1528,9 @@ discard block |
||
1418 | 1528 | return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
1419 | 1529 | } |
1420 | 1530 | $encoded=""; |
1421 | - for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
1531 | + for ($i=0; $i <strlen($password); $i++) |
|
1532 | + { |
|
1533 | +$encoded.="{$password{$i}}\000"; } |
|
1422 | 1534 | return $encoded; |
1423 | 1535 | } |
1424 | 1536 | |
@@ -1438,7 +1550,10 @@ discard block |
||
1438 | 1550 | $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
1439 | 1551 | 'unicodePwd' => $this->encodePassword($password), |
1440 | 1552 | )); |
1441 | - if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
1553 | + if (!$result) |
|
1554 | + { |
|
1555 | + error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
1556 | + } |
|
1442 | 1557 | return $result; |
1443 | 1558 | } |
1444 | 1559 | |
@@ -1465,26 +1580,36 @@ discard block |
||
1465 | 1580 | */ |
1466 | 1581 | public function password($username, $password, $isGUID = false, $old_password=null) |
1467 | 1582 | { |
1468 | - if ($username === NULL) { return false; } |
|
1469 | - if ($password === NULL) { return false; } |
|
1470 | - if (!$this->adldap->getLdapBind()) { return false; } |
|
1471 | - if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
1583 | + if ($username === NULL) |
|
1584 | + { |
|
1585 | +return false; } |
|
1586 | + if ($password === NULL) |
|
1587 | + { |
|
1588 | +return false; } |
|
1589 | + if (!$this->adldap->getLdapBind()) |
|
1590 | + { |
|
1591 | +return false; } |
|
1592 | + if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) |
|
1593 | + { |
|
1472 | 1594 | throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
1473 | 1595 | } |
1474 | 1596 | |
1475 | 1597 | $userDn = $this->dn($username, $isGUID); |
1476 | - if ($userDn === false) { |
|
1598 | + if ($userDn === false) |
|
1599 | + { |
|
1477 | 1600 | return false; |
1478 | 1601 | } |
1479 | 1602 | |
1480 | 1603 | $add=array(); |
1481 | 1604 | |
1482 | - if (empty($old_password) || !function_exists('ldap_modify_batch')) { |
|
1605 | + if (empty($old_password) || !function_exists('ldap_modify_batch')) |
|
1606 | + { |
|
1483 | 1607 | $add["unicodePwd"][0] = $this->encodePassword($password); |
1484 | 1608 | |
1485 | 1609 | $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $add); |
1486 | 1610 | } |
1487 | - else { |
|
1611 | + else |
|
1612 | + { |
|
1488 | 1613 | $mods = array( |
1489 | 1614 | array( |
1490 | 1615 | "attrib" => "unicodePwd", |
@@ -1499,16 +1624,20 @@ discard block |
||
1499 | 1624 | ); |
1500 | 1625 | $result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods); |
1501 | 1626 | } |
1502 | - if ($result === false){ |
|
1627 | + if ($result === false) |
|
1628 | + { |
|
1503 | 1629 | $err = ldap_errno($this->adldap->getLdapConnection()); |
1504 | - if ($err) { |
|
1630 | + if ($err) |
|
1631 | + { |
|
1505 | 1632 | $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
1506 | - if($err == 53) { |
|
1633 | + if($err == 53) |
|
1634 | + { |
|
1507 | 1635 | $msg .= ' Your password might not match the password policy.'; |
1508 | 1636 | } |
1509 | 1637 | throw new adLDAPException($msg); |
1510 | 1638 | } |
1511 | - else { |
|
1639 | + else |
|
1640 | + { |
|
1512 | 1641 | return false; |
1513 | 1642 | } |
1514 | 1643 | } |
@@ -1526,14 +1655,18 @@ discard block |
||
1526 | 1655 | */ |
1527 | 1656 | public function modify($username, $attributes, $isGUID = false) |
1528 | 1657 | { |
1529 | - if ($username === NULL) { return "Missing compulsory field [username]"; } |
|
1530 | - if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
1658 | + if ($username === NULL) |
|
1659 | + { |
|
1660 | +return "Missing compulsory field [username]"; } |
|
1661 | + if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) |
|
1662 | + { |
|
1531 | 1663 | throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.'); |
1532 | 1664 | } |
1533 | 1665 | |
1534 | 1666 | // Find the dn of the user |
1535 | 1667 | $userDn = $this->dn($username, $isGUID); |
1536 | - if ($userDn === false) { |
|
1668 | + if ($userDn === false) |
|
1669 | + { |
|
1537 | 1670 | return false; |
1538 | 1671 | } |
1539 | 1672 | |
@@ -1541,16 +1674,20 @@ discard block |
||
1541 | 1674 | $mod = $this->adldap->adldap_schema($attributes); |
1542 | 1675 | |
1543 | 1676 | // Check to see if this is an enabled status update |
1544 | - if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
1677 | + if (!$mod && !array_key_exists("enabled", $attributes)) |
|
1678 | + { |
|
1545 | 1679 | return false; |
1546 | 1680 | } |
1547 | 1681 | |
1548 | 1682 | // Set the account control attribute (only if specified) |
1549 | - if (array_key_exists("enabled", $attributes)){ |
|
1550 | - if ($attributes["enabled"]){ |
|
1683 | + if (array_key_exists("enabled", $attributes)) |
|
1684 | + { |
|
1685 | + if ($attributes["enabled"]) |
|
1686 | + { |
|
1551 | 1687 | $controlOptions = array("NORMAL_ACCOUNT"); |
1552 | 1688 | } |
1553 | - else { |
|
1689 | + else |
|
1690 | + { |
|
1554 | 1691 | $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE"); |
1555 | 1692 | } |
1556 | 1693 | $mod["userAccountControl"][0] = $this->accountControl($controlOptions); |
@@ -1562,14 +1699,18 @@ discard block |
||
1562 | 1699 | { |
1563 | 1700 | // Do the update |
1564 | 1701 | $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
1565 | - if ($result == false) { |
|
1566 | - if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***'; |
|
1702 | + if ($result == false) |
|
1703 | + { |
|
1704 | + if (isset($mod['unicodePwd'])) |
|
1705 | + { |
|
1706 | + $mod['unicodePwd'] = '***'; |
|
1707 | + } |
|
1567 | 1708 | error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
1568 | 1709 | return false; |
1569 | 1710 | } |
1570 | 1711 | } |
1571 | 1712 | if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
1572 | - { |
|
1713 | + { |
|
1573 | 1714 | return false; |
1574 | 1715 | } |
1575 | 1716 | return true; |
@@ -1591,10 +1732,18 @@ discard block |
||
1591 | 1732 | */ |
1592 | 1733 | public function create($attributes) |
1593 | 1734 | { |
1594 | - if (!is_array($attributes)){ return "Attributes must be an array"; } |
|
1595 | - if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; } |
|
1596 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
1597 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
1735 | + if (!is_array($attributes)) |
|
1736 | + { |
|
1737 | +return "Attributes must be an array"; } |
|
1738 | + if (!array_key_exists("group_name", $attributes)) |
|
1739 | + { |
|
1740 | +return "Missing compulsory field [group_name]"; } |
|
1741 | + if (!array_key_exists("container", $attributes)) |
|
1742 | + { |
|
1743 | +return "Missing compulsory field [container]"; } |
|
1744 | + if (empty($attributes["container"])) |
|
1745 | + { |
|
1746 | +return "Container attribute must be an array or string."; } |
|
1598 | 1747 | |
1599 | 1748 | //$member_array = array(); |
1600 | 1749 | //$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com"; |
@@ -1604,16 +1753,21 @@ discard block |
||
1604 | 1753 | $add["cn"] = $attributes["group_name"]; |
1605 | 1754 | $add["samaccountname"] = $attributes["group_name"]; |
1606 | 1755 | $add["objectClass"] = "Group"; |
1607 | - if (!empty($attributes["description"])) $add["description"] = $attributes["description"]; |
|
1756 | + if (!empty($attributes["description"])) |
|
1757 | + { |
|
1758 | + $add["description"] = $attributes["description"]; |
|
1759 | + } |
|
1608 | 1760 | //$add["member"] = $member_array; UNTESTED |
1609 | 1761 | |
1610 | 1762 | // Determine the container |
1611 | - if (is_array($attributes['container'])) { |
|
1763 | + if (is_array($attributes['container'])) |
|
1764 | + { |
|
1612 | 1765 | $attributes["container"] = array_reverse($attributes["container"]); |
1613 | 1766 | $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
1614 | 1767 | } |
1615 | 1768 | $result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
1616 | - if ($result != true) { |
|
1769 | + if ($result != true) |
|
1770 | + { |
|
1617 | 1771 | return false; |
1618 | 1772 | } |
1619 | 1773 | return true; |
@@ -1643,10 +1797,12 @@ discard block |
||
1643 | 1797 | * @author Port by Andreas Gohr <[email protected]> |
1644 | 1798 | * @return string |
1645 | 1799 | */ |
1646 | - public function ldapSlashes($str){ |
|
1800 | + public function ldapSlashes($str) |
|
1801 | + { |
|
1647 | 1802 | return preg_replace_callback( |
1648 | 1803 | '/([\x00-\x1F\*\(\)\\\\])/', |
1649 | - function ($matches) { |
|
1804 | + function ($matches) |
|
1805 | + { |
|
1650 | 1806 | return "\\".join("", unpack("H2", $matches[1])); |
1651 | 1807 | }, |
1652 | 1808 | $str |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * If no account_id is set in data the account is added and the new id is set in $data. |
191 | 191 | * |
192 | 192 | * @param array $data array with account-data |
193 | - * @return int|boolean the account_id or false on error |
|
193 | + * @return false|string the account_id or false on error |
|
194 | 194 | */ |
195 | 195 | function save(&$data) |
196 | 196 | { |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | * |
996 | 996 | * @param int $_account_id |
997 | 997 | * @param string $ip |
998 | - * @return int lastlogin time |
|
998 | + * @return boolean lastlogin time |
|
999 | 999 | */ |
1000 | 1000 | function update_lastlogin($_account_id, $ip) |
1001 | 1001 | { |
@@ -1097,7 +1097,6 @@ discard block |
||
1097 | 1097 | * @param int $gid gidnumber of group to set |
1098 | 1098 | * @param array $objectclass =null should we set the member and uniqueMember attributes (groupOf(Unique)Names|univentionGroup) (default detect it) |
1099 | 1099 | * @param string $use_cn =null if set $cn is used instead $gid and the attributes are returned, not written to ldap |
1100 | - * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it) |
|
1101 | 1100 | * @return boolean/array false on failure, array or true otherwise |
1102 | 1101 | */ |
1103 | 1102 | function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
@@ -962,7 +962,7 @@ |
||
962 | 962 | 'account_fullname' => 'cn', |
963 | 963 | ); |
964 | 964 | if (!isset($to_ldap[$which]) || $account_type === 'g') { |
965 | - return False; |
|
965 | + return False; |
|
966 | 966 | } |
967 | 967 | |
968 | 968 | $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber')); |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | */ |
85 | 85 | var $requiredObjectClasses = array( |
86 | 86 | 'user' => array( |
87 | - 'top','person','organizationalperson','inetorgperson','posixaccount','shadowaccount' |
|
87 | + 'top', 'person', 'organizationalperson', 'inetorgperson', 'posixaccount', 'shadowaccount' |
|
88 | 88 | ), |
89 | 89 | 'user-if-supported' => array( // these classes get added, if server supports them |
90 | 90 | 'mozillaabpersonalpha', 'mozillaorgperson', 'evolutionperson', |
91 | 91 | 'univentionperson', 'univentionmail', array('univentionobject', 'univentionObjectType' => 'users/user'), |
92 | 92 | ), |
93 | 93 | 'group' => array( |
94 | - 'top','posixgroup','groupofnames' |
|
94 | + 'top', 'posixgroup', 'groupofnames' |
|
95 | 95 | ), |
96 | 96 | 'group-if-supported' => array( // these classes get added, if servers supports them |
97 | 97 | 'univentiongroup', array('univentionobject', 'univentionObjectType' => 'groups/group'), |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | */ |
111 | 111 | var $group_mail_classes = array( |
112 | 112 | 'dbmailforwardingaddress' => 'mailforwardingaddress', |
113 | - 'dbmailuser' => array('mailforwardingaddress','uid'), |
|
114 | - 'qmailuser' => array('mailforwardingaddress','uid'), |
|
113 | + 'dbmailuser' => array('mailforwardingaddress', 'uid'), |
|
114 | + 'qmailuser' => array('mailforwardingaddress', 'uid'), |
|
115 | 115 | 'mailaccount' => 'mailalias', |
116 | 116 | 'univentiongroup' => array(false, false, true), |
117 | 117 | ); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | |
156 | 156 | $this->ldap = new ldap(true); |
157 | 157 | $this->ds = $this->ldap->ldapConnect($this->frontend->config['ldap_host'], |
158 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
158 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
159 | 159 | |
160 | 160 | $this->user_context = $this->frontend->config['ldap_context']; |
161 | 161 | $this->account_filter = $this->frontend->config['ldap_search_filter']; |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | { |
193 | 193 | $is_group = $data['account_id'] < 0 || $data['account_type'] === 'g'; |
194 | 194 | |
195 | - $data_utf8 = translation::convert($data,translation::charset(),'utf-8'); |
|
195 | + $data_utf8 = translation::convert($data, translation::charset(), 'utf-8'); |
|
196 | 196 | $members = $data['account_members']; |
197 | 197 | |
198 | 198 | if (!is_object($this->ldapServerInfo)) |
@@ -204,8 +204,7 @@ discard block |
||
204 | 204 | if ($data_utf8['account_id'] && $data_utf8['account_lid']) |
205 | 205 | { |
206 | 206 | // read the entry first, to check if the dn (account_lid) has changed |
207 | - $sri = $is_group ? ldap_search($this->ds,$this->group_context,'gidnumber='.abs($data['account_id'])) : |
|
208 | - ldap_search($this->ds,$this->user_context,'uidnumber='.$data['account_id']); |
|
207 | + $sri = $is_group ? ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($data['account_id'])) : ldap_search($this->ds, $this->user_context, 'uidnumber='.$data['account_id']); |
|
209 | 208 | $old = ldap_get_entries($this->ds, $sri); |
210 | 209 | |
211 | 210 | if (!$old['count']) |
@@ -217,9 +216,9 @@ discard block |
||
217 | 216 | $old = ldap::result2array($old[0]); |
218 | 217 | $old['objectclass'] = array_map('strtolower', $old['objectclass']); |
219 | 218 | $key = false; |
220 | - if ($is_group && ($key = array_search('namedobject',$old['objectclass'])) !== false || |
|
221 | - $is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'],0,3) != 'cn=') || |
|
222 | - !$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'],0,4) != 'uid=')) |
|
219 | + if ($is_group && ($key = array_search('namedobject', $old['objectclass'])) !== false || |
|
220 | + $is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 3) != 'cn=') || |
|
221 | + !$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 4) != 'uid=')) |
|
223 | 222 | { |
224 | 223 | // query the memberships to set them again later |
225 | 224 | if (!$is_group) |
@@ -248,7 +247,7 @@ discard block |
||
248 | 247 | } |
249 | 248 | } |
250 | 249 | // check if we need to write the objectclass: new entry or required object classes are missing |
251 | - if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'],$old['objectclass'])) |
|
250 | + if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'], $old['objectclass'])) |
|
252 | 251 | { |
253 | 252 | // additional objectclasse might be already set in $to_write or $old |
254 | 253 | if (!is_array($to_write['objectclass'])) |
@@ -257,7 +256,7 @@ discard block |
||
257 | 256 | } |
258 | 257 | if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
259 | 258 | { // as setting them later might loose eg. password, if we are not allowed to read them |
260 | - foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
|
259 | + foreach ($this->requiredObjectClasses[$is_group ? 'group-if-supported' : 'user-if-supported'] as $additional) |
|
261 | 260 | { |
262 | 261 | $add = array(); |
263 | 262 | if (is_array($additional)) |
@@ -279,8 +278,7 @@ discard block |
||
279 | 278 | { |
280 | 279 | if (!$data['account_lid']) return false; |
281 | 280 | |
282 | - $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
|
283 | - 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
281 | + $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
284 | 282 | } |
285 | 283 | // now we merge the user or group data |
286 | 284 | if ($is_group) |
@@ -289,23 +287,23 @@ discard block |
||
289 | 287 | $data['account_type'] = 'g'; |
290 | 288 | |
291 | 289 | $objectclass = $old ? $old['objectclass'] : $to_write['objectclass']; |
292 | - if ($members || !$old && array_intersect(array('groupofnames','groupofuniquenames','univentiongroup'), $objectclass)) |
|
290 | + if ($members || !$old && array_intersect(array('groupofnames', 'groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
293 | 291 | { |
294 | 292 | $to_write = array_merge($to_write, $this->set_members($members, $data['account_id'], $objectclass, $dn)); |
295 | 293 | } |
296 | 294 | // check if we should set a mail address and forwards for each member |
297 | - foreach($this->group_mail_classes as $objectclass => $forward) |
|
295 | + foreach ($this->group_mail_classes as $objectclass => $forward) |
|
298 | 296 | { |
299 | 297 | $extra_attr = false; |
300 | 298 | $keep_objectclass = false; |
301 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
299 | + if (is_array($forward)) list($forward, $extra_attr, $keep_objectclass) = $forward; |
|
302 | 300 | |
303 | 301 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
304 | - ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
302 | + ($old && in_array($objectclass, $old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
305 | 303 | { |
306 | 304 | if ($data_utf8['account_email']) // setting an email |
307 | 305 | { |
308 | - if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
|
306 | + if (!in_array($objectclass, $old ? $old['objectclass'] : $to_write['objectclass'])) |
|
309 | 307 | { |
310 | 308 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
311 | 309 | $to_write['objectclass'][] = $objectclass; |
@@ -319,19 +317,19 @@ discard block |
||
319 | 317 | $to_write[$forward] = array(); |
320 | 318 | foreach (array_keys($members) as $member) |
321 | 319 | { |
322 | - if (($email = $this->id2name($member,'account_email'))) |
|
320 | + if (($email = $this->id2name($member, 'account_email'))) |
|
323 | 321 | { |
324 | 322 | $to_write[$forward][] = $email; |
325 | 323 | } |
326 | 324 | } |
327 | 325 | } |
328 | 326 | } |
329 | - elseif($old) // remove the mail and forwards only for existing entries |
|
327 | + elseif ($old) // remove the mail and forwards only for existing entries |
|
330 | 328 | { |
331 | 329 | $to_write[static::MAIL_ATTR] = array(); |
332 | 330 | if ($forward) $to_write[$forward] = array(); |
333 | 331 | if ($extra_attr) $to_write[$extra_attr] = array(); |
334 | - if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
|
332 | + if (!$keep_objectclass && ($key = array_search($objectclass, $old['objectclass']))) |
|
335 | 333 | { |
336 | 334 | $to_write['objectclass'] = $old['objectclass']; |
337 | 335 | unset($to_write['objectclass'][$key]); |
@@ -345,7 +343,7 @@ discard block |
||
345 | 343 | } |
346 | 344 | else |
347 | 345 | { |
348 | - $to_write = $this->_merge_user($to_write,$data_utf8,!$old); |
|
346 | + $to_write = $this->_merge_user($to_write, $data_utf8, !$old); |
|
349 | 347 | // make sure multiple email-addresses in the mail attribute "survive" |
350 | 348 | if (isset($to_write[static::MAIL_ATTR]) && count($old[static::MAIL_ATTR]) > 1) |
351 | 349 | { |
@@ -364,22 +362,22 @@ discard block |
||
364 | 362 | } |
365 | 363 | |
366 | 364 | // remove memberuid when adding a group |
367 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
365 | + if (!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
368 | 366 | unset($to_write['memberuid']); |
369 | 367 | } |
370 | 368 | //echo "<p>ldap_".($old ? 'modify' : 'add')."(,$dn,".print_r($to_write,true).")</p>\n"; |
371 | 369 | // modifying or adding the entry |
372 | - if ($old && !@ldap_modify($this->ds,$dn,$to_write) || |
|
373 | - !$old && !@ldap_add($this->ds,$dn,$to_write)) |
|
370 | + if ($old && !@ldap_modify($this->ds, $dn, $to_write) || |
|
371 | + !$old && !@ldap_add($this->ds, $dn, $to_write)) |
|
374 | 372 | { |
375 | 373 | $err = true; |
376 | - if ($is_group && ($key = array_search('groupofnames',$to_write['objectclass'])) !== false) |
|
374 | + if ($is_group && ($key = array_search('groupofnames', $to_write['objectclass'])) !== false) |
|
377 | 375 | { |
378 | 376 | // try again with removed groupOfNames stuff, as I cant detect if posixGroup is a structural object |
379 | 377 | unset($to_write['objectclass'][$key]); |
380 | 378 | $to_write['objectclass'] = array_values($to_write['objectclass']); |
381 | 379 | unset($to_write['member']); |
382 | - $err = $old ? !ldap_modify($this->ds,$dn,$to_write) : !ldap_add($this->ds,$dn,$to_write); |
|
380 | + $err = $old ? !ldap_modify($this->ds, $dn, $to_write) : !ldap_add($this->ds, $dn, $to_write); |
|
383 | 381 | } |
384 | 382 | if ($err) |
385 | 383 | { |
@@ -389,7 +387,7 @@ discard block |
||
389 | 387 | } |
390 | 388 | if ($memberships) |
391 | 389 | { |
392 | - $this->set_memberships($memberships,$data['account_id']); |
|
390 | + $this->set_memberships($memberships, $data['account_id']); |
|
393 | 391 | } |
394 | 392 | return $data['account_id']; |
395 | 393 | } |
@@ -406,14 +404,14 @@ discard block |
||
406 | 404 | |
407 | 405 | if ($account_id < 0) |
408 | 406 | { |
409 | - $sri = ldap_search($this->ds, $this->group_context, 'gidnumber=' . abs($account_id)); |
|
407 | + $sri = ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($account_id)); |
|
410 | 408 | } |
411 | 409 | else |
412 | 410 | { |
413 | 411 | // remove the user's memberships |
414 | - $this->set_memberships(array(),$account_id); |
|
412 | + $this->set_memberships(array(), $account_id); |
|
415 | 413 | |
416 | - $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
|
414 | + $sri = ldap_search($this->ds, $this->user_context, 'uidnumber='.$account_id); |
|
417 | 415 | } |
418 | 416 | if (!$sri) return false; |
419 | 417 | |
@@ -437,7 +435,7 @@ discard block |
||
437 | 435 | { |
438 | 436 | $this->ldapServerInfo = $this->ldap->getLDAPServerInfo($this->frontend->config['ldap_host']); |
439 | 437 | } |
440 | - foreach(array_keys($this->group_mail_classes) as $objectclass) |
|
438 | + foreach (array_keys($this->group_mail_classes) as $objectclass) |
|
441 | 439 | { |
442 | 440 | if ($this->ldapServerInfo->supportsObjectClass($objectclass)) |
443 | 441 | { |
@@ -445,15 +443,15 @@ discard block |
||
445 | 443 | break; |
446 | 444 | } |
447 | 445 | } |
448 | - $sri = ldap_search($this->ds, $this->group_context,'(&(objectClass=posixGroup)(gidnumber=' . abs($account_id).'))', |
|
446 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(gidnumber='.abs($account_id).'))', |
|
449 | 447 | array('dn', 'gidnumber', 'cn', 'objectclass', static::MAIL_ATTR, 'memberuid', 'description')); |
450 | 448 | |
451 | 449 | $ldap_data = ldap_get_entries($this->ds, $sri); |
452 | 450 | if (!$ldap_data['count']) |
453 | 451 | { |
454 | - return false; // group not found |
|
452 | + return false; // group not found |
|
455 | 453 | } |
456 | - $data = translation::convert($ldap_data[0],'utf-8'); |
|
454 | + $data = translation::convert($ldap_data[0], 'utf-8'); |
|
457 | 455 | unset($data['objectclass']['count']); |
458 | 456 | |
459 | 457 | $group += array( |
@@ -474,7 +472,7 @@ discard block |
||
474 | 472 | { |
475 | 473 | unset($data['memberuid']['count']); |
476 | 474 | |
477 | - foreach($data['memberuid'] as $lid) |
|
475 | + foreach ($data['memberuid'] as $lid) |
|
478 | 476 | { |
479 | 477 | if (($id = $this->name2id($lid, 'account_lid', 'u'))) |
480 | 478 | { |
@@ -495,16 +493,16 @@ discard block |
||
495 | 493 | */ |
496 | 494 | protected function _read_user($account_id) |
497 | 495 | { |
498 | - $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber=' . (int)$account_id.'))', |
|
499 | - array('dn','uidnumber','uid','gidnumber','givenname','sn','cn',static::MAIL_ATTR,'userpassword','telephonenumber', |
|
500 | - 'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp')); |
|
496 | + $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber='.(int)$account_id.'))', |
|
497 | + array('dn', 'uidnumber', 'uid', 'gidnumber', 'givenname', 'sn', 'cn', static::MAIL_ATTR, 'userpassword', 'telephonenumber', |
|
498 | + 'shadowexpire', 'shadowlastchange', 'homedirectory', 'loginshell', 'createtimestamp', 'modifytimestamp')); |
|
501 | 499 | |
502 | 500 | $ldap_data = ldap_get_entries($this->ds, $sri); |
503 | 501 | if (!$ldap_data['count']) |
504 | 502 | { |
505 | - return false; // user not found |
|
503 | + return false; // user not found |
|
506 | 504 | } |
507 | - $data = translation::convert($ldap_data[0],'utf-8'); |
|
505 | + $data = translation::convert($ldap_data[0], 'utf-8'); |
|
508 | 506 | |
509 | 507 | $utc_diff = date('Z'); |
510 | 508 | $user = array( |
@@ -524,13 +522,13 @@ discard block |
||
524 | 522 | // - if it's set to 0, the account is disabled |
525 | 523 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
526 | 524 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
527 | - 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0]*24*3600+$utc_diff < time() ? false : 'A', |
|
528 | - 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
529 | - 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0]*24*3600+($data['shadowlastchange'][0]!=0?$utc_diff:0) : null, |
|
525 | + 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0] * 24 * 3600 + $utc_diff < time() ? false : 'A', |
|
526 | + 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
527 | + 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0] * 24 * 3600 + ($data['shadowlastchange'][0] != 0 ? $utc_diff : 0) : null, |
|
530 | 528 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
531 | 529 | // 'account_lastlogin' => $data['phpgwaccountlastlogin'][0], |
532 | 530 | // 'account_lastloginfrom' => $data['phpgwaccountlastloginfrom'][0], |
533 | - 'person_id' => $data['uid'][0], // id of associated contact |
|
531 | + 'person_id' => $data['uid'][0], // id of associated contact |
|
534 | 532 | 'account_created' => isset($data['createtimestamp'][0]) ? self::accounts_ldap2ts($data['createtimestamp'][0]) : null, |
535 | 533 | 'account_modified' => isset($data['modifytimestamp'][0]) ? self::accounts_ldap2ts($data['modifytimestamp'][0]) : null, |
536 | 534 | ); |
@@ -551,7 +549,7 @@ discard block |
||
551 | 549 | * @param array $data array with account-data in utf-8 |
552 | 550 | * @return array merged data |
553 | 551 | */ |
554 | - protected function _merge_group($to_write,$data,$old=null) |
|
552 | + protected function _merge_group($to_write, $data, $old = null) |
|
555 | 553 | { |
556 | 554 | $to_write['gidnumber'] = abs($data['account_id']); |
557 | 555 | $to_write['cn'] = $data['account_lid']; |
@@ -571,7 +569,7 @@ discard block |
||
571 | 569 | * @param boolean $new_entry |
572 | 570 | * @return array merged data |
573 | 571 | */ |
574 | - protected function _merge_user($to_write,$data,$new_entry) |
|
572 | + protected function _merge_user($to_write, $data, $new_entry) |
|
575 | 573 | { |
576 | 574 | //echo "<p>accounts_ldap::_merge_user(".print_r($to_write,true).','.print_r($data,true).",$new_entry)</p>\n"; |
577 | 575 | |
@@ -582,12 +580,12 @@ discard block |
||
582 | 580 | { |
583 | 581 | $to_write['givenname'] = $data['account_firstname'] ? $data['account_firstname'] : array(); |
584 | 582 | } |
585 | - $to_write['sn'] = $data['account_lastname']; |
|
583 | + $to_write['sn'] = $data['account_lastname']; |
|
586 | 584 | if (!$new_entry || $data['account_email']) |
587 | 585 | { |
588 | - $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
586 | + $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
589 | 587 | } |
590 | - $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
588 | + $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
591 | 589 | |
592 | 590 | $utc_diff = date('Z'); |
593 | 591 | if (isset($data['account_passwd']) && $data['account_passwd']) |
@@ -596,47 +594,46 @@ discard block |
||
596 | 594 | { |
597 | 595 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
598 | 596 | } |
599 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
597 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd'])) // if it's not already entcrypted, do so now |
|
600 | 598 | { |
601 | 599 | $data['account_passwd'] = auth::encrypt_ldap($data['account_passwd']); |
602 | 600 | } |
603 | 601 | $to_write['userpassword'] = $data['account_passwd']; |
604 | - $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
|
602 | + $to_write['shadowlastchange'] = round((time() - $utc_diff) / (24 * 3600)); |
|
605 | 603 | } |
606 | 604 | // both status and expires are encoded in the single shadowexpire value in LDAP |
607 | 605 | // - if it's unset an account is enabled AND does never expire |
608 | 606 | // - if it's set to 0, the account is disabled |
609 | 607 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
610 | 608 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
611 | - $shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600); |
|
609 | + $shadowexpire = ($data['account_expires'] - $utc_diff) / (24 * 3600); |
|
612 | 610 | //echo "<p align=right>account_expires=".date('Y-m-d H:i',$data['account_expires'])." --> $shadowexpire --> ".date('Y-m-d H:i',$account_expire)."</p>\n"; |
613 | 611 | $to_write['shadowexpire'] = !$data['account_status'] ? |
614 | - ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : |
|
615 | - ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
612 | + ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
616 | 613 | |
617 | 614 | if ($new_entry && is_array($to_write['shadowexpire']) && !count($to_write['shadowexpire'])) |
618 | 615 | { |
619 | - unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
616 | + unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
620 | 617 | } |
621 | 618 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
622 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
623 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
619 | + if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change'] - $utc_diff) / (24 * 3600)); |
|
620 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change'] == 0) $to_write['shadowlastchange'] = 0; |
|
624 | 621 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
625 | 622 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
626 | 623 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
627 | 624 | |
628 | 625 | if ($this->frontend->config['ldap_extra_attributes']) |
629 | 626 | { |
630 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
627 | + if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
631 | 628 | if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
632 | 629 | } |
633 | 630 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
634 | 631 | { |
635 | - $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
632 | + $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
636 | 633 | } |
637 | 634 | if ($new_entry && empty($to_write['loginshell'])) |
638 | 635 | { |
639 | - unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
636 | + unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
640 | 637 | } |
641 | 638 | return $to_write; |
642 | 639 | } |
@@ -664,7 +661,7 @@ discard block |
||
664 | 661 | function search($param) |
665 | 662 | { |
666 | 663 | //error_log(__METHOD__."(".array2string($param).")"); |
667 | - $account_search =& accounts::$cache['account_search']; |
|
664 | + $account_search = & accounts::$cache['account_search']; |
|
668 | 665 | |
669 | 666 | // check if the query is cached |
670 | 667 | $serial = serialize($param); |
@@ -690,12 +687,12 @@ discard block |
||
690 | 687 | $query = ldap::quote(strtolower($param['query'])); |
691 | 688 | |
692 | 689 | $accounts = array(); |
693 | - if($param['type'] != 'groups') |
|
690 | + if ($param['type'] != 'groups') |
|
694 | 691 | { |
695 | 692 | $filter = "(&(objectclass=posixaccount)"; |
696 | 693 | if (!empty($query) && $query != '*') |
697 | 694 | { |
698 | - switch($param['query_type']) |
|
695 | + switch ($param['query_type']) |
|
699 | 696 | { |
700 | 697 | case 'all': |
701 | 698 | default: |
@@ -722,7 +719,7 @@ discard block |
||
722 | 719 | } |
723 | 720 | } |
724 | 721 | // add account_filter to filter (user has to be '*', as we otherwise only search uid's) |
725 | - $filter .= str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$this->account_filter); |
|
722 | + $filter .= str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $this->account_filter); |
|
726 | 723 | $filter .= ')'; |
727 | 724 | |
728 | 725 | if ($param['type'] != 'both') |
@@ -741,9 +738,9 @@ discard block |
||
741 | 738 | 'account_fullname' => 'cn', |
742 | 739 | 'account_primary_group' => 'gidnumber', |
743 | 740 | ); |
744 | - $orders = explode(',',$param['order']); |
|
741 | + $orders = explode(',', $param['order']); |
|
745 | 742 | $order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid'; |
746 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order)); |
|
743 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', $order)); |
|
747 | 744 | $fullSet = array(); |
748 | 745 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
749 | 746 | { |
@@ -753,7 +750,7 @@ discard block |
||
753 | 750 | if (is_numeric($param['type'])) // return only group-members |
754 | 751 | { |
755 | 752 | $relevantAccounts = array(); |
756 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
|
753 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=".abs($param['type'])."))", array('memberuid')); |
|
757 | 754 | $group = ldap_get_entries($this->ds, $sri); |
758 | 755 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
759 | 756 | } |
@@ -762,27 +759,27 @@ discard block |
||
762 | 759 | $sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort'; |
763 | 760 | $sortFn($fullSet); |
764 | 761 | $relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet); |
765 | - $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')'; |
|
766 | - $filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter); |
|
762 | + $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=', $relevantAccounts).'))'.$this->account_filter.')'; |
|
763 | + $filter = str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $filter); |
|
767 | 764 | } |
768 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn',static::MAIL_ATTR,'shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber')); |
|
765 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', 'uidNumber', 'givenname', 'sn', static::MAIL_ATTR, 'shadowExpire', 'createtimestamp', 'modifytimestamp', 'objectclass', 'gidNumber')); |
|
769 | 766 | //echo "<p>ldap_search(,$this->user_context,'$filter',) ".($sri ? '' : ldap_error($this->ds)).microtime()."</p>\n"; |
770 | 767 | |
771 | 768 | $utc_diff = date('Z'); |
772 | - foreach(ldap_get_entries($this->ds, $sri) as $allVals) |
|
769 | + foreach (ldap_get_entries($this->ds, $sri) as $allVals) |
|
773 | 770 | { |
774 | - settype($allVals,'array'); |
|
771 | + settype($allVals, 'array'); |
|
775 | 772 | $test = @$allVals['uid'][0]; |
776 | 773 | if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) |
777 | 774 | { |
778 | 775 | $account = Array( |
779 | 776 | 'account_id' => $allVals['uidnumber'][0], |
780 | - 'account_lid' => translation::convert($allVals['uid'][0],'utf-8'), |
|
777 | + 'account_lid' => translation::convert($allVals['uid'][0], 'utf-8'), |
|
781 | 778 | 'account_type' => 'u', |
782 | - 'account_firstname' => translation::convert($allVals['givenname'][0],'utf-8'), |
|
783 | - 'account_lastname' => translation::convert($allVals['sn'][0],'utf-8'), |
|
784 | - 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A', |
|
785 | - 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
779 | + 'account_firstname' => translation::convert($allVals['givenname'][0], 'utf-8'), |
|
780 | + 'account_lastname' => translation::convert($allVals['sn'][0], 'utf-8'), |
|
781 | + 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0] * 24 * 3600 - $utc_diff < time() ? false : 'A', |
|
782 | + 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
786 | 783 | 'account_email' => $allVals[static::MAIL_ATTR][0], |
787 | 784 | 'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null, |
788 | 785 | 'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null, |
@@ -794,7 +791,7 @@ discard block |
||
794 | 791 | if (isset($totalcount)) --$totalcount; |
795 | 792 | continue; |
796 | 793 | } |
797 | - $account['account_fullname'] = common::display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$allVals['uidnumber'][0]); |
|
794 | + $account['account_fullname'] = common::display_fullname($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $allVals['uidnumber'][0]); |
|
798 | 795 | // return objectclass(es) |
799 | 796 | if ($param['objectclass']) |
800 | 797 | { |
@@ -807,13 +804,13 @@ discard block |
||
807 | 804 | } |
808 | 805 | if ($param['type'] == 'groups' || $param['type'] == 'both') |
809 | 806 | { |
810 | - if(empty($query) || $query == '*') |
|
807 | + if (empty($query) || $query == '*') |
|
811 | 808 | { |
812 | 809 | $filter = '(objectclass=posixgroup)'; |
813 | 810 | } |
814 | 811 | else |
815 | 812 | { |
816 | - switch($param['query_type']) |
|
813 | + switch ($param['query_type']) |
|
817 | 814 | { |
818 | 815 | case 'all': |
819 | 816 | default: |
@@ -827,21 +824,21 @@ discard block |
||
827 | 824 | } |
828 | 825 | $filter = "(&(objectclass=posixgroup)(cn=$query))"; |
829 | 826 | } |
830 | - $sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber')); |
|
831 | - foreach((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
827 | + $sri = ldap_search($this->ds, $this->group_context, $filter, array('cn', 'gidNumber')); |
|
828 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
832 | 829 | { |
833 | - settype($allVals,'array'); |
|
830 | + settype($allVals, 'array'); |
|
834 | 831 | $test = $allVals['cn'][0]; |
835 | 832 | if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0]) |
836 | 833 | { |
837 | 834 | $accounts[(string)-$allVals['gidnumber'][0]] = Array( |
838 | 835 | 'account_id' => -$allVals['gidnumber'][0], |
839 | - 'account_lid' => translation::convert($allVals['cn'][0],'utf-8'), |
|
836 | + 'account_lid' => translation::convert($allVals['cn'][0], 'utf-8'), |
|
840 | 837 | 'account_type' => 'g', |
841 | - 'account_firstname' => translation::convert($allVals['cn'][0],'utf-8'), |
|
838 | + 'account_firstname' => translation::convert($allVals['cn'][0], 'utf-8'), |
|
842 | 839 | 'account_lastname' => lang('Group'), |
843 | 840 | 'account_status' => 'A', |
844 | - 'account_fullname' => translation::convert($allVals['cn'][0],'utf-8'), |
|
841 | + 'account_fullname' => translation::convert($allVals['cn'][0], 'utf-8'), |
|
845 | 842 | ); |
846 | 843 | if (isset($totalcount)) ++$totalcount; |
847 | 844 | } |
@@ -849,9 +846,9 @@ discard block |
||
849 | 846 | } |
850 | 847 | // sort the array |
851 | 848 | $this->_callback_sort = strtoupper($param['sort']); |
852 | - $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
|
849 | + $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']); |
|
853 | 850 | $sortedAccounts = $accounts; |
854 | - uasort($sortedAccounts,array($this,'_sort_callback')); |
|
851 | + uasort($sortedAccounts, array($this, '_sort_callback')); |
|
855 | 852 | $this->total = isset($totalcount) ? $totalcount : count($accounts); |
856 | 853 | |
857 | 854 | // if totalcount is set, $sortedAccounts is NOT the full set, but already a limited set! |
@@ -864,7 +861,7 @@ discard block |
||
864 | 861 | //echo "<p>accounts_ldap::search() found $this->total: ".microtime()."</p>\n"; |
865 | 862 | // return only the wanted accounts |
866 | 863 | reset($sortedAccounts); |
867 | - if(is_numeric($start) && is_numeric($offset)) |
|
864 | + if (is_numeric($start) && is_numeric($offset)) |
|
868 | 865 | { |
869 | 866 | $account_search[$serial]['total'] = $this->total; |
870 | 867 | return $account_search[$serial]['data'] = isset($totalcount) ? $sortedAccounts : array_slice($sortedAccounts, $start, $offset); |
@@ -892,19 +889,19 @@ discard block |
||
892 | 889 | * @param array $b |
893 | 890 | * @return int |
894 | 891 | */ |
895 | - function _sort_callback($a,$b) |
|
892 | + function _sort_callback($a, $b) |
|
896 | 893 | { |
897 | - foreach($this->_callback_order as $col ) |
|
894 | + foreach ($this->_callback_order as $col) |
|
898 | 895 | { |
899 | - if($this->_callback_sort != 'DESC') |
|
896 | + if ($this->_callback_sort != 'DESC') |
|
900 | 897 | { |
901 | - $cmp = strcasecmp( $a[$col], $b[$col] ); |
|
898 | + $cmp = strcasecmp($a[$col], $b[$col]); |
|
902 | 899 | } |
903 | 900 | else |
904 | 901 | { |
905 | - $cmp = strcasecmp( $b[$col], $a[$col] ); |
|
902 | + $cmp = strcasecmp($b[$col], $a[$col]); |
|
906 | 903 | } |
907 | - if ( $cmp != 0 ) |
|
904 | + if ($cmp != 0) |
|
908 | 905 | { |
909 | 906 | return $cmp; |
910 | 907 | } |
@@ -923,8 +920,8 @@ discard block |
||
923 | 920 | { |
924 | 921 | if (!empty($date)) |
925 | 922 | { |
926 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
927 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
923 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
924 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
928 | 925 | } |
929 | 926 | return NULL; |
930 | 927 | } |
@@ -941,14 +938,14 @@ discard block |
||
941 | 938 | * @param string $account_type u = user, g = group, default null = try both |
942 | 939 | * @return int|false numeric account_id or false on error ($name not found) |
943 | 940 | */ |
944 | - function name2id($_name,$which='account_lid',$account_type=null) |
|
941 | + function name2id($_name, $which = 'account_lid', $account_type = null) |
|
945 | 942 | { |
946 | - $name = ldap::quote(translation::convert($_name,translation::charset(),'utf-8')); |
|
943 | + $name = ldap::quote(translation::convert($_name, translation::charset(), 'utf-8')); |
|
947 | 944 | |
948 | 945 | if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
949 | 946 | { |
950 | 947 | |
951 | - $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
|
948 | + $sri = ldap_search($this->ds, $this->group_context, '(&(cn='.$name.')(objectclass=posixgroup))', array('gidNumber')); |
|
952 | 949 | $allValues = ldap_get_entries($this->ds, $sri); |
953 | 950 | |
954 | 951 | if (@$allValues[0]['gidnumber'][0]) |
@@ -965,7 +962,7 @@ discard block |
||
965 | 962 | return False; |
966 | 963 | } |
967 | 964 | |
968 | - $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber')); |
|
965 | + $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'='.$name.')(objectclass=posixaccount))', array('uidNumber')); |
|
969 | 966 | |
970 | 967 | $allValues = ldap_get_entries($this->ds, $sri); |
971 | 968 | |
@@ -985,9 +982,9 @@ discard block |
||
985 | 982 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
986 | 983 | * @return string/false converted value or false on error ($account_id not found) |
987 | 984 | */ |
988 | - function id2name($account_id,$which='account_lid') |
|
985 | + function id2name($account_id, $which = 'account_lid') |
|
989 | 986 | { |
990 | - return $this->frontend->id2name($account_id,$which); |
|
987 | + return $this->frontend->id2name($account_id, $which); |
|
991 | 988 | } |
992 | 989 | |
993 | 990 | /** |
@@ -1000,7 +997,7 @@ discard block |
||
1000 | 997 | function update_lastlogin($_account_id, $ip) |
1001 | 998 | { |
1002 | 999 | unset($_account_id, $ip); |
1003 | - return false; // not longer supported |
|
1000 | + return false; // not longer supported |
|
1004 | 1001 | } |
1005 | 1002 | |
1006 | 1003 | /** |
@@ -1011,11 +1008,11 @@ discard block |
||
1011 | 1008 | */ |
1012 | 1009 | function memberships($account_id) |
1013 | 1010 | { |
1014 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1011 | + if (!(int)$account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1015 | 1012 | |
1016 | - $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.ldap::quote($account_lid).'))',array('cn','gidnumber')); |
|
1013 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(memberuid='.ldap::quote($account_lid).'))', array('cn', 'gidnumber')); |
|
1017 | 1014 | $memberships = array(); |
1018 | - foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
1015 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
1019 | 1016 | { |
1020 | 1017 | if ($key === 'count') continue; |
1021 | 1018 | |
@@ -1036,13 +1033,13 @@ discard block |
||
1036 | 1033 | if (!is_numeric($_gid)) |
1037 | 1034 | { |
1038 | 1035 | // try to recover |
1039 | - $_gid = $this->name2id($_gid,'account_lid','g'); |
|
1036 | + $_gid = $this->name2id($_gid, 'account_lid', 'g'); |
|
1040 | 1037 | if (!is_numeric($_gid)) return false; |
1041 | 1038 | } |
1042 | 1039 | |
1043 | - $gid = abs($_gid); // our gid is negative! |
|
1040 | + $gid = abs($_gid); // our gid is negative! |
|
1044 | 1041 | |
1045 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid')); |
|
1042 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=$gid))", array('memberuid')); |
|
1046 | 1043 | $group = ldap_get_entries($this->ds, $sri); |
1047 | 1044 | |
1048 | 1045 | $members = array(); |
@@ -1050,7 +1047,7 @@ discard block |
||
1050 | 1047 | { |
1051 | 1048 | unset($group[0]['memberuid']['count']); |
1052 | 1049 | |
1053 | - foreach($group[0]['memberuid'] as $lid) |
|
1050 | + foreach ($group[0]['memberuid'] as $lid) |
|
1054 | 1051 | { |
1055 | 1052 | if (($id = $this->name2id($lid, 'account_lid', 'u'))) |
1056 | 1053 | { |
@@ -1068,7 +1065,7 @@ discard block |
||
1068 | 1065 | * @param array $groups array with gidnumbers |
1069 | 1066 | * @param int $account_id uidnumber |
1070 | 1067 | */ |
1071 | - function set_memberships($groups,$account_id) |
|
1068 | + function set_memberships($groups, $account_id) |
|
1072 | 1069 | { |
1073 | 1070 | //echo "<p>accounts_ldap::set_memberships(".print_r($groups,true).",$account_id)</p>\n"; |
1074 | 1071 | |
@@ -1076,21 +1073,21 @@ discard block |
||
1076 | 1073 | if (($old_memberships = $this->memberships($account_id))) |
1077 | 1074 | { |
1078 | 1075 | $old_memberships = array_keys($old_memberships); |
1079 | - foreach(array_diff($old_memberships,$groups) as $gid) |
|
1076 | + foreach (array_diff($old_memberships, $groups) as $gid) |
|
1080 | 1077 | { |
1081 | 1078 | if (($members = $this->members($gid))) |
1082 | 1079 | { |
1083 | 1080 | unset($members[$account_id]); |
1084 | - $this->set_members($members,$gid); |
|
1081 | + $this->set_members($members, $gid); |
|
1085 | 1082 | } |
1086 | 1083 | } |
1087 | 1084 | } |
1088 | 1085 | // adding new memberships |
1089 | - foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid) |
|
1086 | + foreach ($old_memberships ? array_diff($groups, $old_memberships) : $groups as $gid) |
|
1090 | 1087 | { |
1091 | 1088 | $members = $this->members($gid); |
1092 | 1089 | $members[$account_id] = $this->id2name($account_id); |
1093 | - $this->set_members($members,$gid); |
|
1090 | + $this->set_members($members, $gid); |
|
1094 | 1091 | } |
1095 | 1092 | } |
1096 | 1093 | |
@@ -1104,16 +1101,16 @@ discard block |
||
1104 | 1101 | * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it) |
1105 | 1102 | * @return boolean/array false on failure, array or true otherwise |
1106 | 1103 | */ |
1107 | - function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
|
1104 | + function set_members($members, $gid, array $objectclass = null, $use_cn = null) |
|
1108 | 1105 | { |
1109 | 1106 | //echo "<p>accounts_ldap::set_members(".print_r($members,true).",$gid)</p>\n"; |
1110 | 1107 | if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
1111 | 1108 | |
1112 | 1109 | // do that group is a groupOf(Unique)Names or univentionGroup? |
1113 | - if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass'); |
|
1110 | + if (is_null($objectclass)) $objectclass = $this->id2name($gid, 'objectclass'); |
|
1114 | 1111 | |
1115 | 1112 | $to_write = array('memberuid' => array()); |
1116 | - foreach((array)$members as $key => $member) |
|
1113 | + foreach ((array)$members as $key => $member) |
|
1117 | 1114 | { |
1118 | 1115 | $member_dn = $this->id2name($member, 'account_dn'); |
1119 | 1116 | if (is_numeric($member)) $member = $this->id2name($member); |
@@ -1125,7 +1122,7 @@ discard block |
||
1125 | 1122 | { |
1126 | 1123 | $to_write['member'][] = $member_dn; |
1127 | 1124 | } |
1128 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass)) |
|
1125 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
1129 | 1126 | { |
1130 | 1127 | $to_write['uniquemember'][] = $member_dn; |
1131 | 1128 | } |
@@ -1136,31 +1133,31 @@ discard block |
||
1136 | 1133 | { |
1137 | 1134 | $to_write['member'][] = 'uid=dummy'.','.$this->user_context; |
1138 | 1135 | } |
1139 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
1136 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
1140 | 1137 | { |
1141 | 1138 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
1142 | 1139 | } |
1143 | 1140 | if ($use_cn) return $to_write; |
1144 | 1141 | |
1145 | 1142 | // set the member email addresses as forwards |
1146 | - if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
|
1143 | + if ($this->id2name($gid, 'account_email') && ($objectclass = $this->id2name($gid, 'mailAllowed'))) |
|
1147 | 1144 | { |
1148 | 1145 | $forward = $this->group_mail_classes[$objectclass]; |
1149 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
1146 | + if (is_array($forward)) list($forward, $extra_attr) = $forward; |
|
1150 | 1147 | if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
1151 | 1148 | |
1152 | 1149 | if ($forward) |
1153 | 1150 | { |
1154 | 1151 | $to_write[$forward] = array(); |
1155 | - foreach($members as $key => $member) |
|
1152 | + foreach ($members as $key => $member) |
|
1156 | 1153 | { |
1157 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
1154 | + if (($email = $this->id2name($member, 'account_email'))) $to_write[$forward][] = $email; |
|
1158 | 1155 | } |
1159 | 1156 | } |
1160 | 1157 | } |
1161 | - if (!ldap_modify($this->ds,'cn='.ldap::quote($cn).','.$this->group_context,$to_write)) |
|
1158 | + if (!ldap_modify($this->ds, 'cn='.ldap::quote($cn).','.$this->group_context, $to_write)) |
|
1162 | 1159 | { |
1163 | - echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write,true)."))\n"; |
|
1160 | + echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write, true)."))\n"; |
|
1164 | 1161 | return false; |
1165 | 1162 | } |
1166 | 1163 | return true; |
@@ -1173,7 +1170,7 @@ discard block |
||
1173 | 1170 | * @param string $account_type ='u' (optional, default to 'u') |
1174 | 1171 | * @return int|boolean integer account_id (negative for groups) or false if none is free anymore |
1175 | 1172 | */ |
1176 | - protected function _get_nextid($account_type='u') |
|
1173 | + protected function _get_nextid($account_type = 'u') |
|
1177 | 1174 | { |
1178 | 1175 | $min = $this->frontend->config['account_min_id'] ? $this->frontend->config['account_min_id'] : 0; |
1179 | 1176 | $max = $this->frontend->config['account_max_id'] ? $this->frontend->config['account_max_id'] : 0; |
@@ -1195,15 +1192,15 @@ discard block |
||
1195 | 1192 | /* Loop until we find a free id */ |
1196 | 1193 | do |
1197 | 1194 | { |
1198 | - $account_id = (int) common::next_id($type,$min,$max); |
|
1195 | + $account_id = (int)common::next_id($type, $min, $max); |
|
1199 | 1196 | } |
1200 | - while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
1197 | + while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
1201 | 1198 | $this->frontend->exists(-1 * $sign * $account_id) || |
1202 | 1199 | // if sambaadmin is installed, call it to check there's not yet a relative id (last part of SID) with that number |
1203 | 1200 | // to ease migration to AD or Samba4 |
1204 | 1201 | $GLOBALS['egw_info']['apps']['sambaadmin'] && ExecMethod2('sambaadmin.sosambaadmin.sidExists', $account_id))); |
1205 | 1202 | |
1206 | - if (!$account_id || $max && $account_id > $max) |
|
1203 | + if (!$account_id || $max && $account_id > $max) |
|
1207 | 1204 | { |
1208 | 1205 | return False; |
1209 | 1206 | } |
@@ -1216,6 +1213,6 @@ discard block |
||
1216 | 1213 | function __wakeup() |
1217 | 1214 | { |
1218 | 1215 | $this->ds = $this->ldap->ldapConnect($this->frontend->config['ldap_host'], |
1219 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
1216 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
1220 | 1217 | } |
1221 | 1218 | } |
@@ -171,7 +171,10 @@ discard block |
||
171 | 171 | */ |
172 | 172 | function read($account_id) |
173 | 173 | { |
174 | - if (!(int)$account_id) return false; |
|
174 | + if (!(int)$account_id) |
|
175 | + { |
|
176 | + return false; |
|
177 | + } |
|
175 | 178 | |
176 | 179 | if ($account_id < 0) |
177 | 180 | { |
@@ -234,17 +237,23 @@ discard block |
||
234 | 237 | $this->delete($data['account_id']); |
235 | 238 | unset($old['dn']); |
236 | 239 | // removing the namedObject object-class, if it's included |
237 | - if ($key !== false) unset($old['objectclass'][$key]); |
|
240 | + if ($key !== false) |
|
241 | + { |
|
242 | + unset($old['objectclass'][$key]); |
|
243 | + } |
|
238 | 244 | $to_write = $old; |
239 | 245 | unset($old); |
240 | 246 | } |
241 | 247 | } |
242 | 248 | } |
243 | - if (!$data['account_id']) // new account |
|
249 | + if (!$data['account_id']) |
|
250 | + { |
|
251 | + // new account |
|
244 | 252 | { |
245 | 253 | if (!($data['account_id'] = $data_utf8['account_id'] = $this->_get_nextid($is_group ? 'g' : 'u'))) |
246 | 254 | { |
247 | 255 | return false; |
256 | + } |
|
248 | 257 | } |
249 | 258 | } |
250 | 259 | // check if we need to write the objectclass: new entry or required object classes are missing |
@@ -255,11 +264,14 @@ discard block |
||
255 | 264 | { |
256 | 265 | $to_write['objectclass'] = $old ? $old['objectclass'] : array(); |
257 | 266 | } |
258 | - if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
|
267 | + if (!$old) |
|
268 | + { |
|
269 | + // for new accounts add additional addressbook object classes, if supported by server |
|
259 | 270 | { // as setting them later might loose eg. password, if we are not allowed to read them |
260 | 271 | foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
261 | 272 | { |
262 | 273 | $add = array(); |
274 | + } |
|
263 | 275 | if (is_array($additional)) |
264 | 276 | { |
265 | 277 | $add = $additional; |
@@ -268,7 +280,10 @@ discard block |
||
268 | 280 | if ($this->ldapServerInfo->supportsObjectClass($additional)) |
269 | 281 | { |
270 | 282 | $to_write['objectclass'][] = $additional; |
271 | - if ($add) $to_write += $add; |
|
283 | + if ($add) |
|
284 | + { |
|
285 | + $to_write += $add; |
|
286 | + } |
|
272 | 287 | } |
273 | 288 | } |
274 | 289 | } |
@@ -277,7 +292,10 @@ discard block |
||
277 | 292 | } |
278 | 293 | if (!($dn = $old['dn'])) |
279 | 294 | { |
280 | - if (!$data['account_lid']) return false; |
|
295 | + if (!$data['account_lid']) |
|
296 | + { |
|
297 | + return false; |
|
298 | + } |
|
281 | 299 | |
282 | 300 | $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
283 | 301 | 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
@@ -298,24 +316,36 @@ discard block |
||
298 | 316 | { |
299 | 317 | $extra_attr = false; |
300 | 318 | $keep_objectclass = false; |
301 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
319 | + if (is_array($forward)) |
|
320 | + { |
|
321 | + list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
322 | + } |
|
302 | 323 | |
303 | 324 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
304 | 325 | ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
305 | 326 | { |
306 | - if ($data_utf8['account_email']) // setting an email |
|
327 | + if ($data_utf8['account_email']) |
|
328 | + { |
|
329 | + // setting an email |
|
307 | 330 | { |
308 | 331 | if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
309 | 332 | { |
310 | 333 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
334 | + } |
|
311 | 335 | $to_write['objectclass'][] = $objectclass; |
312 | 336 | } |
313 | - if ($extra_attr) $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
337 | + if ($extra_attr) |
|
338 | + { |
|
339 | + $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
340 | + } |
|
314 | 341 | $to_write[static::MAIL_ATTR] = $data_utf8['account_email']; |
315 | 342 | |
316 | 343 | if ($forward) |
317 | 344 | { |
318 | - if (!$members) $members = $this->members($data['account_id']); |
|
345 | + if (!$members) |
|
346 | + { |
|
347 | + $members = $this->members($data['account_id']); |
|
348 | + } |
|
319 | 349 | $to_write[$forward] = array(); |
320 | 350 | foreach (array_keys($members) as $member) |
321 | 351 | { |
@@ -326,11 +356,20 @@ discard block |
||
326 | 356 | } |
327 | 357 | } |
328 | 358 | } |
329 | - elseif($old) // remove the mail and forwards only for existing entries |
|
359 | + elseif($old) |
|
360 | + { |
|
361 | + // remove the mail and forwards only for existing entries |
|
330 | 362 | { |
331 | 363 | $to_write[static::MAIL_ATTR] = array(); |
332 | - if ($forward) $to_write[$forward] = array(); |
|
333 | - if ($extra_attr) $to_write[$extra_attr] = array(); |
|
364 | + } |
|
365 | + if ($forward) |
|
366 | + { |
|
367 | + $to_write[$forward] = array(); |
|
368 | + } |
|
369 | + if ($extra_attr) |
|
370 | + { |
|
371 | + $to_write[$extra_attr] = array(); |
|
372 | + } |
|
334 | 373 | if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
335 | 374 | { |
336 | 375 | $to_write['objectclass'] = $old['objectclass']; |
@@ -364,7 +403,8 @@ discard block |
||
364 | 403 | } |
365 | 404 | |
366 | 405 | // remove memberuid when adding a group |
367 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
406 | + if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) |
|
407 | + { |
|
368 | 408 | unset($to_write['memberuid']); |
369 | 409 | } |
370 | 410 | //echo "<p>ldap_".($old ? 'modify' : 'add')."(,$dn,".print_r($to_write,true).")</p>\n"; |
@@ -402,7 +442,10 @@ discard block |
||
402 | 442 | */ |
403 | 443 | function delete($account_id) |
404 | 444 | { |
405 | - if (!(int)$account_id) return false; |
|
445 | + if (!(int)$account_id) |
|
446 | + { |
|
447 | + return false; |
|
448 | + } |
|
406 | 449 | |
407 | 450 | if ($account_id < 0) |
408 | 451 | { |
@@ -415,10 +458,16 @@ discard block |
||
415 | 458 | |
416 | 459 | $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
417 | 460 | } |
418 | - if (!$sri) return false; |
|
461 | + if (!$sri) |
|
462 | + { |
|
463 | + return false; |
|
464 | + } |
|
419 | 465 | |
420 | 466 | $allValues = ldap_get_entries($this->ds, $sri); |
421 | - if (!$allValues['count']) return false; |
|
467 | + if (!$allValues['count']) |
|
468 | + { |
|
469 | + return false; |
|
470 | + } |
|
422 | 471 | |
423 | 472 | return ldap_delete($this->ds, $allValues[0]['dn']); |
424 | 473 | } |
@@ -592,14 +641,20 @@ discard block |
||
592 | 641 | $utc_diff = date('Z'); |
593 | 642 | if (isset($data['account_passwd']) && $data['account_passwd']) |
594 | 643 | { |
595 | - if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) // md5 --> ldap md5 |
|
644 | + if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) |
|
645 | + { |
|
646 | + // md5 --> ldap md5 |
|
596 | 647 | { |
597 | 648 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
598 | 649 | } |
599 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
650 | + } |
|
651 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) |
|
652 | + { |
|
653 | + // if it's not already entcrypted, do so now |
|
600 | 654 | { |
601 | 655 | $data['account_passwd'] = auth::encrypt_ldap($data['account_passwd']); |
602 | 656 | } |
657 | + } |
|
603 | 658 | $to_write['userpassword'] = $data['account_passwd']; |
604 | 659 | $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
605 | 660 | } |
@@ -619,16 +674,28 @@ discard block |
||
619 | 674 | unset($to_write['shadowexpire']); // gives protocoll error otherwise |
620 | 675 | } |
621 | 676 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
622 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
623 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
677 | + if ($data['account_lastpwd_change']) |
|
678 | + { |
|
679 | + $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
680 | + } |
|
681 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) |
|
682 | + { |
|
683 | + $to_write['shadowlastchange'] = 0; |
|
684 | + } |
|
624 | 685 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
625 | 686 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
626 | 687 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
627 | 688 | |
628 | 689 | if ($this->frontend->config['ldap_extra_attributes']) |
629 | 690 | { |
630 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
631 | - if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
691 | + if (isset($data['homedirectory'])) |
|
692 | + { |
|
693 | + $to_write['homedirectory'] = $data['homedirectory']; |
|
694 | + } |
|
695 | + if (isset($data['loginshell'])) |
|
696 | + { |
|
697 | + $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
698 | + } |
|
632 | 699 | } |
633 | 700 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
634 | 701 | { |
@@ -675,8 +742,14 @@ discard block |
||
675 | 742 | } |
676 | 743 | // if it's a limited query, check if the unlimited query is cached |
677 | 744 | $start = $param['start']; |
678 | - if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15; |
|
679 | - if (!($offset = $param['offset'])) $offset = $maxmatchs; |
|
745 | + if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) |
|
746 | + { |
|
747 | + $maxmatchs = 15; |
|
748 | + } |
|
749 | + if (!($offset = $param['offset'])) |
|
750 | + { |
|
751 | + $offset = $maxmatchs; |
|
752 | + } |
|
680 | 753 | unset($param['start']); |
681 | 754 | unset($param['offset']); |
682 | 755 | $unl_serial = serialize($param); |
@@ -747,12 +820,18 @@ discard block |
||
747 | 820 | $fullSet = array(); |
748 | 821 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
749 | 822 | { |
750 | - if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
823 | + if ($key !== 'count') |
|
824 | + { |
|
825 | + $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
826 | + } |
|
751 | 827 | } |
752 | 828 | |
753 | - if (is_numeric($param['type'])) // return only group-members |
|
829 | + if (is_numeric($param['type'])) |
|
830 | + { |
|
831 | + // return only group-members |
|
754 | 832 | { |
755 | 833 | $relevantAccounts = array(); |
834 | + } |
|
756 | 835 | $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
757 | 836 | $group = ldap_get_entries($this->ds, $sri); |
758 | 837 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
@@ -791,7 +870,10 @@ discard block |
||
791 | 870 | //error_log(__METHOD__."() ldap=".array2string($allVals)." --> account=".array2string($account)); |
792 | 871 | if ($param['active'] && !$this->frontend->is_active($account)) |
793 | 872 | { |
794 | - if (isset($totalcount)) --$totalcount; |
|
873 | + if (isset($totalcount)) |
|
874 | + { |
|
875 | + --$totalcount; |
|
876 | + } |
|
795 | 877 | continue; |
796 | 878 | } |
797 | 879 | $account['account_fullname'] = common::display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$allVals['uidnumber'][0]); |
@@ -843,7 +925,10 @@ discard block |
||
843 | 925 | 'account_status' => 'A', |
844 | 926 | 'account_fullname' => translation::convert($allVals['cn'][0],'utf-8'), |
845 | 927 | ); |
846 | - if (isset($totalcount)) ++$totalcount; |
|
928 | + if (isset($totalcount)) |
|
929 | + { |
|
930 | + ++$totalcount; |
|
931 | + } |
|
847 | 932 | } |
848 | 933 | } |
849 | 934 | } |
@@ -945,10 +1030,13 @@ discard block |
||
945 | 1030 | { |
946 | 1031 | $name = ldap::quote(translation::convert($_name,translation::charset(),'utf-8')); |
947 | 1032 | |
948 | - if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
|
1033 | + if ($which == 'account_lid' && $account_type !== 'u') |
|
1034 | + { |
|
1035 | + // groups only support account_lid |
|
949 | 1036 | { |
950 | 1037 | |
951 | 1038 | $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
1039 | + } |
|
952 | 1040 | $allValues = ldap_get_entries($this->ds, $sri); |
953 | 1041 | |
954 | 1042 | if (@$allValues[0]['gidnumber'][0]) |
@@ -961,7 +1049,8 @@ discard block |
||
961 | 1049 | 'account_email' => static::MAIL_ATTR, |
962 | 1050 | 'account_fullname' => 'cn', |
963 | 1051 | ); |
964 | - if (!isset($to_ldap[$which]) || $account_type === 'g') { |
|
1052 | + if (!isset($to_ldap[$which]) || $account_type === 'g') |
|
1053 | + { |
|
965 | 1054 | return False; |
966 | 1055 | } |
967 | 1056 | |
@@ -1011,13 +1100,19 @@ discard block |
||
1011 | 1100 | */ |
1012 | 1101 | function memberships($account_id) |
1013 | 1102 | { |
1014 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
1103 | + if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) |
|
1104 | + { |
|
1105 | + return false; |
|
1106 | + } |
|
1015 | 1107 | |
1016 | 1108 | $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.ldap::quote($account_lid).'))',array('cn','gidnumber')); |
1017 | 1109 | $memberships = array(); |
1018 | 1110 | foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
1019 | 1111 | { |
1020 | - if ($key === 'count') continue; |
|
1112 | + if ($key === 'count') |
|
1113 | + { |
|
1114 | + continue; |
|
1115 | + } |
|
1021 | 1116 | |
1022 | 1117 | $memberships[(string) -$data['gidnumber'][0]] = $data['cn'][0]; |
1023 | 1118 | } |
@@ -1037,7 +1132,10 @@ discard block |
||
1037 | 1132 | { |
1038 | 1133 | // try to recover |
1039 | 1134 | $_gid = $this->name2id($_gid,'account_lid','g'); |
1040 | - if (!is_numeric($_gid)) return false; |
|
1135 | + if (!is_numeric($_gid)) |
|
1136 | + { |
|
1137 | + return false; |
|
1138 | + } |
|
1041 | 1139 | } |
1042 | 1140 | |
1043 | 1141 | $gid = abs($_gid); // our gid is negative! |
@@ -1107,16 +1205,25 @@ discard block |
||
1107 | 1205 | function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
1108 | 1206 | { |
1109 | 1207 | //echo "<p>accounts_ldap::set_members(".print_r($members,true).",$gid)</p>\n"; |
1110 | - if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
|
1208 | + if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) |
|
1209 | + { |
|
1210 | + return false; |
|
1211 | + } |
|
1111 | 1212 | |
1112 | 1213 | // do that group is a groupOf(Unique)Names or univentionGroup? |
1113 | - if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass'); |
|
1214 | + if (is_null($objectclass)) |
|
1215 | + { |
|
1216 | + $objectclass = $this->id2name($gid,'objectclass'); |
|
1217 | + } |
|
1114 | 1218 | |
1115 | 1219 | $to_write = array('memberuid' => array()); |
1116 | 1220 | foreach((array)$members as $key => $member) |
1117 | 1221 | { |
1118 | 1222 | $member_dn = $this->id2name($member, 'account_dn'); |
1119 | - if (is_numeric($member)) $member = $this->id2name($member); |
|
1223 | + if (is_numeric($member)) |
|
1224 | + { |
|
1225 | + $member = $this->id2name($member); |
|
1226 | + } |
|
1120 | 1227 | |
1121 | 1228 | if ($member) |
1122 | 1229 | { |
@@ -1140,21 +1247,33 @@ discard block |
||
1140 | 1247 | { |
1141 | 1248 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
1142 | 1249 | } |
1143 | - if ($use_cn) return $to_write; |
|
1250 | + if ($use_cn) |
|
1251 | + { |
|
1252 | + return $to_write; |
|
1253 | + } |
|
1144 | 1254 | |
1145 | 1255 | // set the member email addresses as forwards |
1146 | 1256 | if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
1147 | 1257 | { |
1148 | 1258 | $forward = $this->group_mail_classes[$objectclass]; |
1149 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
1150 | - if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
|
1259 | + if (is_array($forward)) |
|
1260 | + { |
|
1261 | + list($forward,$extra_attr) = $forward; |
|
1262 | + } |
|
1263 | + if ($extra_attr && ($uid = $this->id2name($gid))) |
|
1264 | + { |
|
1265 | + $to_write[$extra_attr] = $uid; |
|
1266 | + } |
|
1151 | 1267 | |
1152 | 1268 | if ($forward) |
1153 | 1269 | { |
1154 | 1270 | $to_write[$forward] = array(); |
1155 | 1271 | foreach($members as $key => $member) |
1156 | 1272 | { |
1157 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
1273 | + if (($email = $this->id2name($member,'account_email'))) |
|
1274 | + { |
|
1275 | + $to_write[$forward][] = $email; |
|
1276 | + } |
|
1158 | 1277 | } |
1159 | 1278 | } |
1160 | 1279 | } |
@@ -1180,7 +1299,10 @@ discard block |
||
1180 | 1299 | |
1181 | 1300 | // prefer ids above 1000 (below reserved for system users under AD or Linux), |
1182 | 1301 | // if that's possible within what is configured, or nothing is configured |
1183 | - if ($min < 1000 && (!$max || $max > 1000)) $min = 1000; |
|
1302 | + if ($min < 1000 && (!$max || $max > 1000)) |
|
1303 | + { |
|
1304 | + $min = 1000; |
|
1305 | + } |
|
1184 | 1306 | |
1185 | 1307 | if ($account_type == 'g') |
1186 | 1308 | { |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | $test = @$allVals['uid'][0]; |
776 | 776 | if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) |
777 | 777 | { |
778 | - $account = Array( |
|
778 | + $account = array( |
|
779 | 779 | 'account_id' => $allVals['uidnumber'][0], |
780 | 780 | 'account_lid' => Api\Translation::convert($allVals['uid'][0],'utf-8'), |
781 | 781 | 'account_type' => 'u', |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | $test = $allVals['cn'][0]; |
836 | 836 | if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0]) |
837 | 837 | { |
838 | - $accounts[(string)-$allVals['gidnumber'][0]] = Array( |
|
838 | + $accounts[(string)-$allVals['gidnumber'][0]] = array( |
|
839 | 839 | 'account_id' => -$allVals['gidnumber'][0], |
840 | 840 | 'account_lid' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
841 | 841 | 'account_type' => 'g', |
@@ -639,7 +639,7 @@ |
||
639 | 639 | * |
640 | 640 | * @param int $account_id |
641 | 641 | * @param string $ip |
642 | - * @return int lastlogin time |
|
642 | + * @return string|boolean lastlogin time |
|
643 | 643 | */ |
644 | 644 | function update_lastlogin($account_id, $ip) |
645 | 645 | { |
@@ -192,38 +192,38 @@ discard block |
||
192 | 192 | if ($data['account_passwd']) |
193 | 193 | { |
194 | 194 | // if password it's not already entcrypted, do so now |
195 | - if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']) && |
|
196 | - !preg_match('/^[0-9a-f]{32}$/',$data['account_passwd'])) // md5 hash |
|
195 | + if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd']) && |
|
196 | + !preg_match('/^[0-9a-f]{32}$/', $data['account_passwd'])) // md5 hash |
|
197 | 197 | { |
198 | 198 | $data['account_passwd'] = $GLOBALS['egw']->auth->encrypt_sql($data['account_passwd']); |
199 | 199 | } |
200 | 200 | $to_write['account_pwd'] = $data['account_passwd']; |
201 | 201 | $to_write['account_lastpwd_change'] = time(); |
202 | 202 | } |
203 | - if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change']=0; |
|
203 | + if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change'] = 0; |
|
204 | 204 | if (!(int)$data['account_id'] || !$this->id2name($data['account_id'])) |
205 | 205 | { |
206 | 206 | if ($to_write['account_id'] < 0) $to_write['account_id'] *= -1; |
207 | 207 | |
208 | - if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = ''; // is NOT NULL! |
|
209 | - if (!isset($to_write['account_status'])) $to_write['account_status'] = ''; // is NOT NULL! |
|
208 | + if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = ''; // is NOT NULL! |
|
209 | + if (!isset($to_write['account_status'])) $to_write['account_status'] = ''; // is NOT NULL! |
|
210 | 210 | |
211 | 211 | // postgres requires the auto-id field to be unset! |
212 | 212 | if (isset($to_write['account_id']) && !$to_write['account_id']) unset($to_write['account_id']); |
213 | 213 | |
214 | - if (!in_array($to_write['account_type'],array('u','g')) || |
|
215 | - !$this->db->insert($this->table,$to_write,false,__LINE__,__FILE__)) return false; |
|
214 | + if (!in_array($to_write['account_type'], array('u', 'g')) || |
|
215 | + !$this->db->insert($this->table, $to_write, false, __LINE__, __FILE__)) return false; |
|
216 | 216 | |
217 | 217 | if (!(int)$data['account_id']) |
218 | 218 | { |
219 | - $data['account_id'] = $this->db->get_last_insert_id($this->table,'account_id'); |
|
219 | + $data['account_id'] = $this->db->get_last_insert_id($this->table, 'account_id'); |
|
220 | 220 | if ($data['account_type'] == 'g') $data['account_id'] *= -1; |
221 | 221 | } |
222 | 222 | } |
223 | 223 | else // update of existing account |
224 | 224 | { |
225 | 225 | unset($to_write['account_id']); |
226 | - if (!$this->db->update($this->table,$to_write,array('account_id' => abs($data['account_id'])),__LINE__,__FILE__)) |
|
226 | + if (!$this->db->update($this->table, $to_write, array('account_id' => abs($data['account_id'])), __LINE__, __FILE__)) |
|
227 | 227 | { |
228 | 228 | return false; |
229 | 229 | } |
@@ -272,15 +272,15 @@ discard block |
||
272 | 272 | { |
273 | 273 | if (!(int)$account_id) return false; |
274 | 274 | |
275 | - $contact_id = $this->id2name($account_id,'person_id'); |
|
275 | + $contact_id = $this->id2name($account_id, 'person_id'); |
|
276 | 276 | |
277 | - if (!$this->db->delete($this->table,array('account_id' => abs($account_id)),__LINE__,__FILE__)) |
|
277 | + if (!$this->db->delete($this->table, array('account_id' => abs($account_id)), __LINE__, __FILE__)) |
|
278 | 278 | { |
279 | 279 | return false; |
280 | 280 | } |
281 | 281 | if ($contact_id) |
282 | 282 | { |
283 | - $GLOBALS['egw']->contacts->delete($contact_id,false); // false = allow to delete accounts (!) |
|
283 | + $GLOBALS['egw']->contacts->delete($contact_id, false); // false = allow to delete accounts (!) |
|
284 | 284 | } |
285 | 285 | return true; |
286 | 286 | } |
@@ -296,11 +296,11 @@ discard block |
||
296 | 296 | if (!(int)$account_id) return false; |
297 | 297 | |
298 | 298 | $memberships = array(); |
299 | - if(($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id))) |
|
299 | + if (($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id))) |
|
300 | 300 | { |
301 | - foreach($gids as $gid) |
|
301 | + foreach ($gids as $gid) |
|
302 | 302 | { |
303 | - $memberships[(string) $gid] = $this->id2name($gid); |
|
303 | + $memberships[(string)$gid] = $this->id2name($gid); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | //echo "accounts::memberships($account_id)"; _debug_array($memberships); |
@@ -313,17 +313,17 @@ discard block |
||
313 | 313 | * @param array $groups array with gidnumbers |
314 | 314 | * @param int $account_id numerical account-id |
315 | 315 | */ |
316 | - function set_memberships($groups,$account_id) |
|
316 | + function set_memberships($groups, $account_id) |
|
317 | 317 | { |
318 | 318 | if (!(int)$account_id) return; |
319 | 319 | |
320 | - $acl =& CreateObject('phpgwapi.acl',$account_id); |
|
320 | + $acl = & CreateObject('phpgwapi.acl', $account_id); |
|
321 | 321 | $acl->read_repository(); |
322 | - $acl->delete('phpgw_group',false); |
|
322 | + $acl->delete('phpgw_group', false); |
|
323 | 323 | |
324 | - foreach($groups as $group) |
|
324 | + foreach ($groups as $group) |
|
325 | 325 | { |
326 | - $acl->add('phpgw_group',$group,1); |
|
326 | + $acl->add('phpgw_group', $group, 1); |
|
327 | 327 | } |
328 | 328 | $acl->save_repository(); |
329 | 329 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | if (!is_numeric($account_id)) $account_id = $this->name2id($account_id); |
340 | 340 | |
341 | 341 | $members = array(); |
342 | - foreach($this->db->select($this->table, 'account_id,account_lid', |
|
342 | + foreach ($this->db->select($this->table, 'account_id,account_lid', |
|
343 | 343 | $this->db->expression(acl::TABLE, array( |
344 | 344 | 'acl_appname' => 'phpgw_group', |
345 | 345 | 'acl_location' => $account_id, |
@@ -359,16 +359,16 @@ discard block |
||
359 | 359 | * @param array $members array with uidnumber or uid's |
360 | 360 | * @param int $gid gidnumber of group to set |
361 | 361 | */ |
362 | - function set_members($members,$gid) |
|
362 | + function set_members($members, $gid) |
|
363 | 363 | { |
364 | 364 | //echo "<p align=right>accounts::set_members(".print_r($members,true).",$gid)</p>\n"; |
365 | - $GLOBALS['egw']->acl->delete_repository('phpgw_group',$gid,false); |
|
365 | + $GLOBALS['egw']->acl->delete_repository('phpgw_group', $gid, false); |
|
366 | 366 | |
367 | 367 | if (is_array($members)) |
368 | 368 | { |
369 | - foreach($members as $id) |
|
369 | + foreach ($members as $id) |
|
370 | 370 | { |
371 | - $GLOBALS['egw']->acl->add_repository('phpgw_group',$gid,$id,1); |
|
371 | + $GLOBALS['egw']->acl->add_repository('phpgw_group', $gid, $id, 1); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | } |
@@ -403,20 +403,20 @@ discard block |
||
403 | 403 | ); |
404 | 404 | |
405 | 405 | // fetch order of account_fullname from common::display_fullname |
406 | - if (strpos($param['order'],'account_fullname') !== false) |
|
406 | + if (strpos($param['order'], 'account_fullname') !== false) |
|
407 | 407 | { |
408 | - $param['order'] = str_replace('account_fullname', preg_replace('/[ ,]+/',',',str_replace(array('[',']'),'', |
|
409 | - common::display_fullname('account_lid','account_firstname','account_lastname'))), $param['order']); |
|
408 | + $param['order'] = str_replace('account_fullname', preg_replace('/[ ,]+/', ',', str_replace(array('[', ']'), '', |
|
409 | + common::display_fullname('account_lid', 'account_firstname', 'account_lastname'))), $param['order']); |
|
410 | 410 | } |
411 | - $order = str_replace(array_keys($order2contact),array_values($order2contact),$param['order']); |
|
411 | + $order = str_replace(array_keys($order2contact), array_values($order2contact), $param['order']); |
|
412 | 412 | // allways add 'account_lid', as it is only valid one for groups |
413 | 413 | if (strpos($order, 'account_lid') === false) |
414 | 414 | { |
415 | - $order .= ($order?',':'').'account_lid'; |
|
415 | + $order .= ($order ? ',' : '').'account_lid'; |
|
416 | 416 | } |
417 | 417 | if ($param['sort']) $order = implode(' '.$param['sort'].',', explode(',', $order)).' '.$param['sort']; |
418 | 418 | |
419 | - $search_cols = array('account_lid','n_family','n_given','email'); |
|
419 | + $search_cols = array('account_lid', 'n_family', 'n_given', 'email'); |
|
420 | 420 | $join = $this->contacts_join; |
421 | 421 | $email_cols = array('email'); |
422 | 422 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | } |
433 | 433 | |
434 | 434 | $filter = array(); |
435 | - switch($param['type']) |
|
435 | + switch ($param['type']) |
|
436 | 436 | { |
437 | 437 | case 'accounts': |
438 | 438 | $filter['owner'] = 0; |
@@ -447,9 +447,9 @@ discard block |
||
447 | 447 | case 'groupmembers': |
448 | 448 | case 'groupmembers+memberships': |
449 | 449 | $members = array(); |
450 | - foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp) |
|
450 | + foreach ((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp) |
|
451 | 451 | { |
452 | - $members = array_unique(array_merge($members, (array)$this->members($grp,true))); |
|
452 | + $members = array_unique(array_merge($members, (array)$this->members($grp, true))); |
|
453 | 453 | if ($param['type'] == 'groupmembers+memberships') $members[] = abs($grp); |
454 | 454 | } |
455 | 455 | $filter['account_id'] = $members; |
@@ -481,13 +481,13 @@ discard block |
||
481 | 481 | } |
482 | 482 | if ($param['active']) |
483 | 483 | { |
484 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),addressbook_sql::ACOUNT_ACTIVE_FILTER); |
|
484 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), addressbook_sql::ACOUNT_ACTIVE_FILTER); |
|
485 | 485 | } |
486 | 486 | $criteria = array(); |
487 | 487 | $wildcard = $param['query_type'] == 'start' || $param['query_type'] == 'exact' ? '' : '%'; |
488 | 488 | if (($query = $param['query'])) |
489 | 489 | { |
490 | - switch($param['query_type']) |
|
490 | + switch ($param['query_type']) |
|
491 | 491 | { |
492 | 492 | case 'start': |
493 | 493 | $query .= '*'; |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | case 'all': |
496 | 496 | default: |
497 | 497 | case 'exact': |
498 | - foreach($search_cols as $col) |
|
498 | + foreach ($search_cols as $col) |
|
499 | 499 | { |
500 | 500 | $criteria[$col] = $query; |
501 | 501 | } |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | case 'email': |
517 | 517 | $criteria['email'] = $query; |
518 | 518 | // Group email |
519 | - if(in_array(emailadmin_smtp_sql::TABLE, $this->db->table_names(true))) |
|
519 | + if (in_array(emailadmin_smtp_sql::TABLE, $this->db->table_names(true))) |
|
520 | 520 | { |
521 | 521 | $criteria[emailadmin_smtp_sql::TABLE.'.mail_value'] = $query; |
522 | 522 | } |
@@ -526,12 +526,12 @@ discard block |
||
526 | 526 | if (!is_object($GLOBALS['egw']->contacts)) throw new exception('No $GLOBALS[egw]->contacts!'); |
527 | 527 | |
528 | 528 | $accounts = array(); |
529 | - foreach((array) $GLOBALS['egw']->contacts->search($criteria, |
|
530 | - array_merge(array(1,'n_given','n_family','id','created','modified',$this->table.'.account_id AS account_id'),$email_cols), |
|
531 | - $order,"account_lid,account_type,account_status,account_expires,account_primary_group,account_description", |
|
532 | - $wildcard,false,$query[0] == '!' ? 'AND' : 'OR', |
|
529 | + foreach ((array)$GLOBALS['egw']->contacts->search($criteria, |
|
530 | + array_merge(array(1, 'n_given', 'n_family', 'id', 'created', 'modified', $this->table.'.account_id AS account_id'), $email_cols), |
|
531 | + $order, "account_lid,account_type,account_status,account_expires,account_primary_group,account_description", |
|
532 | + $wildcard, false, $query[0] == '!' ? 'AND' : 'OR', |
|
533 | 533 | $param['offset'] ? array($param['start'], $param['offset']) : (is_null($param['start']) ? false : $param['start']), |
534 | - $filter,$join) as $contact) |
|
534 | + $filter, $join) as $contact) |
|
535 | 535 | { |
536 | 536 | if ($contact) |
537 | 537 | { |
@@ -571,13 +571,13 @@ discard block |
||
571 | 571 | * @param string $account_type u = user, g = group, default null = try both |
572 | 572 | * @return int/false numeric account_id or false on error ($name not found) |
573 | 573 | */ |
574 | - function name2id($name,$which='account_lid',$account_type=null) |
|
574 | + function name2id($name, $which = 'account_lid', $account_type = null) |
|
575 | 575 | { |
576 | 576 | if ($account_type === 'g' && $which != 'account_lid') return false; |
577 | 577 | |
578 | 578 | $where = array(); |
579 | 579 | $cols = 'account_id'; |
580 | - switch($which) |
|
580 | + switch ($which) |
|
581 | 581 | { |
582 | 582 | case 'account_fullname': |
583 | 583 | $table = $this->contacts_table; |
@@ -608,11 +608,11 @@ discard block |
||
608 | 608 | } |
609 | 609 | else |
610 | 610 | { |
611 | - $where[] = 'account_id IS NOT NULL'. // otherwise contacts with eg. the same email hide the accounts! |
|
612 | - ($table == $this->contacts_table ? " AND contact_tid != 'D'" : ''); // ignore deleted accounts contact-data |
|
611 | + $where[] = 'account_id IS NOT NULL'.// otherwise contacts with eg. the same email hide the accounts! |
|
612 | + ($table == $this->contacts_table ? " AND contact_tid != 'D'" : ''); // ignore deleted accounts contact-data |
|
613 | 613 | |
614 | 614 | } |
615 | - if (!($rs = $this->db->select($table,$cols,$where,__LINE__,__FILE__)) || !($row = $rs->fetch())) |
|
615 | + if (!($rs = $this->db->select($table, $cols, $where, __LINE__, __FILE__)) || !($row = $rs->fetch())) |
|
616 | 616 | { |
617 | 617 | //error_log(__METHOD__."('$name', '$which', ".array2string($account_type).") db->select('$table', '$cols', ".array2string($where).") returned ".array2string($rs).' '.function_backtrace()); |
618 | 618 | return false; |
@@ -629,9 +629,9 @@ discard block |
||
629 | 629 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
630 | 630 | * @return string/false converted value or false on error ($account_id not found) |
631 | 631 | */ |
632 | - function id2name($account_id,$which='account_lid') |
|
632 | + function id2name($account_id, $which = 'account_lid') |
|
633 | 633 | { |
634 | - return $this->frontend->id2name($account_id,$which); |
|
634 | + return $this->frontend->id2name($account_id, $which); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | /** |
@@ -643,14 +643,14 @@ discard block |
||
643 | 643 | */ |
644 | 644 | function update_lastlogin($account_id, $ip) |
645 | 645 | { |
646 | - $previous_login = $this->db->select($this->table,'account_lastlogin',array('account_id'=>abs($account_id)),__LINE__,__FILE__)->fetchColumn(); |
|
646 | + $previous_login = $this->db->select($this->table, 'account_lastlogin', array('account_id'=>abs($account_id)), __LINE__, __FILE__)->fetchColumn(); |
|
647 | 647 | |
648 | - $this->db->update($this->table,array( |
|
648 | + $this->db->update($this->table, array( |
|
649 | 649 | 'account_lastloginfrom' => $ip, |
650 | 650 | 'account_lastlogin' => time(), |
651 | - ),array( |
|
651 | + ), array( |
|
652 | 652 | 'account_id' => abs($account_id), |
653 | - ),__LINE__,__FILE__); |
|
653 | + ), __LINE__, __FILE__); |
|
654 | 654 | |
655 | 655 | return $previous_login; |
656 | 656 | } |
@@ -114,7 +114,10 @@ discard block |
||
114 | 114 | */ |
115 | 115 | function read($account_id) |
116 | 116 | { |
117 | - if (!(int)$account_id) return false; |
|
117 | + if (!(int)$account_id) |
|
118 | + { |
|
119 | + return false; |
|
120 | + } |
|
118 | 121 | |
119 | 122 | if ($account_id > 0) |
120 | 123 | { |
@@ -144,11 +147,14 @@ discard block |
||
144 | 147 | unset($e); |
145 | 148 | } |
146 | 149 | |
147 | - if (!$rs) // handle not (yet) existing mailaccounts table |
|
150 | + if (!$rs) |
|
151 | + { |
|
152 | + // handle not (yet) existing mailaccounts table |
|
148 | 153 | { |
149 | 154 | $rs = $this->db->select($this->table, $this->table.'.*', |
150 | 155 | $this->table.'.account_id='.abs($account_id), __LINE__, __FILE__); |
151 | 156 | } |
157 | + } |
|
152 | 158 | if (!$rs || !($data = $rs->fetch())) |
153 | 159 | { |
154 | 160 | return false; |
@@ -158,7 +164,10 @@ discard block |
||
158 | 164 | $data['account_id'] = -$data['account_id']; |
159 | 165 | $data['mailAllowed'] = true; |
160 | 166 | } |
161 | - if (!$data['account_firstname']) $data['account_firstname'] = $data['account_lid']; |
|
167 | + if (!$data['account_firstname']) |
|
168 | + { |
|
169 | + $data['account_firstname'] = $data['account_lid']; |
|
170 | + } |
|
162 | 171 | if (!$data['account_lastname']) |
163 | 172 | { |
164 | 173 | $data['account_lastname'] = $data['account_type'] == 'g' ? 'Group' : 'User'; |
@@ -169,7 +178,10 @@ discard block |
||
169 | 178 | $data['account_lastname'] = lang($data['account_lastname']); |
170 | 179 | } |
171 | 180 | } |
172 | - if (!$data['account_fullname']) $data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname']; |
|
181 | + if (!$data['account_fullname']) |
|
182 | + { |
|
183 | + $data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname']; |
|
184 | + } |
|
173 | 185 | |
174 | 186 | //echo "accounts_sql::read($account_id)"; _debug_array($data); |
175 | 187 | return $data; |
@@ -193,31 +205,57 @@ discard block |
||
193 | 205 | { |
194 | 206 | // if password it's not already entcrypted, do so now |
195 | 207 | if (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']) && |
196 | - !preg_match('/^[0-9a-f]{32}$/',$data['account_passwd'])) // md5 hash |
|
208 | + !preg_match('/^[0-9a-f]{32}$/',$data['account_passwd'])) |
|
209 | + { |
|
210 | + // md5 hash |
|
197 | 211 | { |
198 | 212 | $data['account_passwd'] = $GLOBALS['egw']->auth->encrypt_sql($data['account_passwd']); |
199 | 213 | } |
214 | + } |
|
200 | 215 | $to_write['account_pwd'] = $data['account_passwd']; |
201 | 216 | $to_write['account_lastpwd_change'] = time(); |
202 | 217 | } |
203 | - if ($data['mustchangepassword'] == 1) $to_write['account_lastpwd_change']=0; |
|
218 | + if ($data['mustchangepassword'] == 1) |
|
219 | + { |
|
220 | + $to_write['account_lastpwd_change']=0; |
|
221 | + } |
|
204 | 222 | if (!(int)$data['account_id'] || !$this->id2name($data['account_id'])) |
205 | 223 | { |
206 | - if ($to_write['account_id'] < 0) $to_write['account_id'] *= -1; |
|
224 | + if ($to_write['account_id'] < 0) |
|
225 | + { |
|
226 | + $to_write['account_id'] *= -1; |
|
227 | + } |
|
207 | 228 | |
208 | - if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = ''; // is NOT NULL! |
|
209 | - if (!isset($to_write['account_status'])) $to_write['account_status'] = ''; // is NOT NULL! |
|
229 | + if (!isset($to_write['account_pwd'])) |
|
230 | + { |
|
231 | + $to_write['account_pwd'] = ''; |
|
232 | + } |
|
233 | + // is NOT NULL! |
|
234 | + if (!isset($to_write['account_status'])) |
|
235 | + { |
|
236 | + $to_write['account_status'] = ''; |
|
237 | + } |
|
238 | + // is NOT NULL! |
|
210 | 239 | |
211 | 240 | // postgres requires the auto-id field to be unset! |
212 | - if (isset($to_write['account_id']) && !$to_write['account_id']) unset($to_write['account_id']); |
|
241 | + if (isset($to_write['account_id']) && !$to_write['account_id']) |
|
242 | + { |
|
243 | + unset($to_write['account_id']); |
|
244 | + } |
|
213 | 245 | |
214 | 246 | if (!in_array($to_write['account_type'],array('u','g')) || |
215 | - !$this->db->insert($this->table,$to_write,false,__LINE__,__FILE__)) return false; |
|
247 | + !$this->db->insert($this->table,$to_write,false,__LINE__,__FILE__)) |
|
248 | + { |
|
249 | + return false; |
|
250 | + } |
|
216 | 251 | |
217 | 252 | if (!(int)$data['account_id']) |
218 | 253 | { |
219 | 254 | $data['account_id'] = $this->db->get_last_insert_id($this->table,'account_id'); |
220 | - if ($data['account_type'] == 'g') $data['account_id'] *= -1; |
|
255 | + if ($data['account_type'] == 'g') |
|
256 | + { |
|
257 | + $data['account_id'] *= -1; |
|
258 | + } |
|
221 | 259 | } |
222 | 260 | } |
223 | 261 | else // update of existing account |
@@ -270,7 +308,10 @@ discard block |
||
270 | 308 | */ |
271 | 309 | function delete($account_id) |
272 | 310 | { |
273 | - if (!(int)$account_id) return false; |
|
311 | + if (!(int)$account_id) |
|
312 | + { |
|
313 | + return false; |
|
314 | + } |
|
274 | 315 | |
275 | 316 | $contact_id = $this->id2name($account_id,'person_id'); |
276 | 317 | |
@@ -293,7 +334,10 @@ discard block |
||
293 | 334 | */ |
294 | 335 | function memberships($account_id) |
295 | 336 | { |
296 | - if (!(int)$account_id) return false; |
|
337 | + if (!(int)$account_id) |
|
338 | + { |
|
339 | + return false; |
|
340 | + } |
|
297 | 341 | |
298 | 342 | $memberships = array(); |
299 | 343 | if(($gids = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id))) |
@@ -315,7 +359,10 @@ discard block |
||
315 | 359 | */ |
316 | 360 | function set_memberships($groups,$account_id) |
317 | 361 | { |
318 | - if (!(int)$account_id) return; |
|
362 | + if (!(int)$account_id) |
|
363 | + { |
|
364 | + return; |
|
365 | + } |
|
319 | 366 | |
320 | 367 | $acl =& CreateObject('phpgwapi.acl',$account_id); |
321 | 368 | $acl->read_repository(); |
@@ -336,7 +383,10 @@ discard block |
||
336 | 383 | */ |
337 | 384 | function members($account_id) |
338 | 385 | { |
339 | - if (!is_numeric($account_id)) $account_id = $this->name2id($account_id); |
|
386 | + if (!is_numeric($account_id)) |
|
387 | + { |
|
388 | + $account_id = $this->name2id($account_id); |
|
389 | + } |
|
340 | 390 | |
341 | 391 | $members = array(); |
342 | 392 | foreach($this->db->select($this->table, 'account_id,account_lid', |
@@ -414,7 +464,10 @@ discard block |
||
414 | 464 | { |
415 | 465 | $order .= ($order?',':'').'account_lid'; |
416 | 466 | } |
417 | - if ($param['sort']) $order = implode(' '.$param['sort'].',', explode(',', $order)).' '.$param['sort']; |
|
467 | + if ($param['sort']) |
|
468 | + { |
|
469 | + $order = implode(' '.$param['sort'].',', explode(',', $order)).' '.$param['sort']; |
|
470 | + } |
|
418 | 471 | |
419 | 472 | $search_cols = array('account_lid','n_family','n_given','email'); |
420 | 473 | $join = $this->contacts_join; |
@@ -450,7 +503,10 @@ discard block |
||
450 | 503 | foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp) |
451 | 504 | { |
452 | 505 | $members = array_unique(array_merge($members, (array)$this->members($grp,true))); |
453 | - if ($param['type'] == 'groupmembers+memberships') $members[] = abs($grp); |
|
506 | + if ($param['type'] == 'groupmembers+memberships') |
|
507 | + { |
|
508 | + $members[] = abs($grp); |
|
509 | + } |
|
454 | 510 | } |
455 | 511 | $filter['account_id'] = $members; |
456 | 512 | break; |
@@ -469,9 +525,12 @@ discard block |
||
469 | 525 | // fix ambigous account_id (used in accounts and contacts table) |
470 | 526 | if (array_key_exists('account_id', $filter)) |
471 | 527 | { |
472 | - if (!$filter['account_id']) // eg. group without members (would give SQL error) |
|
528 | + if (!$filter['account_id']) |
|
529 | + { |
|
530 | + // eg. group without members (would give SQL error) |
|
473 | 531 | { |
474 | 532 | $this->total = 0; |
533 | + } |
|
475 | 534 | return array(); |
476 | 535 | } |
477 | 536 | $filter[] = $this->db->expression($this->table, $this->table.'.', array( |
@@ -523,7 +582,10 @@ discard block |
||
523 | 582 | break; |
524 | 583 | } |
525 | 584 | } |
526 | - if (!is_object($GLOBALS['egw']->contacts)) throw new exception('No $GLOBALS[egw]->contacts!'); |
|
585 | + if (!is_object($GLOBALS['egw']->contacts)) |
|
586 | + { |
|
587 | + throw new exception('No $GLOBALS[egw]->contacts!'); |
|
588 | + } |
|
527 | 589 | |
528 | 590 | $accounts = array(); |
529 | 591 | foreach((array) $GLOBALS['egw']->contacts->search($criteria, |
@@ -573,7 +635,10 @@ discard block |
||
573 | 635 | */ |
574 | 636 | function name2id($name,$which='account_lid',$account_type=null) |
575 | 637 | { |
576 | - if ($account_type === 'g' && $which != 'account_lid') return false; |
|
638 | + if ($account_type === 'g' && $which != 'account_lid') |
|
639 | + { |
|
640 | + return false; |
|
641 | + } |
|
577 | 642 | |
578 | 643 | $where = array(); |
579 | 644 | $cols = 'account_id'; |
@@ -596,9 +661,12 @@ discard block |
||
596 | 661 | $cols .= ',account_type'; |
597 | 662 | $where[$which] = $name; |
598 | 663 | // check if we need to treat username case-insensitive |
599 | - if ($which == 'account_lid' && !$GLOBALS['egw_info']['server']['case_sensitive_username']) // = is case sensitiv eg. on postgres, but not on mysql! |
|
664 | + if ($which == 'account_lid' && !$GLOBALS['egw_info']['server']['case_sensitive_username']) |
|
665 | + { |
|
666 | + // = is case sensitiv eg. on postgres, but not on mysql! |
|
600 | 667 | { |
601 | 668 | $where[] = 'account_lid '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($where['account_lid']); |
669 | + } |
|
602 | 670 | unset($where['account_lid']); |
603 | 671 | } |
604 | 672 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | * If no account_id is set in data the account is added and the new id is set in $data. |
48 | 48 | * |
49 | 49 | * @param array $data array with account-data |
50 | - * @return int|boolean the account_id or false on error |
|
50 | + * @return false|string the account_id or false on error |
|
51 | 51 | */ |
52 | 52 | function save(&$data) |
53 | 53 | { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | if (!$data['account_id'] && $data['account_type'] !== 'g') |
63 | 63 | { |
64 | 64 | $params = array( |
65 | - 'users/user','create', |
|
65 | + 'users/user', 'create', |
|
66 | 66 | '--binddn', $config['ldap_root_dn'], |
67 | 67 | '--bindpwd', 5=>$config['ldap_root_pw'], |
68 | 68 | '--position', $config['ldap_context'], |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | $hostname = $account->acc_imap_host; |
89 | 89 | } |
90 | - catch(Exception $e) { |
|
90 | + catch (Exception $e) { |
|
91 | 91 | unset($e); |
92 | 92 | } |
93 | 93 | if (empty($hostname)) $hostname = trim(system('hostname -f')); |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | $output = implode("\n", $output_arr); |
100 | 100 | if ($ret || !preg_match('/^Object created: (uid=.*)$/mui', $output, $matches)) |
101 | 101 | { |
102 | - $params[5] = '********'; // mask out password! |
|
102 | + $params[5] = '********'; // mask out password! |
|
103 | 103 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
104 | 104 | throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output); |
105 | 105 | } |
106 | 106 | $data['account_dn'] = $matches[1]; |
107 | 107 | $data['account_id'] = $this->name2id($data['account_lid'], 'account_lid', 'u'); |
108 | 108 | } |
109 | - elseif($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) && |
|
109 | + elseif ($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) && |
|
110 | 110 | $data['account_lid'] != $data['old_loginid'] && |
111 | 111 | ($data['account_dn'] = $this->id2name($data['account_id'], 'account_dn'))) |
112 | 112 | { |
@@ -123,12 +123,11 @@ discard block |
||
123 | 123 | $output = implode("\n", $output_arr); |
124 | 124 | if ($ret || !preg_match('/^Object modified: ((uid|cn)=.*)$/mui', $output, $matches)) |
125 | 125 | { |
126 | - $params[5] = '********'; // mask out password! |
|
126 | + $params[5] = '********'; // mask out password! |
|
127 | 127 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
128 | 128 | throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output); |
129 | 129 | } |
130 | - $data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] : |
|
131 | - // duno why but directory-manager returns old dn for groups ... |
|
130 | + $data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] : // duno why but directory-manager returns old dn for groups ... |
|
132 | 131 | preg_replace('/^cn=[^,]+,/', 'cn='.$data['account_lid'].',', $data['account_dn']); |
133 | 132 | } |
134 | 133 | } |
@@ -90,7 +90,10 @@ |
||
90 | 90 | catch(Exception $e) { |
91 | 91 | unset($e); |
92 | 92 | } |
93 | - if (empty($hostname)) $hostname = trim(system('hostname -f')); |
|
93 | + if (empty($hostname)) |
|
94 | + { |
|
95 | + $hostname = trim(system('hostname -f')); |
|
96 | + } |
|
94 | 97 | $params[] = '--set'; $params[] = 'mailHomeServer='.$hostname; |
95 | 98 | } |
96 | 99 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * cancels a timer |
325 | 325 | * |
326 | 326 | * @param string $id has to be the one used to set it. |
327 | - * @return boolean True if the timer exists and is not expired. |
|
327 | + * @return integer True if the timer exists and is not expired. |
|
328 | 328 | */ |
329 | 329 | function cancel_timer($id) |
330 | 330 | { |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | /** |
471 | 471 | * reads all matching db-rows / jobs |
472 | 472 | * |
473 | - * @param string $id =0 reads all expired rows / jobs ready to run\ |
|
473 | + * @param integer $id =0 reads all expired rows / jobs ready to run\ |
|
474 | 474 | * != 0 reads all rows/jobs matching $id (sql-wildcards '%' and '_' can be used) |
475 | 475 | * @param array|string $cols ='*' string or array of column-names / select-expressions |
476 | 476 | * @param int|bool $offset =False offset for a limited query or False (default) |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | /** |
559 | 559 | * delete db-row / job with $id |
560 | 560 | * |
561 | - * @return boolean False if $id not found else True |
|
561 | + * @return integer False if $id not found else True |
|
562 | 562 | */ |
563 | 563 | function delete($id) |
564 | 564 | { |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | { |
50 | 50 | $this->db = $GLOBALS['egw_setup']->db; |
51 | 51 | } |
52 | - $this->cronline = EGW_SERVER_ROOT . '/phpgwapi/cron/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
52 | + $this->cronline = EGW_SERVER_ROOT.'/phpgwapi/cron/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
53 | 53 | |
54 | - $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
54 | + $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | * @param boolean $debug =false |
72 | 72 | * @return boolean False if $id already exists, else True |
73 | 73 | */ |
74 | - function set_timer($times,$id,$method,$data=null,$account_id=False,$debug=false) |
|
74 | + function set_timer($times, $id, $method, $data = null, $account_id = False, $debug = false) |
|
75 | 75 | { |
76 | 76 | if (empty($id) || empty($method) || $this->read($id) || |
77 | - !($next = $this->next_run($times,$debug))) |
|
77 | + !($next = $this->next_run($times, $debug))) |
|
78 | 78 | { |
79 | 79 | return False; |
80 | 80 | } |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | * @param int $now Use this time to calculate then next run from. Defaults to time(). |
108 | 108 | * @return int a unix timestamp of the next execution time or False if no more executions |
109 | 109 | */ |
110 | - function next_run($times,$debug=False, $now = null) |
|
110 | + function next_run($times, $debug = False, $now = null) |
|
111 | 111 | { |
112 | 112 | if ($this->debug) |
113 | 113 | { |
114 | - echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n"; |
|
115 | - $debug = True; // enable syntax-error messages too |
|
114 | + echo "<p>next_run("; print_r($times); echo ",'$debug', ".date('Y-m-d H:i', $now).")</p>\n"; |
|
115 | + $debug = True; // enable syntax-error messages too |
|
116 | 116 | } |
117 | - if(is_null($now)) { |
|
117 | + if (is_null($now)) { |
|
118 | 118 | $now = time(); |
119 | 119 | } |
120 | 120 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | 'dow' => 6, |
143 | 143 | 'day' => 31, |
144 | 144 | 'month' => 12, |
145 | - 'year' => date('Y')+10 // else */[0-9] would never stop returning numbers |
|
145 | + 'year' => date('Y') + 10 // else */[0-9] would never stop returning numbers |
|
146 | 146 | ); |
147 | 147 | $min_unit = array( |
148 | 148 | 'min' => 0, |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | // get set to the minimum after |
159 | 159 | // |
160 | 160 | $i = $first_set = $last_set = 0; |
161 | - foreach($units as $u => $date_pattern) |
|
161 | + foreach ($units as $u => $date_pattern) |
|
162 | 162 | { |
163 | 163 | ++$i; |
164 | 164 | if (isset($times[$u])) |
@@ -176,24 +176,24 @@ discard block |
||
176 | 176 | // (as descript above), enumerations are arrays with unit-values as keys |
177 | 177 | // |
178 | 178 | $n = 0; |
179 | - foreach($units as $u => $date_pattern) |
|
179 | + foreach ($units as $u => $date_pattern) |
|
180 | 180 | { |
181 | 181 | ++$n; |
182 | - if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
182 | + if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u]) ? 'True' : 'False')."</p>\n"; } |
|
183 | 183 | if (isset($times[$u])) |
184 | 184 | { |
185 | - if(is_array($times[$u])) { |
|
185 | + if (is_array($times[$u])) { |
|
186 | 186 | $time = array_keys($times[$u]); |
187 | 187 | } else { |
188 | - $time = explode(',',$times[$u]); |
|
188 | + $time = explode(',', $times[$u]); |
|
189 | 189 | } |
190 | 190 | $times[$u] = array(); |
191 | 191 | |
192 | - foreach($time as $t) |
|
192 | + foreach ($time as $t) |
|
193 | 193 | { |
194 | - if (strpos($t,'-') !== False && strpos($t,'/') === False) |
|
194 | + if (strpos($t, '-') !== False && strpos($t, '/') === False) |
|
195 | 195 | { |
196 | - list($min,$max) = $arr = explode('-',$t); |
|
196 | + list($min, $max) = $arr = explode('-', $t); |
|
197 | 197 | |
198 | 198 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
199 | 199 | { |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | { |
211 | 211 | if ((string)$t == '*') $t = '*/1'; |
212 | 212 | |
213 | - list($one,$inc) = $arr = explode('/',$t); |
|
213 | + list($one, $inc) = $arr = explode('/', $t); |
|
214 | 214 | |
215 | 215 | if (!(is_numeric($one) && count($arr) == 1 || |
216 | 216 | count($arr) == 2 && is_numeric($inc))) |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | } |
226 | 226 | else |
227 | 227 | { |
228 | - list($min,$max) = $arr = explode('-',$one); |
|
228 | + list($min, $max) = $arr = explode('-', $one); |
|
229 | 229 | if (empty($one) || $one == '*') |
230 | 230 | { |
231 | 231 | $min = $min_unit[$u]; |
@@ -266,20 +266,19 @@ discard block |
||
266 | 266 | { |
267 | 267 | $future = False; |
268 | 268 | |
269 | - foreach($units as $u => $date_pattern) |
|
269 | + foreach ($units as $u => $date_pattern) |
|
270 | 270 | { |
271 | - $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : |
|
272 | - (int)date($date_pattern,mktime(12,0,0,$found['month'],$found['day'],$found['year'])); |
|
271 | + $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : (int)date($date_pattern, mktime(12, 0, 0, $found['month'], $found['day'], $found['year'])); |
|
273 | 272 | |
274 | 273 | if (isset($found[$u])) |
275 | 274 | { |
276 | 275 | $future = $future || $found[$u] > $unit_now; |
277 | 276 | if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
278 | - continue; // already set |
|
277 | + continue; // already set |
|
279 | 278 | } |
280 | - foreach(array_keys($times[$u]) as $unit_value) |
|
279 | + foreach (array_keys($times[$u]) as $unit_value) |
|
281 | 280 | { |
282 | - switch($u) |
|
281 | + switch ($u) |
|
283 | 282 | { |
284 | 283 | case 'dow': |
285 | 284 | $valid = $unit_value == $unit_now; |
@@ -302,12 +301,12 @@ discard block |
||
302 | 301 | if (!isset($found[$u])) // we have to try the next one, if it exists |
303 | 302 | { |
304 | 303 | $nexts = array_keys($units); |
305 | - if (!isset($nexts[count($found)-1])) |
|
304 | + if (!isset($nexts[count($found) - 1])) |
|
306 | 305 | { |
307 | 306 | if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n"; |
308 | 307 | return False; |
309 | 308 | } |
310 | - $next = $nexts[count($found)-1]; |
|
309 | + $next = $nexts[count($found) - 1]; |
|
311 | 310 | $over = $found[$next]; |
312 | 311 | unset($found[$next]); |
313 | 312 | if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
@@ -317,7 +316,7 @@ discard block |
||
317 | 316 | } |
318 | 317 | if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; } |
319 | 318 | |
320 | - return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
|
319 | + return mktime($found['hour'], $found['min'], 0, $found['month'], $found['day'], $found['year']); |
|
321 | 320 | } |
322 | 321 | |
323 | 322 | /** |
@@ -339,7 +338,7 @@ discard block |
||
339 | 338 | * @return mixed if !$set array('start' => $start,'end' => $end) with timestamps of last check_run start and end, \ |
340 | 339 | * !$end means check_run is just running. If $set returns True if it was able to get the semaphore, else False |
341 | 340 | */ |
342 | - function last_check_run($semaphore=False,$release=False,$run_by='') |
|
341 | + function last_check_run($semaphore = False, $release = False, $run_by = '') |
|
343 | 342 | { |
344 | 343 | //echo "<p>last_check_run(semaphore=".($semaphore?'True':'False').",release=".($release?'True':'False').")</p>\n"; |
345 | 344 | if (($exists = $this->read('##last-check-run##'))) |
@@ -361,7 +360,7 @@ discard block |
||
361 | 360 | } |
362 | 361 | else |
363 | 362 | { |
364 | - @set_time_limit(0); // dont stop for an execution-time-limit |
|
363 | + @set_time_limit(0); // dont stop for an execution-time-limit |
|
365 | 364 | ignore_user_abort(True); |
366 | 365 | |
367 | 366 | $last_run = array( |
@@ -377,7 +376,7 @@ discard block |
||
377 | 376 | ); |
378 | 377 | // as the async_next column is used as a semaphore we only update it, |
379 | 378 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
380 | - if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
379 | + if ($exists) $where = array('async_next=0 OR async_next<'.(time() - 600)); |
|
381 | 380 | } |
382 | 381 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
383 | 382 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -386,20 +385,20 @@ discard block |
||
386 | 385 | /** |
387 | 386 | * checks if there are any jobs ready to run (timer expired) and executes them |
388 | 387 | */ |
389 | - function check_run($run_by='') |
|
388 | + function check_run($run_by = '') |
|
390 | 389 | { |
391 | 390 | if ($run_by === 'fallback') flush(); |
392 | 391 | |
393 | - if (!$this->last_check_run(True,False,$run_by)) |
|
392 | + if (!$this->last_check_run(True, False, $run_by)) |
|
394 | 393 | { |
395 | - return False; // cant obtain semaphore |
|
394 | + return False; // cant obtain semaphore |
|
396 | 395 | } |
397 | 396 | // mark enviroment as async-service, check with isset()! |
398 | 397 | $GLOBALS['egw_info']['flags']['async-service'] = $run_by; |
399 | 398 | |
400 | 399 | if (($jobs = $this->read())) |
401 | 400 | { |
402 | - foreach($jobs as $job) |
|
401 | + foreach ($jobs as $job) |
|
403 | 402 | { |
404 | 403 | // checking / setting up egw_info/user |
405 | 404 | // |
@@ -408,7 +407,7 @@ discard block |
||
408 | 407 | // run notifications, before changing account_id of enviroment |
409 | 408 | egw_link::run_notifies(); |
410 | 409 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
411 | - foreach($GLOBALS as $name => $value) |
|
410 | + foreach ($GLOBALS as $name => $value) |
|
412 | 411 | { |
413 | 412 | if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
414 | 413 | } |
@@ -420,7 +419,7 @@ discard block |
||
420 | 419 | { |
421 | 420 | $GLOBALS['egw']->session->account_lid = $GLOBALS['egw']->accounts->id2name($job['account_id']); |
422 | 421 | $GLOBALS['egw']->session->account_domain = $domain; |
423 | - $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
422 | + $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
424 | 423 | |
425 | 424 | if ($lang != $GLOBALS['egw_info']['user']['preferences']['common']['lang']) |
426 | 425 | { |
@@ -435,12 +434,11 @@ discard block |
||
435 | 434 | $GLOBALS['egw_info']['user']['domain'] = $domain; |
436 | 435 | } |
437 | 436 | } |
438 | - list($app) = strpos($job['method'],'::') !== false ? explode('_',$job['method']) : |
|
439 | - explode('.',$job['method']); |
|
437 | + list($app) = strpos($job['method'], '::') !== false ? explode('_', $job['method']) : explode('.', $job['method']); |
|
440 | 438 | translation::add_app($app); |
441 | 439 | if (is_array($job['data'])) |
442 | 440 | { |
443 | - $job['data'] += array_diff_key($job,array('data' => false)); |
|
441 | + $job['data'] += array_diff_key($job, array('data' => false)); |
|
444 | 442 | } |
445 | 443 | // update job before running it, to cope with jobs taking longer then async-frequency |
446 | 444 | if (($job['next'] = $this->next_run($job['times']))) |
@@ -453,16 +451,16 @@ discard block |
||
453 | 451 | } |
454 | 452 | try |
455 | 453 | { |
456 | - ExecMethod($job['method'],$job['data']); |
|
454 | + ExecMethod($job['method'], $job['data']); |
|
457 | 455 | } |
458 | - catch(Exception $e) |
|
456 | + catch (Exception $e) |
|
459 | 457 | { |
460 | 458 | // log the exception to error_log, but continue running other async jobs |
461 | 459 | _egw_log_exception($e); |
462 | 460 | } |
463 | 461 | } |
464 | 462 | } |
465 | - $this->last_check_run(True,True,$run_by); // release semaphore |
|
463 | + $this->last_check_run(True, True, $run_by); // release semaphore |
|
466 | 464 | |
467 | 465 | return $jobs ? count($jobs) : 0; |
468 | 466 | } |
@@ -478,7 +476,7 @@ discard block |
||
478 | 476 | * @param int $num_rows =0 number of rows to return if offset set, default 0 = use default in user prefs |
479 | 477 | * @return array/boolean db-rows / jobs as array or False if no matches |
480 | 478 | */ |
481 | - function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
|
479 | + function read($id = 0, $cols = '*', $offset = False, $append = 'ORDER BY async_next', $num_rows = 0) |
|
482 | 480 | { |
483 | 481 | if (!is_a($this->db, 'egw_db')) return false; |
484 | 482 | |
@@ -486,7 +484,7 @@ discard block |
||
486 | 484 | { |
487 | 485 | $where = "async_id != '##last-check-run##'"; |
488 | 486 | } |
489 | - elseif (!is_array($id) && (strpos($id,'%') !== False || strpos($id,'_') !== False)) |
|
487 | + elseif (!is_array($id) && (strpos($id, '%') !== False || strpos($id, '_') !== False)) |
|
490 | 488 | { |
491 | 489 | $id = $this->db->quote($id); |
492 | 490 | $where = "async_id LIKE $id AND async_id != '##last-check-run##'"; |
@@ -500,21 +498,21 @@ discard block |
||
500 | 498 | $where = array('async_id' => $id); |
501 | 499 | } |
502 | 500 | $jobs = array(); |
503 | - foreach($this->db->select($this->db_table,$cols,$where,__LINE__,__FILE__,$offset,$append,False,$num_rows) as $row) |
|
501 | + foreach ($this->db->select($this->db_table, $cols, $where, __LINE__, __FILE__, $offset, $append, False, $num_rows) as $row) |
|
504 | 502 | { |
505 | 503 | $row['async_times'] = json_php_unserialize($row['async_times']); |
506 | 504 | // check for broken value during migration |
507 | 505 | if ($row['async_data'][0] == '"' && substr($row['async_data'], 0, 7) == '"\\"\\\\\\"') |
508 | 506 | { |
509 | 507 | $row['async_data'] = null; |
510 | - $this->write(egw_db::strip_array_keys($row,'async_'), true); |
|
508 | + $this->write(egw_db::strip_array_keys($row, 'async_'), true); |
|
511 | 509 | } |
512 | 510 | else |
513 | 511 | { |
514 | 512 | $row['async_data'] = !empty($row['async_data']) ? |
515 | - json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
513 | + json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
516 | 514 | } |
517 | - $jobs[$row['async_id']] = egw_db::strip_array_keys($row,'async_'); |
|
515 | + $jobs[$row['async_id']] = egw_db::strip_array_keys($row, 'async_'); |
|
518 | 516 | } |
519 | 517 | if (!count($jobs)) |
520 | 518 | { |
@@ -531,7 +529,7 @@ discard block |
||
531 | 529 | * @param array $where additional where statemetn to update only if a certain condition is met, used for the semaphore |
532 | 530 | * @return int affected rows, can be 0 if an additional where statement is given |
533 | 531 | */ |
534 | - function write($job, $exists = False, $where=array()) |
|
532 | + function write($job, $exists = False, $where = array()) |
|
535 | 533 | { |
536 | 534 | if (!is_a($this->db, 'egw_db')) return 0; |
537 | 535 | |
@@ -562,7 +560,7 @@ discard block |
||
562 | 560 | */ |
563 | 561 | function delete($id) |
564 | 562 | { |
565 | - $this->db->delete($this->db_table,array('async_id' => $id),__LINE__,__FILE__); |
|
563 | + $this->db->delete($this->db_table, array('async_id' => $id), __LINE__, __FILE__); |
|
566 | 564 | |
567 | 565 | return $this->db->affected_rows(); |
568 | 566 | } |
@@ -587,38 +585,38 @@ discard block |
||
587 | 585 | { |
588 | 586 | $binarys = array( |
589 | 587 | 'php' => '/usr/bin/php', |
590 | - 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
588 | + 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
591 | 589 | 'crontab' => '/usr/bin/crontab' |
592 | 590 | ); |
593 | 591 | foreach ($binarys as $name => $path) |
594 | 592 | { |
595 | - $this->$name = $path; // a reasonable default for *nix |
|
593 | + $this->$name = $path; // a reasonable default for *nix |
|
596 | 594 | |
597 | 595 | if (!($Ok = @is_executable($this->$name))) |
598 | 596 | { |
599 | 597 | if (file_exists($this->$name)) |
600 | 598 | { |
601 | - echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
|
599 | + echo '<p>'.lang('%1 is not executable by the webserver !!!', $this->$name)."</p>\n"; |
|
602 | 600 | $perms = fileperms($this->$name); |
603 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
601 | + if (!($perms&0x0001) && ($perms&0x0008) && function_exists('posix_getuid')) // only executable by group |
|
604 | 602 | { |
605 | 603 | $group = posix_getgrgid(filegroup($this->$name)); |
606 | - $webserver = posix_getpwuid(posix_getuid ()); |
|
607 | - echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
|
604 | + $webserver = posix_getpwuid(posix_getuid()); |
|
605 | + echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.", $webserver['name'], $group['name'])."</p>\n"; } |
|
608 | 606 | } |
609 | - if (($fd = popen('/bin/sh -c "type -p '.$name.'"','r'))) |
|
607 | + if (($fd = popen('/bin/sh -c "type -p '.$name.'"', 'r'))) |
|
610 | 608 | { |
611 | - $this->$name = fgets($fd,256); |
|
609 | + $this->$name = fgets($fd, 256); |
|
612 | 610 | @pclose($fd); |
613 | 611 | } |
614 | - if (($pos = strpos($this->$name,"\n"))) |
|
612 | + if (($pos = strpos($this->$name, "\n"))) |
|
615 | 613 | { |
616 | - $this->$name = substr($this->$name,0,$pos); |
|
614 | + $this->$name = substr($this->$name, 0, $pos); |
|
617 | 615 | } |
618 | 616 | } |
619 | 617 | if (!$Ok && !@is_executable($this->$name)) |
620 | 618 | { |
621 | - $this->$name = $name; // hopefully its in the path |
|
619 | + $this->$name = $name; // hopefully its in the path |
|
622 | 620 | } |
623 | 621 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
624 | 622 | } |
@@ -649,15 +647,15 @@ discard block |
||
649 | 647 | } |
650 | 648 | $times = False; |
651 | 649 | $this->other_cronlines = array(); |
652 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1','r')) !== False) |
|
650 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1', 'r')) !== False) |
|
653 | 651 | { |
654 | 652 | $n = 0; |
655 | - while ($line = fgets($crontab,256)) |
|
653 | + while ($line = fgets($crontab, 256)) |
|
656 | 654 | { |
657 | 655 | if ($this->debug) echo 'line '.++$n.": $line<br>\n"; |
658 | - $parts = explode(' ',$line,6); |
|
656 | + $parts = explode(' ', $line, 6); |
|
659 | 657 | |
660 | - if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
|
658 | + if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5], 0, 3) != 'php')) |
|
661 | 659 | { |
662 | 660 | // ignore comments |
663 | 661 | if ($line{0} != '#') |
@@ -665,10 +663,10 @@ discard block |
||
665 | 663 | $times['error'] .= $line; |
666 | 664 | } |
667 | 665 | } |
668 | - elseif (strpos($line,$this->cronline) !== False) |
|
666 | + elseif (strpos($line, $this->cronline) !== False) |
|
669 | 667 | { |
670 | - $cron_units = array('min','hour','day','month','dow'); |
|
671 | - foreach($cron_units as $n => $u) |
|
668 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
669 | + foreach ($cron_units as $n => $u) |
|
672 | 670 | { |
673 | 671 | $times[$u] = $parts[$n]; |
674 | 672 | } |
@@ -699,29 +697,29 @@ discard block |
||
699 | 697 | if ($this->only_fallback && $times !== False) { |
700 | 698 | return 0; |
701 | 699 | } |
702 | - $this->installed(); // find other installed cronlines |
|
700 | + $this->installed(); // find other installed cronlines |
|
703 | 701 | |
704 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1','w')) !== False) |
|
702 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1', 'w')) !== False) |
|
705 | 703 | { |
706 | 704 | if (is_array($this->other_cronlines)) |
707 | 705 | { |
708 | 706 | foreach ($this->other_cronlines as $cronline) |
709 | 707 | { |
710 | - fwrite($crontab,$cronline); // preserv the other lines on install |
|
708 | + fwrite($crontab, $cronline); // preserv the other lines on install |
|
711 | 709 | } |
712 | 710 | } |
713 | 711 | if ($times !== False) |
714 | 712 | { |
715 | - $cron_units = array('min','hour','day','month','dow'); |
|
713 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
716 | 714 | $cronline = ''; |
717 | - foreach($cron_units as $cu) |
|
715 | + foreach ($cron_units as $cu) |
|
718 | 716 | { |
719 | - $cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' '; |
|
717 | + $cronline .= (isset($times[$cu]) ? $times[$cu] : '*').' '; |
|
720 | 718 | } |
721 | 719 | // -d memory_limit=-1 --> no memory limit |
722 | 720 | $cronline .= $this->php.' -q -d memory_limit=-1 '.$this->cronline."\n"; |
723 | 721 | //echo "<p>Installing: '$cronline'</p>\n"; |
724 | - fwrite($crontab,$cronline); |
|
722 | + fwrite($crontab, $cronline); |
|
725 | 723 | } |
726 | 724 | @pclose($crontab); |
727 | 725 | } |
@@ -114,7 +114,8 @@ discard block |
||
114 | 114 | echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n"; |
115 | 115 | $debug = True; // enable syntax-error messages too |
116 | 116 | } |
117 | - if(is_null($now)) { |
|
117 | + if(is_null($now)) |
|
118 | + { |
|
118 | 119 | $now = time(); |
119 | 120 | } |
120 | 121 | |
@@ -179,12 +180,17 @@ discard block |
||
179 | 180 | foreach($units as $u => $date_pattern) |
180 | 181 | { |
181 | 182 | ++$n; |
182 | - if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
183 | + if ($this->debug) |
|
184 | + { |
|
185 | +echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
183 | 186 | if (isset($times[$u])) |
184 | 187 | { |
185 | - if(is_array($times[$u])) { |
|
188 | + if(is_array($times[$u])) |
|
189 | + { |
|
186 | 190 | $time = array_keys($times[$u]); |
187 | - } else { |
|
191 | + } |
|
192 | + else |
|
193 | + { |
|
188 | 194 | $time = explode(',',$times[$u]); |
189 | 195 | } |
190 | 196 | $times[$u] = array(); |
@@ -197,7 +203,10 @@ discard block |
||
197 | 203 | |
198 | 204 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
199 | 205 | { |
200 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
206 | + if ($debug) |
|
207 | + { |
|
208 | + echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
209 | + } |
|
201 | 210 | |
202 | 211 | return False; |
203 | 212 | } |
@@ -208,14 +217,20 @@ discard block |
||
208 | 217 | } |
209 | 218 | else |
210 | 219 | { |
211 | - if ((string)$t == '*') $t = '*/1'; |
|
220 | + if ((string)$t == '*') |
|
221 | + { |
|
222 | + $t = '*/1'; |
|
223 | + } |
|
212 | 224 | |
213 | 225 | list($one,$inc) = $arr = explode('/',$t); |
214 | 226 | |
215 | 227 | if (!(is_numeric($one) && count($arr) == 1 || |
216 | 228 | count($arr) == 2 && is_numeric($inc))) |
217 | 229 | { |
218 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
230 | + if ($debug) |
|
231 | + { |
|
232 | + echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
233 | + } |
|
219 | 234 | |
220 | 235 | return False; |
221 | 236 | } |
@@ -233,7 +248,10 @@ discard block |
||
233 | 248 | } |
234 | 249 | elseif (count($arr) != 2 || $min > $max) |
235 | 250 | { |
236 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
251 | + if ($debug) |
|
252 | + { |
|
253 | + echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
254 | + } |
|
237 | 255 | return False; |
238 | 256 | } |
239 | 257 | for ($i = $min; $i <= $max; $i += $inc) |
@@ -244,9 +262,13 @@ discard block |
||
244 | 262 | } |
245 | 263 | } |
246 | 264 | } |
247 | - elseif ($n < $last_set || $u == 'dow') // before last value set (or dow) => empty gets enumerated |
|
265 | + elseif ($n < $last_set || $u == 'dow') |
|
266 | + { |
|
267 | + // before last value set (or dow) => empty gets enumerated |
|
248 | 268 | { |
249 | - for ($i = $min_unit[$u]; $i <= $max_unit[$u]; ++$i) |
|
269 | + for ($i = $min_unit[$u]; |
|
270 | + } |
|
271 | + $i <= $max_unit[$u]; ++$i) |
|
250 | 272 | { |
251 | 273 | $times[$u][$i] = True; |
252 | 274 | } |
@@ -256,7 +278,9 @@ discard block |
||
256 | 278 | $times[$u][$min_unit[$u]] = True; |
257 | 279 | } |
258 | 280 | } |
259 | - if ($this->debug) { echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
281 | + if ($this->debug) |
|
282 | + { |
|
283 | +echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
260 | 284 | |
261 | 285 | // now we have the times enumerated, lets find the first not expired one |
262 | 286 | // |
@@ -274,7 +298,10 @@ discard block |
||
274 | 298 | if (isset($found[$u])) |
275 | 299 | { |
276 | 300 | $future = $future || $found[$u] > $unit_now; |
277 | - if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
301 | + if ($this->debug) |
|
302 | + { |
|
303 | + echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
304 | + } |
|
278 | 305 | continue; // already set |
279 | 306 | } |
280 | 307 | foreach(array_keys($times[$u]) as $unit_value) |
@@ -292,30 +319,44 @@ discard block |
||
292 | 319 | break; |
293 | 320 | |
294 | 321 | } |
295 | - if ($valid && ($u != $next || $unit_value > $over)) // valid and not over |
|
322 | + if ($valid && ($u != $next || $unit_value > $over)) |
|
323 | + { |
|
324 | + // valid and not over |
|
296 | 325 | { |
297 | 326 | $found[$u] = $unit_value; |
327 | + } |
|
298 | 328 | $future = $future || $unit_value > $unit_now; |
299 | 329 | break; |
300 | 330 | } |
301 | 331 | } |
302 | - if (!isset($found[$u])) // we have to try the next one, if it exists |
|
332 | + if (!isset($found[$u])) |
|
333 | + { |
|
334 | + // we have to try the next one, if it exists |
|
303 | 335 | { |
304 | 336 | $nexts = array_keys($units); |
337 | + } |
|
305 | 338 | if (!isset($nexts[count($found)-1])) |
306 | 339 | { |
307 | - if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n"; |
|
340 | + if ($this->debug) |
|
341 | + { |
|
342 | + echo "<p>Nothing found, exiting !!!</p>\n"; |
|
343 | + } |
|
308 | 344 | return False; |
309 | 345 | } |
310 | 346 | $next = $nexts[count($found)-1]; |
311 | 347 | $over = $found[$next]; |
312 | 348 | unset($found[$next]); |
313 | - if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
349 | + if ($this->debug) |
|
350 | + { |
|
351 | + echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
352 | + } |
|
314 | 353 | break; |
315 | 354 | } |
316 | 355 | } |
317 | 356 | } |
318 | - if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
357 | + if ($this->debug) |
|
358 | + { |
|
359 | +echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
319 | 360 | |
320 | 361 | return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
321 | 362 | } |
@@ -377,7 +418,10 @@ discard block |
||
377 | 418 | ); |
378 | 419 | // as the async_next column is used as a semaphore we only update it, |
379 | 420 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
380 | - if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
421 | + if ($exists) |
|
422 | + { |
|
423 | + $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
424 | + } |
|
381 | 425 | } |
382 | 426 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
383 | 427 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -388,7 +432,10 @@ discard block |
||
388 | 432 | */ |
389 | 433 | function check_run($run_by='') |
390 | 434 | { |
391 | - if ($run_by === 'fallback') flush(); |
|
435 | + if ($run_by === 'fallback') |
|
436 | + { |
|
437 | + flush(); |
|
438 | + } |
|
392 | 439 | |
393 | 440 | if (!$this->last_check_run(True,False,$run_by)) |
394 | 441 | { |
@@ -410,7 +457,10 @@ discard block |
||
410 | 457 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
411 | 458 | foreach($GLOBALS as $name => $value) |
412 | 459 | { |
413 | - if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
|
460 | + if ($name !== 'egw' && is_object($value)) |
|
461 | + { |
|
462 | + unset($GLOBALS[$name]); |
|
463 | + } |
|
414 | 464 | } |
415 | 465 | $domain = $GLOBALS['egw_info']['user']['domain']; |
416 | 466 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
@@ -480,7 +530,10 @@ discard block |
||
480 | 530 | */ |
481 | 531 | function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
482 | 532 | { |
483 | - if (!is_a($this->db, 'egw_db')) return false; |
|
533 | + if (!is_a($this->db, 'egw_db')) |
|
534 | + { |
|
535 | + return false; |
|
536 | + } |
|
484 | 537 | |
485 | 538 | if ($id === '%') |
486 | 539 | { |
@@ -533,9 +586,15 @@ discard block |
||
533 | 586 | */ |
534 | 587 | function write($job, $exists = False, $where=array()) |
535 | 588 | { |
536 | - if (!is_a($this->db, 'egw_db')) return 0; |
|
589 | + if (!is_a($this->db, 'egw_db')) |
|
590 | + { |
|
591 | + return 0; |
|
592 | + } |
|
537 | 593 | |
538 | - if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) $job['data']['next'] = $job['next']; |
|
594 | + if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) |
|
595 | + { |
|
596 | + $job['data']['next'] = $job['next']; |
|
597 | + } |
|
539 | 598 | $data = array( |
540 | 599 | 'async_next' => $job['next'], |
541 | 600 | 'async_times' => json_encode($job['times']), |
@@ -600,9 +659,12 @@ discard block |
||
600 | 659 | { |
601 | 660 | echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
602 | 661 | $perms = fileperms($this->$name); |
603 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
662 | + if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) |
|
663 | + { |
|
664 | + // only executable by group |
|
604 | 665 | { |
605 | 666 | $group = posix_getgrgid(filegroup($this->$name)); |
667 | + } |
|
606 | 668 | $webserver = posix_getpwuid(posix_getuid ()); |
607 | 669 | echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
608 | 670 | } |
@@ -622,10 +684,13 @@ discard block |
||
622 | 684 | } |
623 | 685 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
624 | 686 | } |
625 | - if ($this->php5{0} == '/') // we found a php5 binary |
|
687 | + if ($this->php5{0} == '/') |
|
688 | + { |
|
689 | + // we found a php5 binary |
|
626 | 690 | { |
627 | 691 | $this->php = $this->php5; |
628 | 692 | } |
693 | + } |
|
629 | 694 | } |
630 | 695 | } |
631 | 696 | |
@@ -637,7 +702,8 @@ discard block |
||
637 | 702 | */ |
638 | 703 | function installed() |
639 | 704 | { |
640 | - if ($this->only_fallback) { |
|
705 | + if ($this->only_fallback) |
|
706 | + { |
|
641 | 707 | return 0; |
642 | 708 | } |
643 | 709 | $this->find_binarys(); |
@@ -654,7 +720,10 @@ discard block |
||
654 | 720 | $n = 0; |
655 | 721 | while ($line = fgets($crontab,256)) |
656 | 722 | { |
657 | - if ($this->debug) echo 'line '.++$n.": $line<br>\n"; |
|
723 | + if ($this->debug) |
|
724 | + { |
|
725 | + echo 'line '.++$n.": $line<br>\n"; |
|
726 | + } |
|
658 | 727 | $parts = explode(' ',$line,6); |
659 | 728 | |
660 | 729 | if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
@@ -696,7 +765,8 @@ discard block |
||
696 | 765 | */ |
697 | 766 | function install($times) |
698 | 767 | { |
699 | - if ($this->only_fallback && $times !== False) { |
|
768 | + if ($this->only_fallback && $times !== False) |
|
769 | + { |
|
700 | 770 | return 0; |
701 | 771 | } |
702 | 772 | $this->installed(); // find other installed cronlines |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * check if users are supposed to change their password every x sdays, then check if password is of old age |
60 | 60 | * or the devil-admin reset the users password and forced the user to change his password on next login. |
61 | 61 | * |
62 | - * @param string& $message =null on return false: message why password needs to be changed |
|
63 | - * @return boolean true: all good, false: password change required, null: password expires in N days |
|
62 | + * @param string $message =null on return false: message why password needs to be changed |
|
63 | + * @return boolean|null true: all good, false: password change required, null: password expires in N days |
|
64 | 64 | */ |
65 | 65 | static function check_password_change(&$message=null) |
66 | 66 | { |
@@ -386,6 +386,7 @@ discard block |
||
386 | 386 | * @param string $form_val user input value for comparison |
387 | 387 | * @param string $db_val stored value / hash (from database) |
388 | 388 | * @param string &$type detected crypt type on return |
389 | + * @param string $type |
|
389 | 390 | * @return boolean True on successful comparison |
390 | 391 | */ |
391 | 392 | static function crypt_compare($form_val, $db_val, &$type) |
@@ -598,7 +599,7 @@ discard block |
||
598 | 599 | * @param string $forbid_name =null if "yes" username or full-name split by delimiters AND longer then 3 chars are |
599 | 600 | * forbidden to be included in password, default to whatever set in config for "passwd_forbid_name" |
600 | 601 | * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check |
601 | - * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
|
602 | + * @return string|false false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
|
602 | 603 | */ |
603 | 604 | static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
604 | 605 | { |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * @param string $db_val stored value / hash (from database) |
408 | 408 | * @param string &$type detected crypt type on return |
409 | 409 | * @return boolean True on successful comparison |
410 | - */ |
|
410 | + */ |
|
411 | 411 | static function crypt_compare($form_val, $db_val, &$type) |
412 | 412 | { |
413 | 413 | // detect type of hash by salt part of $db_val |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | * @param string $form_val user input value for comparison |
707 | 707 | * @param string $db_val stored value (from database) |
708 | 708 | * @return boolean True on successful comparison |
709 | - */ |
|
709 | + */ |
|
710 | 710 | static function smd5_compare($form_val,$db_val) |
711 | 711 | { |
712 | 712 | /* Start with the first char after {SMD5} */ |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | * @param string $form_val user input value for comparison |
729 | 729 | * @param string $db_val stored value (from database) |
730 | 730 | * @return boolean True on successful comparison |
731 | - */ |
|
731 | + */ |
|
732 | 732 | static function sha_compare($form_val,$db_val) |
733 | 733 | { |
734 | 734 | /* Start with the first char after {SHA} */ |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | * @param string $form_val user input value for comparison |
746 | 746 | * @param string $db_val stored value (from database) |
747 | 747 | * @return boolean True on successful comparison |
748 | - */ |
|
748 | + */ |
|
749 | 749 | static function ssha_compare($form_val,$db_val) |
750 | 750 | { |
751 | 751 | /* Start with the first char after {SSHA} */ |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | { |
19 | 19 | $GLOBALS['egw_info']['server']['auth_type'] = $GLOBALS['egw_info']['server']['auth_type_'.$GLOBALS['egw_info']['flags']['currentapp']]; |
20 | 20 | } |
21 | -if(empty($GLOBALS['egw_info']['server']['auth_type'])) |
|
21 | +if (empty($GLOBALS['egw_info']['server']['auth_type'])) |
|
22 | 22 | { |
23 | 23 | $GLOBALS['egw_info']['server']['auth_type'] = 'sql'; |
24 | 24 | } |
@@ -62,22 +62,22 @@ discard block |
||
62 | 62 | * @param string& $message =null on return false: message why password needs to be changed |
63 | 63 | * @return boolean true: all good, false: password change required, null: password expires in N days |
64 | 64 | */ |
65 | - static function check_password_change(&$message=null) |
|
65 | + static function check_password_change(&$message = null) |
|
66 | 66 | { |
67 | 67 | // dont check anything for anonymous sessions/ users that are flagged as anonymous |
68 | 68 | if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true; |
69 | 69 | |
70 | 70 | // some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request |
71 | 71 | // if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed |
72 | - static $UserKnowsAboutPwdChange=null; |
|
73 | - if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& egw_cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
72 | + static $UserKnowsAboutPwdChange = null; |
|
73 | + if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange = & egw_cache::getSession('phpgwapi', 'auth_UserKnowsAboutPwdChange'); |
|
74 | 74 | |
75 | 75 | // retrieve the timestamp regarding the last change of the password from auth system and store it with the session |
76 | - static $alpwchange_val=null; |
|
77 | - static $pwdTsChecked=null; |
|
76 | + static $alpwchange_val = null; |
|
77 | + static $pwdTsChecked = null; |
|
78 | 78 | if (is_null($pwdTsChecked) && is_null($alpwchange_val) || (string)$alpwchange_val === '0') |
79 | 79 | { |
80 | - $alpwchange_val =& egw_cache::getSession('phpgwapi','auth_alpwchange_val'); // set that one with the session stored value |
|
80 | + $alpwchange_val = & egw_cache::getSession('phpgwapi', 'auth_alpwchange_val'); // set that one with the session stored value |
|
81 | 81 | // initalize statics - better readability of conditions |
82 | 82 | if (is_null($alpwchange_val) || (string)$alpwchange_val === '0') |
83 | 83 | { |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $backend = new $backend_class; |
86 | 86 | // this may change behavior, as it should detect forced PasswordChanges from your Authentication System too. |
87 | 87 | // on the other side, if your auth system does not require an forcedPasswordChange, you will not be asked. |
88 | - if (method_exists($backend,'getLastPwdChange')) |
|
88 | + if (method_exists($backend, 'getLastPwdChange')) |
|
89 | 89 | { |
90 | 90 | $alpwchange_val = $backend->getLastPwdChange($GLOBALS['egw']->session->account_lid); |
91 | 91 | $pwdTsChecked = true; |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | //error_log(__METHOD__.__LINE__.'#'.$alpwchange_val.'# is null:'.is_null($alpwchange_val).'# is empty:'.empty($alpwchange_val).'# is set:'.isset($alpwchange_val)); |
100 | 100 | } |
101 | 101 | } |
102 | - static $passwordAgeBorder=null; |
|
103 | - static $daysLeftUntilChangeReq=null; |
|
102 | + static $passwordAgeBorder = null; |
|
103 | + static $daysLeftUntilChangeReq = null; |
|
104 | 104 | |
105 | 105 | // if neither timestamp isset return true, nothing to do (exept this means the password is too old) |
106 | 106 | if (is_null($alpwchange_val) && |
@@ -110,15 +110,15 @@ discard block |
||
110 | 110 | } |
111 | 111 | if (is_null($passwordAgeBorder) && $GLOBALS['egw_info']['server']['change_pwd_every_x_days']) |
112 | 112 | { |
113 | - $passwordAgeBorder = (egw_time::to('now','ts')-($GLOBALS['egw_info']['server']['change_pwd_every_x_days']*86400)); |
|
113 | + $passwordAgeBorder = (egw_time::to('now', 'ts') - ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] * 86400)); |
|
114 | 114 | } |
115 | 115 | if (is_null($daysLeftUntilChangeReq) && $GLOBALS['egw_info']['server']['warn_about_upcoming_pwd_change']) |
116 | 116 | { |
117 | 117 | // maxage - passwordage = days left until change is required |
118 | - $daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((egw_time::to('now','ts')-($alpwchange_val?$alpwchange_val:0))/86400)); |
|
118 | + $daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((egw_time::to('now', 'ts') - ($alpwchange_val ? $alpwchange_val : 0)) / 86400)); |
|
119 | 119 | } |
120 | - if ($alpwchange_val == 0 || // admin requested password change |
|
121 | - $passwordAgeBorder > $alpwchange_val || // change password every N days policy requests change |
|
120 | + if ($alpwchange_val == 0 || // admin requested password change |
|
121 | + $passwordAgeBorder > $alpwchange_val || // change password every N days policy requests change |
|
122 | 122 | // user should be warned N days in advance about change and is not yet |
123 | 123 | $GLOBALS['egw_info']['server']['change_pwd_every_x_days'] && |
124 | 124 | $GLOBALS['egw_info']['user']['apps']['preferences'] && |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | error_log(__METHOD__.' Password of '.$GLOBALS['egw_info']['user']['account_lid'].' ('.$GLOBALS['egw_info']['user']['account_fullname'].') is of old age.'.array2string(array( |
136 | 136 | 'ts'=> $alpwchange_val, |
137 | 137 | 'date'=>egw_time::to($alpwchange_val)))); |
138 | - $message = lang('It has been more then %1 days since you changed your password',$GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
138 | + $message = lang('It has been more then %1 days since you changed your password', $GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
139 | 139 | } |
140 | 140 | else |
141 | 141 | { |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | { |
147 | 147 | $UserKnowsAboutPwdChange = true; |
148 | 148 | } |
149 | - $message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq)); |
|
149 | + $message = lang('Your password is about to expire in %1 days, you may change your password now', round($daysLeftUntilChangeReq)); |
|
150 | 150 | // user has no rights to change password --> do NOT warn, as only forced check ignores rights |
151 | 151 | if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true; |
152 | 152 | return null; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | static function check_password_age() |
165 | 165 | { |
166 | - return true; // no change |
|
166 | + return true; // no change |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | function getLastPwdChange($username) |
176 | 176 | { |
177 | - if (method_exists($this->backend,'getLastPwdChange')) return $this->backend->getLastPwdChange($username); |
|
177 | + if (method_exists($this->backend, 'getLastPwdChange')) return $this->backend->getLastPwdChange($username); |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | * @param int $lastpwdchange must be a unixtimestamp |
187 | 187 | * @return boolean true if account_lastpwd_change successful changed, false otherwise |
188 | 188 | */ |
189 | - function setLastPwdChange($account_id=0, $passwd=NULL, $lastpwdchange=NULL) |
|
189 | + function setLastPwdChange($account_id = 0, $passwd = NULL, $lastpwdchange = NULL) |
|
190 | 190 | { |
191 | - if (method_exists($this->backend,'setLastPwdChange')) return $this->backend->setLastPwdChange($account_id, $passwd, $lastpwdchange); |
|
191 | + if (method_exists($this->backend, 'setLastPwdChange')) return $this->backend->setLastPwdChange($account_id, $passwd, $lastpwdchange); |
|
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @param string $passwd_type ='text' 'text' for cleartext passwords (default) |
201 | 201 | * @return boolean true if successful authenticated, false otherwise |
202 | 202 | */ |
203 | - function authenticate($username, $passwd, $passwd_type='text') |
|
203 | + function authenticate($username, $passwd, $passwd_type = 'text') |
|
204 | 204 | { |
205 | 205 | return $this->backend->authenticate($username, $passwd, $passwd_type); |
206 | 206 | } |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | * @throws Exception from backends having extra requirements |
216 | 216 | * @return boolean true if password successful changed, false otherwise |
217 | 217 | */ |
218 | - function change_password($old_passwd, $new_passwd, $account_id=0) |
|
218 | + function change_password($old_passwd, $new_passwd, $account_id = 0) |
|
219 | 219 | { |
220 | - if (($err = self::crackcheck($new_passwd,null,null,null,$account_id))) |
|
220 | + if (($err = self::crackcheck($new_passwd, null, null, null, $account_id))) |
|
221 | 221 | { |
222 | 222 | throw new egw_exception_wrong_userinput($err); |
223 | 223 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | // need to change current users password in session |
229 | 229 | egw_cache::setSession('phpgwapi', 'password', base64_encode($new_passwd)); |
230 | 230 | $GLOBALS['egw_info']['user']['passwd'] = $new_passwd; |
231 | - $GLOBALS['egw_info']['user']['account_lastpwd_change'] = egw_time::to('now','ts'); |
|
231 | + $GLOBALS['egw_info']['user']['account_lastpwd_change'] = egw_time::to('now', 'ts'); |
|
232 | 232 | // invalidate EGroupware session, as password is stored in egw_info in session |
233 | 233 | egw::invalidate_session_cache(); |
234 | 234 | } |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | 'old_passwd' => $old_passwd, |
241 | 241 | 'new_passwd' => $new_passwd, |
242 | 242 | ); |
243 | - $GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array( |
|
243 | + $GLOBALS['egw']->hooks->process($GLOBALS['hook_values'] + array( |
|
244 | 244 | 'location' => 'changepassword' |
245 | - ),False,True); // called for every app now, not only enabled ones) |
|
245 | + ), False, True); // called for every app now, not only enabled ones) |
|
246 | 246 | } |
247 | 247 | return $ret; |
248 | 248 | } |
@@ -255,16 +255,16 @@ discard block |
||
255 | 255 | static function randomstring($size) |
256 | 256 | { |
257 | 257 | static $random_char = array( |
258 | - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', |
|
259 | - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', |
|
260 | - 'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L', |
|
261 | - 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' |
|
258 | + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', |
|
259 | + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', |
|
260 | + 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', |
|
261 | + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' |
|
262 | 262 | ); |
263 | 263 | |
264 | 264 | $s = ''; |
265 | - for ($i=0; $i<$size; $i++) |
|
265 | + for ($i = 0; $i < $size; $i++) |
|
266 | 266 | { |
267 | - $s .= $random_char[mt_rand(1,61)]; |
|
267 | + $s .= $random_char[mt_rand(1, 61)]; |
|
268 | 268 | } |
269 | 269 | return $s; |
270 | 270 | } |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @param $password password to encrypt |
278 | 278 | */ |
279 | - static function encrypt_password($password,$sql=False) |
|
279 | + static function encrypt_password($password, $sql = False) |
|
280 | 280 | { |
281 | - if($sql) |
|
281 | + if ($sql) |
|
282 | 282 | { |
283 | 283 | return self::encrypt_sql($password); |
284 | 284 | } |
@@ -297,21 +297,21 @@ discard block |
||
297 | 297 | * @param string &$type =null on return detected type of hash |
298 | 298 | * @return boolean |
299 | 299 | */ |
300 | - static function compare_password($cleartext, $encrypted, $type_in, $username='', &$type=null) |
|
300 | + static function compare_password($cleartext, $encrypted, $type_in, $username = '', &$type = null) |
|
301 | 301 | { |
302 | 302 | // allow to specify the hash type to prefix the hash, to easy migrate passwords from ldap |
303 | 303 | $type = $type_in; |
304 | 304 | $saved_enc = $encrypted; |
305 | 305 | $matches = null; |
306 | - if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i',$encrypted,$matches)) |
|
306 | + if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i', $encrypted, $matches)) |
|
307 | 307 | { |
308 | 308 | $type = strtolower($matches[1]); |
309 | 309 | $encrypted = $matches[2]; |
310 | 310 | |
311 | - switch($type) // some hashs are specially "packed" in ldap |
|
311 | + switch ($type) // some hashs are specially "packed" in ldap |
|
312 | 312 | { |
313 | 313 | case 'md5': |
314 | - $encrypted = implode('',unpack('H*',base64_decode($encrypted))); |
|
314 | + $encrypted = implode('', unpack('H*', base64_decode($encrypted))); |
|
315 | 315 | break; |
316 | 316 | case 'plain': |
317 | 317 | case 'crypt': |
@@ -322,24 +322,24 @@ discard block |
||
322 | 322 | break; |
323 | 323 | } |
324 | 324 | } |
325 | - elseif($encrypted[0] == '$') |
|
325 | + elseif ($encrypted[0] == '$') |
|
326 | 326 | { |
327 | 327 | $type = 'crypt'; |
328 | 328 | } |
329 | 329 | |
330 | - switch($type) |
|
330 | + switch ($type) |
|
331 | 331 | { |
332 | 332 | case 'plain': |
333 | 333 | $ret = $cleartext === $encrypted; |
334 | 334 | break; |
335 | 335 | case 'smd5': |
336 | - $ret = self::smd5_compare($cleartext,$encrypted); |
|
336 | + $ret = self::smd5_compare($cleartext, $encrypted); |
|
337 | 337 | break; |
338 | 338 | case 'sha': |
339 | - $ret = self::sha_compare($cleartext,$encrypted); |
|
339 | + $ret = self::sha_compare($cleartext, $encrypted); |
|
340 | 340 | break; |
341 | 341 | case 'ssha': |
342 | - $ret = self::ssha_compare($cleartext,$encrypted); |
|
342 | + $ret = self::ssha_compare($cleartext, $encrypted); |
|
343 | 343 | break; |
344 | 344 | case 'crypt': |
345 | 345 | case 'des': |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $ret = self::crypt_compare($cleartext, $encrypted, $type); |
353 | 353 | break; |
354 | 354 | case 'md5_hmac': |
355 | - $ret = self::md5_hmac_compare($cleartext,$encrypted,$username); |
|
355 | + $ret = self::md5_hmac_compare($cleartext, $encrypted, $username); |
|
356 | 356 | break; |
357 | 357 | default: |
358 | 358 | $type = 'md5'; |
@@ -375,9 +375,9 @@ discard block |
||
375 | 375 | 'ext_crypt' => array('CRYPT_EXT_DES', '_J9..', 4, ''), |
376 | 376 | 'md5_crypt' => array('CRYPT_MD5', '$1$', 8, '$'), |
377 | 377 | //'old_blowfish_crypt' => array('CRYPT_BLOWFISH', '$2$', 13, ''), // old blowfish hash not in line with php.net docu, but could be in use |
378 | - 'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''), // $2a$12$ = 2^12 = 4096 rounds |
|
379 | - 'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
380 | - 'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
378 | + 'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''), // $2a$12$ = 2^12 = 4096 rounds |
|
379 | + 'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
380 | + 'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
381 | 381 | ); |
382 | 382 | |
383 | 383 | /** |
@@ -392,17 +392,17 @@ discard block |
||
392 | 392 | { |
393 | 393 | // detect type of hash by salt part of $db_val |
394 | 394 | list($first, $dollar, $salt, $salt2) = explode('$', $db_val); |
395 | - foreach(self::$crypt_params as $type => $params) |
|
395 | + foreach (self::$crypt_params as $type => $params) |
|
396 | 396 | { |
397 | 397 | list(,$prefix, $random, $postfix) = $params; |
398 | 398 | list(,$d) = explode('$', $prefix); |
399 | 399 | if ($dollar === $d || !$dollar && ($first[0] === $prefix[0] || $first[0] !== '_' && !$prefix)) |
400 | 400 | { |
401 | - $len = !$postfix ? strlen($prefix)+$random : strlen($prefix.$salt.$postfix); |
|
401 | + $len = !$postfix ? strlen($prefix) + $random : strlen($prefix.$salt.$postfix); |
|
402 | 402 | // sha(256|512) might contain options, explicit $rounds=N$ prefix in salt |
403 | 403 | if (($type == 'sha256_crypt' || $type == 'sha512_crypt') && substr($salt, 0, 7) === 'rounds=') |
404 | 404 | { |
405 | - $len += strlen($salt2)+1; |
|
405 | + $len += strlen($salt2) + 1; |
|
406 | 406 | } |
407 | 407 | break; |
408 | 408 | } |
@@ -424,12 +424,12 @@ discard block |
||
424 | 424 | * @param string $type =null default to $GLOBALS['egw_info']['server']['ldap_encryption_type'] |
425 | 425 | * @return string |
426 | 426 | */ |
427 | - static function encrypt_ldap($password, $type=null) |
|
427 | + static function encrypt_ldap($password, $type = null) |
|
428 | 428 | { |
429 | 429 | if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
430 | 430 | |
431 | 431 | $salt = ''; |
432 | - switch(strtolower($type)) |
|
432 | + switch (strtolower($type)) |
|
433 | 433 | { |
434 | 434 | default: // eg. setup >> config never saved |
435 | 435 | case 'des': |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | case 'md5_crypt': |
444 | 444 | case 'ext_crypt': |
445 | 445 | list($const, $prefix, $len, $postfix) = self::$crypt_params[$type]; |
446 | - if(defined($const) && constant($const) == 1) |
|
446 | + if (defined($const) && constant($const) == 1) |
|
447 | 447 | { |
448 | 448 | $salt = $prefix.self::randomstring($len).$postfix; |
449 | 449 | $e_password = '{crypt}'.crypt($password, $salt); |
@@ -456,20 +456,20 @@ discard block |
||
456 | 456 | /* New method taken from the openldap-software list as recommended by |
457 | 457 | * Kervin L. Pierre" <[email protected]> |
458 | 458 | */ |
459 | - $e_password = '{md5}' . base64_encode(pack("H*",md5($password))); |
|
459 | + $e_password = '{md5}'.base64_encode(pack("H*", md5($password))); |
|
460 | 460 | break; |
461 | 461 | case 'smd5': |
462 | 462 | $salt = self::randomstring(16); |
463 | - $hash = md5($password . $salt, true); |
|
464 | - $e_password = '{SMD5}' . base64_encode($hash . $salt); |
|
463 | + $hash = md5($password.$salt, true); |
|
464 | + $e_password = '{SMD5}'.base64_encode($hash.$salt); |
|
465 | 465 | break; |
466 | 466 | case 'sha': |
467 | - $e_password = '{SHA}' . base64_encode(sha1($password,true)); |
|
467 | + $e_password = '{SHA}'.base64_encode(sha1($password, true)); |
|
468 | 468 | break; |
469 | 469 | case 'ssha': |
470 | 470 | $salt = self::randomstring(16); |
471 | - $hash = sha1($password . $salt, true); |
|
472 | - $e_password = '{SSHA}' . base64_encode($hash . $salt); |
|
471 | + $hash = sha1($password.$salt, true); |
|
472 | + $e_password = '{SSHA}'.base64_encode($hash.$salt); |
|
473 | 473 | break; |
474 | 474 | case 'plain': |
475 | 475 | // if plain no type is prepended |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @param string $type =null default $GLOBALS['egw_info']['server']['sql_encryption_type'] |
488 | 488 | * @return string hash |
489 | 489 | */ |
490 | - static function encrypt_sql($password, $type=null) |
|
490 | + static function encrypt_sql($password, $type = null) |
|
491 | 491 | { |
492 | 492 | /* Grab configured type, or default to md5() (old method) */ |
493 | 493 | if (is_null($type)) |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | $type = @$GLOBALS['egw_info']['server']['sql_encryption_type'] ? |
496 | 496 | strtolower($GLOBALS['egw_info']['server']['sql_encryption_type']) : 'md5'; |
497 | 497 | } |
498 | - switch($type) |
|
498 | + switch ($type) |
|
499 | 499 | { |
500 | 500 | case 'plain': |
501 | 501 | // since md5 is the default, type plain must be prepended, for eGroupware to understand |
@@ -537,28 +537,28 @@ discard block |
||
537 | 537 | * @param string &$securest =null on return securest available hash |
538 | 538 | * @return array hash => label |
539 | 539 | */ |
540 | - public static function passwdhashes(&$securest=null) |
|
540 | + public static function passwdhashes(&$securest = null) |
|
541 | 541 | { |
542 | 542 | $hashes = array(); |
543 | 543 | |
544 | 544 | /* Check for available crypt methods based on what is defined by php */ |
545 | - if(defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) |
|
545 | + if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) |
|
546 | 546 | { |
547 | 547 | $hashes['blowfish_crypt'] = 'blowfish_crypt'; |
548 | 548 | } |
549 | - if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) |
|
549 | + if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) |
|
550 | 550 | { |
551 | 551 | $hashes['sha512_crypt'] = 'sha512_crypt'; |
552 | 552 | } |
553 | - if(defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) |
|
553 | + if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) |
|
554 | 554 | { |
555 | 555 | $hashes['sha256_crypt'] = 'sha256_crypt'; |
556 | 556 | } |
557 | - if(defined('CRYPT_MD5') && CRYPT_MD5 == 1) |
|
557 | + if (defined('CRYPT_MD5') && CRYPT_MD5 == 1) |
|
558 | 558 | { |
559 | 559 | $hashes['md5_crypt'] = 'md5_crypt'; |
560 | 560 | } |
561 | - if(defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1) |
|
561 | + if (defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1) |
|
562 | 562 | { |
563 | 563 | $hashes['ext_crypt'] = 'ext_crypt'; |
564 | 564 | } |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | 'smd5' => 'smd5', |
568 | 568 | 'sha' => 'sha', |
569 | 569 | ); |
570 | - if(@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1) |
|
570 | + if (@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1) |
|
571 | 571 | { |
572 | 572 | $hashes['crypt'] = 'crypt'; |
573 | 573 | } |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check |
601 | 601 | * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
602 | 602 | */ |
603 | - static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
|
603 | + static function crackcheck($passwd, $reqstrength = null, $minlength = null, $forbid_name = null, $account = null) |
|
604 | 604 | { |
605 | 605 | if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
606 | 606 | if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
@@ -614,11 +614,11 @@ discard block |
||
614 | 614 | { |
615 | 615 | if (!isset($reqstrength) || $reqstrength == 5) |
616 | 616 | { |
617 | - config::save_value('force_pwd_strength', $reqstrength=4, 'phpgwapi'); |
|
617 | + config::save_value('force_pwd_strength', $reqstrength = 4, 'phpgwapi'); |
|
618 | 618 | } |
619 | 619 | if (!isset($minlength)) |
620 | 620 | { |
621 | - config::save_value('force_pwd_length', $minlength=7, 'phpgwapi'); |
|
621 | + config::save_value('force_pwd_length', $minlength = 7, 'phpgwapi'); |
|
622 | 622 | } |
623 | 623 | config::save_value('check_save_passwd', null, 'phpgwapi'); |
624 | 624 | } |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | throw new egw_exception_wrong_parameter('crackcheck(..., forbid_name=true, account) requires account-data!'); |
638 | 638 | } |
639 | 639 | $parts = preg_split("/[,._ \t0-9-]+/", $account['account_fullname'].','.$account['account_lid']); |
640 | - foreach($parts as $part) |
|
640 | + foreach ($parts as $part) |
|
641 | 641 | { |
642 | 642 | if (strlen($part) > 2 && stripos($passwd, $part) !== false) |
643 | 643 | { |
@@ -650,15 +650,15 @@ discard block |
||
650 | 650 | if ($reqstrength) |
651 | 651 | { |
652 | 652 | $missing = array(); |
653 | - if (!preg_match('/(.*\d.*){'. ($non=1). ',}/',$passwd)) |
|
653 | + if (!preg_match('/(.*\d.*){'.($non = 1).',}/', $passwd)) |
|
654 | 654 | { |
655 | 655 | $missing[] = lang('numbers'); |
656 | 656 | } |
657 | - if (!preg_match('/(.*[[:upper:]].*){'. ($nou=1). ',}/',$passwd)) |
|
657 | + if (!preg_match('/(.*[[:upper:]].*){'.($nou = 1).',}/', $passwd)) |
|
658 | 658 | { |
659 | 659 | $missing[] = lang('uppercase letters'); |
660 | 660 | } |
661 | - if (!preg_match('/(.*[[:lower:]].*){'. ($nol=1). ',}/',$passwd)) |
|
661 | + if (!preg_match('/(.*[[:lower:]].*){'.($nol = 1).',}/', $passwd)) |
|
662 | 662 | { |
663 | 663 | $missing[] = lang('lowercase letters'); |
664 | 664 | } |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | if (4 - count($missing) < $reqstrength) |
670 | 670 | { |
671 | 671 | $errors[] = lang('password contains only %1 of required %2 character classes: no %3', |
672 | - 4-count($missing), $reqstrength, implode(', ', $missing)); |
|
672 | + 4 - count($missing), $reqstrength, implode(', ', $missing)); |
|
673 | 673 | } |
674 | 674 | } |
675 | 675 | if ($errors) |
@@ -687,19 +687,19 @@ discard block |
||
687 | 687 | * @param string $db_val stored value (from database) |
688 | 688 | * @return boolean True on successful comparison |
689 | 689 | */ |
690 | - static function smd5_compare($form_val,$db_val) |
|
690 | + static function smd5_compare($form_val, $db_val) |
|
691 | 691 | { |
692 | 692 | /* Start with the first char after {SMD5} */ |
693 | - $hash = base64_decode(substr($db_val,6)); |
|
693 | + $hash = base64_decode(substr($db_val, 6)); |
|
694 | 694 | |
695 | 695 | /* SMD5 hashes are 16 bytes long */ |
696 | - $orig_hash = cut_bytes($hash, 0, 16); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
696 | + $orig_hash = cut_bytes($hash, 0, 16); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
697 | 697 | $salt = cut_bytes($hash, 16); |
698 | 698 | |
699 | - $new_hash = md5($form_val . $salt,true); |
|
699 | + $new_hash = md5($form_val.$salt, true); |
|
700 | 700 | //echo '<br> DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash); |
701 | 701 | |
702 | - return strcmp($orig_hash,$new_hash) == 0; |
|
702 | + return strcmp($orig_hash, $new_hash) == 0; |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | /** |
@@ -709,14 +709,14 @@ discard block |
||
709 | 709 | * @param string $db_val stored value (from database) |
710 | 710 | * @return boolean True on successful comparison |
711 | 711 | */ |
712 | - static function sha_compare($form_val,$db_val) |
|
712 | + static function sha_compare($form_val, $db_val) |
|
713 | 713 | { |
714 | 714 | /* Start with the first char after {SHA} */ |
715 | - $hash = base64_decode(substr($db_val,5)); |
|
716 | - $new_hash = sha1($form_val,true); |
|
715 | + $hash = base64_decode(substr($db_val, 5)); |
|
716 | + $new_hash = sha1($form_val, true); |
|
717 | 717 | //echo '<br> DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash); |
718 | 718 | |
719 | - return strcmp($hash,$new_hash) == 0; |
|
719 | + return strcmp($hash, $new_hash) == 0; |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -726,18 +726,18 @@ discard block |
||
726 | 726 | * @param string $db_val stored value (from database) |
727 | 727 | * @return boolean True on successful comparison |
728 | 728 | */ |
729 | - static function ssha_compare($form_val,$db_val) |
|
729 | + static function ssha_compare($form_val, $db_val) |
|
730 | 730 | { |
731 | 731 | /* Start with the first char after {SSHA} */ |
732 | 732 | $hash = base64_decode(substr($db_val, 6)); |
733 | 733 | |
734 | 734 | // SHA-1 hashes are 160 bits long |
735 | - $orig_hash = cut_bytes($hash, 0, 20); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
735 | + $orig_hash = cut_bytes($hash, 0, 20); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
736 | 736 | $salt = cut_bytes($hash, 20); |
737 | - $new_hash = sha1($form_val . $salt,true); |
|
737 | + $new_hash = sha1($form_val.$salt, true); |
|
738 | 738 | |
739 | 739 | //error_log(__METHOD__."('$form_val', '$db_val') hash='$hash', orig_hash='$orig_hash', salt='$salt', new_hash='$new_hash' returning ".array2string(strcmp($orig_hash,$new_hash) == 0)); |
740 | - return strcmp($orig_hash,$new_hash) == 0; |
|
740 | + return strcmp($orig_hash, $new_hash) == 0; |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -748,12 +748,12 @@ discard block |
||
748 | 748 | * @param string $_key key for md5_hmac-encryption (username for imported smf users) |
749 | 749 | * @return boolean True on successful comparison |
750 | 750 | */ |
751 | - static function md5_hmac_compare($form_val,$db_val,$_key) |
|
751 | + static function md5_hmac_compare($form_val, $db_val, $_key) |
|
752 | 752 | { |
753 | 753 | $key = str_pad(strlen($_key) <= 64 ? $_key : pack('H*', md5($_key)), 64, chr(0x00)); |
754 | - $md5_hmac = md5(($key ^ str_repeat(chr(0x5c), 64)) . pack('H*', md5(($key ^ str_repeat(chr(0x36), 64)). $form_val))); |
|
754 | + $md5_hmac = md5(($key^str_repeat(chr(0x5c), 64)).pack('H*', md5(($key^str_repeat(chr(0x36), 64)).$form_val))); |
|
755 | 755 | |
756 | - return strcmp($md5_hmac,$db_val) == 0; |
|
756 | + return strcmp($md5_hmac, $db_val) == 0; |
|
757 | 757 | } |
758 | 758 | } |
759 | 759 | |
@@ -770,7 +770,7 @@ discard block |
||
770 | 770 | * @param string $passwd_type ='text' 'text' for cleartext passwords (default) |
771 | 771 | * @return boolean true if successful authenticated, false otherwise |
772 | 772 | */ |
773 | - function authenticate($username, $passwd, $passwd_type='text'); |
|
773 | + function authenticate($username, $passwd, $passwd_type = 'text'); |
|
774 | 774 | |
775 | 775 | /** |
776 | 776 | * changes password in sql datababse |
@@ -781,5 +781,5 @@ discard block |
||
781 | 781 | * @throws Exception to give a verbose error, why changing password failed |
782 | 782 | * @return boolean true if password successful changed, false otherwise |
783 | 783 | */ |
784 | - function change_password($old_passwd, $new_passwd, $account_id=0); |
|
784 | + function change_password($old_passwd, $new_passwd, $account_id = 0); |
|
785 | 785 | } |
@@ -65,12 +65,18 @@ discard block |
||
65 | 65 | static function check_password_change(&$message=null) |
66 | 66 | { |
67 | 67 | // dont check anything for anonymous sessions/ users that are flagged as anonymous |
68 | - if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true; |
|
68 | + if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') |
|
69 | + { |
|
70 | + return true; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | // some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request |
71 | 74 | // if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed |
72 | 75 | static $UserKnowsAboutPwdChange=null; |
73 | - if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& egw_cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
76 | + if (is_null($UserKnowsAboutPwdChange)) |
|
77 | + { |
|
78 | + $UserKnowsAboutPwdChange =& egw_cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
79 | + } |
|
74 | 80 | |
75 | 81 | // retrieve the timestamp regarding the last change of the password from auth system and store it with the session |
76 | 82 | static $alpwchange_val=null; |
@@ -148,7 +154,10 @@ discard block |
||
148 | 154 | } |
149 | 155 | $message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq)); |
150 | 156 | // user has no rights to change password --> do NOT warn, as only forced check ignores rights |
151 | - if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true; |
|
157 | + if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) |
|
158 | + { |
|
159 | + return true; |
|
160 | + } |
|
152 | 161 | return null; |
153 | 162 | } |
154 | 163 | return false; |
@@ -174,7 +183,10 @@ discard block |
||
174 | 183 | */ |
175 | 184 | function getLastPwdChange($username) |
176 | 185 | { |
177 | - if (method_exists($this->backend,'getLastPwdChange')) return $this->backend->getLastPwdChange($username); |
|
186 | + if (method_exists($this->backend,'getLastPwdChange')) |
|
187 | + { |
|
188 | + return $this->backend->getLastPwdChange($username); |
|
189 | + } |
|
178 | 190 | return false; |
179 | 191 | } |
180 | 192 | |
@@ -188,7 +200,10 @@ discard block |
||
188 | 200 | */ |
189 | 201 | function setLastPwdChange($account_id=0, $passwd=NULL, $lastpwdchange=NULL) |
190 | 202 | { |
191 | - if (method_exists($this->backend,'setLastPwdChange')) return $this->backend->setLastPwdChange($account_id, $passwd, $lastpwdchange); |
|
203 | + if (method_exists($this->backend,'setLastPwdChange')) |
|
204 | + { |
|
205 | + return $this->backend->setLastPwdChange($account_id, $passwd, $lastpwdchange); |
|
206 | + } |
|
192 | 207 | return false; |
193 | 208 | } |
194 | 209 | |
@@ -426,7 +441,10 @@ discard block |
||
426 | 441 | */ |
427 | 442 | static function encrypt_ldap($password, $type=null) |
428 | 443 | { |
429 | - if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
|
444 | + if (is_null($type)) |
|
445 | + { |
|
446 | + $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
|
447 | + } |
|
430 | 448 | |
431 | 449 | $salt = ''; |
432 | 450 | switch(strtolower($type)) |
@@ -602,9 +620,18 @@ discard block |
||
602 | 620 | */ |
603 | 621 | static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
604 | 622 | { |
605 | - if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
|
606 | - if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
|
607 | - if (!isset($forbid_name)) $forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name']; |
|
623 | + if (!isset($reqstrength)) |
|
624 | + { |
|
625 | + $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
|
626 | + } |
|
627 | + if (!isset($minlength)) |
|
628 | + { |
|
629 | + $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
|
630 | + } |
|
631 | + if (!isset($forbid_name)) |
|
632 | + { |
|
633 | + $forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name']; |
|
634 | + } |
|
608 | 635 | |
609 | 636 | // load preferences translations, as changepassword get's called from admin too |
610 | 637 | translation::add_app('preferences'); |
@@ -60,7 +60,7 @@ |
||
60 | 60 | * |
61 | 61 | * @param string $old_passwd must be cleartext or empty to not to be checked |
62 | 62 | * @param string $new_passwd must be cleartext |
63 | - * @param int $account_id=0 account id of user whose passwd should be changed |
|
63 | + * @param int $account_id account id of user whose passwd should be changed |
|
64 | 64 | * @return boolean true if password successful changed, false otherwise |
65 | 65 | */ |
66 | 66 | function change_password($old_passwd, $new_passwd, $account_id=0) |
@@ -26,7 +26,7 @@ discard block |
||
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 | 31 | if (pam_auth($username, get_magic_quotes_gpc() ? stripslashes($passwd) : $passwd)) |
32 | 32 | { |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | if (!$GLOBALS['egw']->accounts->name2id($username) && |
35 | 35 | function_exists('posix_getpwnam') && ($data = posix_getpwnam($username))) |
36 | 36 | { |
37 | - list($fullname) = explode(',',$data['gecos']); |
|
38 | - $parts = explode(' ',$fullname); |
|
37 | + list($fullname) = explode(',', $data['gecos']); |
|
38 | + $parts = explode(' ', $fullname); |
|
39 | 39 | if (count($parts) > 1) |
40 | 40 | { |
41 | 41 | $lastname = array_pop($parts); |
42 | - $firstname = implode(' ',$parts); |
|
42 | + $firstname = implode(' ', $parts); |
|
43 | 43 | $email = common::email_address($firstname, $lastname, $username); |
44 | 44 | |
45 | 45 | $GLOBALS['auto_create_acct'] = array( |
@@ -63,7 +63,7 @@ discard block |
||
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 | 68 | // deny password changes. |
69 | 69 | return False; |
@@ -234,8 +234,7 @@ |
||
234 | 234 | * @param string $encrypted_passwd |
235 | 235 | * @param string $new_passwd cleartext |
236 | 236 | * @param int $account_id account id of user whose passwd should be changed |
237 | - * @param boolean $admin=false called by admin, if not update password in the session |
|
238 | - * @param boolean $update_lastpw_change=true |
|
237 | + * @param boolean $update_lastpw_change |
|
239 | 238 | * @return boolean true if password successful changed, false otherwise |
240 | 239 | */ |
241 | 240 | private function _update_passwd($encrypted_passwd,$new_passwd,$account_id,$admin=false,$update_lastpw_change=true) |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param string $passwd_type='text' 'text' for cleartext passwords (default) |
49 | 49 | * @return boolean true if successful authenticated, false otherwise |
50 | 50 | */ |
51 | - function authenticate($username, $passwd, $passwd_type='text') |
|
51 | + function authenticate($username, $passwd, $passwd_type = 'text') |
|
52 | 52 | { |
53 | 53 | /* normal web form login */ |
54 | 54 | $where = array( |
@@ -61,25 +61,25 @@ discard block |
||
61 | 61 | $where[] = 'account_lid '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username); |
62 | 62 | unset($where['account_lid']); |
63 | 63 | } |
64 | - if($passwd_type == 'text') |
|
64 | + if ($passwd_type == 'text') |
|
65 | 65 | { |
66 | - if (!($row = $this->db->select($this->table,'account_lid,account_pwd,account_lastlogin,account_id',$where,__LINE__,__FILE__)->fetch()) || |
|
66 | + if (!($row = $this->db->select($this->table, 'account_lid,account_pwd,account_lastlogin,account_id', $where, __LINE__, __FILE__)->fetch()) || |
|
67 | 67 | empty($row['account_pwd']) || |
68 | 68 | $GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username) |
69 | 69 | { |
70 | 70 | return false; |
71 | 71 | } |
72 | - if(!($match = auth::compare_password($passwd, $row['account_pwd'], $this->type, strtolower($username), $type)) || |
|
73 | - $type != $this->type && in_array($type, explode(',',strtolower($GLOBALS['egw_info']['server']['pwd_migration_types'])))) |
|
72 | + if (!($match = auth::compare_password($passwd, $row['account_pwd'], $this->type, strtolower($username), $type)) || |
|
73 | + $type != $this->type && in_array($type, explode(',', strtolower($GLOBALS['egw_info']['server']['pwd_migration_types'])))) |
|
74 | 74 | { |
75 | 75 | // do we have to migrate an old password ? |
76 | - if($GLOBALS['egw_info']['server']['pwd_migration_allowed'] && !empty($GLOBALS['egw_info']['server']['pwd_migration_types'])) |
|
76 | + if ($GLOBALS['egw_info']['server']['pwd_migration_allowed'] && !empty($GLOBALS['egw_info']['server']['pwd_migration_types'])) |
|
77 | 77 | { |
78 | 78 | if (!$match) |
79 | 79 | { |
80 | - foreach(explode(',', $GLOBALS['egw_info']['server']['pwd_migration_types']) as $type) |
|
80 | + foreach (explode(',', $GLOBALS['egw_info']['server']['pwd_migration_types']) as $type) |
|
81 | 81 | { |
82 | - if(($match = auth::compare_password($passwd,$row['account_pwd'],$type,strtolower($username)))) |
|
82 | + if (($match = auth::compare_password($passwd, $row['account_pwd'], $type, strtolower($username)))) |
|
83 | 83 | { |
84 | 84 | break; |
85 | 85 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | if ($match) |
89 | 89 | { |
90 | 90 | $encrypted_passwd = auth::encrypt_sql($passwd); |
91 | - $this->_update_passwd($encrypted_passwd,$passwd,$row['account_id'],false,true); |
|
91 | + $this->_update_passwd($encrypted_passwd, $passwd, $row['account_id'], false, true); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | if (!$match) return false; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | else |
99 | 99 | { |
100 | 100 | $where['account_pwd'] = $passwd; |
101 | - if (!($row = $this->db->select($this->table,'account_lid,account_lastlogin',$where,__LINE__,__FILE__)->fetch()) || |
|
101 | + if (!($row = $this->db->select($this->table, 'account_lid,account_lastlogin', $where, __LINE__, __FILE__)->fetch()) || |
|
102 | 102 | $GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username) |
103 | 103 | { |
104 | 104 | return false; |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $where[] = 'account_lid '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username); |
130 | 130 | unset($where['account_lid']); |
131 | 131 | } |
132 | - if (!($row = $this->db->select($this->table,'account_lid,account_lastpwd_change',$where,__LINE__,__FILE__)->fetch()) || |
|
132 | + if (!($row = $this->db->select($this->table, 'account_lid,account_lastpwd_change', $where, __LINE__, __FILE__)->fetch()) || |
|
133 | 133 | $GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username) |
134 | 134 | { |
135 | 135 | return false; |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | * @param int $lastpwdchange must be a unixtimestamp |
149 | 149 | * @return boolean true if account_lastpwd_change successful changed, false otherwise |
150 | 150 | */ |
151 | - function setLastPwdChange($account_id=0, $passwd=NULL, $lastpwdchange=NULL) |
|
151 | + function setLastPwdChange($account_id = 0, $passwd = NULL, $lastpwdchange = NULL) |
|
152 | 152 | { |
153 | 153 | $admin = True; |
154 | 154 | // Don't allow password changes for other accounts when using XML-RPC |
155 | - if(!$account_id || $GLOBALS['egw_info']['flags']['currentapp'] == 'login') |
|
155 | + if (!$account_id || $GLOBALS['egw_info']['flags']['currentapp'] == 'login') |
|
156 | 156 | { |
157 | 157 | $admin = False; |
158 | 158 | $account_id = $GLOBALS['egw_info']['user']['account_id']; |
@@ -163,28 +163,28 @@ discard block |
||
163 | 163 | $username = $GLOBALS['egw']->accounts->id2name($account_id); |
164 | 164 | } |
165 | 165 | |
166 | - if (($pw = $this->db->select($this->table,'account_pwd',array( |
|
166 | + if (($pw = $this->db->select($this->table, 'account_pwd', array( |
|
167 | 167 | 'account_id' => $account_id, |
168 | 168 | 'account_type' => 'u', |
169 | 169 | 'account_status' => 'A', |
170 | - ),__LINE__,__FILE__)->fetchColumn()) === false) |
|
170 | + ), __LINE__, __FILE__)->fetchColumn()) === false) |
|
171 | 171 | { |
172 | - return false; // account not found |
|
172 | + return false; // account not found |
|
173 | 173 | } |
174 | 174 | // Check the passwd to make sure this is legal |
175 | - if(!$admin && !auth::compare_password($passwd,$pw,$this->type,strtolower($username))) |
|
175 | + if (!$admin && !auth::compare_password($passwd, $pw, $this->type, strtolower($username))) |
|
176 | 176 | { |
177 | 177 | return false; |
178 | 178 | } |
179 | - $lastpwdchange = (is_null($lastpwdchange) || $lastpwdchange<0 ? time():$lastpwdchange); |
|
180 | - $this->db->update($this->table,array( |
|
179 | + $lastpwdchange = (is_null($lastpwdchange) || $lastpwdchange < 0 ? time() : $lastpwdchange); |
|
180 | + $this->db->update($this->table, array( |
|
181 | 181 | 'account_lastpwd_change' => $lastpwdchange, |
182 | - ),array( |
|
182 | + ), array( |
|
183 | 183 | 'account_id' => $account_id, |
184 | - ),__LINE__,__FILE__); |
|
184 | + ), __LINE__, __FILE__); |
|
185 | 185 | |
186 | - if(!$this->db->affected_rows()) return false; |
|
187 | - if (!$admin) egw_cache::setSession('phpgwapi','auth_alpwchange_val',$lastpwdchange); |
|
186 | + if (!$this->db->affected_rows()) return false; |
|
187 | + if (!$admin) egw_cache::setSession('phpgwapi', 'auth_alpwchange_val', $lastpwdchange); |
|
188 | 188 | return true; |
189 | 189 | } |
190 | 190 | |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | * @param int $account_id account id of user whose passwd should be changed |
197 | 197 | * @return boolean true if password successful changed, false otherwise |
198 | 198 | */ |
199 | - function change_password($old_passwd, $new_passwd, $account_id=0) |
|
199 | + function change_password($old_passwd, $new_passwd, $account_id = 0) |
|
200 | 200 | { |
201 | 201 | $admin = True; |
202 | 202 | // Don't allow password changes for other accounts when using XML-RPC |
203 | - if(!$account_id) |
|
203 | + if (!$account_id) |
|
204 | 204 | { |
205 | 205 | $admin = False; |
206 | 206 | $account_id = $GLOBALS['egw_info']['user']['account_id']; |
@@ -211,21 +211,21 @@ discard block |
||
211 | 211 | $username = $GLOBALS['egw']->accounts->id2name($account_id); |
212 | 212 | } |
213 | 213 | |
214 | - if (($pw = $this->db->select($this->table,'account_pwd',array( |
|
214 | + if (($pw = $this->db->select($this->table, 'account_pwd', array( |
|
215 | 215 | 'account_id' => $account_id, |
216 | 216 | 'account_type' => 'u', |
217 | - ),__LINE__,__FILE__)->fetchColumn()) === false) |
|
217 | + ), __LINE__, __FILE__)->fetchColumn()) === false) |
|
218 | 218 | { |
219 | - return false; // account not found |
|
219 | + return false; // account not found |
|
220 | 220 | } |
221 | 221 | // Check the old_passwd to make sure this is legal |
222 | - if(!$admin && !auth::compare_password($old_passwd,$pw,$this->type,strtolower($username))) |
|
222 | + if (!$admin && !auth::compare_password($old_passwd, $pw, $this->type, strtolower($username))) |
|
223 | 223 | { |
224 | 224 | return false; |
225 | 225 | } |
226 | 226 | |
227 | 227 | // old password ok, or admin called the function from the admin application (no old passwd available). |
228 | - return $this->_update_passwd(auth::encrypt_sql($new_passwd),$new_passwd,$account_id,$admin); |
|
228 | + return $this->_update_passwd(auth::encrypt_sql($new_passwd), $new_passwd, $account_id, $admin); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -238,21 +238,21 @@ discard block |
||
238 | 238 | * @param boolean $update_lastpw_change=true |
239 | 239 | * @return boolean true if password successful changed, false otherwise |
240 | 240 | */ |
241 | - private function _update_passwd($encrypted_passwd,$new_passwd,$account_id,$admin=false,$update_lastpw_change=true) |
|
241 | + private function _update_passwd($encrypted_passwd, $new_passwd, $account_id, $admin = false, $update_lastpw_change = true) |
|
242 | 242 | { |
243 | 243 | $update = array('account_pwd' => $encrypted_passwd); |
244 | 244 | if ($update_lastpw_change) $update['account_lastpwd_change'] = time(); |
245 | 245 | |
246 | - if (!$this->db->update($this->table,$update,array( |
|
246 | + if (!$this->db->update($this->table, $update, array( |
|
247 | 247 | 'account_id' => $account_id, |
248 | - ),__LINE__,__FILE__)) |
|
248 | + ), __LINE__, __FILE__)) |
|
249 | 249 | { |
250 | 250 | return false; |
251 | 251 | } |
252 | 252 | |
253 | - if(!$admin) |
|
253 | + if (!$admin) |
|
254 | 254 | { |
255 | - egw_cache::setSession('phpgwapi','auth_alpwchange_val',$update['account_lastpwd_change']); |
|
255 | + egw_cache::setSession('phpgwapi', 'auth_alpwchange_val', $update['account_lastpwd_change']); |
|
256 | 256 | } |
257 | 257 | return true; |
258 | 258 | } |
@@ -56,9 +56,12 @@ discard block |
||
56 | 56 | 'account_type' => 'u', |
57 | 57 | 'account_status' => 'A' |
58 | 58 | ); |
59 | - if (!$GLOBALS['egw_info']['server']['case_sensitive_username']) // = is case sensitiv eg. on postgres, but not on mysql! |
|
59 | + if (!$GLOBALS['egw_info']['server']['case_sensitive_username']) |
|
60 | + { |
|
61 | + // = is case sensitiv eg. on postgres, but not on mysql! |
|
60 | 62 | { |
61 | 63 | $where[] = 'account_lid '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username); |
64 | + } |
|
62 | 65 | unset($where['account_lid']); |
63 | 66 | } |
64 | 67 | if($passwd_type == 'text') |
@@ -91,7 +94,10 @@ discard block |
||
91 | 94 | $this->_update_passwd($encrypted_passwd,$passwd,$row['account_id'],false,true); |
92 | 95 | } |
93 | 96 | } |
94 | - if (!$match) return false; |
|
97 | + if (!$match) |
|
98 | + { |
|
99 | + return false; |
|
100 | + } |
|
95 | 101 | } |
96 | 102 | } |
97 | 103 | /* Auth via crypted password. NOTE: mail needs cleartext password to authenticate against mailserver! */ |
@@ -124,9 +130,12 @@ discard block |
||
124 | 130 | 'account_type' => 'u', |
125 | 131 | 'account_status' => 'A' |
126 | 132 | ); |
127 | - if (!$GLOBALS['egw_info']['server']['case_sensitive_username']) // = is case sensitiv eg. on postgres, but not on mysql! |
|
133 | + if (!$GLOBALS['egw_info']['server']['case_sensitive_username']) |
|
134 | + { |
|
135 | + // = is case sensitiv eg. on postgres, but not on mysql! |
|
128 | 136 | { |
129 | 137 | $where[] = 'account_lid '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username); |
138 | + } |
|
130 | 139 | unset($where['account_lid']); |
131 | 140 | } |
132 | 141 | if (!($row = $this->db->select($this->table,'account_lid,account_lastpwd_change',$where,__LINE__,__FILE__)->fetch()) || |
@@ -183,8 +192,14 @@ discard block |
||
183 | 192 | 'account_id' => $account_id, |
184 | 193 | ),__LINE__,__FILE__); |
185 | 194 | |
186 | - if(!$this->db->affected_rows()) return false; |
|
187 | - if (!$admin) egw_cache::setSession('phpgwapi','auth_alpwchange_val',$lastpwdchange); |
|
195 | + if(!$this->db->affected_rows()) |
|
196 | + { |
|
197 | + return false; |
|
198 | + } |
|
199 | + if (!$admin) |
|
200 | + { |
|
201 | + egw_cache::setSession('phpgwapi','auth_alpwchange_val',$lastpwdchange); |
|
202 | + } |
|
188 | 203 | return true; |
189 | 204 | } |
190 | 205 | |
@@ -241,7 +256,10 @@ discard block |
||
241 | 256 | private function _update_passwd($encrypted_passwd,$new_passwd,$account_id,$admin=false,$update_lastpw_change=true) |
242 | 257 | { |
243 | 258 | $update = array('account_pwd' => $encrypted_passwd); |
244 | - if ($update_lastpw_change) $update['account_lastpwd_change'] = time(); |
|
259 | + if ($update_lastpw_change) |
|
260 | + { |
|
261 | + $update['account_lastpwd_change'] = time(); |
|
262 | + } |
|
245 | 263 | |
246 | 264 | if (!$this->db->update($this->table,$update,array( |
247 | 265 | 'account_id' => $account_id, |
@@ -178,18 +178,16 @@ discard block |
||
178 | 178 | /** |
179 | 179 | * return an array populated with categories |
180 | 180 | * |
181 | - * @param string $type='all' 'subs','mains','appandmains','appandsubs','noglobal','noglobalapp', defaults to 'all' |
|
182 | - * @param int $start=0 see $limit |
|
181 | + * @param int $start see $limit |
|
183 | 182 | * @param boolean|int $limit if true limited query to maxmatches rows (starting with $start) |
184 | 183 | * @param string $query='' query-pattern |
185 | - * @param string $sort='ASC' sort order, defaults to 'ASC' |
|
186 | 184 | * @param string $order='' order by, default cat_main, cat_level, cat_name ASC |
187 | 185 | * @param boolean|string $globals includes the global egroupware categories or not, |
188 | 186 | * 'all_no_acl' to return global and all non-private user categories independent of ACL |
189 | - * @param array|int $parent_id=null return only subcats of $parent_id(s) |
|
187 | + * @param array|int $parent_id return only subcats of $parent_id(s) |
|
190 | 188 | * @param int $lastmod = -1 if > 0 return only cats modified since then |
191 | 189 | * @param string $column='' if column-name given only that column is returned, not the full array with all cat-data |
192 | - * @param array $filter=null array with column-name (without cat_-prefix) => value pairs (! negates the value) |
|
190 | + * @param array $filter array with column-name (without cat_-prefix) => value pairs (! negates the value) |
|
193 | 191 | * @return array of cat-arrays or $column values |
194 | 192 | */ |
195 | 193 | function return_array($type='all', $start=0, $limit=true, $query='', $sort='ASC',$order='',$globals=false, $parent_id=null, $lastmod=-1, $column='', $filter=null) |
@@ -324,15 +322,13 @@ discard block |
||
324 | 322 | /** |
325 | 323 | * return a sorted array populated with categories (main sorting criteria is hierachy!) |
326 | 324 | * |
327 | - * @param int $start=0 see $limit |
|
328 | - * @param boolean|int $limit if true limited query to maxmatches rows (starting with $start) |
|
325 | + * @param int $start see $limit |
|
326 | + * @param boolean $limit if true limited query to maxmatches rows (starting with $start) |
|
329 | 327 | * @param string $query='' query-pattern |
330 | - * @param string $sort='ASC' sort order, either defaults to 'ASC' |
|
331 | - * @param string $order='cat_name' order by |
|
332 | 328 | * @param boolean|string $globals includes the global egroupware categories or not, |
333 | 329 | * 'all_no_acl' to return global and all non-private user categories independent of ACL |
334 | - * @param array|int $parent_id=0 return only subcats of $parent_id(s) |
|
335 | - * @param boolean $unserialize_data=true return $cat['data'] as array (not serialized array) |
|
330 | + * @param array|int $parent_id return only subcats of $parent_id(s) |
|
331 | + * @param boolean $unserialize_data return $cat['data'] as array (not serialized array) |
|
336 | 332 | * @return array with cats |
337 | 333 | */ |
338 | 334 | function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
@@ -429,7 +425,7 @@ discard block |
||
429 | 425 | * |
430 | 426 | * Owner and appname are set from the values used to instanciate the class! |
431 | 427 | * |
432 | - * @param array $value cat-data |
|
428 | + * @param array $values cat-data |
|
433 | 429 | * @return int new cat-id |
434 | 430 | */ |
435 | 431 | function add($values) |
@@ -508,9 +504,9 @@ discard block |
||
508 | 504 | * |
509 | 505 | * @param int $needed necessary ACL right: EGW_ACL_{READ|EDIT|DELETE} |
510 | 506 | * @param mixed $category category as array or the category_id |
511 | - * @param boolean $no_acl_check=false if true, grants are NOT checked, gives access to all non-private categories of all users |
|
507 | + * @param boolean $no_acl_check if true, grants are NOT checked, gives access to all non-private categories of all users |
|
512 | 508 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
513 | - * @return boolean true permission granted, false for permission denied, null for category does not exist |
|
509 | + * @return null|boolean true permission granted, false for permission denied, null for category does not exist |
|
514 | 510 | */ |
515 | 511 | public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
516 | 512 | { |
@@ -570,8 +566,8 @@ discard block |
||
570 | 566 | * delete a category |
571 | 567 | * |
572 | 568 | * @param int $cat_id category id |
573 | - * @param boolean $drop_subs=false if true delete sub-cats too |
|
574 | - * @param boolean $modify_subs=false if true make the subs owned by the parent of $cat_id |
|
569 | + * @param boolean $drop_subs if true delete sub-cats too |
|
570 | + * @param boolean $modify_subs if true make the subs owned by the parent of $cat_id |
|
575 | 571 | */ |
576 | 572 | function delete($cat_id, $drop_subs = False, $modify_subs = False) |
577 | 573 | { |
@@ -769,7 +765,6 @@ discard block |
||
769 | 765 | * - cat's of other user |
770 | 766 | * |
771 | 767 | * @param string $cat_name cat-name |
772 | - * @param boolean|string $strip=false if true, strips 'X-' ($strip) from category names added by some SyncML clients |
|
773 | 768 | * @return int cat-id or 0 if not found |
774 | 769 | */ |
775 | 770 | function name2id($cat_name, $strip=false) |
@@ -821,8 +816,8 @@ discard block |
||
821 | 816 | * Check if category is global (owner <= 0 || appname == 'phpgw') |
822 | 817 | * |
823 | 818 | * @param int|array $cat |
824 | - * @param boolean $application_global=false true check for application global categories only (appname == 'phpgw') |
|
825 | - * @return boolean |
|
819 | + * @param boolean $application_global true check for application global categories only (appname == 'phpgw') |
|
820 | + * @return null|boolean |
|
826 | 821 | */ |
827 | 822 | static function is_global($cat,$application_global=false) |
828 | 823 | { |
@@ -842,8 +837,7 @@ discard block |
||
842 | 837 | * We use a shared cache together with read |
843 | 838 | * $item == 'data' is returned as array (not serialized array)! |
844 | 839 | * |
845 | - * @param int $cat_id=0 cat-id |
|
846 | - * @param string $item='name' requested information, 'path' = / delimited path of category names (incl. parents) |
|
840 | + * @param int $cat_id cat-id |
|
847 | 841 | * @return string information or '--' if not found or !$cat_id |
848 | 842 | */ |
849 | 843 | static function id2name($cat_id=0, $item='name') |
@@ -883,8 +877,8 @@ discard block |
||
883 | 877 | * |
884 | 878 | * @param string $type subs or mains |
885 | 879 | * @param string $cat_name='' category name |
886 | - * @param int $cat_id=0 category id |
|
887 | - * @param int $parent=0 category id of parent |
|
880 | + * @param int $cat_id category id |
|
881 | + * @param int $parent category id of parent |
|
888 | 882 | * @return int/boolean cat_id or false if cat not exists |
889 | 883 | */ |
890 | 884 | function exists($type,$cat_name = '',$cat_id = 0,$parent = 0) |
@@ -914,8 +908,6 @@ discard block |
||
914 | 908 | * Change the owner of all cats owned by $owner to $to OR deletes them if !$to |
915 | 909 | * |
916 | 910 | * @param int $owner owner or the cats to delete or change |
917 | - * @param int $to=0 new owner or 0 to delete the cats |
|
918 | - * @param string $app='' if given only cats matching $app are modifed/deleted |
|
919 | 911 | */ |
920 | 912 | function change_owner($owner,$to=0,$app='') |
921 | 913 | { |
@@ -1030,7 +1022,7 @@ discard block |
||
1030 | 1022 | * |
1031 | 1023 | * @param string appname |
1032 | 1024 | * |
1033 | - * @return Returns the URL, but you do not need to do anything with it. |
|
1025 | + * @return string the URL, but you do not need to do anything with it. |
|
1034 | 1026 | */ |
1035 | 1027 | public static function css($appname) |
1036 | 1028 | { |
@@ -1047,7 +1039,7 @@ discard block |
||
1047 | 1039 | * Delete categories belonging to a given account, when account got deleted |
1048 | 1040 | * |
1049 | 1041 | * @param int $account_id |
1050 | - * @param int $new_owner=null for users data can be transfered to new owner |
|
1042 | + * @param int $new_owner for users data can be transfered to new owner |
|
1051 | 1043 | * @return int number of deleted or modified categories |
1052 | 1044 | */ |
1053 | 1045 | public static function delete_account($account_id, $new_owner=null) |
@@ -1138,7 +1130,7 @@ discard block |
||
1138 | 1130 | /** |
1139 | 1131 | * return into a select box, list or other formats |
1140 | 1132 | * |
1141 | - * @param string/array $format string 'select' or 'list', or array with all params |
|
1133 | + * @param string $format string 'select' or 'list', or array with all params |
|
1142 | 1134 | * @param string $type='' subs or mains |
1143 | 1135 | * @param int/array $selected - cat_id or array with cat_id values |
1144 | 1136 | * @param boolean $globals True or False, includes the global egroupware categories or not |
@@ -118,23 +118,23 @@ discard block |
||
118 | 118 | * @param int|string $accountid='' account id or lid, default to current user |
119 | 119 | * @param string $app_name='' app name defaults to current app |
120 | 120 | */ |
121 | - function __construct($accountid='',$app_name = '') |
|
121 | + function __construct($accountid = '', $app_name = '') |
|
122 | 122 | { |
123 | 123 | if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
124 | 124 | |
125 | 125 | if ($accountid === self::GLOBAL_ACCOUNT || |
126 | 126 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
127 | 127 | { |
128 | - $this->account_id = (int) $accountid; |
|
128 | + $this->account_id = (int)$accountid; |
|
129 | 129 | } |
130 | 130 | else |
131 | 131 | { |
132 | - $this->account_id = (int) get_account_id($accountid); |
|
132 | + $this->account_id = (int)get_account_id($accountid); |
|
133 | 133 | $this->global_owners = $this->account_id ? $GLOBALS['egw']->accounts->memberships($this->account_id, true) : array(); |
134 | 134 | $this->global_owners[] = self::GLOBAL_ACCOUNT; |
135 | 135 | } |
136 | - $this->app_name = $app_name; |
|
137 | - $this->db = $GLOBALS['egw']->db; |
|
136 | + $this->app_name = $app_name; |
|
137 | + $this->db = $GLOBALS['egw']->db; |
|
138 | 138 | |
139 | 139 | if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
140 | 140 | { |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @deprecated |
153 | 153 | */ |
154 | - function categories($accountid='',$app_name='') |
|
154 | + function categories($accountid = '', $app_name = '') |
|
155 | 155 | { |
156 | - self::__construct($accountid,$app_name); |
|
156 | + self::__construct($accountid, $app_name); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | */ |
165 | 165 | function return_all_children($cat_id) |
166 | 166 | { |
167 | - $all_children = (array) $cat_id; |
|
167 | + $all_children = (array)$cat_id; |
|
168 | 168 | |
169 | - $children = $this->return_array('subs',0,False,'','','',True,$cat_id,-1,'id'); |
|
169 | + $children = $this->return_array('subs', 0, False, '', '', '', True, $cat_id, -1, 'id'); |
|
170 | 170 | if (is_array($children) && count($children)) |
171 | 171 | { |
172 | - $all_children = array_merge($all_children,$this->return_all_children($children)); |
|
172 | + $all_children = array_merge($all_children, $this->return_all_children($children)); |
|
173 | 173 | } |
174 | 174 | //echo "<p>categories::return_all_children($cat_id)=(".implode(',',$all_children).")</p>\n"; |
175 | 175 | return $all_children; |
@@ -192,24 +192,24 @@ discard block |
||
192 | 192 | * @param array $filter=null array with column-name (without cat_-prefix) => value pairs (! negates the value) |
193 | 193 | * @return array of cat-arrays or $column values |
194 | 194 | */ |
195 | - function return_array($type='all', $start=0, $limit=true, $query='', $sort='ASC',$order='',$globals=false, $parent_id=null, $lastmod=-1, $column='', $filter=null) |
|
195 | + function return_array($type = 'all', $start = 0, $limit = true, $query = '', $sort = 'ASC', $order = '', $globals = false, $parent_id = null, $lastmod = -1, $column = '', $filter = null) |
|
196 | 196 | { |
197 | 197 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,globals=$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).") account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
198 | 198 | $cats = array(); |
199 | - foreach(self::$cache as $cat) |
|
199 | + foreach (self::$cache as $cat) |
|
200 | 200 | { |
201 | - if ($filter) foreach($filter as $col => $val) |
|
201 | + if ($filter) foreach ($filter as $col => $val) |
|
202 | 202 | { |
203 | 203 | if (!is_array($val) && $val[0] === '!') |
204 | 204 | { |
205 | 205 | // also match against trimmed database entry on name and description fields |
206 | 206 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
207 | 207 | { |
208 | - if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
|
208 | + if ($cat[$col] == substr($val, 1) || trim($cat[$col]) == substr($val, 1)) continue 2; |
|
209 | 209 | } |
210 | 210 | else |
211 | 211 | { |
212 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
212 | + if ($cat[$col] == substr($val, 1)) continue 2; |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | elseif (is_array($val)) |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | // also match against trimmed database entry on name and description fields |
218 | 218 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
219 | 219 | { |
220 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
220 | + if (!in_array($cat[$col], $val) && !in_array(trim($cat[$col]), $val)) continue 2; |
|
221 | 221 | } |
222 | 222 | else |
223 | 223 | { |
224 | - if (!in_array($cat[$col],$val)) continue 2; |
|
224 | + if (!in_array($cat[$col], $val)) continue 2; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | else |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | } |
239 | 239 | } |
240 | 240 | // check if certain parent required |
241 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
241 | + if ($parent_id && !in_array($cat['parent'], (array)$parent_id)) continue; |
|
242 | 242 | |
243 | 243 | // return global categories just if $globals is set |
244 | 244 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | } |
248 | 248 | |
249 | 249 | // check for read permission |
250 | - if(!$this->check_perms(EGW_ACL_READ, $cat, $globals === 'all_no_acl')) |
|
250 | + if (!$this->check_perms(EGW_ACL_READ, $cat, $globals === 'all_no_acl')) |
|
251 | 251 | { |
252 | 252 | continue; |
253 | 253 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | switch ($type) |
257 | 257 | { |
258 | 258 | case 'subs': |
259 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
259 | + if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
260 | 260 | break; |
261 | 261 | case 'mains': |
262 | 262 | if ($cat['parent']) continue 2; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | // check name and description for $query |
279 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
279 | + if ($query && stristr($cat['name'], $query) === false && stristr($cat['description'], $query) === false) continue; |
|
280 | 280 | |
281 | 281 | // check if last modified since |
282 | 282 | if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
@@ -293,31 +293,31 @@ discard block |
||
293 | 293 | if (!$sort) $sort = 'ASC'; |
294 | 294 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
295 | 295 | if ($this->total_records > 1 && !empty($order) && |
296 | - preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
|
296 | + preg_match('/^[a-zA-Z_(), ]+$/', $order) && preg_match('/^(ASC|DESC|asc|desc)$/', $sort)) |
|
297 | 297 | { |
298 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
299 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
298 | + if (strstr($order, 'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
299 | + if (substr($order, 0, 4) == 'cat_') $order = substr($order, 4); |
|
300 | 300 | $sign = strtoupper($sort) == 'DESC' ? '-' : ''; |
301 | - usort($cats,create_function('$a,$b',$func=(in_array($order,array('name','description','appname','app_name')) ? |
|
301 | + usort($cats, create_function('$a,$b', $func = (in_array($order, array('name', 'description', 'appname', 'app_name')) ? |
|
302 | 302 | "return ${sign}strcasecmp(\$a['$order'],\$b['$order']);" : "return $sign(int)\$a['$order'] - $sign(int)\$b['$order'];"))); |
303 | 303 | } |
304 | 304 | // limit the number of returned rows |
305 | 305 | if ($limit) |
306 | 306 | { |
307 | 307 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
308 | - $cats = array_slice($cats,(int)$start,$limit); |
|
308 | + $cats = array_slice($cats, (int)$start, $limit); |
|
309 | 309 | } |
310 | 310 | // return only a certain column (why not return is as value?) |
311 | 311 | if ($column) |
312 | 312 | { |
313 | - foreach($cats as $k => $cat) |
|
313 | + foreach ($cats as $k => $cat) |
|
314 | 314 | { |
315 | 315 | $cats[$k] = $cat[$column]; |
316 | 316 | } |
317 | 317 | } |
318 | 318 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).",$unserialize_data) account_id=$this->account_id, appname=$this->app_name = ".array2string($cats)); |
319 | 319 | |
320 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
320 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
321 | 321 | return $cats; |
322 | 322 | } |
323 | 323 | |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @param boolean $unserialize_data=true return $cat['data'] as array (not serialized array) |
336 | 336 | * @return array with cats |
337 | 337 | */ |
338 | - function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
|
338 | + function return_sorted_array($start = 0, $limit = True, $query = '', $sort = 'ASC', $order = 'cat_name', $globals = False, $parent_id = 0, $unserialize_data = true, $filter = null) |
|
339 | 339 | { |
340 | 340 | if (!$sort) $sort = 'ASC'; |
341 | 341 | if (!$order) $order = 'cat_name'; |
@@ -345,27 +345,27 @@ discard block |
||
345 | 345 | $parents = $cats = array(); |
346 | 346 | |
347 | 347 | // Cast parent_id to array, but only if there is one |
348 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
349 | - if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
|
348 | + if ($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
349 | + if (!($cats = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parent_id, -1, '', $filter, $unserialize_data))) |
|
350 | 350 | { |
351 | 351 | $cats = array(); |
352 | 352 | } |
353 | - foreach($cats as $cat) |
|
353 | + foreach ($cats as $cat) |
|
354 | 354 | { |
355 | 355 | $parents[] = $cat['id']; |
356 | 356 | } |
357 | 357 | |
358 | - if($parent_id || !$cats) // Avoid wiping search results |
|
358 | + if ($parent_id || !$cats) // Avoid wiping search results |
|
359 | 359 | { |
360 | 360 | // Go find the children |
361 | 361 | while (count($parents)) |
362 | 362 | { |
363 | - if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
|
363 | + if (!($subs = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parents, -1, '', $filter, $unserialize_data))) |
|
364 | 364 | { |
365 | 365 | break; |
366 | 366 | } |
367 | 367 | $parents = $children = array(); |
368 | - foreach($subs as $cat) |
|
368 | + foreach ($subs as $cat) |
|
369 | 369 | { |
370 | 370 | $parents[] = $cat['id']; |
371 | 371 | $children[$cat['parent']][] = $cat; |
@@ -375,12 +375,12 @@ discard block |
||
375 | 375 | { |
376 | 376 | $cats2 = $cats; |
377 | 377 | $cats = array(); |
378 | - foreach($cats2 as $cat) |
|
378 | + foreach ($cats2 as $cat) |
|
379 | 379 | { |
380 | 380 | $cats[] = $cat; |
381 | 381 | if (isset($children[$cat['id']])) |
382 | 382 | { |
383 | - foreach($children[$cat['id']] as $child) |
|
383 | + foreach ($children[$cat['id']] as $child) |
|
384 | 384 | { |
385 | 385 | $cats[] = $child; |
386 | 386 | } |
@@ -395,9 +395,9 @@ discard block |
||
395 | 395 | if ($limit) |
396 | 396 | { |
397 | 397 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
398 | - $cats = array_slice($cats,(int)$start,$limit); |
|
398 | + $cats = array_slice($cats, (int)$start, $limit); |
|
399 | 399 | } |
400 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
400 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
401 | 401 | return $cats; |
402 | 402 | } |
403 | 403 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | if (!isset(self::$cache[$id])) return false; |
419 | 419 | |
420 | 420 | $cat = self::$cache[$id]; |
421 | - $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
421 | + $cat['data'] = $cat['data'] ? ((($arr = json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
422 | 422 | $arr : $cat['data']) : array(); |
423 | 423 | |
424 | 424 | return $cat; |
@@ -436,31 +436,31 @@ discard block |
||
436 | 436 | { |
437 | 437 | if ((int)$values['parent'] > 0) |
438 | 438 | { |
439 | - $values['level'] = $this->id2name($values['parent'],'level')+1; |
|
440 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
439 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
440 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
441 | 441 | } |
442 | 442 | else |
443 | 443 | { |
444 | 444 | $values['level'] = 0; |
445 | 445 | } |
446 | - $this->db->insert(self::TABLE,$cat=array( |
|
446 | + $this->db->insert(self::TABLE, $cat = array( |
|
447 | 447 | 'cat_parent' => $values['parent'], |
448 | 448 | 'cat_owner' => isset($values['owner']) ? $values['owner'] : $this->account_id, |
449 | 449 | 'cat_access' => isset($values['access']) ? $values['access'] : 'public', |
450 | 450 | 'cat_appname' => $this->app_name, |
451 | 451 | 'cat_name' => $values['name'], |
452 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
452 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
453 | 453 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
454 | 454 | 'cat_main' => $values['main'], |
455 | 455 | 'cat_level' => $values['level'], |
456 | 456 | 'last_mod' => time(), |
457 | - ),(int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(),__LINE__,__FILE__); |
|
457 | + ), (int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(), __LINE__, __FILE__); |
|
458 | 458 | |
459 | - $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE,'cat_id'); |
|
459 | + $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE, 'cat_id'); |
|
460 | 460 | |
461 | 461 | if (!(int)$values['parent'] && $id != $values['main']) |
462 | 462 | { |
463 | - $this->db->update(self::TABLE,array('cat_main' => $id),array('cat_id' => $id),__LINE__,__FILE__); |
|
463 | + $this->db->update(self::TABLE, array('cat_main' => $id), array('cat_id' => $id), __LINE__, __FILE__); |
|
464 | 464 | $cat['cat_main'] = $id; |
465 | 465 | } |
466 | 466 | // update cache accordingly |
@@ -482,20 +482,20 @@ discard block |
||
482 | 482 | if (empty($cat_list)) return $cat_list; |
483 | 483 | if (is_array($cat_list)) |
484 | 484 | { |
485 | - $cat_list = implode(',',$cat_list); |
|
485 | + $cat_list = implode(',', $cat_list); |
|
486 | 486 | //error_log(__METHOD__.__LINE__.' string expected, array found for cat_list. Converted to:'.$cat_list); |
487 | 487 | } |
488 | - $cat_arr = explode(',',$cat_list); |
|
488 | + $cat_arr = explode(',', $cat_list); |
|
489 | 489 | if (!empty($cat_arr) && is_array($cat_arr) && count($cat_arr) > 0) |
490 | 490 | { |
491 | - foreach($cat_arr as $id=>$cat_id) |
|
491 | + foreach ($cat_arr as $id=>$cat_id) |
|
492 | 492 | { |
493 | 493 | if (!$this->check_perms($needed, $cat_id, false, $needed == EGW_ACL_READ)) // allow reading all global cats |
494 | 494 | { |
495 | 495 | unset($cat_arr[$id]); |
496 | 496 | } |
497 | 497 | } |
498 | - $cat_list = implode(',',$cat_arr); |
|
498 | + $cat_list = implode(',', $cat_arr); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | return $cat_list; |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
513 | 513 | * @return boolean true permission granted, false for permission denied, null for category does not exist |
514 | 514 | */ |
515 | - public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
|
515 | + public function check_perms($needed, $category, $no_acl_check = false, $allow_global_read = false) |
|
516 | 516 | { |
517 | 517 | if (!is_array($category) && !($category = self::read($category))) |
518 | 518 | { |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | } |
529 | 529 | |
530 | 530 | // Read access to global categories |
531 | - if ($needed == EGW_ACL_READ && (($is_global=array_intersect(explode(',',$category['owner']),$this->global_owners)) || |
|
532 | - $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
531 | + if ($needed == EGW_ACL_READ && (($is_global = array_intersect(explode(',', $category['owner']), $this->global_owners)) || |
|
532 | + $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
533 | 533 | ($category['appname'] == self::GLOBAL_APPNAME || $category['appname'] == $this->app_name || |
534 | 534 | $is_global && $allow_global_read)) |
535 | 535 | { |
@@ -552,16 +552,16 @@ discard block |
||
552 | 552 | // Load the application grants |
553 | 553 | if ($category['appname'] == $this->app_name && is_null($this->grants)) |
554 | 554 | { |
555 | - $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name,true); |
|
555 | + $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name, true); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | // Check for ACL granted access, the self::GLOBAL_ACCOUNT user must not get access by ACL to keep old behaviour |
559 | 559 | $acl_grant = $this->account_id != self::GLOBAL_ACCOUNT && $category['appname'] == $this->app_name; |
560 | 560 | $owner_grant = false; |
561 | - foreach(explode(',',$category['owner']) as $owner) |
|
561 | + foreach (explode(',', $category['owner']) as $owner) |
|
562 | 562 | { |
563 | - $owner_grant = $owner_grant || (($this->grants[$owner] & $needed) && |
|
564 | - ($category['access'] == 'public' || ($this->grants[$owner] & EGW_ACL_PRIVATE))); |
|
563 | + $owner_grant = $owner_grant || (($this->grants[$owner]&$needed) && |
|
564 | + ($category['access'] == 'public' || ($this->grants[$owner]&EGW_ACL_PRIVATE))); |
|
565 | 565 | } |
566 | 566 | return $acl_grant && $owner_grant; |
567 | 567 | } |
@@ -578,35 +578,35 @@ discard block |
||
578 | 578 | //error_log(__METHOD__."(".array2string($cat_id).', drop_subs='.array2string($drop_subs).', modify_subs='.array2string($modify_subs).') '.function_backtrace()); |
579 | 579 | if ($modify_subs) |
580 | 580 | { |
581 | - $new_parent = $this->id2name($cat_id,'parent'); |
|
581 | + $new_parent = $this->id2name($cat_id, 'parent'); |
|
582 | 582 | |
583 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $cat_id) as $cat) |
|
583 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $cat_id) as $cat) |
|
584 | 584 | { |
585 | 585 | if ($cat['level'] == 1) |
586 | 586 | { |
587 | - $this->db->update(self::TABLE,array( |
|
587 | + $this->db->update(self::TABLE, array( |
|
588 | 588 | 'cat_level' => 0, |
589 | 589 | 'cat_parent' => 0, |
590 | 590 | 'cat_main' => $cat['id'], |
591 | - ),array( |
|
591 | + ), array( |
|
592 | 592 | 'cat_id' => $cat['id'], |
593 | 593 | 'cat_appname' => $this->app_name, |
594 | - ),__LINE__,__FILE__); |
|
594 | + ), __LINE__, __FILE__); |
|
595 | 595 | |
596 | 596 | $new_main = $cat['id']; |
597 | 597 | } |
598 | 598 | else |
599 | 599 | { |
600 | - $update = array('cat_level' => $cat['level']-1); |
|
600 | + $update = array('cat_level' => $cat['level'] - 1); |
|
601 | 601 | |
602 | 602 | if ($new_main) $update['cat_main'] = $new_main; |
603 | 603 | |
604 | 604 | if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
605 | 605 | |
606 | - $this->db->update(self::TABLE,$update,array( |
|
606 | + $this->db->update(self::TABLE, $update, array( |
|
607 | 607 | 'cat_id' => $cat['id'], |
608 | 608 | 'cat_appname' => $this->app_name, |
609 | - ),__LINE__,__FILE__); |
|
609 | + ), __LINE__, __FILE__); |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | } |
@@ -627,16 +627,16 @@ discard block |
||
627 | 627 | 'modify_subs' => $modify_subs, |
628 | 628 | 'location' => 'delete_category' |
629 | 629 | ); |
630 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
630 | + if ($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
631 | 631 | { |
632 | - $GLOBALS['egw']->hooks->process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
632 | + $GLOBALS['egw']->hooks->process($GLOBALS['hook_values'], False, True); // called for every app now, not only enabled ones) |
|
633 | 633 | } |
634 | 634 | else |
635 | 635 | { |
636 | - $GLOBALS['egw']->hooks->single($GLOBALS['hook_values'], self::id2name($cat_id,'appname')); |
|
636 | + $GLOBALS['egw']->hooks->single($GLOBALS['hook_values'], self::id2name($cat_id, 'appname')); |
|
637 | 637 | } |
638 | 638 | |
639 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
639 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
640 | 640 | |
641 | 641 | // update cache accordingly |
642 | 642 | self::invalidate_cache($modify_subs ? null : $where['cat_id']); |
@@ -652,17 +652,17 @@ discard block |
||
652 | 652 | */ |
653 | 653 | function adapt_level_in_subtree($values) |
654 | 654 | { |
655 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
655 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
656 | 656 | { |
657 | 657 | if ($cat['parent'] == $values['id']) |
658 | 658 | { |
659 | - $this->db->update(self::TABLE,array( |
|
660 | - 'cat_level' => $values['level']+1, |
|
659 | + $this->db->update(self::TABLE, array( |
|
660 | + 'cat_level' => $values['level'] + 1, |
|
661 | 661 | 'last_mod' => time(), |
662 | - ),array( |
|
662 | + ), array( |
|
663 | 663 | 'cat_id' => $cat['id'], |
664 | 664 | 'cat_appname' => $this->app_name, |
665 | - ),__LINE__,__FILE__); |
|
665 | + ), __LINE__, __FILE__); |
|
666 | 666 | $cat['level'] = $values['level'] + 1; |
667 | 667 | self::invalidate_cache($cat['id']); |
668 | 668 | $this->adapt_level_in_subtree($cat); |
@@ -683,14 +683,14 @@ discard block |
||
683 | 683 | function check_consistency4update($values) |
684 | 684 | { |
685 | 685 | // check if we try to move an element down its own subtree, which will fail |
686 | - foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
686 | + foreach ($this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
687 | 687 | { |
688 | 688 | if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
689 | 689 | } |
690 | 690 | // check if we try to be our own parent |
691 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
691 | + if ($values['parent'] == $values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
692 | 692 | // check if parent still exists |
693 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
693 | + if ((int)$values['parent'] > 0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
694 | 694 | return true; |
695 | 695 | } |
696 | 696 | |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | $ret = $this->check_consistency4update($values); |
710 | 710 | if ($ret !== true) throw new egw_exception_wrong_userinput($ret); |
711 | 711 | // everything seems in order -> proceed |
712 | - $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
|
712 | + $values['level'] = ($values['parent'] ? $this->id2name($values['parent'], 'level') + 1 : 0); |
|
713 | 713 | $this->adapt_level_in_subtree($values); |
714 | 714 | |
715 | 715 | return $this->add($values); |
@@ -723,8 +723,8 @@ discard block |
||
723 | 723 | if ($ret !== true) throw new egw_exception_wrong_userinput($ret); |
724 | 724 | |
725 | 725 | // everything seems in order -> proceed |
726 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
727 | - $values['level'] = $this->id2name($values['parent'],'level') + 1; |
|
726 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
727 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
728 | 728 | } |
729 | 729 | else |
730 | 730 | { |
@@ -735,9 +735,9 @@ discard block |
||
735 | 735 | // adapt the level info in each child |
736 | 736 | $this->adapt_level_in_subtree($values); |
737 | 737 | } |
738 | - $this->db->update(self::TABLE,$cat=array( |
|
738 | + $this->db->update(self::TABLE, $cat = array( |
|
739 | 739 | 'cat_name' => $values['name'], |
740 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
740 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
741 | 741 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
742 | 742 | 'cat_parent' => $values['parent'], |
743 | 743 | 'cat_access' => $values['access'], |
@@ -745,10 +745,10 @@ discard block |
||
745 | 745 | 'cat_main' => $values['main'], |
746 | 746 | 'cat_level' => $values['level'], |
747 | 747 | 'last_mod' => time(), |
748 | - ),array( |
|
748 | + ), array( |
|
749 | 749 | 'cat_id' => $values['id'], |
750 | 750 | 'cat_appname' => $this->app_name, |
751 | - ),__LINE__,__FILE__); |
|
751 | + ), __LINE__, __FILE__); |
|
752 | 752 | |
753 | 753 | $cat['cat_id'] = $values['id']; |
754 | 754 | $cat['cat_appname'] = $this->app_name; |
@@ -772,9 +772,9 @@ discard block |
||
772 | 772 | * @param boolean|string $strip=false if true, strips 'X-' ($strip) from category names added by some SyncML clients |
773 | 773 | * @return int cat-id or 0 if not found |
774 | 774 | */ |
775 | - function name2id($cat_name, $strip=false) |
|
775 | + function name2id($cat_name, $strip = false) |
|
776 | 776 | { |
777 | - static $cache = array(); // a litle bit of caching |
|
777 | + static $cache = array(); // a litle bit of caching |
|
778 | 778 | |
779 | 779 | if (isset($cache[$cat_name])) return $cache[$cat_name]; |
780 | 780 | |
@@ -795,26 +795,26 @@ discard block |
||
795 | 795 | $cats[] = $stripped_cat_name; |
796 | 796 | } |
797 | 797 | |
798 | - if (!($cats = $this->return_array('all',0,false,'','','',true,null,-1,'',array( |
|
798 | + if (!($cats = $this->return_array('all', 0, false, '', '', '', true, null, -1, '', array( |
|
799 | 799 | 'name' => $cats, |
800 | 800 | 'appname' => array($this->app_name, self::GLOBAL_APPNAME), |
801 | 801 | )))) |
802 | 802 | { |
803 | - return 0; // cat not found, dont cache it, as it might be created in this request |
|
803 | + return 0; // cat not found, dont cache it, as it might be created in this request |
|
804 | 804 | } |
805 | 805 | if (count($cats) > 1) |
806 | 806 | { |
807 | 807 | // if more the one cat matches we weight them by: exact name match; own, global, other users cat; appplication cats |
808 | - foreach($cats as $k => $cat) |
|
808 | + foreach ($cats as $k => $cat) |
|
809 | 809 | { |
810 | 810 | $cats[$k]['weight'] = 100 * ($cat['name'] == $cat_name) + |
811 | 811 | 10 * ($cat['owner'] == $this->account_id ? 3 : ($cat['owner'] <= self::GLOBAL_ACCOUNT ? 2 : 1)) + |
812 | 812 | ($cat['appname'] != self::GLOBAL_APPNAME); |
813 | 813 | } |
814 | 814 | // sort heighest weight to the top |
815 | - usort($cats,create_function('$a,$b',"return \$b['weight'] - \$a['weight'];")); |
|
815 | + usort($cats, create_function('$a,$b', "return \$b['weight'] - \$a['weight'];")); |
|
816 | 816 | } |
817 | - return $cache[$cat['cat_name']] = (int) $cats[0]['id']; |
|
817 | + return $cache[$cat['cat_name']] = (int)$cats[0]['id']; |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
@@ -824,12 +824,12 @@ discard block |
||
824 | 824 | * @param boolean $application_global=false true check for application global categories only (appname == 'phpgw') |
825 | 825 | * @return boolean |
826 | 826 | */ |
827 | - static function is_global($cat,$application_global=false) |
|
827 | + static function is_global($cat, $application_global = false) |
|
828 | 828 | { |
829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
829 | + if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
830 | 830 | |
831 | 831 | $global_owner = false; |
832 | - foreach(explode(',',$cat['owner']) as $owner) |
|
832 | + foreach (explode(',', $cat['owner']) as $owner) |
|
833 | 833 | { |
834 | 834 | $global_owner = $global_owner || $owner <= self::GLOBAL_ACCOUNT; |
835 | 835 | } |
@@ -846,9 +846,9 @@ discard block |
||
846 | 846 | * @param string $item='name' requested information, 'path' = / delimited path of category names (incl. parents) |
847 | 847 | * @return string information or '--' if not found or !$cat_id |
848 | 848 | */ |
849 | - static function id2name($cat_id=0, $item='name') |
|
849 | + static function id2name($cat_id = 0, $item = 'name') |
|
850 | 850 | { |
851 | - if(!$cat_id) return '--'; |
|
851 | + if (!$cat_id) return '--'; |
|
852 | 852 | if (!$item) $item = 'parent'; |
853 | 853 | |
854 | 854 | if (is_null(self::$cache)) self::init_cache(); |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | { |
859 | 859 | if ($cat['parent']) |
860 | 860 | { |
861 | - return self::id2name($cat['parent'],'path').' / '.$cat['name']; |
|
861 | + return self::id2name($cat['parent'], 'path').' / '.$cat['name']; |
|
862 | 862 | } |
863 | 863 | $item = 'name'; |
864 | 864 | } |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @param int $parent=0 category id of parent |
888 | 888 | * @return int/boolean cat_id or false if cat not exists |
889 | 889 | */ |
890 | - function exists($type,$cat_name = '',$cat_id = 0,$parent = 0) |
|
890 | + function exists($type, $cat_name = '', $cat_id = 0, $parent = 0) |
|
891 | 891 | { |
892 | 892 | if ($cat_name) |
893 | 893 | { |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | { |
899 | 899 | $filter['id'] = $cat_id; |
900 | 900 | } |
901 | - if (!($cats = $this->return_array($type,0,false,'','','',true,$parent,-1,'id',$filter))) |
|
901 | + if (!($cats = $this->return_array($type, 0, false, '', '', '', true, $parent, -1, 'id', $filter))) |
|
902 | 902 | { |
903 | 903 | $ret = false; |
904 | 904 | } |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | * @param int $to=0 new owner or 0 to delete the cats |
918 | 918 | * @param string $app='' if given only cats matching $app are modifed/deleted |
919 | 919 | */ |
920 | - function change_owner($owner,$to=0,$app='') |
|
920 | + function change_owner($owner, $to = 0, $app = '') |
|
921 | 921 | { |
922 | 922 | $where = array('cat_owner' => $owner); |
923 | 923 | |
@@ -925,11 +925,11 @@ discard block |
||
925 | 925 | |
926 | 926 | if ((int)$to) |
927 | 927 | { |
928 | - $this->db->update(self::TABLE,array('cat_owner' => $to),$where,__LINE__,__FILE__); |
|
928 | + $this->db->update(self::TABLE, array('cat_owner' => $to), $where, __LINE__, __FILE__); |
|
929 | 929 | } |
930 | 930 | else |
931 | 931 | { |
932 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
932 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
933 | 933 | } |
934 | 934 | // update cache accordingly |
935 | 935 | self::invalidate_cache(); |
@@ -947,10 +947,10 @@ discard block |
||
947 | 947 | if (is_null(self::$cache)) |
948 | 948 | { |
949 | 949 | // check if we are already updated to global owner == 0, if not do it now |
950 | - if (!$GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',array('cat_owner'=>'0'),__LINE__,__FILE__)->fetchColumn()) |
|
950 | + if (!$GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', array('cat_owner'=>'0'), __LINE__, __FILE__)->fetchColumn()) |
|
951 | 951 | { |
952 | - $GLOBALS['egw']->db->update(self::TABLE,array('cat_owner'=>'0'),"(cat_owner='-1' OR cat_appname='phpgw')",__LINE__,__FILE__); |
|
953 | - $GLOBALS['egw']->db->insert(self::TABLE,array( |
|
952 | + $GLOBALS['egw']->db->update(self::TABLE, array('cat_owner'=>'0'), "(cat_owner='-1' OR cat_appname='phpgw')", __LINE__, __FILE__); |
|
953 | + $GLOBALS['egw']->db->insert(self::TABLE, array( |
|
954 | 954 | 'cat_main' => 0, |
955 | 955 | 'cat_parent' => 0, |
956 | 956 | 'cat_level' => 0, |
@@ -959,15 +959,15 @@ discard block |
||
959 | 959 | 'cat_name' => 'global=0', |
960 | 960 | 'cat_description' => 'global=0', |
961 | 961 | 'last_mod' => time(), |
962 | - ),false,__LINE__,__FILE__); |
|
962 | + ), false, __LINE__, __FILE__); |
|
963 | 963 | } |
964 | 964 | self::$cache = array(); |
965 | 965 | // read all cats (cant use $this->db!) |
966 | - foreach($GLOBALS['egw']->db->select(self::TABLE,'*',false,__LINE__,__FILE__, |
|
967 | - false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
966 | + foreach ($GLOBALS['egw']->db->select(self::TABLE, '*', false, __LINE__, __FILE__, |
|
967 | + false, 'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
968 | 968 | { |
969 | - $cat = egw_db::strip_array_keys($cat,'cat_'); |
|
970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
969 | + $cat = egw_db::strip_array_keys($cat, 'cat_'); |
|
970 | + if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
971 | 971 | $cat['app_name'] = $cat['appname']; |
972 | 972 | // backlink children to their parent |
973 | 973 | if ($cat['parent']) |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | if (isset(self::$cache[$cat['id']])) |
978 | 978 | { |
979 | 979 | $cat['children'] = self::$cache[$cat['id']]['children']; |
980 | - unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
980 | + unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
981 | 981 | } |
982 | 982 | self::$cache[$cat['id']] = $cat; |
983 | 983 | } |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | * |
995 | 995 | * @param int|array $cat concerned id(s) or array with cat-data or null for all cats |
996 | 996 | */ |
997 | - public static function invalidate_cache($cat=null) |
|
997 | + public static function invalidate_cache($cat = null) |
|
998 | 998 | { |
999 | 999 | //error_log(__METHOD__."(".array2string($cat).') '.function_backtrace()); |
1000 | 1000 | |
@@ -1006,12 +1006,12 @@ discard block |
||
1006 | 1006 | { |
1007 | 1007 | if (!is_array($cat) || isset($cat[0])) |
1008 | 1008 | { |
1009 | - foreach((array)$cat as $cat_id) |
|
1009 | + foreach ((array)$cat as $cat_id) |
|
1010 | 1010 | { |
1011 | 1011 | unset(self::$cache[$cat_id]); |
1012 | 1012 | } |
1013 | 1013 | } |
1014 | - elseif($cat['id']) |
|
1014 | + elseif ($cat['id']) |
|
1015 | 1015 | { |
1016 | 1016 | self::$cache[$cat['id']] = $cat; |
1017 | 1017 | } |
@@ -1034,8 +1034,8 @@ discard block |
||
1034 | 1034 | */ |
1035 | 1035 | public static function css($appname) |
1036 | 1036 | { |
1037 | - $cats = new categories('',$appname); |
|
1038 | - $last_mod = $cats->return_array('all',0,1,'','DESC','last_mod', $appname == self::GLOBAL_APPNAME); |
|
1037 | + $cats = new categories('', $appname); |
|
1038 | + $last_mod = $cats->return_array('all', 0, 1, '', 'DESC', 'last_mod', $appname == self::GLOBAL_APPNAME); |
|
1039 | 1039 | $time = count($last_mod) ? $last_mod[0]['last_mod'] : time(); |
1040 | 1040 | $path = '/phpgwapi/categories.php?app='.$appname.'&'.$time; |
1041 | 1041 | egw_framework::includeCSS($path); |
@@ -1050,13 +1050,13 @@ discard block |
||
1050 | 1050 | * @param int $new_owner=null for users data can be transfered to new owner |
1051 | 1051 | * @return int number of deleted or modified categories |
1052 | 1052 | */ |
1053 | - public static function delete_account($account_id, $new_owner=null) |
|
1053 | + public static function delete_account($account_id, $new_owner = null) |
|
1054 | 1054 | { |
1055 | 1055 | if (is_null(self::$cache)) self::init_cache(); |
1056 | 1056 | |
1057 | 1057 | $deleted = 0; |
1058 | 1058 | $cat = null; |
1059 | - foreach(self::$cache as $cat_id => $data) |
|
1059 | + foreach (self::$cache as $cat_id => $data) |
|
1060 | 1060 | { |
1061 | 1061 | if ($data['owner'] && ($owners = explode(',', $data['owner'])) && ($owner_key = array_search($account_id, $owners)) !== false) |
1062 | 1062 | { |
@@ -1098,9 +1098,9 @@ discard block |
||
1098 | 1098 | |
1099 | 1099 | $checked = array(); |
1100 | 1100 | $deleted = 0; |
1101 | - foreach(self::$cache as $data) |
|
1101 | + foreach (self::$cache as $data) |
|
1102 | 1102 | { |
1103 | - foreach(explode(',', $data['owner']) as $owner) |
|
1103 | + foreach (explode(',', $data['owner']) as $owner) |
|
1104 | 1104 | { |
1105 | 1105 | if ($owner && !in_array($owner, $checked)) |
1106 | 1106 | { |
@@ -1145,37 +1145,37 @@ discard block |
||
1145 | 1145 | * @deprecated use html class to create selectboxes |
1146 | 1146 | * @return string populated with categories |
1147 | 1147 | */ |
1148 | - function formatted_list($format,$type='',$selected = '',$globals = False,$site_link = 'site') |
|
1148 | + function formatted_list($format, $type = '', $selected = '', $globals = False, $site_link = 'site') |
|
1149 | 1149 | { |
1150 | - if(is_array($format)) |
|
1150 | + if (is_array($format)) |
|
1151 | 1151 | { |
1152 | - $type = ($format['type']?$format['type']:'all'); |
|
1153 | - $selected = (isset($format['selected'])?$format['selected']:''); |
|
1154 | - $self = (isset($format['self'])?$format['self']:''); |
|
1155 | - $globals = (isset($format['globals'])?$format['globals']:True); |
|
1156 | - $site_link = (isset($format['site_link'])?$format['site_link']:'site'); |
|
1152 | + $type = ($format['type'] ? $format['type'] : 'all'); |
|
1153 | + $selected = (isset($format['selected']) ? $format['selected'] : ''); |
|
1154 | + $self = (isset($format['self']) ? $format['self'] : ''); |
|
1155 | + $globals = (isset($format['globals']) ? $format['globals'] : True); |
|
1156 | + $site_link = (isset($format['site_link']) ? $format['site_link'] : 'site'); |
|
1157 | 1157 | $format = $format['format'] ? $format['format'] : 'select'; |
1158 | 1158 | } |
1159 | 1159 | |
1160 | 1160 | if (!is_array($selected)) |
1161 | 1161 | { |
1162 | - $selected = explode(',',$selected); |
|
1162 | + $selected = explode(',', $selected); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | if ($type != 'all') |
1166 | 1166 | { |
1167 | - $cats = $this->return_array($type,0,False,'','','',$globals); |
|
1167 | + $cats = $this->return_array($type, 0, False, '', '', '', $globals); |
|
1168 | 1168 | } |
1169 | 1169 | else |
1170 | 1170 | { |
1171 | - $cats = $this->return_sorted_array(0,False,'','','',$globals); |
|
1171 | + $cats = $this->return_sorted_array(0, False, '', '', '', $globals); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | if (!$cats) return ''; |
1175 | 1175 | |
1176 | - if($self) |
|
1176 | + if ($self) |
|
1177 | 1177 | { |
1178 | - foreach($cats as $key => $cat) |
|
1178 | + foreach ($cats as $key => $cat) |
|
1179 | 1179 | { |
1180 | 1180 | if ($cat['id'] == $self) |
1181 | 1181 | { |
@@ -1187,50 +1187,50 @@ discard block |
||
1187 | 1187 | switch ($format) |
1188 | 1188 | { |
1189 | 1189 | case 'select': |
1190 | - foreach($cats as $cat) |
|
1190 | + foreach ($cats as $cat) |
|
1191 | 1191 | { |
1192 | - $s .= '<option value="' . $cat['id'] . '"'; |
|
1193 | - if (in_array($cat['id'],$selected)) |
|
1192 | + $s .= '<option value="'.$cat['id'].'"'; |
|
1193 | + if (in_array($cat['id'], $selected)) |
|
1194 | 1194 | { |
1195 | 1195 | $s .= ' selected="selected"'; |
1196 | 1196 | } |
1197 | - $s .= '>'.str_repeat(' ',$cat['level']); |
|
1197 | + $s .= '>'.str_repeat(' ', $cat['level']); |
|
1198 | 1198 | $s .= $GLOBALS['egw']->strip_html($cat['name']); |
1199 | 1199 | if (self::is_global($cat)) |
1200 | 1200 | { |
1201 | 1201 | $s .= self::$global_marker; |
1202 | 1202 | } |
1203 | - $s .= '</option>' . "\n"; |
|
1203 | + $s .= '</option>'."\n"; |
|
1204 | 1204 | } |
1205 | 1205 | break; |
1206 | 1206 | |
1207 | 1207 | case 'list': |
1208 | 1208 | $space = ' '; |
1209 | 1209 | |
1210 | - $s = '<table border="0" cellpadding="2" cellspacing="2">' . "\n"; |
|
1210 | + $s = '<table border="0" cellpadding="2" cellspacing="2">'."\n"; |
|
1211 | 1211 | |
1212 | - foreach($cats as $cat) |
|
1212 | + foreach ($cats as $cat) |
|
1213 | 1213 | { |
1214 | 1214 | $image_set = ' '; |
1215 | 1215 | |
1216 | - if (in_array($cat['id'],$selected)) |
|
1216 | + if (in_array($cat['id'], $selected)) |
|
1217 | 1217 | { |
1218 | - $image_set = '<img src="' . EGW_IMAGES_DIR . '/roter_pfeil.gif">'; |
|
1218 | + $image_set = '<img src="'.EGW_IMAGES_DIR.'/roter_pfeil.gif">'; |
|
1219 | 1219 | } |
1220 | - if (($cat['level'] == 0) && !in_array($cat['id'],$selected)) |
|
1220 | + if (($cat['level'] == 0) && !in_array($cat['id'], $selected)) |
|
1221 | 1221 | { |
1222 | - $image_set = '<img src="' . EGW_IMAGES_DIR . '/grauer_pfeil.gif">'; |
|
1222 | + $image_set = '<img src="'.EGW_IMAGES_DIR.'/grauer_pfeil.gif">'; |
|
1223 | 1223 | } |
1224 | - $space_set = str_repeat($space,$cat['level']); |
|
1224 | + $space_set = str_repeat($space, $cat['level']); |
|
1225 | 1225 | |
1226 | - $s .= '<tr>' . "\n"; |
|
1227 | - $s .= '<td width="8">' . $image_set . '</td>' . "\n"; |
|
1228 | - $s .= '<td>' . $space_set . '<a href="' . $GLOBALS['egw']->link($site_link,'cat_id=' . $cat['id']) . '">' |
|
1226 | + $s .= '<tr>'."\n"; |
|
1227 | + $s .= '<td width="8">'.$image_set.'</td>'."\n"; |
|
1228 | + $s .= '<td>'.$space_set.'<a href="'.$GLOBALS['egw']->link($site_link, 'cat_id='.$cat['id']).'">' |
|
1229 | 1229 | . $GLOBALS['egw']->strip_html($cat['name']) |
1230 | - . '</a></td>' . "\n" |
|
1231 | - . '</tr>' . "\n"; |
|
1230 | + . '</a></td>'."\n" |
|
1231 | + . '</tr>'."\n"; |
|
1232 | 1232 | } |
1233 | - $s .= '</table>' . "\n"; |
|
1233 | + $s .= '</table>'."\n"; |
|
1234 | 1234 | break; |
1235 | 1235 | } |
1236 | 1236 | return $s; |
@@ -120,7 +120,10 @@ discard block |
||
120 | 120 | */ |
121 | 121 | function __construct($accountid='',$app_name = '') |
122 | 122 | { |
123 | - if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
123 | + if (!$app_name) |
|
124 | + { |
|
125 | + $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
126 | + } |
|
124 | 127 | |
125 | 128 | if ($accountid === self::GLOBAL_ACCOUNT || |
126 | 129 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
@@ -136,10 +139,13 @@ discard block |
||
136 | 139 | $this->app_name = $app_name; |
137 | 140 | $this->db = $GLOBALS['egw']->db; |
138 | 141 | |
139 | - if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
|
142 | + if (is_null(self::$cache)) |
|
143 | + { |
|
144 | + // should not be necessary, as cache is load and restored by egw object |
|
140 | 145 | { |
141 | 146 | self::init_cache(); |
142 | 147 | } |
148 | + } |
|
143 | 149 | if (is_null(self::$global_marker)) |
144 | 150 | { |
145 | 151 | // as et2 adds options with .text(), it can't be entities, but php knows no string literals with utf-8 |
@@ -198,7 +204,9 @@ discard block |
||
198 | 204 | $cats = array(); |
199 | 205 | foreach(self::$cache as $cat) |
200 | 206 | { |
201 | - if ($filter) foreach($filter as $col => $val) |
|
207 | + if ($filter) |
|
208 | + { |
|
209 | + foreach($filter as $col => $val) |
|
202 | 210 | { |
203 | 211 | if (!is_array($val) && $val[0] === '!') |
204 | 212 | { |
@@ -206,10 +214,14 @@ discard block |
||
206 | 214 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
207 | 215 | { |
208 | 216 | if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
217 | + } |
|
209 | 218 | } |
210 | 219 | else |
211 | 220 | { |
212 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
221 | + if ($cat[$col] == substr($val,1)) |
|
222 | + { |
|
223 | + continue 2; |
|
224 | + } |
|
213 | 225 | } |
214 | 226 | } |
215 | 227 | elseif (is_array($val)) |
@@ -217,11 +229,17 @@ discard block |
||
217 | 229 | // also match against trimmed database entry on name and description fields |
218 | 230 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
219 | 231 | { |
220 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
232 | + if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) |
|
233 | + { |
|
234 | + continue 2; |
|
235 | + } |
|
221 | 236 | } |
222 | 237 | else |
223 | 238 | { |
224 | - if (!in_array($cat[$col],$val)) continue 2; |
|
239 | + if (!in_array($cat[$col],$val)) |
|
240 | + { |
|
241 | + continue 2; |
|
242 | + } |
|
225 | 243 | } |
226 | 244 | } |
227 | 245 | else |
@@ -229,16 +247,25 @@ discard block |
||
229 | 247 | // also match against trimmed database entry on name and description fields |
230 | 248 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
231 | 249 | { |
232 | - if ($cat[$col] != $val && trim($cat[$col]) != $val) continue 2; |
|
250 | + if ($cat[$col] != $val && trim($cat[$col]) != $val) |
|
251 | + { |
|
252 | + continue 2; |
|
253 | + } |
|
233 | 254 | } |
234 | 255 | else |
235 | 256 | { |
236 | - if ($cat[$col] != $val) continue 2; |
|
257 | + if ($cat[$col] != $val) |
|
258 | + { |
|
259 | + continue 2; |
|
260 | + } |
|
237 | 261 | } |
238 | 262 | } |
239 | 263 | } |
240 | 264 | // check if certain parent required |
241 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
265 | + if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) |
|
266 | + { |
|
267 | + continue; |
|
268 | + } |
|
242 | 269 | |
243 | 270 | // return global categories just if $globals is set |
244 | 271 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -256,30 +283,55 @@ discard block |
||
256 | 283 | switch ($type) |
257 | 284 | { |
258 | 285 | case 'subs': |
259 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
286 | + if (!$cat['parent']) |
|
287 | + { |
|
288 | + continue 2; |
|
289 | + } |
|
290 | + // 2 for switch AND foreach! |
|
260 | 291 | break; |
261 | 292 | case 'mains': |
262 | - if ($cat['parent']) continue 2; |
|
293 | + if ($cat['parent']) |
|
294 | + { |
|
295 | + continue 2; |
|
296 | + } |
|
263 | 297 | break; |
264 | 298 | case 'appandmains': |
265 | - if ($cat['appname'] != $this->app_name || $cat['parent']) continue 2; |
|
299 | + if ($cat['appname'] != $this->app_name || $cat['parent']) |
|
300 | + { |
|
301 | + continue 2; |
|
302 | + } |
|
266 | 303 | break; |
267 | 304 | case 'appandsubs': |
268 | - if ($cat['appname'] != $this->app_name || !$cat['parent']) continue 2; |
|
305 | + if ($cat['appname'] != $this->app_name || !$cat['parent']) |
|
306 | + { |
|
307 | + continue 2; |
|
308 | + } |
|
269 | 309 | break; |
270 | 310 | case 'noglobal': |
271 | - if ($cat['appname'] == $this->app_name) continue 2; |
|
311 | + if ($cat['appname'] == $this->app_name) |
|
312 | + { |
|
313 | + continue 2; |
|
314 | + } |
|
272 | 315 | break; |
273 | 316 | case 'noglobalapp': |
274 | - if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) continue 2; |
|
317 | + if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) |
|
318 | + { |
|
319 | + continue 2; |
|
320 | + } |
|
275 | 321 | break; |
276 | 322 | } |
277 | 323 | |
278 | 324 | // check name and description for $query |
279 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
325 | + if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) |
|
326 | + { |
|
327 | + continue; |
|
328 | + } |
|
280 | 329 | |
281 | 330 | // check if last modified since |
282 | - if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
|
331 | + if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) |
|
332 | + { |
|
333 | + continue; |
|
334 | + } |
|
283 | 335 | |
284 | 336 | $cat['data'] = $cat['data'] ? json_php_unserialize($cat['data'], true) : array(); |
285 | 337 | |
@@ -290,13 +342,23 @@ discard block |
||
290 | 342 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=$parent_id,$lastmod,$column) account_id=$this->account_id, appname=$this->app_name = FALSE"); |
291 | 343 | return array(); |
292 | 344 | } |
293 | - if (!$sort) $sort = 'ASC'; |
|
345 | + if (!$sort) |
|
346 | + { |
|
347 | + $sort = 'ASC'; |
|
348 | + } |
|
294 | 349 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
295 | 350 | if ($this->total_records > 1 && !empty($order) && |
296 | 351 | preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
297 | 352 | { |
298 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
299 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
353 | + if (strstr($order,'cat_data') !== false) |
|
354 | + { |
|
355 | + $order = 'cat_data'; |
|
356 | + } |
|
357 | + // sitemgr orders by round(cat_data)! |
|
358 | + if (substr($order,0,4) == 'cat_') |
|
359 | + { |
|
360 | + $order = substr($order,4); |
|
361 | + } |
|
300 | 362 | $sign = strtoupper($sort) == 'DESC' ? '-' : ''; |
301 | 363 | usort($cats,create_function('$a,$b',$func=(in_array($order,array('name','description','appname','app_name')) ? |
302 | 364 | "return ${sign}strcasecmp(\$a['$order'],\$b['$order']);" : "return $sign(int)\$a['$order'] - $sign(int)\$b['$order'];"))); |
@@ -304,7 +366,10 @@ discard block |
||
304 | 366 | // limit the number of returned rows |
305 | 367 | if ($limit) |
306 | 368 | { |
307 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
369 | + if (!is_int($limit)) |
|
370 | + { |
|
371 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
372 | + } |
|
308 | 373 | $cats = array_slice($cats,(int)$start,$limit); |
309 | 374 | } |
310 | 375 | // return only a certain column (why not return is as value?) |
@@ -337,15 +402,24 @@ discard block |
||
337 | 402 | */ |
338 | 403 | function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
339 | 404 | { |
340 | - if (!$sort) $sort = 'ASC'; |
|
341 | - if (!$order) $order = 'cat_name'; |
|
405 | + if (!$sort) |
|
406 | + { |
|
407 | + $sort = 'ASC'; |
|
408 | + } |
|
409 | + if (!$order) |
|
410 | + { |
|
411 | + $order = 'cat_name'; |
|
412 | + } |
|
342 | 413 | |
343 | 414 | //error_log(__METHOD__."($start,$limit,$query,$sort,$order,globals=$globals,parent=$parent_id,$unserialize_data) account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
344 | 415 | |
345 | 416 | $parents = $cats = array(); |
346 | 417 | |
347 | 418 | // Cast parent_id to array, but only if there is one |
348 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
419 | + if($parent_id !== false && $parent_id !== null) |
|
420 | + { |
|
421 | + $parent_id = (array)$parent_id; |
|
422 | + } |
|
349 | 423 | if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
350 | 424 | { |
351 | 425 | $cats = array(); |
@@ -355,7 +429,9 @@ discard block |
||
355 | 429 | $parents[] = $cat['id']; |
356 | 430 | } |
357 | 431 | |
358 | - if($parent_id || !$cats) // Avoid wiping search results |
|
432 | + if($parent_id || !$cats) |
|
433 | + { |
|
434 | + // Avoid wiping search results |
|
359 | 435 | { |
360 | 436 | // Go find the children |
361 | 437 | while (count($parents)) |
@@ -363,6 +439,7 @@ discard block |
||
363 | 439 | if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
364 | 440 | { |
365 | 441 | break; |
442 | + } |
|
366 | 443 | } |
367 | 444 | $parents = $children = array(); |
368 | 445 | foreach($subs as $cat) |
@@ -394,7 +471,10 @@ discard block |
||
394 | 471 | // limit the number of returned rows |
395 | 472 | if ($limit) |
396 | 473 | { |
397 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
474 | + if (!is_int($limit)) |
|
475 | + { |
|
476 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
477 | + } |
|
398 | 478 | $cats = array_slice($cats,(int)$start,$limit); |
399 | 479 | } |
400 | 480 | reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
@@ -413,9 +493,15 @@ discard block |
||
413 | 493 | */ |
414 | 494 | static function read($id) |
415 | 495 | { |
416 | - if (is_null(self::$cache)) self::init_cache(); |
|
496 | + if (is_null(self::$cache)) |
|
497 | + { |
|
498 | + self::init_cache(); |
|
499 | + } |
|
417 | 500 | |
418 | - if (!isset(self::$cache[$id])) return false; |
|
501 | + if (!isset(self::$cache[$id])) |
|
502 | + { |
|
503 | + return false; |
|
504 | + } |
|
419 | 505 | |
420 | 506 | $cat = self::$cache[$id]; |
421 | 507 | $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
@@ -478,8 +564,11 @@ discard block |
||
478 | 564 | * @return string truncated commaseparated list of category ids |
479 | 565 | */ |
480 | 566 | function check_list($needed, $cat_list) |
481 | - { |
|
482 | - if (empty($cat_list)) return $cat_list; |
|
567 | + { |
|
568 | + if (empty($cat_list)) |
|
569 | + { |
|
570 | + return $cat_list; |
|
571 | + } |
|
483 | 572 | if (is_array($cat_list)) |
484 | 573 | { |
485 | 574 | $cat_list = implode(',',$cat_list); |
@@ -490,10 +579,13 @@ discard block |
||
490 | 579 | { |
491 | 580 | foreach($cat_arr as $id=>$cat_id) |
492 | 581 | { |
493 | - if (!$this->check_perms($needed, $cat_id, false, $needed == EGW_ACL_READ)) // allow reading all global cats |
|
582 | + if (!$this->check_perms($needed, $cat_id, false, $needed == EGW_ACL_READ)) |
|
583 | + { |
|
584 | + // allow reading all global cats |
|
494 | 585 | { |
495 | 586 | unset($cat_arr[$id]); |
496 | 587 | } |
588 | + } |
|
497 | 589 | } |
498 | 590 | $cat_list = implode(',',$cat_arr); |
499 | 591 | } |
@@ -599,9 +691,15 @@ discard block |
||
599 | 691 | { |
600 | 692 | $update = array('cat_level' => $cat['level']-1); |
601 | 693 | |
602 | - if ($new_main) $update['cat_main'] = $new_main; |
|
694 | + if ($new_main) |
|
695 | + { |
|
696 | + $update['cat_main'] = $new_main; |
|
697 | + } |
|
603 | 698 | |
604 | - if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
|
699 | + if ($cat['parent'] == $cat_id) |
|
700 | + { |
|
701 | + $update['cat_parent'] = $new_parent; |
|
702 | + } |
|
605 | 703 | |
606 | 704 | $this->db->update(self::TABLE,$update,array( |
607 | 705 | 'cat_id' => $cat['id'], |
@@ -627,9 +725,13 @@ discard block |
||
627 | 725 | 'modify_subs' => $modify_subs, |
628 | 726 | 'location' => 'delete_category' |
629 | 727 | ); |
630 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
728 | + if($this->is_global($cat_id, true)) |
|
729 | + { |
|
730 | + // true = application global (otherwise eg. global addressbook categories call all apps) |
|
631 | 731 | { |
632 | - $GLOBALS['egw']->hooks->process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
732 | + $GLOBALS['egw']->hooks->process($GLOBALS['hook_values'],False,True); |
|
733 | + } |
|
734 | + // called for every app now, not only enabled ones) |
|
633 | 735 | } |
634 | 736 | else |
635 | 737 | { |
@@ -685,12 +787,22 @@ discard block |
||
685 | 787 | // check if we try to move an element down its own subtree, which will fail |
686 | 788 | foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
687 | 789 | { |
688 | - if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
790 | + if ($cat['id'] == $values['parent']) |
|
791 | + { |
|
792 | + return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
793 | + } |
|
689 | 794 | } |
690 | 795 | // check if we try to be our own parent |
691 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
796 | + if ($values['parent']==$values['id']) |
|
797 | + { |
|
798 | + return lang('Cannot set this cat as its own parent!'); |
|
799 | + } |
|
800 | + // deny to be our own parent |
|
692 | 801 | // check if parent still exists |
693 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
802 | + if ((int)$values['parent']>0 && !$this->read($values['parent'])) |
|
803 | + { |
|
804 | + return lang('Chosen parent category no longer exists'); |
|
805 | + } |
|
694 | 806 | return true; |
695 | 807 | } |
696 | 808 | |
@@ -707,7 +819,10 @@ discard block |
||
707 | 819 | if (isset($values['old_parent']) && (int)$values['old_parent'] != (int)$values['parent']) |
708 | 820 | { |
709 | 821 | $ret = $this->check_consistency4update($values); |
710 | - if ($ret !== true) throw new egw_exception_wrong_userinput($ret); |
|
822 | + if ($ret !== true) |
|
823 | + { |
|
824 | + throw new egw_exception_wrong_userinput($ret); |
|
825 | + } |
|
711 | 826 | // everything seems in order -> proceed |
712 | 827 | $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
713 | 828 | $this->adapt_level_in_subtree($values); |
@@ -720,7 +835,10 @@ discard block |
||
720 | 835 | if ($values['parent'] > 0) |
721 | 836 | { |
722 | 837 | $ret = $this->check_consistency4update($values); |
723 | - if ($ret !== true) throw new egw_exception_wrong_userinput($ret); |
|
838 | + if ($ret !== true) |
|
839 | + { |
|
840 | + throw new egw_exception_wrong_userinput($ret); |
|
841 | + } |
|
724 | 842 | |
725 | 843 | // everything seems in order -> proceed |
726 | 844 | $values['main'] = $this->id2name($values['parent'],'main'); |
@@ -776,7 +894,10 @@ discard block |
||
776 | 894 | { |
777 | 895 | static $cache = array(); // a litle bit of caching |
778 | 896 | |
779 | - if (isset($cache[$cat_name])) return $cache[$cat_name]; |
|
897 | + if (isset($cache[$cat_name])) |
|
898 | + { |
|
899 | + return $cache[$cat_name]; |
|
900 | + } |
|
780 | 901 | |
781 | 902 | if ($strip === true) |
782 | 903 | { |
@@ -826,7 +947,11 @@ discard block |
||
826 | 947 | */ |
827 | 948 | static function is_global($cat,$application_global=false) |
828 | 949 | { |
829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
950 | + if (!is_array($cat) && !($cat = self::read($cat))) |
|
951 | + { |
|
952 | + return null; |
|
953 | + } |
|
954 | + // cat not found |
|
830 | 955 | |
831 | 956 | $global_owner = false; |
832 | 957 | foreach(explode(',',$cat['owner']) as $owner) |
@@ -848,10 +973,19 @@ discard block |
||
848 | 973 | */ |
849 | 974 | static function id2name($cat_id=0, $item='name') |
850 | 975 | { |
851 | - if(!$cat_id) return '--'; |
|
852 | - if (!$item) $item = 'parent'; |
|
976 | + if(!$cat_id) |
|
977 | + { |
|
978 | + return '--'; |
|
979 | + } |
|
980 | + if (!$item) |
|
981 | + { |
|
982 | + $item = 'parent'; |
|
983 | + } |
|
853 | 984 | |
854 | - if (is_null(self::$cache)) self::init_cache(); |
|
985 | + if (is_null(self::$cache)) |
|
986 | + { |
|
987 | + self::init_cache(); |
|
988 | + } |
|
855 | 989 | |
856 | 990 | $cat = self::$cache[$cat_id]; |
857 | 991 | if ($item == 'path') |
@@ -892,7 +1026,10 @@ discard block |
||
892 | 1026 | if ($cat_name) |
893 | 1027 | { |
894 | 1028 | $filter['name'] = $cat_name; |
895 | - if ($cat_id) $filter['id'] = '!'.(int)$cat_id; |
|
1029 | + if ($cat_id) |
|
1030 | + { |
|
1031 | + $filter['id'] = '!'.(int)$cat_id; |
|
1032 | + } |
|
896 | 1033 | } |
897 | 1034 | elseif ($cat_id) |
898 | 1035 | { |
@@ -921,7 +1058,10 @@ discard block |
||
921 | 1058 | { |
922 | 1059 | $where = array('cat_owner' => $owner); |
923 | 1060 | |
924 | - if ($app) $where['cat_appname'] = $app; |
|
1061 | + if ($app) |
|
1062 | + { |
|
1063 | + $where['cat_appname'] = $app; |
|
1064 | + } |
|
925 | 1065 | |
926 | 1066 | if ((int)$to) |
927 | 1067 | { |
@@ -967,7 +1107,11 @@ discard block |
||
967 | 1107 | false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
968 | 1108 | { |
969 | 1109 | $cat = egw_db::strip_array_keys($cat,'cat_'); |
970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
1110 | + if ($cat['appname'] == '*update*') |
|
1111 | + { |
|
1112 | + continue; |
|
1113 | + } |
|
1114 | + // --> ignore update marker |
|
971 | 1115 | $cat['app_name'] = $cat['appname']; |
972 | 1116 | // backlink children to their parent |
973 | 1117 | if ($cat['parent']) |
@@ -1052,7 +1196,10 @@ discard block |
||
1052 | 1196 | */ |
1053 | 1197 | public static function delete_account($account_id, $new_owner=null) |
1054 | 1198 | { |
1055 | - if (is_null(self::$cache)) self::init_cache(); |
|
1199 | + if (is_null(self::$cache)) |
|
1200 | + { |
|
1201 | + self::init_cache(); |
|
1202 | + } |
|
1056 | 1203 | |
1057 | 1204 | $deleted = 0; |
1058 | 1205 | $cat = null; |
@@ -1072,7 +1219,10 @@ discard block |
||
1072 | 1219 | else |
1073 | 1220 | { |
1074 | 1221 | unset($owners[$owner_key]); |
1075 | - if ($new_owner && $account_id > 0) $owners[] = $new_owner; |
|
1222 | + if ($new_owner && $account_id > 0) |
|
1223 | + { |
|
1224 | + $owners[] = $new_owner; |
|
1225 | + } |
|
1076 | 1226 | $data['owner'] = implode(',', $owners); |
1077 | 1227 | // app_name have to match cat to update! |
1078 | 1228 | if (!isset($cat) || $cat->app_name != $data['appname']) |
@@ -1094,7 +1244,10 @@ discard block |
||
1094 | 1244 | */ |
1095 | 1245 | public static function delete_orphans() |
1096 | 1246 | { |
1097 | - if (is_null(self::$cache)) self::init_cache(); |
|
1247 | + if (is_null(self::$cache)) |
|
1248 | + { |
|
1249 | + self::init_cache(); |
|
1250 | + } |
|
1098 | 1251 | |
1099 | 1252 | $checked = array(); |
1100 | 1253 | $deleted = 0; |
@@ -1130,7 +1283,10 @@ discard block |
||
1130 | 1283 | */ |
1131 | 1284 | static function return_single($id) |
1132 | 1285 | { |
1133 | - if (is_null(self::$cache)) self::init_cache(); |
|
1286 | + if (is_null(self::$cache)) |
|
1287 | + { |
|
1288 | + self::init_cache(); |
|
1289 | + } |
|
1134 | 1290 | |
1135 | 1291 | return isset(self::$cache[$id]) ? array(self::$cache[$id]) : false; |
1136 | 1292 | } |
@@ -1171,7 +1327,10 @@ discard block |
||
1171 | 1327 | $cats = $this->return_sorted_array(0,False,'','','',$globals); |
1172 | 1328 | } |
1173 | 1329 | |
1174 | - if (!$cats) return ''; |
|
1330 | + if (!$cats) |
|
1331 | + { |
|
1332 | + return ''; |
|
1333 | + } |
|
1175 | 1334 | |
1176 | 1335 | if($self) |
1177 | 1336 | { |