2009-06-30 09:29:51 +00:00
< ? php
2009-06-30 10:40:33 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/template_engine.php,v 1.33 2006/05/13 12:52:26 wurley Exp $
2009-06-30 09:29:51 +00:00
/**
* Template render engine .
* @ param dn $dn DN of the object being edited . ( For editing existing entries )
* @ param dn $container DN where the new object will be created . ( For creating new entries )
* @ param string $template to use for new entry . ( For creating new entries )
* @ todo schema attr keys should be in lowercase .
* @ package phpLDAPadmin
* @ author The phpLDAPadmin development team
*/
/**
*/
2009-06-30 10:26:08 +00:00
require './common.php' ;
if ( ! $ldapserver -> haveAuthInfo ())
pla_error ( _ ( 'Not enough information to login to server. Please check your configuration.' ));
2009-06-30 09:29:51 +00:00
$friendly_attrs = process_friendly_attr_table (); // @todo might not need this.
2009-06-30 10:26:08 +00:00
$pjs = array ();
2009-06-30 09:29:51 +00:00
# REMOVE THSE @todo
$today = date ( 'U' );
$shadow_before_today_attrs = arrayLower ( array ( 'shadowLastChange' , 'shadowMin' ));
$shadow_after_today_attrs = arrayLower ( array ( 'shadowMax' , 'shadowExpire' , 'shadowWarning' , 'shadowInactive' ));
2009-06-30 10:26:08 +00:00
$shadow_format_attrs = array_merge ( $shadow_before_today_attrs , $shadow_after_today_attrs );
2009-06-30 09:29:51 +00:00
# END REMOVE
# If we have a DN, then this is to edit the entry.
if ( isset ( $_REQUEST [ 'dn' ])) {
2009-06-30 10:26:08 +00:00
$dn = $_GET [ 'dn' ];
$decoded_dn = rawurldecode ( $dn );
$encoded_dn = rawurlencode ( $decoded_dn );
if ( ! $ldapserver -> haveAuthInfo ())
pla_error ( _ ( 'Not enough information to login to server. Please check your configuration.' ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:03 +00:00
$ldapserver -> dnExists ( $dn )
2009-06-30 10:26:08 +00:00
or pla_error ( sprintf ( _ ( 'No such entry: %s' ), pretty_print_dn ( $dn )));
2009-06-30 09:29:51 +00:00
$rdn = get_rdn ( $dn );
2009-06-30 10:26:08 +00:00
$attrs = $ldapserver -> getDNAttrs ( $dn , false , $config -> GetValue ( 'deref' , 'view' ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$modified_attrs = isset ( $_REQUEST [ 'modified_attrs' ]) ? $_REQUEST [ 'modified_attrs' ] : false ;
$show_internal_attrs = isset ( $_REQUEST [ 'show_internal_attrs' ]) ? true : false ;
2009-06-30 09:29:51 +00:00
# If an entry has more children than this, stop searching and display this amount with a '+'
$max_children = 100 ;
} else {
$dn = '' ;
$rdn = '' ;
$encoded_dn = '' ;
if ( $_REQUEST [ 'template' ] == 'custom' ) {
include TMPLDIR . 'template_header.php' ;
require TMPLDIR . 'creation/custom.php' ;
die ();
} else {
$templates = new Templates ( $ldapserver -> server_id );
$template = $templates -> GetTemplate ( $_REQUEST [ 'template' ]);
}
}
include TMPLDIR . 'template_header.php' ;
2009-06-30 10:26:08 +00:00
/*
* When we get here , ( either a new entry , or modifying an existing entry ), if the
* empty_attrs array has content , then we need to ask the user for this information .
*/
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( isset ( $template [ 'empty_attrs' ])) {
masort ( $template [ 'empty_attrs' ], 'page,order' , 1 );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# What page are we working on.
$page = isset ( $_REQUEST [ 'page' ]) ? $_REQUEST [ 'page' ] : 1 ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf ( '<center><h2>%s</h2></center>' , $template [ 'description' ]);
echo " \n \n " ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( isset ( $_REQUEST [ 'nextpage' ]) && ! $_REQUEST [ 'nextpage' ]) {
$new_dn = sprintf ( '%s=%s,%s' , $template [ 'rdn' ], $_REQUEST [ 'form' ][ $template [ 'rdn' ]], $_REQUEST [ 'container' ]);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<form action="create.php" method="post">' ;
2009-06-30 10:40:33 +00:00
printf ( '<input type="hidden" name="new_dn" value="%s" />' , htmlspecialchars ( $new_dn ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
2009-06-30 10:26:45 +00:00
echo '<form action="template_engine.php" method="post" id="template_form" name="template_form" enctype="multipart/form-data">' ;
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:45 +00:00
if ( isset ( $_REQUEST [ 'form' ])) {
2009-06-30 10:26:08 +00:00
foreach ( $_REQUEST [ 'form' ] as $attr => $value ) {
# Check for any with post actions.
if ( isset ( $template [ 'attribute' ][ $attr ][ 'post' ]) && $_REQUEST [ 'page' ] == $template [ 'attribute' ][ $attr ][ 'page' ] + 1 ) {
if ( preg_match ( '/^=php\.(\w+)\((.*)\)$/' , $template [ 'attribute' ][ $attr ][ 'post' ], $matches )) {
switch ( $matches [ 1 ]) {
case 'Password' :
preg_match_all ( '/%(\w+)(\|.+)?(\/[lU])?%/U' , $matches [ 2 ], $matchall );
$enc = $_REQUEST [ $matchall [ 1 ][ 0 ]];
$password = $_REQUEST [ 'form' ][ $matchall [ 1 ][ 1 ]];
if ( trim ( $password )) {
$value = password_hash ( $password , $enc );
$_REQUEST [ 'form' ][ $attr ] = $value ;
}
break ;
case 'SambaPassword' :
$matchall = explode ( ',' , $matches [ 2 ]);
$attr = preg_replace ( '/%/' , '' , $matchall [ 1 ]);
# If we have no password, then dont hash nothing!
if ( ! trim ( $_REQUEST [ 'form' ][ $attr ]))
2009-06-30 09:40:37 +00:00
break ;
2009-06-30 10:26:08 +00:00
$sambapassword = new smbHash ;
2009-06-30 09:40:37 +00:00
2009-06-30 10:26:08 +00:00
switch ( $matchall [ 0 ]) {
case 'LM' : $value = $sambapassword -> lmhash ( $_REQUEST [ 'form' ][ $attr ]);
break ;
case 'NT' : $value = $sambapassword -> nthash ( $_REQUEST [ 'form' ][ $attr ]);
break ;
default :
$value = null ;
}
2009-06-30 09:40:37 +00:00
2009-06-30 10:26:08 +00:00
$_REQUEST [ 'form' ][ $attr ] = $value ;
break ;
2009-06-30 09:40:37 +00:00
2009-06-30 10:26:08 +00:00
case 'Join' :
preg_match_all ( '/%(\w+)(\|.+)?(\/[lU])?%/U' , $matches [ 2 ], $matchall );
$matchattrs = explode ( ',' , $matches [ 2 ]);
$char = $matchattrs [ 0 ];
2009-06-30 09:40:37 +00:00
2009-06-30 10:26:08 +00:00
$values = array ();
foreach ( $matchall [ 1 ] as $joinattr ) {
if ( isset ( $_REQUEST [ 'form' ][ $joinattr ]))
$values [] = $_REQUEST [ 'form' ][ $joinattr ];
else if ( isset ( $_REQUEST [ $joinattr ]))
$values [] = $_REQUEST [ $joinattr ];
2009-06-30 09:40:37 +00:00
2009-06-30 10:26:08 +00:00
else
pla_error ( sprintf ( _ ( 'Your template is missing variable (%s)' ), $joinattr ));
}
$value = implode ( $char , $values );
$_REQUEST [ 'form' ][ $attr ] = $value ;
break ;
default :
pla_error ( sprintf ( _ ( 'Your template has an unknown post function (%s).' ), $matches [ 1 ]));
}
2009-06-30 09:29:51 +00:00
}
}
2009-06-30 10:26:08 +00:00
if ( is_array ( $value ))
foreach ( $value as $item )
printf ( '<input type="hidden" name="form[%s][]" value="%s" />' , $attr , $item );
else
printf ( '<input type="hidden" name="form[%s]" value="%s" />' , $attr , $value );
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:45 +00:00
# Have we got a Binary Attribute?
if ( isset ( $_FILES [ 'form' ][ 'name' ]) && is_array ( $_FILES [ 'form' ][ 'name' ])) {
foreach ( $_FILES [ 'form' ][ 'name' ] as $attr => $details ) {
if ( is_uploaded_file ( $_FILES [ 'form' ][ 'tmp_name' ][ $attr ])) {
$file = $_FILES [ 'form' ][ 'tmp_name' ][ $attr ];
$f = fopen ( $file , 'r' );
$binary_data = fread ( $f , filesize ( $file ));
fclose ( $f );
// @todo: This may need to be implemented.
//if (is_binary_option_required($ldapserver,$attr))
// $attr .= ';binary';
$_SESSION [ 'submitform' ][ $attr ] = $binary_data ;
printf ( '<input type="hidden" name="form[%s]" value="" />' , $attr );
}
}
}
}
2009-06-30 10:26:08 +00:00
printf ( '<input type="hidden" name="server_id" value="%s" />' , $ldapserver -> server_id );
2009-06-30 10:40:33 +00:00
printf ( '<input type="hidden" name="template" value="%s" />' , htmlspecialchars ( $_REQUEST [ 'template' ]));
2009-06-30 10:26:08 +00:00
printf ( '<input type="hidden" name="object_classes" value="%s" />' , rawurlencode ( serialize ( array_values ( $template [ 'objectclass' ]))));
printf ( '<input type="hidden" name="page" value="%s" />' , $page + 1 );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo " \n \n " ;
echo '<center>' ;
echo '<table class="confirm" border="0">' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<tr class="spacer"><td colspan="3"> </td></tr>' ;
echo " \n \n " ;
echo '<tr>' ;
2009-06-30 09:29:51 +00:00
if ( isset ( $template [ 'askcontainer' ]) && $template [ 'askcontainer' ] && $page == 1 ) {
if ( ! ( isset ( $template [ 'regexp' ]) && isset ( $template [ 'regexp' ]))) {
2009-06-30 10:26:08 +00:00
echo '<td> </td>' ;
echo '<td class="heading">Container <acronym title="Distinguished Name">DN</acronym>:</td>' ;
printf ( '<td><input type="text" name="container" size="40" value="%s" /> ' ,
htmlspecialchars ( $_REQUEST [ 'container' ]));
draw_chooser_link ( 'template_form.container' );
echo '</td></tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<tr class="spacer"><td colspan="3"></td></tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
echo '<td> </td>' ;
echo '<td class="heading">Container <acronym title="Distinguished Name">DN</acronym>:</td>' ;
2009-06-30 10:26:45 +00:00
printf ( '<td><input type="text" name="container" size="40" value="%s" disabled />' ,
2009-06-30 10:26:08 +00:00
htmlspecialchars ( $_REQUEST [ 'container' ]));
2009-06-30 10:40:33 +00:00
printf ( '<input type="hidden" name="container" value="%s" /></td></tr>' , htmlspecialchars ( $_REQUEST [ 'container' ]));
2009-06-30 10:26:08 +00:00
echo '<tr class="spacer"><td colspan="3"></td></tr>' ;
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
2009-06-30 10:40:33 +00:00
printf ( '<td><input type="hidden" name="container" value="%s" /></td></tr>' , htmlspecialchars ( $_REQUEST [ 'container' ]));
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$count = 0 ;
$nextpage = 0 ;
$mustitems = 0 ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
foreach ( $template [ 'empty_attrs' ] as $attr => $detail ) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$mustitem = false ;
$verifyitem = false ;
$type = isset ( $detail [ 'type' ]) ? $detail [ 'type' ] : 'text' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( ! isset ( $detail [ 'page' ]))
$detail [ 'page' ] = 1 ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$size = isset ( $detail [ 'size' ]) ? $detail [ 'size' ] : 20 ;
$maxlength = isset ( $detail [ 'maxlength' ]) ? $detail [ 'maxlength' ] : null ;
$rows = isset ( $detail [ 'rows' ]) ? $detail [ 'rows' ] : null ;
$cols = isset ( $detail [ 'cols' ]) ? $detail [ 'cols' ] : null ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Check that the page number is correct.
if ( $detail [ 'page' ] < $page && ! isset ( $attr [ $attr ])) {
# ERROR: This attribute should be set by now.
print " We should have set [ $attr ] by now.<BR> " ;
2009-06-30 09:40:37 +00:00
2009-06-30 10:26:08 +00:00
} elseif ( $detail [ 'page' ] == $page ) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$count ++ ;
echo '<tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Some conditional checking.
# $detail['must'] & $detail['disable'] cannot be set at the same time.
if ( isset ( $detail [ 'must' ]) && $detail [ 'must' ] && isset ( $detail [ 'disable' ]) && $detail [ 'disable' ])
2009-06-30 10:40:33 +00:00
pla_error ( sprintf ( _ ( 'Attribute [%s] is a MUST attribute, so it cannot be disabled.' ), $attr ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# If this attribute is disabled, go to the next one.
if ( isset ( $detail [ 'disable' ]) && $detail [ 'disable' ])
continue ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Evaluate our Default Value, if its a function call result.
if ( isset ( $detail [ 'value' ])) {
if ( is_array ( $detail [ 'value' ])) {
# If value is an array, then it must a select list.
$type = 'select' ;
$defaultresult = sprintf ( '<select name="form[%s]" id="%%s" %%s %%s>' , $attr );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
foreach ( $detail [ 'value' ] as $key => $value ) {
if ( preg_match ( '/^_KEY:/' , $key ))
$key = preg_replace ( '/^_KEY:/' , '' , $key );
else
$key = $value ;
$defaultresult .= sprintf ( '<option name="%s" value="%s" %s>%s</option>' , $value , $key ,
(( isset ( $detail [ 'default' ]) && $detail [ 'default' ] == $key ) ? 'selected' : '' ), $value );
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
$defaultresult .= '</select>' ;
$detail [ 'value' ] = $defaultresult ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
$detail [ 'value' ] = $templates -> EvaluateDefault ( $ldapserver , $detail [ 'value' ], $_REQUEST [ 'container' ], null ,
( isset ( $detail [ 'default' ]) ? $detail [ 'default' ] : null ));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
#if the default has a select list, then change the type to select
if ( preg_match ( '/<select .*>/i' , $detail [ 'value' ]))
$type = 'select' ;
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# @todo: if value is a select list, then it cannot be hidden.
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# If this is a hidden attribute, then set its value.
if ( isset ( $detail [ 'hidden' ]) && $detail [ 'hidden' ]) {
2009-06-30 10:40:33 +00:00
if ( isset ( $detail [ 'value' ])) {
printf ( '<input type="%s" name="form[%s]" id="%s" value="%s"/>' , 'hidden' , $attr , $attr , $detail [ 'value' ]);
continue ;
} else {
pla_error ( sprintf ( _ ( 'Attribute [%s] is a HIDDEN attribute, however, it is missing a VALUE in your template.' ), $attr ));
}
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# This is a displayed attribute.
# Flag it as a must attribute so that we do get a value.
if ( isset ( $detail [ 'must' ]) && $detail [ 'must' ] &&
! isset ( $detail [ 'presubmit' ]) &&
$type != 'select' ) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$mustitems ++ ;
$mustitem = true ;
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Display the icon if one is required.
if ( isset ( $detail [ 'icon' ]) && trim ( $detail [ 'icon' ]))
2009-06-30 10:40:33 +00:00
printf ( '<td><img src="%s" alt="Icon" /></td>' , $detail [ 'icon' ]);
2009-06-30 10:26:08 +00:00
else
printf ( '<td> </td>' );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<td class="heading">' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Display the label.
if ( isset ( $detail [ 'description' ]) && ( trim ( $detail [ 'description' ])))
printf ( '<acronym title="%s">%s</acronym>:' , $detail [ 'description' ], $detail [ 'display' ]);
2009-06-30 10:40:33 +00:00
elseif ( isset ( $detail [ 'display' ]))
2009-06-30 10:40:03 +00:00
printf ( '%s:' , $detail [ 'display' ]);
2009-06-30 10:27:11 +00:00
2009-06-30 10:40:33 +00:00
else
printf ( '%s:' , _ ( 'No DISPLAY/DESCRIPTION attribute in template file' ));
2009-06-30 10:26:08 +00:00
echo '</td>' ;
# Calculate the events.
# @todo: Need to change js so that if a must attr is auto populated, it decrements the total and enables the submit.
if ( isset ( $detail [ 'onchange' ])) {
if ( is_array ( $detail [ 'onchange' ])) {
foreach ( $detail [ 'onchange' ] as $value )
$templates -> OnChangeAdd ( $ldapserver , $attr , $value );
} else {
$templates -> OnChangeAdd ( $ldapserver , $attr , $detail [ 'onchange' ]);
}
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Display the input box.
echo '<td>' ;
2009-06-30 10:26:45 +00:00
# Is this a binary attribute
if ( $ldapserver -> isAttrBinary ( $attr )) {
printf ( '<input type="file" name="form[%s]" size="20" />' , $attr );
if ( ! ini_get ( 'file_uploads' ))
printf ( '<br /><small><b>%s</b></small><br />' ,
_ ( 'Your PHP configuration has disabled file uploads. Please check php.ini before proceeding.' ));
else
printf ( '<br /><small><b>%s: %s</b></small><br />' ,
_ ( 'Maximum file size' ), ini_get ( 'upload_max_filesize' ));
} elseif ( in_array ( $type , array ( 'text' , 'password' ))) {
2009-06-30 10:26:08 +00:00
printf ( '<input type="%s" size="%s" name="form[%s]%s" id="%s" value="%s" %s%s%s />' ,
$type , $size , $attr ,( isset ( $detail [ 'array' ]) && ( $detail [ 'array' ] > 1 ) ? '[]' : '' ), $attr ,
( isset ( $detail [ 'value' ]) ? $detail [ 'value' ] : '' ),
" onBlur= \" fill(' $attr ', this.value); \" " ,
( isset ( $detail [ 'disable' ]) ? 'disabled' : '' ),
( $maxlength ? sprintf ( ' maxlength="%s" ' , $maxlength ) : '' ));
} elseif ( $type == 'textarea' ) {
printf ( '<textarea size="%s" name="form[%s]%s" id="%s" value="%s" cols="%s" rows="%s" %s%s ></textarea>' ,
$size , $attr ,( isset ( $detail [ 'array' ]) && ( $detail [ 'array' ] > 1 ) ? '[]' : '' ), $attr ,
( isset ( $detail [ 'value' ]) ? $detail [ 'value' ] : '' ),
( $cols ? $cols : 35 ),
( $rows ? $rows : 4 ),
" onBlur= \" fill(' $attr ', this.value); \" " ,
( isset ( $detail [ 'disable' ]) ? 'disabled' : '' ));
} elseif ( $type == 'select' ) {
printf ( $detail [ 'value' ], $attr ,
" onBlur= \" fill(' $attr ', this.value); \" " ,
( isset ( $detail [ 'disable' ]) ? 'disabled' : ' ' ));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Disabled items dont get submitted.
# @todo need to add some js to enable them on submit, or add them as hidden items.
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $mustitem )
echo ' *' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Do we have a helper, and is it configured for the side.
if ( isset ( $detail [ 'helper' ]) && isset ( $detail [ 'helper' ][ 'location' ])
&& $detail [ 'helper' ][ 'location' ] == 'side' && isset ( $detail [ 'helper' ][ 'value' ])) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf ( ' %s' , $templates -> HelperValue ( $detail [ 'helper' ][ 'value' ],
( isset ( $detail [ 'helper' ][ 'id' ]) ? $detail [ 'helper' ][ 'id' ] : '' ), $_REQUEST [ 'container' ], $ldapserver , null ,
isset ( $detail [ 'helper' ][ 'default' ]) ? $detail [ 'helper' ][ 'default' ] : '' ));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( isset ( $detail [ 'hint' ]) && ( trim ( $detail [ 'hint' ])))
printf ( ' <span class="hint">(hint: %s)</span></td>' , $detail [ 'hint' ]);
else
echo '</td>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</tr>' . " \n " ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Do we have a verify attribute?
if ( isset ( $detail [ 'verify' ]) && ( $detail [ 'verify' ])) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$verifyitems = true ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<tr><td> </td><td class="heading">' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Display the label.
if ( isset ( $detail [ 'description' ]) && ( trim ( $detail [ 'description' ])))
printf ( '<acronym title="%s">%s %s</acronym>:' , _ ( 'Verify' ), $detail [ 'description' ], $detail [ 'display' ]);
else
printf ( '%s %s:' , _ ( 'Verify' ), $detail [ 'display' ]);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</td><td>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( in_array ( $type , array ( 'text' , 'password' ))) {
printf ( '<input type="%s" name="%s" id="%s" value="%s" %s/>' ,
$type , $attr . " V " , $attr . " V " ,( isset ( $detail [ 'value' ]) ? $detail [ 'value' ] : '' ),
sprintf ( 'onBlur="check(form.%s,form.%sV)"' , $attr , $attr ));
}
echo '</td></tr>' . " \n " ;
}
# Is this a multiarray input?
if ( isset ( $detail [ 'array' ]) && ( $detail [ 'array' ])) {
for ( $i = 2 ; $i <= $detail [ 'array' ]; $i ++ ) {
echo '<tr><td> </td><td> </td>' ;
printf ( '<td><input type="%s" name="form[%s][]" id="%s" value="%s" %s %s />' ,
$type , $attr , $attr . $i ,( isset ( $detail [ 'value' ]) ? $detail [ 'value' ] : '' ),
" onBlur= \" fill(' $attr ', this.value); \" " ,
isset ( $detail [ 'disable' ]) ? 'disabled' : '' );
if ( isset ( $detail [ 'helper' ]) && isset ( $detail [ 'helper' ][ 'location' ])
&& $detail [ 'helper' ][ 'location' ] == 'side' && isset ( $detail [ 'helper' ][ 'value' ])) {
printf ( ' %s' , $templates -> HelperValue ( $detail [ 'helper' ][ 'value' ],
( isset ( $detail [ 'helper' ][ 'id' ]) ? $detail [ 'helper' ][ 'id' ] : '' ), $_REQUEST [ 'container' ], $ldapserver , $i ));
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
echo '</td></tr>' . " \n " ;
}
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Do we have a helper.
# Side helpers are handled above.
# @todo: Helpers must have an onchange or onsubmit.
# @todo: Helpers must have an id field.
# @todo: Helpers must have an post field.
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( isset ( $detail [ 'helper' ]) && ( ! isset ( $detail [ 'helper' ][ 'location' ]) || $detail [ 'helper' ][ 'location' ] != 'side' )) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<tr><td> </td>' ;
echo '<td class="heading">' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Display the label.
if ( isset ( $detail [ 'helper' ][ 'description' ]) && ( trim ( $detail [ 'helper' ][ 'description' ])))
printf ( '<acronym title="%s">%s</acronym>:' , $detail [ 'helper' ][ 'description' ], $detail [ 'helper' ][ 'display' ]);
else
printf ( '%s:' , $detail [ 'helper' ][ 'display' ]);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</td>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf ( '<td>%s</td>' , $templates -> HelperValue ( $detail [ 'helper' ][ 'value' ], $detail [ 'helper' ][ 'id' ]));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( isset ( $detail [ 'spacer' ]) && $detail [ 'spacer' ])
echo '<tr class="spacer"><td colspan="3"></td></tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# See if there are any future ones - if there are and we dont ask any this round, then thats an error.
} elseif ( $detail [ 'page' ] > $page ) {
$nextpage ++ ;
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# @todo: Proper error message required.
if ( $nextpage && ! $count )
pla_error ( sprintf ( _ ( 'We are missing a page for [%s] attributes.' ), $nextpage ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# If there is no count, display the summary
if ( ! $count ) {
2009-06-30 10:40:33 +00:00
printf ( '<tr><td><img src="%s" alt="Create" /></td><td><span class="x-small">%s :</span></td><td><b>%s</b></td></tr>' ,
2009-06-30 10:26:08 +00:00
$template [ 'icon' ], _ ( 'Create Object' ), htmlspecialchars ( $new_dn ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<tr class="spacer"><td colspan="3"></td></tr>' ;
2009-06-30 09:29:51 +00:00
$counter = 0 ;
foreach ( $_REQUEST [ 'form' ] as $attr => $value ) {
# Remove blank attributes.
2009-06-30 10:40:33 +00:00
if ( ! is_array ( $_REQUEST [ 'form' ][ $attr ]) && trim ( $_REQUEST [ 'form' ][ $attr ]) == '' ) {
2009-06-30 09:29:51 +00:00
unset ( $_REQUEST [ 'form' ][ $attr ]);
continue ;
}
$attrs [] = $attr ;
2009-06-30 10:26:45 +00:00
printf ( '<tr class="%s"><td colspan=2>' ,( $counter ++% 2 == 0 ? 'even' : 'odd' ));
2009-06-30 09:29:51 +00:00
printf ( '<input type="hidden" name="attrs[]" value="%s" />' , $attr );
2009-06-30 10:26:45 +00:00
2009-06-30 09:29:51 +00:00
if ( is_array ( $value ))
foreach ( $value as $item ) {
if ( $item && ! isset ( $unique [ $item ])) {
$unique [ $item ] = 1 ;
2009-06-30 10:26:45 +00:00
printf ( '<input type="hidden" name="vals[%s][]" value="%s" />' ,
array_search ( $attr , $attrs ), $item );
printf ( '%s</td><td><b>%s</b></td></tr>' , $attr , htmlspecialchars ( $item ));
2009-06-30 09:29:51 +00:00
}
}
else {
$display = $value ;
2009-06-30 10:40:03 +00:00
if ( isset ( $template [ 'attribute' ][ $attr ][ 'type' ]) && $template [ 'attribute' ][ $attr ][ 'type' ] == 'password' )
if ( obfuscate_password_display ( $_REQUEST [ 'enc' ]))
2009-06-30 09:29:51 +00:00
$display = '********' ;
printf ( '<input type="hidden" name="vals[]" value="%s" />' , $value );
2009-06-30 10:26:45 +00:00
printf ( '%s</td><td><b>%s</b></td></tr>' , $attr , htmlspecialchars ( $display ));
2009-06-30 09:29:51 +00:00
}
}
2009-06-30 10:40:33 +00:00
if ( isset ( $_SESSION [ 'submitform' ])) {
echo '<tr class="spacer"><td colspan="3"></td></tr>' ;
foreach ( array_keys ( $_SESSION [ 'submitform' ]) as $attr ) {
2009-06-30 10:26:45 +00:00
2009-06-30 10:40:33 +00:00
printf ( '<tr class="%s"><td colspan=2>%s</td><td><b>%s</b>' ,
( $counter ++% 2 == 0 ? 'even' : 'odd' ), $attr , _ ( 'Binary value not displayed' ));
printf ( '<input type="hidden" name="attrs[]" value="%s" /></td></tr>' , $attr );
}
2009-06-30 10:26:45 +00:00
}
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<tr class="spacer"><td colspan="3"></td></tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( ! $nextpage && isset ( $_REQUEST [ 'nextpage' ]) && ! $_REQUEST [ 'nextpage' ]) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Look for any presubmit functions.
foreach ( $template [ 'empty_attrs' ] as $attr => $detail ) {
if ( isset ( $template [ 'attribute' ][ $attr ][ 'presubmit' ]) && ! isset ( $_REQUEST [ 'form' ][ $attr ])) {
printf ( '<tr class="%s"><td colspan=2>%s</td><td><b>%s</b></td></tr>' ,
( $counter ++% 2 == 0 ? 'even' : 'odd' ), $attr , htmlspecialchars ( _ ( '(Auto evaluated on submission.)' )));
printf ( '<input type="hidden" name="presubmit[]" value="%s" />' , $attr );
}
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
printf ( '<tr><td colspan="3"><center><br /><input type="submit" name="submit" value="%s" %s /></center></td></tr>' ,
_ ( 'Create Object' ), $mustitems ? 'disabled' : '' );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} elseif ( $nextpage ) {
printf ( '<tr><td colspan="3"><center><br /><input type="submit" name="submit" value="%s" %s /></center></td></tr>' ,
_ ( 'Next Page' ), $mustitems ? 'disabled' : '' );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
printf ( '<tr><td colspan="3"><center><br /><input type="submit" name="submit" value="%s" %s /></center></td></tr>' ,
_ ( 'Proceed >>' ), $mustitems ? 'disabled' : '' );
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</table>' ;
echo '</center>' ;
if ( $mustitems )
printf ( '<input type="hidden" name="mustitems" value="%s" />' , $mustitems );
printf ( '<input type="hidden" name="nextpage" value="%s" />' , $nextpage );
echo '</form>' . " \n \n " ;
printf ( '<span class="hint">' . _ ( 'Page %d' ) . '</span>' , $page );
echo " \n \n " ;
if ( $mustitems ) {
$jstext = '
< script type = " text/javascript " language = " javascript " >
var reduced = new Array ();
var form = document . getElementById ( " template_form " );
function reduceMust ( attrname ){
attr = document . getElementById ( attrname );
if ( attr . value . length > 0 ) {
if ( ! reduced [ attrname ]) {
reduced [ attrname ] = 1 ;
form . mustitems . value -- ;
}
if ( form . mustitems . value < 0 ) {
form . mustitems . value = 0 ;
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( form . mustitems . value == 0 ) {
form . submit . disabled = false ;
}
} else {
if ( reduced [ attrname ]) {
reduced [ attrname ] = 0 ;
form . mustitems . value ++ ;
}
if ( form . mustitems . value > 0 ) {
form . submit . disabled = true ;
}
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
var attrTrace ;
function fill ( id , value ) {
attrTrace = new Array ();
fillRec ( id , value );
}
function fillRec ( id , value ) {
if ( attrTrace [ id ] == 1 )
return ;
else {
attrTrace [ id ] = 1 ;
document . getElementById ( id ) . value = value ;
// here comes template-specific implementation, generated by php
if ( false ) {} ' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
foreach ( $template [ 'empty_attrs' ] as $attr => $detail ) {
$jstext .= " \t \t \t else if (id == ' $attr ') { \n " ;
if ( isset ( $detail [ 'must' ]))
$jstext .= " \t \t \t \t reduceMust(' $attr '); \n " ;
2009-06-30 10:26:45 +00:00
$hash = $templates -> getJsHash ();
2009-06-30 10:26:08 +00:00
if ( isset ( $hash [ 'autoFill' . $attr ])) {
$jstext .= $hash [ 'autoFill' . $attr ];
}
$jstext .= " \t \t \t } \n " ;
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
$jstext .= '}}</script>' ;
$pjs [] = $jstext ;
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( isset ( $verifyitems ) && $verifyitems ) {
//@todo: Return focus to the first item.
$pjs [] = '
< script type = " text/javascript " language = " javascript " >
function check ( a , b ){
if ( a . value != b . value ){
alert ( \ ' Values dont compare\ ' )
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
}
</ script > ' ;
}
# User needs to submit form to continue.
foreach ( $pjs as $script )
echo $script ;
die ();
}
2009-06-30 09:29:51 +00:00
if ( ! isset ( $template ))
$template [ 'attrs' ] = $attrs ;
# If we get here - we are displaying/editing the entry.
# Sort these entries.
2009-06-30 10:26:08 +00:00
uksort ( $template [ 'attrs' ], 'sortAttrs' );
2009-06-30 09:29:51 +00:00
2009-06-30 09:40:37 +00:00
$js_date_attrs = $config -> GetValue ( 'appearance' , 'date_attrs' );
2009-06-30 10:26:08 +00:00
$js [] = sprintf ( '<script type="text/javascript" language="javascript">var defaults = new Array();var default_date_format = "%s";</script>' , $config -> GetValue ( 'appearance' , 'date' ));
2009-06-30 09:40:37 +00:00
2009-06-30 10:26:08 +00:00
foreach ( $template [ 'attrs' ] as $attr => $vals ) {
if ( ! is_array ( $vals ))
$vals = array ( $vals );
2009-06-30 09:29:51 +00:00
flush ();
2009-06-30 09:40:37 +00:00
$schema_attr = $ldapserver -> getSchemaAttribute ( $attr , $dn );
2009-06-30 10:26:08 +00:00
if ( $schema_attr )
2009-06-30 09:29:51 +00:00
$attr_syntax = $schema_attr -> getSyntaxOID ();
else
$attr_syntax = null ;
2009-06-30 10:26:08 +00:00
if ( ! strcasecmp ( $attr , 'dn' ))
2009-06-30 09:29:51 +00:00
continue ;
2009-06-30 10:26:08 +00:00
# has the config.php specified that this attribute is to be hidden or shown?
if ( $ldapserver -> isAttrHidden ( $attr ))
2009-06-30 09:29:51 +00:00
continue ;
2009-06-30 10:26:08 +00:00
# Setup the $attr_note, which will be displayed to the right of the attr name (if any)
2009-06-30 09:29:51 +00:00
$attr_note = '' ;
2009-06-30 10:26:08 +00:00
# is there a user-friendly translation available for this attribute?
if ( isset ( $friendly_attrs [ strtolower ( $attr ) ])) {
$attr_display = $friendly_attrs [ strtolower ( $attr ) ];
$attr_note = " <acronym title= \" " . sprintf ( _ ( 'Note: \'%s\' is an alias for \'%s\'' ), $attr_display , $attr ) . " \" >alias</acronym> " ;
2009-06-30 09:29:51 +00:00
} else {
$attr_display = $attr ;
}
2009-06-30 10:26:08 +00:00
# is this attribute required by an objectClass?
2009-06-30 09:29:51 +00:00
$required_by = '' ;
2009-06-30 10:26:08 +00:00
if ( $schema_attr )
foreach ( $schema_attr -> getRequiredByObjectClasses () as $required ) {
if ( isset ( $attrs [ 'objectClass' ]) && ! is_array ( $attrs [ 'objectClass' ]))
$attrs [ 'objectClass' ] = array ( $attrs [ 'objectClass' ]);
if ( isset ( $attrs [ 'objectClass' ]) && in_array ( strtolower ( $required ), arrayLower ( $attrs [ 'objectClass' ])))
2009-06-30 09:29:51 +00:00
$required_by .= $required . ' ' ;
2009-06-30 10:26:08 +00:00
# It seems that some LDAP servers (Domino) returns attributes in lower case?
elseif ( isset ( $attrs [ 'objectclass' ]) && in_array ( strtolower ( $required ), arrayLower ( $attrs [ 'objectclass' ])))
2009-06-30 09:29:51 +00:00
$required_by .= $required . ' ' ;
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $required_by ) {
if ( trim ( $attr_note ))
2009-06-30 09:29:51 +00:00
$attr_note .= ', ' ;
2009-06-30 10:26:08 +00:00
$attr_note .= " <acronym title= \" " . sprintf ( _ ( 'Required attribute for objectClass(es) %s' ), $required_by ) . " \" > " . _ ( 'required' ) . " </acronym> " ;
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
# is this attribute required because its the RDN
2009-06-30 09:29:51 +00:00
if ( preg_match ( " /^ ${ attr } =/ " , $rdn )) {
2009-06-30 10:26:08 +00:00
if ( trim ( $attr_note ))
2009-06-30 09:29:51 +00:00
$attr_note .= ', ' ;
2009-06-30 10:26:08 +00:00
$attr_note .= " <acronym title= \" " . _ ( 'This attribute is required for the RDN.' ) . " \" > " . 'rdn' . " </acronym> " ;
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
if ( is_array ( $modified_attrs ) && in_array ( $attr , $modified_attrs ))
2009-06-30 09:29:51 +00:00
$is_modified_attr = true ;
else
$is_modified_attr = false ;
2009-06-30 10:26:08 +00:00
if ( $is_modified_attr )
echo '<tr class="updated_attr">' ;
else
echo '<tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<td class="attr">' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$schema_href = sprintf ( 'schema.php?server_id=%s&view=attributes&viewvalue=%s' ,
$ldapserver -> server_id , real_attr_name ( $attr ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:03 +00:00
printf ( '<b><a title="' . _ ( 'Click to view the schema defintion for attribute type \'%s\'' ) . '" href="%s">%s</a></b>' , $attr , $schema_href , $attr_display );
2009-06-30 10:26:08 +00:00
echo '</td>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<td class="attr_note">' ;
if ( $attr_note )
printf ( '<sup><small>%s</small></sup>' , $attr_note );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $ldapserver -> isAttrReadOnly ( $attr ))
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 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</td>' ;
echo '</tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $is_modified_attr )
echo '<tr class="updated_attr">' ;
else
echo '<tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<td class="val" colspan="2">' ;
2009-06-30 09:29:51 +00:00
/*
* Is this attribute a jpegPhoto ?
*/
2009-06-30 10:26:08 +00:00
if ( $ldapserver -> isJpegPhoto ( $attr )) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
/* Don ' t draw the delete buttons if there is more than one jpegPhoto
( phpLDAPadmin can ' t handle this case yet ) */
if ( $ldapserver -> isReadOnly () || $ldapserver -> isAttrReadOnly ( $attr ))
draw_jpeg_photos ( $ldapserver , $dn , $attr , false );
2009-06-30 09:29:51 +00:00
else
2009-06-30 10:26:08 +00:00
draw_jpeg_photos ( $ldapserver , $dn , $attr , true );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# proceed to the next attribute
echo '</td></tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $is_modified_attr )
2009-06-30 09:29:51 +00:00
echo '<tr class="updated_attr"><td class="bottom" colspan="2"></td></tr>' ;
continue ;
}
/*
* Is this attribute binary ?
*/
2009-06-30 10:26:08 +00:00
if ( $ldapserver -> isAttrBinary ( $attr )) {
2009-06-30 09:29:51 +00:00
$href = sprintf ( 'download_binary_attr.php?server_id=%s&dn=%s&attr=%s' ,
$ldapserver -> server_id , $encoded_dn , $attr );
2009-06-30 10:26:08 +00:00
echo '<small>' ;
echo _ ( 'Binary value' );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( ! strcasecmp ( $attr , 'objectSid' ))
2009-06-30 09:29:51 +00:00
printf ( ' (%s)' , binSIDtoText ( $vals [ 0 ]));
2009-06-30 10:26:08 +00:00
echo '<br />' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( count ( $vals ) > 1 ) {
for ( $i = 1 ; $i <= count ( $vals ); $i ++ )
2009-06-30 10:40:33 +00:00
printf ( '<a href="%s&value_num=%s"><img src="images/save.png" alt="Save" /> %s(%s)</a><br />' ,
2009-06-30 10:26:08 +00:00
$href , $i , _ ( 'download value' ), $i );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
2009-06-30 10:40:33 +00:00
printf ( '<a href="%s"><img src="images/save.png" alt="Save" /> %s</a><br />' , $href , _ ( 'download value' ));
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( ! $ldapserver -> isReadOnly () && ! $ldapserver -> isAttrReadOnly ( $attr ))
2009-06-30 10:40:33 +00:00
printf ( '<a href="javascript:deleteAttribute(\'%s\');" style="color:red;"><img src="images/trash.png" alt="Trash" /> %s</a>' ,
2009-06-30 10:26:08 +00:00
$attr , _ ( 'delete attribute' ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</small>' ;
echo '</td>' ;
echo '</tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $is_modified_attr )
2009-06-30 09:29:51 +00:00
echo '<tr class="updated_attr"><td class="bottom" colspan="2"></td></tr>' ;
continue ;
}
/*
2009-06-30 10:26:08 +00:00
* Note : at this point , the attribute must be text - based ( not binary or jpeg )
2009-06-30 09:29:51 +00:00
*/
2009-06-30 10:26:08 +00:00
# If this is the userPassword attribute, add the javascript so we can call check password later.
if ( ! strcasecmp ( $attr , 'userPassword' )) {
$js [] = '
< script type = " text/javascript " language = " javascript " >
2009-06-30 09:29:51 +00:00
<!--
2009-06-30 10:26:08 +00:00
function passwordComparePopup ( hash ) {
mywindow = open ( \ ' password_checker . php\ ' , \ ' myname\ ' , \ ' resizable = no , width = 450 , height = 200 , scrollbars = 1 \ ' );
mywindow . location . href = \ ' password_checker . php ? hash = \ ' + hash + \ ' & base64 = true \ ' ;
if ( mywindow . opener == null ) mywindow . opener = self ;
2009-06-30 09:29:51 +00:00
}
-->
2009-06-30 10:26:08 +00:00
</ script > ' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
/*
* If this server is in read - only mode or this attribute is configured as read_only ,
* simply draw the attribute values and continue .
*/
2009-06-30 10:26:08 +00:00
if ( $ldapserver -> isReadOnly () || $ldapserver -> isAttrReadOnly ( $attr ) || ( preg_match ( " /^ ${ attr } =/ " , $rdn ))) {
if ( is_array ( $vals )) {
foreach ( $vals as $i => $val ) {
if ( trim ( $val ) == '' )
printf ( '<span style="color:red">[%s]</span><br />' , _ ( 'empty' ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:33 +00:00
elseif ( ! strcasecmp ( $attr , 'userPassword' ) && $config -> GetValue ( 'appearance' , 'obfuscate_password_display' )) {
$user_password = $val ;
2009-06-30 10:26:08 +00:00
echo preg_replace ( '/./' , '*' , $val ) . '<br />' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:33 +00:00
} elseif ( in_array ( strtolower ( $attr ), $shadow_format_attrs )) {
2009-06-30 10:26:08 +00:00
$shadow_date = shadow_date ( $attrs , $attr );
echo htmlspecialchars ( $val ) . ' ' ;
echo '<small>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if (( $today < $shadow_date ) && in_array ( strtolower ( $attr ), $shadow_before_today_attrs ))
2009-06-30 09:29:51 +00:00
echo '<span style="color:red">' . htmlspecialchars ( " ( " . strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date ) . " ) " ) . '</span>' ;
2009-06-30 10:26:08 +00:00
elseif ( $today > $shadow_date && in_array ( strtolower ( $attr ), $shadow_after_today_attrs ))
2009-06-30 09:29:51 +00:00
echo '<span style="color:red">' . htmlspecialchars ( " ( " . strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date ) . " ) " ) . '</span>' ;
else
2009-06-30 10:26:08 +00:00
echo htmlspecialchars ( " ( " . strftime ( $config -> GetValue ( 'appearance' , 'date' ), shadow_date ( $attrs , $attr )) . " ) " );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</small>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:03 +00:00
} else
echo htmlspecialchars ( $val ) . '<br />' ;
2009-06-30 10:28:51 +00:00
}
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:40:33 +00:00
if ( ! strcasecmp ( $attr , 'userPassword' ) && isset ( $user_password ))
2009-06-30 10:26:08 +00:00
printf ( '<small><a href="javascript:passwordComparePopup(\'%s\')">%s</a></small>' , base64_encode ( $user_password ), _ ( 'Check password...' ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:03 +00:00
if ( preg_match ( " /^ ${ attr } =/ " , $rdn ))
2009-06-30 10:26:08 +00:00
printf ( '<small>(<a href="%s">%s</a>)</small>' , $rename_href , _ ( 'rename' ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</td>' ;
echo '</tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $is_modified_attr )
2009-06-30 09:29:51 +00:00
echo '<tr class="updated_attr"><td class="bottom" colspan="2"></td></tr>' ;
continue ;
}
/*
* Is this a userPassword attribute ?
*/
2009-06-30 10:26:08 +00:00
if ( 0 == strcasecmp ( $attr , 'userpassword' )) {
foreach ( $vals as $user_password ) {
$enc_type = get_enc_type ( $user_password );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Set the default hashing type if the password is blank (must be newly created)
if ( $user_password == '' )
$enc_type = get_default_hash ( $ldapserver -> server_id );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf ( '<input type="hidden" name="old_values[userpassword][]" value="%s" />' , htmlspecialchars ( $user_password ));
echo '<!-- Special case of enc_type to detect changes when user changes enc_type but not the password value -->' ;
printf ( '<input size="38" type="hidden" name="old_enc_type[]" value="%s" />' ,( $enc_type == '' ? 'clear' : $enc_type ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( obfuscate_password_display ( $enc_type ))
echo htmlspecialchars ( preg_replace ( '/./' , '*' , $user_password ));
else
echo htmlspecialchars ( $user_password );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<br />' ;
2009-06-30 10:40:33 +00:00
printf ( '<input style="width: 260px" type="%s" name="new_values[userpassword][]" value="%s" />' ,
( obfuscate_password_display ( $enc_type ) ? 'password' : 'text' ), htmlspecialchars ( $user_password ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo enc_type_select_list ( $enc_type );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<br />' ;
printf ( '<small><a href="javascript:passwordComparePopup(\'%s\')">%s</a></small>' , base64_encode ( $user_password ), _ ( 'Check password...' ));
echo '<br />' ;
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
/* Draw the "add value" link under the list of values for this attributes */
if ( ! $ldapserver -> isReadOnly () && ( $schema_attr = $ldapserver -> getSchemaAttribute ( $attr , $dn )) &&
! $schema_attr -> getIsSingleValue ()) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$add_href = sprintf ( 'add_value_form.php?server_id=%s&dn=%s&attr=%s' ,
$ldapserver -> server_id , $encoded_dn , rawurlencode ( $attr ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf ( '<div class="add_value">(<a href="%s" title="%s">%s</a>)</div>' ,
$add_href , sprintf ( _ ( 'Add an additional value to attribute \'%s\'' ), $attr ), _ ( 'add value' ));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</td>' ;
echo '</tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $is_modified_attr )
echo '<tr class="updated_attr"><td class="bottom" colspan="2"></td></tr>' ;
2009-06-30 09:29:51 +00:00
continue ;
}
/*
* Is this a boolean attribute ?
*/
2009-06-30 10:26:08 +00:00
if ( $ldapserver -> isAttrBoolean ( $attr )) {
$val = $vals [ 0 ];
printf ( '<input type="hidden" name="old_values[%s][]" value="%s" />' , htmlspecialchars ( $attr ), htmlspecialchars ( $val ));
printf ( '<select name="new_values[%s][]">' , htmlspecialchars ( $attr ));
printf ( '<option value="TRUE" %s>%s</option>' ,( $val == 'TRUE' ? ' selected' : '' ), _ ( 'true' ));
printf ( '<option value="FALSE" %s>%s</option>' ,( $val == 'FALSE' ? ' selected' : '' ), _ ( 'false' ));
printf ( '<option value="">(%s)</option>' , _ ( 'none, remove value' ));
echo '</select>' ;
echo '</td>' ;
echo '</tr>' ;
if ( $is_modified_attr )
2009-06-30 09:29:51 +00:00
echo '<tr class="updated_attr"><td class="bottom" colspan="2"></td></tr>' ;
continue ;
}
2009-06-30 10:26:08 +00:00
2009-06-30 09:40:37 +00:00
/*
* Is this a date type attribute ?
*/
2009-06-30 10:26:08 +00:00
if ( in_array_ignore_case ( $attr , array_keys ( $js_date_attrs ))) {
$val = $vals [ 0 ];
printf ( '<input type="hidden" name="old_values[%s][]" value="%s" />' , htmlspecialchars ( $attr ), htmlspecialchars ( $val ));
2009-06-30 10:40:03 +00:00
printf ( '<nobr><input type="text" size="30" id="f_date_%s" name="new_values[%s][0]" value="%s" /> ' ,
2009-06-30 10:26:08 +00:00
$attr , htmlspecialchars ( $attr ), htmlspecialchars ( $val ));
draw_date_selector_link ( $attr );
2009-06-30 10:40:03 +00:00
echo '</nobr></td>' ;
2009-06-30 10:26:08 +00:00
echo '</tr>' ;
$js [] = sprintf ( '<script type="text/javascript" language="javascript">defaults[\'f_date_%s\'] = \'%s\';</script>' , $attr , $js_date_attrs [ $attr ]);
if ( $is_modified_attr )
2009-06-30 09:40:37 +00:00
echo '<tr class="updated_attr"><td class="bottom" colspan="2"></td></tr>' ;
continue ;
}
2009-06-30 09:29:51 +00:00
/*
* End of special case attributes ( non plain text ) .
*/
/*
* This is a plain text attribute , to be displayed and edited in plain text .
*/
2009-06-30 10:26:08 +00:00
foreach ( $vals as $i => $val ) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$input_name = sprintf ( 'new_values[%s][%s]' , htmlspecialchars ( $attr ), $i );
/* 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 . */
$input_id = sprintf ( 'new_values_%s_%s' , htmlspecialchars ( $attr ), $i );
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
/* The old_values array will let update . php know if the entry contents changed
between the time the user loaded this page and saved their changes . */
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf ( '<input type="hidden" name="old_values[%s][%s]" value="%s" />' ,
htmlspecialchars ( $attr ), $i , htmlspecialchars ( $val ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Is this value is a structural objectClass, make it read-only
if ( ! strcasecmp ( $attr , 'objectClass' )) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:33 +00:00
printf ( '<a title="%s" href="schema.php?server_id=%s&view=objectClasses&viewvalue=%s"><img src="images/info.png" alt="Info" /></a> ' ,
2009-06-30 10:40:03 +00:00
_ ( 'View the schema description for this objectClass' ), $ldapserver -> server_id , htmlspecialchars ( $val ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$schema_object = $ldapserver -> getSchemaObjectClass ( $val );
2009-06-30 09:29:51 +00:00
2009-06-30 10:40:33 +00:00
# This should be an object, but we'll test it anyway
if ( is_object ( $schema_object ) && $schema_object -> getType () == 'structural' ) {
2009-06-30 10:26:08 +00:00
printf ( ' %s <small>(<acronym title="%s">%s</acronym>)</small><br />' ,
$val , _ ( 'This is a structural ObjectClass and cannot be removed.' ), _ ( 'structural' ));
printf ( '<input type="hidden" name="%s" id="%s" value="%s" />' , $input_name , $input_id , htmlspecialchars ( $val ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
continue ;
2009-06-30 09:29:51 +00:00
}
}
2009-06-30 10:26:08 +00:00
if ( is_dn_string ( $val ) || $ldapserver -> isDNAttr ( $attr ))
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $ldapserver -> dnExists ( $val )) {
2009-06-30 10:40:03 +00:00
printf ( '<a title="' . _ ( 'Go to %s' ) . '" href="template_engine.php?server_id=%s&dn=%s"><img style="vertical-align: top" src="images/go.png" /></a> ' ,
2009-06-30 10:26:08 +00:00
htmlspecialchars ( $val ), $ldapserver -> server_id , rawurlencode ( $val ));
} else {
2009-06-30 10:40:03 +00:00
printf ( '<a title="' . _ ( 'DN not available %s' ) . '"><img style="vertical-align: top" src="images/nogo.png" /></a> ' ,
2009-06-30 10:26:08 +00:00
htmlspecialchars ( $val ), $ldapserver -> server_id , rawurlencode ( $val ));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
elseif ( is_mail_string ( $val ))
2009-06-30 10:40:33 +00:00
printf ( '<a href="mailto:%s"><img style="vertical-align: center" src="images/mail.png" alt="Mail" /></a> ' , htmlspecialchars ( $val ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
elseif ( is_url_string ( $val ))
2009-06-30 10:40:33 +00:00
printf ( '<a href="%s" target="new"><img style="vertical-align: center" src="images/dc.png" alt="URL" /></a> ' , htmlspecialchars ( $val ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $ldapserver -> isMultiLineAttr ( $attr , $val ))
2009-06-30 10:40:03 +00:00
printf ( '<textarea class="val" rows="3" cols="50" name="%s" id="%s">%s</textarea>' , $input_name , $input_id , htmlspecialchars ( $val ));
2009-06-30 10:26:08 +00:00
else
2009-06-30 10:40:03 +00:00
printf ( '<input type="text" class="val" name="%s" id="%s" value="%s" /> ' , $input_name , $input_id , htmlspecialchars ( $val ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
/* draw a link for popping up the entry browser if this is the type of attribute
that houses DNs . */
if ( $ldapserver -> isDNAttr ( $attr ))
draw_chooser_link ( " edit_form. $input_id " , false );
2009-06-30 09:29:51 +00:00
2009-06-30 09:40:37 +00:00
echo '<br />' ;
2009-06-30 10:26:08 +00:00
# If this is a gidNumber on a non-PosixGroup entry, lookup its name and description for convenience
if ( ! strcasecmp ( $attr , 'gidNumber' ) &&
! in_array_ignore_case ( 'posixGroup' , $ldapserver -> getDNAttr ( $dn , 'objectClass' ))) {
2009-06-30 09:29:51 +00:00
$gid_number = $val ;
$search_group_filter = " (&(objectClass=posixGroup)(gidNumber= $val )) " ;
2009-06-30 10:26:08 +00:00
$group = $ldapserver -> search ( null , null , $search_group_filter , array ( 'dn' , 'description' ));
if ( count ( $group ) > 0 ) {
echo '<br />' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$group = array_pop ( $group );
2009-06-30 09:29:51 +00:00
$group_dn = $group [ 'dn' ];
2009-06-30 10:26:08 +00:00
$group_name = explode ( '=' , get_rdn ( $group_dn ));
2009-06-30 09:29:51 +00:00
$group_name = $group_name [ 1 ];
2009-06-30 10:26:08 +00:00
$href = sprintf ( 'template_engine.php?server_id=%s&dn=%s' , $ldapserver -> server_id , urlencode ( $group_dn ));
echo '<small>' ;
printf ( '<a href="%s">%s</a>' , $href , htmlspecialchars ( $group_name ));
$description = isset ( $group [ 'description' ]) ? $group [ 'description' ] : null ;
2009-06-30 10:40:03 +00:00
if ( $description )
2009-06-30 10:26:08 +00:00
printf ( ' (%s)' , htmlspecialchars ( $description ));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</small>' ;
2009-06-30 09:29:51 +00:00
}
}
2009-06-30 10:26:08 +00:00
# Show the dates for all the shadow attributes.
if ( in_array ( strtolower ( $attr ), $shadow_format_attrs )) {
if (( $shadow_date = shadow_date ( $attrs , $attr )) !== false ) {
echo '<br />' ;
echo '<small>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if (( $today < $shadow_date ) && in_array ( strtolower ( $attr ), $shadow_before_today_attrs ))
2009-06-30 09:29:51 +00:00
echo '<span style="color:red">' . htmlspecialchars ( strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date )) . '</span>' ;
2009-06-30 10:26:08 +00:00
elseif ( $today > $shadow_date && in_array ( strtolower ( $attr ), $shadow_after_today_attrs ))
2009-06-30 09:29:51 +00:00
echo '<span style="color:red">' . htmlspecialchars ( strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date )) . '</span>' ;
else
echo htmlspecialchars ( strftime ( $config -> GetValue ( 'appearance' , 'date' ), $shadow_date ));
2009-06-30 10:26:08 +00:00
echo '</small>' ;
2009-06-30 09:29:51 +00:00
}
}
} /* end foreach value */
/* Draw the "add value" link under the list of values for this attributes */
2009-06-30 10:26:08 +00:00
if ( ! $ldapserver -> isReadOnly () && ( $schema_attr = $ldapserver -> getSchemaAttribute ( $attr , $dn )) &&
! $schema_attr -> getIsSingleValue ()) {
2009-06-30 09:29:51 +00:00
$add_href = sprintf ( 'add_value_form.php?server_id=%s&dn=%s&attr=%s' ,
$ldapserver -> server_id , $encoded_dn , rawurlencode ( $attr ));
printf ( '<div class="add_value">(<a href="%s" title="%s">%s</a>)</div>' ,
2009-06-30 10:26:08 +00:00
$add_href , sprintf ( _ ( 'Add an additional value to attribute \'%s\'' ), $attr ), _ ( 'add value' ));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</td>' ;
echo '</tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( $is_modified_attr )
echo '<tr class="updated_attr"><td class="bottom" colspan="2"></td></tr>' ;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo " \n " ;
2009-06-30 09:29:51 +00:00
flush ();
2009-06-30 10:26:08 +00:00
} /* End foreach ($attrs as $attr => $vals) */
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ( ! $ldapserver -> isReadOnly ())
printf ( '<tr><td colspan="2"><center><input type="submit" value="%s" /></center></td></tr></table></form>' ,
_ ( 'Save Changes' ));
else
printf ( '</table>' );
?>
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
<!-- This form is submitted by JavaScript when the user clicks " Delete attribute " on a binary attribute -->
< form name = " delete_attribute_form " action = " delete_attr.php " method = " post " >
< input type = " hidden " name = " server_id " value = " <?php echo $ldapserver->server_id ; ?> " />
2009-06-30 10:40:33 +00:00
< input type = " hidden " name = " dn " value = " <?php echo htmlspecialchars( $dn ); ?> " />
2009-06-30 10:26:08 +00:00
< input type = " hidden " name = " attr " value = " FILLED IN BY JAVASCRIPT " />
</ form >
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
< ? php
foreach ( $js as $script )
echo $script ;
?>
<!-- If this entry has a binary attribute , we need to provide a form for it to submit when deleting it . -->
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
< script type = " text/javascript " language = " javascript " >
2009-06-30 09:29:51 +00:00
<!--
2009-06-30 10:26:08 +00:00
function deleteAttribute ( attrName )
2009-06-30 09:29:51 +00:00
{
2009-06-30 10:26:08 +00:00
if ( confirm ( " <?php echo _('Really delete attribute'); ?> ' " + attrName + " '? " )) {
2009-06-30 09:29:51 +00:00
document . delete_attribute_form . attr . value = attrName ;
document . delete_attribute_form . submit ();
}
}
-->
</ script >
2009-06-30 10:26:08 +00:00
</ body >
</ html >