diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 26aa7640..c86374e3 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -192,8 +192,8 @@ function RndInt($Format){ /* Whis function will return the quotas from the specified user If empty only filesystems with enabled quotas are returned -* $users = array of account objects. If $user is a string (user or group) -* an array with all quota-enabled partitions will be returned in this case all returned values are 0 exept mointpoint[x][0] +* $users = array of account objects. +* An array with all quota-enabled partitions will be returned in this case all returned values are 0 exept mointpoint[x][0] */ function getquotas($users) { // define new object @@ -258,38 +258,42 @@ function getquotas($users) { * mountpoint, used blocks, soft block limit, hard block limit, grace block period, used inodes, * soft inode limit, hard inode limit, grace inode period */ - for ($i=0; $iquota[$j][$k] = $single_quota[$k]; - if ($return[$i]->quota[$j][4]quota[$j][4] = ''; - else $return[$i]->quota[$j][4] = strval(($return[$i]->quota[$j][4]-time())/3600) .' '. _('hours'); - if ($return[$i]->quota[$j][8]quota[$j][8] = ''; - else $return[$i]->quota[$j][8] = strval(($return[$i]->quota[$j][8]-time())/3600) .' '. _('hours'); + if (is_array($output_array)) { + for ($i=0; $iquota[$j][$k] = $single_quota[$k]; + if ($return[$i]->quota[$j][4]quota[$j][4] = ''; + else $return[$i]->quota[$j][4] = strval(($return[$i]->quota[$j][4]-time())/3600) .' '. _('hours'); + if ($return[$i]->quota[$j][8]quota[$j][8] = ''; + else $return[$i]->quota[$j][8] = strval(($return[$i]->quota[$j][8]-time())/3600) .' '. _('hours'); + } + $j=0; + while (isset($return[$i]->quota[$j][0])) + // remove invalid quotas + if (!in_array($return[$i]->quota[$j][0], $real_quotas)) unset($return[$i]->quota[$j]); + else $j++; + // Beautify array, repair index + if (is_array($return[$i]->quota)) $return[$i]->quota = array_values($return[$i]->quota); } - $j=0; - while (isset($return[$i]->quota[$j][0])) - // remove invalid quotas - if (!in_array($return[$i]->quota[$j][0], $real_quotas)) unset($return[$i]->quota[$j]); - else $j++; - // Beautify array, repair index - $return[$i]->quota = array_values($return[$i]->quota); + return $return; + } + else { + return -1; } - return $return; } - /* Whis function will set the quotas from the specified user. * $values2 = array of object account with quotas which should be set * $values2_old = array of object account if set values and values_old will be compared. Quota will only be changed * if values differ */ -function setquotas($values2,$values2_old=false) { +function setquotas($values2) { // get username and password of the current lam-admin $ldap_q = $_SESSION['ldap']->decrypt(); /* $towrite has the following syntax: @@ -1745,6 +1749,13 @@ function modifyuser($values,$values_old,$uselamdaemon=true) { // Will modify the if (($values->personal_employeeType != $values_old->personal_employeeType) && ($values->personal_employeeType=='')) $attr_rem['employeeType'] = utf8_encode($values_old->personal_employeeType); + if (($values->general_uidNumber != $values_old->general_uidNumber) && $_SESSION['config']->scriptServer) { + // Remove old quotas + remquotas(array($values_old->general_username), "user"); + // Remove quotas from $values_old because we have to rewrite them all + unset ($values_old->quota); + } + if ($values->general_dn != $values_old->general_dn) { // Account should be moved to a new location // Load old account @@ -1829,8 +1840,8 @@ function modifyuser($values,$values_old,$uselamdaemon=true) { // Will modify the } // Change quotas if quotas are set and lamdaemon.pl should be used - if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon) - setquotas(array($values),array($values_old)); + if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon && ($values->quota != $values_old->quota)) + setquotas(array($values)); //make required changes in cache-array if ((isset($_SESSION['userDN']))) { if ($values->general_dn != $values_old->general_dn) { @@ -2246,6 +2257,13 @@ function modifygroup($values,$values_old, $uselamdaemon=true) { if (count($values->unix_memberUid)==0) $attr_rem['memberUid'] = $values_old->unix_memberUid; else $attr['memberUid'] = $values->unix_memberUid; } + // Rewrite quotas if uidnumbers has changed + if ($values->general_uidNumber != $values_old->general_uidNumber && $_SESSION['config']->scriptServer) { + // Remove old quotas + remquotas(array($values_old->general_username), "user"); + // Remove quotas from $values_old because we have to rewrite them all + unset ($values_old->quota); + } if ($values->general_dn != $values_old->general_dn) { // Account should be moved to a new location @@ -2302,7 +2320,8 @@ function modifygroup($values,$values_old, $uselamdaemon=true) { } // Change quotas if quotas are set and lamdaemon.pl should be used - if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon) setquotas(array($values),array($values_old)); + if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon && ($values->quota != $values_old->quota)) + setquotas(array($values)); //make required changes in cache-array if ((isset($_SESSION['groupDN']))) { if ($values->general_dn != $values_old->general_dn) { diff --git a/lam/templates/account/groupedit.php b/lam/templates/account/groupedit.php index 4b7a4a12..019d9ecf 100644 --- a/lam/templates/account/groupedit.php +++ b/lam/templates/account/groupedit.php @@ -110,7 +110,12 @@ else if (count($_POST)==0) { else $j++; } // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota); + // Set used blocks + for ($i=0; $iquota); $i++) { + $account_new->quota[$i][1] = 0; + $account_new->quota[$i][5] = 0; + } } // Display general-page $select_local = 'general'; @@ -272,7 +277,7 @@ switch ($_POST['select']) { // Load quotas if not yet done because they are needed for the pdf-file if ($config_intern->scriptServer && !isset($account_new->quota[0])) { // load quotas $quotas = getquotas(array($account_old)); - $account_new = $quotas[0]; + $account_new->quota = $quotas[0]->quota; } // Create / display PDf-file createGroupPDF(array($account_new)); @@ -398,7 +403,22 @@ do { // X-Or, only one if() can be true else $j++; } // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota); + // Set used blocks + if (isset($account_old)) { + for ($i=0; $iquota); $i++) + for ($j=0; $jquota); $j++) + if ($quotas[0]->quota[$j][0] == $account_new->quota[$i][0]) { + $account_new->quota[$i][1] = $quotas[0]->quota[$i][1]; + $account_new->quota[$i][4] = $quotas[0]->quota[$i][4]; + $account_new->quota[$i][5] = $quotas[0]->quota[$i][5]; + $account_new->quota[$i][8] = $quotas[0]->quota[$i][8]; + } + } + else for ($i=0; $iquota); $i++) { + $account_new->quota[$i][1] = 0; + $account_new->quota[$i][5] = 0; + } } // select general page after group has been loaded $select_local='general'; @@ -707,7 +727,7 @@ switch ($select_local) { // Load quotas if not yet done if ($config_intern->scriptServer && !isset($account_new->quota[0]) ) { // load quotas $quotas = getquotas(array($account_new)); - $account_new = $quotas[0]; + $account_new->quota = $quotas[0]->quota; } echo "\n"; echo "\n
"; diff --git a/lam/templates/account/useredit.php b/lam/templates/account/useredit.php index 3883b451..9710eae5 100644 --- a/lam/templates/account/useredit.php +++ b/lam/templates/account/useredit.php @@ -81,7 +81,6 @@ if (isset($_GET['DN']) && $_GET['DN']!='') { $DN = str_replace("\'", '',$_GET['DN']); // Load existing group $account_new = loaduser($DN); - $account_new ->type = 'user'; $account_old = $account_new; $account_new->unix_password=''; $account_new->smb_password=''; @@ -131,7 +130,12 @@ if (isset($_GET['DN']) && $_GET['DN']!='') { else $j++; } // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota); + // Set used blocks + for ($i=0; $iquota); $i++) { + $account_new->quota[$i][1] = 0; + $account_new->quota[$i][5] = 0; + } } // Display general-page $select_local = 'general'; @@ -506,8 +510,7 @@ switch ($_POST['select']) { // Load quotas if not yet done because they are needed for the pdf-file if ($config_intern->scriptServer && !isset($account_new->quota[0])) { // load quotas $quotas = getquotas(array($account_old)); - $account_new = $quotas[0]; - $account_new->quota = $account_old->quota; + $account_new->quota = $quotas[0]->quota; } // Create / display PDf-file createUserPDF(array($account_new)); @@ -670,7 +673,8 @@ do { // X-Or, only one if() can be true $account_new->smb_smbhome = str_replace('$user', $account_new->general_username, $account_new->smb_smbhome); if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid - $quotas = getquotas(array($account_new)); + if (isset($account_old)) $quotas = getquotas(array($account_old)); + else $quotas = getquotas(array($account_new)); for ($i=0; $iquota); $i++) $profile_quotas[] = $account_new->quota[$i][0]; for ($i=0; $iquota); $i++) { $real_quotas[] = $quotas[0]->quota[$i][0]; @@ -687,7 +691,22 @@ do { // X-Or, only one if() can be true else $j++; } // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota); + // Set used blocks + if (isset($account_old)) { + for ($i=0; $iquota); $i++) + for ($j=0; $jquota); $j++) + if ($quotas[0]->quota[$j][0] == $account_new->quota[$i][0]) { + $account_new->quota[$i][1] = $quotas[0]->quota[$i][1]; + $account_new->quota[$i][4] = $quotas[0]->quota[$i][4]; + $account_new->quota[$i][5] = $quotas[0]->quota[$i][5]; + $account_new->quota[$i][8] = $quotas[0]->quota[$i][8]; + } + } + else for ($i=0; $iquota); $i++) { + $account_new->quota[$i][1] = 0; + $account_new->quota[$i][5] = 0; + } } // select general page after group has been loaded $select_local='general'; @@ -735,10 +754,9 @@ echo "\n". if (is_array($errors)) for ($i=0; $iscriptServer && !isset($account_new->quota[0])) { // load quotas $quotas = getquotas(array($account_old)); - $account_new = $quotas[0]; + $account_new->quota = $quotas[0]->quota; } echo "\n"; echo "\n
"; diff --git a/lam/templates/delete.php b/lam/templates/delete.php index 75845aa6..4bb312af 100644 --- a/lam/templates/delete.php +++ b/lam/templates/delete.php @@ -69,7 +69,6 @@ if ($_GET['type']) { // $_GET['type'] is true if delete.php was called from *list.php // Store $_GET['type'] as $_POST['type'] // Replace wrong chars from Session - for ($i=0; $i'; switch ($_GET['type']) { // Select which layout and text should be displayed