Example #1
0
 private function _getForm()
 {
     $this->data = array();
     $this->data['error'] = $this->error;
     $this->data['cancel'] = $this->html->getSecureURL('catalog/attribute');
     $this->data['get_attribute_type'] = $this->html->getSecureURL('r/catalog/attribute/get_attribute_type');
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/attribute'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     if (isset($this->request->get['attribute_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') {
         $attribute_info = $this->attribute_manager->getAttribute($this->request->get['attribute_id'], $this->session->data['content_language_id']);
         $attribute_type_info = $this->attribute_manager->getAttributeTypeInfoById((int) $attribute_info['attribute_type_id']);
         //load values for attributes with options
         $this->data['elements_with_options'] = HtmlElementFactory::getElementsWithOptions();
         if (in_array($attribute_info['element_type'], $this->data['elements_with_options'])) {
             $values = $this->attribute_manager->getAttributeValues($this->request->get['attribute_id'], $this->session->data['content_language_id']);
             $attribute_info['values'] = array();
             foreach ($values as $v) {
                 $attribute_info['values'][] = addslashes(html_entity_decode($v['value'], ENT_COMPAT, 'UTF-8'));
             }
         }
         if (has_value($attribute_info['settings'])) {
             $attribute_info['settings'] = unserialize($attribute_info['settings']);
         }
     }
     if (has_value($this->request->get['attribute_type_id'])) {
         $attribute_type_info = $this->attribute_manager->getAttributeTypeInfoById((int) $this->request->get['attribute_type_id']);
     }
     $fields = array('name', 'attribute_group_id', 'attribute_type_id', 'element_type', 'sort_order', 'required', 'regexp_pattern', 'error_text', 'settings', 'status', 'values');
     if ($attribute_type_info['type_key'] != 'download_attribute') {
         $fields[] = 'attribute_parent_id';
     }
     foreach ($fields as $f) {
         if (isset($this->request->post[$f])) {
             $this->data[$f] = $this->request->post[$f];
         } elseif (isset($attribute_info[$f])) {
             $this->data[$f] = $attribute_info[$f];
         } else {
             $this->data[$f] = '';
             if ($f == 'status') {
                 $this->data[$f] = 1;
             }
         }
     }
     // build tabs on page
     $results = $this->attribute_manager->getAttributeTypes();
     foreach ($results as $type) {
         $this->data['attribute_types'][$type['attribute_type_id']] = $type;
     }
     if (isset($attribute_info['attribute_type_id'])) {
         $attribute_type_id = (int) $attribute_info['attribute_type_id'];
     } else {
         $attribute_type_id = (int) $this->request->get_or_post('attribute_type_id');
     }
     if (!$attribute_type_id) {
         $attribute_type_id = key($this->data['attribute_types']);
     }
     $this->_initTabs($attribute_type_id);
     //NOTE: Future inplementation
     /*$attribute_groups = array( '' => $this->language->get('text_select'));
     		$results = $this->attribute_manager->getAttributeGroups(array('language_id' => $this->session->data['content_language_id']));
     		foreach ($results as $type) {
     		    $attribute_groups[$type['attribute_group_id']] = $type['name'];
     	    }*/
     if (!isset($this->request->get['attribute_id'])) {
         $this->data['action'] = $this->html->getSecureURL('catalog/attribute/insert', '&attribute_type_id=' . $attribute_type_id);
         $this->data['heading_title'] = $this->language->get('text_insert') . $this->language->get('text_attribute');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('catalog/attribute/update', '&attribute_id=' . $this->request->get['attribute_id'] . '&attribute_type_id=' . $attribute_type_id);
         $this->data['heading_title'] = $this->language->get('text_edit') . $this->language->get('text_attribute');
         $this->data['update'] = $this->html->getSecureURL('listing_grid/attribute/update_field', '&id=' . $this->request->get['attribute_id']);
         $form = new AForm('HT');
         $this->data['attribute_id'] = $this->request->get['attribute_id'];
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: '));
     $form->setForm(array('form_name' => 'editFrm', 'update' => $this->data['update']));
     $this->data['form']['id'] = 'editFrm';
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'editFrm', 'attr' => 'confirm-exit="true"', 'action' => $this->data['action']));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $this->data['form']['fields']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => $this->data['status'], 'style' => 'btn_switch'));
     $this->data['form']['fields']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'name', 'value' => $this->data['name'], 'required' => true, 'style' => 'large-field'));
     if ($attribute_type_info['type_key'] != 'download_attribute') {
         $parent_attributes = array('' => $this->language->get('text_select'));
         $results = $this->attribute_manager->getAttributes(array('attribute_type_id' => $attribute_type_id, 'limit' => null), 0, 0);
         foreach ($results as $type) {
             if (isset($this->request->get['attribute_id']) && $this->request->get['attribute_id'] == $type['attribute_id']) {
                 continue;
             }
             $parent_attributes[$type['attribute_id']] = $type['name'];
         }
         $this->data['form']['fields']['attribute_parent'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'attribute_parent_id', 'value' => $this->data['attribute_parent_id'], 'options' => $parent_attributes));
     }
     //NOTE: Future implementation
     /*$this->data['form']['fields']['attribute_group'] = $form->getFieldHtml(array(
     			'type' => 'selectbox',
     			'name' => 'attribute_group_id',
     			'value' => $this->data['attribute_group_id'],
     			'options' => $attribute_groups,
     		));*/
     if ($this->data['attribute_types'][$attribute_type_id]['controller']) {
         $subform = $this->dispatch($this->data['attribute_types'][$attribute_type_id]['controller'], array(array('data' => $this->data, 'aform' => $form, 'attribute_manager' => $this->attribute_manager)));
         $this->data['subform'] = $subform->dispatchGetOutput();
     }
     $this->data['insert'] = $this->html->getSecureURL('catalog/attribute/insert');
     $this->data['form_language_switch'] = $this->html->getContentLanguageSwitcher();
     $this->data['text_parent_note'] = $this->language->get('text_parent_note');
     $this->data['help_url'] = $this->gen_help_url('global_attributes_edit');
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/catalog/attribute_form.tpl');
 }