Location: PHPKode > projects > LDAP Navigator > ldapnavigator-0.9.6/modules/entry/add.php
<?php


$pageTitle = "$config->appName > Adding entry $newdn";

$sr = @ldap_read ($ds, $newdn, "objectclass=*" );

if( $sr ) {
	ErrorPage(  "Error",
		"The entry you want to add allready exists ($newdn)",
		"javascript:history.go(-1)"
	);
}


// form fields that are to be treated as entry attributes
$fields =& $HTTP_POST_VARS;

$addentry = array();

foreach( $fields as $k => $formvalues ) 
{

	if( strpos( $k, 'ldapnav_' ) === 0 ) {
	
		$attrname = substr( $k, strlen( 'ldapnav_' ) );
		$dbg = "\n\nattribute $attrname:";

	// not an attribute field
	} else {

		continue;
	}

	if( ! is_array($formvalues) ) {
		$dbg .= "not an array?";
		continue;
	}
	
	// remove empty values in form attributes
	for( $i=0; $i<count($formvalues); $i++ ) 
	{
		if( $formvalues[$i] == "" ) {
			unset($formvalues[$i] );
		} else {
			$formvalues[$i] = utf8_encode( $formvalues[$i] );
		}
	}
	
	// if the attribute contains 0 values, we must not add it
	if( count($formvalues) == 0 ) {
		continue;
	}
			
	if( ! is_array($addentry[$attrname]) )
		$addentry[$attrname] = array();

	$addentry[$attrname] = $formvalues;
	
}


foreach( $HTTP_POST_VARS['newattrname'] as $idx => $attrname ) {
	
	$attrname = strtolower(trim($attrname));
	$value = $HTTP_POST_VARS['newattrval'][$idx];

	if( trim($attrname) == "" )
		continue;

	if( $value == "" )
		continue;
	
	if( ! is_array($addentry[$attrname]) )
		$addentry[$attrname] = array();
	$addentry[$attrname][] = $value;
	
}


// NO PAGE OUTPUT (silent action)

if( count($addentry) > 0 ) {

	$ret = @ldap_add( $ds, $newdn, $addentry );
	if( ! $ret ) {
		ErrorPage( 
			$pageTitle,
			"LDAP server reported an error: "  . ldap_error($ds)
		);
	}
	$dn = $newdn;
	$statusMsg = "Adding entry $newdn OK";
}


?>
Return current item: LDAP Navigator