RELEASE 0.9.8
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/create.php,v 1.43.2.1 2005/10/09 09:07:21 wurley Exp $
|
||||
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/create.php,v 1.44.2.5 2005/12/09 14:29:15 wurley Exp $
|
||||
|
||||
/**
|
||||
* Creates a new object.
|
||||
@@ -23,19 +23,16 @@
|
||||
require './common.php';
|
||||
|
||||
if ($ldapserver->isReadOnly())
|
||||
pla_error($lang['no_updates_in_read_only_mode']);
|
||||
pla_error(_('You cannot perform updates while server is in read-only mode'));
|
||||
if (! $ldapserver->haveAuthInfo())
|
||||
pla_error($lang['not_enough_login_info']);
|
||||
pla_error(_('Not enough information to login to server. Please check your configuration.'));
|
||||
|
||||
$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;
|
||||
$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;
|
||||
|
||||
$encoded_dn = rawurlencode( $new_dn );
|
||||
$container = get_container( $new_dn );
|
||||
|
||||
// See if there are any presubmit values to work out.
|
||||
# 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->GetTemplate($_POST['template']);
|
||||
@@ -56,32 +53,34 @@ if (isset($_POST['presubmit']) && count($_POST['presubmit']) && isset($_POST['te
|
||||
}
|
||||
}
|
||||
|
||||
$vals = isset( $_POST['vals'] ) ? $_POST['vals'] : array();
|
||||
$attrs = isset( $_POST['attrs'] ) ? $_POST['attrs'] : array();
|
||||
$vals = isset($_POST['vals']) ? $_POST['vals'] : array();
|
||||
$attrs = isset($_POST['attrs']) ? $_POST['attrs'] : array();
|
||||
|
||||
// build the new entry
|
||||
# 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( $lang['create_required_attribute'], htmlspecialchars( $attr ) ) );
|
||||
$new_entry[ $attr ][] = $val;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $attrs ) && is_array( $attrs ) ) {
|
||||
foreach( $attrs as $i => $attr ) {
|
||||
if( is_attr_binary( $ldapserver, $attr ) ) {
|
||||
if( isset( $_FILES['vals']['name'][$i] ) && $_FILES['vals']['name'][$i] != '' ) {
|
||||
if (isset($attrs) && is_array($attrs)) {
|
||||
foreach ($attrs as $i => $attr) {
|
||||
|
||||
// read in the data from the file
|
||||
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 );
|
||||
$f = fopen($file,'r');
|
||||
$binary_data = fread($f,filesize($file));
|
||||
fclose($f);
|
||||
|
||||
$val = $binary_data;
|
||||
$new_entry[ $attr ][] = $val;
|
||||
$new_entry[$attr][] = $val;
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -89,102 +88,69 @@ if( isset( $attrs ) && is_array( $attrs ) ) {
|
||||
|
||||
# If the array has blank entries, then ignore them.
|
||||
foreach ($vals[$i] as $value) {
|
||||
# $new_entry[$attr] = $vals[$i];
|
||||
if (trim($value))
|
||||
$new_entry[$attr][] = $value;
|
||||
}
|
||||
} else {
|
||||
$val = isset( $vals[$i] ) ? $vals[$i] : '';
|
||||
|
||||
if( '' !== trim($val) )
|
||||
$new_entry[ $attr ][] = $val;
|
||||
} 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 = checkUniqueAttr( $ldapserver, $new_dn, $attr, $vals ) ) {
|
||||
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);
|
||||
pla_error(sprintf( $lang['unique_attr_failed'],$attr,$badattr,$new_dn,$search_href ) );
|
||||
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( ! is_attr_binary( $ldapserver, $attr ) )
|
||||
if( is_array( $vals ) )
|
||||
foreach( $vals as $i => $v )
|
||||
$new_entry[ $attr ][ $i ] = $v;
|
||||
|
||||
if (! $ldapserver->isAttrBinary($attr))
|
||||
if (is_array($vals))
|
||||
foreach ($vals as $i => $v)
|
||||
$new_entry[$attr][$i] = $v;
|
||||
else
|
||||
$new_entry[ $attr ] = $vals;
|
||||
$new_entry[$attr] = $vals;
|
||||
}
|
||||
|
||||
//echo "<pre>"; var_dump( $new_dn );print_r( $new_entry ); echo "</pre>";
|
||||
# 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);
|
||||
|
||||
// Check the user-defined custom call back first
|
||||
if( true === run_hook ( 'pre_entry_create', array ( 'server_id' => $ldapserver->server_id,'dn' => $new_dn,'attrs' => $new_entry ) ) )
|
||||
$add_result = @ldap_add( $ldapserver->connect(), $new_dn, $new_entry );
|
||||
|
||||
else {
|
||||
pla_error( $lang['create_could_not_add'] );
|
||||
exit;
|
||||
}
|
||||
|
||||
if( $add_result ) {
|
||||
run_hook ( 'post_entry_create', array ( 'server_id' => $ldapserver->server_id, 'dn' => $new_dn, 'attrs' => $new_entry ) );
|
||||
if ($add_result) {
|
||||
run_hook('post_entry_create',array('server_id'=>$ldapserver->server_id,'dn'=>$new_dn,'attrs'=>$new_entry));
|
||||
|
||||
if ($redirect)
|
||||
$redirect_url = $redirect;
|
||||
|
||||
else
|
||||
$redirect_url = sprintf('edit.php?server_id=%s&dn=%s',$ldapserver->server_id,rawurlencode($new_dn));
|
||||
$redirect_url = sprintf('template_engine.php?server_id=%s&dn=%s',$ldapserver->server_id,rawurlencode($new_dn));
|
||||
|
||||
if( array_key_exists( 'tree', $_SESSION ) ) {
|
||||
$tree = $_SESSION['tree'];
|
||||
$tree_icons = $_SESSION['tree_icons'];
|
||||
echo '<html><head>';
|
||||
$tree = get_cached_item($ldapserver->server_id,'tree');
|
||||
$container = get_container($new_dn);
|
||||
|
||||
if( isset( $tree[$ldapserver->server_id][$container] ) ) {
|
||||
$tree[$ldapserver->server_id][$container][] = $new_dn;
|
||||
sort( $tree[$ldapserver->server_id][$container] );
|
||||
$tree_icons[$ldapserver->server_id][$new_dn] = get_icon( $ldapserver, $new_dn );
|
||||
}
|
||||
if ((isset($tree['browser'][$container]['open']) && $tree['browser'][$container]['open']) ||
|
||||
in_array($new_dn,$ldapserver->getBaseDN())) {
|
||||
|
||||
$_SESSION['tree'] = $tree;
|
||||
$_SESSION['tree_icons'] = $tree_icons;
|
||||
session_write_close();
|
||||
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);
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
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>';
|
||||
|
||||
<?php if (isset($tree[$ldapserver->server_id][$container]) || in_array($new_dn,$ldapserver->getBaseDN())) { ?>
|
||||
|
||||
<!-- refresh the tree view (with the new DN renamed)
|
||||
and redirect to the edit_dn page -->
|
||||
<script language="javascript">
|
||||
parent.left_frame.location.reload();
|
||||
location.href='<?php echo $redirect_url; ?>';
|
||||
</script>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<meta http-equiv="refresh" content="0; url=<?php echo $redirect_url; ?>" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php echo $lang['redirecting'] ?> <a href="<?php echo $redirect_url; ?>"><?php echo $lang['here']?></a>.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php } else {
|
||||
pla_error( $lang['create_could_not_add'], $ldapserver->error(), $ldapserver->errno() );
|
||||
} else {
|
||||
pla_error(_('Could not add the object to the LDAP server.'),$ldapserver->error(),$ldapserver->errno());
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user