From 1c467a61155b633e30b9a72dd27a26459ca4674b Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 17 Mar 2010 13:16:26 +1100 Subject: [PATCH] New feature: Copy a DN and edit values before creation --- htdocs/copy.php | 45 +++++++++++++++++++++++++++++++++--------- lib/Template.php | 11 +++++++++-- lib/TemplateRender.php | 23 +++++++++++++++------ lib/config_default.php | 4 ++++ 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/htdocs/copy.php b/htdocs/copy.php index 6d68f12..588a1e0 100644 --- a/htdocs/copy.php +++ b/htdocs/copy.php @@ -63,16 +63,43 @@ if ($request['recursive']) { print ''; } else { - $copy_result = copy_dn($ldap['SRC'],$ldap['DST'],$request['dnSRC'],$request['dnDST'],$request['remove']); + if ($_SESSION[APPCONFIG]->getValue('confirm','copy')) { + $request['pageSRC'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,null)); + $request['pageSRC']->setDN($request['dnSRC']); + $request['pageSRC']->accept(true); - if ($copy_result) - $copy_message = sprintf('%s %s: %s %s', - $request['remove'] ? _('Move successful') : _('Copy successful'), - _('DN'),$request['dnDST'],_('has been created.')); - else - $copy_message = sprintf('%s %s: %s %s', - $request['remove'] ? _('Move NOT successful') : _('Copy NOT successful'), - _('DN'),$request['dnDST'],_('has NOT been created.')); + $request['pageDST'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none')); + $request['pageDST']->setContainer($app['server']->getContainer($request['dnDST'])); + $request['pageDST']->accept(true); + + $request['templateSRC'] = $request['pageSRC']->getTemplate(); + $request['templateDST'] = $request['pageDST']->getTemplate(); + + $request['templateDST']->copy($request['templateSRC'],get_rdn($request['dnDST']),true); + + # Set all attributes with a values as shown, and remove the add value options + foreach ($request['templateDST']->getAttributes(true) as $sattribute) + if ($sattribute->getValues() && ! $sattribute->isInternal()) { + $sattribute->show(); + $sattribute->setMaxValueCount(count($sattribute->getValues())); + } + + $request['pageDST']->accept(); + + return; + + } else { + $copy_result = copy_dn($ldap['SRC'],$ldap['DST'],$request['dnSRC'],$request['dnDST'],$request['remove']); + + if ($copy_result) + $copy_message = sprintf('%s %s: %s %s', + $request['remove'] ? _('Move successful') : _('Copy successful'), + _('DN'),$request['dnDST'],_('has been created.')); + else + $copy_message = sprintf('%s %s: %s %s', + $request['remove'] ? _('Move NOT successful') : _('Copy NOT successful'), + _('DN'),$request['dnDST'],_('has NOT been created.')); + } } if ($copy_result) { diff --git a/lib/Template.php b/lib/Template.php index 8b5ed4d..39d1daf 100644 --- a/lib/Template.php +++ b/lib/Template.php @@ -656,7 +656,7 @@ class Template extends xmlTemplate { /** * Copy a DN */ - public function copy($template,$rdn) { + public function copy($template,$rdn,$asnew=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); @@ -709,6 +709,11 @@ class Template extends xmlTemplate { else $attribute->setRDN($counter++); } + + # If we are copying into a new entry, we need to discard all the "old values" + if ($asnew) + foreach ($this->getAttributes(true) as $sattribute) + $sattribute->setOldValue(array()); } /** @@ -854,7 +859,9 @@ class Template extends xmlTemplate { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - if ($this->getContainer()) + if ($this->getContainer() && get_request('cmd','REQUEST') == 'copy') + return 'copyasnew'; + elseif ($this->getContainer() || get_request('create_base')) return 'create'; elseif ($this->getDN()) return 'edit'; diff --git a/lib/TemplateRender.php b/lib/TemplateRender.php index ce2d625..bdf3b0d 100644 --- a/lib/TemplateRender.php +++ b/lib/TemplateRender.php @@ -49,7 +49,8 @@ class TemplateRender extends PageRender { $this->page = get_request('page','REQUEST',false,1); if ($this->template_id) { - parent::accept(); + if (! $this->template) + parent::accept(); $this->url_base = sprintf('server_id=%s&dn=%s', $this->getServerID(),rawurlencode($this->template->getDN())); @@ -611,11 +612,11 @@ class TemplateRender extends PageRender { # If we have a DN, then we are an editing template if ($this->dn) - $this->template->setDN(get_request('dn','REQUEST')); + $this->template->setDN($this->dn); # Else if we have a container, we are a creating template - elseif ($this->container) - $this->template->setContainer(get_request('container','REQUEST')); + elseif ($this->container || get_request('create_base')) + $this->template->setContainer($this->container); else debug_dump_backtrace('Dont know what type of template we are - no DN or CONTAINER?',1); @@ -641,6 +642,15 @@ class TemplateRender extends PageRender { $this->drawStepForm($this->page); $this->drawStepFormEnd(); + } elseif ($this->template->getContext() == 'copyasnew') { + $this->drawStepFormStart($this->page); + printf('',htmlspecialchars($this->template->getContainer())); + echo '
'; + $this->drawRDNChooser(); + echo '
'; + $this->drawForm(true); + $this->drawStepFormSubmitButton($this->page); + } else { # Draw internal attributes if (get_request('show_internal_attrs','REQUEST')) { @@ -1360,7 +1370,7 @@ class TemplateRender extends PageRender { echo ''; } - protected function drawForm() { + protected function drawForm($nosubmit=false) { if (DEBUGTMP) printf('%s
',__METHOD__); echo '
'; @@ -1372,7 +1382,8 @@ class TemplateRender extends PageRender { echo ''; $this->drawShownAttributes(); - $this->drawFormSubmitButton(); + if (! $nosubmit) + $this->drawFormSubmitButton(); echo '
'; diff --git a/lib/config_default.php b/lib/config_default.php index 8cd80cd..e9d7117 100644 --- a/lib/config_default.php +++ b/lib/config_default.php @@ -284,6 +284,10 @@ class Config { /** Confirm actions */ + $this->default->confirm['copy'] = array( + 'desc'=>'Confirm copy actions', + 'default'=>true); + $this->default->confirm['create'] = array( 'desc'=>'Confirm creation actions', 'default'=>true);