New Feature: Mass Edit

This commit is contained in:
Deon George 2009-07-07 19:40:48 +10:00
parent e7ce1030c0
commit 4cab46a55e
6 changed files with 365 additions and 2 deletions

View File

@ -17,6 +17,12 @@ require './common.php';
$request = array();
$request['dn'] = get_request('dn','REQUEST');
if (! $request['dn'])
system_message(array(
'title'=>_('No entry selected'),
'body'=>_('No entry was selected to delete'),
'type'=>'warn'),'index.php');
if (! is_array($request['dn']))
$request['dn'] = array($request['dn']);

128
htdocs/mass_edit.php Normal file
View File

@ -0,0 +1,128 @@
<?php
/**
* Main command page for phpLDAPadmin
* Enable mass editing of Attribute values from a list of DNs.
*
* @package phpLDAPadmin
* @subpackage Page
*/
/**
*/
require_once './common.php';
# The DN we are working with
$request = array();
$request['dn'] = get_request('dn','REQUEST');
$request['attrs'] = get_request('attrs','REQUEST');
# Check if the entries exist.
$counter = 0;
$attrcols = array();
foreach ($request['dn'] as $dn) {
# Check if the entry exists.
if (! $dn || ! $app['server']->dnExists($dn)) {
system_message(array(
'title'=>_('Entry does not exist'),
'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn),
'type'=>'error'));
continue;
}
$request['page'][$counter] = new MassRender($app['server']->getIndex(),'none');
$request['page'][$counter]->setDN($dn);
$request['page'][$counter]->accept(true);
$template = $request['page'][$counter]->getTemplate();
# Mark our attributes to edit as shown.
foreach ($template->getAttributes(true) as $attribute) {
if ($attribute->isInternal())
continue;
if (in_array_ignore_case($attribute->getName(),$request['attrs']) || in_array('*',$request['attrs'])) {
$attribute->show();
# Get a list of our columns (we are not interested in these attribute values)
if (! isset($attrcols[$attribute->getName()]))
$attrcols[$attribute->getName()] = $attribute;
}
}
$counter++;
}
usort($attrcols,'sortAttrs');
if (! count($request['page']))
header('Location: index.php');
# We'll render this forms Title with the first DN's object.
$request['page'][0]->drawTitle(_('Bulk edit the following DNs'));
$request['page'][0]->drawSubTitle(sprintf('%s: <b>%s</b>',_('Server'),$app['server']->getName()));
echo '<form action="cmd.php" method="post">';
echo '<input type="hidden" name="cmd" value="mass_update" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
foreach ($request['page'] as $j => $page)
printf('<input type="hidden" name="dn[%s]" value="%s" />',$j,$page->getTemplate()->getDN());
echo '<table class="result_table" border=0>';
echo '<tr class="heading">';
echo '<td>DN</td>';
foreach ($attrcols as $attribute) {
echo '<td>';
$request['page'][0]->draw('Name',$attribute);
echo '</td>';
}
echo '</tr>';
$counter = 0;
foreach ($request['page'] as $j => $page) {
$template = $page->getTemplate();
printf('<tr class="%s">',$counter++%2==0?'even':'odd');
printf('<td><span style="white-space: nowrap;"><acronym title="%s"><b>%s</b>...</acronym></span></td>',
$template->getDN(),substr($template->getDN(),0,20));
foreach ($attrcols as $attrcol) {
$attribute = $template->getAttribute($attrcol->getName());
echo '<td>';
if ($attribute) {
foreach ($attribute->getValues() as $i => $val)
$page->draw('MassFormReadWriteValue',$attribute,$i,$j);
# The attribute doesnt exist. If it is available by the shema, we can draw an empty input box.
} else {
$match = false;
foreach ($template->getAvailAttrs() as $attribute) {
if ($attrcol->getName() == $attribute->getName()) {
$page->draw('MassFormReadWriteValue',$attribute,0,$j);
$match = true;
break;
}
}
if (! $match)
printf('<center><small>%s</small></center>', _('Attribute not available'));
}
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
echo '<br/>';
printf('<input type="submit" id="save_button" name="submit" value="%s" />',_('Update Values'));
echo '</form>';
?>

175
htdocs/mass_update.php Normal file
View File

@ -0,0 +1,175 @@
<?php
/**
* Main command page for phpLDAPadmin
* This script will handle bulk updates.
*
* @package phpLDAPadmin
* @subpackage Page
*/
/**
*/
require_once './common.php';
$request = array();
$request['dn'] = get_request('dn','REQUEST',true);
$request['mass_values'] = get_request('mass_values','REQUEST',true);
# Check if the entries exist.
$request['update'] = array();
foreach ($request['dn'] as $index => $dn) {
# Check if the entry exists.
if (! $dn || ! $app['server']->dnExists($dn)) {
system_message(array(
'title'=>_('Entry does not exist'),
'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn),
'type'=>'error'));
continue;
}
# Simulate the requirements for *Render->accept()
if (! isset($request['mass_values'][$index]))
continue;
$_REQUEST['new_values'] = $request['mass_values'][$index];
$render = new MassRender($app['server']->getIndex(),'none');
$render->setDN($dn);
$render->accept(true);
if ($render->getTemplate()->getLDAPmodify(false,$index))
$request['update'][$index] = $render;
}
# We can use the $render to give us a title
$render->drawTitle(_('Bulk update the following DNs'));
$render->drawSubTitle(sprintf('%s: <b>%s</b>',_('Server'),$app['server']->getName()));
if (count($request['update'])) {
if (get_request('confirm','REQUEST')) {
foreach ($request['update'] as $index => $page) {
$template = $page->getTemplate();
# Perform the modification
$result = $app['server']->modify($template->getDN(),$template->getLDAPmodify(false,$index));
if ($result)
printf('%s: <b>%s</b><br>',$template->getDN(),_('Modification successful!'));
else
printf('%s: <b>%s</b><br>',$template->getDN(),_('Modification NOT successful!'));
}
} else {
echo '<form action="cmd.php" method="post">';
echo '<input type="hidden" name="cmd" value="mass_update" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
echo '<input type="hidden" name="confirm" value="1" />';
foreach ($request['update'] as $j => $page)
printf('<input type="hidden" name="dn[%s]" value="%s" />',$j,$page->getTemplate()->getDN());
echo '<table class="result_box" width=100% border=1>';
echo '<tr><td>';
echo '<br/>';
echo '<table class="result" border=0>';
echo '<tr><td>';
printf(_('There will be %s updates done with this mass update'),sprintf('<b>%s</b>',count($request['update'])));
echo '</td></tr>';
echo '</table>';
echo '<br/>';
foreach ($request['update'] as $index => $page) {
$template = $page->getTemplate();
echo '<table class="result" border=0>';
echo '<tr class="list_title">';
printf('<td class="icon"><img src="%s/%s" alt="icon" /></td>',IMGDIR,get_icon($app['server']->getIndex(),$template->getDN()));
printf('<td colspan=3><a href="cmd.php?cmd=template_engine&amp;server_id=%s&amp;dn=%s">%s</a></td>',
$app['server']->getIndex(),rawurlencode(dn_unescape($template->getDN())),htmlspecialchars(get_rdn($template->getDN())));
echo '</tr>';
printf('<tr class="list_item"><td class="blank">&nbsp;</td><td class="heading">dn</td><td class="value" width="45%%">%s</td><td class="value" width="45%%"><b>%s</b></td></tr>',
htmlspecialchars(dn_unescape($template->getDN())),_('Old Value'));
foreach ($template->getLDAPmodify(true,$index) as $attribute) {
echo '<tr class="list_item">';
echo '<td class="blank">&nbsp;</td>';
echo '<td class="heading">';
$page->draw('Name',$attribute);
echo '</td>';
# Show NEW Values
echo '<td><span style="white-space: nowrap;">';
if (! $attribute->getValueCount() || $attribute->isForceDelete()) {
printf('<span style="color: red">[%s]</span>',_('attribute deleted'));
printf('<input type="hidden" name="mass_values[%s][%s][%s]" value="%s" />',$index,$attribute->getName(),0,'');
}
foreach ($attribute->getValues() as $key => $value) {
# For multiple values, we'll highlight the changed ones
if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues()))
echo '<span style="color:#004400; background:#FFFFA0">';
$page->draw('CurrentValue',$attribute,$key);
# For multiple values, close the highlighting
if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues()))
echo '</span>';
echo '<br />';
printf('<input type="hidden" name="mass_values[%s][%s][%s]" value="%s" />',$index,$attribute->getName(),$key,$value);
}
echo '</span></td>';
# Show OLD Values
echo '<td><span style="white-space: nowrap;">';
if (! $attribute->getOldValues())
printf('<span style="color: green">[%s]</span>',_('attribute doesnt exist'));
foreach ($attribute->getOldValues() as $key => $value) {
# For multiple values, we'll highlight the changed ones
if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues()))
echo '<span style="color:#880000; background:#FFFFA0">';
$page->draw('OldValue',$attribute,$key);
# For multiple values, close the highlighting
if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues()))
echo '</span>';
echo '<br />';
}
echo '</span></td>';
echo '</tr>';
}
echo '</table>';
echo '<br/>';
}
echo '</td></tr>';
echo '</table>';
printf('<input type="submit" id="save_button" name="submit" value="%s" />',_('Update Values'));
echo '</form>';
}
} else {
echo '<center>';
echo _('You made no changes');
echo '</center>';
}
?>

48
lib/MassRender.php Normal file
View File

@ -0,0 +1,48 @@
<?php
/**
* This class will render the editing of multiple LDAP entries.
*
* @author The phpLDAPadmin development team
* @package phpLDAPadmin
*/
/**
* TemplateRender class
*
* @package phpLDAPadmin
* @subpackage Templates
*/
class MassRender extends TemplateRender {
protected function drawMassFormReadWriteValueAttribute($attribute,$i,$j) {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$val = $attribute->getValue($i);
if ($attribute->getHelper())
echo '<table cellspacing="0" cellpadding="0" border=1><tr><td valign="top">';
printf('<input type="text" class="value" name="mass_values[%s][%s][%s]" id="new_values_%s_%s_%s" value="%s" %s%s %s %s/>',
$j,htmlspecialchars($attribute->getName()),$i,
$j,htmlspecialchars($attribute->getName()),$i,
htmlspecialchars($val),
$attribute->needJS('focus') ? sprintf('onFocus="focus_%s(this);" ',$attribute->getName()) : '',
$attribute->needJS('blur') ? sprintf('onBlur="blur_%s(this);" ',$attribute->getName()) : '',
($attribute->getSize() > 0) ? sprintf('size="%s"',$attribute->getSize()) : '',
($attribute->getMaxLength() > 0) ? sprintf('maxlength="%s"',$attribute->getMaxLength()) : '');
if ($attribute->getHelper()) {
echo '</td><td valign="top">';
$this->draw('AttributeHelper',$attribute,$i);
echo '</td></tr></table>';
}
}
protected function drawMassFormReadWriteValueBinaryAttribute($attribute,$i,$j) {
$this->drawFormReadWriteValueBinaryAttribute($attribute,$i);
}
protected function drawMassFormReadWriteValueJpegAttribute($attribute,$i,$j) {
$this->drawFormReadOnlyValueJpegAttribute($attribute,$i);
}
}
?>

View File

@ -208,7 +208,8 @@ class QueryRender extends PageRender {
if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) {
$mass_actions = array(
'&nbsp;' => '',
_('delete') => 'mass_delete'
_('delete') => 'mass_delete',
_('edit') => 'mass_edit'
);
}
@ -364,6 +365,9 @@ function hideall(key,except) {
echo '<form action="cmd.php" method="post" name="massform">';
printf('<input type="hidden" name="server_id" value="%s" />',$server->getIndex());
foreach ($this->template->resultsdata[$base]['attrs'] as $attr)
printf('<input type="hidden" name="attrs[]" value="%s" />',$attr);
echo '<table class="result_table" border=0>';
echo '<thead class="fixheader">';
@ -394,7 +398,7 @@ function hideall(key,except) {
# Is mass action enabled.
if ($_SESSION[APPCONFIG]->getValue('mass','enabled'))
printf('<td><input type="checkbox" id="ma%s" name="dn[]" value="%s"/ onclick="this.checked=!this.checked;"></td>',$counter,$dn);
printf('<td><input type="checkbox" id="ma%s" name="dn[]" value="%s" onclick="this.checked=!this.checked;" /></td>',$counter,$dn);
$href = sprintf('cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($dn));
printf('<td class="icon"><a href="cmd.php?%s"><img src="%s/%s" alt="icon" /></a></td>',

View File

@ -308,6 +308,8 @@ class Config {
'logout' => true,
'login_form' => true,
'mass_delete' => true,
'mass_edit' => true,
'mass_update' => true,
'modify_member_form' => true,
'monitor' => true,
'purge_cache' => true,