From 4cab46a55e8d9fa668a86a62c34aa0acf51c1f2c Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 7 Jul 2009 19:40:48 +1000 Subject: [PATCH] New Feature: Mass Edit --- htdocs/mass_delete.php | 6 ++ htdocs/mass_edit.php | 128 ++++++++++++++++++++++++++++++ htdocs/mass_update.php | 175 +++++++++++++++++++++++++++++++++++++++++ lib/MassRender.php | 48 +++++++++++ lib/QueryRender.php | 8 +- lib/config_default.php | 2 + 6 files changed, 365 insertions(+), 2 deletions(-) create mode 100644 htdocs/mass_edit.php create mode 100644 htdocs/mass_update.php create mode 100644 lib/MassRender.php diff --git a/htdocs/mass_delete.php b/htdocs/mass_delete.php index cc87010..4956d36 100644 --- a/htdocs/mass_delete.php +++ b/htdocs/mass_delete.php @@ -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']); diff --git a/htdocs/mass_edit.php b/htdocs/mass_edit.php new file mode 100644 index 0000000..beb2b5b --- /dev/null +++ b/htdocs/mass_edit.php @@ -0,0 +1,128 @@ +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: %s',_('Server'),$app['server']->getName())); + +echo '
'; +echo ''; +printf('',$app['server']->getIndex()); + +foreach ($request['page'] as $j => $page) + printf('',$j,$page->getTemplate()->getDN()); + +echo ''; +echo ''; +echo ''; + +foreach ($attrcols as $attribute) { + echo ''; +} + +echo ''; + +$counter = 0; +foreach ($request['page'] as $j => $page) { + $template = $page->getTemplate(); + + printf('',$counter++%2==0?'even':'odd'); + printf('', + $template->getDN(),substr($template->getDN(),0,20)); + + foreach ($attrcols as $attrcol) { + $attribute = $template->getAttribute($attrcol->getName()); + + echo ''; + } + + echo ''; +} + +echo '
DN'; + $request['page'][0]->draw('Name',$attribute); + echo '
%s...'; + 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('
%s
', _('Attribute not available')); + } + + echo '
'; +echo '
'; +printf('',_('Update Values')); +echo '
'; +?> diff --git a/htdocs/mass_update.php b/htdocs/mass_update.php new file mode 100644 index 0000000..0d489e8 --- /dev/null +++ b/htdocs/mass_update.php @@ -0,0 +1,175 @@ + $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: %s',_('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: %s
',$template->getDN(),_('Modification successful!')); + else + printf('%s: %s
',$template->getDN(),_('Modification NOT successful!')); + } + + } else { + echo '
'; + echo ''; + printf('',$app['server']->getIndex()); + echo ''; + + foreach ($request['update'] as $j => $page) + printf('',$j,$page->getTemplate()->getDN()); + + echo ''; + echo ''; + echo '
'; + + echo '
'; + + echo ''; + echo ''; + echo '
'; + printf(_('There will be %s updates done with this mass update'),sprintf('%s',count($request['update']))); + echo '
'; + + echo '
'; + + foreach ($request['update'] as $index => $page) { + $template = $page->getTemplate(); + + echo ''; + echo ''; + printf('',IMGDIR,get_icon($app['server']->getIndex(),$template->getDN())); + + printf('', + $app['server']->getIndex(),rawurlencode(dn_unescape($template->getDN())),htmlspecialchars(get_rdn($template->getDN()))); + echo ''; + + printf('', + htmlspecialchars(dn_unescape($template->getDN())),_('Old Value')); + + foreach ($template->getLDAPmodify(true,$index) as $attribute) { + echo ''; + echo ''; + + echo ''; + + # Show NEW Values + echo ''; + + # Show OLD Values + echo ''; + + echo ''; + } + + echo '
icon%s
 dn%s%s
 '; + $page->draw('Name',$attribute); + echo ''; + + if (! $attribute->getValueCount() || $attribute->isForceDelete()) { + printf('[%s]',_('attribute deleted')); + printf('',$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 ''; + + $page->draw('CurrentValue',$attribute,$key); + + # For multiple values, close the highlighting + if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues())) + echo ''; + + echo '
'; + printf('',$index,$attribute->getName(),$key,$value); + } + + echo '
'; + + if (! $attribute->getOldValues()) + printf('[%s]',_('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 ''; + + $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 ''; + + echo '
'; + } + + echo '
'; + + echo '
'; + } + + echo '
'; + printf('',_('Update Values')); + echo '
'; + } + +} else { + echo '
'; + echo _('You made no changes'); + echo '
'; +} +?> diff --git a/lib/MassRender.php b/lib/MassRender.php new file mode 100644 index 0000000..c9510f9 --- /dev/null +++ b/lib/MassRender.php @@ -0,0 +1,48 @@ +%s
',__METHOD__); + + $val = $attribute->getValue($i); + + if ($attribute->getHelper()) + echo '
'; + + printf('', + $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 ''; + $this->draw('AttributeHelper',$attribute,$i); + echo '
'; + } + } + + protected function drawMassFormReadWriteValueBinaryAttribute($attribute,$i,$j) { + $this->drawFormReadWriteValueBinaryAttribute($attribute,$i); + } + + protected function drawMassFormReadWriteValueJpegAttribute($attribute,$i,$j) { + $this->drawFormReadOnlyValueJpegAttribute($attribute,$i); + } +} +?> diff --git a/lib/QueryRender.php b/lib/QueryRender.php index 7394af3..abd05b7 100644 --- a/lib/QueryRender.php +++ b/lib/QueryRender.php @@ -208,7 +208,8 @@ class QueryRender extends PageRender { if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) { $mass_actions = array( ' ' => '', - _('delete') => 'mass_delete' + _('delete') => 'mass_delete', + _('edit') => 'mass_edit' ); } @@ -364,6 +365,9 @@ function hideall(key,except) { echo '
'; printf('',$server->getIndex()); + foreach ($this->template->resultsdata[$base]['attrs'] as $attr) + printf('',$attr); + echo ''; echo ''; @@ -394,7 +398,7 @@ function hideall(key,except) { # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) - printf('',$counter,$dn); + printf('',$counter,$dn); $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($dn)); printf('', diff --git a/lib/config_default.php b/lib/config_default.php index 70e8e92..f179356 100644 --- a/lib/config_default.php +++ b/lib/config_default.php @@ -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,
icon