multi edit tool
This commit is contained in:
parent
b323d66ffd
commit
8bc0489f39
|
@ -141,8 +141,8 @@ if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_po
|
||||||
$progress = ($_SESSION['mass_counter'] * 100) / sizeof($accounts);
|
$progress = ($_SESSION['mass_counter'] * 100) / sizeof($accounts);
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
jQuery(function() {
|
||||||
$( "#progressbarGeneral" ).progressbar({
|
jQuery( "#progressbarGeneral" ).progressbar({
|
||||||
value: <?php echo $progress; ?>
|
value: <?php echo $progress; ?>
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -161,8 +161,8 @@ if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_po
|
||||||
?>
|
?>
|
||||||
<div id="progressbar<?php echo $return['module']; ?>"></div>
|
<div id="progressbar<?php echo $return['module']; ?>"></div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
jQuery(function() {
|
||||||
$( "#progressbar<?php echo $return['module']; ?>" ).progressbar({
|
jQuery( "#progressbar<?php echo $return['module']; ?>" ).progressbar({
|
||||||
value: <?php echo $return['progress']; ?>
|
value: <?php echo $return['progress']; ?>
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -203,8 +203,8 @@ if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_po
|
||||||
?>
|
?>
|
||||||
<div id="progressbarPDF"></div>
|
<div id="progressbarPDF"></div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
jQuery(function() {
|
||||||
$( "#progressbarPDF" ).progressbar({
|
jQuery( "#progressbarPDF" ).progressbar({
|
||||||
value: <?php echo $progress; ?>
|
value: <?php echo $progress; ?>
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,6 +51,12 @@ const ADD = 'add';
|
||||||
const MOD = 'mod';
|
const MOD = 'mod';
|
||||||
const DEL = 'del';
|
const DEL = 'del';
|
||||||
|
|
||||||
|
const STAGE_START = 'start';
|
||||||
|
const STAGE_READ_FINISHED = 'readFinished';
|
||||||
|
const STAGE_ACTIONS_CALCULATED = 'actionsCalculated';
|
||||||
|
const STAGE_WRITING = 'writing';
|
||||||
|
const STAGE_FINISHED = 'finished';
|
||||||
|
|
||||||
if (isset($_GET['ajaxStatus'])) {
|
if (isset($_GET['ajaxStatus'])) {
|
||||||
runAjaxActions();
|
runAjaxActions();
|
||||||
}
|
}
|
||||||
|
@ -200,7 +206,7 @@ function runActions(&$container) {
|
||||||
$operations = array();
|
$operations = array();
|
||||||
for ($i = 0; $i < sizeof($_POST['opcount']); $i++) {
|
for ($i = 0; $i < sizeof($_POST['opcount']); $i++) {
|
||||||
if (!empty($_POST['attr_' . $i])) {
|
if (!empty($_POST['attr_' . $i])) {
|
||||||
$operations[] = array($_POST['op_' . $i], $_POST['attr_' . $i], $_POST['val_' . $i]);
|
$operations[] = array($_POST['op_' . $i], strtolower(trim($_POST['attr_' . $i])), trim($_POST['val_' . $i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sizeof($operations) == 0) {
|
if (sizeof($operations) == 0) {
|
||||||
|
@ -212,7 +218,8 @@ function runActions(&$container) {
|
||||||
$_SESSION['multiEdit_suffix'] = $suffix;
|
$_SESSION['multiEdit_suffix'] = $suffix;
|
||||||
$_SESSION['multiEdit_filter'] = $filter;
|
$_SESSION['multiEdit_filter'] = $filter;
|
||||||
$_SESSION['multiEdit_operations'] = $operations;
|
$_SESSION['multiEdit_operations'] = $operations;
|
||||||
$_SESSION['multiEdit_status'] = null;
|
$_SESSION['multiEdit_status'] = array('stage' => STAGE_START);
|
||||||
|
$_SESSION['multiEdit_dryRun'] = isset($_POST['dryRun']);
|
||||||
// disable all input elements
|
// disable all input elements
|
||||||
$jsContent = '
|
$jsContent = '
|
||||||
jQuery(\'input\').attr(\'disabled\', true);
|
jQuery(\'input\').attr(\'disabled\', true);
|
||||||
|
@ -222,6 +229,9 @@ function runActions(&$container) {
|
||||||
$container->addElement(new htmlJavaScript($jsContent), true);
|
$container->addElement(new htmlJavaScript($jsContent), true);
|
||||||
// progress area
|
// progress area
|
||||||
$container->addElement(new htmlSubTitle(_('Progress')), true);
|
$container->addElement(new htmlSubTitle(_('Progress')), true);
|
||||||
|
$progressBarDiv = new htmlDiv('progressBar', '');
|
||||||
|
$progressBarDiv->colspan = 5;
|
||||||
|
$container->addElement($progressBarDiv, true);
|
||||||
$progressDiv = new htmlDiv('progressArea', '');
|
$progressDiv = new htmlDiv('progressArea', '');
|
||||||
$progressDiv->colspan = 5;
|
$progressDiv->colspan = 5;
|
||||||
$container->addElement($progressDiv, true);
|
$container->addElement($progressDiv, true);
|
||||||
|
@ -230,6 +240,7 @@ function runActions(&$container) {
|
||||||
jQuery.get(\'multiEdit.php?ajaxStatus\', null, function(data) {handleReply(data);}, \'json\');
|
jQuery.get(\'multiEdit.php?ajaxStatus\', null, function(data) {handleReply(data);}, \'json\');
|
||||||
|
|
||||||
function handleReply(data) {
|
function handleReply(data) {
|
||||||
|
jQuery(\'#progressBar\').progressbar({value: data.progress, max: 120});
|
||||||
jQuery(\'#progressArea\').html(data.content);
|
jQuery(\'#progressArea\').html(data.content);
|
||||||
if (data.status != "finished") {
|
if (data.status != "finished") {
|
||||||
jQuery.get(\'multiEdit.php?ajaxStatus\', null, function(data) {handleReply(data);}, \'json\');
|
jQuery.get(\'multiEdit.php?ajaxStatus\', null, function(data) {handleReply(data);}, \'json\');
|
||||||
|
@ -238,6 +249,7 @@ function runActions(&$container) {
|
||||||
jQuery(\'input\').removeAttr(\'disabled\');
|
jQuery(\'input\').removeAttr(\'disabled\');
|
||||||
jQuery(\'select\').removeAttr(\'disabled\');
|
jQuery(\'select\').removeAttr(\'disabled\');
|
||||||
jQuery(\'button\').removeAttr(\'disabled\');
|
jQuery(\'button\').removeAttr(\'disabled\');
|
||||||
|
jQuery(\'#progressBar\').hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
';
|
';
|
||||||
|
@ -249,9 +261,120 @@ function runActions(&$container) {
|
||||||
*/
|
*/
|
||||||
function runAjaxActions() {
|
function runAjaxActions() {
|
||||||
$jsonReturn = array(
|
$jsonReturn = array(
|
||||||
'status' => 'finished',
|
'status' => STAGE_START,
|
||||||
'content' => 'content'
|
'progress' => 0,
|
||||||
|
'content' => ''
|
||||||
);
|
);
|
||||||
|
switch ($_SESSION['multiEdit_status']['stage']) {
|
||||||
|
case STAGE_START:
|
||||||
|
$jsonReturn = readLDAPData();
|
||||||
|
break;
|
||||||
|
case STAGE_READ_FINISHED:
|
||||||
|
$jsonReturn = generateActions();
|
||||||
|
break;
|
||||||
|
case STAGE_ACTIONS_CALCULATED:
|
||||||
|
if ($_SESSION['multiEdit_dryRun']) {
|
||||||
|
$jsonReturn = dryRun();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$jsonReturn = doModify();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
echo json_encode($jsonReturn);
|
echo json_encode($jsonReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the LDAP entries from the directory.
|
||||||
|
*
|
||||||
|
* @return array status
|
||||||
|
*/
|
||||||
|
function readLDAPData() {
|
||||||
|
$suffix = $_SESSION['multiEdit_suffix'];
|
||||||
|
$filter = $_SESSION['multiEdit_filter'];
|
||||||
|
if (empty($filter)) {
|
||||||
|
$filter = '(objectClass=*)';
|
||||||
|
}
|
||||||
|
$operations = $_SESSION['multiEdit_operations'];
|
||||||
|
$attributes = array();
|
||||||
|
foreach ($operations as $op) {
|
||||||
|
if (!in_array(strtolower($op[1]), $attributes)) {
|
||||||
|
$attributes[] = strtolower($op[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// run LDAP query
|
||||||
|
$results = searchLDAP($suffix, $filter, $attributes);
|
||||||
|
// print error message if no data returned
|
||||||
|
if (empty($results)) {
|
||||||
|
$code = ldap_errno($_SESSION['ldap']->server());
|
||||||
|
if ($code !== 0) {
|
||||||
|
$msg = new htmlStatusMessage('ERROR', _('Encountered an error while performing search.'), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$msg = new htmlStatusMessage('ERROR', _('No objects found!'));
|
||||||
|
}
|
||||||
|
$tabindex = 0;
|
||||||
|
ob_start();
|
||||||
|
parseHtml(null, $msg, array(), true, $tabindex, 'user');
|
||||||
|
$content = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
return array(
|
||||||
|
'status' => STAGE_FINISHED,
|
||||||
|
'progress' => 120,
|
||||||
|
'content' => $content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// save LDAP data
|
||||||
|
$_SESSION['multiEdit_status']['entries'] = $results;
|
||||||
|
$_SESSION['multiEdit_status']['stage'] = STAGE_READ_FINISHED;
|
||||||
|
return array(
|
||||||
|
'status' => STAGE_READ_FINISHED,
|
||||||
|
'progress' => 10,
|
||||||
|
'content' => ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the required actions based on the read LDAP data.
|
||||||
|
*
|
||||||
|
* @return array status
|
||||||
|
*/
|
||||||
|
function generateActions() {
|
||||||
|
$actions = array();
|
||||||
|
foreach ($_SESSION['multiEdit_status']['entries'] as $entry) {
|
||||||
|
foreach ($_SESSION['multiEdit_operations'] as $op) {
|
||||||
|
$opType = $op[0];
|
||||||
|
$attr = $op[1];
|
||||||
|
$val = $op[2];
|
||||||
|
switch ($opType) {
|
||||||
|
case ADD:
|
||||||
|
if (empty($entry[$attr]) || !in_array_ignore_case($val, $entry[$attr])) {
|
||||||
|
$actions[] = array(ADD, $attr, $val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MOD:
|
||||||
|
if (empty($entry[$attr]) || !in_array_ignore_case($val, $entry[$attr])) {
|
||||||
|
$actions[] = array(ADD, $attr, $val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DEL:
|
||||||
|
if (empty($val) && !empty($entry[$attr])) {
|
||||||
|
$actions[] = array(MOD, $attr, array());
|
||||||
|
}
|
||||||
|
elseif (!empty($val) && in_array($val, $entry[$attr])) {
|
||||||
|
$actions[] = array(DEL, $attr, array($val));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// save actions
|
||||||
|
$_SESSION['multiEdit_status']['actions'] = $actions;
|
||||||
|
$_SESSION['multiEdit_status']['stage'] = STAGE_ACTIONS_CALCULATED;
|
||||||
|
return array(
|
||||||
|
'status' => STAGE_ACTIONS_CALCULATED,
|
||||||
|
'progress' => 20,
|
||||||
|
'content' => ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue