phpldapadmin/htdocs/create.php

104 lines
3.9 KiB
PHP
Raw Permalink Normal View History

2009-06-30 08:09:20 +00:00
<?php
2009-06-30 09:29:51 +00:00
/**
* Creates a new object in LDAP.
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
* @subpackage Page
2009-06-30 09:29:51 +00:00
*/
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:29:51 +00:00
require './common.php';
# If cancel was selected, we'll redirect
if (get_request('cancel','REQUEST')) {
header('Location: index.php');
die();
2009-06-30 08:05:37 +00:00
}
$request = array();
$request['redirect'] = get_request('redirect','POST',false,false);
$request['page'] = new PageRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none'));
$request['page']->setContainer(get_request('container','REQUEST',true));
$request['page']->accept();
$request['template'] = $request['page']->getTemplate();
2010-03-11 06:46:03 +00:00
if ((! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer())) && ! get_request('create_base'))
error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),$request['template']->getContainer()),'error','index.php');
# Check if the container is a leaf - we shouldnt really return a hit here, the template engine shouldnt have allowed a user to attempt to create an entry...
$tree = get_cached_item($app['server']->getIndex(),'tree');
$request['container'] = $tree->getEntry($request['template']->getContainer());
2010-03-11 06:46:03 +00:00
if (! $request['container'] && ! get_request('create_base')) {
$tree->addEntry($request['template']->getContainer());
$request['container'] = $tree->getEntry($request['template']->getContainer());
}
# Check our RDN
if (! count($request['template']->getRDNAttrs()))
error(_('The were no attributes marked as an RDN attribute.'),'error','index.php');
if (! $request['template']->getRDN())
error(_('The RDN field is empty?'),'error','index.php');
# Some other attribute checking...
foreach ($request['template']->getAttributes() as $attribute) {
# Check that our Required Attributes have a value - we shouldnt really return a hit here, the template engine shouldnt have allowed this to slip through.
if ($attribute->isRequired() && ! count($attribute->getValues()))
error(sprintf(_('You left the value blank for required attribute (%s).'),
$attribute->getName(false)),'error','index.php');
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:07:14 +00:00
# Create the entry
$add_result = $app['server']->add($request['template']->getDN(),$request['template']->getLDAPadd());
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ($add_result) {
$action_number = $_SESSION[APPCONFIG]->getValue('appearance','action_after_creation');
$href = sprintf('cmd=template_engine&server_id=%s',$app['server']->getIndex());
2009-06-30 09:29:51 +00:00
if ($request['redirect'])
$redirect_url = $request['redirect'];
2009-06-30 08:05:37 +00:00
else if ($action_number == 2)
$redirect_url = sprintf('cmd.php?%s&template=%s&container=%s',
$href,'default',$request['template']->getContainerEncode());
2009-06-30 08:05:37 +00:00
else
$redirect_url = sprintf('cmd.php?%s&template=%s&dn=%s',
$href,'default',$request['template']->getDNEncode());
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if ($action_number == 1 || $action_number == 2)
printf('<meta http-equiv="refresh" content="0; url=%s" />',$redirect_url);
if ($action_number == 1 || $action_number == 2) {
$create_message = sprintf('%s %s: <b>%s</b> %s',
_('Creation successful!'),_('DN'),$request['template']->getDN(),_('has been created.'));
if (isAjaxEnabled())
$redirect_url .= sprintf('&refresh=SID_%s_nodes&noheader=1',$app['server']->getIndex());
2009-06-30 10:46:00 +00:00
system_message(array(
'title'=>_('Create Entry'),
'body'=>$create_message,
'type'=>'info'),
$redirect_url);
2009-06-30 10:46:00 +00:00
} else {
$request['page']->drawTitle(_('Entry created'));
$request['page']->drawSubTitle(sprintf('%s: <b>%s</b>&nbsp;&nbsp;&nbsp;%s: <b>%s</b>',
_('Server'),$app['server']->getName(),_('Distinguished Name'),$request['template']->getDN()));
2009-06-30 10:46:00 +00:00
echo '<br />';
echo '<center>';
printf('<a href="cmd.php?%s&amp;dn=%s">%s</a>.',
htmlspecialchars($href),rawurlencode($request['template']->getDN()),_('Display the new created entry'));
2009-06-30 10:46:00 +00:00
echo '<br />';
printf('<a href="cmd.php?%s&amp;container=%s">%s</a>.',
htmlspecialchars($href),rawurlencode($request['template']->getContainer()),_('Create another entry'));
2009-06-30 10:46:00 +00:00
echo '</center>';
}
2009-06-30 09:29:51 +00:00
}
2009-06-30 08:05:37 +00:00
?>