New feature: Copy a DN and edit values before creation

This commit is contained in:
Deon George 2010-03-17 13:16:26 +11:00
parent 2e8e9625d6
commit 1c467a6115
4 changed files with 66 additions and 17 deletions

View File

@ -62,6 +62,32 @@ if ($request['recursive']) {
$copy_message = $copy_result;
print '</small>';
} else {
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);
$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']);
@ -74,6 +100,7 @@ if ($request['recursive']) {
$request['remove'] ? _('Move NOT successful') : _('Copy NOT successful'),
_('DN'),$request['dnDST'],_('has NOT been created.'));
}
}
if ($copy_result) {
$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&refresh=SID_%s_nodes&noheader=1',

View File

@ -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';

View File

@ -49,6 +49,7 @@ class TemplateRender extends PageRender {
$this->page = get_request('page','REQUEST',false,1);
if ($this->template_id) {
if (! $this->template)
parent::accept();
$this->url_base = sprintf('server_id=%s&dn=%s',
@ -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('<input type="hidden" name="container" value="%s" />',htmlspecialchars($this->template->getContainer()));
echo '<div><table>';
$this->drawRDNChooser();
echo '</table></div>';
$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 '</div>';
}
protected function drawForm() {
protected function drawForm($nosubmit=false) {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
echo '<div>';
@ -1372,6 +1382,7 @@ class TemplateRender extends PageRender {
echo '<table class="entry" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto;">';
$this->drawShownAttributes();
if (! $nosubmit)
$this->drawFormSubmitButton();
echo '</table>';

View File

@ -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);