phpldapadmin/htdocs/create.php

139 lines
5.2 KiB
PHP
Raw Normal View History

2009-06-30 08:09:20 +00:00
<?php
2009-06-30 11:52:55 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/create.php,v 1.48.2.4 2008/12/12 12:20:22 wurley Exp $
2009-06-30 09:22:30 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
* 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)
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
*/
/**
* @todo: posixgroup with empty memberlist generates an error.
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:29:51 +00:00
require './common.php';
if ($ldapserver->isReadOnly())
2009-06-30 11:52:55 +00:00
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
2009-06-30 08:05:37 +00:00
2009-06-30 11:46:44 +00:00
if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_create'))
2009-06-30 11:52:55 +00:00
error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('create entry')),'error','index.php');
2009-06-30 09:29:51 +00:00
2009-06-30 11:52:55 +00:00
$rdn_attr = get_request('rdn_attribute');
2009-06-30 09:29:51 +00:00
2009-06-30 11:46:44 +00:00
$entryfactoryclass = $_SESSION[APPCONFIG]->GetValue('appearance','entry_factory');
2009-06-30 10:46:00 +00:00
eval('$entry_factory = new '.$entryfactoryclass.'();');
$entry = $entry_factory->newCreatingEntry('');
2009-06-30 08:05:37 +00:00
2009-06-30 11:46:44 +00:00
eval('$reader = new '.$_SESSION[APPCONFIG]->GetValue('appearance', 'entry_reader').'($ldapserver);');
2009-06-30 10:46:00 +00:00
$entry->accept($reader);
2009-06-30 10:26:08 +00:00
2009-06-30 10:46:00 +00:00
$container = $entry->getContainer();
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (!$container || !$ldapserver->dnExists($container))
2009-06-30 11:52:55 +00:00
error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),htmlspecialchars($container)),'error','index.php');
2009-06-30 10:26:08 +00:00
2009-06-30 10:46:00 +00:00
$tree = get_cached_item($ldapserver->server_id,'tree');
if ($tree) {
$container_entry = $tree->getEntry($container);
if (!$container_entry)
$tree->addEntry($container);
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$container_entry = $tree->getEntry($container);
if ($container_entry->isLeaf())
2009-06-30 11:52:55 +00:00
error(sprintf(_('The container (%s) is a leaf.'), htmlspecialchars($container)),'error','index.php');
2009-06-30 10:46:00 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$entry->setRdnAttributeName($rdn_attr);
if (!$entry->getRdnAttribute())
2009-06-30 11:52:55 +00:00
error(sprintf(_('The Rdn attribute (%s) does not exist.'), htmlspecialchars($rdn_attr)),'error','index.php');
2009-06-30 10:26:45 +00:00
2009-06-30 10:46:00 +00:00
$new_dn = $entry->getDn();
if (! $new_dn)
2009-06-30 11:52:55 +00:00
error(_('You left the RDN field blank.'),'error','index.php');
2009-06-30 09:29:51 +00:00
2009-06-30 11:52:55 +00:00
$redirect = get_request('redirect','POST',false,false);
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$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;
}
2009-06-30 10:26:08 +00:00
2009-06-30 11:52:55 +00:00
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');
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if ($new_vals)
$new_entry[$attr->getName()] = $new_vals;
2009-06-30 08:05:37 +00:00
}
2009-06-30 10:46:00 +00:00
if (! in_array('top', $new_entry['objectClass']))
2009-06-30 08:05:37 +00:00
$new_entry['objectClass'][] = 'top';
2009-06-30 10:26:08 +00:00
foreach ($new_entry as $attr => $vals) {
# Check to see if this is a unique Attribute
if ($badattr = $ldapserver->checkUniqueAttr($new_dn,$attr,$vals)) {
2009-06-30 10:46:00 +00:00
$search_href = sprintf('?cmd=search&amp;search=true&amp;form=advanced&amp;server_id=%s&amp;filter=%s=%s', $ldapserver->server_id,$attr,$badattr);
2009-06-30 11:52:55 +00:00
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');
2009-06-30 09:22:30 +00:00
}
}
2009-06-30 08:07:14 +00:00
2009-06-30 10:26:08 +00:00
# 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);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ($add_result) {
run_hook('post_entry_create',array('server_id'=>$ldapserver->server_id,'dn'=>$new_dn,'attrs'=>$new_entry));
2009-06-30 09:29:51 +00:00
2009-06-30 11:46:44 +00:00
$action_number = $_SESSION[APPCONFIG]->GetValue('appearance', 'action_after_creation');
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
$container = get_container($new_dn,false);
//$container_container = get_container($container);
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
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));
2009-06-30 08:05:37 +00:00
}
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 DN%s <b>%s</b> %s',_('Creation successful!'),_(':'),htmlspecialchars($new_dn),_('has been created.'));
system_message(array(
'title'=>_('Create Entry'),
'body'=>$create_message,
'type'=>'info'),
$redirect_url);
} else {
printf('<h3 class="title">%s</h3>',_('Entry created'));
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'));
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'));
echo '</center>';
}
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
} else {
2009-06-30 11:52:55 +00:00
system_message(array(
'title'=>_('Could not add the object to the LDAP server.'),
'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()),
'type'=>'error'));
2009-06-30 09:29:51 +00:00
}
2009-06-30 08:05:37 +00:00
?>