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

// $DEBUG = 1;

$pageTitle = "$config->appName > Edit entry";

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

if( ! $sr )
	ErrorPage(  "Error",
		"Entry not found : "	. ldap_error($ds) . "<br>Maybe someone has just deleted this entry ?",
		"page.default.php"
	);

$es = ldap_first_entry ($ds, $sr);
$attrs = ldap_get_attributes ($ds, $es);

debug( $attrs );

$encdn = rawurlencode($dn); // used when building urls with the dn

include_once( './page.header.php' );

// TEMP DEBUG
html::form( @$PHP_SELF, "post", 'name="frm"' );
// html::form( $PHP_SELF, "post", 'name="frm" enctype="multipart/form-data"' );

//$DEBUG = 1 ;debug( $GLOBALS );

html::hidden( "A", "" );
html::hidden( "dn", utf8_decode($dn) );

echo '<div align=center><table style="width:300px; border: 1px solid gray;">';
echo '<caption>', $pageTitle, "</caption>\n";

if( isset($statusMsg) ) {
	FormLine( "&nbsp;",   $statusMsg );
}

// output DN field
FormLine(
	"DN", 
	new TextInput( "newdn", utf8_decode($dn), $tbL )
);

$known_attributes = array();

for( $i = 0; $i < $attrs["count"]; $i++ ) {

	$attribute = strtolower( $attrs[$i] );
	$attributevalue = ldap_get_values_len ($ds, $es, $attrs[$i]);
	// used as a popup for first "Add new attribute" field
	$known_attributes[$attribute] = $attribute;
	
	for ($j = 0; $j < $attrs[$attrs[$i]]["count"]; $j++) {

		$value = $attributevalue[$j];
		$valuelen = strlen( $value );
		$fieldname = 'ldapnav_' . $attrs[$i] . "[$j]"; 				
		
		// determine widget width from value length
		if( $valuelen > 30 ) 
			$cssClass= $tbL;
		elseif( $valuelen > 20 ) 
			$cssClass= $tbM;
		else 
			$cssClass= $tbS;
		
		// several case depending on attribute
		switch( $attribute ) {

		case "aci":
			$widget = new Button( "Edit", "formAction(this.form,'aci.edit')" );
			break;

		case "userpassword":
			$widget = new TextInput( $fieldname, "", $cssClass );
			break;
		
		default: 		
			if (strstr( $attribute, ";binary") ) {
				$value = base64_encode($value);
				$randomdata = uniqid("rand");
				$encattribute = urlencode($attribute);
				// build download button
				$url = "submit.php?A=attribute.download&dn=$encdn&attribute=$encattribute&idx=$j&$randomdata";
				$w1 = new Button( "Download", "Loadfile('$url')", "btn" );
				// build delete button			
				$url = "submit.php?A=attribute.delete&dn=$encdn&attribute=$encattribute&idx=$j";
				$w2 = new Button( "Delete", "Loadfile('$url')", "btn" );
				$widget = $w1->toString() . $w2->toString();
			} elseif( in_array( $attribute, $config->readOnlyAttributes ) ) {
				echo "RO";
				$widget = $value;
//				$widget = new Hidden( $fieldname, utf8_decode($value) );
			} else {
				$widget = new TextInput( $fieldname, utf8_decode($value), $cssClass );
			}
		} // switch
		// output the widget 
		FormLine( 
			$attrs[$i],
			$widget
		);
	}
}
ldap_unbind ($ds);


// fields for new values

//FormStart( "New attributes" );

FormLine( 
	"",
	"<br><i>To add new attribute, use fields below</i>"
);
		



for ($i = 0; $i < $config->newattrnum; $i++) {

	FormLine( 
		new TextInput( "newattrname[$i]", @$newattrname[$i], $tbS ),
		new TextInput( "newattrval[$i]", @$newattrval[$i], $tbL )
	);

}

FormLine( 
	new TextInput( "newattrname[$i]", @$newattrname[$i], $tbS ),
	new FileInput( "newattrvalbin[$i]", @$newattrvalbin[$i], $tbS )
);


// create button bar elements
$wModify = new Button( "Modify", "formAction(this.form, 'entry.modify' )", "mod", $btM );
$wAdd = new Button( "Add", "formAction(this.form, 'entry.add' )", "add", $btM );
$wDelete = new Button( "Delete", "formAction(this.form, 'entry.delete' )", "del", $btS );
$wRename = new Button( "Rename", "formAction(this.form, 'entry.rename' )", "rename", $btS );
$wNewChild = new Button( "New...", "formAction(this.form, 'entry.new' )", "new", $btS );
if( $config->directoryBrand == 'iplanet' || $config->directoryBrand == 'netscape' )
	$wAci = new Button( "Permissions...", "formAction(this.form, 'aci.edit' )", "aci", $btM );
else
	$wAci = "";
$wBack = new Button( "Cancel", "history.go(-1)", $btS );

// display buttons bar
echo "<tr><td colspan=2><table>";
RowN(
	array(
		$wModify,
		$wAdd,
		$wDelete,
		$wRename,
		$wAci,
		$wBack
	 )
);
echo "</table></td></tr>\n";

echo "</table></div>\n</form>\n";



// JS invoqued by form buttons
?>
<script language="javascript">
<!--
 
function formAction( formObj, actionStr )
{ 
	document.frm.A.value = actionStr;
	document.frm.submit();
}

function Loadfile( url )
{
	window.location = url;
}

// -->
</script>
<?php


include("./page.footer.php");

?> 
Return current item: LDAP Navigator