RELEASE 1.1.0
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
<?php
|
||||
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/create.php,v 1.47 2006/10/28 16:37:59 wurley Exp $
|
||||
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/create.php,v 1.48 2007/12/15 07:50:30 wurley Exp $
|
||||
|
||||
/**
|
||||
* Creates a new object.
|
||||
*
|
||||
* Variables that come in via common.php
|
||||
* - server_id
|
||||
* Variables that come in as POST vars:
|
||||
* - new_dn
|
||||
* - attrs (an array of attributes)
|
||||
* - vals (an array of values for the above attrs)
|
||||
* - required_attrs (an array with indices being the attributes,
|
||||
* and the values being their respective values)
|
||||
* - object_classes (rawurlencoded, and serialized array of objectClasses)
|
||||
@@ -23,107 +19,72 @@
|
||||
require './common.php';
|
||||
|
||||
if ($ldapserver->isReadOnly())
|
||||
pla_error(_('You cannot perform updates while server is in read-only mode'));
|
||||
if (! $ldapserver->haveAuthInfo())
|
||||
pla_error(_('Not enough information to login to server. Please check your configuration.'));
|
||||
pla_error(_('You cannot perform updates while server is in read-only mode'), null, -1, true);
|
||||
|
||||
if (! $_SESSION['plaConfig']->isCommandAvailable('entry_create'))
|
||||
pla_error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('create entry')));
|
||||
|
||||
$rdn_attr = isset($_POST['rdn_attribute']) ? $_POST['rdn_attribute'] : null;
|
||||
|
||||
$entryfactoryclass = $_SESSION['plaConfig']->GetValue('appearance','entry_factory');
|
||||
eval('$entry_factory = new '.$entryfactoryclass.'();');
|
||||
$entry = $entry_factory->newCreatingEntry('');
|
||||
|
||||
eval('$reader = new '.$_SESSION['plaConfig']->GetValue('appearance', 'entry_reader').'($ldapserver);');
|
||||
$entry->accept($reader);
|
||||
|
||||
$container = $entry->getContainer();
|
||||
|
||||
if (!$container || !$ldapserver->dnExists($container))
|
||||
pla_error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),htmlspecialchars($container)),null,-1,true);
|
||||
|
||||
$tree = get_cached_item($ldapserver->server_id,'tree');
|
||||
if ($tree) {
|
||||
$container_entry = $tree->getEntry($container);
|
||||
if (!$container_entry)
|
||||
$tree->addEntry($container);
|
||||
|
||||
$container_entry = $tree->getEntry($container);
|
||||
if ($container_entry->isLeaf())
|
||||
pla_error(sprintf(_('The container (%s) is a leaf.'), htmlspecialchars($container)), null, -1, true);
|
||||
}
|
||||
|
||||
$entry->setRdnAttributeName($rdn_attr);
|
||||
if (!$entry->getRdnAttribute())
|
||||
pla_error(sprintf(_('The Rdn attribute (%s) does not exist.'), htmlspecialchars($rdn_attr)), null, -1, true);
|
||||
|
||||
$new_dn = $entry->getDn();
|
||||
if (! $new_dn)
|
||||
pla_error(_('You left the RDN field blank.'));
|
||||
|
||||
$new_dn = isset($_POST['new_dn']) ? $_POST['new_dn'] : null;
|
||||
$required_attrs = isset($_POST['required_attrs']) ? $_POST['required_attrs'] : false;
|
||||
$object_classes = unserialize(rawurldecode($_POST['object_classes']));
|
||||
$redirect = isset($_POST['redirect']) ? $_POST['redirect'] : false;
|
||||
|
||||
# See if there are any presubmit values to work out.
|
||||
if (isset($_POST['presubmit']) && count($_POST['presubmit']) && isset($_POST['template'])) {
|
||||
$templates = new Templates($ldapserver->server_id);
|
||||
$template = $templates->getCreationTemplate($_POST['template']);
|
||||
|
||||
foreach ($_POST['presubmit'] as $attr) {
|
||||
$_POST['attrs'][] = $attr;
|
||||
$_POST['form'][$attr] = $templates->EvaluateDefault($ldapserver,$template['attribute'][$attr]['presubmit'],$_POST['container']);
|
||||
$_POST['vals'][] = $_POST['form'][$attr];
|
||||
}
|
||||
|
||||
# @todo: This section needs to be cleaned up, and will be when the old templates are removed. In the mean time...
|
||||
# Rebuild the $_POST['attrs'] & $_POST['vals'], as they can be inconsistent.
|
||||
unset($_POST['attrs']);
|
||||
unset($_POST['vals']);
|
||||
foreach ($_POST['form'] as $attr => $val) {
|
||||
$_POST['attrs'][] = $attr;
|
||||
$_POST['vals'][] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$vals = isset($_POST['vals']) ? $_POST['vals'] : array();
|
||||
$attrs = isset($_POST['attrs']) ? $_POST['attrs'] : array();
|
||||
|
||||
# build the new entry
|
||||
$new_entry = array();
|
||||
if (isset($required_attrs) && is_array($required_attrs)) {
|
||||
foreach ($required_attrs as $attr => $val) {
|
||||
if ($val == '')
|
||||
pla_error(sprintf(_('You left the value blank for required attribute (%s).'),htmlspecialchars($attr)));
|
||||
|
||||
$new_entry[$attr][] = $val;
|
||||
$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)
|
||||
pla_error(sprintf(_('You left the value blank for required attribute (%s).'), htmlspecialchars($attr->getName())));
|
||||
|
||||
if ($new_vals)
|
||||
$new_entry[$attr->getName()] = $new_vals;
|
||||
}
|
||||
|
||||
if (isset($attrs) && is_array($attrs)) {
|
||||
foreach ($attrs as $i => $attr) {
|
||||
|
||||
if ($ldapserver->isAttrBinary($attr)) {
|
||||
if (isset($_FILES['vals']['name'][$i]) && $_FILES['vals']['name'][$i] != '' ) {
|
||||
|
||||
# read in the data from the file
|
||||
$file = $_FILES['vals']['tmp_name'][$i];
|
||||
$f = fopen($file,'r');
|
||||
$binary_data = fread($f,filesize($file));
|
||||
fclose($f);
|
||||
|
||||
$val = $binary_data;
|
||||
$new_entry[$attr][] = $val;
|
||||
|
||||
} elseif (isset($_SESSION['submitform'][$attr])) {
|
||||
$new_entry[$attr][] = $_SESSION['submitform'][$attr];
|
||||
unset($_SESSION['submitform'][$attr]);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (is_array($vals[$i])) {
|
||||
|
||||
# If the array has blank entries, then ignore them.
|
||||
foreach ($vals[$i] as $value) {
|
||||
if (trim($value))
|
||||
$new_entry[$attr][] = $value;
|
||||
}
|
||||
|
||||
} else {
|
||||
$val = isset($vals[$i]) ? $vals[$i] : '';
|
||||
|
||||
if ('' !== trim($val))
|
||||
$new_entry[$attr][] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$new_entry['objectClass'] = $object_classes;
|
||||
if (! in_array('top',$new_entry['objectClass']))
|
||||
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('search.php?search=true&form=advanced&server_id=%s&filter=%s=%s',
|
||||
$ldapserver->server_id,$attr,$badattr);
|
||||
$search_href = sprintf('?cmd=search&search=true&form=advanced&server_id=%s&filter=%s=%s', $ldapserver->server_id,$attr,$badattr);
|
||||
pla_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));
|
||||
}
|
||||
|
||||
if (! $ldapserver->isAttrBinary($attr))
|
||||
if (is_array($vals))
|
||||
foreach ($vals as $i => $v)
|
||||
$new_entry[$attr][$i] = $v;
|
||||
else
|
||||
$new_entry[$attr] = $vals;
|
||||
}
|
||||
|
||||
# Check the user-defined custom call back first
|
||||
@@ -133,26 +94,39 @@ if (run_hook('pre_entry_create',array('server_id'=>$ldapserver->server_id,'dn'=>
|
||||
if ($add_result) {
|
||||
run_hook('post_entry_create',array('server_id'=>$ldapserver->server_id,'dn'=>$new_dn,'attrs'=>$new_entry));
|
||||
|
||||
if ($redirect)
|
||||
$action_number = $_SESSION['plaConfig']->GetValue('appearance', 'action_after_creation');
|
||||
|
||||
$container = get_container($new_dn,false);
|
||||
//$container_container = get_container($container);
|
||||
|
||||
if ($redirect) {
|
||||
$redirect_url = $redirect;
|
||||
else
|
||||
$redirect_url = sprintf('template_engine.php?server_id=%s&dn=%s',$ldapserver->server_id,rawurlencode($new_dn));
|
||||
|
||||
echo '<html><head>';
|
||||
$tree = get_cached_item($ldapserver->server_id,'tree');
|
||||
$container = get_container($new_dn);
|
||||
|
||||
if ((isset($tree['browser'][$container]['open']) && $tree['browser'][$container]['open']) ||
|
||||
in_array($new_dn,$ldapserver->getBaseDN())) {
|
||||
|
||||
echo '<!-- refresh the tree view (with the new DN renamed) and redirect to the edit_dn page -->';
|
||||
printf('<script language="javascript">parent.left_frame.location.reload();location.href="%s"</script>',$redirect_url);
|
||||
} 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));
|
||||
}
|
||||
|
||||
printf('<meta http-equiv="refresh" content="0; url=%s" />',$redirect_url);
|
||||
echo '</head><body>';
|
||||
printf('%s <a href="%s">%s</a>.',_('Redirecting...'),$redirect_url,_('here'));
|
||||
echo '</body></html>';
|
||||
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>';
|
||||
}
|
||||
|
||||
} else {
|
||||
pla_error(_('Could not add the object to the LDAP server.'),$ldapserver->error(),$ldapserver->errno());
|
||||
|
Reference in New Issue
Block a user