From b6fda6b30527b9373c769691a59972d112c608ef Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 19 May 2010 19:22:29 +0000 Subject: [PATCH] fixed some PHP notices and sorting --- lam/lib/modules.inc | 16 +++++++++++----- lam/lib/modules/eduPerson.inc | 3 +++ lam/lib/modules/kolabUser.inc | 2 +- lam/lib/modules/ldapPublicKey.inc | 18 +++++++++++------- lam/lib/modules/nisnetgroup.inc | 4 +++- lam/lib/modules/posixGroup.inc | 2 +- lam/templates/masscreate.php | 2 +- lam/templates/ou_edit.php | 17 +++++++++++------ lam/templates/profedit/profilemain.php | 10 ++++++++-- lam/templates/profedit/profilepage.php | 13 ++++++------- 10 files changed, 56 insertions(+), 31 deletions(-) diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 2537b1a2..f7d0e0b2 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -1605,7 +1605,7 @@ class accountContainer { // find new attributes if (isset($attributes[$name]) && is_array($attributes[$name])) { foreach ($attributes[$name] as $j => $value) { - if (is_array($orig[$name])) { + if (isset($orig[$name]) && is_array($orig[$name])) { if (!in_array($value, $orig[$name])) if ($value != '') { $toadd[$name][] = $value; @@ -1615,7 +1615,7 @@ class accountContainer { } } // find unchanged attributes - if (is_array($orig[$name]) && is_array($attributes[$name])) { + if (isset($orig[$name]) && is_array($orig[$name]) && is_array($attributes[$name])) { foreach ($attributes[$name] as $j => $value) { if (($value != '') && in_array($value, $orig[$name])) { $notchanged[$name][] = $value; @@ -1913,9 +1913,15 @@ class accountContainer { // create complete new dn else { $attr = array(); - if (is_array($attributes[$this->finalDN]['add'])) $attr = array_merge_recursive($attr, $attributes[$this->finalDN]['add']); - if (is_array($attributes[$this->finalDN]['notchanged'])) $attr = array_merge_recursive($attr, $attributes[$this->finalDN]['notchanged']); - if (is_array($attributes[$this->finalDN]['modify'])) $attr = array_merge_recursive($attr, $attributes[$this->finalDN]['modify']); + if (isset($attributes[$this->finalDN]['add']) && is_array($attributes[$this->finalDN]['add'])) { + $attr = array_merge_recursive($attr, $attributes[$this->finalDN]['add']); + } + if (isset($attributes[$this->finalDN]['notchanged']) && is_array($attributes[$this->finalDN]['notchanged'])) { + $attr = array_merge_recursive($attr, $attributes[$this->finalDN]['notchanged']); + } + if (isset($attributes[$this->finalDN]['modify']) && is_array($attributes[$this->finalDN]['modify'])) { + $attr = array_merge_recursive($attr, $attributes[$this->finalDN]['modify']); + } $success = ldap_add($_SESSION['ldap']->server(), $this->finalDN, $attr); if (!$success) { logNewMessage(LOG_ERR, '[' . $ldapUser .'] Unable to create DN: ' . $this->finalDN . ' (' . ldap_err2str(ldap_errno($_SESSION['ldap']->server())) . ').'); diff --git a/lam/lib/modules/eduPerson.inc b/lam/lib/modules/eduPerson.inc index c25bac68..1dc6f3bd 100644 --- a/lam/lib/modules/eduPerson.inc +++ b/lam/lib/modules/eduPerson.inc @@ -431,6 +431,9 @@ class eduPerson extends baseModule { } return array(); } + if (!in_array('eduPerson', $this->attributes['objectClass'])) { + return array(); + } $errors = array(); // primary affiliation $this->attributes['eduPersonPrimaryAffiliation'][0] = $_POST['primaryAffiliation']; diff --git a/lam/lib/modules/kolabUser.inc b/lam/lib/modules/kolabUser.inc index 4b34f4ff..0024466e 100644 --- a/lam/lib/modules/kolabUser.inc +++ b/lam/lib/modules/kolabUser.inc @@ -422,7 +422,7 @@ class kolabUser extends baseModule { $this->attributes['objectClass'][] = 'kolabInetOrgPerson'; } else { - if ($_POST['form_subpage_kolabUser_deleteUser_open']) return array(); + if (isset($_POST['form_subpage_kolabUser_deleteUser_open'])) return array(); $this->attributes['kolabInvitationPolicy'] = array(); // country if (isset($_POST['country'])) { diff --git a/lam/lib/modules/ldapPublicKey.inc b/lam/lib/modules/ldapPublicKey.inc index 2dd6d554..93142791 100644 --- a/lam/lib/modules/ldapPublicKey.inc +++ b/lam/lib/modules/ldapPublicKey.inc @@ -90,13 +90,17 @@ class ldapPublicKey extends baseModule { */ function display_html_attributes() { $return = array(); + $keyCount = 0; // list current keys - for ($i = 0; $i < sizeof($this->attributes['sshPublicKey']); $i++) { - $return[] = array( - array('kind' => 'text', 'text' => _('SSH public key')), - array('kind' => 'input', 'name' => 'sshPublicKey' . $i, 'type' => 'text', 'size' => '50', 'maxlength' => '2048', 'value' => $this->attributes['sshPublicKey'][$i]), - array('kind' => 'input', 'type' => 'submit', 'name' => 'delKey' . $i, 'value' => _("Remove")), - array('kind' => 'help', 'value' => 'key')); + if (isset($this->attributes['sshPublicKey'])) { + $keyCount = sizeof($this->attributes['sshPublicKey']); + for ($i = 0; $i < sizeof($this->attributes['sshPublicKey']); $i++) { + $return[] = array( + array('kind' => 'text', 'text' => _('SSH public key')), + array('kind' => 'input', 'name' => 'sshPublicKey' . $i, 'type' => 'text', 'size' => '50', 'maxlength' => '2048', 'value' => $this->attributes['sshPublicKey'][$i]), + array('kind' => 'input', 'type' => 'submit', 'name' => 'delKey' . $i, 'value' => _("Remove")), + array('kind' => 'help', 'value' => 'key')); + } } // input box for new key $return[] = array( @@ -104,7 +108,7 @@ class ldapPublicKey extends baseModule { array('kind' => 'input', 'name' => 'sshPublicKey', 'type' => 'text', 'size' => '50', 'maxlength' => '2048', 'value' => ''), array('kind' => 'input', 'type' => 'submit', 'name' => 'addKey', 'value' => _("Add")), array('kind' => 'help', 'value' => 'key'), - array('kind' => 'input', 'type' => 'hidden', 'value' => sizeof($this->attributes['sshPublicKey']), 'name' => 'key_number')); + array('kind' => 'input', 'type' => 'hidden', 'value' => $keyCount, 'name' => 'key_number')); return $return; } diff --git a/lam/lib/modules/nisnetgroup.inc b/lam/lib/modules/nisnetgroup.inc index 289452ab..b95f30e9 100644 --- a/lam/lib/modules/nisnetgroup.inc +++ b/lam/lib/modules/nisnetgroup.inc @@ -178,9 +178,11 @@ class nisnetgroup extends baseModule { array('kind' => 'text', 'text' => _("Group name").'*'), array('kind' => 'input', 'name' => 'cn', 'type' => 'text', 'size' => '30', 'maxlength' => '20', 'value' => $groupName), array('kind' => 'help', 'value' => 'cn')); + $description = ''; + if (isset($this->attributes['description'][0])) $description = $this->attributes['description'][0]; $return[] = array( array('kind' => 'text', 'text' => _('Description')), - array('kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $this->attributes['description'][0]), + array('kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $description), array ('kind' => 'help', 'value' => 'description')); $subgroups = array(); if (isset($this->attributes['memberNisNetgroup']) && is_array($this->attributes['memberNisNetgroup'])) { diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index cbf978c8..1d795e30 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -536,7 +536,7 @@ class posixGroup extends baseModule implements passwordService { if (isset($_POST['form_subpage_' . get_class($this) . '_attributes_removePassword'])) { unset($this->attributes['userPassword']); } - if ($_POST['changegids']) $this->changegids=true; + if (isset($_POST['changegids'])) $this->changegids=true; else $this->changegids=false; if (($this->attributes['gidNumber'][0] != $_POST['gidNumber']) || !isset($this->attributes['gidNumber'][0])) { // Check if GID is valid. If none value was entered, the next useable value will be inserted diff --git a/lam/templates/masscreate.php b/lam/templates/masscreate.php index 776229ba..50a72558 100644 --- a/lam/templates/masscreate.php +++ b/lam/templates/masscreate.php @@ -153,7 +153,7 @@ echo " $label) { $style = 'style="display:none;"'; - if ((!isset($_POST['type']) && ($counter == 0)) || ($_POST['type'] == $type)) { + if ((!isset($_POST['type']) && ($counter == 0)) || (isset($_POST['type']) && ($_POST['type'] == $type))) { // show first account type or last selected one $style = ''; } diff --git a/lam/templates/ou_edit.php b/lam/templates/ou_edit.php index 5d4f330a..68c26901 100644 --- a/lam/templates/ou_edit.php +++ b/lam/templates/ou_edit.php @@ -117,8 +117,8 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) { include 'main_header.php'; // display messages if ($error || $message || $text) { - if ($text) echo $text; - elseif ($error) { + if (isset($text)) echo $text; + elseif (isset($error)) { StatusMessage("ERROR", "", $error); echo ("
" . _("Back to OU-Editor") . "\n"); } @@ -138,17 +138,22 @@ display_main(); * Displays the main page of the OU editor */ function display_main() { - $types = $_SESSION['config']->get_ActiveTypes(); // display main page include 'main_header.php'; echo "

" . _("OU editor") . "

"; echo ("
\n"); echo ("\n"); + $types = array(); + $typeList = $_SESSION['config']->get_ActiveTypes(); + for ($i = 0; $i < sizeof($typeList); $i++) { + $types[$typeList[$i]] = getTypeAlias($typeList[$i]); + } + natcasesort($types); $options = ""; - for ($i = 0; $i < sizeof($types); $i++) { - $options .= "\n"; - $units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($types[$i])); + foreach ($types as $name => $title) { + $options .= "\n"; + $units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($name)); for ($u = 0; $u < sizeof($units); $u++) { $options .= "\n"; } diff --git a/lam/templates/profedit/profilemain.php b/lam/templates/profedit/profilemain.php index 1d1b288b..ce3a567a 100644 --- a/lam/templates/profedit/profilemain.php +++ b/lam/templates/profedit/profilemain.php @@ -47,13 +47,19 @@ setlanguage(); $types = $_SESSION['config']->get_ActiveTypes(); $profileClasses = array(); +$profileClassesTemp = array(); for ($i = 0; $i < sizeof($types); $i++) { - $profileClasses[] = array( + $profileClassesTemp[getTypeAlias($types[$i])] = array( 'scope' => $types[$i], 'title' => getTypeAlias($types[$i]), 'profiles' => ""); } - +$profileClassesKeys = array_keys($profileClassesTemp); +natcasesort($profileClassesKeys); +$profileClassesKeys = array_values($profileClassesKeys); +for ($i = 0; $i < sizeof($profileClassesKeys); $i++) { + $profileClasses[] = $profileClassesTemp[$profileClassesKeys[$i]]; +} // check if user is logged in, if not go to login if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) { diff --git a/lam/templates/profedit/profilepage.php b/lam/templates/profedit/profilepage.php index 2d3267d2..3439114a 100644 --- a/lam/templates/profedit/profilepage.php +++ b/lam/templates/profedit/profilepage.php @@ -107,12 +107,7 @@ if (isset($_POST['save'])) { // print error messages if any if (sizeof($errors) > 0) { for ($i = 0; $i < sizeof($errors); $i++) { - if (sizeof($errors[$i]) > 3) { // messages with additional variables - StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2], $errors[$i][3]); - } - else { - StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]); - } + call_user_func_array('StatusMessage', $errors[$i]); } echo "
\n"; } @@ -246,7 +241,11 @@ for ($m = 0; $m < sizeof($modules); $m++) { // profile name and submit/abort buttons echo ("" . _("Profile name") . ": \n"); $tabindex++; -echo ("\n"); +$profName = ''; +if (isset($_GET['edit'])) { + $profName = $_GET['edit']; +} +echo ("\n"); printHelpLink(getHelp('', '360'), '360'); echo "

\n"; $tabindex++;