diff --git a/lam/templates/initsuff.php b/lam/templates/initsuff.php
index b90e2259..fcdba617 100644
--- a/lam/templates/initsuff.php
+++ b/lam/templates/initsuff.php
@@ -55,7 +55,6 @@ if (!empty($_POST)) {
if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
if (isset($_POST['add_suff'])) {
$failedDNs = array();
- $error = array();
$newSuffixes = $_POST['new_suff'];
$newSuffixes = str_replace("\\", "", $newSuffixes);
$newSuffixes = str_replace("'", "", $newSuffixes);
@@ -63,9 +62,14 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
// add entries
foreach ($newSuffixes as $newSuffix) {
// check if entry is already present
- $info = ldap_read($_SESSION['ldap']->server(), escapeDN($newSuffix), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
- $res = ldap_get_entries($_SESSION['ldap']->server(), $info);
- if ($res) continue;
+ $info = @ldap_read($_SESSION['ldap']->server(), escapeDN($newSuffix), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
+ $res = false;
+ if ($info !== false) {
+ $res = ldap_get_entries($_SESSION['ldap']->server(), $info);
+ }
+ if ($res) {
+ continue;
+ }
$suff = $newSuffix;
// generate DN and attributes
$tmp = explode(",", $suff);
@@ -78,8 +82,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
$attr['objectClass'] = 'organization';
$dn = $suff;
if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) {
- $failedDNs[] = $suff;
- $error[] = ldap_error($_SESSION['ldap']->server());
+ $failedDNs[$suff] = ldap_error($_SESSION['ldap']->server());
continue;
}
}
@@ -108,8 +111,11 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
$subsuffCount = sizeof($subsuffs);
for ($k = $subsuffCount - 1; $k >= 0; $k--) {
// check if subsuffix is present
- $info = ldap_read($_SESSION['ldap']->server(), escapeDN($subsuffs[$k]), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
- $res = ldap_get_entries($_SESSION['ldap']->server(), $info);
+ $info = @ldap_read($_SESSION['ldap']->server(), escapeDN($subsuffs[$k]), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
+ $res = false;
+ if ($info !== false) {
+ $res = ldap_get_entries($_SESSION['ldap']->server(), $info);
+ }
if (!$res) {
$suffarray = explode(",", $subsuffs[$k]);
$headarray = explode("=", $suffarray[0]);
@@ -119,8 +125,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
$attr['ou'] = $headarray[1];
$dn = $subsuffs[$k];
if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) {
- $failedDNs[] = $suff;
- $error[] = ldap_error($_SESSION['ldap']->server());
+ $failedDNs[$suff] = ldap_error($_SESSION['ldap']->server());
break;
}
}
@@ -134,8 +139,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
}
$dn = $subsuffs[$k];
if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) {
- $failedDNs[] = $suff;
- $error[] = ldap_error($_SESSION['ldap']->server());
+ $failedDNs[$suff] = ldap_error($_SESSION['ldap']->server());
break;
}
}
@@ -143,8 +147,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
}
}
else {
- $failedDNs[] = $suff;
- $error[] = ldap_error($_SESSION['ldap']->server());
+ $failedDNs[$suff] = ldap_error($_SESSION['ldap']->server());
}
}
}
@@ -155,8 +158,8 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
if (isset($_POST['add_suff'])) {
if (sizeof($failedDNs) > 0) {
// print error messages
- for ($i = 0; $i < sizeof($failedDNs); $i++) {
- StatusMessage("ERROR", _("Failed to create entry!") . "
" . htmlspecialchars($error[$i]), htmlspecialchars($failedDNs[$i]));
+ foreach ($failedDNs as $suffix => $error) {
+ StatusMessage("ERROR", _("Failed to create entry!") . "
" . htmlspecialchars($error), htmlspecialchars($suffix));
}
include 'main_footer.php';
}
diff --git a/lam/templates/main.php b/lam/templates/main.php
index e594859f..4da6b94a 100644
--- a/lam/templates/main.php
+++ b/lam/templates/main.php
@@ -50,7 +50,11 @@ $new_suffs = array();
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
foreach ($types as $type) {
- $info = ldap_read($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
+ $info = @ldap_read($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
+ if (($info === false) && !in_array($type->getSuffix(), $new_suffs)) {
+ $new_suffs[] = $type->getSuffix();
+ continue;
+ }
$res = ldap_get_entries($_SESSION['ldap']->server(), $info);
if (!$res && !in_array($type->getSuffix(), $new_suffs)) {
$new_suffs[] = $type->getSuffix();
diff --git a/lam/templates/main_header.php b/lam/templates/main_header.php
index 0cad6a14..d0a32abb 100644
--- a/lam/templates/main_header.php
+++ b/lam/templates/main_header.php
@@ -85,8 +85,7 @@ $availableTools = getTools();
$toolSettings = $_SESSION['config']->getToolSettings();
// sort tools
$toSort = array();
-for ($i = 0; $i < sizeof($availableTools); $i++) {
- $toolClass = $availableTools[$i];
+foreach ($availableTools as $toolClass) {
$myTool = new $toolClass();
if ($myTool->getRequiresWriteAccess() && !checkIfWriteAccessIsAllowed()) {
continue;
@@ -103,7 +102,7 @@ for ($i = 0; $i < sizeof($availableTools); $i++) {
if (isset($toolSettings['tool_hide_' . $toolName]) && ($toolSettings['tool_hide_' . $toolName] == 'true')) {
continue;
}
- $toSort[$availableTools[$i]] = $myTool->getPosition();
+ $toSort[$toolClass] = $myTool->getPosition();
}
asort($toSort);
$tools = array();
@@ -148,19 +147,19 @@ foreach ($toSort as $key => $value) {
getSubTools();
- echo '- ';
- $link = $headerPrefix . $tools[$i]->getLink();
+ foreach ($tools as $tool) {
+ $subTools = $tool->getSubTools();
+ echo '
- ';
+ $link = $headerPrefix . $tool->getLink();
echo '\n";
- echo ' ' . $tools[$i]->getName();
+ echo ' ' . $tool->getName();
echo "\n";
if (sizeof($subTools) > 0) {
echo "
\n";
- for ($s = 0; $s < sizeof($subTools); $s++) {
- echo "- description . "\">\n";
- echo "link . "\">\n";
- echo ' ' . $subTools[$s]->name;
+ foreach ($subTools as $subTool) {
+ echo "
- description . "\">\n";
+ echo "link . "\">\n";
+ echo ' ' . $subTool->name;
echo "\n";
echo "
\n";
}
diff --git a/lam/templates/ou_edit.php b/lam/templates/ou_edit.php
index 3759017a..51ad58be 100644
--- a/lam/templates/ou_edit.php
+++ b/lam/templates/ou_edit.php
@@ -191,8 +191,8 @@ function display_main($message, $error) {
$type = $typeManager->getConfiguredType($typeId);
$elements = array();
$units = searchLDAP($type->getSuffix(), '(objectclass=organizationalunit)', array('dn'));
- for ($u = 0; $u < sizeof($units); $u++) {
- $elements[getAbstractDN($units[$u]['dn'])] = $units[$u]['dn'];
+ foreach ($units as $unit) {
+ $elements[getAbstractDN($unit['dn'])] = $unit['dn'];
}
$options[$title] = $elements;
}
diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php
index a5d64764..8d350ef8 100644
--- a/lam/templates/pdfedit/pdfmain.php
+++ b/lam/templates/pdfedit/pdfmain.php
@@ -243,10 +243,6 @@ include '../main_header.php';
$container->addElement(new htmlSubTitle(_("Manage existing PDF structures")), true);
$existingContainer = new htmlTable();
foreach ($templateClasses as $templateClass) {
- if ($i > 0) {
- $existingContainer->addElement(new htmlSpacer(null, '10px'), true);
- }
-
$existingContainer->addElement(new htmlImage('../../graphics/' . $templateClass['icon']));
$existingContainer->addElement(new htmlSpacer('3px', null));
$existingContainer->addElement(new htmlOutputText($templateClass['title']));
diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php
index d38e9be8..d9bf703a 100644
--- a/lam/templates/pdfedit/pdfpage.php
+++ b/lam/templates/pdfedit/pdfpage.php
@@ -188,8 +188,8 @@ include '../main_header.php';
// print error messages if any
if (sizeof($saveErrors) > 0) {
- for ($i = 0; $i < sizeof($saveErrors); $i++) {
- call_user_func_array('StatusMessage', $saveErrors[$i]);
+ foreach ($saveErrors as $saveError) {
+ call_user_func_array('StatusMessage', $saveError);
}
echo "
\n";
}
@@ -259,8 +259,7 @@ $structure = $_SESSION['currentPDFStructure'];
// print every entry in the current structure
$structureContent = new htmlTable();
$sections = $structure->getSections();
-for ($key = 0; $key < sizeof($sections); $key++) {
- $section = $sections[$key];
+foreach ($sections as $key => $section) {
// create the up/down/remove links
$linkUp = new htmlButton('up_section_' . $key, 'up.gif', true);
$linkUp->setTitle(_("Up"));
@@ -317,8 +316,7 @@ for ($key = 0; $key < sizeof($sections); $key++) {
$structureContent->addElement($linkRemove, true);
// add section entries
$sectionEntries = $section->getEntries();
- for ($e = 0; $e < sizeof($sectionEntries); $e++) {
- $sectionEntry = $sectionEntries[$e];
+ foreach ($sectionEntries as $e => $sectionEntry) {
$structureContent->addElement(new htmlSpacer('10px', null));
$fieldOutput = new htmlOutputText(translateFieldIDToName($sectionEntry->getKey(), $type->getScope(), $availablePDFFields));
$structureContent->addElement($fieldOutput);
diff --git a/lam/templates/profedit/profilemain.php b/lam/templates/profedit/profilemain.php
index 983abd12..82ffde4d 100644
--- a/lam/templates/profedit/profilemain.php
+++ b/lam/templates/profedit/profilemain.php
@@ -86,8 +86,8 @@ foreach ($types as $type) {
$profileClassesKeys = array_keys($profileClassesTemp);
natcasesort($profileClassesKeys);
$profileClassesKeys = array_values($profileClassesKeys);
-for ($i = 0; $i < sizeof($profileClassesKeys); $i++) {
- $profileClasses[] = $profileClassesTemp[$profileClassesKeys[$i]];
+foreach ($profileClassesKeys as $profileClassesKey) {
+ $profileClasses[] = $profileClassesTemp[$profileClassesKey];
}
// check if user is logged in, if not go to login
@@ -102,10 +102,10 @@ elseif (isset($_POST['createProfileButton'])) {
exit;
}
// check if a profile should be edited
-for ($i = 0; $i < sizeof($profileClasses); $i++) {
- if (isset($_POST['editProfile_' . $profileClasses[$i]['typeId']]) || isset($_POST['editProfile_' . $profileClasses[$i]['typeId'] . '_x'])) {
- metaRefresh("profilepage.php?type=" . htmlspecialchars($profileClasses[$i]['typeId']) .
- "&edit=" . htmlspecialchars($_POST['profile_' . $profileClasses[$i]['typeId']]));
+foreach ($profileClasses as $profileClass) {
+ if (isset($_POST['editProfile_' . $profileClass['typeId']]) || isset($_POST['editProfile_' . $profileClass['typeId'] . '_x'])) {
+ metaRefresh("profilepage.php?type=" . htmlspecialchars($profileClass['typeId']) .
+ "&edit=" . htmlspecialchars($_POST['profile_' . $profileClass['typeId']]));
exit;
}
}
@@ -189,10 +189,10 @@ if (!empty($_POST['export'])) {
}
// get list of profiles for each account type
-for ($i = 0; $i < sizeof($profileClasses); $i++) {
- $profileList = \LAM\PROFILES\getAccountProfiles($profileClasses[$i]['typeId']);
+foreach ($profileClasses as &$profileClass) {
+ $profileList = \LAM\PROFILES\getAccountProfiles($profileClass['typeId']);
natcasesort($profileList);
- $profileClasses[$i]['profiles'] = $profileList;
+ $profileClass['profiles'] = $profileList;
}
if (isset($_GET['savedSuccessfully'])) {
@@ -205,8 +205,8 @@ if (isset($_GET['savedSuccessfully'])) {
if (!empty($profileClasses)) {
$container->addElement(new htmlSubTitle(_('Create a new profile')), true);
$sortedTypes = array();
- for ($i = 0; $i < sizeof($profileClasses); $i++) {
- $sortedTypes[$profileClasses[$i]['title']] = $profileClasses[$i]['typeId'];
+ foreach ($profileClasses as $profileClass) {
+ $sortedTypes[$profileClass['title']] = $profileClass['typeId'];
}
natcasesort($sortedTypes);
$newContainer = new htmlTable();
@@ -226,37 +226,33 @@ $container->addElement(new htmlSubTitle(_('Manage existing profiles')), true);
$existingContainer = new htmlTable();
$existingContainer->colspan = 5;
-for ($i = 0; $i < sizeof($profileClasses); $i++) {
- if ($i > 0) {
- $existingContainer->addElement(new htmlSpacer(null, '10px'), true);
- }
-
- $existingContainer->addElement(new htmlImage('../../graphics/' . $profileClasses[$i]['icon']));
+foreach ($profileClasses as $profileClass) {
+ $existingContainer->addElement(new htmlImage('../../graphics/' . $profileClass['icon']));
$existingContainer->addElement(new htmlSpacer('3px', null));
- $existingContainer->addElement(new htmlOutputText($profileClasses[$i]['title']));
+ $existingContainer->addElement(new htmlOutputText($profileClass['title']));
$existingContainer->addElement(new htmlSpacer('3px', null));
- $select = new htmlSelect('profile_' . $profileClasses[$i]['typeId'], $profileClasses[$i]['profiles']);
+ $select = new htmlSelect('profile_' . $profileClass['typeId'], $profileClass['profiles']);
$select->setWidth('15em');
$existingContainer->addElement($select);
$existingContainer->addElement(new htmlSpacer('3px', null));
- $editButton = new htmlButton('editProfile_' . $profileClasses[$i]['typeId'], 'edit.png', true);
+ $editButton = new htmlButton('editProfile_' . $profileClass['typeId'], 'edit.png', true);
$editButton->setTitle(_('Edit'));
$existingContainer->addElement($editButton);
$deleteLink = new htmlLink(null, '#', '../../graphics/delete.png');
$deleteLink->setTitle(_('Delete'));
- $deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', '" . 'profile_' . $profileClasses[$i]['typeId'] . "');");
+ $deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $profileClass['typeId'] . "', '" . 'profile_' . $profileClass['typeId'] . "');");
$existingContainer->addElement($deleteLink);
if (count($configProfiles) > 1) {
$importLink = new htmlLink(null, '#', '../../graphics/import.png');
$importLink->setTitle(_('Import profiles'));
$importLink->setOnClick("showDistributionDialog('" . _("Import profiles") . "', '" .
- _('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', 'import');");
+ _('Ok') . "', '" . _('Cancel') . "', '" . $profileClass['typeId'] . "', 'import');");
$existingContainer->addElement($importLink);
}
$exportLink = new htmlLink(null, '#', '../../graphics/export.png');
$exportLink->setTitle(_('Export profile'));
$exportLink->setOnClick("showDistributionDialog('" . _("Export profile") . "', '" .
- _('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', 'export', '" . 'profile_' . $profileClasses[$i]['typeId'] . "');");
+ _('Ok') . "', '" . _('Cancel') . "', '" . $profileClass['typeId'] . "', 'export', '" . 'profile_' . $profileClass['typeId'] . "');");
$existingContainer->addElement($exportLink);
$existingContainer->addNewLine();
}
@@ -270,9 +266,9 @@ parseHtml(null, $container, array(), false, $tabindex, 'user');
echo "\n";
echo "\n";
-for ($i = 0; $i < sizeof($profileClasses); $i++) {
- $typeId = $profileClasses[$i]['typeId'];
- $scope = $profileClasses[$i]['scope'];
+foreach ($profileClasses as $profileClass) {
+ $typeId = $profileClass['typeId'];
+ $scope = $profileClass['scope'];
$importOptions = array();
foreach ($configProfiles as $profile) {
$typeManagerImport = new TypeManager($serverProfiles[$profile]);
@@ -281,8 +277,8 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
if (($profile != $_SESSION['config']->getName()) || ($typeImport->getId() != $typeId)) {
$accountProfiles = \LAM\PROFILES\getAccountProfiles($typeImport->getId(), $profile);
if (!empty($accountProfiles)) {
- for ($p = 0; $p < sizeof($accountProfiles); $p++) {
- $importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfiles[$p]] = $profile . '##' . $typeImport->getId() . '##' . $accountProfiles[$p];
+ foreach ($accountProfiles as $accountProfile) {
+ $importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfile] = $profile . '##' . $typeImport->getId() . '##' . $accountProfile;
}
}
}