1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
<?php
/**
* Allows to create new attributes
*
* @author The phpLDAPadmin development team
* @package phpLDAPadmin
*/
/**
* AttributeFactory Class
*
* @package phpLDAPadmin
* @subpackage Templates
*/
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:
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'))) {
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:
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':
if (! strcasecmp($name,'sambaLMPassword') || ! strcasecmp($name,'sambaNTPassword'))
return $this->newSambaPasswordAttribute($name,$values,$server_id,$source);
else
return $this->newPasswordAttribute($name,$values,$server_id,$source);
case 'multiselect':
case 'select':
return $this->newSelectionAttribute($name,$values,$server_id,$source);
case 'textarea':
return $this->newMultiLineAttribute($name,$values,$server_id,$source);
}
if (! strcasecmp($name,'objectClass')) {
return $this->newObjectClassAttribute($name,$values,$server_id,$source);
} elseif ($app['server']->isJpegPhoto($name) || in_array($name,$app['server']->getValue('server','jpeg_attributes'))) {
return $this->newJpegAttribute($name,$values,$server_id,$source);
} elseif ($app['server']->isAttrBinary($name)) {
return $this->newBinaryAttribute($name,$values,$server_id,$source);
} elseif (! strcasecmp($name,'userPassword')) {
return $this->newPasswordAttribute($name,$values,$server_id,$source);
} elseif (! strcasecmp($name,'sambaLMPassword') || ! strcasecmp($name,'sambaNTPassword')) {
return $this->newSambaPasswordAttribute($name,$values,$server_id,$source);
} 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);
} elseif (in_array(strtolower($name),array('shadowlastchange','shadowmin','shadowmax','shadowexpire','shadowwarning','shadowinactive'))) {
return $this->newShadowAttribute($name,$values,$server_id,$source);
} elseif ($app['server']->isAttrBoolean($name)) {
$attribute = $this->newSelectionAttribute($name,$values,$server_id,$source);
$attribute->addOption('TRUE',_('true'));
$attribute->addOption('FALSE',_('false'));
return $attribute;
} elseif ($app['server']->isDNAttr($name)) {
return $this->newDnAttribute($name,$values,$server_id,$source);
} elseif ($app['server']->isMultiLineAttr($name)) {
return $this->newMultiLineAttribute($name,$values,$server_id,$source);
} elseif (! strcasecmp($name,'gidNumber')) {
return $this->newGidAttribute($name,$values,$server_id,$source);
} else {
return new PLAAttribute($name,$values,$server_id,$source);
}
}
private function newJpegAttribute($name,$values,$server_id,$source) {
return new JpegAttribute($name,$values,$server_id,$source);
}
private function newBinaryAttribute($name,$values,$server_id,$source) {
return new BinaryAttribute($name,$values,$server_id,$source);
}
private function newPasswordAttribute($name,$values,$server_id,$source) {
return new PasswordAttribute($name,$values,$server_id,$source);
}
private function newSambaPasswordAttribute($name,$values,$server_id,$source) {
return new SambaPasswordAttribute($name,$values,$server_id,$source);
}
private function newRandomPasswordAttribute($name,$values,$server_id,$source) {
return new RandomPasswordAttribute($name,$values,$server_id,$source);
}
private function newShadowAttribute($name,$values,$server_id,$source) {
return new ShadowAttribute($name,$values,$server_id,$source);
}
private function newSelectionAttribute($name,$values,$server_id,$source) {
return new SelectionAttribute($name,$values,$server_id,$source);
}
private function newMultiLineAttribute($name,$values,$server_id,$source) {
return new MultiLineAttribute($name,$values,$server_id,$source);
}
private function newDateAttribute($name,$values,$server_id,$source) {
return new DateAttribute($name,$values,$server_id,$source);
}
private function newObjectClassAttribute($name,$values,$server_id,$source) {
return new ObjectClassAttribute($name,$values,$server_id,$source);
}
private function newDnAttribute($name,$values,$server_id,$source) {
return new DnAttribute($name,$values,$server_id,$source);
}
private function newGidAttribute($name,$values,$server_id,$source) {
return new GidAttribute($name,$values,$server_id,$source);
}
}
?>
|