refactoring

This commit is contained in:
Roland Gruber 2024-12-11 22:12:01 +01:00
parent cff1728603
commit f1b3ecd63f
5 changed files with 28 additions and 32 deletions

View file

@ -244,7 +244,7 @@ function checkImportData(): void {
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$_SESSION[Importer::SESSION_KEY_TASKS] = $tasks; $_SESSION[Importer::SESSION_KEY_TASKS] = $tasks;
$_SESSION[Importer::SESSION_KEY_COUNT] = sizeof($tasks); $_SESSION[Importer::SESSION_KEY_COUNT] = count($tasks);
$_SESSION[Importer::SESSION_KEY_STOP_ON_ERROR] = (!isset($_POST['noStop']) || ($_POST['noStop'] != 'on')); $_SESSION[Importer::SESSION_KEY_STOP_ON_ERROR] = (!isset($_POST['noStop']) || ($_POST['noStop'] != 'on'));
} }

View file

@ -122,7 +122,7 @@ function displayStartPage(): void {
} }
$treeSuffixes = TreeViewTool::getRootDns(); $treeSuffixes = TreeViewTool::getRootDns();
if (!empty($treeSuffixes)) { if (!empty($treeSuffixes)) {
if (sizeof($treeSuffixes) === 1) { if (count($treeSuffixes) === 1) {
$suffixes[_('Tree view')] = $treeSuffixes[0]; $suffixes[_('Tree view')] = $treeSuffixes[0];
$hideRules[$treeSuffixes[0]] = ['otherSuffix']; $hideRules[$treeSuffixes[0]] = ['otherSuffix'];
} }
@ -187,7 +187,7 @@ function displayStartPage(): void {
$container->add(new htmlButton('addFields', _('Add more fields')), 12); $container->add(new htmlButton('addFields', _('Add more fields')), 12);
$container->add(new htmlHiddenInput('opcount', $opCount), 12); $container->add(new htmlHiddenInput('opcount', $opCount), 12);
// error messages // error messages
if (sizeof($errors) > 0) { if ($errors !== []) {
$container->addVerticalSpacer('5rem'); $container->addVerticalSpacer('5rem');
foreach ($errors as $error) { foreach ($errors as $error) {
$error->colspan = 5; $error->colspan = 5;
@ -209,7 +209,7 @@ function displayStartPage(): void {
$container->addVerticalSpacer('1rem'); $container->addVerticalSpacer('1rem');
// run actions // run actions
if ((sizeof($errors) == 0) && (isset($_POST['dryRun']) || isset($_POST['applyChanges']))) { if ((count($errors) == 0) && (isset($_POST['dryRun']) || isset($_POST['applyChanges']))) {
runActions($container); runActions($container);
} }
@ -228,12 +228,7 @@ function displayStartPage(): void {
*/ */
function runActions(htmlResponsiveRow &$container): void { function runActions(htmlResponsiveRow &$container): void {
// LDAP suffix // LDAP suffix
if ($_POST['suffix'] == '-') { $suffix = ($_POST['suffix'] === '-') ? trim($_POST['otherSuffix']) : $_POST['suffix'];
$suffix = trim($_POST['otherSuffix']);
}
else {
$suffix = $_POST['suffix'];
}
if (empty($suffix)) { if (empty($suffix)) {
$error = new htmlStatusMessage('ERROR', _('LDAP Suffix is invalid!')); $error = new htmlStatusMessage('ERROR', _('LDAP Suffix is invalid!'));
$error->colspan = 5; $error->colspan = 5;
@ -249,7 +244,7 @@ function runActions(htmlResponsiveRow &$container): void {
$operations[] = [$_POST['op_' . $i], strtolower(trim($_POST['attr_' . $i])), trim($_POST['val_' . $i])]; $operations[] = [$_POST['op_' . $i], strtolower(trim($_POST['attr_' . $i])), trim($_POST['val_' . $i])];
} }
} }
if (sizeof($operations) == 0) { if (count($operations) == 0) {
$error = new htmlStatusMessage('ERROR', _('Please specify at least one operation.')); $error = new htmlStatusMessage('ERROR', _('Please specify at least one operation.'));
$error->colspan = 5; $error->colspan = 5;
$container->add($error, 12); $container->add($error, 12);
@ -290,12 +285,7 @@ function runAjaxActions(): void {
break; break;
case STAGE_ACTIONS_CALCULATED: case STAGE_ACTIONS_CALCULATED:
case STAGE_WRITING: case STAGE_WRITING:
if ($_SESSION['multiEdit_dryRun']) { $jsonReturn = $_SESSION['multiEdit_dryRun'] ? dryRun() : doModify();
$jsonReturn = dryRun();
}
else {
$jsonReturn = doModify();
}
break; break;
} }
echo json_encode($jsonReturn, JSON_THROW_ON_ERROR); echo json_encode($jsonReturn, JSON_THROW_ON_ERROR);
@ -515,7 +505,7 @@ function doModify(): array {
} }
// run 10 modifications in each call // run 10 modifications in each call
$localCount = 0; $localCount = 0;
while (($localCount < 10) && ($_SESSION['multiEdit_status']['index'] < sizeof($_SESSION['multiEdit_status']['actions']))) { while (($localCount < 10) && ($_SESSION['multiEdit_status']['index'] < count($_SESSION['multiEdit_status']['actions']))) {
$action = $_SESSION['multiEdit_status']['actions'][$_SESSION['multiEdit_status']['index']]; $action = $_SESSION['multiEdit_status']['actions'][$_SESSION['multiEdit_status']['index']];
$opType = $action[0]; $opType = $action[0];
$dn = $action[1]; $dn = $action[1];
@ -548,7 +538,7 @@ function doModify(): array {
$_SESSION['multiEdit_status']['index']++; $_SESSION['multiEdit_status']['index']++;
} }
// check if finished // check if finished
if ($_SESSION['multiEdit_status']['index'] == sizeof($_SESSION['multiEdit_status']['actions'])) { if ($_SESSION['multiEdit_status']['index'] == count($_SESSION['multiEdit_status']['actions'])) {
$_SESSION['multiEdit_status']['modContent'] .= '<br><br>' . _('Finished all operations.'); $_SESSION['multiEdit_status']['modContent'] .= '<br><br>' . _('Finished all operations.');
return [ return [
'status' => STAGE_FINISHED, 'status' => STAGE_FINISHED,
@ -559,7 +549,7 @@ function doModify(): array {
// return current status // return current status
return [ return [
'status' => STAGE_WRITING, 'status' => STAGE_WRITING,
'progress' => 20 + (($_SESSION['multiEdit_status']['index'] / sizeof($_SESSION['multiEdit_status']['actions'])) * 80), 'progress' => 20 + (($_SESSION['multiEdit_status']['index'] / count($_SESSION['multiEdit_status']['actions'])) * 80),
'content' => $_SESSION['multiEdit_status']['modContent'] 'content' => $_SESSION['multiEdit_status']['modContent']
]; ];
} }

View file

@ -1,5 +1,7 @@
<?php <?php
namespace LAM\TOOLS\OU_EDIT; namespace LAM\TOOLS\OU_EDIT;
use \htmlSpacer; use \htmlSpacer;
use \htmlOutputText; use \htmlOutputText;
use \htmlButton; use \htmlButton;
@ -35,11 +37,11 @@ use LAM\TYPES\TypeManager;
*/ */
/** /**
* This is an editor for organizational units. * This is an editor for organizational units.
* *
* @author Roland Gruber * @author Roland Gruber
* @package tools * @package tools
*/ */
/** security functions */ /** security functions */
include_once(__DIR__ . "/../../lib/security.inc"); include_once(__DIR__ . "/../../lib/security.inc");
@ -55,7 +57,9 @@ startSecureSession();
enforceUserIsLoggedIn(); enforceUserIsLoggedIn();
// die if no write access // die if no write access
if (!checkIfWriteAccessIsAllowed()) die(); if (!checkIfWriteAccessIsAllowed()) {
die();
}
checkIfToolIsActive('toolOUEditor'); checkIfToolIsActive('toolOUEditor');
@ -96,7 +100,9 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
$error = _("Unable to create new OU!"); $error = _("Unable to create new OU!");
} }
} }
else $error = _("OU already exists!"); else {
$error = _("OU already exists!");
}
} }
// show errormessage if ou is invalid // show errormessage if ou is invalid
else { else {
@ -124,7 +130,7 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr); $info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if (($info !== false) && ($info['count'] === 0)) { if (($info !== false) && ($info['count'] === 0)) {
// print header // print header
include '../../lib/adminHeader.inc'; include __DIR__ . '/../../lib/adminHeader.inc';
echo '<div class="smallPaddingContent">'; echo '<div class="smallPaddingContent">';
echo "<form action=\"ou_edit.php\" method=\"post\">\n"; echo "<form action=\"ou_edit.php\" method=\"post\">\n";
$container = new htmlResponsiveRow(); $container = new htmlResponsiveRow();
@ -149,7 +155,7 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
parseHtml(null, $container, [], false, 'user'); parseHtml(null, $container, [], false, 'user');
echo "</form>"; echo "</form>";
echo '</div>'; echo '</div>';
include '../../lib/adminFooter.inc'; include __DIR__ . '/../../lib/adminFooter.inc';
exit(); exit();
} }
else { else {

View file

@ -54,7 +54,7 @@ if ($result) {
$info = ldap_get_entries($_SESSION['ldap']->server(), $result); $info = ldap_get_entries($_SESSION['ldap']->server(), $result);
if (is_array($info) && is_array($info[0])) { if (is_array($info) && is_array($info[0])) {
$info = $info[0]; $info = $info[0];
foreach ($info as $key => $value) { foreach (array_keys($info) as $key) {
if (is_array($info[$key]) && isset($info[$key]['count'])) { if (is_array($info[$key]) && isset($info[$key]['count'])) {
unset($info[$key]['count']); unset($info[$key]['count']);
} }
@ -118,7 +118,7 @@ if ($configcontext != '') {
$container->addLabel(new htmlOutputText('<b>' . _("Schema suffix") . '</b>', false)); $container->addLabel(new htmlOutputText('<b>' . _("Schema suffix") . '</b>', false));
$container->addField(new htmlOutputText($subschemasubentry)); $container->addField(new htmlOutputText($subschemasubentry));
if ($dynamicSubtrees != '') { if ($dynamicSubtrees !== '') {
$container->addLabel(new htmlOutputText('<b>' . _("Dynamic subtrees") . '</b>', false)); $container->addLabel(new htmlOutputText('<b>' . _("Dynamic subtrees") . '</b>', false));
$container->addField(new htmlOutputText($dynamicSubtrees)); $container->addField(new htmlOutputText($dynamicSubtrees));
} }

View file

@ -77,7 +77,7 @@ function showTree(): void {
$dnParts = ldap_explode_dn($extraDnPart, 0); $dnParts = ldap_explode_dn($extraDnPart, 0);
if ($dnParts !== false) { if ($dnParts !== false) {
unset($dnParts['count']); unset($dnParts['count']);
$dnPartsCount = sizeof($dnParts); $dnPartsCount = count($dnParts);
for ($i = 0; $i < $dnPartsCount; $i++) { for ($i = 0; $i < $dnPartsCount; $i++) {
$currentParts = array_slice($dnParts, $dnPartsCount - ($i + 1)); $currentParts = array_slice($dnParts, $dnPartsCount - ($i + 1));
$openInitial[] = '"' . base64_encode(implode(',', $currentParts) . ',' . $rootDn) . '"'; $openInitial[] = '"' . base64_encode(implode(',', $currentParts) . ',' . $rootDn) . '"';