34 protected $attributes;
36 protected $applied = FALSE;
38 static protected $uiSpecialAttributes = [
'dn',
'cn',
'uid',
'sn',
'givenName'];
40 static function plInfo ()
43 'plShortName' => _(
'Template'),
44 'plDescription' => _(
'Object template, used to create several objects with similar values'),
49 'template_cn' => _(
'Template name')
54 static function getTemplatedTypes ()
57 $types = objects::types();
58 foreach ($types as $type) {
59 if (in_array($type, departmentManagement::getDepartmentTypes())) {
62 $infos = objects::infos($type);
63 if ($infos[
'templateActive']) {
64 $result[$type] = $infos[
'name'];
71 function __construct ($type, $dn)
77 $this->needed[] =
'base';
78 $this->tabObject = objects::create($this->type);
81 $tempTabObject->setActiveTabs($this->tabObject);
82 $this->attributes = [];
83 foreach ($this->tabObject->by_object as $class => $tab) {
84 if ($tab->isActive()) {
85 $this->attributes[$class] = [];
86 $attrs = array_unique(array_merge($tab->getRequiredAttributes(), $this->needed));
87 foreach (array_keys($tab->attributesAccess) as $attr) {
88 if (!$tab->showInTemplate($attr, $this->attrs)) {
91 if (in_array($attr, $attrs)) {
92 $this->attributes[$class][] = $attr;
95 if (empty($this->attributes[$class])) {
97 unset($this->attributes[$class]);
109 $this->needed[] =
'base';
110 $this->tabObject = objects::create($this->type);
113 $tempTabObject->setActiveTabs($this->tabObject);
114 $this->applied = FALSE;
124 if (is_object($this->tabObject)) {
125 return $this->tabObject->getBaseObject()->base;
127 $infos = objects::infos($this->type);
128 return dn2base($this->dn,
'ou=templates,'.$infos[
'ou']);
132 function getNeeded (): array
134 return $this->attributes;
137 function alterAttributes ($mandatories, $readonly, $hidden)
139 foreach ($mandatories as $class => $attrs) {
140 foreach ($attrs as $attr) {
141 if (!in_array($attr, $this->attributes[$class])) {
142 $this->attributes[$class][] = $attr;
144 $this->tabObject->by_object[$class]->attributesAccess[$attr]->setRequired(TRUE);
147 foreach ($readonly as $class => $attrs) {
148 foreach ($attrs as $attr) {
149 if (!in_array($attr, $this->attributes[$class])) {
150 $this->attributes[$class][] = $attr;
152 $this->tabObject->by_object[$class]->attributesAccess[$attr]->setDisabled(TRUE);
155 foreach ($hidden as $class => $attrs) {
156 foreach ($attrs as $attr) {
157 if (!in_array($attr, $this->attributes[$class])) {
158 $this->attributes[$class][] = $attr;
160 $this->tabObject->by_object[$class]->attributesAccess[$attr]->setDisabled(TRUE);
161 $this->tabObject->by_object[$class]->attributesAccess[$attr]->setVisible(FALSE);
166 function getAttribute ($tab, $attr)
168 return $this->tabObject->by_object[$tab]->attributesAccess[$attr];
171 function getAttributeTab ($attr)
173 foreach ($this->tabObject->by_object as $tab => $tabObject) {
174 if (isset($tabObject->attributesAccess[$attr])) {
185 foreach ($this->tabObject->by_object as $class => $plugin) {
186 if (!isset($this->attributes[$class])) {
189 $ret[$class] = [
'name' => $this->tabObject->by_name[$class],
'attrs' => []];
190 foreach ($this->attributes[$class] as $attr) {
191 $plugin->attributesAccess[$attr]->serializeAttribute($ret[$class][
'attrs'], FALSE);
193 $ret[$class][
'attrs_order'] = array_keys($ret[$class][
'attrs']);
203 foreach ($values as $class => $class_values) {
204 $result = $this->tabObject->by_object[$class]->deserializeValues($class_values);
205 if ($result !== TRUE) {
219 foreach ($this->tabObject->by_object as $class => $plugin) {
221 foreach ($plugin->attributesAccess as $name => $attr) {
222 $ret[$class][$name] = $attr->getValue();
233 foreach ($values as $class => $class_values) {
234 foreach ($class_values as $name => $value) {
236 $value = $this->tabObject->by_object[$class]->attributesAccess[$name]->inputValue($value);
238 $this->tabObject->by_object[$class]->attributesAccess[$name]->setValue($value);
245 foreach ($this->tabObject->by_object as $plugin) {
252 foreach ($this->tabObject->by_object as $plugin) {
258 public function dialogOpened ()
260 return $this->tabObject->dialogOpened();
268 $smarty->assign(
'baseACL',
'rw');
269 foreach ($this->tabObject->by_object as $class => &$plugin) {
270 if (!isset($this->attributes[$class])) {
273 if ($plugin->is_modal_dialog()) {
274 $this->tabObject->current = $class;
275 return $plugin->render();
277 $attributesRendered = [];
278 foreach ($this->attributes[$class] as $attr) {
279 if ($plugin->attributesAccess[$attr]->getAclInfo() !== FALSE) {
281 $smarty->assign($plugin->attributesAccess[$attr]->getAcl().
'ACL', $plugin->aclGetPermissions($plugin->attributesAccess[$attr]->getAcl()));
283 $readable = $plugin->attrIsReadable($attr);
284 $writable = $plugin->attrIsWriteable($attr);
285 $plugin->attributesAccess[$attr]->renderAttribute($attributesRendered, FALSE, $readable, $writable);
288 $smarty->assign(
'section', $this->tabObject->by_name[$class]);
289 $smarty->assign(
'sectionId', $class);
290 $smarty->assign(
'sectionClasses',
' fullwidth');
291 $smarty->assign(
'attributes', $attributesRendered);
293 $posted[] = $class.
'_posted';
298 $smarty->assign(
'sections', $sections);
299 $smarty->assign(
'hiddenPostedInput', $posted);
300 $smarty->assign(
'focusedField',
'');
307 function apply ($targetdn = NULL)
309 if ($this->applied) {
310 trigger_error(
'Templates can’t be applied twice without calling reset before');
314 if ($targetdn !== NULL) {
316 unset($this->attrs[
'objectClass'][
'count']);
317 foreach ($this->tabObject->by_object as $class => $plugin) {
318 if ($plugin->isActive()) {
319 $this->attrs[
'objectClass'] = $plugin->mergeObjectClasses($this->attrs[
'objectClass']);
324 foreach ($this->tabObject->by_object as $class => &$plugin) {
325 if (!isset($this->attributes[$class])) {
328 foreach ($this->attributes[$class] as $attr) {
329 $plugin->attributesAccess[$attr]->fillLdapValue($this->attrs);
333 foreach ($this->tabObject->by_object as $class => &$plugin) {
334 if (!isset($this->attributes[$class])) {
337 foreach ($this->attributes[$class] as $attr) {
338 $plugin->attributesAccess[$attr]->fillLdapValueHook($this->attrs);
342 foreach ($this->attrs as &$array) {
343 if (!is_array($array)) {
346 if (!isset($array[
'count'])) {
347 $array[
'count'] = count($array);
354 foreach (static::$uiSpecialAttributes as $attr) {
355 $specialAttrs[
'caller'.strtoupper($attr)] = $ui->$attr;
358 $this->tabObject->adapt_from_template($this->attrs, array_merge([], ...array_values($this->attributes)));
360 $this->applied = TRUE;
361 return $this->tabObject;
Class for applying a template.
get_template_path($filename='', $plugin=FALSE, $path='')
Return themed path for specified base file.
This interface should be implemented by all dialog classes in FusionDirectory.
static parseArray(array $attrs, array $specialAttrs, $target=NULL)
Parse template masks in an array.
setValues($values, $ldapFormat=FALSE)
Set values.
& get_userinfo()
Return the current userinfo object.
reset()
Used when you need to re-apply the same template with different values.
render()
Render the dialog and returns the HTML code.
static fetch($dn)
Fetch a template from LDAP and returns its attributes and dependencies information.
& get_smarty()
Get global smarty object.
update()
Update state and return FALSE if the dialog was closed.
static open(string $dn, string $type)
Create the tab object for the given dn.
deserialize($values)
Deserialize values into the template.
static neededAttrs(array &$attrs, array $flatdepends)
Return attrs needed before applying template.
dn2base($dn, $ou=NULL)
Return the base of a given DN.
serialize()
Serialize this template for webservice.
getValues()
Get all attribute values.
readPost()
Interpret POST content.