phpldapadmin/lib/template_functions.php

1046 lines
34 KiB
PHP
Raw Normal View History

2009-06-30 09:29:51 +00:00
<?php
2009-06-30 11:52:55 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/template_functions.php,v 1.43.2.8 2008/12/12 12:20:23 wurley Exp $
2009-06-30 09:29:51 +00:00
/**
* Classes and functions for the template engine.ation and capability
*
* @author The phpLDAPadmin development team
* @package phpLDAPadmin
* @todo: Should be able to auto figure what type of entry we are asking for ie: DN entry.
*/
class xml2array {
var $stack = array();
var $stack_ref;
var $arrOutput = array();
var $resParser;
var $strXmlData;
function push_pos(&$pos) {
$this->stack[count($this->stack)] = &$pos;
$this->stack_ref = &$pos;
}
function pop_pos() {
unset($this->stack[count($this->stack) - 1]);
$this->stack_ref = &$this->stack[count($this->stack) - 1];
}
function parse($file) {
$f = fopen($file,'r');
$strInputXML = fread($f,filesize($file));
fclose($f);
$this->resParser = xml_parser_create();
xml_set_object($this->resParser,$this);
2009-06-30 10:26:08 +00:00
xml_set_element_handler($this->resParser,'tagOpen','tagClosed');
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
xml_set_character_data_handler($this->resParser,'tagData');
2009-06-30 09:29:51 +00:00
$this->push_pos($this->arrOutput);
$this->strXmlData = xml_parse($this->resParser,$strInputXML);
if (! $this->strXmlData)
2009-06-30 11:52:55 +00:00
die(sprintf('XML error: %s at line %d in file %s',
2009-06-30 09:29:51 +00:00
xml_error_string(xml_get_error_code($this->resParser)),
2009-06-30 11:52:55 +00:00
xml_get_current_line_number($this->resParser),
$file));
2009-06-30 09:29:51 +00:00
xml_parser_free($this->resParser);
return $this->arrOutput;
}
function tagOpen($parser,$name,$attrs) {
$name = strtolower($name);
if (isset($this->stack_ref[$name])) {
if (! isset($this->stack_ref[$name][0])) {
$tmp = $this->stack_ref[$name];
unset($this->stack_ref[$name]);
$this->stack_ref[$name][0] = $tmp;
}
$cnt = count($this->stack_ref[$name]);
$this->stack_ref[$name][$cnt] = array();
if (isset($attrs))
$this->stack_ref[$name][$cnt] = $attrs;
$this->push_pos($this->stack_ref[$name][$cnt]);
} else {
$this->stack_ref[$name]=array();
2009-06-30 09:40:37 +00:00
if (isset($attrs))
2009-06-30 09:29:51 +00:00
$this->stack_ref[$name]=$attrs;
$this->push_pos($this->stack_ref[$name]);
}
}
function tagData($parser,$tagData) {
if (trim($tagData) != '') {
if (isset($this->stack_ref['#text']))
$this->stack_ref['#text'] .= $tagData;
else
$this->stack_ref['#text'] = $tagData;
}
}
function tagClosed($parser,$name) {
$this->pop_pos();
}
}
class Templates {
2009-06-30 10:41:18 +00:00
var $_creation_template = array();
2009-06-30 10:46:00 +00:00
var $_editing_template = array();
2009-06-30 10:26:08 +00:00
var $_js_hash = array();
2009-06-30 09:29:51 +00:00
function Templates($server_id) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Entered with ()',5,__FILE__,__LINE__,__METHOD__);
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
if ($this->_creation_template = get_cached_item($server_id,'template','creation')) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Using CACHED [%s]',5,__FILE__,__LINE__,__METHOD__,'templates');
2009-06-30 09:29:51 +00:00
2009-06-30 09:40:37 +00:00
} else {
2009-06-30 10:46:00 +00:00
$dir = opendir(TMPLDIR.'creation');
2009-06-30 09:29:51 +00:00
$this->template_num = 0;
while( ( $file = readdir( $dir ) ) !== false ) {
if (! preg_match('/.xml$/',$file)) continue;
2009-06-30 11:52:55 +00:00
if ($_SESSION[APPCONFIG]->GetValue('appearance','custom_templates_only')
2009-06-30 11:46:44 +00:00
&& ! preg_match('/^custom_/',$file))
continue;
2009-06-30 09:29:51 +00:00
$objXML = new xml2array();
2009-06-30 10:46:00 +00:00
$xmldata = $objXML->parse(TMPLDIR.'creation/'.$file);
2009-06-30 09:29:51 +00:00
$template_name = preg_replace('/.xml$/','',$file);
2009-06-30 10:46:00 +00:00
$this->_creation_template[$template_name] = array();
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$this->storeTemplate($this->_creation_template[$template_name],$xmldata);
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:41:18 +00:00
masort($this->_creation_template,'title');
set_cached_item($server_id,'template','creation',$this->_creation_template);
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:46:00 +00:00
if ($this->_editing_template = get_cached_item($server_id,'template','editing')) {
if (DEBUG_ENABLED)
debug_log('Using CACHED [%s]',5,__FILE__,__LINE__,__METHOD__,'templates');
} else {
$dir = opendir(TMPLDIR.'modification');
$this->template_num = 0;
while (($file = readdir($dir)) !== false) {
if (! preg_match('/.xml$/',$file))
continue;
2009-06-30 11:52:55 +00:00
if ($_SESSION[APPCONFIG]->GetValue('appearance','custom_templates_only')
2009-06-30 11:50:46 +00:00
&& ! preg_match('/^custom_/',$file))
continue;
2009-06-30 10:46:00 +00:00
$objXML = new xml2array();
$xmldata = $objXML->parse(TMPLDIR.'modification/'.$file);
$template_name = preg_replace('/.xml$/','',$file);
$this->_editing_template[$template_name] = array();
$this->storeTemplate($this->_editing_template[$template_name], $xmldata);
}
masort($this->_creation_template,'title');
set_cached_item($server_id,'template','editing',$this->_editing_template);
}
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:46:00 +00:00
function storeTemplate(&$template,$xmldata) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Entered with (%s,%s)',5,__FILE__,__LINE__,__METHOD__,$template,$xmldata);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
global $ldapserver;
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
$template['objectclass'] = array();
2009-06-30 09:29:51 +00:00
foreach ($xmldata['template'] as $xml_key => $xml_value) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Foreach loop Key [%s] Value [%s]',4,__FILE__,__LINE__,__METHOD__,$xml_key,is_array($xml_value));
2009-06-30 09:29:51 +00:00
switch ($xml_key) {
2009-06-30 10:26:08 +00:00
2009-06-30 09:29:51 +00:00
# Build our object Classes from the DN and Template.
case ('objectclasses') :
if (isset($xmldata['template']['objectclasses']) && is_array($xmldata['template']['objectclasses'])) {
foreach ($xmldata['template']['objectclasses']['objectclass'] as $index => $details) {
if (is_numeric($index)) {
2009-06-30 10:46:00 +00:00
# XML files with only 1 objectClass dont have a numeric index.
2009-06-30 10:26:08 +00:00
if ($schema = $ldapserver->getSchemaObjectClass($details['ID'])) {
# If we havent recorded this objectclass already, do so now.
2009-06-30 10:41:18 +00:00
if (! isset($template['objectclass']) ||
! in_array($schema->getName(),$template['objectclass'])) {
2009-06-30 10:26:08 +00:00
2009-06-30 10:41:18 +00:00
$template['objectclass'][] = $schema->getName();
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 objectClass doesnt exist.
} else {
}
2009-06-30 09:29:51 +00:00
} else {
2009-06-30 10:26:08 +00:00
if ($schema = $ldapserver->getSchemaObjectClass($details)) {
2009-06-30 10:41:18 +00:00
if (! isset($template['objectclass']) ||
2009-06-30 10:46:00 +00:00
//! in_array($details,$template['objectclass'])) {
! in_array($schema->getName(),$template['objectclass'])) {
2009-06-30 10:41:18 +00:00
$template['objectclass'][] = $schema->getName();
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 objectClass doesnt exist.
} else {
}
2009-06-30 09:29:51 +00:00
}
}
}
break;
# Build our attribute list from the DN and Template.
case ('attributes') :
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Case [%s]',4,__FILE__,__LINE__,__METHOD__,'attributes');
2009-06-30 09:29:51 +00:00
if (isset($xmldata['template']['attributes']) && is_array($xmldata['template']['attributes'])) {
2009-06-30 10:41:18 +00:00
$template['attribute'] = array();
2009-06-30 09:29:51 +00:00
foreach ($xmldata['template']['attributes'] as $tattrs) {
foreach ($tattrs as $index => $attr_details) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Foreach tattrs Key [%s] Value [%s]',4,__FILE__,__LINE__,__METHOD__,
$index,serialize($attr_details));
2009-06-30 09:29:51 +00:00
# Single attribute XML files are not indexed.
2009-06-30 09:40:37 +00:00
if (is_numeric($index)) {
2009-06-30 10:26:08 +00:00
if ($attr = $ldapserver->getSchemaAttribute($attr_details['ID']))
2009-06-30 10:41:18 +00:00
$template['attribute'][$attr->getName()] = $this->_parseXML($index,$attr_details);
2009-06-30 09:29:51 +00:00
} else {
2009-06-30 09:41:11 +00:00
if (! strcmp($index,'ID'))
continue;
2009-06-30 10:26:08 +00:00
if ($attr = $ldapserver->getSchemaAttribute($tattrs['ID'])) {
foreach ($attr_details as $key => $values) {
if (is_array($values) && isset($values['ID'])) {
2009-06-30 10:41:18 +00:00
$template['attribute'][$attr->getName()][$index]['_KEY:'.$values['ID']] = $this->_parseXML($key,$values);
2009-06-30 10:46:00 +00:00
2009-06-30 10:26:08 +00:00
} elseif (is_array($values) && isset($values['#text'])) {
2009-06-30 10:41:18 +00:00
$template['attribute'][$attr->getName()][$index][] = $values['#text'];
2009-06-30 10:26:08 +00:00
} else {
2009-06-30 10:41:18 +00:00
$template['attribute'][$attr->getName()][$index] = $this->_parseXML($key,$values);
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:40:37 +00:00
}
2009-06-30 09:29:51 +00:00
}
}
}
}
# Do we have an override parameter?
2009-06-30 10:41:18 +00:00
foreach ($template['attribute'] as $key => $data) {
2009-06-30 09:29:51 +00:00
if (isset($data['override'])) {
2009-06-30 10:41:18 +00:00
$template['attribute'][$data['override']] = $data;
unset($template['attribute'][$key]);
$template['attribute'][$key] = $data['override'];
2009-06-30 09:29:51 +00:00
}
}
}
break;
default :
2009-06-30 10:41:18 +00:00
$template[$xml_key] = $xml_value['#text'];
2009-06-30 09:29:51 +00:00
}
}
2009-06-30 10:41:18 +00:00
if (! count($template['objectclass'])) {
$template['invalid'] = 1;
$template['invalid_reason'] = _('ObjectClasses in XML dont exist in LDAP server.');
2009-06-30 10:26:08 +00:00
return;
}
2009-06-30 10:41:18 +00:00
2009-06-30 09:29:51 +00:00
# Collect our structural, must & may attributes.
2009-06-30 10:41:18 +00:00
$template['must'] = array();
$template['may'] = array();
$template['empty_attrs'] = array();
2009-06-30 09:29:51 +00:00
$superclasslist = array();
2009-06-30 10:41:18 +00:00
foreach ($template['objectclass'] as $oclass) {
2009-06-30 09:29:51 +00:00
# If we get some superclasses - then we'll need to go through them too.
$supclass = true;
$enherited = false;
while ($supclass == true) {
2009-06-30 09:40:37 +00:00
$schema_object = $ldapserver->getSchemaObjectClass($oclass);
2009-06-30 09:29:51 +00:00
2009-06-30 09:40:37 +00:00
if ($schema_object->getType() == 'structural' && (! $enherited))
2009-06-30 10:41:18 +00:00
$template['structural'][] = $oclass;
2009-06-30 09:29:51 +00:00
2009-06-30 09:40:37 +00:00
if ($schema_object->getMustAttrs() )
foreach ($schema_object->getMustAttrs() as $index => $detail) {
2009-06-30 10:26:08 +00:00
$objectclassattr = $detail->getName();
2009-06-30 09:40:37 +00:00
2009-06-30 10:46:00 +00:00
// We add the 'objectClass' attribute, only if it's explicitly
// in the template attribute list
if (! in_array($objectclassattr,$template['must'])
&& ((strcasecmp('objectClass',$objectclassattr) != 0)
|| ((strcasecmp('objectClass',$objectclassattr) == 0)
&& isset($template['attribute']['objectClass'])))) {
2009-06-30 09:40:37 +00:00
# Go through the aliases, and ignore any that are already defined.
$ignore = false;
2009-06-30 10:26:08 +00:00
$attr = $ldapserver->getSchemaAttribute($objectclassattr);
2009-06-30 09:40:37 +00:00
foreach ($attr->aliases as $alias) {
2009-06-30 10:41:18 +00:00
if (in_array($alias,$template['must'])) {
2009-06-30 09:40:37 +00:00
$ignore = true;
break;
}
}
if ($ignore)
continue;
2009-06-30 10:41:18 +00:00
if (isset($template['attribute'][$objectclassattr]) &&
! is_array($template['attribute'][$objectclassattr]))
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
$template['must'][] =
$template['attribute'][$objectclassattr];
2009-06-30 09:40:37 +00:00
2009-06-30 09:29:51 +00:00
else
2009-06-30 10:41:18 +00:00
$template['must'][] = $objectclassattr;
2009-06-30 09:29:51 +00:00
}
2009-06-30 09:40:37 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ($schema_object->getMayAttrs())
foreach ($schema_object->getMayAttrs() as $index => $detail) {
$objectclassattr = $detail->getName();
2009-06-30 10:41:18 +00:00
if (! in_array($objectclassattr,$template['may']))
$template['may'][] = $objectclassattr;
2009-06-30 10:26:08 +00:00
}
2009-06-30 09:29:51 +00:00
# Keep a list to objectclasses we have processed, so we dont get into a loop.
$oclass_processed[] = $oclass;
2009-06-30 10:46:00 +00:00
$supoclasses = $schema_object->getSupClasses();
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if (count($supoclasses) || count($superclasslist)) {
foreach ($supoclasses as $supoclass) {
2009-06-30 09:29:51 +00:00
if (! in_array($supoclass,$oclass_processed))
2009-06-30 10:46:00 +00:00
$superclasslist[] = $supoclass;
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:46:00 +00:00
$oclass = array_shift($superclasslist);
2009-06-30 09:29:51 +00:00
if ($oclass)
$enherited = true;
else
$supclass = false;
} else {
$supclass = false;
}
}
}
# Remove any must attributes in the may list.
2009-06-30 10:41:18 +00:00
foreach ($template['may'] as $index => $detail) {
if (in_array($detail,$template['must'])) {
unset($template['may'][$index]);
2009-06-30 09:29:51 +00:00
continue;
}
}
# Remove any attributes not in the xml file and not in the dn.
2009-06-30 10:41:18 +00:00
foreach ($template['may'] as $index => $detail) {
if (isset($template['attribute'])
&& ! isset($template['attribute'][$detail])) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
unset($template['may'][$index]);
2009-06-30 09:29:51 +00:00
continue;
}
if (! isset($attrs[$detail]))
2009-06-30 10:41:18 +00:00
if (isset($template['attribute'][$detail]))
$template['empty_attrs'][$detail] = $template['attribute'][$detail];
2009-06-30 09:29:51 +00:00
else
2009-06-30 10:41:18 +00:00
$template['empty_attrs'][$detail]['display'] = $detail;
2009-06-30 09:29:51 +00:00
else
2009-06-30 10:41:18 +00:00
$template['attrs'][$detail] = $attrs[$detail];
2009-06-30 09:29:51 +00:00
}
# Add the must attrs to the attributes key.
2009-06-30 10:41:18 +00:00
foreach ($template['must'] as $index => $detail) {
2009-06-30 09:29:51 +00:00
if (! isset($attrs[$detail])) {
2009-06-30 10:41:18 +00:00
if (isset($template['attribute'][$detail]))
$template['empty_attrs'][$detail] = $template['attribute'][$detail];
2009-06-30 09:29:51 +00:00
else
2009-06-30 10:41:18 +00:00
$template['empty_attrs'][$detail]['display'] = $detail;
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
$template['empty_attrs'][$detail]['must'] = true;
2009-06-30 09:29:51 +00:00
} else
2009-06-30 10:41:18 +00:00
$template['attrs'][$detail] = $attrs[$detail];
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:46:00 +00:00
# are there attributes defined in templates but not in may/must attributes ?
foreach ($template['attribute'] as $attr => $details) {
if (!isset($template['empty_attrs'][$attr])) $template['empty_attrs'][$attr] = $details;
}
2009-06-30 09:29:51 +00:00
# Check if there are any items without a page or order parameter, and make it 1 and 255.
2009-06-30 10:41:18 +00:00
foreach ($template['empty_attrs'] as $index => $detail) {
2009-06-30 09:29:51 +00:00
if (! isset($detail['page']))
2009-06-30 10:41:18 +00:00
$template['empty_attrs'][$index]['page'] = 1;
2009-06-30 09:29:51 +00:00
if (! isset($detail['order']))
2009-06-30 10:41:18 +00:00
$template['empty_attrs'][$index]['order'] = 255;
2009-06-30 09:29:51 +00:00
}
# Check we have some manditory items.
foreach (array('rdn','structural','visible') as $key) {
2009-06-30 10:41:18 +00:00
if (! isset($template[$key])
|| (! is_array($template[$key]) && ! trim($template[$key]))) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
$template['invalid'] = 1;
$template['invalid_reason'] = sprintf(_('Missing %s in the XML file.'),$key);
2009-06-30 09:29:51 +00:00
break;
}
}
2009-06-30 10:41:18 +00:00
2009-06-30 10:46:00 +00:00
# Define attribute type according to the values
foreach ($template['empty_attrs'] as $attr => $details) {
if (isset($template['empty_attrs'][$attr]['type'])) continue;
if (isset($details['option'])) {
if (is_array($details['option'])) {
$details['type'] = 'select';
} elseif (preg_match('/^=php\.(\w+)\((.*)\)$/', $details['option'], $matches)) {
$args = preg_split('/,/',$matches[2]);
switch($matches[1]) {
case 'GetNextNumber' :
break;
case 'MultiList' :
$template['empty_attrs'][$attr]['type'] = 'multiselect';
break;
case 'PickList' :
$template['empty_attrs'][$attr]['type'] = 'select';
break;
case 'RandomPassword' :
break;
case 'DrawChooserLink' :
break;
default :
break;
}
}
}
}
2009-06-30 09:29:51 +00:00
}
function _parseXML($index,$attr_details) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Entered with (%s,%s)',5,__FILE__,__LINE__,__METHOD__,$index,$attr_details);
2009-06-30 09:29:51 +00:00
if (! $attr_details) {
2009-06-30 09:40:37 +00:00
return '';
} elseif (! is_array($attr_details)) {
return $attr_details;
2009-06-30 09:29:51 +00:00
} elseif (isset($attr_details['#text'])) {
2009-06-30 09:40:37 +00:00
# If index is numeric, then this is part of an array...
2009-06-30 09:29:51 +00:00
return $attr_details['#text'];
}
foreach ($attr_details as $key => $values) {
2009-06-30 09:40:37 +00:00
if (($key == 'ID') && ! is_array($values))
continue;
elseif (isset($values['ID']) && (! $key['#text'])) {
$key = '_KEY:'.$values['ID'];
unset($values['ID']);
} elseif (isset($values['ID']) && ($values['#text'])) {
$key = '_KEY:'.$values['ID'];
}
2009-06-30 09:29:51 +00:00
$parseXML[$key] = $this->_parseXML($index,$values);
}
return $parseXML;
}
2009-06-30 10:41:18 +00:00
function getCreationTemplate($template) {
return isset($this->_creation_template[$template]) ? $this->_creation_template[$template] : null;
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:46:00 +00:00
function getEditingTemplate($template) {
return isset($this->_editing_template[$template]) ? $this->_editing_template[$template] : null;
}
2009-06-30 10:41:18 +00:00
function getCreationTemplates() {
return $this->_creation_template;
2009-06-30 09:40:37 +00:00
}
2009-06-30 10:46:00 +00:00
function getEditingTemplates() {
return $this->_editing_template;
}
2009-06-30 10:26:08 +00:00
function OnChangeAdd($ldapserver,$origin,$value) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Entered with (%s,%s,%s)',5,__FILE__,__LINE__,__METHOD__,$ldapserver->server_id,$origin,$value);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
global $_js_hash;
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
# limit to 2 fields because of 'C:\\my directory\\foobar'
list($command,$arg) = split(':',$value,2);
2009-06-30 09:29:51 +00:00
switch ($command) {
2009-06-30 10:26:45 +00:00
/*
autoFill:string
string is a literal string, and may contain many fields like %attr|start-end/flags%
2009-06-30 10:46:00 +00:00
to substitute values read from other fields.
2009-06-30 10:26:45 +00:00
|start-end is optional, but must be present if the k flag is used.
/flags is optional.
2009-06-30 10:41:18 +00:00
2009-06-30 10:26:45 +00:00
flags may be:
2009-06-30 10:46:00 +00:00
T: Read display text from selection item (drop-down list), otherwise, read the value of the field
For fields that aren't selection items, /T shouldn't be used, and the field value will always be read.
k: Tokenize:
If the "k" flag is not given:
A |start-end instruction will perform a sub-string operation upon
the value of the attr, passing character positions start-end through.
start can be 0 for first character, or any other integer.
end can be 0 for last character, or any other integer for a specific position.
If the "k" flag is given:
The string read will be split into fields, using : as a delimiter
"start" indicates which field number to pass through.
l: Make the result lower case.
U: Make the result upper case.
2009-06-30 10:26:45 +00:00
*/
2009-06-30 09:29:51 +00:00
case 'autoFill' :
2009-06-30 10:40:33 +00:00
list($attr,$string) = preg_split('(([^,]+),(.*))',$arg,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
2009-06-30 10:41:18 +00:00
preg_match_all('/%(\w+)(\|[0-9]*-[0-9]*)?(\/[klTUA]+)?%/U',$string,$matchall);
2009-06-30 09:29:51 +00:00
//print"<PRE>";print_r($matchall); //0 = highlevel match, 1 = attr, 2 = subst, 3 = mod
2009-06-30 10:26:08 +00:00
if (! isset($_js_hash['autoFill'.$origin]))
$_js_hash['autoFill'.$origin] = '';
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$formula = $string;
$formula = preg_replace('/^([^%])/','\'$1',$formula);
$formula = preg_replace('/([^%])$/','$1\'',$formula);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Check that our attributes match our schema attributes.
foreach ($matchall[1] as $index => $checkattr) {
$matchattr = $ldapserver->getSchemaAttribute($checkattr);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# If the attribute is the same as in the XML file, then dont need to do anything.
if ($matchattr->getName() == $checkattr)
continue;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$formula = preg_replace("/$checkattr/",$matchattr->getName(),$formula);
$matchall[1][$index] = $matchattr->getName();
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$elem_id = 0;
2009-06-30 10:26:08 +00:00
foreach ($matchall[0] as $index => $null) {
$match_attr = $matchall[1][$index];
$match_subst = $matchall[2][$index];
$match_mod = $matchall[3][$index];
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
$substrarray = array();
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if (! isset($varcount[$match_attr]))
$varcount[$match_attr] = 0;
else
$varcount[$match_attr]++;
$js_match_attr = $match_attr;
$match_attr = $js_match_attr.'xx'.$varcount[$match_attr];
$formula = preg_replace('/%'.$js_match_attr.'([|\/%])/','%'.$match_attr.'$1',$formula,1);
2009-06-30 10:26:08 +00:00
$_js_hash['autoFill'.$origin] .= sprintf(" var %s;\n",$match_attr);
2009-06-30 10:46:00 +00:00
$_js_hash['autoFill'.$origin] .= sprintf(
" var elem$elem_id = document.getElementById(pre+'%s'+suf);\n".
" if (!elem$elem_id) return;\n", $js_match_attr);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:45 +00:00
if (strstr($match_mod,'T')) {
2009-06-30 10:46:00 +00:00
$_js_hash['autoFill'.$origin] .= sprintf(" %s = elem$elem_id.options[elem$elem_id.selectedIndex].text;\n",
$match_attr);
2009-06-30 10:26:45 +00:00
} else {
2009-06-30 10:46:00 +00:00
$_js_hash['autoFill'.$origin] .= sprintf(" %s = elem$elem_id.value;\n",$match_attr);
2009-06-30 10:26:45 +00:00
}
2009-06-30 10:26:08 +00:00
2009-06-30 10:46:00 +00:00
$elem_id++;
2009-06-30 10:26:45 +00:00
if (strstr($match_mod,'k')) {
preg_match_all('/([0-9]+)/',trim($match_subst),$substrarray);
if (isset($substrarray[1][0])) {
$tok_idx = $substrarray[1][0];
} else {
$tok_idx = '0';
}
$_js_hash['autoFill'.$origin] .= sprintf(" %s = %s.split(':')[%s];\n",$match_attr,$match_attr,$tok_idx);
2009-06-30 10:26:08 +00:00
} else {
2009-06-30 10:26:45 +00:00
preg_match_all('/([0-9]*)-([0-9]*)/',trim($match_subst),$substrarray);
2009-06-30 10:26:08 +00:00
if ((isset($substrarray[1][0]) && $substrarray[1][0]) || (isset($substrarray[2][0]) && $substrarray[2][0])) {
2009-06-30 10:26:45 +00:00
$_js_hash['autoFill'.$origin] .= sprintf(" %s = %s.substr(%s,%s);\n",
2009-06-30 10:26:08 +00:00
$match_attr,$match_attr,
$substrarray[1][0] ? $substrarray[1][0] : '0',
2009-06-30 10:26:45 +00:00
$substrarray[2][0] ? $substrarray[2][0] : sprintf('%s.length',$match_attr));
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:45 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:45 +00:00
if (strstr($match_mod,'l')) {
$_js_hash['autoFill'.$origin] .= sprintf(" %s = %s.toLowerCase();\n",$match_attr,$match_attr);
}
if (strstr($match_mod,'U')) {
$_js_hash['autoFill'.$origin] .= sprintf(" %s = %s.toUpperCase();\n",$match_attr,$match_attr);
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:41:18 +00:00
if (strstr($match_mod,'A')) {
$_js_hash['autoFill'.$origin] .= sprintf(" %s = toAscii(%s);\n",$match_attr,$match_attr);
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# Matchfor only entry without modifiers.
$formula = preg_replace('/^%('.$match_attr.')%$/U','$1 + \'\'',$formula);
# Matchfor only entry with modifiers.
2009-06-30 10:41:18 +00:00
$formula = preg_replace('/^%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[klTUA]+)?%$/U','$1 + \'\'',$formula);
2009-06-30 10:26:08 +00:00
# Matchfor begining entry.
2009-06-30 10:41:18 +00:00
$formula = preg_replace('/^%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[klTUA]+)?%/U','$1 + \'',$formula);
2009-06-30 10:26:08 +00:00
# Matchfor ending entry.
2009-06-30 10:41:18 +00:00
$formula = preg_replace('/%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[klTUA]+)?%$/U','\' + $1 ',$formula);
2009-06-30 10:26:08 +00:00
# Match for entries not at begin/end.
2009-06-30 10:41:18 +00:00
$formula = preg_replace('/%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[:lTUA]+)?%/U','\' + $1 + \'',$formula);
2009-06-30 10:46:00 +00:00
$_js_hash['autoFill'.$origin] .= "\n";
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:46:00 +00:00
$_js_hash['autoFill'.$origin] .= sprintf(" fillRec(pre+'%s'+suf, %s); // %s\n",$attr,$formula,$string);
2009-06-30 10:26:08 +00:00
$_js_hash['autoFill'.$origin] .= "\n";
2009-06-30 09:29:51 +00:00
break;
2009-06-30 10:26:08 +00:00
default: $return = '';
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
return '1';
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
function getJsHash() {
global $_js_hash;
return $_js_hash;
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:26:08 +00:00
// @todo: The XML files need to change the field seperater to something else (ie: not comma)
// as it is clashing when a DN is used as an argument.
2009-06-30 10:46:00 +00:00
static function EvaluateDefault(&$ldapserver,$value,$container,$counter='',$default=null) {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Entered with (%s,%s,%s,%s)',5,__FILE__,__LINE__,__METHOD__,
$ldapserver->server_id,$value,$container,$counter);
2009-06-30 09:29:51 +00:00
2009-06-30 09:40:37 +00:00
if (preg_match('/^=php\.(\w+)\((.*)\)$/',$value,$matches)) {
2009-06-30 09:29:51 +00:00
$args = preg_split('/,/',$matches[2]);
2009-06-30 10:46:00 +00:00
$vals = array();
2009-06-30 09:29:51 +00:00
switch($matches[1]) {
case 'GetNextNumber' :
2009-06-30 10:41:18 +00:00
/*
* mandatory arguments:
* * arg 0
2009-06-30 10:46:00 +00:00
* - "$" => 'auto_number','search_base' in config file
* - "/","..","." => get container parent as usual
2009-06-30 10:41:18 +00:00
* * arg 1
2009-06-30 10:46:00 +00:00
* - "gid" or "uid" for autosearch
* - idem or real attribute name for uidpool mechanism
* (gid and uid are mapped to sambaNextGroupRid and sambaNextUserRid)
2009-06-30 10:41:18 +00:00
* optional arguments:
* * arg 2 (uidpool mechanism only)
2009-06-30 10:46:00 +00:00
* - "true" increments attribute by 1
* - "false" do nothing
2009-06-30 10:41:18 +00:00
* * arg 3 (uidpool mechanism only)
2009-06-30 10:46:00 +00:00
* ldap filter (must match one entry only in container)
2009-06-30 10:41:18 +00:00
* * arg 4
2009-06-30 10:46:00 +00:00
* calculus on number, eg:
* *2;+1000 => number = (2*number) + 1000
2009-06-30 10:41:18 +00:00
*/
2009-06-30 10:26:08 +00:00
if ($args[0] == '$')
2009-06-30 11:46:44 +00:00
$args[0] = $_SESSION[APPCONFIG]->ldapservers->GetValue($ldapserver->server_id,'auto_number','search_base');
2009-06-30 10:26:08 +00:00
$container = $ldapserver->getContainerParent($container,$args[0]);
2009-06-30 11:52:55 +00:00
$vals = get_next_number($ldapserver,$container,$args[1],(!empty($args[2]) && ($args[2] == 'false')) ? false : true,(!empty($args[3])) ? $args[3] : false);
2009-06-30 10:41:18 +00:00
# operate calculus on next number.
if (!empty($args[4])) {
$mod = split(';',$args[4]);
2009-06-30 10:46:00 +00:00
$next_number = $vals;
2009-06-30 10:41:18 +00:00
foreach ($mod as $calc) {
$operand = $calc{0};
$operator = substr ($calc,1);
switch ($operand) {
case '*':
$next_number = $next_number * $operator;
break;
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
case '+':
$next_number = $next_number + $operator;
break;
case '-':
$next_number = $next_number - $operator;
break;
case '/':
$next_number = $next_number / $operator;
break;
}
}
2009-06-30 10:46:00 +00:00
$vals = $next_number;
2009-06-30 10:41:18 +00:00
}
2009-06-30 09:29:51 +00:00
break;
case 'PickList' :
2009-06-30 10:41:18 +00:00
/*
* PickList Syntax:
* arg0: container, from current position
* arg1: LDAP filter. must replace '&' by '&amp;'
* arg2: list attribute key
* arg3: display, as usual
2009-06-30 10:46:00 +00:00
* optional arguments:
2009-06-30 10:41:18 +00:00
* arg4: output attribute
* arg5: container override
* arg6: csv list (; separator) of added values. syntax key => display_attribute=value; key...
* arg7: csv list (; separator) of sort attributes (less to more important)
* example
* <value>=php.PickList(/,(&amp;(objectClass=sambaGroupMapping)(|(cn=domain administrator)(cn=domain users)(cn=domain guests))),sambaSID,%cn% (%sambaSID%),sambaPrimaryGroupSID,dmdname=users:::dmdName=groups:::dc=example:::dc=com, S-1-5-XX-YYY => cn=Administrators ; S-1-5-XX-YYY => cn=Users ; S-1-5-XX-YYY => cn=Guests ; S-1-5-XX-YYY => cn=power users,cn)</value>
*/
2009-06-30 10:26:08 +00:00
$container = $ldapserver->getContainerParent($container,$args[0]);
2009-06-30 09:29:51 +00:00
preg_match_all('/%(\w+)(\|.+)?(\/[lU])?%/U',$args[3],$matchall);
//print_r($matchall); // -1 = highlevel match, 1 = attr, 2 = subst, 3 = mod
$ldap_attrs = $matchall[1];
array_push($ldap_attrs,$args[2]);
2009-06-30 10:41:18 +00:00
$args[1] = str_replace ('&amp;','&',$args[1]);
# arg5 overrides container
if (!empty($args[5]))
$container = str_replace(':::',',',$args[5]);
if (!empty($args[7])) {
$sort_attrs = split(';',$args[7]);
$ldap_attrs = array_merge($ldap_attrs,$sort_attrs);
}
$picklistvalues = return_ldap_hash($ldapserver,$container,$args[1],$args[2],$ldap_attrs,
(isset($args[7])) ? $sort_attrs : false);
if (!empty($args[6])) {
$args[6] = str_replace(':::',',',$args[6]);
$fixedvalues = split(';',$args[6]);
foreach ($fixedvalues as $fixedvalue) {
$fixedvalue = preg_split('#=\>#',$fixedvalue);
$displayvalue = split('=',$fixedvalue[1]);
$newvalue[trim($fixedvalue[0])] = array( $args[2] => trim($fixedvalue[0]),
trim($displayvalue[0]) => trim($displayvalue[1]));
$picklistvalues = array_merge($picklistvalues,$newvalue);
}
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$vals = array();
2009-06-30 09:29:51 +00:00
foreach ($picklistvalues as $key => $values) {
$display = $args[3];
2009-06-30 10:41:18 +00:00
foreach ($matchall[1] as $arg)
2009-06-30 09:29:51 +00:00
$display = preg_replace('/%('.$arg.')(\|.+)?(\/[lU])?%/U',$values[$arg],$display);
2009-06-30 10:41:18 +00:00
if (! isset($picklist[$values[$args[2]]])) {
2009-06-30 10:46:00 +00:00
$vals['_KEY:'.$values[$args[2]]] = $display;
$picklist[$display] = true;
2009-06-30 10:41:18 +00:00
}
}
break;
case 'MultiList' :
/*
* MultiList Syntax:
*/
/**
2009-06-30 10:46:00 +00:00
* mandatory fields:
* arg 0: "/" ,"..","." - from container dn
* arg 1: search filter, may have values like '%gidNumber%, in case of it is replaced
* by the gidNumber setted in previous pages. '&' must be replaced by '&amp;'
* because of xml...
* arg 2: the key of retrived values
* optional fields:
* arg 3: display, as usual (plus modifier /C: Capitalize). replaced by %arg 2% if not given
* arg 4: the value furnished in output - must be attribute id. replaced by arg 2 if not given
* arg 5: override of container (replace ',' by ':::' in dn)
* arg 6: csv (; separator) list of added values. syntax: value => display_key=display_value
* arg 7: csv (; separator) list of attributes which list must be sort by. less to more important
* arg 8: size of displayed list (default: 10lines)
* arg 9: preselected values filter. see arg 1.
* arg 10: key of preselected values. replaced by arg 4 if not given. replaced bty arg 2 if both are not given.
* arg 11: base dn override for preselected values
* unusual exemple:)
* <value>=php.MultiList(/,(&amp;(objectClass=posixAccount)(uid=groupA*)),uid,%cn/U% (%gidNumber%),memberUid,dmdName=users,root => cn=root; nobody => cn=nobody,gidNumber,10,(gidNuber=%gidNumber%),uid)</value>
* minimal exemple:
* <value>=php.MultiList(/,(objectClass=posixAccount),uid)</value>
2009-06-30 10:41:18 +00:00
**/
$container = $ldapserver->getContainerParent($container,$args[0]);
/*
* process filter (arg 1), eventually replace %attr% by it's value
* setted in a previous page.
*/
$args[1] = str_replace('&amp;','&',$args[1]);
preg_match_all('/%(\w+)(\|.+)?(\/[lUC])?%/U',$args[1],$filtermatchall);
2009-06-30 10:46:00 +00:00
if (isset($_REQUEST['form'])) {
$formvalues = array_change_key_case($_REQUEST['form']);
foreach ($filtermatchall[1] as $arg) {
$value = $formvalues[strtolower($arg)];
$args[1] = preg_replace('/%('.$arg.')(\|.+)?(\/[lU])?%/U',$value,$args[1]);
}
2009-06-30 10:41:18 +00:00
}
$args[3] = !empty($args[3]) ? $args[3] : "%{$args[2]}%";
preg_match_all('/%(\w+)(\|.+)?(\/[lUC])?%/U',$args[3],$matchall);
//print_r($matchall); // -1 = highlevel match, 1 = attr, 2 = subst, 3 = mod
$ldap_attrs = $matchall[1];
array_push($ldap_attrs,$args[2]);
/*
* container is arg 5 if set
* with arg 5 = 'dc=thissubtree:::dc=thistree' stands for 'dc=subtree,dc=tree'
* => 'dc=subtree,dc=tree,dc=container'
*/
if (isset($args[5]) && ($args[5]))
$container = str_replace(':::',',',$args[5]);
/*
* arg 7 is sort attributes
* eg: 'sn;givenName'
*/
if (isset($args[7])) {
$sort_attrs = split(';',$args[7]);
$ldap_attrs = array_merge($ldap_attrs,$sort_attrs);
}
$picklistvalues = return_ldap_hash($ldapserver,$container,$args[1],$args[2],$ldap_attrs,
(isset($args[7]) && ($args[7])) ? $sort_attrs : false);
# arg 6 is a set of fixed values to add to search result
if (isset($args[6])) {
$args[6] = str_replace(':::',',',$args[6]);
$fixedvalues = split(';',$args[6]);
foreach ($fixedvalues as $fixedvalue) {
if (empty($fixedvalue))
continue;
$fixedvalue = preg_split('#=\>#',$fixedvalue);
$displayvalue = split('=',$fixedvalue[1]);
$newvalue[trim($fixedvalue[0])] = array($args[2] => trim($fixedvalue[0]),
trim($displayvalue[0]) => trim($displayvalue[1]));
$picklistvalues = array_merge($picklistvalues,$newvalue);
}
}
/*
* arg 9 is the search filter for already selected values, with criteriai eventually
* coming from previous pages (eg: %uid%)
*/
if (isset($args[9])) {
$args[9] = str_replace('&amp;','&',$args[9]);
preg_match_all('/%(\w+)(\|.+)?(\/[lUC])?%/U',$args[9],$matchallinlist);
foreach ($matchallinlist[1] as $arg) {
$value=$formvalues[strtolower($arg)];
$args[9] = preg_replace('/%('.$arg.')(\|.+)?(\/[lU])?%/U',$value,$args[9]);
}
# arg 11 overrides container dn for selected values
if (!empty($args[11]))
$container = str_replace(':::',',',$args[11]);
$inpicklistvalues = return_ldap_hash($ldapserver,$container,$args[9],$args[2],$ldap_attrs);
}
2009-06-30 10:46:00 +00:00
$vals = array();
2009-06-30 10:41:18 +00:00
foreach ($picklistvalues as $key => $values) {
$display = $args[3];
foreach ($matchall[1] as $key => $arg) {
$disp_val = $values[$arg];
2009-06-30 10:46:00 +00:00
if (is_array($disp_val)) $disp_val = $disp_val[0];
if (!$disp_val) $disp_val = '';
2009-06-30 10:41:18 +00:00
if ($matchall[3][$key])
switch ($matchall[3][$key]) {
case '/l':
# lowercase
2009-06-30 10:46:00 +00:00
if (function_exists('mb_convert_case'))
$disp_val = mb_convert_case($disp_val,MB_CASE_LOWER,'utf-8');
else
$disp_val = strtolower($disp_val);
2009-06-30 10:41:18 +00:00
break;
case '/U':
# uppercase
2009-06-30 10:46:00 +00:00
if (function_exists('mb_convert_case'))
$disp_val = mb_convert_case($disp_val,MB_CASE_UPPER,'utf-8');
else
$disp_val = strtoupper($disp_val);
2009-06-30 10:41:18 +00:00
break;
case '/C':
# capitalize
2009-06-30 10:46:00 +00:00
if (function_exists('mb_convert_case'))
$disp_val = mb_convert_case($disp_val,MB_CASE_TITLE,'utf-8');
else
$disp_val = ucfirst($disp_val);
2009-06-30 10:41:18 +00:00
break;
default:
break;
}
# make value a substring of
preg_match_all('/^\|([0-9]*)-([0-9]*)$/',trim($matchall[2][$key]),$substrarray);
if ((isset($substrarray[1][0]) && $substrarray[1][0]) || (isset($substrarray[2][0]) && $substrarray[2][0])) {
$begin = $substrarray[1][0] ? $substrarray[1][0] : '0';
$end = $substrarray[2][0] ? $substrarray[2][0] : strlen($disp_val);
2009-06-30 10:46:00 +00:00
if (function_exists('mb_substr'))
$disp_val = mb_substr($disp_val,$begin,$end,'utf-8');
else
$disp_val = substr($disp_val,$begin,$end);
2009-06-30 10:41:18 +00:00
}
$display = preg_replace('/%('.$arg.')(\|.+)?(\/[lUC])?%/U',$disp_val,$display);
}
if (! isset($picklist[$values[$args[2]]])) {
2009-06-30 10:46:00 +00:00
$vals['_KEY:'.$values[$args[2]]] = $display;
2009-06-30 10:41:18 +00:00
$picklist[$values[$args[2]]] = true;
2009-06-30 09:29:51 +00:00
}
}
break;
case 'RandomPassword' :
2009-06-30 10:46:00 +00:00
$vals = password_generate();
2009-06-30 10:26:08 +00:00
printf('<script type="text/javascript" language="javascript">alert(\'%s:\n%s\')</script>',
2009-06-30 10:46:00 +00:00
_('A random password was generated for you'),$vals);
2009-06-30 09:29:51 +00:00
break;
case 'DrawChooserLink' :
2009-06-30 10:46:00 +00:00
$vals = draw_chooser_link(sprintf('template_form.%s%s',$args[0],$counter),$args[1]);
2009-06-30 09:29:51 +00:00
break;
case 'Function' :
# Capture the function name and remove function name from $args
$function_name = array_shift($args);
2009-06-30 10:26:08 +00:00
$function_args = array();
foreach ($args as $arg) {
if (preg_match('/^%(\w+)(\|.+)?(\/[lU])?%/U',$arg,$matches)) {
$varname = $matches[1];
2009-06-30 10:26:45 +00:00
if (isset($_POST['form'][$varname]))
$function_args[] = $_POST['form'][$varname];
2009-06-30 10:26:08 +00:00
else
2009-06-30 11:52:55 +00:00
error(sprintf(_('Your template calls php.Function for a default value, however (%s) is NOT available in the POST FORM variables. The following variables are available [%s].'),$varname,
(isset($_POST['form']) ? implode('|',array_keys($_POST['form'])) : 'NONE')),'error','index.php');
2009-06-30 10:26:08 +00:00
} else {
$function_args[] = $arg;
}
}
2009-06-30 09:29:51 +00:00
# Call the PHP function if exists (PHP 4 >= 4.0.4, PHP 5)
if (function_exists($function_name))
2009-06-30 10:46:00 +00:00
$vals = call_user_func_array($function_name,$function_args);
2009-06-30 09:29:51 +00:00
break;
2009-06-30 10:46:00 +00:00
default : $vals = 'UNKNOWN';
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:46:00 +00:00
$return = $vals;
2009-06-30 09:29:51 +00:00
} else {
2009-06-30 09:40:37 +00:00
$return = $value;
2009-06-30 09:29:51 +00:00
}
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Returning (%s)',5,__FILE__,__LINE__,__METHOD__,$return);
2009-06-30 09:29:51 +00:00
return $return;
}
function HelperValue($helper,$id='',$container='',$ldapserver='',$counter='',$default='') {
2009-06-30 09:40:37 +00:00
if (DEBUG_ENABLED)
2009-06-30 10:46:00 +00:00
debug_log('Entered with (%s,%s,%s,%s,%s,%s)',5,__FILE__,__LINE__,__METHOD__,
$helper,$id,$container,$ldapserver->server_id,$counter,$default);
2009-06-30 09:29:51 +00:00
if ($container && $ldapserver && ! is_array($helper)) {
2009-06-30 09:40:37 +00:00
if (preg_match('/^=php./',$helper))
2009-06-30 10:41:18 +00:00
$html = sprintf('<input type="text" name="%s" value="%s" size="8" />',$id,
$this->EvaluateDefault($ldapserver,$helper,$container,$counter));
2009-06-30 09:40:37 +00:00
else
# @todo: Enable size and width configuration in template
2009-06-30 10:46:00 +00:00
$html = sprintf('<input type="text" name="%s" size="8" value="%s" />',$id,$helper);
2009-06-30 09:29:51 +00:00
} else {
if (is_array($helper)) {
2009-06-30 10:26:08 +00:00
$html = sprintf('<select name="%s" id="%s">',$id,$id);
2009-06-30 09:29:51 +00:00
foreach ($helper as $value) {
2009-06-30 10:26:08 +00:00
$html .= sprintf('<option id="%s" value="%s" %s>%s</option>',
2009-06-30 09:29:51 +00:00
$value,$value,($default == $value ? 'selected' : ''),$value);
}
$html .= '</select>';
} else {
print "ERROR: HelperValue NOT complete, how did you get HERE?";
die();
}
}
return $html;
}
}
?>