2019-02-08 13:44:52 -05:00
< ? php
/**
* @ author The phpLDAPadmin development team
* @ package phpLDAPadmin
*/
/**
* PageRender class
*
* @ package phpLDAPadmin
* @ subpackage Templates
*/
class PageRender extends Visitor {
# Template ID
protected $template_id ;
protected $template = null ;
# Object Variables
protected $dn ;
protected $container ;
# Page number
protected $page ;
public function __construct ( $server_id , $template_id ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
$this -> server_id = $server_id ;
$this -> template_id = $template_id ;
}
/**
* Dummy method ...
*/
protected function visitAttribute () {}
/**
* Get our templates applicable for this object
*/
protected function getTemplates () {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
return new Templates ( $this -> server_id );
}
public function getTemplate () {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
return $this -> template ;
}
public function getTemplateID () {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
return $this -> template -> getID ();
}
/**
* Initialise the PageRender
*/
public function accept () {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s:%s</font><br />' , time (), __METHOD__ );
}
2019-02-08 13:44:52 -05:00
if ( $this -> template_id ) {
$templates = $this -> getTemplates ();
$this -> template = $templates -> getTemplate ( $this -> template_id );
if ( $this -> dn )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$this -> template -> setDN ( $this -> dn );
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
elseif ( $this -> container )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$this -> template -> setContainer ( $this -> container );
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$this -> template -> accept ();
# Process our <post> actions
if ( get_request ( 'post_value' , 'REQUEST' ))
2019-02-12 14:57:50 -05:00
{
foreach ( get_request ( 'post_value' , 'REQUEST' ) as $attr => $values )
{
2019-02-08 13:44:52 -05:00
$attribute = $this -> template -> getAttribute ( $attr );
2019-02-12 14:57:50 -05:00
if ( ! $attribute )
{
debug_dump_backtrace ( sprintf ( 'There was a post_value for an attribute [%s], but it doesnt exist?' , $attr ), 1 );
}
2019-02-08 13:44:52 -05:00
foreach ( $values as $index )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
if ( $attribute -> getPostValue ())
2019-02-12 14:57:50 -05:00
{
$this -> get ( 'Post' , $attribute , $index );
} else
{
$this -> get ( 'AutoPost' , $attribute , $index );
}
}
2019-02-08 13:44:52 -05:00
}
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
foreach ( $this -> template -> getAttributes ( true ) as $attribute ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP || DEBUGTMPSUB )
{
printf ( '<font size=-2>* %s [Accept:%s]</font><br />' , __METHOD__ , get_class ( $attribute ));
}
2019-02-08 13:44:52 -05:00
$this -> visit ( '' , $attribute );
}
// Sort our attribute values for display, if we are the custom template.
if ( $this -> template -> getID () == 'none' )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$this -> template -> sort ();
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
}
public function drawTitle ( $title = 'Title' ) {
printf ( '<h3 class="title">%s</h3>' , $title );
}
public function drawSubTitle ( $subtitle = null ) {
if ( is_null ( $subtitle ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$subtitle = sprintf ( '%s: <b>%s</b> %s: <b>%s</b>' ,
2019-02-12 14:57:50 -05:00
_ ( 'Server' ), $this -> getServer () -> getName (), _ ( 'Distinguished Name' ), $this -> dn );
}
2019-02-08 13:44:52 -05:00
printf ( '<h3 class="subtitle">%s</h3>' , $subtitle );
}
public function setDN ( $dn ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
if ( $this -> container )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
system_message ( array (
2019-02-12 14:57:50 -05:00
'title' => __METHOD__ ,
'body' => 'CONTAINER set while setting DN' ,
'type' => 'info' ));
}
2019-02-08 13:44:52 -05:00
$this -> dn = $dn ;
}
public function setContainer ( $dn ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
if ( $this -> dn )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
system_message ( array (
2019-02-12 14:57:50 -05:00
'title' => __METHOD__ ,
'body' => 'DN set while setting CONTAINER' ,
'type' => 'info' ));
}
2019-02-08 13:44:52 -05:00
$this -> container = $dn ;
}
/**
* May be overloaded in other classes
*/
protected function getMode () {}
protected function getModeContainer () {}
/**
* Process our < post > arguments from the templates
2019-02-12 14:52:01 -05:00
* @ param $attribute
* @ param $i
2019-02-08 13:44:52 -05:00
*/
protected function getPostAttribute ( $attribute , $i ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
$autovalue = $attribute -> getPostValue ();
$args = explode ( ';' , $autovalue [ 'args' ]);
$server = $this -> getServer ();
$vals = $attribute -> getValues ();
switch ( $autovalue [ 'function' ]) {
/**
* Join will concatenate values with a string , similiar to explode ()
* eg : = php . Join ( - ; % sambaSID % , % sidsuffix % )
*
* * arg 0
* - character to use when joining the attributes
*
* * arg 1
* - values to concatenate together . we ' ll explode % attr % values .
*/
case 'Join' :
preg_match_all ( '/%(\w+)(\|.+)?(\/[lU])?%/U' , $args [ 1 ], $matchall );
$matchattrs = $matchall [ 1 ];
$char = $args [ 0 ];
$values = array ();
$blank = 0 ;
foreach ( $matchattrs as $joinattr ) {
$attribute2 = $this -> template -> getAttribute ( $joinattr );
if ( ! $attribute2 ) {
if (( $pv = get_request ( strtolower ( $joinattr ), 'REQUEST' )) && isset ( $pv [ $attribute -> getName ()][ $i ])) {
2019-02-12 15:23:38 -05:00
$values [] = $pv [ $attribute -> getName ()][ $i ];
2019-02-08 13:44:52 -05:00
if ( ! $pv [ $attribute -> getName ()][ $i ])
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$blank ++ ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
} else {
2019-02-12 15:23:38 -05:00
$values [] = '' ;
2019-02-08 13:44:52 -05:00
$blank ++ ;
}
} elseif ( count ( $attribute2 -> getValues ()) == 0 ) {
return ;
} elseif ( count ( $attribute2 -> getValues ()) != 1 ) {
2019-02-12 15:23:38 -05:00
$values [] = '' ;
2019-02-08 13:44:52 -05:00
$blank ++ ;
system_message ( array (
'title' => _ ( 'Invalid value count for [post] processing' ),
'body' => sprintf ( '%s (<b>%s [%s]</b>)' , _ ( 'Function() variable expansion can only handle 1 value' ),
$attribute -> getName ( false ), count ( $attribute -> getValues ())),
'type' => 'warn' ));
} else
2019-02-12 14:57:50 -05:00
{
2019-02-12 15:23:38 -05:00
$values [] = $attribute2 -> getValue ( 0 );
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
# If all our value expansion results in blanks, we'll return no value
if ( count ( $matchattrs ) == $blank )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
if ( count ( $vals ) > 1 )
2019-02-12 14:57:50 -05:00
{
$vals [ $i ] = NULL ;
} else
{
$vals = NULL ;
}
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
$vals [ $i ] = implode ( $char , $values );
}
2019-02-08 13:44:52 -05:00
break ;
/**
* PasswordEncrypt will encrypt a password
* eg : = php . PasswordEncrypt ( % enc % ; % userPassword % )
*
* This function will encrypt the users password " userPassword " using the " enc " method .
*/
case 'PasswordEncrypt' :
if ( count ( $args ) != 2 ) {
system_message ( array (
'title' => _ ( 'Invalid argument count for PasswordEncrypt' ),
'body' => sprintf ( '%s (<b>%s</b>)' , _ ( 'PasswordEncrypt() only accepts two arguments' ), $autovalue [ 'args' ]),
'type' => 'warn' ));
return ;
}
if ( ! $attribute -> hasBeenModified ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
# Get the attribute.
if ( preg_match_all ( '/%(\w+)(\|.+)?(\/[lU])?%/U' , strtolower ( $args [ 1 ]), $matchall )) {
if ( count ( $matchall [ 1 ]) != 1 )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
system_message ( array (
2019-02-12 14:57:50 -05:00
'title' => _ ( 'Invalid value count for PasswordEncrypt' ),
'body' => sprintf ( '%s (<b>%s</b>)' , _ ( 'Unable to get the attribute value for PasswordEncrypt()' ), count ( $matchall [ 1 ])),
'type' => 'warn' ));
}
2019-02-08 13:44:52 -05:00
$passwordattr = $matchall [ 1 ][ 0 ];
$passwordvalue = $_REQUEST [ 'new_values' ][ $passwordattr ][ $i ];
} else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$passwordvalue = $args [ 1 ];
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
if ( ! trim ( $passwordvalue ) || in_array ( $passwordvalue , $attribute -> getOldValues ()))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
# Get the encoding
if ( $passwordattr && preg_match_all ( '/%(\w+)(\|.+)?(\/[lU])?%/U' , strtolower ( $args [ 0 ]), $matchall )) {
if ( count ( $matchall [ 1 ]) != 1 )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
system_message ( array (
2019-02-12 14:57:50 -05:00
'title' => _ ( 'Invalid value count for PasswordEncrypt' ),
'body' => sprintf ( '%s (<b>%s</b>)' , _ ( 'Unable to get the attribute value for PasswordEncrypt()' ), count ( $matchall [ 1 ])),
'type' => 'warn' ));
}
2019-02-08 13:44:52 -05:00
$enc = $_REQUEST [ $matchall [ 1 ][ 0 ]][ $passwordattr ][ $i ];
} else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$enc = $args [ 0 ];
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$enc = strtolower ( $enc );
switch ( $enc ) {
case 'lm' :
$sambapassword = new smbHash ;
$vals [ $i ] = $sambapassword -> lmhash ( $passwordvalue );
break ;
case 'nt' :
$sambapassword = new smbHash ;
$vals [ $i ] = $sambapassword -> nthash ( $passwordvalue );
break ;
default :
2019-02-08 13:51:51 -05:00
$vals [ $i ] = hash_password ( $passwordvalue , $enc );
2019-02-08 13:44:52 -05:00
}
$vals = array_unique ( $vals );
break ;
default :
$vals = $this -> get ( 'AutoPost' , $attribute , $i );
}
if ( ! $vals || $vals == $attribute -> getValues ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$attribute -> clearValue ();
if ( ! is_array ( $vals ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$attribute -> setValue ( array ( $vals ));
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$attribute -> setValue ( $vals );
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
/**
* This function is invoked if we dont know which template we should be using .
*
* @ return string Template ID to be used or null if the user was presented with a list .
*/
protected function getTemplateChoice () {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
# First work out our template
$templates = $this -> getTemplates ();
$template = $templates -> getTemplate ( $this -> template_id );
# If the template we asked for is available
if ( $this -> template_id === $template -> getID ()) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s:<u>%s</u></font><br />' , __METHOD__ , 'Choosing the SELECTED template' );
}
2019-02-08 13:44:52 -05:00
return $this -> template_id ;
# If there are no defined templates
} elseif ( count ( $templates -> getTemplates ( $this -> getMode (), $this -> getModeContainer (), false )) <= 0 ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s:<u>%s</u></font><br />' , __METHOD__ , 'Choosing the DEFAULT template, no other template applicable' );
}
2019-02-08 13:44:52 -05:00
# Since getTemplate() returns a default template if the one we want doesnt exist, we can return $templates->getID(), it should be the default.
if ( $_SESSION [ APPCONFIG ] -> getValue ( 'appearance' , 'disable_default_template' ) AND $this -> getMode () == 'creation' ) {
system_message ( array (
'title' => _ ( 'No available templates' ),
'body' => _ ( 'There are no available active templates for this container.' ),
'type' => 'warn' ));
return 'invalid' ;
} else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return $template -> getID ();
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
# If there is only 1 defined template, and no default available, then that is our template.
} elseif (( count ( $templates -> getTemplates ( $this -> getMode (), $this -> getModeContainer (), true )) == 1 ) && ! $this -> haveDefaultTemplate ()) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s:<u>%s</u></font><br />' , __METHOD__ , 'AUTOMATIC choosing a template, only 1 template applicable' );
}
2019-02-08 13:44:52 -05:00
$template = $templates -> getTemplates ( $this -> getMode (), $this -> getModeContainer (), true );
$template = array_shift ( $template );
# Dont render the only available template if it is invalid.
if ( ! $template -> isInvalid ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return $template -> getID ();
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$this -> drawTemplateChoice ();
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
} else {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s:<u>%s</u></font><br />' , __METHOD__ , 'SELECT a template to use.' );
}
2019-02-08 13:44:52 -05:00
# Propose the template choice
$this -> drawTemplateChoice ();
}
# If we got here, then there wasnt a template.
return null ;
}
2019-02-12 14:52:01 -05:00
/** DRAW ATTRIBUTE NAME *
* @ param $attribute
*/
2019-02-08 13:44:52 -05:00
final protected function drawNameAttribute ( $attribute ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$href = sprintf ( 'cmd.php?cmd=schema&server_id=%s&view=attributes&viewvalue=%s' ,
$this -> getServerID (), $attribute -> getName ());
if ( ! $_SESSION [ APPCONFIG ] -> getValue ( 'appearance' , 'show_schema_link' ) || ! $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'script' , 'schema' ))
2019-02-12 14:57:50 -05:00
{
printf ( '%s' , _ ( $attribute -> getFriendlyName ()));
}
2019-02-08 13:44:52 -05:00
elseif ( $attribute -> getLDAPtype ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
printf ( '<a href="%s" title="%s: %s">%s</a>' ,
htmlspecialchars ( $href ),
2019-02-12 14:57:50 -05:00
_ ( 'Click to view the schema definition for attribute type' ), $attribute -> getName ( FALSE ), _ ( $attribute -> getFriendlyName ()));
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
printf ( '<acronym title="%s">%s</acronym>' , _ ( 'This attribute is not defined in the LDAP schema' ), _ ( $attribute -> getFriendlyName ()));
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMPSUB )
{
printf ( ' <small>[%s]</small>' , get_class ( $attribute ));
}
2019-02-08 13:44:52 -05:00
}
2019-02-12 14:52:01 -05:00
/** ATTRIBUTE NOTES
* @ param $attribute
*/
2019-02-08 13:44:52 -05:00
protected function drawNotesAttribute ( $attribute ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$attr_note = '' ;
foreach ( array ( 'NoteAlias' , 'NoteRequired' , 'NoteRDN' , 'NoteHint' , 'NoteRO' ) as $note ) {
$alias_note = $this -> get ( $note , $attribute );
if ( $alias_note ) {
if ( trim ( $attr_note ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$attr_note .= ', ' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$attr_note .= $alias_note ;
}
}
if ( $attr_note )
2019-02-12 14:57:50 -05:00
{
printf ( '<sup><small>%s</small></sup>' , $attr_note );
}
2019-02-08 13:44:52 -05:00
}
protected function getNoteAliasAttribute ( $attribute ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
# Is there a user-friendly translation available for this attribute?
$friendly_name = $attribute -> getFriendlyName ();
if ( strtolower ( $friendly_name ) != $attribute -> getName ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return sprintf ( '<acronym title="%s: \'%s\' %s \'%s\'">%s</acronym>' ,
2019-02-12 14:57:50 -05:00
_ ( 'Note' ), $friendly_name , _ ( 'is an alias for' ), $attribute -> getName ( FALSE ), _ ( 'alias' ));
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return '' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
#@todo this function shouldnt re-calculate requiredness, it should be known in the template already - need to set the ldaptype when initiating the attribute.
protected function getNoteRequiredAttribute ( $attribute ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$required_by = '' ;
$sattr_required = '' ;
# Is this attribute required by an objectClass ?
$sattr = $this -> getServer () -> getSchemaAttribute ( $attribute -> getName ());
if ( $sattr )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$sattr_required = $sattr -> getRequiredByObjectClasses ();
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
if ( $sattr_required ) {
$oc = $this -> template -> getAttribute ( 'objectclass' );
if ( $oc )
2019-02-12 14:57:50 -05:00
{
foreach ( $oc -> getValues () as $objectclass )
{
2019-02-08 13:44:52 -05:00
# If this objectclass is in our required list
2019-02-12 14:57:50 -05:00
if ( in_array_ignore_case ( $objectclass , $sattr_required ))
{
$required_by .= sprintf ( '%s ' , $objectclass );
2019-02-08 13:44:52 -05:00
continue ;
}
# If not, see if it is in our parent.
$sattr = $this -> getServer () -> getSchemaObjectClass ( $objectclass );
2019-02-12 14:57:50 -05:00
if ( array_intersect ( $sattr -> getParents (), $sattr_required ))
{
$required_by .= sprintf ( '%s ' , $objectclass );
}
2019-02-08 13:44:52 -05:00
}
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
debug_dump_backtrace ( 'How can there be no objectclasses?' , 1 );
}
2019-02-08 13:44:52 -05:00
}
if ( $required_by )
2019-02-12 14:57:50 -05:00
{
return sprintf ( '<acronym title="%s %s">%s</acronym>' , _ ( 'Required attribute for objectClass(es)' ), $required_by , _ ( 'required' ));
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return '' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
protected function getNoteRDNAttribute ( $attribute ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
# Is this attribute required because its the RDN
if ( $attribute -> isRDN ())
2019-02-12 14:57:50 -05:00
{
return sprintf ( '<acronym title="%s">rdn</acronym>' , _ ( 'This attribute is required for the RDN.' ));
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return '' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
protected function getNoteHintAttribute ( $attribute ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
# Is there a hint for this attribute
if ( $attribute -> getHint ())
2019-02-12 14:57:50 -05:00
{
return sprintf ( '<acronym title="%s">%s</acronym>' , _ ( $attribute -> getHint ()), _ ( 'hint' ));
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return '' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
protected function getNoteROAttribute ( $attribute ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
# Is this attribute is readonly
if ( $attribute -> isReadOnly ())
2019-02-12 14:57:50 -05:00
{
return sprintf ( '<acronym title="%s">ro</acronym>' , _ ( 'This attribute has been marked as Read Only.' ));
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return '' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
/** DRAW HIDDEN VALUES **/
/**
* Draw all hidden attributes
*/
final public function drawHiddenAttributes () {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
foreach ( $this -> template -> getAttributes ( true ) as $attribute )
2019-02-12 14:57:50 -05:00
{
if ( $attribute -> hasbeenModified ())
{
2019-02-08 13:44:52 -05:00
if ( $attribute -> getValues ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
foreach ( $attribute -> getValues () as $index => $details )
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'HiddenValue' , $attribute , $index );
}
} # We are deleting this attribute, so we need to display an empty value
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'HiddenValue' , $attribute , 0 );
}
2019-02-08 13:44:52 -05:00
}
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
/**
* Draw specific hidden attribute
2019-02-12 14:52:01 -05:00
* @ param $attribute
* @ param $i
2019-02-08 13:44:52 -05:00
*/
final protected function drawHiddenValueAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
printf ( '<input type="hidden" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" />' ,
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $val ));
}
2019-02-12 14:52:01 -05:00
/** DRAW DISPLAYED OLD VALUES *
* @ param $attribute
*/
2019-02-08 13:44:52 -05:00
protected function drawOldValuesAttribute ( $attribute ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
foreach ( $attribute -> getValues () as $index => $details )
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'OldValue' , $attribute , $index );
}
2019-02-08 13:44:52 -05:00
}
final protected function drawOldValueAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
echo $attribute -> getOldValue ( $i );
}
2019-02-12 14:52:01 -05:00
/** DRAW DISPLAYED CURRENT VALUES *
* @ param $attribute
*/
2019-02-08 13:44:52 -05:00
protected function drawCurrentValuesAttribute ( $attribute ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
for ( $i = 0 ; $i < $attribute -> getValueCount (); $i ++ ) {
if ( $i > 0 )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo '<br/>' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$this -> draw ( 'CurrentValue' , $attribute , $i );
}
}
/**
* Draw the current specific value of an attribute
2019-02-12 14:52:01 -05:00
* @ param $attribute
* @ param $i
2019-02-08 13:44:52 -05:00
*/
final protected function drawCurrentValueAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
if ( DEBUGTMPSUB )
{
printf ( ' <small>[%s]</small>' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
echo htmlspecialchars ( $attribute -> getValue ( $i ));
}
/**
* Draw a input value for an attribute - used in a form .
2019-02-12 14:52:01 -05:00
* @ param $attribute
* @ param $i
2019-02-08 13:44:52 -05:00
*/
protected function drawFormValueAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
if ( DEBUGTMPSUB )
{
printf ( ' <small>[%s]</small>' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
if ( $this -> getServer () -> isReadOnly () || $attribute -> isReadOnly ()
|| ( $attribute -> isRDN () && $this -> template -> getType () != 'creation' && $i < count ( $attribute -> getValues ())))
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'FormReadOnlyValue' , $attribute , $i );
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'FormReadWriteValue' , $attribute , $i );
}
2019-02-08 13:44:52 -05:00
# Show the ADDVALUE DIV if the attribute can have more values, and we have rendered the last value
if ( $attribute -> haveMoreValues () && $attribute -> getValueCount () == $i + 1 )
2019-02-12 14:57:50 -05:00
{
printf ( '<div id="ajADDVALUE%s"></div>' , $attribute -> getName ());
}
2019-02-08 13:44:52 -05:00
if ( $attribute -> getPostValue ())
2019-02-12 14:57:50 -05:00
{
printf ( '<input type="hidden" name="post_value[%s][]" value="%s"/>' , $attribute -> getName (), $i );
}
2019-02-08 13:44:52 -05:00
}
protected function drawFormReadOnlyValueAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
printf ( '<input type="text" class="roval" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" readonly="readonly" />' ,
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $val ));
}
protected function drawFormReadWriteValueAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
if ( $attribute -> getHelper () || $attribute -> getVerify ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo '<table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
printf ( '<input type="text" class="value" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" %s%s %s %s/>' ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $val ),
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' ,
( $attribute -> getSize () > 0 ) ? sprintf ( 'size="%s"' , $attribute -> getSize ()) : '' ,
( $attribute -> getMaxLength () > 0 ) ? sprintf ( 'maxlength="%s"' , $attribute -> getMaxLength ()) : '' );
if ( $attribute -> getHelper ()) {
echo '</td><td valign="top">' ;
$this -> draw ( 'AttributeHelper' , $attribute , $i );
echo '</td></tr>' ;
} elseif ( $attribute -> getVerify ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo '</td></tr>' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
if ( $attribute -> getVerify ()) {
printf ( '<tr><td><input type="text" class="value" name="new_values_verify[%s][%s]" id="new_values_verify_%s_%s" value="" %s %s/>' ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
( $attribute -> getSize () > 0 ) ? sprintf ( 'size="%s"' , $attribute -> getSize ()) : '' ,
( $attribute -> getMaxLength () > 0 ) ? sprintf ( 'maxlength="%s"' , $attribute -> getMaxLength ()) : '' );
echo '</td><td valign="top">' ;
printf ( '(%s)' , _ ( 'confirm' ));
echo '</td></tr>' ;
}
if ( $attribute -> getHelper () || $attribute -> getVerify ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo '</table>' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
/**
* Draw specific hidden binary attribute
2019-02-12 14:52:01 -05:00
* @ param $attribute
* @ param $i
2019-02-08 13:44:52 -05:00
*/
final protected function drawHiddenValueBinaryAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
printf ( '<input type="hidden" name="new_values[%s][%s]" value="%s" />' ,
htmlspecialchars ( $attribute -> getName ()), $i , base64_encode ( $val ));
}
final protected function drawOldValueBinaryAttribute ( $attribute , $i ) {
# If we dont have a value, we'll just return;
if ( ! $attribute -> getOldValue ( $i ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
printf ( '<small>[%s]</small>' , _ ( 'Binary Value' ));
}
final protected function drawCurrentValueBinaryAttribute ( $attribute , $i ) {
printf ( '<small>[%s]</small>' , _ ( 'Binary Value' ));
if ( in_array ( $attribute -> getName (), array ( 'objectsid' )))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
printf ( '<small> (%s)</small>' , binSIDtoText ( $attribute -> getValue ( 0 )));
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
protected function drawFormReadOnlyValueBinaryAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$this -> draw ( 'CurrentValue' , $attribute , $i );
echo '<br/><br/>' ;
$href = sprintf ( 'download_binary_attr.php?server_id=%s&dn=%s&attr=%s&index=%s' ,
$this -> getServerID (), rawurlencode ( $this -> template -> getDN ()), $attribute -> getName (), $i );
printf ( '<a href="%s"><img src="%s/save.png" alt="Save" /> %s</a>' ,
htmlspecialchars ( $href ), IMGDIR , _ ( 'download value' ));
echo '<br/>' ;
}
protected function drawFormReadWriteValueBinaryAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
if ( $attribute -> getValue ( $i )) {
$this -> draw ( 'FormReadOnlyValue' , $attribute , $i );
if ( ! $attribute -> isReadOnly () && $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'script' , 'delete_attr' ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
printf ( '<a href="javascript:deleteAttribute(\'%s\',\'%s\',\'%s\');" style="color:red;"><img src="%s/trash.png" alt="Trash" /> %s</a>' ,
2019-02-12 14:57:50 -05:00
$attribute -> getName (), $attribute -> getFriendlyName (), $i , IMGDIR , _ ( 'delete attribute' ));
}
2019-02-08 13:44:52 -05:00
} else {
printf ( '<input type="file" class="value" name="new_values[%s][%s]" id="new_values_%s_%s" value="" %s%s %s %s/><br />' ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' ,
( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' ,
( $attribute -> getMaxLength () > 0 ) ? 'maxlength="' . $attribute -> getMaxLength () . '"' : '' );
}
}
protected function drawFormReadWriteValueDateAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
echo '<span style="white-space: nowrap;">' ;
printf ( '<input type="text" class="value" id="new_values_%s_%s" name="new_values[%s][%s]" value="%s" %s%s %s %s/> ' ,
$attribute -> getName (), $i ,
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $val ),
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' ,
( $attribute -> getSize () > 0 ) ? sprintf ( 'size="%s"' , $attribute -> getSize ()) : '' ,
( $attribute -> getMaxLength () > 0 ) ? sprintf ( 'maxlength="%s"' , $attribute -> getMaxLength ()) : '' );
$this -> draw ( 'SelectorPopup' , $attribute , $i );
echo '</span>' . " \n " ;
}
protected function drawFormReadWriteValueDnAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
if ( $attribute -> getHelper ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$input_name = sprintf ( 'new_values[%s][%s]' , htmlspecialchars ( $attribute -> getName ()), $i );
$id = sprintf ( 'new_values_%s_%s' , htmlspecialchars ( $attribute -> getName ()), $i );
printf ( '<span style="white-space: nowrap;"><input type="text" class="value" name="%s" id="%s" value="%s" %s%s %s %s/> ' ,
$input_name , $id , htmlspecialchars ( $val ),
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $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' , $id , false );
echo '</span>' ;
if ( $attribute -> getHelper ()) {
echo '</td><td valign="top">' ;
$this -> draw ( 'Helper' , $attribute , $i );
echo '</td></tr></table>' ;
}
echo " \n " ;
}
protected function drawFormReadWriteValueGidAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$this -> drawFormReadWriteValueAttribute ( $attribute , $i );
$server = $this -> getServer ();
$val = $attribute -> getValue ( $i );
# If this is a gidNumber on a non-PosixGroup entry, lookup its name and description for convenience
if ( $this -> template -> getDN () && ! in_array_ignore_case ( 'posixGroup' , $this -> getServer () -> getDNAttrValue ( $this -> template -> getDN (), 'objectclass' ))) {
$query [ 'filter' ] = sprintf ( '(&(objectClass=posixGroup)(gidNumber=%s))' , $val );
$query [ 'attrs' ] = array ( 'dn' , 'description' );
# Reorganise our base, so that our base is first
$bases = array_unique ( array_merge ( array ( $server -> getContainerTop ( $this -> template -> getDN ())), $server -> getBaseDN ()));
# Search our bases, until we find a match.
foreach ( $bases as $base ) {
$query [ 'base' ] = $base ;
$group = $this -> getServer () -> query ( $query , null );
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' ,
$this -> getServerID (), rawurlencode ( $group_dn ));
echo '<small>' ;
printf ( '<a href="%s">%s</a>' , htmlspecialchars ( $href ), $group_name );
$description = isset ( $group [ 'description' ]) ? $group [ 'description' ] : null ;
if ( is_array ( $description ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
foreach ( $description as $item )
2019-02-12 14:57:50 -05:00
{
printf ( ' (%s)' , $item );
}
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
printf ( ' (%s)' , $description );
}
2019-02-08 13:44:52 -05:00
echo '</small>' ;
break ;
}
}
}
}
/**
* Draw a Jpeg Attribute
2019-02-12 14:52:01 -05:00
* @ param $attribute
* @ param $i
2019-02-08 13:44:52 -05:00
*/
final protected function drawOldValueJpegAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
if ( DEBUGTMPSUB )
{
printf ( ' <small>[%s]</small>' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
# If we dont have a value, we'll just return;
if ( ! $attribute -> getOldValue ( $i ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
draw_jpeg_photo ( $this -> getServer (), $this -> template -> getDN (), $attribute -> getName (), $i , false , false );
}
/**
* Draw a Jpeg Attribute
2019-02-12 14:52:01 -05:00
* @ param $attribute
* @ param $i
2019-02-08 13:44:52 -05:00
*/
final protected function drawCurrentValueJpegAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
if ( DEBUGTMPSUB )
{
printf ( ' <small>[%s]</small>' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
# If we dont have a value, we'll just return;
if ( ! $attribute -> getValue ( $i ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
# If the attribute is modified, the new value needs to be stored in a session variable for the draw_jpeg_photo callback.
if ( $attribute -> hasBeenModified ()) {
$_SESSION [ 'tmp' ][ $attribute -> getName ()][ $i ] = $attribute -> getValue ( $i );
draw_jpeg_photo ( null , $this -> template -> getDN (), $attribute -> getName (), $i , false , false );
} else
2019-02-12 14:57:50 -05:00
{
draw_jpeg_photo ( $this -> getServer (), $this -> template -> getDN (), $attribute -> getName (), $i , FALSE , FALSE );
}
2019-02-08 13:44:52 -05:00
}
protected function drawFormReadOnlyValueJpegAttribute ( $attribute , $i ) {
$this -> draw ( 'HiddenValue' , $attribute , $i );
$_SESSION [ 'tmp' ][ $attribute -> getName ()][ $i ] = $attribute -> getValue ( $i );
draw_jpeg_photo ( null , $this -> template -> getDN (), $attribute -> getName (), $i , false , false );
}
protected function drawFormReadOnlyValueMultiLineAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
printf ( '<textarea class="roval" rows="%s" cols="%s" name="new_values[%s][%s]" id="new_values_%s_%s" readonly="readonly">%s</textarea>' ,
( $attribute -> getRows () > 0 ) ? $attribute -> getRows () : 5 ,
( $attribute -> getCols () > 0 ) ? $attribute -> getCols () : 100 ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
$val );
}
protected function drawFormReadWriteValueMultiLineAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
printf ( '<textarea class="value" rows="%s" cols="%s" name="new_values[%s][%s]" id="new_values_%s_%s" %s%s>%s</textarea>' ,
( $attribute -> getRows () > 0 ) ? $attribute -> getRows () : 5 ,
( $attribute -> getCols () > 0 ) ? $attribute -> getCols () : 100 ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' ,
$val );
}
protected function drawFormValueObjectClassAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
/* It seems that openLDAP allows us to remove additional structural objectclasses
however other LDAP servers , dont remove them ( even if we ask them to ) . */
# Do we have our internal attributes.
$internal = $this -> template -> getAttribute ( 'structuralobjectclass' );
if ( $internal ) {
$structural = in_array_ignore_case ( $val , $internal -> getValues ());
# We'll work it out the traditional way.
} else {
# If this schema structural?
$schema_object = ( $val ) ? $this -> getServer () -> getSchemaObjectClass ( $val ) : false ;
$structural = ( is_object ( $schema_object ) && $schema_object -> getType () == 'structural' );
}
if ( $structural ) {
$this -> draw ( 'FormReadOnlyValue' , $attribute , $i );
printf ( ' <small>(<acronym title="%s">%s</acronym>)</small>' ,
_ ( 'This is a structural ObjectClass and cannot be removed.' ),
_ ( 'structural' ));
} else
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'FormReadWriteValue' , $attribute , $i );
}
2019-02-08 13:44:52 -05:00
}
protected function getAutoPostPasswordAttribute ( $attribute , $i ) {
# If the password is already encoded, then we'll return
if ( preg_match ( '/^\{.+\}.+/' , $attribute -> getValue ( $i )))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$attribute -> setPostValue ( array ( 'function' => 'PasswordEncrypt' , 'args' => sprintf ( '%%enc%%;%%%s%%' , $attribute -> getName ())));
$this -> get ( 'Post' , $attribute , $i );
}
protected function drawOldValuePasswordAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
if ( DEBUGTMPSUB )
{
printf ( ' <small>[%s]</small>' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getOldValue ( $i );
if ( obfuscate_password_display ( get_enc_type ( $val )))
2019-02-12 14:57:50 -05:00
{
echo str_repeat ( '*' , 16 );
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo nl2br ( htmlspecialchars ( $attribute -> getOldValue ( $i )));
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
final protected function drawCurrentValuePasswordAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
if ( DEBUGTMPSUB )
{
printf ( ' <small>[%s]</small>' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$val = $attribute -> getValue ( $i );
if ( obfuscate_password_display ( get_enc_type ( $val )))
2019-02-12 14:57:50 -05:00
{
echo str_repeat ( '*' , 16 );
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo nl2br ( htmlspecialchars ( $attribute -> getValue ( $i )));
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
}
protected function drawFormReadOnlyValuePasswordAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$server = $this -> getServer ();
$val = $attribute -> getValue ( $i );
if ( trim ( $val ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$enc_type = get_enc_type ( $val );
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
$enc_type = $server -> getValue ( 'appearance' , 'password_hash' );
}
2019-02-08 13:44:52 -05: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="readonly" /><br />' ,
( $obfuscate_password ? 'password' : 'text' ),
htmlspecialchars ( $attribute -> getName ()), $i , htmlspecialchars ( $attribute -> getName ()),
$i , htmlspecialchars ( $val ),( $attribute -> getSize () > 0 ) ? 'size="' . $attribute -> getSize () . '"' : '' );
if ( trim ( $val ))
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'CheckLink' , $attribute , 'new_values_' . htmlspecialchars ( $attribute -> getName ()) . '_' . $i );
}
2019-02-08 13:44:52 -05:00
}
protected function drawFormReadWriteValuePasswordAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$server = $this -> getServer ();
$val = $attribute -> getValue ( $i );
$enc_type = get_enc_type ( $val );
# Set the default hashing type if the password is blank (must be newly created)
if ( trim ( $val ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$enc_type = get_enc_type ( $val );
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
$enc_type = $server -> getValue ( 'appearance' , 'password_hash' );
}
2019-02-08 13:44:52 -05: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 );
printf ( '<input type="%s" class="value" name="new_values[%s][%s]" id="%s" value="%s" %s%s %s %s/>' ,
( $obfuscate_password ? 'password' : 'text' ),
htmlspecialchars ( $attribute -> getName ()), $i , $id ,
htmlspecialchars ( $val ),
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' ,
( $attribute -> getSize () > 0 ) ? sprintf ( 'size="%s"' , $attribute -> getSize ()) : '' ,
( $attribute -> getMaxLength () > 0 ) ? sprintf ( 'maxlength="%s"' , $attribute -> getMaxLength ()) : '' );
echo '</td><td valign="top">' ;
if ( $attribute -> getHelper ())
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'Helper' , $attribute , $i );
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
$this -> draw ( 'DefaultHelper' , $attribute , $i );
}
2019-02-08 13:44:52 -05:00
echo '</td></tr><tr><td valign="top">' ;
if ( $attribute -> getVerify () && $obfuscate_password ) {
printf ( '<input type="password" class="value" name="new_values_verify[%s][%s]" id="new_values_verify_%s_%s" value="" %s %s/>' ,
htmlspecialchars ( $attribute -> getName ()), $i ,
htmlspecialchars ( $attribute -> getName ()), $i ,
( $attribute -> getSize () > 0 ) ? sprintf ( 'size="%s"' , $attribute -> getSize ()) : '' ,
( $attribute -> getMaxLength () > 0 ) ? sprintf ( 'maxlength="%s"' , $attribute -> getMaxLength ()) : '' );
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 drawFormReadWriteValueSelectionAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
if ( $attribute -> isMultiple ()) {
# For multiple selection, we draw the component only one time
if ( $i > 0 )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$selected = array ();
$vals = $attribute -> getValues ();
$j = 0 ;
if ( ! $vals && ! is_null ( $attribute -> getDefault ()) && ! is_array ( $vals = $attribute -> getDefault ()))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$vals = array ( $attribute -> getDefault ());
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
if (( $attribute -> getSize () > 0 ) && ( $attribute -> getSize () < $attribute -> getOptionCount ())) {
printf ( '<select name="new_values[%s][]" size="%s" multiple="multiple">' ,
htmlspecialchars ( $attribute -> getName ()), $attribute -> getSize ());
foreach ( $attribute -> getSelection () as $value => $description ) {
if ( in_array ( $value , $vals ))
2019-02-12 14:57:50 -05:00
{
$selected [ $value ] = TRUE ;
}
2019-02-08 13:44:52 -05:00
printf ( '<option id="new_values_%s_%s" value="%s" onmouseDown="focus_%s(this);" onclick="blur_%s(this);" %s>%s</option>' ,
htmlspecialchars ( $attribute -> getName ()), $j ++ ,
$value , htmlspecialchars ( $attribute -> getName ()), htmlspecialchars ( $attribute -> getName ()),
isset ( $selected [ $value ]) ? 'selected="selected"' : '' , $description );
echo " \n " ;
}
foreach ( $vals as $val ) {
if ( ! isset ( $selected [ $val ]))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
printf ( '<option id="new_values_%s_%s" value="%s" onmousedown="focus_%s(this);" onclick="blur_%s(this);" selected="selected">%s</option>' ,
2019-02-12 14:57:50 -05:00
htmlspecialchars ( $attribute -> getName ()), $j ++ ,
$val , htmlspecialchars ( $attribute -> getName ()),
htmlspecialchars ( $attribute -> getName ()), $val );
}
2019-02-08 13:44:52 -05:00
echo " \n " ;
}
echo '</select>' ;
} else {
echo '<table cellspacing="0" cellpadding="0" border="0">' ;
// For checkbox items, we need to render a blank entry, so that we detect an all-unselect situation
printf ( '<tr><td colspan="2"><input type="hidden" id="new_values_%s_%s" name="new_values[%s][]" value="%s"/></td></tr>' ,
htmlspecialchars ( $attribute -> getName ()), $j ++ ,
htmlspecialchars ( $attribute -> getName ()), '' );
foreach ( $attribute -> getSelection () as $value => $description ) {
if ( in_array ( $value , $vals ))
2019-02-12 14:57:50 -05:00
{
$selected [ $value ] = TRUE ;
}
2019-02-08 13:44:52 -05:00
printf ( '<tr><td><input type="checkbox" id="new_values_%s_%s" name="new_values[%s][]" value="%s" %s%s %s/></td><td><span style="white-space: nowrap;"> %s</span></td></tr>' ,
htmlspecialchars ( $attribute -> getName ()), $j ++ ,
htmlspecialchars ( $attribute -> getName ()), $value ,
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' ,
isset ( $selected [ $value ]) ? 'checked="checked"' : '' ,
$description );
}
foreach ( $vals as $val )
2019-02-12 14:57:50 -05:00
{
if ( ! isset ( $selected [ $val ]))
{
2019-02-08 13:44:52 -05:00
printf ( '<tr><td><input type="checkbox" id="new_values_%s_%s" name="new_values[%s][]" value="%s" %s%s checked="checked"/></td><td><span style="white-space: nowrap;"> %s</span></td></tr>' ,
2019-02-12 14:57:50 -05:00
htmlspecialchars ( $attribute -> getName ()), $j ++ ,
htmlspecialchars ( $attribute -> getName ()), $val ,
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' ,
2019-02-08 13:44:52 -05:00
$val );
2019-02-12 14:57:50 -05:00
}
}
2019-02-08 13:44:52 -05:00
echo '</table>' ;
}
# This is a single value attribute
} else {
2019-02-12 15:34:47 -05:00
$val = $attribute -> getValue ( $i ) ? : $attribute -> getDefault ();
2019-02-08 13:44:52 -05:00
if ( $attribute -> getHelper ())
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">' ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$found = false ;
$empty_value = false ;
# If we are a required attribute, and the selection is blank, then the user cannot submit this form.
if ( $attribute -> isRequired () && ! count ( $attribute -> getSelection ()))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
system_message ( array (
2019-02-12 14:57:50 -05:00
'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 ( FALSE )),
'type' => 'warn' ));
}
2019-02-08 13:44:52 -05:00
printf ( '<select name="new_values[%s][]" id="new_values_%s_%s" %s%s>' ,
htmlspecialchars ( $attribute -> getName ()),
htmlspecialchars ( $attribute -> getName ()), $i ,
$attribute -> needJS ( 'focus' ) ? sprintf ( 'onfocus="focus_%s(this);" ' , $attribute -> getName ()) : '' ,
$attribute -> needJS ( 'blur' ) ? sprintf ( 'onblur="blur_%s(this);" ' , $attribute -> getName ()) : '' );
foreach ( $attribute -> getSelection () as $value => $description ) {
printf ( '<option value="%s" %s>%s</option>' , $value ,
(( strcasecmp ( $value , $val ) == 0 ) && $found = true ) ? 'selected="selected"' : '' , $description );
if ( $value == '' )
2019-02-12 14:57:50 -05:00
{
$empty_value = TRUE ;
}
2019-02-08 13:44:52 -05:00
echo " \n " ;
}
if ( ! $found ) {
printf ( '<option value="%s" selected="selected">%s</option>' , $val , $val == '' ? ' ' : $val );
if ( $val == '' )
2019-02-12 14:57:50 -05:00
{
$empty_value = TRUE ;
}
2019-02-08 13:44:52 -05:00
echo " \n " ;
}
if (( strlen ( $val ) > 0 ) && ! $empty_value && $this -> template -> getDN ()) {
printf ( '<option value="">(%s)</option>' , _ ( 'none, remove value' ));
echo " \n " ;
}
echo '</select>' ;
if ( $attribute -> getHelper ()) {
echo '</td><td valign="top">' ;
$this -> draw ( 'Helper' , $attribute , $i );
echo '</td></tr></table>' ;
}
}
}
/**
* Takes a shadow * attribute and returns the date as an integer .
*
* @ param array Attribute objects
* @ param string A shadow attribute name
*/
private function shadow_date ( $attribute ) {
if ( DEBUG_ENABLED && (( $fargs = func_get_args ()) || $fargs = 'NOARGS' ))
2019-02-12 14:57:50 -05:00
{
debug_log ( 'Entered (%%)' , 129 , 0 , __FILE__ , __LINE__ , __METHOD__ , $fargs );
}
2019-02-08 13:44:52 -05:00
$shadowattr = array ();
$shadowattr [ 'lastchange' ] = $this -> template -> getAttribute ( 'shadowlastchange' );
$shadowattr [ 'max' ] = $this -> template -> getAttribute ( 'shadowmax' );
$shadow = array ();
$shadow [ 'lastchange' ] = $shadowattr [ 'lastchange' ] ? $shadowattr [ 'lastchange' ] -> getValue ( 0 ) : null ;
$shadow [ 'max' ] = $shadowattr [ 'max' ] ? $shadowattr [ 'max' ] -> getValue ( 0 ) : null ;
if (( $attribute -> getName () == 'shadowlastchange' ) && $shadow [ 'lastchange' ])
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$shadow_date = $shadow [ 'lastchange' ];
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
elseif (( $attribute -> getName () == 'shadowmax' ) && ( $shadow [ 'max' ] > 0 ) && $shadow [ 'lastchange' ])
2019-02-12 14:57:50 -05:00
{
$shadow_date = $shadow [ 'lastchange' ] + $shadow [ 'max' ];
}
2019-02-08 13:44:52 -05:00
elseif (( $attribute -> getName () == 'shadowwarning' ) && ( $attribute -> getValue ( 0 ) > 0 )
&& $shadow [ 'lastchange' ] && $shadow [ 'max' ] && $shadow [ 'max' ] > 0 )
2019-02-12 14:57:50 -05:00
{
$shadow_date = $shadow [ 'lastchange' ] + $shadow [ 'max' ] - $attribute -> getValue ( 0 );
}
2019-02-08 13:44:52 -05:00
elseif (( $attribute -> getName () == 'shadowinactive' ) && ( $attribute -> getValue ( 0 ) > 0 )
&& $shadow [ 'lastchange' ] && $shadow [ 'max' ] && $shadow [ 'max' ] > 0 )
2019-02-12 14:57:50 -05:00
{
$shadow_date = $shadow [ 'lastchange' ] + $shadow [ 'max' ] + $attribute -> getValue ( 0 );
}
2019-02-08 13:44:52 -05:00
elseif (( $attribute -> getName () == 'shadowmin' ) && ( $attribute -> getValue ( 0 ) > 0 ) && $shadow [ 'lastchange' ])
2019-02-12 14:57:50 -05:00
{
$shadow_date = $shadow [ 'lastchange' ] + $attribute -> getValue ( 0 );
}
2019-02-08 13:44:52 -05:00
elseif (( $attribute -> getName () == 'shadowexpire' ) && ( $attribute -> getValue ( 0 ) > 0 ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
$shadow_date = $shadowattr -> getValue ( 0 );
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
# Couldn't interpret the shadow date (could be 0 or -1 or something)
else
2019-02-12 14:57:50 -05:00
{
return FALSE ;
}
2019-02-08 13:44:52 -05:00
return $shadow_date * 24 * 3600 ;
}
protected function drawShadowDateShadowAttribute ( $attribute ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$shadow_before_today_attrs = arrayLower ( $attribute -> shadow_before_today_attrs );
$shadow_after_today_attrs = arrayLower ( $attribute -> shadow_after_today_attrs );
$shadow_date = $this -> shadow_date ( $attribute );
if ( ! $shadow_date )
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
return ;
2019-02-12 14:57:50 -05:00
}
2019-02-08 13:44:52 -05:00
$today = date ( 'U' );
echo '<br/><small>' ;
if (( $today < $shadow_date ) && in_array ( strtolower ( $attribute -> getName ()), $shadow_before_today_attrs ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
printf ( '<span style="color:red">(%s)</span>' ,
2019-02-12 14:57:50 -05:00
strftime ( $_SESSION [ APPCONFIG ] -> getValue ( 'appearance' , 'date' ), $shadow_date ));
}
2019-02-08 13:44:52 -05:00
elseif (( $today > $shadow_date ) && in_array ( strtolower ( $attribute -> getName ()), $shadow_after_today_attrs ))
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
printf ( '<span style="color:red">(%s)</span>' ,
2019-02-12 14:57:50 -05:00
strftime ( $_SESSION [ APPCONFIG ] -> getValue ( 'appearance' , 'date' ), $shadow_date ));
}
2019-02-08 13:44:52 -05:00
else
2019-02-12 14:57:50 -05:00
{
2019-02-08 13:44:52 -05:00
printf ( '(%s)' ,
2019-02-12 14:57:50 -05:00
strftime ( $_SESSION [ APPCONFIG ] -> getValue ( 'appearance' , 'date' ), $shadow_date ));
}
2019-02-08 13:44:52 -05:00
echo '</small><br />' ;
}
protected function drawFormReadOnlyValueShadowAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$this -> drawFormReadOnlyValueAttribute ( $attribute , $i );
$this -> draw ( 'ShadowDate' , $attribute );
}
protected function drawFormReadWriteValueShadowAttribute ( $attribute , $i ) {
2019-02-12 14:57:50 -05:00
if ( DEBUGTMP )
{
printf ( '<font size=-2>%s</font><br />' , __METHOD__ );
}
2019-02-08 13:44:52 -05:00
$this -> drawFormReadWriteValueAttribute ( $attribute , $i );
$this -> draw ( 'ShadowDate' , $attribute );
}
}
2019-02-12 14:52:01 -05:00