phpldapadmin/lib/AttributeFactory.php

185 lines
6.6 KiB
PHP
Raw Permalink Normal View History

2009-06-30 10:46:00 +00:00
<?php
/**
* Allows to create new attributes
*
* @author The phpLDAPadmin development team
2009-06-30 10:46:00 +00:00
* @package phpLDAPadmin
*/
/**
* AttributeFactory Class
2009-06-30 10:46:00 +00:00
*
* @package phpLDAPadmin
* @subpackage Templates
2009-06-30 10:46:00 +00:00
*/
class AttributeFactory {
public function newAttribute($name,$values,$server_id,$source=null) {
global $app;
# Check to see if the value is auto generated, our attribute type is dependant on the function called.
if (isset($values['post']) && ! is_array($values['post'])) {
if (preg_match('/^=php\.(\w+)\((.*)\)$/',$values['post'],$matches)) {
switch ($matches[1]) {
case 'Join':
case 'PasswordEncrypt':
break;
default:
2009-08-30 02:11:18 +00:00
if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
system_message(array(
'title'=>sprintf('%s [<i>%s</i>]',_('Unknown template [post] function'),$matches[1]),
'body'=>sprintf('%s <small>[%s]</small>',_('The template function is not known and will be ignored.'),$values['post']),
'type'=>'warn'));
unset($values['post']);
}
}
}
# Check our helper functions exists
if (isset($values['helper']['value']) && ! is_array($values['helper']['value']))
if (preg_match('/^=php\.(\w+)\((.*)\)$/',$values['helper']['value'],$matches))
if (! in_array($matches[1],array('GetNextNumber','PasswordEncryptionTypes'))) {
2009-08-30 02:11:18 +00:00
if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
system_message(array(
'title'=>sprintf('%s [<i>%s</i>]',_('Unknown template helper function'),$matches[1]),
'body'=>sprintf('%s <small>[%s]</small>',_('The template helper function is not known and will be ignored.'),$values['helper']['value']),
'type'=>'warn'));
unset($values['helper']['value']);
}
# Check to see if the value is auto generated, our attribute type is dependant on the function called.
if (isset($values['value']) && ! is_array($values['value'])) {
if (preg_match('/^=php\.(\w+)\((.*)\)$/',$values['value'],$matches)) {
switch ($matches[1]) {
case 'MultiList':
if (! isset($values['type']))
$values['type'] = 'multiselect';
case 'PickList':
return $this->newSelectionAttribute($name,$values,$server_id,$source);
case 'RandomPassword':
return $this->newRandomPasswordAttribute($name,$values,$server_id,$source);
# Fall through and determine the attribute using other methods.
case 'GetNextNumber':
case 'Function' :
break;
default:
2009-08-30 02:11:18 +00:00
if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
system_message(array(
'title'=>sprintf('%s [<i>%s</i>]',_('Unknown template function'),$matches[1]),
'body'=>sprintf('%s <small>[%s]</small>',_('The template function is not known and will be ignored.'),$values['value']),
'type'=>'warn'));
unset($values['value']);
}
}
}
if (isset($values['type']))
switch ($values['type']) {
case 'password':
return $this->newPasswordAttribute($name,$values,$server_id,$source);
case 'select':
return $this->newSelectionAttribute($name,$values,$server_id,$source);
case 'textarea':
return $this->newMultiLineAttribute($name,$values,$server_id,$source);
}
2009-06-30 10:46:00 +00:00
if (! strcasecmp($name,'objectClass')) {
return $this->newObjectClassAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif ($app['server']->isJpegPhoto($name)) {
return $this->newJpegAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif ($app['server']->isAttrBinary($name)) {
return $this->newBinaryAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif (! strcasecmp($name,'userPassword')) {
return $this->newPasswordAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif (! strcasecmp($name,'sambaLMPassword') || ! strcasecmp($name,'sambaNTPassword')) {
return $this->newSambaPasswordAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif (in_array(strtolower($name),array_keys(array_change_key_case($_SESSION[APPCONFIG]->getValue('appearance','date_attrs'))))) {
return $this->newDateAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif (in_array(strtolower($name),array('shadowlastchange','shadowmin','shadowmax','shadowexpire','shadowwarning','shadowinactive'))) {
return $this->newShadowAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif ($app['server']->isAttrBoolean($name)) {
$attribute = $this->newSelectionAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
$attribute->addOption('TRUE',_('true'));
$attribute->addOption('FALSE',_('false'));
return $attribute;
} elseif ($app['server']->isDNAttr($name)) {
return $this->newDnAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif ($app['server']->isMultiLineAttr($name)) {
return $this->newMultiLineAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} elseif (! strcasecmp($name,'gidNumber')) {
return $this->newGidAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
} else {
return new Attribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
}
private function newJpegAttribute($name,$values,$server_id,$source) {
return new JpegAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newBinaryAttribute($name,$values,$server_id,$source) {
return new BinaryAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newPasswordAttribute($name,$values,$server_id,$source) {
return new PasswordAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newSambaPasswordAttribute($name,$values,$server_id,$source) {
return new SambaPasswordAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newRandomPasswordAttribute($name,$values,$server_id,$source) {
return new RandomPasswordAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newShadowAttribute($name,$values,$server_id,$source) {
return new ShadowAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newSelectionAttribute($name,$values,$server_id,$source) {
return new SelectionAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newMultiLineAttribute($name,$values,$server_id,$source) {
return new MultiLineAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newDateAttribute($name,$values,$server_id,$source) {
return new DateAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newObjectClassAttribute($name,$values,$server_id,$source) {
return new ObjectClassAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newDnAttribute($name,$values,$server_id,$source) {
return new DnAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
private function newGidAttribute($name,$values,$server_id,$source) {
return new GidAttribute($name,$values,$server_id,$source);
2009-06-30 10:46:00 +00:00
}
}
?>