2009-06-30 10:46:00 +00:00
< ? php
2009-06-30 12:05:31 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/EntryWriter1.php,v 1.3.2.31 2009/01/30 04:40:03 wurley Exp $
2009-06-30 10:46:00 +00:00
define ( 'IdEntryRefreshMenuItem' , '0' );
define ( 'IdEntryExportBaseMenuItem' , '1' );
define ( 'IdEntryMoveMenuItem' , '2' );
define ( 'IdEntryInternalAttributesMenuItem' , '3' );
define ( 'IdEntryDeleteMenuItem' , '4' );
define ( 'IdEntryRenameMenuItem' , '5' );
define ( 'IdEntryDeleteAttributeMessage' , '6' );
define ( 'IdEntryCompareMenuItem' , '7' );
define ( 'IdEntryCreateMenuItem' , '8' );
define ( 'IdEntryAddAttributeMenuItem' , '9' );
define ( 'IdEntryShowChildrenMenuItem' , '10' );
define ( 'IdEntryExportSubMenuItem' , '11' );
define ( 'IdEntryViewSchemaMessage' , '12' );
define ( 'IdEntryReadOnlyMessage' , '13' );
define ( 'IdEntryModifiedAttributesMessage' , '14' );
define ( 'IdAttributeAddValueMenuItem' , '0' );
define ( 'IdAttributeModifyMemberMenuItem' , '1' );
define ( 'IdAttributeRenameMenuItem' , '2' );
/**
* @ package phpLDAPadmin
* @ author The phpLDAPadmin development team
* @ author Xavier Bruyet
*
* Visit an entry and its attributes to draw them
*/
class EntryWriter1 extends EntryWriter {
protected $url_base ;
protected $hint_layout ;
protected $action_layout ;
protected $step ;
protected $laststep ;
/**************************/
/* Paint an Entry */
/**************************/
protected function drawEntryHeader ( $entry ) {
2009-06-30 11:52:55 +00:00
# Title
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Title' , $entry );
$this -> draw ( 'Subtitle' , $entry );
echo " \n " ;
2009-06-30 11:52:55 +00:00
# Menu
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Menu' , $entry );
}
protected function drawEntryTitle ( $entry ) {}
protected function drawEntrySubtitle ( $entry ) {}
protected function drawEntryMenu ( $entry ) {}
protected function drawEntryJavascript ( $entry ) {
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- START: %s --> \n " , __METHOD__ );
2009-06-30 11:46:44 +00:00
if ( isset ( $_SESSION [ APPCONFIG ])) {
2009-06-30 11:52:55 +00:00
echo " \n " ;
echo '<!-- Global settings for the js_calendar -->' . " \n " ;
echo '<script type="text/javascript" language="javascript">' . " \n " ;
echo 'var defaults = new Array();' . " \n " ;
printf ( 'var default_date_format = "%s";' , $_SESSION [ APPCONFIG ] -> GetValue ( 'appearance' , 'date' ));
echo " \n " ;
echo '</script>' . " \n " ;
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:52:55 +00:00
echo '<!-- START Global functions for general PLA processing. -->' . " \n " ;
2009-06-30 10:46:00 +00:00
echo ' < script type = " text/javascript " language = " javascript " >
function pla_getComponentById ( id ) {
return document . getElementById ( id );
}
function pla_getComponentsByName ( name ) {
return document . getElementsByName ( name );
}
function pla_getComponentValue ( component ) {
if ( component . type == " checkbox " ) {
if ( component . checked ) return component . value ;
} else if ( component . type == " select-one " ) {
if ( component . selectedIndex >= 0 ) return component . options [ component . selectedIndex ] . value ;
} else if ( component . type == " select-multiple " ) {
if ( component . selectedIndex >= 0 ) return component . options [ component . selectedIndex ] . value ;
} else if ( component . type == undefined ) { // option
if ( component . selected ) return component . value ;
} else {
return component . value ;
}
return " " ;
}
function pla_setComponentValue ( component , value ) {
if ( component . type == " checkbox " ) {
if ( component . value == value ) component . checked = true ;
else component . checked = false ;
} else if ( component . type == " select-one " ) {
for ( var i = 0 ; i < component . options . length ; i ++ ) {
if ( component . options [ i ] . value == value ) component . options [ i ] . selected = true ;
}
} else if ( component . type == " select-multiple " ) {
for ( var i = 0 ; i < component . options . length ; i ++ ) {
if ( component . options [ i ] . value == value ) component . options [ i ] . selected = true ;
}
} else if ( component . type == undefined ) { // option
if ( component . value == value ) component . selected = true ;
else component . selected = false ;
} else { // text, textarea
component . value = value ;
}
2009-06-30 11:52:55 +00:00
}
2009-06-30 10:46:00 +00:00
function getAttributeComponents ( prefix , name ) {
var components = new Array ();
2009-06-30 11:52:55 +00:00
var i = 0 ;
2009-06-30 10:46:00 +00:00
var j = 0 ;
var c = pla_getComponentsByName ( prefix + " _values[ " + name + " ][ " + j + " ] " );
while ( c && ( c . length > 0 )) {
for ( var k = 0 ; k < c . length ; k ++ ) {
2009-06-30 11:52:55 +00:00
components [ i ++ ] = c [ k ];
2009-06-30 10:46:00 +00:00
}
++ j ;
c = pla_getComponentsByName ( prefix + " _values[ " + name + " ][ " + j + " ] " );
}
2009-06-30 11:52:55 +00:00
c = pla_getComponentsByName ( prefix + " _values[ " + name + " ][] " );
2009-06-30 10:46:00 +00:00
if ( c && ( c . length > 0 )) {
for ( var k = 0 ; k < c . length ; k ++ ) {
2009-06-30 11:52:55 +00:00
components [ i ++ ] = c [ k ];
2009-06-30 10:46:00 +00:00
}
}
2009-06-30 11:52:55 +00:00
return components ;
}
2009-06-30 10:46:00 +00:00
function getAttributeValues ( prefix , name ) {
2009-06-30 11:52:55 +00:00
var components = getAttributeComponents ( prefix , name );
2009-06-30 10:46:00 +00:00
var values = new Array ();
for ( var k = 0 ; k < components . length ; k ++ ) {
var val = pla_getComponentValue ( components [ k ]);
if ( val ) values [ values . length ] = val ;
}
2009-06-30 11:52:55 +00:00
return values ;
}
</ script > ' . " \n " ;
echo '<!-- END Global functions for general PLA processing. -->' . " \n " ;
echo " \n " ;
2009-06-30 10:46:00 +00:00
echo ' < script type = " text/javascript " language = " javascript " >
function validateForm ( silence ) {
2009-06-30 11:52:55 +00:00
var i = 0 ;
var valid = true ;
var components = null ; ' . " \n " ;
2009-06-30 10:46:00 +00:00
foreach ( $entry -> getAttributes () as $attribute ) {
2009-06-30 11:52:55 +00:00
if ( $attribute -> isVisible () && ( $attribute -> hasProperty ( 'onchange' )) || $attribute -> isRequired ()) {
echo " \n " ;
echo ' components = getAttributeComponents("new", "' . $attribute -> getName () . ' " );
for ( i = 0 ; i < components . length ; i ++ ) {
if ( window . validate_ '.$attribute->getName().' ) {
2009-06-30 10:46:00 +00:00
valid = ( ! validate_ '.$attribute->getName().' ( components [ i ], silence ) || ! valid ) ? false : true ;
}
} ' ;
2009-06-30 11:52:55 +00:00
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
}
echo ' return valid ;
}
2009-06-30 11:52:55 +00:00
</ script > ' . " \n " ;
2009-06-30 10:46:00 +00:00
echo ' < script type = " text/javascript " language = " javascript " >
function submitForm ( form ) {
for ( var i = 0 ; i < form . elements . length ; i ++ ) {
form . elements [ i ] . blur ();
}
2009-06-30 11:52:55 +00:00
return validateForm ( true );
2009-06-30 10:46:00 +00:00
}
function alertError ( err , silence ) {
if ( ! silence ) alert ( err );
}
2009-06-30 11:52:55 +00:00
</ script > ' . " \n " ;
2009-06-30 10:46:00 +00:00
for ( $i = 0 ; $i < count ( $this -> shown_attributes ); $i ++ ) {
$this -> draw ( 'Javascript' , $this -> shown_attributes [ $i ]);
}
echo ' < script type = " text/javascript " language = " javascript " >
validateForm ( true );
2009-06-30 11:52:55 +00:00
</ script > ' . " \n " ;
printf ( " \n <!-- END: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
}
/********************************/
/* Paint a DefaultCreatingEntry */
/********************************/
public function visitDefaultCreatingEntryStart ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
2009-06-30 11:52:55 +00:00
# Init
2009-06-30 10:46:00 +00:00
$this -> visit ( 'Entry::Start' , $entry );
2009-06-30 11:52:55 +00:00
# Check
2009-06-30 10:46:00 +00:00
$container = $entry -> getContainer ();
$container_ok = true ;
$objectclasses_ok = true ;
if ( $this -> step != 1 ) {
2009-06-30 11:51:50 +00:00
if ( ! $container || ! $this -> getLDAPServer () -> dnExists ( $container )) {
2009-06-30 10:46:00 +00:00
$container_ok = false ;
$this -> step = 1 ;
}
if ( ! $entry -> getAttributes ()) {
$objectclasses_ok = false ;
$this -> step = 1 ;
}
}
2009-06-30 11:52:55 +00:00
# Header
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Header' , $entry );
2009-06-30 11:52:55 +00:00
# Errors
2009-06-30 10:46:00 +00:00
if ( ! $container_ok ) {
2009-06-30 11:52:55 +00:00
error ( sprintf ( _ ( 'The container you specified (%s) does not exist.' ), htmlspecialchars ( $container )), 'error' );
2009-06-30 10:46:00 +00:00
echo '<br />' ;
}
if ( ! $objectclasses_ok ) {
2009-06-30 11:52:55 +00:00
error ( _ ( 'You did not select any objectClasses for this object.' ), 'error' );
2009-06-30 10:46:00 +00:00
echo '<br />' ;
}
}
public function visitDefaultCreatingEntryEnd ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
$this -> draw ( 'StepTitle' , $entry , $this -> step );
$this -> draw ( 'StepFormStart' , $entry , $this -> step );
$this -> draw ( 'StepForm' , $entry , $this -> step );
$this -> draw ( 'StepFormEnd' , $entry , $this -> step );
}
protected function initDefaultCreatingEntryVisit ( $entry ) {
parent :: initDefaultCreatingEntryVisit ( $entry );
$this -> step = 1 ;
$step = get_request ( 'step' , 'REQUEST' );
if ( $step ) $this -> step = $step ;
}
protected function drawDefaultCreatingEntryTitle ( $entry ) {
printf ( '<h3 class="title">%s</h3>' , _ ( 'Create Object' ));
}
protected function drawDefaultCreatingEntrySubtitle ( $entry ) {
printf ( '<h3 class="subtitle">%s%s <b>%s</b></h3>' ,
2009-06-30 11:51:50 +00:00
_ ( 'Server' ), _ ( ':' ), $this -> getLDAPServer () -> name );
2009-06-30 10:46:00 +00:00
}
protected function drawDefaultCreatingEntryStepTitle ( $entry , $step ) {
if ( $step == 1 ) {
echo '<center><h4>' ;
printf ( _ ( 'Step %s of %s' ), '1' , '2' );
echo _ ( ':' );
echo ' ' ;
echo _ ( 'Container and ObjectClass(es)' );
echo '</h4></center>' ;
} else {
echo '<center><h4>' ;
printf ( _ ( 'Step %s of %s' ), '2' , '2' );
echo _ ( ':' );
echo ' ' ;
echo _ ( 'Specify attributes and values' );
echo '</h4></center>' ;
}
}
public function drawDefaultCreatingEntryStepFormStart ( $entry , $step ) {
if ( $step == 1 ) {
echo '<form action="cmd.php?cmd=template_engine" method="post" enctype="multipart/form-data" name="entry_form" onSubmit="return submitForm(this)">' ;
} else {
echo '<form action="cmd.php?cmd=create" method="post" enctype="multipart/form-data" name="entry_form" onSubmit="return submitForm(this)">' ;
}
}
public function drawDefaultCreatingEntryStepForm ( $entry , $step ) {
$container = $entry -> getContainer ();
if ( $step == 1 ) {
2009-06-30 11:51:50 +00:00
printf ( '<input type="hidden" name="server_id" value="%s" />' , $this -> index );
2009-06-30 10:46:00 +00:00
printf ( '<input type="hidden" name="step" value="%s" />' , $step + 1 );
2009-06-30 11:51:50 +00:00
echo '<table class="forminput" align="center">' ;
2009-06-30 10:46:00 +00:00
$this -> draw ( 'ContainerChooser' , $entry , $container );
$this -> draw ( 'ObjectClassChooser' , $entry );
$this -> draw ( 'StepFormSubmitButton' , $entry , $step );
echo '</table>' ;
} else {
printf ( '<input type="hidden" name="container" value="%s" />' , htmlspecialchars ( $container ));
2009-06-30 11:51:50 +00:00
printf ( '<input type="hidden" name="server_id" value="%s" />' , $this -> index );
2009-06-30 10:46:00 +00:00
printf ( '<input type="hidden" name="step" value="%s" />' , $step + 1 );
2009-06-30 11:51:50 +00:00
echo '<table class="entry" cellspacing="0" align="center" border=0>' ;
2009-06-30 10:46:00 +00:00
$this -> draw ( 'RdnChooser' , $entry );
$this -> draw ( 'ShownAttributes' , $entry );
$this -> draw ( 'StepFormSubmitButton' , $entry , $step );
echo '</table>' ;
$this -> draw ( 'HiddenAttributes' , $entry );
}
}
public function drawDefaultCreatingEntryStepFormSubmitButton ( $entry , $step ) {
if ( $step == 1 ) {
echo '<tr><td> </td><td>' ;
printf ( '<input type="submit" id="create_button" value="%s" />' , _ ( 'Proceed >>' ));
echo '</td></tr>' ;
} else {
echo '<tr><td><center>' ;
printf ( '<input type="submit" id="create_button" name="submit" value="%s" />' , _ ( 'Create Object' ));
echo '</center></td></tr>' ;
}
}
public function drawDefaultCreatingEntryStepFormEnd ( $entry , $step ) {
echo '</form>' ;
2009-06-30 11:52:55 +00:00
# Javascript
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Javascript' , $entry );
}
protected function drawDefaultCreatingEntryContainerChooser ( $entry , $default_container ) {
echo '<tr>' ;
printf ( '<td class="heading">%s</td>' , _ ( 'Container' ));
printf ( '<td><input type="text" name="container" size="40" value="%s" />' , htmlspecialchars ( $default_container ));
draw_chooser_link ( 'entry_form.container' );
echo '</td>' ;
echo '</tr>' ;
}
protected function drawDefaultCreatingEntryObjectClassChooser ( $entry ) {
2009-06-30 11:51:50 +00:00
$oclasses = $this -> getLDAPServer () -> SchemaObjectClasses ();
2009-06-30 10:46:00 +00:00
if ( ! $oclasses ) $oclasses = array ();
elseif ( ! is_array ( $oclasses )) $oclasses = array ( $oclasses );
echo '<tr>' ;
printf ( '<td class="heading">%s</td>' , _ ( 'ObjectClasses' ));
echo '<td><select name="new_values[objectClass][]" multiple="true" size="15">' ;
foreach ( $oclasses as $name => $oclass ) {
if ( 0 == strcasecmp ( 'top' , $name )) continue ;
printf ( '<option %s value="%s">%s</option>' ,
( $oclass -> getType () == 'structural' ) ? 'style="font-weight: bold" ' : '' ,
htmlspecialchars ( $oclass -> getName ()), htmlspecialchars ( $oclass -> getName ()));
}
echo '</select>' ;
echo '</td>' ;
echo '</tr>' ;
2009-06-30 11:46:44 +00:00
if ( $_SESSION [ APPCONFIG ] -> GetValue ( 'appearance' , 'show_hints' )) {
2009-06-30 11:51:50 +00:00
printf ( '<tr><td> </td><td><small><img src="%s/light.png" alt="Hint" /><span class="hint">' , IMGDIR );
2009-06-30 10:46:00 +00:00
echo _ ( 'Hint: You must choose exactly one structural objectClass (shown in bold above)' );
echo '</span></small><br /></td></tr>' ;
}
}
protected function drawDefaultCreatingEntryRdnChooser ( $entry ) {
$attrs = $entry -> getAttributes ();
$rdn_attr = $entry -> getRdnAttribute ();
printf ( '<tr><th colspan="2">%s</th></tr>' , 'RDN' );
2009-06-30 11:51:50 +00:00
echo '<tr><td class="value" colspan="2"><select name="rdn_attribute">' ;
2009-06-30 10:46:00 +00:00
printf ( '<option value="">%s</option>' , _ ( 'select the rdn attribute' ));
foreach ( $attrs as $attr ) {
$n = $attr -> getName ();
if ( $attr -> getName () != 'objectClass' ) {
$m = $attr -> getFriendlyName ();
$b = ' ' ;
printf ( '<option value="%s" %s>%s%s(%s)</option>' , $n , ( $rdn_attr == $attr ) ? 'selected' : '' , htmlspecialchars ( $m ), $b , $n );
}
}
echo '</select></td></tr>' ;
}
protected function drawDefaultCreatingEntryShownAttributes ( $entry ) {
$attrs = array ();
2009-06-30 11:52:55 +00:00
# Put required attributes first
foreach ( $this -> shown_attributes as $sa )
2009-06-30 10:46:00 +00:00
if ( $sa -> isRequired ()) $attrs [] = $sa ;
2009-06-30 11:52:55 +00:00
foreach ( $this -> shown_attributes as $sa )
2009-06-30 10:46:00 +00:00
if ( ! $sa -> isRequired ()) $attrs [] = $sa ;
$has_required_attrs = false ;
$has_optional_attrs = false ;
foreach ( $attrs as $attr ) {
if ( $attr -> isRequired ()) {
if ( ! $has_required_attrs ) {
printf ( '<tr><th colspan="2">%s</th></tr>' , _ ( 'Required Attributes' ));
$has_required_attrs = true ;
}
} else {
if ( ! $has_optional_attrs ) {
if ( ! $has_required_attrs ) {
printf ( '<tr><th colspan="2">%s</th></tr>' , _ ( 'Required Attributes' ));
2009-06-30 11:51:50 +00:00
printf ( '<tr class="noinput"><td colspan="2"><center>(%s)</center></td></tr>' , _ ( 'none' ));
2009-06-30 10:46:00 +00:00
}
printf ( '<tr><th colspan="2">%s</th></tr>' , _ ( 'Optional Attributes' ));
$has_optional_attrs = true ;
}
}
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
2009-06-30 10:46:00 +00:00
echo " \n " ;
}
if ( ! $has_optional_attrs ) {
printf ( '<tr><th colspan="2">%s</th></tr>' , _ ( 'Optional Attributes' ));
2009-06-30 11:51:50 +00:00
printf ( '<tr class="noinput"><td colspan="2"><center>(%s)</center></td></tr>' , _ ( 'none' ));
2009-06-30 10:46:00 +00:00
}
}
protected function drawDefaultCreatingEntryHiddenAttributes ( $entry ) {
foreach ( $this -> hidden_attributes as $attr ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
2009-06-30 10:46:00 +00:00
echo " \n " ;
}
}
protected function drawDefaultCreatingEntryJavascript ( $entry ) {
$this -> draw ( 'Entry::Javascript' , $entry );
}
/*******************************/
/* Paint a DefaultEditingEntry */
/*******************************/
public function visitDefaultEditingEntryStart ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
2009-06-30 11:52:55 +00:00
# Init
2009-06-30 10:46:00 +00:00
$this -> visit ( 'Entry::Start' , $entry );
2009-06-30 11:52:55 +00:00
# Header
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Header' , $entry );
2009-06-30 11:52:55 +00:00
# Form start
2009-06-30 10:46:00 +00:00
if ( ! $entry -> isReadOnly ()) {
echo '<form action="cmd.php?cmd=update_confirm" method="post" enctype="multipart/form-data" name="entry_form" onSubmit="return submitForm(this)">' ;
2009-06-30 11:51:50 +00:00
printf ( '<input type="hidden" name="server_id" value="%s" />' , $this -> index );
2009-06-30 10:46:00 +00:00
printf ( '<input type="hidden" name="dn" value="%s" />' , htmlspecialchars ( $entry -> getDn ()));
}
echo '<br />' . " \n \n " ;
2009-06-30 11:51:50 +00:00
echo '<table class="entry" align="center" border=0>' ;
2009-06-30 10:46:00 +00:00
}
public function visitDefaultEditingEntryEnd ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
2009-06-30 11:52:55 +00:00
# Draw internal attributes
2009-06-30 10:46:00 +00:00
if ( get_request ( 'show_internal_attrs' , 'REQUEST' )) {
$this -> draw ( 'InternalAttributes' , $entry );
echo " \n \n " ;
}
2009-06-30 11:52:55 +00:00
# Draw visible attributes
2009-06-30 10:46:00 +00:00
$this -> draw ( 'ShownAttributes' , $entry );
2009-06-30 11:52:55 +00:00
# Form end
2009-06-30 10:46:00 +00:00
if ( ! $entry -> isReadOnly ()) {
$this -> draw ( 'FormSubmitButton' , $entry );
echo '</table>' ;
2009-06-30 11:52:55 +00:00
# Draw hidden attributes
2009-06-30 10:46:00 +00:00
$this -> draw ( 'HiddenAttributes' , $entry );
printf ( '</form>' );
} else {
printf ( '</table>' );
}
2009-06-30 11:52:55 +00:00
# Javascript
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Javascript' , $entry );
}
protected function initDefaultEditingEntryVisit ( $entry ) {
parent :: initDefaultEditingEntryVisit ( $entry );
2009-06-30 11:51:50 +00:00
$this -> url_base = sprintf ( 'cmd.php?server_id=%s&dn=%s' , $this -> index , rawurlencode ( $entry -> getDn ()));
$this -> hint_layout = sprintf ( '<td class="icon"><img src="%s/light.png" alt="%s" /></td><td colspan="3"><span class="hint">%%s</span></td>' , IMGDIR , _ ( 'Hint' ));
$this -> action_layout = '<td class="icon"><img src="%s/%s" alt="%s" /></td><td><a href="%s" title="%s">%s</a></td>' ;
2009-06-30 10:46:00 +00:00
}
protected function drawDefaultEditingEntryTitle ( $entry ) {
$dn = $entry -> getDn ();
$rdn = get_rdn ( $dn );
printf ( '<h3 class="title">%s</h3>' , htmlspecialchars ( $rdn ));
}
protected function drawDefaultEditingEntrySubtitle ( $entry ) {
echo '<h3 class="subtitle">' ;
echo _ ( 'Server' );
echo _ ( ':' );
echo ' <b>' ;
2009-06-30 11:51:50 +00:00
echo $this -> getLDAPServer () -> name ;
2009-06-30 10:46:00 +00:00
echo '</b> ' ;
2009-06-30 11:50:46 +00:00
2009-06-30 10:46:00 +00:00
echo _ ( 'Distinguished Name' );
echo _ ( ':' );
echo ' <b>' ;
echo htmlspecialchars ( $entry -> getDn ());
2009-06-30 11:50:46 +00:00
echo '</b>' ;
echo '<br />' ;
echo _ ( 'Template' );
echo _ ( ':' );
echo ' <b>' ;
echo htmlspecialchars ( $entry -> getTemplateTitle ());
echo '</b>' ;
if ( $entry -> getTemplateName ()) {
echo ' (<b>' ;
echo htmlspecialchars ( $entry -> getTemplateName ());
echo '</b>)' ;
}
echo '</h3>' ;
2009-06-30 10:46:00 +00:00
}
protected function drawDefaultEditingEntryMenu ( $entry ) {
$i = 0 ;
$item = '' ;
2009-06-30 11:51:50 +00:00
echo '<table class="menu" width="100%" border=0>' ;
2009-06-30 10:46:00 +00:00
echo '<tr>' ;
$menuitem_number = 0 ;
while (( $item = $this -> get ( 'MenuItem' , $entry , $i )) !== false ) {
if ( $item ) {
$endofrow = 0 ;
$it = '' ; // menu item
$ms = '' ; // item message
if ( is_array ( $item )) {
if ( count ( $item ) > 0 ) {
$it = $item [ 0 ];
if ( count ( $item ) > 1 ) $ms = $item [ 1 ];
}
} else {
$it = $item ;
}
if ( $it ) {
$menuitem_number ++ ;
echo $it ;
if ( $ms ) {
if (( $menuitem_number % 2 ) == 1 ) {
$menuitem_number ++ ;
echo '<td> </td><td> </td>' ;
$endofrow = 0 ;
}
if ( $endofrow )
print $ms ;
else
echo " </tr><tr> $ms " ;
echo " </tr><tr> " ;
$endofrow = 1 ;
} else {
if ( $menuitem_number > 1 && ( $menuitem_number % 2 ) == 0 ) {
echo '</tr><tr>' ;
$endofrow = 1 ;
}
}
} elseif ( $ms ) {
if (( $menuitem_number % 2 ) == 1 ) {
$menuitem_number ++ ;
echo '<td> </td><td> </td>' ;
$endofrow = 0 ;
}
if ( $endofrow )
print $ms ;
else
echo " </tr><tr> $ms " ;
echo " </tr><tr> " ;
$endofrow = 1 ;
}
}
$i ++ ;
}
if (( $menuitem_number % 2 ) == 1 ) echo '<td> </td><td> </td>' ;
else echo '<td> </td><td> </td><td> </td><td> </td>' ;
echo '</tr>' ;
echo '</table>' ;
}
protected function getDefaultEditingEntryMenuItem ( $entry , $i ) {
2009-06-30 11:46:44 +00:00
$config = $_SESSION [ APPCONFIG ];
2009-06-30 10:46:00 +00:00
switch ( $i ) {
case IdEntryRefreshMenuItem :
if ( $config -> isCommandAvailable ( 'entry_refresh' ))
return $this -> get ( 'RefreshMenuItem' , $entry );
else return '' ;
case IdEntryExportBaseMenuItem :
if ( $config -> isCommandAvailable ( 'export' ))
return $this -> get ( 'ExportBaseMenuItem' , $entry );
else return '' ;
case IdEntryMoveMenuItem :
if ( ! $entry -> isReadOnly () && $config -> isCommandAvailable ( 'entry_move' ))
return $this -> get ( 'MoveMenuItem' , $entry );
else return '' ;
case IdEntryInternalAttributesMenuItem :
if ( $config -> isCommandAvailable ( 'entry_internal_attributes_show' ))
return $this -> get ( 'InternalAttributesMenuItem' , $entry );
else return '' ;
case IdEntryDeleteMenuItem :
if ( ! $entry -> isReadOnly () && $config -> isCommandAvailable ( 'entry_delete' , 'simple_delete' ))
return $this -> get ( 'DeleteMenuItem' , $entry );
else return '' ;
case IdEntryRenameMenuItem :
if ( ! $entry -> isReadOnly () && $config -> isCommandAvailable ( 'entry_rename' )) {
2009-06-30 11:52:55 +00:00
foreach ( $entry -> getRdnAttributeName () as $rdnAttr ) {
$rdnAttr = $entry -> getAttribute ( $rdnAttr );
if ( $rdnAttr && $rdnAttr -> isVisible () && ! $rdnAttr -> isReadOnly ())
return $this -> get ( 'RenameMenuItem' , $entry );
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:52:55 +00:00
}
return '' ;
2009-06-30 10:46:00 +00:00
case IdEntryDeleteAttributeMessage :
if ( $config -> GetValue ( 'appearance' , 'show_hints' )
&& $config -> isCommandAvailable ( 'attribute_delete' ))
return array ( '' , $this -> get ( 'DeleteAttributeMessage' , $entry ));
else return '' ;
case IdEntryCompareMenuItem :
if ( ! $entry -> isReadOnly () && $config -> isCommandAvailable ( 'entry_compare' ))
return $this -> get ( 'CompareMenuItem' , $entry );
else return '' ;
case IdEntryCreateMenuItem :
if ( ! $entry -> isReadOnly () && ! $entry -> isLeaf ()
&& $config -> isCommandAvailable ( 'entry_create' ))
return $this -> get ( 'CreateMenuItem' , $entry );
else return '' ;
case IdEntryAddAttributeMenuItem :
if ( ! $entry -> isReadOnly () && $config -> isCommandAvailable ( 'attribute_add' ))
return $this -> get ( 'AddAttributeMenuItem' , $entry );
else return '' ;
case IdEntryShowChildrenMenuItem :
case IdEntryExportSubMenuItem :
static $children_count = false ;
static $more_children = false ;
if ( $children_count === false ) {
2009-06-30 11:52:55 +00:00
# Visible children in the tree
2009-06-30 10:46:00 +00:00
$children_count = $entry -> getChildrenNumber ();
2009-06-30 11:52:55 +00:00
# Is there filtered children ?
2009-06-30 10:46:00 +00:00
$more_children = $entry -> isSizeLimited ();
if ( ! $more_children ) {
2009-06-30 11:52:55 +00:00
# All children in ldap
2009-06-30 11:51:50 +00:00
$all_children = $this -> getLDAPServer () -> getContainerContents (
2009-06-30 11:52:55 +00:00
$entry -> getDn (), $children_count + 1 ,
'(objectClass=*)' , $config -> GetValue ( 'deref' , 'view' ));
2009-06-30 10:46:00 +00:00
$more_children = ( count ( $all_children ) > $children_count );
}
}
if ( $children_count > 0 || $more_children ) {
if ( $children_count <= 0 ) $children_count = '' ;
if ( $more_children ) $children_count .= '+' ;
if ( $i == IdEntryShowChildrenMenuItem ) {
return $this -> get ( 'ShowChildrenMenuItem' , $entry , $children_count );
} elseif ( $i == IdEntryExportSubMenuItem && $config -> isCommandAvailable ( 'export' )) {
return $this -> get ( 'ExportSubMenuItem' , $entry );
} else {
return '' ;
}
} else {
return '' ;
}
case IdEntryViewSchemaMessage :
if ( $config -> GetValue ( 'appearance' , 'show_hints' ) && $config -> isCommandAvailable ( 'schema' ))
return array ( '' , $this -> get ( 'ViewSchemaMessage' , $entry ));
else return '' ;
case IdEntryReadOnlyMessage :
if ( $entry -> isReadOnly ())
return array ( '' , $this -> get ( 'ReadOnlyMessage' , $entry ));
else return '' ;
case IdEntryModifiedAttributesMessage :
$modified_attrs = array ();
foreach ( $entry -> getAttributes () as $attr ) {
if ( $attr -> hasBeenModified ())
$modified_attrs [] = $attr -> getFriendlyName ();
}
if ( $modified_attrs ) {
return array ( '' , $this -> get ( 'ModifiedAttributesMessage' , $entry , $modified_attrs ));
} else return '' ;
default :
return false ;
}
}
protected function getDefaultEditingEntryRefreshMenuItem ( $entry ) {
$href = $this -> url_base . '&cmd=template_engine&junk=' . random_junk ();
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'refresh.png' , _ ( 'Refresh' ),
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $href ), _ ( 'Refresh this entry' ), _ ( 'Refresh' ));
}
protected function getDefaultEditingEntryExportBaseMenuItem ( $entry ) {
$href = $this -> url_base . '&cmd=export_form&scope=base' ;
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'save.png' , _ ( 'Save' ),
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $href ), _ ( 'Save a dump of this object' ), _ ( 'Export' ));
}
protected function getDefaultEditingEntryMoveMenuItem ( $entry ) {
$href = $this -> url_base . '&cmd=copy_form' ;
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'cut.png' , _ ( 'Cut' ), htmlspecialchars ( $href ),
2009-06-30 10:46:00 +00:00
_ ( 'Copy this object to another location,a new DN, or another server' ),
_ ( 'Copy or move this entry' ));
}
protected function getDefaultEditingEntryInternalAttributesMenuItem ( $entry ) {
if ( get_request ( 'show_internal_attrs' , 'REQUEST' )) {
$href = $this -> url_base . '&cmd=template_engine&junk=' . random_junk ();
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'tools-no.png' , _ ( 'Hide' ),
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $href ), '' , _ ( 'Hide internal attributes' ));
} else {
$href = $this -> url_base . '&cmd=template_engine&show_internal_attrs=true' ;
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'tools.png' , _ ( 'Show' ),
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $href ), '' , _ ( 'Show internal attributes' ));
}
}
protected function getDefaultEditingEntryDeleteMenuItem ( $entry ) {
$href = $this -> url_base . '&cmd=delete_form' ;
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'trash.png' , _ ( 'Trash' ), htmlspecialchars ( $href ),
2009-06-30 10:46:00 +00:00
_ ( 'You will be prompted to confirm this decision' ), _ ( 'Delete this entry' ));
}
protected function getDefaultEditingEntryRenameMenuItem ( $entry ) {
$href = $this -> url_base . '&cmd=rename_form' ;
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'rename.png' , _ ( 'Rename' ), htmlspecialchars ( $href ), '' , _ ( 'Rename' ));
2009-06-30 10:46:00 +00:00
}
protected function getDefaultEditingEntryCompareMenuItem ( $entry ) {
$href = $this -> url_base . '&cmd=compare_form' ;
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'compare.png' , _ ( 'Compare' ),
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $href ), '' , _ ( 'Compare with another entry' ));
}
protected function getDefaultEditingEntryCreateMenuItem ( $entry ) {
$href = sprintf ( 'cmd.php?cmd=template_engine&server_id=%s&container=%s' ,
2009-06-30 11:51:50 +00:00
$this -> index , rawurlencode ( $entry -> getDn ()));
2009-06-30 10:46:00 +00:00
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'star.png' , _ ( 'Create' ), htmlspecialchars ( $href ), '' , _ ( 'Create a child entry' ));
2009-06-30 10:46:00 +00:00
}
protected function getDefaultEditingEntryAddAttributeMenuItem ( $entry ) {
$href = $this -> url_base . '&cmd=add_attr_form' ;
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'add.png' , _ ( 'Add' ), htmlspecialchars ( $href ), '' , _ ( 'Add new attribute' ));
2009-06-30 10:46:00 +00:00
}
protected function getDefaultEditingEntryShowChildrenMenuItem ( $entry , $children_count ) {
$href = sprintf ( 'cmd.php?cmd=search&server_id=%s&search=true&filter=%s&base_dn=%s&form=advanced&scope=one' ,
2009-06-30 11:51:50 +00:00
$this -> index , rawurlencode ( 'objectClass=*' ), rawurlencode ( $entry -> getDn ()));
2009-06-30 10:46:00 +00:00
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'children.png' , _ ( 'Children' ), htmlspecialchars ( $href ), '' ,
2009-06-30 10:46:00 +00:00
( $children_count == 1 ) ? _ ( 'View 1 child' ) : sprintf ( _ ( 'View %s children' ), $children_count ));
}
protected function getDefaultEditingEntryExportSubMenuItem ( $entry ) {
$href = sprintf ( '%s&cmd=export_form&scope=%s' , $this -> url_base , 'sub' );
2009-06-30 11:51:50 +00:00
return sprintf ( $this -> action_layout , IMGDIR , 'save.png' , _ ( 'Save' ), htmlspecialchars ( $href ),
2009-06-30 10:46:00 +00:00
_ ( 'Save a dump of this object and all of its children' ), _ ( 'Export subtree' ));
}
protected function getDefaultEditingEntryDeleteAttributeMessage ( $entry ) {
2009-06-30 11:52:55 +00:00
if ( $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_delete_value' ) && ! $entry -> isReadOnly ())
2009-06-30 10:46:00 +00:00
return sprintf ( $this -> hint_layout , _ ( 'Hint: To delete an attribute, empty the text field and click save.' ));
else
return '' ;
}
protected function getDefaultEditingEntryViewSchemaMessage ( $entry ) {
return sprintf ( $this -> hint_layout , _ ( 'Hint: To view the schema for an attribute, click the attribute name.' ));
}
protected function getDefaultEditingEntryReadOnlyMessage ( $entry ) {
return sprintf ( $this -> hint_layout , _ ( 'Viewing entry in read-only mode.' ));
}
protected function getDefaultEditingEntryModifiedAttributesMessage ( $entry , & $modified_attributes ) {
return sprintf ( $this -> hint_layout ,
( count ( $modified_attributes ) == 1 )
? sprintf ( _ ( 'An attribute (%s) was modified and is highlighted below.' ), implode ( '' , $modified_attributes ))
: sprintf ( _ ( 'Some attributes (%s) were modified and are highlighted below.' ), implode ( ', ' , $modified_attributes )));
}
protected function drawDefaultEditingEntryInternalAttributes ( $entry ) {
$counter = 0 ;
foreach ( $this -> internal_attributes as $attr ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
2009-06-30 10:46:00 +00:00
$counter ++ ;
echo " \n " ;
}
if ( $counter == 0 ) {
echo '<tr><td colspan="2">(' ;
echo _ ( 'No internal attributes' );
echo ')</td></tr>' ;
}
}
protected function drawDefaultEditingEntryShownAttributes ( $entry ) {
foreach ( $this -> shown_attributes as $attr ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
2009-06-30 10:46:00 +00:00
echo " \n " ;
}
}
protected function drawDefaultEditingEntryHiddenAttributes ( $entry ) {
foreach ( $this -> hidden_attributes as $attr ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
2009-06-30 10:46:00 +00:00
echo " \n " ;
}
}
protected function drawDefaultEditingEntryFormSubmitButton ( $entry ) {
echo '<tr><td colspan="2"><center><input type="submit" value="' ;
echo _ ( 'Save Changes' );
echo '" id="save_button" /></center></td></tr>' ;
}
protected function drawDefaultEditingEntryJavascript ( $entry ) {
$this -> draw ( 'Entry::Javascript' , $entry );
}
/*********************************/
/* Paint a TemplateCreatingEntry */
/*********************************/
public function visitTemplateCreatingEntryStart ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
$template = get_request ( 'template' , 'REQUEST' );
$step = get_request ( 'step' , 'REQUEST' );
if ( $template ) {
if ( $template == 'none' ) {
$this -> visit ( 'DefaultCreatingEntry::Start' , $entry );
return ;
} else {
$entry -> setSelectedTemplateName ( $template );
}
} elseif ( $step && $step > 0 ) {
$this -> visit ( 'DefaultCreatingEntry::Start' , $entry );
return ;
}
if ( $entry -> getSelectedTemplateName ()) {
# if we already choose an creation template, use it to display the entry
$this -> visit ( 'DefaultCreatingEntry::Start' , $entry );
} elseif ( $entry -> getTemplatesCount () <= 0 ) {
# if no template is available for this entry, draws it
# to the parent manner
$this -> visit ( 'DefaultCreatingEntry::Start' , $entry );
} elseif (( $entry -> getTemplatesCount () == 1 ) && ! $entry -> hasDefaultTemplate ()) {
$templates = & $entry -> getTemplates ();
$template_names = array_keys ( $templates );
$entry -> setSelectedTemplateName ( $template_names [ 0 ]);
$this -> visit ( 'DefaultCreatingEntry::Start' , $entry );
} else {
$this -> visit_attributes = false ;
# propose the template choice
$this -> draw ( 'TemplateChoice' , $entry );
}
}
public function visitTemplateCreatingEntryEnd ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
if ( $this -> visit_attributes ) {
foreach ( $this -> shown_attributes as $attr ) {
$page = 1 ;
if ( $attr -> hasProperty ( 'page' )) {
$page = $attr -> getProperty ( 'page' );
} else {
$attr -> setProperty ( 'page' , 1 );
}
if ( $page && $page > $this -> laststep ) {
$this -> laststep = $page ;
}
}
$this -> visit ( 'DefaultCreatingEntry::End' , $entry );
$entry -> setSelectedTemplateName ( '' );
}
}
protected function initTemplateCreatingEntryVisit ( $entry ) {
$this -> init ( 'DefaultCreatingEntry::Visit' , $entry );
$this -> laststep = 1 ;
}
protected function drawTemplateCreatingEntryRdnChooser ( $entry ) {
$rdn_attr = $entry -> getRdnAttribute ();
if ( ! $rdn_attr ) {
$this -> draw ( 'DefaultCreatingEntry::RdnChooser' , $entry );
} else {
printf ( '<input type="hidden" name="rdn_attribute" value="%s" />' , htmlspecialchars ( $rdn_attr -> getName ()));
}
}
protected function drawTemplateCreatingEntryStepTitle ( $entry , $step ) {
if ( ! $entry -> getSelectedTemplateName ()) {
$this -> draw ( 'DefaultCreatingEntry::StepTitle' , $entry , $step );
} else if ( $entry -> hasProperty ( 'description' )) {
echo '<center><h4>' ;
echo $entry -> getProperty ( 'description' );
echo ' ' ;
echo _ ( '(' );
printf ( _ ( 'step %s of %s' ), $step , $this -> laststep );
echo _ ( ')' );
echo '</h4></center>' ;
}
}
public function drawTemplateCreatingEntryStepFormStart ( $entry , $step ) {
if ( $entry -> getSelectedTemplateName ()) {
if ( $step < $this -> laststep ) {
echo '<form action="cmd.php?cmd=template_engine" method="post" enctype="multipart/form-data" name="entry_form" onSubmit="return submitForm(this)">' ;
} else {
echo '<form action="cmd.php" method="post" enctype="multipart/form-data" name="entry_form" onSubmit="return submitForm(this)">' ;
printf ( '<input type="hidden" name="cmd" value="%s" />' ,
$entry -> hasProperty ( 'action' ) ? rawurlencode ( $entry -> getProperty ( 'action' )) : 'create' );
}
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
} else {
$this -> draw ( 'DefaultCreatingEntry::StepFormStart' , $entry , $step );
}
}
public function drawTemplateCreatingEntryStepForm ( $entry , $step ) {
if ( ! $entry -> getSelectedTemplateName ()) {
$this -> draw ( 'DefaultCreatingEntry::StepForm' , $entry , $step );
return ;
}
$container = $entry -> getContainer ();
printf ( '<input type="hidden" name="container" value="%s" />' , htmlspecialchars ( $container ));
2009-06-30 11:51:50 +00:00
printf ( '<input type="hidden" name="server_id" value="%s" />' , $this -> index );
2009-06-30 10:46:00 +00:00
printf ( '<input type="hidden" name="template" value="%s" />' , $entry -> getSelectedTemplateName ());
printf ( '<input type="hidden" name="step" value="%s" />' , $step + 1 );
2009-06-30 11:51:50 +00:00
echo '<table class="entry" cellspacing="0" align="center">' ;
2009-06-30 10:46:00 +00:00
$this -> draw ( 'RdnChooser' , $entry );
2009-06-30 11:52:55 +00:00
# Draw attributes
2009-06-30 10:46:00 +00:00
$this -> draw ( 'ShownAttributes' , $entry );
$this -> draw ( 'StepFormSubmitButton' , $entry , $step );
echo '</table>' ;
$this -> draw ( 'HiddenAttributes' , $entry );
}
protected function drawTemplateCreatingEntryStepFormSubmitButton ( $entry , $step ) {
if ( $step < $this -> laststep ) $this -> draw ( 'DefaultCreatingEntry::StepFormSubmitButton' , $entry , 1 );
else $this -> draw ( 'DefaultCreatingEntry::StepFormSubmitButton' , $entry , 2 );
}
protected function drawTemplateCreatingEntryTemplateChoice ( $entry ) {
$this -> draw ( 'Title' , $entry );
$this -> draw ( 'Subtitle' , $entry );
echo " \n " ;
printf ( '<center><h3>%s</h3></center>' , _ ( 'Select a template for the creation process' ));
$href = sprintf ( 'cmd.php?%s' , array_to_query_string ( $_GET , array ( 'meth' ), false ));
echo '<form name="template_choice_form" action="' . htmlspecialchars ( $href ) . '" method="post">' ;
foreach ( $_POST as $p => $v ) {
echo " <input type= \" hidden \" name= \" $p\ " value = \ " $v\ " > " ;
}
2009-06-30 11:51:50 +00:00
echo '<table class="forminput" width="100%" border=0>' ;
2009-06-30 10:46:00 +00:00
2009-06-30 11:51:50 +00:00
$server_menu_html = server_select_list ( $this -> index , true );
printf ( '<tr><td class="heading">%s%s</td><td colspan=2>%s</td></tr>' , _ ( 'Server' ), _ ( ':' ), $server_menu_html );
2009-06-30 10:46:00 +00:00
echo '<tr>' ;
printf ( '<td class="heading">%s%s</td>' , _ ( 'Templates' ), _ ( ':' ));
echo '<td>' ;
2009-06-30 11:51:50 +00:00
echo '<table border=0>' ;
2009-06-30 10:46:00 +00:00
$i = - 1 ;
$templates = & $entry -> getTemplates ();
$nb_templates = count ( $templates );
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
if ( $entry -> hasDefaultTemplate ()) $nb_templates ++ ;
foreach ( $templates as $template_name => $template_attrs ) {
$i ++ ;
# If the template doesnt have a title, we'll use the desc field.
$template_attrs [ 'desc' ] = isset ( $template_attrs [ 'title' ]) ? $template_attrs [ 'title' ] : $template_attrs [ 'desc' ];
# Balance the columns properly
if (( $nb_templates % 2 == 0 && $i == intval ( $nb_templates / 2 )) ||
( $nb_templates % 2 == 1 && $i == intval ( $nb_templates / 2 ) + 1 )) {
2009-06-30 11:51:50 +00:00
echo '</table></td><td><table>' ;
2009-06-30 10:46:00 +00:00
}
echo '<tr>' ;
if ( isset ( $template_attrs [ 'invalid' ]) && $template_attrs [ 'invalid' ]) {
2009-06-30 11:51:50 +00:00
printf ( '<td class="icon"><img src="%s/error.png" alt="Error" /></td>' , IMGDIR );
2009-06-30 10:46:00 +00:00
} else {
printf ( '<td><input type="radio" name="template" value="%s" id="%s" onclick="document.forms.template_choice_form.submit()" /></td>' ,
htmlspecialchars ( $template_name ), htmlspecialchars ( $template_name ));
}
printf ( '<td class="icon"><label for="%s"><img src="%s" alt="" /></label></td>' ,
htmlspecialchars ( $template_name ), $template_attrs [ 'icon' ]);
2009-06-30 11:51:50 +00:00
printf ( '<td class="label"><label for="%s">' ,
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $template_name ));
if ( isset ( $template_attrs [ 'invalid' ]) && $template_attrs [ 'invalid' ]) {
printf ( '<span style="color: gray"><acronym title="%s">' , _ ( 'This template is not allowed in this container.' ));
}
echo htmlspecialchars ( $template_attrs [ 'desc' ]);
if ( isset ( $template_attrs [ 'invalid' ]) && $template_attrs [ 'invalid' ]) {
echo '</acronym></span>' ;
}
echo '</label></td></tr>' ;
}
# Default template
if ( $entry -> hasDefaultTemplate ()) {
$i ++ ;
if (( $nb_templates % 2 == 0 && $i == intval ( $nb_templates / 2 )) ||
( $nb_templates % 2 == 1 && $i == intval ( $nb_templates / 2 ) + 1 )) {
2009-06-30 11:51:50 +00:00
echo '</table></td><td><table>' ;
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:51:50 +00:00
echo '<tr>' ;
echo '<td><input type="radio" name="template" value="none" onclick="document.forms.template_choice_form.submit()" /></td>' ;
printf ( '<td class="icon"><label><img src="%s/object.png" alt="" /></label></td>' , IMGDIR );
printf ( '<td class="label"><label>%s</label></td></tr>' , _ ( 'Default' ));
2009-06-30 10:46:00 +00:00
}
echo '</table>' ;
echo '</td></tr>' ;
echo '</table>' ;
echo '</form>' ;
}
protected function drawTemplateCreatingEntryShownAttributes ( $entry ) {
if ( ! $entry -> getSelectedTemplateName ()) {
$this -> draw ( 'DefaultCreatingEntry::ShownAttributes' , $entry );
return ;
}
foreach ( $this -> shown_attributes as $attr ) {
$page = $attr -> getProperty ( 'page' );
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
if ( $page == $this -> step ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
2009-06-30 10:46:00 +00:00
echo " \n " ;
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
} else {
2009-06-30 11:52:55 +00:00
# The displayed attributes are the visible attributes in shown_attributes list
2009-06-30 10:46:00 +00:00
$attr -> hide ();
$this -> hidden_attributes [] = $attr ;
}
}
}
protected function drawTemplateCreatingEntryHiddenAttributes ( $entry ) {
if ( ! $entry -> getSelectedTemplateName ()) {
$this -> draw ( 'DefaultCreatingEntry::HiddenAttributes' , $entry );
return ;
}
foreach ( $this -> hidden_attributes as $attr ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
}
protected function drawTemplateCreatingEntryJavascript ( $entry ) {
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- START: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
$this -> draw ( 'DefaultCreatingEntry::Javascript' , $entry );
2009-06-30 11:51:50 +00:00
$templates = new Templates ( $this -> index );
2009-06-30 10:46:00 +00:00
foreach ( $entry -> getAttributes () as $attribute ) {
if ( $attribute -> hasProperty ( 'onchange' )) {
$onchange = $attribute -> getProperty ( 'onchange' );
if ( is_array ( $onchange )) {
foreach ( $onchange as $value )
2009-06-30 11:51:50 +00:00
$templates -> OnChangeAdd ( $this -> getLDAPServer (), $attribute -> getName (), $value );
2009-06-30 10:46:00 +00:00
} else {
2009-06-30 11:51:50 +00:00
$templates -> OnChangeAdd ( $this -> getLDAPServer (), $attribute -> getName (), $onchange );
2009-06-30 10:46:00 +00:00
}
}
}
$hash = $templates -> getJsHash ();
echo ' < script type = " text/javascript " language = " javascript " >
var attrTrace ;
function fill ( id , value ) {
attrTrace = new Array ();
fillRec ( id , value );
}
function fillRec ( id , value ) {
if ( attrTrace [ id ] == 1 ) {
return ;
} else {
var pre = " " ;
var suf = " " ;
var i ;
attrTrace [ id ] = 1 ;
pla_setComponentValue ( pla_getComponentById ( id ), value );
// here comes template-specific implementation, generated by php
if ( false ) {} ' ;
foreach ( $entry -> getAttributes () as $attribute ) {
2009-06-30 11:52:55 +00:00
if ( $attribute -> isVisible () && ( $attribute -> hasProperty ( 'onchange' )) || $attribute -> isRequired ()) {
$attr = $attribute -> getName ();
echo " \n \t \t \t \t \t else if ((i = id.indexOf('_ " . $attr . " _')) >= 0) { \n " ;
echo " \t \t \t \t \t \t pre = id.substring(0, i+1); \n " ;
echo " \t \t \t \t \t \t suf = id.substring(i + 1 + ' $attr '.length, id.length); \n " ;
$this -> draw ( 'FillJavascript' , $attribute , 'id' , 'value' );
if ( isset ( $hash [ 'autoFill' . $attr ])) {
echo $hash [ 'autoFill' . $attr ];
}
echo " \t \t \t } \n " ;
2009-06-30 10:46:00 +00:00
}
}
echo '}}</script>' ;
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- END: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
}
/********************************/
/* Paint a TemplateEditingEntry */
/********************************/
public function visitTemplateEditingEntryStart ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
$template = get_request ( 'template' , 'REQUEST' );
if ( $template ) {
if ( $template == 'none' ) {
$this -> visit ( 'DefaultEditingEntry::Start' , $entry );
return ;
} else {
$entry -> setSelectedTemplateName ( $template );
}
}
if ( $entry -> getSelectedTemplateName ()) {
# if we already choose an editing template, use it to display the entry
$this -> visit ( 'DefaultEditingEntry::Start' , $entry );
} elseif ( $entry -> getTemplatesCount () <= 0 ) {
# if no template is available for this entry, draws it
# to the parent manner
$this -> visit ( 'DefaultEditingEntry::Start' , $entry );
} elseif (( $entry -> getTemplatesCount () == 1 ) && ! $entry -> hasDefaultTemplate ()) {
$templates = & $entry -> getTemplates ();
$template_names = array_keys ( $templates );
$entry -> setSelectedTemplateName ( $template_names [ 0 ]);
$this -> visit ( 'DefaultEditingEntry::Start' , $entry );
} else {
$this -> visit_attributes = false ;
# propose the template choice
$this -> draw ( 'TemplateChoice' , $entry );
}
}
public function visitTemplateEditingEntryEnd ( $entry ) {
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $entry -> getDn ());
if ( $this -> visit_attributes ) {
$this -> visit ( 'DefaultEditingEntry::End' , $entry );
$entry -> setSelectedTemplateName ( '' );
}
}
protected function drawTemplateEditingEntryTemplateChoice ( $entry ) {
$this -> draw ( 'Title' , $entry );
$this -> draw ( 'Subtitle' , $entry );
echo " \n " ;
printf ( '<center><h3>%s</h3></center>' , _ ( 'Select a template to edit the entry' ));
$href = sprintf ( 'cmd.php?%s' , array_to_query_string ( $_GET , array ( 'meth' ), false ));
echo '<form name="template_choice_form" action="' . htmlspecialchars ( $href ) . '" method="post">' ;
foreach ( $_POST as $p => $v ) {
echo " <input type= \" hidden \" name= \" $p\ " value = \ " $v\ " > " ;
}
2009-06-30 11:51:50 +00:00
echo '<table class="forminput" width="100%" border=0>' ;
2009-06-30 10:46:00 +00:00
echo '<tr>' ;
printf ( '<td class="heading">%s%s</td>' , _ ( 'Templates' ), _ ( ':' ));
echo '<td>' ;
2009-06-30 11:51:50 +00:00
echo '<table>' ;
2009-06-30 10:46:00 +00:00
$i = - 1 ;
$templates = & $entry -> getTemplates ();
$nb_templates = count ( $templates );
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
if ( $entry -> hasDefaultTemplate ()) $nb_templates ++ ;
foreach ( $templates as $template_name => $template_attrs ) {
$i ++ ;
# If the template doesnt have a title, we'll use the desc field.
$template_attrs [ 'desc' ] = isset ( $template_attrs [ 'title' ]) ? $template_attrs [ 'title' ] : $template_attrs [ 'desc' ];
# Balance the columns properly
if (( $nb_templates % 2 == 0 && $i == intval ( $nb_templates / 2 )) ||
( $nb_templates % 2 == 1 && $i == intval ( $nb_templates / 2 ) + 1 )) {
2009-06-30 11:51:50 +00:00
echo '</table></td><td><table>' ;
2009-06-30 10:46:00 +00:00
}
echo '<tr>' ;
2009-06-30 11:51:50 +00:00
printf ( '<td><input type="radio" name="template" value="%s" id="%s" onclick="document.forms.template_choice_form.submit()" /></td>' ,
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $template_name ), htmlspecialchars ( $template_name ));
printf ( '<td class="icon"><label for="%s"><img src="%s" alt="" /></label></td>' ,
htmlspecialchars ( $template_name ), $template_attrs [ 'icon' ]);
2009-06-30 11:51:50 +00:00
printf ( '<td class="label"><label for="%s">' , htmlspecialchars ( $template_name ));
2009-06-30 10:46:00 +00:00
echo htmlspecialchars ( $template_attrs [ 'desc' ]);
echo '</label></td></tr>' ;
}
# Default template
if ( $entry -> hasDefaultTemplate ()) {
$i ++ ;
if (( $nb_templates % 2 == 0 && $i == intval ( $nb_templates / 2 )) ||
( $nb_templates % 2 == 1 && $i == intval ( $nb_templates / 2 ) + 1 )) {
2009-06-30 11:51:50 +00:00
echo '</table></td><td><table>' ;
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:51:50 +00:00
echo '<tr>' ;
echo '<td><input type="radio" name="template" value="none" onclick="document.forms.template_choice_form.submit()" /></td>' ;
printf ( '<td class="icon"><label><img src="%s/object.png" alt="" /></label></td>' , IMGDIR );
printf ( '<td class="label"><label>%s</label></td></tr>' , _ ( 'Default' ));
2009-06-30 10:46:00 +00:00
}
echo '</table>' ;
echo '</td></tr>' ;
echo '</table>' ;
echo '</form>' ;
}
protected function drawTemplateEditingEntryShownAttributes ( $entry ) {
foreach ( $this -> shown_attributes as $attr ) {
// @todo if this->page == attr->page
2009-06-30 11:52:55 +00:00
$this -> draw ( '' , $attr , $entry );
2009-06-30 10:46:00 +00:00
echo " \n " ;
}
}
protected function drawTemplateEditingEntryHiddenAttributes ( $entry ) {
printf ( '<input type="hidden" name="template" value="%s" />' , $entry -> getSelectedTemplateName ());
$this -> draw ( 'DefaultEditingEntry::HiddenAttributes' , $entry );
}
protected function drawTemplateEditingEntryJavascript ( $entry ) {
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- START: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
$this -> draw ( 'DefaultEditingEntry::Javascript' , $entry );
2009-06-30 11:51:50 +00:00
$templates = new Templates ( $this -> index );
2009-06-30 10:46:00 +00:00
foreach ( $entry -> getAttributes () as $attribute ) {
if ( $attribute -> hasProperty ( 'onchange' )) {
$onchange = $attribute -> getProperty ( 'onchange' );
if ( is_array ( $onchange )) {
foreach ( $onchange as $value )
2009-06-30 11:51:50 +00:00
$templates -> OnChangeAdd ( $this -> getLDAPServer (), $attribute -> getName (), $value );
2009-06-30 10:46:00 +00:00
} else {
2009-06-30 11:51:50 +00:00
$templates -> OnChangeAdd ( $this -> getLDAPServer (), $attribute -> getName (), $onchange );
2009-06-30 10:46:00 +00:00
}
}
}
$hash = $templates -> getJsHash ();
echo ' < script type = " text/javascript " language = " javascript " >
var attrTrace ;
function fill ( id , value ) {
attrTrace = new Array ();
fillRec ( id , value );
}
function fillRec ( id , value ) {
if ( attrTrace [ id ] == 1 ) {
return ;
} else {
var pre = " " ;
var suf = " " ;
var i ;
attrTrace [ id ] = 1 ;
pla_setComponentValue ( pla_getComponentById ( id ), value );
// here comes template-specific implementation, generated by php
if ( false ) {} ' ;
foreach ( $entry -> getAttributes () as $attribute ) {
2009-06-30 11:52:55 +00:00
if ( $attribute -> isVisible () && ( $attribute -> hasProperty ( 'onchange' )) || $attribute -> isRequired ()) {
$attr = $attribute -> getName ();
echo " \n \t \t \t else if ((i = id.indexOf('_ " . $attr . " _')) >= 0) { \n " ;
echo " \t \t \t \t pre = id.substring(0, i+1); \n " ;
echo " \t \t \t \t suf = id.substring(i + 1 + ' $attr '.length, id.length); \n " ;
$this -> draw ( 'FillJavascript' , $attribute , 'id' , 'value' );
if ( isset ( $hash [ 'autoFill' . $attr ])) {
echo $hash [ 'autoFill' . $attr ];
}
echo " \t \t \t } \n " ;
2009-06-30 10:46:00 +00:00
}
}
echo '}}</script>' ;
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- END: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
}
/**************************/
/* Paint an Attribute */
/**************************/
2009-06-30 11:52:55 +00:00
protected function drawAttribute ( $attribute , $entry ) {
2009-06-30 10:46:00 +00:00
if ( $attribute -> isVisible ()) $this -> draw ( 'Informations' , $attribute );
2009-06-30 11:52:55 +00:00
$this -> draw ( 'Values' , $attribute , $entry );
2009-06-30 10:46:00 +00:00
}
protected function drawAttributeJavascript ( $attribute ) {
2009-06-30 11:52:55 +00:00
echo '<script type="text/javascript" language="javascript">' . " \n " ;
2009-06-30 10:46:00 +00:00
echo 'function focus_' . $attribute -> getName () . '(component) {' ;
$this -> draw ( 'FocusJavascript' , $attribute , 'component' );
2009-06-30 11:52:55 +00:00
echo '}' . " \n " ;
2009-06-30 10:46:00 +00:00
echo 'function blur_' . $attribute -> getName () . '(component) {' ;
$this -> draw ( 'BlurJavascript' , $attribute , 'component' );
2009-06-30 11:52:55 +00:00
echo '}' . " \n " ;
2009-06-30 10:46:00 +00:00
echo 'function validate_' . $attribute -> getName () . '(component, silence) {' ;
echo ' var valid = true;' ;
$this -> draw ( 'ValidateJavascript' , $attribute , 'component' , 'silence' , 'valid' );
2009-06-30 11:52:55 +00:00
echo ' if (valid) { component.style.backgroundColor = "white"; component.style.color = "black"; }' ;
echo ' else { component.style.backgroundColor = \'#FFFFA0\'; component.style.color = "black"; }' ;
2009-06-30 10:46:00 +00:00
echo ' return valid;' ;
2009-06-30 11:52:55 +00:00
echo '}' . " \n " ;
echo '</script>' . " \n " ;
2009-06-30 10:46:00 +00:00
}
protected function drawAttributeFocusJavascript ( $attribute , $component ) {
$entry = $attribute -> getEntry ();
if ( $entry )
echo $this -> get ( 'AttributeFocusJavascript' , $entry , $attribute , $component );
}
protected function drawAttributeBlurJavascript ( $attribute , $component ) {
$entry = $attribute -> getEntry ();
if ( $entry )
echo $this -> get ( 'AttributeBlurJavascript' , $entry , $attribute , $component );
}
protected function drawAttributeValidateJavascript ( $attribute , $component , $silence , $var_valid ) {
if ( $attribute -> isRequired ()) {
echo 'var vals = getAttributeValues("new", "' . $attribute -> getName () . ' " );
if ( vals . length <= 0 ) {
'.$var_valid.' = false ;
2009-06-30 11:52:55 +00:00
alertError ( " '._('This attribute is required')._(':').' '. $attribute->getFriendlyName ().' " , '.$silence.' );
2009-06-30 10:46:00 +00:00
} ' ;
echo 'var comp = getAttributeComponents("new", "' . $attribute -> getName () . ' " );
for ( var i = 0 ; i < comp . length ; i ++ ) {
2009-06-30 11:52:55 +00:00
comp [ i ] . style . backgroundColor = '.$var_valid.' ? " white " : \ ' #FFFFA0\';
comp [ i ] . style . color = '.$var_valid.' ? " black " : \ ' #00005F\';
2009-06-30 10:46:00 +00:00
} ' ;
}
}
protected function getEntryAttributeFocusJavascript ( $entry , $attribute , $component ) {
return '' ;
}
protected function getEntryAttributeBlurJavascript ( $entry , $attribute , $component ) {
return '' ;
}
protected function getDefaultCreatingEntryAttributeBlurJavascript ( $entry , $attribute , $component ) {
return " \n \t \t \t \t \t \t " . 'validate_' . $attribute -> getName () . '(' . $component . ', false);' . " \n " ;
}
protected function getTemplateCreatingEntryAttributeBlurJavascript ( $entry , $attribute , $component ) {
$j = 'fill(' . $component . '.id, pla_getComponentValue(' . $component . '));' ;
return $j ;
}
protected function getDefaultEditingEntryAttributeBlurJavascript ( $entry , $attribute , $component ) {
return " \n \t \t \t \t \t \t " . 'validate_' . $attribute -> getName () . '(' . $component . ', false);' . " \n " ;
}
protected function getTemplateEditingEntryAttributeBlurJavascript ( $entry , $attribute , $component ) {
$j = 'fill(' . $component . '.id, pla_getComponentValue(' . $component . '));' ;
return $j ;
}
protected function drawAttributeFillJavascript ( $attribute , $component_id , $component_value ) {
echo " \n \t \t \t \t \t \t " . 'validate_' . $attribute -> getName () . '(pla_getComponentById(' . $component_id . '), false);' . " \n " ;
}
protected function drawAttributeInformations ( $attribute ) {
2009-06-30 11:51:50 +00:00
if (( $this -> context == ENTRY_WRITER_EDITING_CONTEXT ) && $attribute -> hasBeenModified ()) echo '<tr class="updated">' ;
2009-06-30 10:46:00 +00:00
else echo '<tr>' ;
2009-06-30 11:51:50 +00:00
echo '<td class="title">' ;
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Name' , $attribute );
echo '</td>' ;
2009-06-30 11:51:50 +00:00
echo '<td class="note">' ;
2009-06-30 10:46:00 +00:00
# Setup the $attr_note, which will be displayed to the right of the attr name (if any)
2009-06-30 11:46:44 +00:00
if ( $_SESSION [ APPCONFIG ] -> GetValue ( 'appearance' , 'show_attribute_notes' )) {
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Notes' , $attribute );
}
echo '</td>' ;
echo '</tr>' ;
}
protected function drawAttributeNotes ( $attribute ) {
$attr_note = '' ;
$alias_note = $this -> get ( 'AliasNote' , $attribute );
if ( $alias_note ) {
if ( trim ( $attr_note )) $attr_note .= ', ' ;
$attr_note .= $alias_note ;
}
$required_note = $this -> get ( 'RequiredNote' , $attribute );
if ( $required_note ) {
if ( trim ( $attr_note )) $attr_note .= ', ' ;
$attr_note .= $required_note ;
}
$rdn_note = $this -> get ( 'RdnNote' , $attribute );
if ( $rdn_note ) {
if ( trim ( $attr_note )) $attr_note .= ', ' ;
$attr_note .= $rdn_note ;
}
2009-06-30 11:52:55 +00:00
$hint_note = $this -> get ( 'HintNote' , $attribute );
if ( $hint_note ) {
if ( trim ( $attr_note )) $attr_note .= ', ' ;
$attr_note .= $hint_note ;
}
2009-06-30 10:46:00 +00:00
if ( $attr_note ) printf ( '<sup><small>%s</small></sup>' , $attr_note );
2009-06-30 11:51:50 +00:00
if ( $attribute -> isReadOnly () && $this -> getLDAPServer () -> isAttrReadOnly ( $attribute -> getName ())) {
2009-06-30 10:46:00 +00:00
printf ( '<small>(<acronym title="%s">%s</acronym>)</small>' ,
_ ( 'This attribute has been flagged as read only by the phpLDAPadmin administrator' ),
_ ( 'read only' ));
}
}
2009-06-30 11:52:55 +00:00
protected function drawAttributeValues ( $attribute , $entry ) {
2009-06-30 10:46:00 +00:00
if ( $attribute -> isVisible ()) $this -> draw ( 'StartValueLine' , $attribute );
# draws values
$value_count = $attribute -> getValueCount ();
$i = 0 ;
for (; $i < $value_count ; $i ++ ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( 'Value' , $attribute , $i , $entry );
2009-06-30 10:46:00 +00:00
}
if ( $this -> context == ENTRY_WRITER_CREATION_CONTEXT ) {
$blankvalue_count = $attribute -> getMaxValueCount ();
if ( $blankvalue_count < 0 ) $blankvalue_count = 1 ;
else $blankvalue_count -= $value_count ;
for ( $j = 0 ; $j < $blankvalue_count ; $j ++ ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( 'BlankValue' , $attribute , $i + $j , $entry );
2009-06-30 10:46:00 +00:00
}
}
if ( $attribute -> isVisible ()) {
$this -> draw ( 'Menu' , $attribute );
$this -> draw ( 'EndValueLine' , $attribute );
}
}
protected function drawAttributeMenu ( $attribute ) {
$i = 0 ;
$item = '' ;
while (( $item = $this -> get ( 'MenuItem' , $attribute , $i )) !== false ) {
if ( $item ) {
echo '<div class="add_value">' . $item . '</div>' ;
}
$i ++ ;
}
}
protected function getAttributeMenuItem ( $attribute , $i ) {
if ( $this -> context != ENTRY_WRITER_EDITING_CONTEXT )
return false ;
switch ( $i ) {
case IdAttributeAddValueMenuItem :
if ( $attribute -> isVisible () && ! $attribute -> isReadOnly ()
2009-06-30 11:52:55 +00:00
&& $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_add_value' )) {
2009-06-30 10:46:00 +00:00
if ( $attribute -> getMaxValueCount () < 0 || $attribute -> getValueCount () < $attribute -> getMaxValueCount ()) {
return $this -> get ( 'AddValueMenuItem' , $attribute );
}
}
return '' ;
case IdAttributeModifyMemberMenuItem :
2009-06-30 11:46:44 +00:00
if ( in_array ( $attribute -> getName (), $_SESSION [ APPCONFIG ] -> GetValue ( 'modify_member' , 'groupattr' ))) {
2009-06-30 10:46:00 +00:00
if ( $attribute -> isVisible () && ! $attribute -> isReadOnly () && ! $attribute -> isRdn ()
2009-06-30 11:46:44 +00:00
&& ( $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_add_value' )
|| $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_delete_value' ))) {
2009-06-30 10:46:00 +00:00
return $this -> get ( 'ModifyMemberMenuItem' , $attribute );
}
}
return '' ;
case IdAttributeRenameMenuItem :
if ( $attribute -> isVisible () && $attribute -> isRdn () && ! $attribute -> isReadOnly ()
2009-06-30 11:46:44 +00:00
&& $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'entry_rename' )) {
2009-06-30 10:46:00 +00:00
return $this -> get ( 'RenameMenuItem' , $attribute );
}
return '' ;
default :
return false ;
}
}
protected function drawAttributeStartValueLine ( $attribute ) {
if (( $this -> context == ENTRY_WRITER_EDITING_CONTEXT ) && $attribute -> hasBeenModified ()) {
2009-06-30 11:51:50 +00:00
echo '<tr class="updated">' ;
2009-06-30 10:46:00 +00:00
} else {
echo '<tr>' ;
}
2009-06-30 11:51:50 +00:00
echo '<td class="value" colspan="2">' ;
2009-06-30 10:46:00 +00:00
}
protected function drawAttributeEndValueLine ( $attribute ) {
echo '</td>' ;
echo '</tr>' ;
if (( $this -> context == ENTRY_WRITER_EDITING_CONTEXT ) && $attribute -> hasBeenModified ()) {
2009-06-30 11:51:50 +00:00
echo '<tr class="updated"><td class="bottom" colspan="2"></td></tr>' ;
2009-06-30 10:46:00 +00:00
}
}
2009-06-30 11:52:55 +00:00
protected function drawAttributeValue ( $attribute , $i , $entry ) {
2009-06-30 10:46:00 +00:00
if ( DEBUG_ENABLED )
debug_log ( 'Entered with (%s, %d)' , 1 , __FILE__ , __LINE__ , __METHOD__ , $attribute -> getName (), $i );
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $attribute -> isVisible ()) {
echo '<table cellspacing="0" cellpadding="0" width="100%"><tr><td>' ;
$this -> draw ( 'Icon' , $attribute , $val );
echo '</td><td valign="top">' ;
}
$this -> draw ( 'OldValue' , $attribute , $i );
2009-06-30 11:52:55 +00:00
$this -> draw ( 'NewValue' , $attribute , $i , $entry );
2009-06-30 10:46:00 +00:00
if ( $attribute -> isVisible ()) {
echo '</td><td valign="top" align="right" width="100%">' ;
if (( $i == 0 ) && $attribute -> isRequired () && $attribute -> getEntry () && ! $attribute -> getEntry () -> isReadOnly ()) {
echo ' ' ;
$this -> draw ( 'RequiredSymbol' , $attribute );
}
echo '</td></tr></table>' ;
}
}
/**
* Save the current value to detect changes
*/
protected function drawAttributeOldValue ( $attribute , $i ) {
2009-06-30 11:52:55 +00:00
if ( $this -> context == ENTRY_WRITER_EDITING_CONTEXT )
$val = $attribute -> getValue ( $i );
else
$val = '' ;
2009-06-30 10:46:00 +00:00
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
printf ( '<input type="hidden" name="old_values[%s][%s]" value="%s" />' ,
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $val ));
}
/**
* Display the current value
*/
2009-06-30 11:52:55 +00:00
protected function drawAttributeNewValue ( $attribute , $i , $entry ) {
2009-06-30 10:46:00 +00:00
if ( ! $attribute -> isVisible ()) {
$this -> draw ( 'HiddenValue' , $attribute , $i );
2009-06-30 11:52:55 +00:00
$this -> draw ( 'Javascript' , $attribute );
2009-06-30 10:46:00 +00:00
} elseif ( $attribute -> isReadOnly () || ( $attribute -> getEntry () && $attribute -> getEntry () -> getDn () && $attribute -> isRdn ())) {
2009-06-30 11:52:55 +00:00
/* If this is the RDN , we need to see if it has multiple values . If it does , and the multivalues are not
* not in the RDN , then we need to make them editable . */
if ( $attribute -> isRdn ()) {
$rdn = split ( '\+' , get_rdn ( $entry -> getDN ()));
if ( in_array ( sprintf ( '%s=%s' , $attribute -> getName (), $attribute -> getValue ( $i )), $rdn ))
$this -> draw ( 'ReadOnlyValue' , $attribute , $i );
else
$this -> draw ( 'ReadWriteValue' , $attribute , $i );
} else
$this -> draw ( 'ReadOnlyValue' , $attribute , $i );
2009-06-30 10:46:00 +00:00
} else {
$this -> draw ( 'ReadWriteValue' , $attribute , $i );
2009-06-30 11:52:55 +00:00
}
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:52:55 +00:00
protected function drawAttributeBlankValue ( $attribute , $i , $entry ) {
$this -> draw ( 'Value' , $attribute , $i , $entry );
2009-06-30 10:46:00 +00:00
}
protected function drawAttributeHiddenValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
2009-06-30 11:51:50 +00:00
printf ( '<input type="hidden" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" />' ,
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $val ));
}
protected function drawAttributeReadOnlyValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
printf ( '<input type="text" class="roval" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" %s readonly /><br />' ,
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $attribute -> getName ()),
$i , htmlspecialchars ( $val ), ( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' );
}
protected function drawAttributeReadWriteValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
if ( $attribute -> hasProperty ( 'helper' )) {
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">' ;
}
/* We smack an id = " ... " tag in here that doesn ' t have [][] in it to allow the
* draw_chooser_link () to identify it after the user clicks . */
$id = sprintf ( 'new_values_%s_%s' , htmlspecialchars ( $attribute -> getName ()), $i );
2009-06-30 11:51:50 +00:00
printf ( '<input type="text" class="value" name="new_values[%s][%s]"' .
2009-06-30 10:46:00 +00:00
' id="%s" value="%s" onFocus="focus_%s(this);" onBlur="blur_%s(this);" %s %s/>' ,
htmlspecialchars ( $attribute -> getName ()), $i , $id ,
htmlspecialchars ( $val ), $attribute -> getName (), $attribute -> getName (),
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
if ( $attribute -> hasProperty ( 'helper' )) {
echo '</td><td valign="top">' ;
$this -> draw ( 'Helper' , $attribute , $i );
echo '</td></tr></table>' ;
}
}
protected function drawAttributeHelper ( $attribute , $i ) {
$params = $attribute -> getProperty ( 'helper' );
if ( ! $params ) $params = array ();
elseif ( ! is_array ( $params )) $params = array ( $params );
$id = isset ( $params [ 'id' ]) ? $params [ 'id' ] : '' ;
if ( is_array ( $id )) $id = ( count ( $id ) > 0 ? $id [ 0 ] : '' );
$display = isset ( $params [ 'display' ]) ? $params [ 'display' ] : '' ;
if ( is_array ( $display )) $display = ( count ( $display ) > 0 ? $display [ 0 ] : '' );
$vals = isset ( $params [ 'value' ]) ? $params [ 'value' ] : array ();
if ( ! is_array ( $vals )) $vals = array ( $vals );
$opts = isset ( $params [ 'option' ]) ? $params [ 'option' ] : array ();
if ( ! is_array ( $opts )) $opts = array ( $opts );
$dn = '' ;
if ( $attribute -> getEntry ()) {
if ( $this -> context == ENTRY_WRITER_CREATION_CONTEXT ) {
$dn = $attribute -> getEntry () -> getContainer ();
} else {
$dn = $attribute -> getEntry () -> getDn ();
}
}
2009-06-30 11:51:50 +00:00
$ldapserver = $this -> getLDAPServer ();
2009-06-30 10:46:00 +00:00
$arr1 = array ();
foreach ( $vals as $id_parval => $parval ) {
2009-06-30 11:51:50 +00:00
$arr2 = Templates :: EvaluateDefault ( $ldapserver , $parval , $dn , null , null );
2009-06-30 10:46:00 +00:00
if ( is_array ( $arr2 )) $arr1 = array_merge ( $arr1 , $arr2 );
else $arr1 [ $id_parval ] = $arr2 ;
}
$vals = $arr1 ;
$arr1 = array ();
foreach ( $opts as $id_parval => $parval ) {
2009-06-30 11:51:50 +00:00
$arr2 = Templates :: EvaluateDefault ( $ldapserver , $parval , $dn , null , null );
2009-06-30 10:46:00 +00:00
if ( is_array ( $arr2 )) $arr1 = array_merge ( $arr1 , $arr2 );
else $arr1 [ $id_parval ] = $arr2 ;
}
$opts = $arr1 ;
$default = ( count ( $vals ) > 0 ? $vals [ 0 ] : '' );
2009-06-30 11:46:44 +00:00
if ( ! is_scalar ( $default )) $default = '' ;
if ( ! is_null ( $attribute -> getValue ( $i )) && ( strlen ( $default ) <= 0 )) {
2009-06-30 10:46:00 +00:00
$default = $this -> get ( 'DefaultValueHelper' , $attribute , $i );
}
if ( count ( $opts ) > 0 ) {
$found = false ;
printf ( '<select id="%s_%s_%s" name="%s[%s][%s]">' ,
2009-06-30 11:52:55 +00:00
$id , htmlspecialchars ( $attribute -> getName ()), $i ,
$id , htmlspecialchars ( $attribute -> getName ()), $i );
2009-06-30 10:46:00 +00:00
foreach ( $opts as $v ) {
printf ( '<option value="%s" %s>%s</option>' , $v , ( $v == $default ) ? 'selected' : '' , $v );
if ( $v == $default ) $found = true ;
}
if ( ! $found ) {
printf ( '<option value="%s" selected>%s</option>' , $default , $default );
}
echo '</select>' ;
} else {
printf ( '<input type="text" name="%s[%s][%s]" id="%s_%s_%s" value="%s" size="4" />' ,
2009-06-30 11:52:55 +00:00
$id , htmlspecialchars ( $attribute -> getName ()), $i ,
$id , htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $default ));
2009-06-30 10:46:00 +00:00
}
if ( $display ) {
echo '<div class="helper">' ;
echo '<span class="hint">' . $display . '</span>' ;
echo '</div>' ;
}
}
protected function getAttributeDefaultValueHelper ( $attribute , $i ) {
2009-06-30 10:46:41 +00:00
$params = $attribute -> getProperty ( 'helper' );
# Should only return 1 default entry.
if ( isset ( $params [ 'value' ]) && ! is_array ( $params [ 'value' ]))
return $params [ 'value' ];
# If there are multiple values, return the first one.
else if ( isset ( $params [ 'value' ]) && is_array ( $params [ 'value' ]))
return array_shift ( $params [ 'value' ]);
# No default values, return a blank.
else
return '' ;
2009-06-30 10:46:00 +00:00
}
protected function getAttributeRenameMenuItem ( $attribute ) {
$encoded_dn = '' ;
if ( $attribute -> getEntry ()) $encoded_dn = rawurlencode ( $attribute -> getEntry () -> getDn ());
if ( ! $encoded_dn ) return ; // creating entry
2009-06-30 11:51:50 +00:00
$url_base = sprintf ( 'cmd.php?server_id=%s&dn=%s' , $this -> index , $encoded_dn );
2009-06-30 10:46:00 +00:00
$href = sprintf ( '%s&cmd=rename_form' , $url_base );
return sprintf ( '<small>(<a href="%s">%s</a>)</small>' , htmlspecialchars ( $href ), _ ( 'rename' ));
}
protected function getAttributeAddValueMenuItem ( $attribute ) {
/* Draw the "add value" link under the list of values for this attributes */
$encoded_dn = '' ;
$template = '' ;
if ( $attribute -> getEntry ()) {
$encoded_dn = rawurlencode ( $attribute -> getEntry () -> getDn ());
if ( method_exists ( $attribute -> getEntry (), 'getSelectedTemplateName' ))
$template = $attribute -> getEntry () -> getSelectedTemplateName ();
}
if ( ! $encoded_dn ) return ; // creating entry
$href = sprintf ( 'cmd.php?cmd=add_value_form&server_id=%s&dn=%s%s&attr=%s' ,
2009-06-30 11:51:50 +00:00
$this -> index , $encoded_dn , $template ? " &template= $template " : '' , rawurlencode ( $attribute -> getName ()));
2009-06-30 10:46:00 +00:00
return sprintf ( '(<a href="%s" title="%s">%s</a>)' ,
htmlspecialchars ( $href ), sprintf ( _ ( 'Add an additional value to attribute \'%s\'' ),
$attribute -> getName ()), _ ( 'add value' ));
}
protected function getAttributeModifyMemberMenuItem ( $attribute ) {
$dn = ( $attribute -> getEntry ()) ? $attribute -> getEntry () -> getDn () : '' ;
$encoded_dn = ( $dn ) ? rawurlencode ( $dn ) : '' ;
if ( ! $encoded_dn ) return ; // creating entry
$href = sprintf ( 'cmd.php?cmd=modify_member_form&server_id=%s&dn=%s&attr=%s' ,
2009-06-30 11:51:50 +00:00
$this -> index , $encoded_dn , rawurlencode ( $attribute -> getName ()));
2009-06-30 10:46:00 +00:00
return sprintf ( '(<a href="%s" title="%s">%s</a>)' ,
htmlspecialchars ( $href ), sprintf ( _ ( 'Modify members for \'%s\'' ), $dn ), _ ( 'modify group members' ));
}
protected function drawAttributeIcon ( $attribute , $val ) {
2009-06-30 11:51:50 +00:00
if ( is_dn_string ( $val ) || $this -> getLDAPServer () -> isDNAttr ( $attribute -> getName ())) {
2009-06-30 10:46:00 +00:00
$this -> draw ( 'DnValueIcon' , $attribute , $val );
} elseif ( is_mail_string ( $val )) {
$this -> draw ( 'MailValueIcon' , $attribute , $val );
} elseif ( is_url_string ( $val )) {
$this -> draw ( 'UrlValueIcon' , $attribute , $val );
} else {
$icon = $attribute -> getIcon ();
if ( $icon ) printf ( '<img src="%s" alt="Icon" align="top" /> ' , $icon );
}
}
protected function drawAttributeDnValueIcon ( $attribute , $val ) {
if ( strlen ( $val ) <= 0 ) {
2009-06-30 11:51:50 +00:00
printf ( '<img src="%s/go.png" alt="Go" align="top" /> ' , IMGDIR );
2009-06-30 10:46:00 +00:00
2009-06-30 11:51:50 +00:00
} elseif ( $this -> getLDAPServer () -> dnExists ( $val )) {
2009-06-30 11:52:55 +00:00
printf ( '<a title="%s %s" href="cmd.php?cmd=template_engine&server_id=%s&dn=%s"><img src="%s/go.png" alt="Go" /></a> ' ,
_ ( 'Go to' ), htmlspecialchars ( $val ), $this -> index , rawurlencode ( $val ), IMGDIR );
2009-06-30 10:46:00 +00:00
} else {
2009-06-30 11:51:50 +00:00
printf ( '<a title="%s %s"><img src="%s/nogo.png" alt="Go" /></a> ' , _ ( 'DN not available' ), htmlspecialchars ( $val ), IMGDIR );
2009-06-30 10:46:00 +00:00
}
}
protected function drawAttributeMailValueIcon ( $attribute , $val ) {
2009-06-30 11:51:50 +00:00
$img = sprintf ( '<img src="%s/mail.png" alt="%s" align="top" />' , IMGDIR , _ ( 'Mail' ));
2009-06-30 10:46:00 +00:00
if ( strlen ( $val ) <= 0 ) echo $img ;
else printf ( '<a href="mailto:%s">' . $img . '</a>' , htmlspecialchars ( $val ));
echo ' ' ;
}
protected function drawAttributeUrlValueIcon ( $attribute , $val ) {
2009-06-30 11:51:50 +00:00
$img = sprintf ( '<img src="%s/dc.png" alt="%s" align="top" />' , IMGDIR , _ ( 'URL' ));
2009-06-30 11:52:55 +00:00
$url = split ( ' +' , $val , 2 );
2009-06-30 10:46:00 +00:00
if ( strlen ( $val ) <= 0 ) echo $img ;
2009-06-30 11:52:55 +00:00
else printf ( '<a href="%s" target="new">%s</a>' , htmlspecialchars ( $url [ 0 ]), $img );
2009-06-30 10:46:00 +00:00
echo ' ' ;
}
protected function drawAttributeName ( $attribute ) {
2009-06-30 11:46:44 +00:00
$config = $_SESSION [ APPCONFIG ];
2009-06-30 10:46:00 +00:00
$attr_display = $attribute -> getFriendlyName ();
if ( $attribute -> getEntry () && $attribute -> getEntry () -> getDn () // if not creating attribute
&& $config -> isCommandAvailable ( 'schema' ) ) {
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
$href = sprintf ( 'cmd.php?cmd=schema&server_id=%s&view=attributes&viewvalue=%s' ,
2009-06-30 11:51:50 +00:00
$this -> index , real_attr_name ( $attribute -> getName ()));
2009-06-30 10:46:00 +00:00
printf ( '<a title="' . _ ( 'Click to view the schema definition for attribute type \'%s\'' )
. '" href="%s">%s</a>' , $attribute -> getName (), htmlspecialchars ( $href ), $attr_display );
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
} else {
printf ( '%s' , $attr_display );
}
}
protected function getAttributeAliasNote ( $attribute ) {
2009-06-30 11:52:55 +00:00
# Is there a user-friendly translation available for this attribute?
2009-06-30 10:46:00 +00:00
$friendly_name = $attribute -> getFriendlyName ();
2009-06-30 11:52:55 +00:00
if ( $friendly_name != $attribute -> getName ())
return sprintf ( '<acronym title="%s: \'%s\' %s \'%s\'">%s</acronym>' ,
_ ( 'Note' ), $friendly_name , _ ( 'is an alias for' ), $attribute -> getName (), _ ( 'alias' ));
else
2009-06-30 10:46:00 +00:00
return '' ;
}
protected function getAttributeRequiredNote ( $attribute ) {
# is this attribute required by an objectClass ?
$required_by = '' ;
if ( $attribute -> getEntry ()) {
2009-06-30 11:51:50 +00:00
$schema_attr = $this -> getLDAPServer () -> getSchemaAttribute ( $attribute -> getName (), $attribute -> getEntry () -> getDn ());
2009-06-30 10:46:00 +00:00
if ( $schema_attr ) {
$entry_attributes = $attribute -> getEntry () -> getAttributes ();
$objectclass_attribute = null ;
foreach ( $entry_attributes as $entry_attribute ) {
# It seems that some LDAP servers (Domino) returns attributes in lower case?
if ( $entry_attribute -> getName () == 'objectClass'
|| $entry_attribute -> getName () == 'objectclass' ) {
$objectclass_attribute = $entry_attribute ;
break ;
}
}
if ( $objectclass_attribute ) {
$classes = arrayLower ( $objectclass_attribute -> getValues ());
foreach ( $schema_attr -> getRequiredByObjectClasses () as $required ) {
if ( in_array ( strtolower ( $required ), $classes )) {
$required_by .= $required . ' ' ;
}
}
}
}
}
if ( $required_by ) {
return " <acronym title= \" " . sprintf ( _ ( 'Required attribute for objectClass(es) %s' ), $required_by ) . " \" > " . _ ( 'required' ) . " </acronym> " ;
} else {
return '' ;
}
}
protected function getAttributeRdnNote ( $attribute ) {
# is this attribute required because its the RDN
if ( $attribute -> isRdn ()) {
return " <acronym title= \" " . _ ( 'This attribute is required for the RDN.' ) . " \" > " . 'rdn' . " </acronym> " ;
} else {
return '' ;
}
}
2009-06-30 11:52:55 +00:00
protected function getAttributeHintNote ( $attribute ) {
# Is there a hint for this attribute
if ( $attribute -> getHint ()) {
return sprintf ( '<acronym title="%s">%s</acronym> ' , htmlspecialchars ( $attribute -> getHint ()), _ ( 'hint' ));
} else {
return '' ;
}
}
2009-06-30 10:46:00 +00:00
protected function drawAttributeRequiredSymbol ( $attribute ) {
echo '*' ;
}
/***************************/
/* Paint a BinaryAttribute */
/***************************/
protected function drawBinaryAttributeValues ( $attribute ) {
$valcount = $attribute -> getValueCount ();
if ( $attribute -> isVisible ()) {
$this -> draw ( 'StartValueLine' , $attribute );
echo '<small>' ;
echo _ ( 'Binary value' );
if ( $valcount > 0 ) {
if ( strcasecmp ( $attribute -> getName (), 'objectSid' ) == 0 ) {
printf ( ' (%s)' , binSIDtoText ( $attribute -> getValue ( 0 )));
}
}
echo '<br />' ;
if ( $valcount > 0 ) {
if ( $attribute -> getEntry () && $attribute -> getEntry () -> getDn ()) {
$href = sprintf ( 'download_binary_attr.php?server_id=%s&dn=%s&attr=%s' ,
2009-06-30 11:51:50 +00:00
$this -> index , rawurlencode ( $attribute -> getEntry () -> getDn ()),
2009-06-30 10:46:00 +00:00
$attribute -> getName ());
if ( $valcount > 1 ) {
for ( $i = 1 ; $i <= $valcount ; $i ++ ) {
2009-06-30 11:51:50 +00:00
printf ( '<a href="%s&value_num=%s"><img src="%s/save.png" alt="Save" /> %s(%s)</a><br />' ,
htmlspecialchars ( $href ), $i , IMGDIR , _ ( 'download value' ), $i );
2009-06-30 10:46:00 +00:00
}
} else {
2009-06-30 11:51:50 +00:00
printf ( '<a href="%s"><img src="%s/save.png" alt="Save" /> %s</a><br />' ,
htmlspecialchars ( $href ), IMGDIR , _ ( 'download value' ));
2009-06-30 10:46:00 +00:00
}
}
2009-06-30 11:46:44 +00:00
if ( ! $attribute -> isReadOnly () && $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_delete' )) {
2009-06-30 10:46:00 +00:00
printf ( '<a href="javascript:deleteAttribute(\'%s\', \'%s\');" style="color:red;">' .
2009-06-30 11:51:50 +00:00
'<img src="%s/trash.png" alt="Trash" /> %s</a>' ,
$attribute -> getName (), $attribute -> getFriendlyName (), IMGDIR , _ ( 'delete attribute' ));
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:46:44 +00:00
} elseif ( $attribute -> isReadOnly () || ! $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_add_value' )) {
2009-06-30 10:46:00 +00:00
printf ( '<input type="text" class="roval" value="%s" readonly /><br />' ,
_ ( " [no value] " ));
} else {
$i = 0 ;
$val = '' ;
$id = sprintf ( 'new_values_%s_%s' , htmlspecialchars ( $attribute -> getName ()), $i );
2009-06-30 11:51:50 +00:00
printf ( '<input type="file" class="value" name="new_values[%s][%s]"' .
2009-06-30 10:46:00 +00:00
' id="%s" value="%s" onFocus="focus_%s(this);" onBlur="blur_%s(this);" %s %s/><br />' ,
htmlspecialchars ( $attribute -> getName ()), $i , $id ,
htmlspecialchars ( $val ), $attribute -> getName (), $attribute -> getName (),
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
}
echo '</small>' ;
$this -> draw ( 'EndValueLine' , $attribute );
} else {
for ( $i = 0 ; $i < $valcount ; $i ++ ) {
$n = $attribute -> getFileName ( $i );
$p = $attribute -> getFilePath ( $i );
if ( $n && $p ) {
printf ( '<input type="hidden" name="old_values[%s][%s]" value="%s" />' ,
htmlspecialchars ( $attribute -> getName ()), $i , md5 ( " $n | $p " ));
printf ( '<input type="hidden" name="new_values[%s][%s]" value="%s" />' ,
htmlspecialchars ( $attribute -> getName ()), $i , md5 ( " $n | $p " ));
}
}
}
}
protected function drawBinaryAttributeJavascript ( $attribute ) {
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- START: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Attribute::Javascript' , $attribute );
$dn = '' ;
if ( $attribute -> getEntry ()) $dn = $attribute -> getEntry () -> getDn ();
if ( ! $dn ) return ;
static $already_draw = false ;
if ( $already_draw ) return ;
else $already_draw = true ;
echo '
<!-- This form is submitted by JavaScript when the user clicks " Delete attribute " on a binary attribute -->
< form name = " delete_attribute_form " action = " cmd.php?cmd=delete_attr " method = " post " >
2009-06-30 11:51:50 +00:00
< input type = " hidden " name = " server_id " value = " '. $this->index .' " />
2009-06-30 10:46:00 +00:00
< input type = " hidden " name = " dn " value = " '.htmlspecialchars( $dn ).' " />
< input type = " hidden " name = " attr " value = " FILLED IN BY JAVASCRIPT " />
</ form > ' ;
echo '
< script type = " text/javascript " language = " javascript " >
function deleteAttribute ( attrName , friendlyName )
{
if ( confirm ( " '._('Really delete attribute').' \ ' " + friendlyName + " \ '? " )) {
document . delete_attribute_form . attr . value = attrName ;
document . delete_attribute_form . submit ();
}
}
</ script > ' ;
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- END: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
}
protected function drawBinaryAttributeBlurJavascript ( $attribute , $component ) {
}
/***************************/
/* Paint a DateAttribute */
/***************************/
protected function drawDateAttributeReadWriteValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
2009-06-30 11:51:50 +00:00
printf ( '<span style="white-space: nowrap;"><input type="text" class="value" id="f_date_%s_%s"'
2009-06-30 11:52:55 +00:00
. ' name="new_values[%s][%s]" value="%s" onFocus="focus_%s(this);" onBlur="blur_%s(this);" %s %s/> ' ,
2009-06-30 10:46:00 +00:00
$attribute -> getName (), $i , htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $val ),
$attribute -> getName (), $attribute -> getName (),
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
draw_date_selector_link ( $attribute -> getName () . '_' . $i );
2009-06-30 11:52:55 +00:00
echo '</span>' . " \n " ;
2009-06-30 10:46:00 +00:00
}
protected function drawDateAttributeJavascript ( $attribute ) {
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- START: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Attribute::Javascript' , $attribute );
2009-06-30 11:46:44 +00:00
$entry [ 'date' ] = $_SESSION [ APPCONFIG ] -> GetValue ( 'appearance' , 'date_attrs' );
$entry [ 'time' ] = $_SESSION [ APPCONFIG ] -> GetValue ( 'appearance' , 'date_attrs_showtime' );
$entry [ 'format' ] = $_SESSION [ APPCONFIG ] -> GetValue ( 'appearance' , 'date' );
2009-06-30 10:46:00 +00:00
if ( isset ( $entry [ 'date' ][ $attribute -> getName ()]))
$entry [ 'format' ] = $entry [ 'date' ][ $attribute -> getName ()];
2009-06-30 11:51:50 +00:00
printf ( '<script type="text/javascript" src="%sjscalendar/lang/calendar-en.js"></script>' , JSDIR );
printf ( '<script type="text/javascript" src="%sjscalendar/calendar-setup.js"></script>' , JSDIR );
printf ( '<script type="text/javascript" src="%sdate_selector.js"></script>' , JSDIR );
2009-06-30 10:46:00 +00:00
for ( $i = 0 ; $i <= $attribute -> getValueCount (); $i ++ ) {
printf ( '<script type="text/javascript" language="javascript">defaults[\'f_date_%s_%s\'] = \'%s\';</script>' , $attribute -> getName (), $i , $entry [ 'format' ]);
if ( in_array_ignore_case ( $attribute -> getName (), array_keys ( $entry [ 'time' ])) && ( $entry [ 'time' ][ $attribute -> getName ()]))
printf ( '<script type="text/javascript" language="javascript">defaults[\'f_time_%s_%s\'] = \'%s\';</script>' , $attribute -> getName (), $i , 'true' );
}
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- END: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
}
/***************************/
/* Paint a DnAttribute */
/***************************/
protected function drawDnAttributeReadWriteValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
if ( $attribute -> hasProperty ( 'helper' )) {
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">' ;
}
$input_name = sprintf ( 'new_values[%s][%s]' , htmlspecialchars ( $attribute -> getName ()), $i );
$input_id = sprintf ( 'new_values_%s_%s' , htmlspecialchars ( $attribute -> getName ()), $i );
2009-06-30 11:51:50 +00:00
printf ( '<span style="white-space: nowrap;"><input type="text" class="value" name="%s" id="%s" value="%s"'
2009-06-30 11:52:55 +00:00
. ' onFocus="focus_%s(this);" onBlur="blur_%s(this);" %s %s/> ' ,
2009-06-30 10:46:00 +00:00
$input_name , $input_id , htmlspecialchars ( $val ),
$attribute -> getName (), $attribute -> getName (),
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
/* draw a link for popping up the entry browser if this is the type of attribute
* that houses DNs . */
draw_chooser_link ( " entry_form. $input_id " , false );
echo '</span>' ;
if ( $attribute -> hasProperty ( 'helper' )) {
echo '</td><td valign="top">' ;
$this -> draw ( 'Helper' , $attribute , $i );
echo '</td></tr></table>' ;
}
2009-06-30 11:52:55 +00:00
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
protected function drawDnAttributeIcon ( $attribute , $val ) {
$this -> draw ( 'DnValueIcon' , $attribute , $val );
}
/***************************/
/* Paint a GidAttribute */
/***************************/
protected function drawGidAttributeReadWriteValue ( $attribute , $i ) {
$this -> draw ( 'Attribute::ReadWriteValue' , $attribute , $i );
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
$dn = '' ;
if ( $attribute -> getEntry ()) $dn = $attribute -> getEntry () -> getDn ();
# If this is a gidNumber on a non-PosixGroup entry, lookup its name and description for convenience
2009-06-30 11:51:50 +00:00
if ( ! in_array_ignore_case ( 'posixGroup' , $this -> getLDAPServer () -> getDNAttr ( $dn , 'objectClass' ))) {
2009-06-30 10:46:00 +00:00
$gid_number = $val ;
$search_group_filter = " (&(objectClass=posixGroup)(gidNumber= $val )) " ;
2009-06-30 11:51:50 +00:00
$group = $this -> getLDAPServer () -> search ( null , null , $search_group_filter , array ( 'dn' , 'description' ));
2009-06-30 10:46:00 +00:00
if ( count ( $group ) > 0 ) {
echo '<br />' ;
$group = array_pop ( $group );
$group_dn = $group [ 'dn' ];
$group_name = explode ( '=' , get_rdn ( $group_dn ));
$group_name = $group_name [ 1 ];
$href = sprintf ( 'cmd.php?cmd=template_engine&server_id=%s&dn=%s' ,
2009-06-30 11:51:50 +00:00
$this -> index , rawurlencode ( $group_dn ));
2009-06-30 10:46:00 +00:00
echo '<small>' ;
printf ( '<a href="%s">%s</a>' , htmlspecialchars ( $href ), htmlspecialchars ( $group_name ));
$description = isset ( $group [ 'description' ]) ? $group [ 'description' ] : null ;
if ( is_array ( $description )) {
foreach ( $description as $item )
printf ( ' (%s)' , htmlspecialchars ( $item ));
} else {
printf ( ' (%s)' , htmlspecialchars ( $description ));
}
echo '</small>' ;
}
}
}
/***************************/
/* Paint a JpegAttribute */
/***************************/
protected function drawJpegAttributeValues ( $attribute ) {
if ( $attribute -> isVisible ()) {
$this -> draw ( 'StartValueLine' , $attribute );
$value_count = $attribute -> getValueCount ();
if ( $value_count > 0 ) {
/* Don ' t draw the delete buttons if there is more than one jpegPhoto
* ( phpLDAPadmin can ' t handle this case yet ) */
if ( $attribute -> getEntry () && $attribute -> getEntry () -> getDn ()) {
2009-06-30 11:51:50 +00:00
draw_jpeg_photos ( $this -> getLDAPServer (), $attribute -> getEntry () -> getDn (),
2009-06-30 10:46:00 +00:00
$attribute -> getName (), ! $attribute -> isReadOnly ()
2009-06-30 11:46:44 +00:00
&& $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_delete' ));
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:46:44 +00:00
} elseif ( $attribute -> isReadOnly () || ! $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_add_value' )) {
2009-06-30 10:46:00 +00:00
printf ( '<input type="text" class="roval" value="%s" readonly /><br />' , _ ( '[no value]' ));
} else {
$i = 0 ;
$val = '' ;
$id = sprintf ( 'new_values_%s_%s' , htmlspecialchars ( $attribute -> getName ()), $i );
2009-06-30 11:51:50 +00:00
printf ( '<input type="file" class="value" name="new_values[%s][%s]"' .
2009-06-30 10:46:00 +00:00
' id="%s" value="%s" onFocus="focus_%s(this);" onBlur="blur_%s(this);" %s %s/><br />' ,
htmlspecialchars ( $attribute -> getName ()), $i , $id ,
htmlspecialchars ( $val ), $attribute -> getName (), $attribute -> getName (),
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
}
$this -> draw ( 'EndValueLine' , $attribute );
} else {
$this -> draw ( 'BinaryAttribute::Values' , $attribute );
}
}
/******************************/
/* Paint a MultiLineAttribute */
/******************************/
protected function drawMultiLineAttributeReadOnlyValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
printf ( '<textarea class="roval" %s %s name="new_values[%s][%s]" ' .
'id="new_values_%s_%s" readonly>%s</textarea><br />' ,
( $attribute -> getRows () > 0 ) ? 'rows="' . $attribute -> getRows () . '"' : '' ,
( $attribute -> getCols () > 0 ) ? 'cols="' . $attribute -> getCols () . '"' : '' ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $val ));
}
protected function drawMultiLineAttributeReadWriteValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
2009-06-30 11:51:50 +00:00
printf ( '<textarea class="value" %s %s name="new_values[%s][%s]" ' .
2009-06-30 10:46:00 +00:00
'id="new_values_%s_%s" onFocus="focus_%s(this);" onBlur="blur_%s(this);">%s</textarea>' ,
( $attribute -> getRows () > 0 ) ? 'rows="' . $attribute -> getRows () . '"' : '' ,
( $attribute -> getCols () > 0 ) ? 'cols="' . $attribute -> getCols () . '"' : '' ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
$attribute -> getName (), $attribute -> getName (),
htmlspecialchars ( $val ));
}
/********************************/
/* Paint a ObjectClassAttribute */
/********************************/
2009-06-30 11:52:55 +00:00
protected function drawObjectClassAttributeNewValue ( $attribute , $i , $entry ) {
2009-06-30 10:46:00 +00:00
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
2009-06-30 11:51:50 +00:00
$schema_object = ( $val ) ? $this -> getLDAPServer () -> getSchemaObjectClass ( $val ) : false ;
2009-06-30 10:46:00 +00:00
$structural = ( is_object ( $schema_object ) && $schema_object -> getType () == 'structural' );
if ( ! $attribute -> isVisible ()) {
$this -> draw ( 'HiddenValue' , $attribute , $i );
} elseif ( $structural ) {
# Is this value is a structural objectClass, make it read-only
printf ( ' < input type = " text " class = " roval " name = " new_values[%s][%s] "
id = " new_values_%s_%s " value = " %s " readonly /> ' ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $val ));
printf ( ' <small>(<acronym title="%s">%s</acronym>)</small><br />' ,
_ ( 'This is a structural ObjectClass and cannot be removed.' ),
_ ( 'structural' ));
} else {
2009-06-30 11:52:55 +00:00
$this -> draw ( 'Attribute::NewValue' , $attribute , $i , $entry );
2009-06-30 10:46:00 +00:00
}
}
protected function drawObjectClassAttributeIcon ( $attribute , $val ) {
if ( strlen ( $val ) > 0 ) {
2009-06-30 11:50:46 +00:00
$href = sprintf ( 'cmd.php?cmd=schema&server_id=%s&view=objectClasses&viewvalue=%s' ,
2009-06-30 11:51:50 +00:00
$this -> index , $val );
printf ( '<a title="%s" href="%s"><img src="%s/info.png" alt="Info" /></a> ' ,
_ ( 'View the schema description for this objectClass' ), htmlspecialchars ( $href ), IMGDIR );
2009-06-30 10:46:00 +00:00
}
}
/*****************************/
/* Paint a PasswordAttribute */
/*****************************/
protected function drawPasswordAttributeOldValue ( $attribute , $i ) {
2009-06-30 11:52:55 +00:00
$this -> draw ( 'Attribute::OldValue' , $attribute , $i );
2009-06-30 10:46:00 +00:00
}
protected function drawPasswordAttributeHiddenValue ( $attribute , $i ) {
2009-06-30 11:52:55 +00:00
if ( $this -> context == ENTRY_WRITER_CREATION_CONTEXT )
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Attribute::HiddenValue' , $attribute , $i );
}
protected function drawPasswordAttributeReadOnlyValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
$enc_type = get_enc_type ( $val );
2009-06-30 11:51:50 +00:00
if ( $val == '' ) $enc_type = get_default_hash ( $this -> index );
2009-06-30 10:46:00 +00:00
$obfuscate_password = obfuscate_password_display ( $enc_type );
printf ( '<input type="%s" class="roval" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" %s readonly /><br />' ,
2009-06-30 11:52:55 +00:00
( $obfuscate_password ? 'password' : 'text' ),
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $attribute -> getName ()),
$i , htmlspecialchars ( $val ), ( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' );
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
if ( $val != '' ) $this -> draw ( 'CheckLink' , $attribute , 'new_values_' . htmlspecialchars ( $attribute -> getName ()) . '_' . $i );
}
protected function drawPasswordAttributeReadWriteValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
$enc_type = get_enc_type ( $val );
# Set the default hashing type if the password is blank (must be newly created)
2009-06-30 11:52:55 +00:00
if ( $val == '' )
2009-06-30 11:51:50 +00:00
$enc_type = get_default_hash ( $this -> index );
2009-06-30 10:46:00 +00:00
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">' ;
$obfuscate_password = obfuscate_password_display ( $enc_type );
$id = sprintf ( 'new_values_%s_%s' , htmlspecialchars ( $attribute -> getName ()), $i );
2009-06-30 11:51:50 +00:00
printf ( '<input type="%s" class="value" name="new_values[%s][%s]" id="%s" value="%s"'
2009-06-30 11:52:55 +00:00
. ' onFocus="focus_%s(this);" onBlur="blur_%s(this);" %s %s/>' ,
2009-06-30 10:46:00 +00:00
( $obfuscate_password ? 'password' : 'text' ),
htmlspecialchars ( $attribute -> getName ()), $i , $id ,
htmlspecialchars ( $val ),
$attribute -> getName (), $attribute -> getName (),
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
echo '</td><td valign="top">' ;
2009-06-30 11:52:55 +00:00
if ( $attribute -> hasProperty ( 'helper' ))
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Helper' , $attribute , $i );
2009-06-30 11:52:55 +00:00
else
echo enc_type_select_list ( $enc_type , 'enc' , $attribute -> getName (), $i );
2009-06-30 10:46:00 +00:00
echo '</td></tr><tr><td valign="top">' ;
if ( $attribute -> hasProperty ( 'verify' ) && $attribute -> getProperty ( 'verify' ) && $obfuscate_password ) {
$id_v = sprintf ( 'new_values_verify_%s_%s' , htmlspecialchars ( $attribute -> getName ()), $i );
2009-06-30 11:51:50 +00:00
printf ( '<input type="password" class="value" name="new_values_verify[%s][%s]" id="%s" value="" %s %s/>' ,
2009-06-30 11:52:55 +00:00
htmlspecialchars ( $attribute -> getName ()), $i , $id_v ,
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
2009-06-30 10:46:00 +00:00
echo '</td><td valign="top">' ;
printf ( '(%s)' , _ ( 'confirm' ));
echo '</td></tr><tr><td valign="top">' ;
}
$this -> draw ( 'CheckLink' , $attribute , $id );
echo '</td></tr></table>' ;
}
protected function getPasswordAttributeDefaultValueHelper ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
$enc_type = get_enc_type ( $val );
# Set the default hashing type if the password is blank (must be newly created)
if ( $val == '' ) {
2009-06-30 11:51:50 +00:00
$enc_type = get_default_hash ( $this -> index );
2009-06-30 10:46:00 +00:00
}
return $enc_type ;
}
protected function drawPasswordAttributeCheckLink ( $attribute , $component_id ) {
printf ( '<small><a href="javascript:passwordComparePopup(\'%s\')">%s</a></small><br />' ,
$component_id /*base64_encode($val)*/ , _ ( 'Check password...' ));
}
protected function drawPasswordAttributeJavascript ( $attribute ) {
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- START: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Attribute::Javascript' , $attribute );
static $already_draw = false ;
if ( $already_draw ) return ;
else $already_draw = true ;
# add the javascript so we can call check password later.
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
echo '
< script type = " text/javascript " language = " javascript " >
function passwordComparePopup ( component_id ) {
mywindow = open ( \ ' password_checker . php\ ' , \ ' myname\ ' , \ ' resizable = no , width = 500 , height = 200 , scrollbars = 1 \ ' );
mywindow . location . href = \ ' password_checker . php ? componentid = \ ' + component_id ;
if ( mywindow . opener == null ) mywindow . opener = self ;
}
</ script > ' ;
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- END: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
}
/***********************************/
/* Paint a RandomPasswordAttribute */
/***********************************/
protected function drawRandomPasswordAttributeJavascript ( $attribute ) {
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- START: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
$this -> draw ( 'PasswordAttribute::Javascript' , $attribute );
$pwd = password_generate ();
$pwd = str_replace ( " \\ " , " \\ \\ " , $pwd );
$pwd = str_replace ( " ' " , " \\ ' " , $pwd );
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
echo '<script type="text/javascript" language="javascript">' ;
printf ( 'var i = 0; var component = document.getElementById(\'new_values_%s_\'+i);' , $attribute -> getName ());
printf ( 'while (component) { if (!component.value) {' );
printf ( 'component.value = \'%s\';' , $pwd );
printf ( 'alert(\'%s%s\n%s\');' , _ ( 'A random password was generated for you' ), _ ( ':' ), $pwd );
printf ( '} i++; component = document.getElementById(\'new_values_%s_\'+i); }' , $attribute -> getName ());
echo '</script>' ;
2009-06-30 11:52:55 +00:00
printf ( " \n <!-- END: %s --> \n " , __METHOD__ );
2009-06-30 10:46:00 +00:00
}
/******************************/
/* Paint a SelectionAttribute */
/******************************/
2009-06-30 11:52:55 +00:00
protected function drawSelectionAttributeValues ( $attribute , $entry ) {
2009-06-30 10:46:00 +00:00
if ( ! $attribute -> isVisible () || ! $attribute -> isMultiple () || ( $attribute -> getValueCount () > 0 )) {
2009-06-30 11:52:55 +00:00
$this -> draw ( 'Attribute::Values' , $attribute , $entry );
2009-06-30 10:46:00 +00:00
} else {
$this -> draw ( 'StartValueLine' , $attribute );
2009-06-30 12:05:31 +00:00
$this -> draw ( 'Value' , $attribute , 0 , $entry );
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Menu' , $attribute );
$this -> draw ( 'EndValueLine' , $attribute );
}
}
protected function drawSelectionAttributeReadOnlyValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
2009-06-30 11:51:50 +00:00
printf ( '<input type="hidden" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" />' ,
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $val ));
$select = $attribute -> getSelection ();
if ( isset ( $select [ $val ])) $val = $select [ $val ];
echo htmlspecialchars ( $val ) . '<br />' ;
}
protected function drawSelectionAttributeReadWriteValue ( $attribute , $i ) {
if ( $attribute -> isMultiple ()) {
2009-06-30 11:52:55 +00:00
# For multiple selection, we draw the component only one time
2009-06-30 10:46:00 +00:00
if ( $i > 0 ) return ;
if (( $attribute -> getSize () > 0 ) && ( $attribute -> getSize () < $attribute -> getOptionCount ())) {
$selected = array ();
printf ( '<select name="new_values[%s][]" multiple size="%s">' ,
htmlspecialchars ( $attribute -> getName ()), $attribute -> getSize ());
$vals = $attribute -> getValues ();
$j = 0 ;
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
foreach ( $attribute -> getSelection () as $value => $description ) {
if ( in_array ( $value , $vals )) $selected [ $value ] = true ;
$id = 'new_values_' . htmlspecialchars ( $attribute -> getName ()) . '_' . ( $j ++ );
printf ( '<option id="%s" value="%s" onMouseDown="focus_%s(this);" onClick="blur_%s(this);" %s>%s</option>' ,
2009-06-30 11:52:55 +00:00
$id , $value , htmlspecialchars ( $attribute -> getName ()), htmlspecialchars ( $attribute -> getName ()),
isset ( $selected [ $value ]) ? 'selected' : '' , $description );
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
foreach ( $vals as $val ) {
if ( ! isset ( $selected [ $val ])) {
$id = 'new_values_' . htmlspecialchars ( $attribute -> getName ()) . '_' . ( $j ++ );
printf ( '<option id="%s" value="%s" onMouseDown="focus_%s(this);" onClick="blur_%s(this);" selected>'
2009-06-30 11:52:55 +00:00
. '%s</option>' , $id , $val , htmlspecialchars ( $attribute -> getName ()),
htmlspecialchars ( $attribute -> getName ()), $val );
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:52:55 +00:00
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
echo '</select>' ;
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
} else {
$selected = array ();
$vals = $attribute -> getValues ();
$j = 0 ;
echo '<table cellspacing="0" cellpadding="0">' ;
foreach ( $attribute -> getSelection () as $value => $description ) {
if ( in_array ( $value , $vals )) $selected [ $value ] = true ;
$id = 'new_values_' . htmlspecialchars ( $attribute -> getName ()) . '_' . ( $j ++ );
printf ( '<tr><td><input type="checkbox" id="%s" name="new_values[%s][]" value="%s"'
2009-06-30 11:52:55 +00:00
. ' onFocus="focus_%s(this);" onClick="blur_%s(this);" %s /></td><td>%s</td></tr>' ,
$id , htmlspecialchars ( $attribute -> getName ()), $value ,
$attribute -> getName (), $attribute -> getName (),
2009-06-30 10:46:00 +00:00
isset ( $selected [ $value ]) ? 'checked' : '' ,
" <span style= \" white-space: nowrap; \" > $description </span> " );
}
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
foreach ( $vals as $val ) {
if ( ! isset ( $selected [ $val ])) {
$id = 'new_values_' . htmlspecialchars ( $attribute -> getName ()) . '_' . ( $j ++ );
printf ( '<tr><td><input type="checkbox" id="%s" name="new_values[%s][]"'
. ' value="%s" onFocus="focus_%s(this);" onClick="blur_%s(this);" checked /></td><td>%s</td></tr>' ,
$id , htmlspecialchars ( $attribute -> getName ()), $val ,
$attribute -> getName (), $attribute -> getName (),
" <span style= \" white-space: nowrap; \" > $val </span> " );
}
}
echo '</table>' ;
}
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
} else {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
2009-06-30 11:52:55 +00:00
if ( $attribute -> hasProperty ( 'helper' ))
2009-06-30 10:46:00 +00:00
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">' ;
$found = false ;
$empty_value = false ;
$id = 'new_values_' . htmlspecialchars ( $attribute -> getName ()) . '_' . $i ;
2009-06-30 11:52:55 +00:00
# If we are a required attribute, and the selection is blank, then the user cannot submit this form.
if ( $attribute -> isRequired () && ! count ( $attribute -> getSelection ()))
system_message ( array (
'title' => _ ( 'Template Value Error' ),
'body' => sprintf ( 'This template uses a selection list for attribute [<b>%s</b>], however the selection list is empty.<br />You may need to create some dependancy entries in your LDAP server so that this attribute renders with values. Alternatively, you may be able to define the appropriate selection values in the template file.' , $attribute -> getName ()),
'type' => 'warn' ));
2009-06-30 10:46:00 +00:00
printf ( '<select id="%s" name="new_values[%s][]" onFocus="focus_%s(this);" onChange="blur_%s(this);">' ,
2009-06-30 11:52:55 +00:00
$id , htmlspecialchars ( $attribute -> getName ()), $attribute -> getName (), $attribute -> getName ());
2009-06-30 10:46:00 +00:00
foreach ( $attribute -> getSelection () as $value => $description ) {
printf ( '<option value="%s" %s>%s</option>' , $value ,
( $value == $val ) ? 'selected' : '' , $description );
if ( $value == $val ) $found = true ;
if ( $value == '' ) $empty_value = true ;
2009-06-30 11:52:55 +00:00
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
if ( ! $found ) {
/*if ($val || ($i >= 0) || ($attribute->getEntry() && $attribute->getEntry()->getDn()))*/
printf ( '<option value="%s" selected>%s</option>' , $val , $val );
if ( $val == '' ) $empty_value = true ;
2009-06-30 11:52:55 +00:00
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
if (( strlen ( $val ) > 0 ) && ! $empty_value && ( $attribute -> getEntry () && $attribute -> getEntry () -> getDn ())) {
printf ( '<option value="">(%s)</option>' , _ ( 'none, remove value' ));
2009-06-30 11:52:55 +00:00
echo " \n " ;
2009-06-30 10:46:00 +00:00
}
echo '</select>' ;
if ( $attribute -> hasProperty ( 'helper' )) {
echo '</td><td valign="top">' ;
$this -> draw ( 'Helper' , $attribute , $i );
echo '</td></tr></table>' ;
}
}
}
protected function getSelectionAttributeMenuItem ( $attribute , $i ) {
switch ( $i ) {
case IdAttributeAddValueMenuItem :
if ( ! $attribute -> isMultiple ()) {
return $this -> get ( 'Attribute::MenuItem' , $attribute , $i );
}
return '' ;
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
case IdAttributeModifyMemberMenuItem :
return '' ;
2009-06-30 11:52:55 +00:00
2009-06-30 10:46:00 +00:00
default :
return $this -> get ( 'Attribute::MenuItem' , $attribute , $i );
}
}
protected function drawSelectionAttributeIcon ( $attribute , $val ) {
2009-06-30 11:52:55 +00:00
if ( ! $attribute -> isMultiple () || $attribute -> isReadOnly ())
2009-06-30 10:46:00 +00:00
$this -> draw ( 'Attribute::Icon' , $attribute , $val );
}
/***************************/
/* Paint a ShadowAttribute */
/***************************/
protected function drawShadowAttributeReadOnlyValue ( $attribute , $i ) {
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val )) $val = '' ;
if ( $i < 0 ) $i = 0 ;
2009-06-30 11:51:50 +00:00
printf ( '<input type="hidden" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" />' ,
2009-06-30 10:46:00 +00:00
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $val ));
$today = date ( 'U' );
$shadow_date = $today ;
if ( $attribute -> getEntry ()) {
$shadow_date = shadow_date ( $attribute -> getEntry () -> getAttributes (), $attribute -> getName ());
}
echo htmlspecialchars ( $val ) . ' ' ;
echo '<small>' ;
$this -> draw ( 'ShadowDate' , $attribute , $shadow_date );
echo '</small><br />' ;
}
protected function drawShadowAttributeReadWriteValue ( $attribute , $i ) {
$this -> draw ( 'Attribute::ReadWriteValue' , $attribute , $i );
$val = $attribute -> getValue ( $i );
if ( ! is_string ( $val ) || ( strlen ( $val ) <= 0 )) return ;
$today = date ( 'U' );
$shadow_date = $today ;
if ( $attribute -> getEntry ()) {
$shadow_date = shadow_date ( $attribute -> getEntry () -> getAttributes (), $attribute -> getName ());
}
# Show the dates for all the shadow attributes.
if ( $shadow_date !== false ) {
echo '<small>' ;
$this -> draw ( 'ShadowDate' , $attribute , $shadow_date );
echo '</small>' ;
echo '<br />' ;
}
}
protected function drawShadowAttributeShadowDate ( $attribute , $shadow_date ) {
2009-06-30 11:46:44 +00:00
$config = $_SESSION [ APPCONFIG ];
2009-06-30 10:46:00 +00:00
$shadow_before_today_attrs = arrayLower ( $attribute -> shadow_before_today_attrs );
$shadow_after_today_attrs = arrayLower ( $attribute -> shadow_after_today_attrs );
$today = date ( 'U' );
if (( $today < $shadow_date ) && in_array ( strtolower ( $attribute -> getName ()), $shadow_before_today_attrs )) {
echo '<span style="color:red">(' ;
echo htmlspecialchars ( strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date ));
echo ')</span>' ;
} elseif (( $today > $shadow_date ) && in_array ( strtolower ( $attribute -> getName ()), $shadow_after_today_attrs )) {
echo '<span style="color:red">(' ;
echo htmlspecialchars ( strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date ));
echo ')</span>' ;
} else {
echo '(' ;
echo htmlspecialchars ( strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date ));
echo ')' ;
}
}
}
?>