multi edit tool

This commit is contained in:
Roland Gruber 2013-11-17 19:05:10 +00:00
parent d2e078c269
commit b1d5aa8ac2
10 changed files with 406 additions and 6 deletions

BIN
lam/graphics/dryRun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

View File

@ -248,7 +248,14 @@ $helpArray = array (
"Text" => _("This will create a new organisational unit under the selected one.")), "Text" => _("This will create a new organisational unit under the selected one.")),
"602" => array ("Headline" => _("OU-Editor") . " - " . _("Delete organisational unit"), "602" => array ("Headline" => _("OU-Editor") . " - " . _("Delete organisational unit"),
"Text" => _("This will delete the selected organisational unit. The OU has to be empty.")), "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. /* This is a sample help entry. Just copy this line an modify the values between the [] brackets.

View File

@ -96,7 +96,7 @@ class toolFileUpload implements LAMTool {
* @return int prefered position * @return int prefered position
*/ */
function getPosition() { function getPosition() {
return 200; return 300;
} }
/** /**

131
lam/lib/tools/multiEdit.inc Normal file
View File

@ -0,0 +1,131 @@
<?php
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Multi edit tool that allows LDAP operations on multiple entries.
*
* @author Roland Gruber
* @package tools
*/
/**
* Multi edit tool that allows LDAP operations on multiple entries.
*
* @package tools
*/
class toolMultiEdit implements LAMTool {
/**
* Returns the name of the tool.
*
* @return string name
*/
function getName() {
return _("Multi edit");
}
/**
* returns a description text for the tool.
*
* @return string description
*/
function getDescription() {
return _("Performs modifications on multiple LDAP entries.");
}
/**
* Returns a link to the tool page (relative to templates/).
*
* @return string link
*/
function getLink() {
return "multiEdit.php";
}
/**
* Returns if the tool requires write access to LDAP.
*
* @return boolean true if write access is needed
*/
function getRequiresWriteAccess() {
return true;
}
/**
* Returns if the tool requires password change rights.
*
* @return boolean true if password change rights are needed
*/
function getRequiresPasswordChangeRights() {
return true;
}
/**
* Returns the link to the tool image (relative to graphics/)
*
* @return string image URL
*/
function getImageLink() {
return 'edit.png';
}
/**
* Returns the prefered position of this tool on the tools page.
* The position may be between 0 and 1000. 0 is the top position.
*
* @return int prefered position
*/
function getPosition() {
return 400;
}
/**
* Returns a list of sub tools or an empty array.
*
* @return array list of subtools (LAMTool)
*/
function getSubTools() {
return array();
}
/**
* Returns if the tool is visible in the menu.
*
* @return boolean visible
*/
function isVisible() {
return true;
}
/**
* Returns if a tool may be hidden by configuration in the LAM server profile.
*
* @return boolean hideable
*/
function isHideable() {
return true;
}
}
?>

View File

@ -96,7 +96,7 @@ class toolOUEditor implements LAMTool {
* @return int prefered position * @return int prefered position
*/ */
function getPosition() { function getPosition() {
return 300; return 500;
} }
/** /**

View File

@ -96,7 +96,7 @@ class toolPDFEditor implements LAMTool {
* @return int prefered position * @return int prefered position
*/ */
function getPosition() { function getPosition() {
return 400; return 200;
} }
/** /**

View File

@ -96,7 +96,7 @@ class toolSchemaBrowser implements LAMTool {
* @return int prefered position * @return int prefered position
*/ */
function getPosition() { function getPosition() {
return 500; return 600;
} }
/** /**

View File

@ -96,7 +96,7 @@ class toolServerInformation implements LAMTool {
* @return int prefered position * @return int prefered position
*/ */
function getPosition() { function getPosition() {
return 600; return 700;
} }
/** /**

View File

@ -211,6 +211,11 @@ table.collapse {
background-position: 0px 0px !important; background-position: 0px 0px !important;
} }
.dryRunButton {
background-image: url(../graphics/dryRun.png) !important;
background-position: 0px 0px !important;
}
.smallPadding span { .smallPadding span {
padding: 0.1em 0.4em !important; padding: 0.1em 0.4em !important;
} }

257
lam/templates/multiEdit.php Normal file
View File

@ -0,0 +1,257 @@
<?php
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Multi edit tool that allows LDAP operations on multiple entries.
*
* @author Roland Gruber
* @package tools
*/
/** security functions */
include_once("../lib/security.inc");
/** access to configuration data */
include_once("../lib/config.inc");
/** access LDAP server */
include_once("../lib/ldap.inc");
/** used to print status messages */
include_once("../lib/status.inc");
// start session
startSecureSession();
// die if no write access
if (!checkIfWriteAccessIsAllowed()) die();
checkIfToolIsActive('toolMultiEdit');
setlanguage();
const ADD = 'add';
const MOD = 'mod';
const DEL = 'del';
if (isset($_GET['ajaxStatus'])) {
runAjaxActions();
}
else {
displayStartPage();
}
/**
* Displays the main page of the multi edit tool.
*/
function displayStartPage() {
// display main page
include 'main_header.php';
echo '<div class="user-bright smallPaddingContent">';
echo ("<form action=\"multiEdit.php\" method=\"post\">\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 ("</form>\n");
echo '</div>';
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);
}