Latest SANDPIT - MERGE from CVS (MERGE-GIT)
This commit is contained in:
@@ -1,138 +1,111 @@
|
||||
<?php
|
||||
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/create.php,v 1.48.2.4 2008/12/12 12:20:22 wurley Exp $
|
||||
// $Header$
|
||||
|
||||
/**
|
||||
* Creates a new object.
|
||||
*
|
||||
* Variables that come in as POST vars:
|
||||
* - new_dn
|
||||
* - required_attrs (an array with indices being the attributes,
|
||||
* and the values being their respective values)
|
||||
* - object_classes (rawurlencoded, and serialized array of objectClasses)
|
||||
* Creates a new object in LDAP.
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Page
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo: posixgroup with empty memberlist generates an error.
|
||||
*/
|
||||
|
||||
require './common.php';
|
||||
|
||||
if ($ldapserver->isReadOnly())
|
||||
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
|
||||
# If cancel was selected, we'll redirect
|
||||
if (get_request('cancel','REQUEST')) {
|
||||
header('Location: index.php');
|
||||
die();
|
||||
}
|
||||
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_create'))
|
||||
error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('create entry')),'error','index.php');
|
||||
error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('create entry')),'error','index.php');
|
||||
|
||||
$rdn_attr = get_request('rdn_attribute');
|
||||
$request = array();
|
||||
$request['redirect'] = get_request('redirect','POST',false,false);
|
||||
|
||||
$entryfactoryclass = $_SESSION[APPCONFIG]->GetValue('appearance','entry_factory');
|
||||
eval('$entry_factory = new '.$entryfactoryclass.'();');
|
||||
$entry = $entry_factory->newCreatingEntry('');
|
||||
$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();
|
||||
|
||||
eval('$reader = new '.$_SESSION[APPCONFIG]->GetValue('appearance', 'entry_reader').'($ldapserver);');
|
||||
$entry->accept($reader);
|
||||
if (! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer()))
|
||||
error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),$request['template']->getContainer()),'error','index.php');
|
||||
|
||||
$container = $entry->getContainer();
|
||||
# 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());
|
||||
if (! $request['container'])
|
||||
$tree->addEntry($request['template']->getContainer());
|
||||
|
||||
if (!$container || !$ldapserver->dnExists($container))
|
||||
error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),htmlspecialchars($container)),'error','index.php');
|
||||
$request['container'] = $tree->getEntry($request['template']->getContainer());
|
||||
|
||||
$tree = get_cached_item($ldapserver->server_id,'tree');
|
||||
if ($tree) {
|
||||
$container_entry = $tree->getEntry($container);
|
||||
if (!$container_entry)
|
||||
$tree->addEntry($container);
|
||||
if ($request['container']->isLeaf())
|
||||
error(sprintf(_('The container (%s) is a leaf.'),$request['template']->getContainer()),'error','index.php');
|
||||
|
||||
$container_entry = $tree->getEntry($container);
|
||||
if ($container_entry->isLeaf())
|
||||
error(sprintf(_('The container (%s) is a leaf.'), htmlspecialchars($container)),'error','index.php');
|
||||
# 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.
|
||||
# @todo this isIgnoredAttr() function is missing?
|
||||
if ($attribute->isRequired() && ! count($attribute->getValues()) && ! $app['server']->isIgnoredAttr($attr->getName()))
|
||||
error(sprintf(_('You left the value blank for required attribute (%s).'),
|
||||
$attribute->getName(false)),'error','index.php');
|
||||
}
|
||||
|
||||
$entry->setRdnAttributeName($rdn_attr);
|
||||
if (!$entry->getRdnAttribute())
|
||||
error(sprintf(_('The Rdn attribute (%s) does not exist.'), htmlspecialchars($rdn_attr)),'error','index.php');
|
||||
|
||||
$new_dn = $entry->getDn();
|
||||
if (! $new_dn)
|
||||
error(_('You left the RDN field blank.'),'error','index.php');
|
||||
|
||||
$redirect = get_request('redirect','POST',false,false);
|
||||
|
||||
$new_entry = array();
|
||||
$attrs = $entry->getAttributes();
|
||||
foreach ($attrs as $attr) {
|
||||
$vals = $attr->getValues();
|
||||
$new_vals = array();
|
||||
foreach ($vals as $val) {
|
||||
if (strlen($val) > 0)
|
||||
$new_vals[] = $val;
|
||||
}
|
||||
|
||||
if ($attr->isRequired() && !$new_vals && !$ldapserver->isIgnoredAttr($attr->getName()))
|
||||
error(sprintf(_('You left the value blank for required attribute (%s).'),htmlspecialchars($attr->getName())),'error','index.php');
|
||||
|
||||
|
||||
if ($new_vals)
|
||||
$new_entry[$attr->getName()] = $new_vals;
|
||||
}
|
||||
|
||||
if (! in_array('top', $new_entry['objectClass']))
|
||||
$new_entry['objectClass'][] = 'top';
|
||||
|
||||
foreach ($new_entry as $attr => $vals) {
|
||||
# Check to see if this is a unique Attribute
|
||||
if ($badattr = $ldapserver->checkUniqueAttr($new_dn,$attr,$vals)) {
|
||||
$search_href = sprintf('?cmd=search&search=true&form=advanced&server_id=%s&filter=%s=%s', $ldapserver->server_id,$attr,$badattr);
|
||||
error(sprintf(_('Your attempt to add <b>%s</b> (<i>%s</i>) to <br><b>%s</b><br> is NOT allowed. That attribute/value belongs to another entry.<p>You might like to <a href=\'%s\'>search</a> for that entry.'),$attr,$badattr,$new_dn,$search_href),'error','index.php');
|
||||
}
|
||||
}
|
||||
|
||||
# Check the user-defined custom call back first
|
||||
if (run_hook('pre_entry_create',array('server_id'=>$ldapserver->server_id,'dn'=>$new_dn,'attrs'=>$new_entry)))
|
||||
$add_result = $ldapserver->add($new_dn,$new_entry);
|
||||
# Create the entry
|
||||
$add_result = $app['server']->add($request['template']->getDN(),$request['template']->getLDAPadd());
|
||||
|
||||
if ($add_result) {
|
||||
run_hook('post_entry_create',array('server_id'=>$ldapserver->server_id,'dn'=>$new_dn,'attrs'=>$new_entry));
|
||||
$action_number = $_SESSION[APPCONFIG]->getValue('appearance','action_after_creation');
|
||||
$href = sprintf('cmd=template_engine&server_id=%s',$app['server']->getIndex());
|
||||
|
||||
$action_number = $_SESSION[APPCONFIG]->GetValue('appearance', 'action_after_creation');
|
||||
if ($request['redirect'])
|
||||
$redirect_url = $request['redirect'];
|
||||
|
||||
$container = get_container($new_dn,false);
|
||||
//$container_container = get_container($container);
|
||||
else if ($action_number == 2)
|
||||
$redirect_url = sprintf('cmd.php?%s&template=%s&container=%s',
|
||||
$href,$request['template']->getID(),rawurlencode($request['template']->getContainer()));
|
||||
|
||||
if ($redirect) {
|
||||
$redirect_url = $redirect;
|
||||
} else if ($action_number == 2) {
|
||||
$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&container=%s', $ldapserver->server_id, rawurlencode($container));
|
||||
} else {
|
||||
$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', $ldapserver->server_id, rawurlencode($new_dn));
|
||||
}
|
||||
else
|
||||
$redirect_url = sprintf('cmd.php?%s&template=%s&dn=%s',
|
||||
$href,$request['template']->getID(),rawurlencode($request['template']->getDN()));
|
||||
|
||||
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 DN%s <b>%s</b> %s',_('Creation successful!'),_(':'),htmlspecialchars($new_dn),_('has been created.'));
|
||||
$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());
|
||||
|
||||
system_message(array(
|
||||
'title'=>_('Create Entry'),
|
||||
'body'=>$create_message,
|
||||
'type'=>'info'),
|
||||
$redirect_url);
|
||||
|
||||
} else {
|
||||
printf('<h3 class="title">%s</h3>',_('Entry created'));
|
||||
$request['page']->drawTitle(_('Entry created'));
|
||||
$request['page']->drawSubTitle(sprintf('%s: <b>%s</b> %s: <b>%s</b>',
|
||||
_('Server'),$app['server']->getName(),_('Distinguished Name'),$request['template']->getDN()));
|
||||
|
||||
echo '<br />';
|
||||
echo '<center>';
|
||||
printf('<a href="cmd.php?cmd=template_engine&server_id=%s&dn=%s">%s</a>.',$ldapserver->server_id,rawurlencode($new_dn),_('Display the new created entry'));
|
||||
printf('<a href="cmd.php?%s&dn=%s">%s</a>.',
|
||||
htmlspecialchars($href),rawurlencode($request['template']->getDN()),_('Display the new created entry'));
|
||||
echo '<br />';
|
||||
printf('<a href="cmd.php?cmd=template_engine&server_id=%s&container=%s">%s</a>.',$ldapserver->server_id,rawurlencode($container),_('Create another entry'));
|
||||
printf('<a href="cmd.php?%s&container=%s">%s</a>.',
|
||||
htmlspecialchars($href),rawurlencode($request['template']->getContainer()),_('Create another entry'));
|
||||
echo '</center>';
|
||||
}
|
||||
|
||||
} else {
|
||||
system_message(array(
|
||||
'title'=>_('Could not add the object to the LDAP server.'),
|
||||
'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()),
|
||||
'type'=>'error'));
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user