From b1d5aa8ac23ac1d08938cd643ead1a1105421113 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 17 Nov 2013 19:05:10 +0000 Subject: [PATCH] multi edit tool --- lam/graphics/dryRun.png | Bin 0 -> 936 bytes lam/help/help.inc | 9 +- lam/lib/tools/fileUpload.inc | 2 +- lam/lib/tools/multiEdit.inc | 131 ++++++++++++++++ lam/lib/tools/ouEditor.inc | 2 +- lam/lib/tools/pdfEdit.inc | 2 +- lam/lib/tools/schemaBrowser.inc | 2 +- lam/lib/tools/serverInfo.inc | 2 +- lam/style/500_layout.css | 5 + lam/templates/multiEdit.php | 257 ++++++++++++++++++++++++++++++++ 10 files changed, 406 insertions(+), 6 deletions(-) create mode 100644 lam/graphics/dryRun.png create mode 100644 lam/lib/tools/multiEdit.inc create mode 100644 lam/templates/multiEdit.php diff --git a/lam/graphics/dryRun.png b/lam/graphics/dryRun.png new file mode 100644 index 0000000000000000000000000000000000000000..0d826bbf3ce4cfa5fa6bbbd1a926b6897af14c35 GIT binary patch literal 936 zcmV;Z16TZsP)WFU8GbZ8({Xk{QrNlj4iWF>9@00Rt3L_t(|+GUeXXk29& zg`e;5&Ye3m$)rilq(+TRjHFsqtJYRfCrS&Ix=_=FE~G_-ZURN?!j-FR6bT3-h+PyB zOSDqdU^c~IwYVs)MTHbvL#9nSA%8PXCYiZ&@AtV#6Iwm1m&4)kayUouAAB(~e&p=M z+5X&?*b4_Vr=o@Gj$O zBslfcWhSQzU!ER5{N@I)0B#f)S_eNI8#^+P-}~Io4&pc>VKiG?Q&UF{R~@=8Q*; z)ID80p3h%8_uWbT@rkil|C|wz3+K2#w+etmaQW&Ydmd@!?|&93%vDfIgL43M=F(i8 z$mG8nJ>M=~e)rTTJ>A`d>4aQQLRw8l=v_?ybvkvDRp^y*j5W#f04pJbb1R+2OuH4+n1DsMw z;eoX{Yr$Et4&f;Tg3GcQM+?#Nt^6-m2A9OWDWCD+D%Fq-TvVlkH zwt*Co4Gc}Gb-uyZq>_g1Ev|Cx^{0nq{+aD7Pqgq}TgK6t^k@t``Z^nUZFdWE7fJTcZ~^P_~g$Ar_1t(_O17!jE7bVa72-%9@Utiogutc>>qyr(D?t> zxPi&Z$?kK1%)T`>Tiu^Y2fF~Owc4*8t>$cgXYSLE`#b0E)c*?=RUdD@rmGhK0000< KMNUMnLSTaJnX07# literal 0 HcmV?d00001 diff --git a/lam/help/help.inc b/lam/help/help.inc index 44831df3..1f4c892d 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -248,7 +248,14 @@ $helpArray = array ( "Text" => _("This will create a new organisational unit under the selected one.")), "602" => array ("Headline" => _("OU-Editor") . " - " . _("Delete organisational unit"), "Text" => _("This will delete the selected organisational unit. The OU has to be empty.")), - + // 700 - 799 + // multi edit tool + "700" => array ("Headline" => _('LDAP suffix'), + "Text" => _('Please select the suffix where changes should be done.')), + "701" => array ("Headline" => _('LDAP filter'), + "Text" => _('Use this to enter an additional LDAP filter (e.g. "(cn!=admin)") to reduce the number of entries to modify.')), + "702" => array ("Headline" => _('Operations'), + "Text" => _('Please specify which attributes should be changed. The modify operation will also add an value if the attribute does not yet exist. To delete all values of an attribute please leave the value field empty.')), ); /* This is a sample help entry. Just copy this line an modify the values between the [] brackets. diff --git a/lam/lib/tools/fileUpload.inc b/lam/lib/tools/fileUpload.inc index af7a2fff..e90f27c8 100644 --- a/lam/lib/tools/fileUpload.inc +++ b/lam/lib/tools/fileUpload.inc @@ -96,7 +96,7 @@ class toolFileUpload implements LAMTool { * @return int prefered position */ function getPosition() { - return 200; + return 300; } /** diff --git a/lam/lib/tools/multiEdit.inc b/lam/lib/tools/multiEdit.inc new file mode 100644 index 00000000..90b4c9c0 --- /dev/null +++ b/lam/lib/tools/multiEdit.inc @@ -0,0 +1,131 @@ + \ No newline at end of file diff --git a/lam/lib/tools/ouEditor.inc b/lam/lib/tools/ouEditor.inc index b44c8a70..81769e63 100644 --- a/lam/lib/tools/ouEditor.inc +++ b/lam/lib/tools/ouEditor.inc @@ -96,7 +96,7 @@ class toolOUEditor implements LAMTool { * @return int prefered position */ function getPosition() { - return 300; + return 500; } /** diff --git a/lam/lib/tools/pdfEdit.inc b/lam/lib/tools/pdfEdit.inc index 33cfffc4..f3c36650 100644 --- a/lam/lib/tools/pdfEdit.inc +++ b/lam/lib/tools/pdfEdit.inc @@ -96,7 +96,7 @@ class toolPDFEditor implements LAMTool { * @return int prefered position */ function getPosition() { - return 400; + return 200; } /** diff --git a/lam/lib/tools/schemaBrowser.inc b/lam/lib/tools/schemaBrowser.inc index adea0b71..dbe9b38e 100644 --- a/lam/lib/tools/schemaBrowser.inc +++ b/lam/lib/tools/schemaBrowser.inc @@ -96,7 +96,7 @@ class toolSchemaBrowser implements LAMTool { * @return int prefered position */ function getPosition() { - return 500; + return 600; } /** diff --git a/lam/lib/tools/serverInfo.inc b/lam/lib/tools/serverInfo.inc index b49f27e5..4f979f90 100644 --- a/lam/lib/tools/serverInfo.inc +++ b/lam/lib/tools/serverInfo.inc @@ -96,7 +96,7 @@ class toolServerInformation implements LAMTool { * @return int prefered position */ function getPosition() { - return 600; + return 700; } /** diff --git a/lam/style/500_layout.css b/lam/style/500_layout.css index 9fc1184f..62144359 100644 --- a/lam/style/500_layout.css +++ b/lam/style/500_layout.css @@ -211,6 +211,11 @@ table.collapse { background-position: 0px 0px !important; } +.dryRunButton { + background-image: url(../graphics/dryRun.png) !important; + background-position: 0px 0px !important; +} + .smallPadding span { padding: 0.1em 0.4em !important; } diff --git a/lam/templates/multiEdit.php b/lam/templates/multiEdit.php new file mode 100644 index 00000000..5b1083b6 --- /dev/null +++ b/lam/templates/multiEdit.php @@ -0,0 +1,257 @@ +'; + echo ("
\n"); + $errors = array(); + $tabindex = 1; + $container = new htmlTable(); + $container->addElement(new htmlTitle(_("Multi edit")), true); + // LDAP suffix + $showRules = array('-' => array('otherSuffix')); + $hideRules = array(); + $container->addElement(new htmlOutputText(_('LDAP suffix'))); + $suffixGroup = new htmlTable(); + $types = $_SESSION['config']->get_ActiveTypes(); + $suffixes = array(); + foreach ($types as $type) { + $suffixes[getTypeAlias($type)] = $_SESSION['config']->get_Suffix($type); + $hideRules[$_SESSION['config']->get_Suffix($type)] = array('otherSuffix'); + } + $treeSuffix = $_SESSION['config']->get_Suffix('tree'); + if (!empty($treeSuffix)) { + $suffixes[_('Tree view')] = $_SESSION['config']->get_Suffix('tree'); + $hideRules[$_SESSION['config']->get_Suffix('tree')] = array('otherSuffix'); + } + $suffixes = array_flip($suffixes); + natcasesort($suffixes); + $suffixes = array_flip($suffixes); + $suffixes[_('other')] = '-'; + $suffixValues = array_values($suffixes); + $valSuffix = empty($_POST['suffix']) ? $suffixValues[0] : $_POST['suffix']; + $suffixSelect = new htmlSelect('suffix', $suffixes, array($valSuffix)); + $suffixSelect->setHasDescriptiveElements(true); + $suffixSelect->setSortElements(false); + $suffixSelect->setTableRowsToShow($showRules); + $suffixSelect->setTableRowsToHide($hideRules); + $suffixGroup->addElement($suffixSelect); + $otherSuffixTable = new htmlTable(); + $valOtherSuffix = empty($_POST['otherSuffix']) ? '' : $_POST['otherSuffix']; + $otherSuffixTable->addElement(new htmlInputField('otherSuffix')); + $suffixGroup->addElement($otherSuffixTable); + $container->addElement($suffixGroup); + $container->addElement(new htmlHelpLink('700'), true); + // LDAP filter + $valFilter = empty($_POST['filter']) ? '' : $_POST['filter']; + $container->addElement(new htmlTableExtendedInputField(_('LDAP filter'), 'filter', $valFilter, '701'), true); + // operation fields + $container->addElement(new htmlSubTitle(_('Operations')), true); + $container->addElement(new htmlOutputText(_('Type'))); + $container->addElement(new htmlOutputText(_('Attribute name'))); + $container->addElement(new htmlOutputText(_('Value'))); + $container->addElement(new htmlHelpLink('702'), true); + $opCount = empty($_POST['opcount']) ? '3' : $_POST['opcount']; + if (isset($_POST['addFields'])) { + $opCount += 3; + } + $operations = array(_('Add') => ADD, _('Modify') => MOD, _('Delete') => DEL); + for ($i = 0; $i < $opCount; $i++) { + // operation type + $selOp = empty($_POST['op_' . $i]) ? ADD : $_POST['op_' . $i]; + $opSelect = new htmlSelect('op_' . $i, $operations, array($selOp)); + $opSelect->setHasDescriptiveElements(true); + $container->addElement($opSelect); + // attribute name + $attrVal = empty($_POST['attr_' . $i]) ? '' : $_POST['attr_' . $i]; + $container->addElement(new htmlInputField('attr_' . $i, $attrVal)); + $valVal = empty($_POST['val_' . $i]) ? '' : $_POST['val_' . $i]; + $container->addElement(new htmlInputField('val_' . $i, $valVal), true); + // check input + if (($selOp == ADD) && !empty($attrVal) && empty($valVal)) { + $errors[] = new htmlStatusMessage('ERROR', _('Please enter a value to add.'), htmlspecialchars($attrVal)); + } + if (($selOp == MOD) && !empty($attrVal) && empty($valVal)) { + $errors[] = new htmlStatusMessage('ERROR', _('Please enter a value to modify.'), htmlspecialchars($attrVal)); + } + } + // add more fields + $container->addVerticalSpace('5px'); + $container->addElement(new htmlButton('addFields', _('Add more fields'))); + $container->addElement(new htmlHiddenInput('opcount', $opCount), true); + // error messages + if (sizeof($errors) > 0) { + $container->addVerticalSpace('20px'); + foreach ($errors as $error) { + $error->colspan = 5; + $container->addElement($error, true); + } + } + // action buttons + $container->addVerticalSpace('20px'); + $buttonGroup = new htmlGroup(); + $buttonGroup->colspan = 3; + $dryRunButton = new htmlButton('dryRun', _('Dry run')); + $dryRunButton->setIconClass('dryRunButton'); + $buttonGroup->addElement($dryRunButton); + $buttonGroup->addElement(new htmlSpacer('10px', null)); + $applyButton = new htmlButton('applyChanges', _('Apply changes')); + $applyButton->setIconClass('saveButton'); + $buttonGroup->addElement($applyButton); + $container->addElement($buttonGroup, true); + $container->addVerticalSpace('10px'); + + // run actions + if ((sizeof($errors) == 0) && (isset($_POST['dryRun']) || isset($_POST['applyChanges']))) { + runActions($container); + } + + + parseHtml(null, $container, array(), false, $tabindex, 'user'); + echo ("
\n"); + echo ''; + include 'main_footer.php'; +} + +/** + * Runs the dry run and change actions. + * + * @param htmlTable $container container + */ +function runActions(&$container) { + // LDAP suffix + if ($_POST['suffix'] == '-') { + $suffix = trim($_POST['otherSuffix']); + } + else { + $suffix = $_POST['suffix']; + } + if (empty($suffix)) { + $error = new htmlStatusMessage('ERROR', _('LDAP Suffix is invalid!')); + $error->colspan = 5; + $container->addElement($error); + return; + } + // LDAP filter + $filter = trim($_POST['filter']); + // operations + $operations = array(); + for ($i = 0; $i < sizeof($_POST['opcount']); $i++) { + if (!empty($_POST['attr_' . $i])) { + $operations[] = array($_POST['op_' . $i], $_POST['attr_' . $i], $_POST['val_' . $i]); + } + } + if (sizeof($operations) == 0) { + $error = new htmlStatusMessage('ERROR', _('Please specify at least one operation.')); + $error->colspan = 5; + $container->addElement($error); + return; + } + $_SESSION['multiEdit_suffix'] = $suffix; + $_SESSION['multiEdit_filter'] = $filter; + $_SESSION['multiEdit_operations'] = $operations; + $_SESSION['multiEdit_status'] = null; + // disable all input elements + $jsContent = ' + jQuery(\'input\').attr(\'disabled\', true); + jQuery(\'select\').attr(\'disabled\', true); + jQuery(\'button\').attr(\'disabled\', true); + '; + $container->addElement(new htmlJavaScript($jsContent), true); + // progress area + $container->addElement(new htmlSubTitle(_('Progress')), true); + $progressDiv = new htmlDiv('progressArea', ''); + $progressDiv->colspan = 5; + $container->addElement($progressDiv, true); + // JS block for AJAX status update + $ajaxBlock = ' + jQuery.get(\'multiEdit.php?ajaxStatus\', null, function(data) {handleReply(data);}, \'json\'); + + function handleReply(data) { + jQuery(\'#progressArea\').html(data.content); + if (data.status != "finished") { + jQuery.get(\'multiEdit.php?ajaxStatus\', null, function(data) {handleReply(data);}, \'json\'); + } + else { + jQuery(\'input\').removeAttr(\'disabled\'); + jQuery(\'select\').removeAttr(\'disabled\'); + jQuery(\'button\').removeAttr(\'disabled\'); + } + } + '; + $container->addElement(new htmlJavaScript($ajaxBlock), true); +} + +/** + * Performs the modify operations. + */ +function runAjaxActions() { + $jsonReturn = array( + 'status' => 'finished', + 'content' => 'content' + ); + echo json_encode($jsonReturn); +} +