<?php
namespace Modules\Admin\Config\Gds\Profiles\Templates; class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract { public function getForm() { $entCfg = \Entity\GdsProfileTemplate::loadCFG(); $form = \Engine\Form\General::create(); $form->setStyle('width', '300'); $fieldset = \Engine\Form\Container\Fieldset::create($this->lang['formFieldCat']['template']); $form->addContainer($fieldset); $fld = new \Engine\Form\Input\Select($this->lang['formFields']['category'], 'category', $this->values['category']); $fld->setPossibleValues([ 'corporate' => $this->lang['formFields']['categories']['corporate'], 'customer' => $this->lang['formFields']['categories']['customer'], ]); $fld->showDefaultOption(); $fld->importFromConfig($entCfg['category']); if ($this->controller->getAction()=='update' or $this->values['idOriginalTemplate']) { $fld->setDisabled(); } $fld->onChange("$('{$this->submitButtonName}').value=0;$('categoryChanged').value='1';this.form.submit();"); $fieldset->addElement($fld); if ($this->controller->getAction()=='update' or $this->values['idOriginalTemplate']) { $fieldset->addElement(new \Engine\Form\Input\Hidden('', 'category', $this->values['category'])); } $fld = new \Engine\Form\Input\Text($this->lang['formFields']['name'], 'name', $this->values['name']); $fld->importFromConfig($entCfg['name']); $fieldset->addElement($fld); if ($this->values['category']) { $listObj = new \App\EntityList\GdsProfilesFields(); $listObj->setColumns(['fld.category', 'fld.label', 'fld.type', 'fld.inputType', 'fld.description', 'fld.remarkVar', 'fld.tagSabre']); $listObj->setFilter('fld.category', '=', $this->values['category']); $listObj->setOrderBy('fld.label', 'ASC'); $fields = $listObj->exportRecords(); $staticFields = array_filter(array_map(function($elm) { if ($elm['type']=='static') { return $elm; } return null; }, $fields)); $dynamicFields = array_filter(array_map(function($elm) { if ($elm['type']=='dynamic') { return $elm; } return null; }, $fields)); usort($staticFields, function($f1, $f2) { return strnatcmp($f1["label"], $f2["label"]); }); usort($dynamicFields, function($f1, $f2) { return strnatcmp($f1["label"], $f2["label"]); }); $fieldset2 = \Engine\Form\Container\Fieldset::create($this->lang['formFieldCat']['staticFields']); $fieldset2->setCollapsible(); $form->addContainer($fieldset2); foreach ($staticFields as $field) { if (!isset($this->values['templateFields'][$field['id']])) { $visibility = 'invisible'; } elseif ($this->values['templateFields'][$field['id']]['mandatory']=='1') { $visibility = 'mandatory1'; } elseif ($this->values['templateFields'][$field['id']]['mandatory']=='2') { $visibility = 'mandatory2'; } else { $visibility = 'optional'; } $fld = new \Engine\Form\Input\Select($field['label'], 'field['.$field['id'].']', $visibility); $fld->setPossibleValues([ 'mandatory1' => $this->lang['formFields']['visibility']['mandatory1'], 'mandatory2' => $this->lang['formFields']['visibility']['mandatory2'], 'optional' => $this->lang['formFields']['visibility']['optional'], 'invisible' => $this->lang['formFields']['visibility']['invisible'], ]); $details = ""; if ($field['remarkVar']) { $details .= sprintf($this->lang['formFields']['rmVar'], $field['remarkVar'])."\n"; } if ($field['tagSabre']) { $details .= "Sabre: ".$field['tagSabre']."\n"; } $fld->setDetails(nl2br(trim($details))); $fld->setTooltip($field['description']); $fieldset2->addElement($fld); } $fieldset3 = \Engine\Form\Container\Fieldset::create($this->lang['formFieldCat']['dynamicFields']); $fieldset3->setCollapsible(); $form->addContainer($fieldset3); foreach ($dynamicFields as $field) { if (!isset($this->values['templateFields'][$field['id']])) { $visibility = 'invisible'; } elseif ($this->values['templateFields'][$field['id']]['mandatory']=='1') { $visibility = 'mandatory1'; } elseif ($this->values['templateFields'][$field['id']]['mandatory']=='2') { $visibility = 'mandatory2'; } else { $visibility = 'optional'; } $fld = new \Engine\Form\Input\Select($field['label'], 'field['.$field['id'].']', $visibility); $fld->setPossibleValues([ 'mandatory1' => $this->lang['formFields']['visibility']['mandatory1'], 'mandatory2' => $this->lang['formFields']['visibility']['mandatory2'], 'optional' => $this->lang['formFields']['visibility']['optional'], 'invisible' => $this->lang['formFields']['visibility']['invisible'], ]); $details = ""; if ($field['remarkVar']) { $details .= sprintf($this->lang['formFields']['rmVar'], $field['remarkVar'])."\n"; } if ($field['tagSabre']) { $details .= "Sabre: ".$field['tagSabre']."\n"; } $fld->setDetails(nl2br(trim($details))); $fld->setTooltip($field['description']); $fieldset3->addElement($fld); } } if ($this->controller->getAction()=='update') { $form->addElement(new \Engine\Form\Input\Hidden('', 'id', $this->values['id'])); } $form->addElement(new \Engine\Form\Input\Hidden('', $this->submitButtonName, 1)); $form->addElement(new \Engine\Form\Input\Hidden('', 'categoryChanged', 0)); return $form; } } 