refactoring
This commit is contained in:
parent
ed325fcab6
commit
ce68219e6a
|
@ -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);
|
||||
$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;
|
||||
}
|
||||
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);
|
||||
$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!") . "<br>" . htmlspecialchars($error[$i]), htmlspecialchars($failedDNs[$i]));
|
||||
foreach ($failedDNs as $suffix => $error) {
|
||||
StatusMessage("ERROR", _("Failed to create entry!") . "<br>" . htmlspecialchars($error), htmlspecialchars($suffix));
|
||||
}
|
||||
include 'main_footer.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();
|
||||
|
|
|
@ -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) {
|
|||
<a href="<?php echo $headerPrefix; ?>tools.php"><img class="align-middle" height="16" width="16" alt="tools" src="<?php echo $headerPrefix; ?>../graphics/tools.png"> <?php echo _("Tools") ?></a>
|
||||
<ul>
|
||||
<?php
|
||||
for ($i = 0; $i < sizeof($tools); $i++) {
|
||||
$subTools = $tools[$i]->getSubTools();
|
||||
echo '<li title="' . $tools[$i]->getDescription() . '">';
|
||||
$link = $headerPrefix . $tools[$i]->getLink();
|
||||
foreach ($tools as $tool) {
|
||||
$subTools = $tool->getSubTools();
|
||||
echo '<li title="' . $tool->getDescription() . '">';
|
||||
$link = $headerPrefix . $tool->getLink();
|
||||
echo '<a href="' . $link . "\">\n";
|
||||
echo '<img height="16" width="16" alt="" src="' . $headerPrefix . '../graphics/' . $tools[$i]->getImageLink() . '"> ' . $tools[$i]->getName();
|
||||
echo '<img height="16" width="16" alt="" src="' . $headerPrefix . '../graphics/' . $tool->getImageLink() . '"> ' . $tool->getName();
|
||||
echo "</a>\n";
|
||||
if (sizeof($subTools) > 0) {
|
||||
echo "<ul>\n";
|
||||
for ($s = 0; $s < sizeof($subTools); $s++) {
|
||||
echo "<li title=\"" . $subTools[$s]->description . "\">\n";
|
||||
echo "<a href=\"" . $headerPrefix . $subTools[$s]->link . "\">\n";
|
||||
echo '<img width=16 height=16 alt="" src="' . $headerPrefix . '../graphics/' . $subTools[$s]->image . '"> ' . $subTools[$s]->name;
|
||||
foreach ($subTools as $subTool) {
|
||||
echo "<li title=\"" . $subTool->description . "\">\n";
|
||||
echo "<a href=\"" . $headerPrefix . $subTool->link . "\">\n";
|
||||
echo '<img width=16 height=16 alt="" src="' . $headerPrefix . '../graphics/' . $subTool->image . '"> ' . $subTool->name;
|
||||
echo "</a>\n";
|
||||
echo "</li>\n";
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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']));
|
||||
|
|
|
@ -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 "<br>\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);
|
||||
|
|
|
@ -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 "</form>\n";
|
||||
echo "</div>\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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue