Example #1
0
 private function _getForm()
 {
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     $this->data['error'] = $this->error;
     $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('design/menu'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['cancel'] = $this->html->getSecureURL('design/menu');
     $menu_item = null;
     $parent_id = array();
     $menu_ids = $this->menu->getItemIds();
     foreach ($menu_ids as $v) {
         $parent_id[$v] = $v;
     }
     if (isset($this->request->get['item_id'])) {
         $menu_item = $this->menu->getMenuItem($this->request->get['item_id']);
         unset($parent_id[array_search($this->request->get['item_id'], $parent_id)]);
     }
     foreach ($this->columns as $column) {
         if (isset($this->request->post[$column])) {
             $this->data[$column] = $this->request->post[$column];
         } elseif (!empty($menu_item)) {
             $this->data[$column] = $menu_item[$column];
         } else {
             $this->data[$column] = '';
         }
     }
     if (!isset($this->request->get['item_id'])) {
         $this->data['action'] = $this->html->getSecureURL('design/menu/insert');
         $this->data['heading_title'] = $this->language->get('text_insert') . ' ' . $this->language->get('heading_title');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         //do not allow to edit item_id
         $this->data['item_id'] = $menu_item['item_id'];
         $this->data['action'] = $this->html->getSecureURL('design/menu/update', '&item_id=' . $this->request->get['item_id']);
         $this->data['heading_title'] = $this->language->get('text_edit') . $this->language->get('heading_title');
         $this->data['update'] = $this->html->getSecureURL('listing_grid/menu/update_field', '&id=' . $this->request->get['item_id']);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: '));
     $form->setForm(array('form_name' => 'menuFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'menuFrm', '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'));
     if (!isset($this->request->get['item_id'])) {
         $this->data['form']['fields']['item_id'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'item_id', 'value' => $this->data['item_id'], 'required' => true));
     } else {
         $this->data['form']['fields']['item_id'] = $this->data['item_id'];
     }
     $this->data['form']['fields']['item_text'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'item_text[' . $this->session->data['content_language_id'] . ']', 'value' => $this->data['item_text'][$this->session->data['content_language_id']], 'required' => true, 'style' => 'large-field'));
     $this->data['form']['fields']['item_url'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'item_url', 'value' => $this->data['item_url'], 'style' => 'large-field', 'help_url' => $this->gen_help_url('item_url')));
     $this->data['form']['fields']['parent_id'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'parent_id', 'options' => array_merge(array('' => $this->language->get('text_none')), $parent_id), 'value' => $this->data['parent_id'], 'style' => 'medium-field'));
     $this->data['form']['fields']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'value' => $this->data['sort_order'], 'style' => 'small-field'));
     $this->data['form']['fields']['item_icon'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'item_icon', 'value' => htmlspecialchars($this->data['item_icon'], ENT_COMPAT, 'UTF-8')));
     //Added this hidden filed to save selected RL ID. Field is set from RL dialog same as item_icon
     //TODO: Need to add this filed to menu dataset
     $this->data['form']['fields']['item_icon_rl_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'item_icon_rl_id', 'value' => $this->data['item_icon_rl_id']));
     $this->loadModel('catalog/category');
     $categories = $this->model_catalog_category->getCategories(0);
     $options = array('' => $this->language->get('text_select'));
     foreach ($categories as $c) {
         if (!$c['status']) {
             continue;
         }
         $options[$c['category_id']] = $c['name'];
     }
     $this->data['categories'] = $this->html->buildSelectbox(array('type' => 'selectbox', 'name' => 'menu_categories', 'options' => $options, 'style' => 'no-save large-field'));
     $acm = new AContentManager();
     $results = $acm->getContents();
     $options = array('' => $this->language->get('text_select'));
     foreach ($results as $c) {
         if (!$c['status']) {
             continue;
         }
         $options[$c['content_id']] = $c['title'];
     }
     $this->data['pages'] = $this->html->buildSelectbox(array('type' => 'selectbox', 'name' => 'menu_information', 'options' => $options, 'style' => 'no-save large-field'));
     $this->data['button_link'] = $this->html->buildButton(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('text_link'), 'style' => 'button1'));
     $resource = new AResource('image');
     //TODO: Need to complete item_icon_rl_id
     if ($menu_item['item_icon_rl_id'] > 0) {
         $this->data['icon'] = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'image', 'wrapper_id' => 'item_icon', 'resource_id' => $menu_item['item_icon_rl_id'], 'field' => 'item_icon'));
     } else {
         $this->data['icon'] = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'image', 'wrapper_id' => 'item_icon', 'resource_id' => $resource->getIdFromHexPath(str_replace('image/', '', $menu_item['item_icon'])), 'field' => 'item_icon'));
     }
     $this->data['icon'] = $this->data['icon']->dispatchGetOutput();
     $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'storefront_menu_item', 'object_id' => $this->request->get['item_id'], 'types' => 'image', 'mode' => 'url'));
     $this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
     $this->view->batchAssign($this->language->getASet());
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('help_url', $this->gen_help_url('menu_edit'));
     $this->processTemplate('pages/design/menu_form.tpl');
 }
Example #2
0
 public function update()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('design/menu');
     if (!$this->user->canModify('listing_grid/menu')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/menu'), 'reset_value' => true));
     }
     $menu = new AMenu_Storefront();
     $item_keys = array('item_text', 'item_url', 'parent_id', 'sort_order');
     switch ($this->request->post['oper']) {
         case 'del':
             $ids = explode(',', $this->request->post['id']);
             if (!empty($ids)) {
                 $all_menu_ids = $menu->getItemIds();
                 foreach ($ids as $item_id) {
                     if (in_array($item_id, $all_menu_ids)) {
                         $menu->deleteMenuItem($item_id);
                     }
                 }
             }
             break;
         case 'save':
             $ids = explode(',', $this->request->post['id']);
             if (!empty($ids)) {
                 //resort required.
                 if ($this->request->post['resort'] == 'yes') {
                     //get only ids we need
                     foreach ($ids as $id) {
                         $array[$id] = $this->request->post['sort_order'][$id];
                     }
                     $new_sort = build_sort_order($ids, min($array), max($array), $this->request->post['sort_direction']);
                     $this->request->post['sort_order'] = $new_sort;
                 }
                 foreach ($ids as $item_id) {
                     $item_values = array();
                     foreach ($item_keys as $key) {
                         if (isset($this->request->post[$key][$item_id])) {
                             $item_values[$key] = $this->request->post[$key][$item_id];
                         }
                     }
                     // if item already in menu dataset
                     if ($menu->getMenuItem($item_id)) {
                         $menu->updateMenuItem($item_id, $item_values);
                     }
                 }
             }
             break;
         default:
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #3
0
 private function _getForm()
 {
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     $this->data['error'] = $this->error;
     $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('design/menu'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['cancel'] = $this->html->getSecureURL('design/menu');
     $language_id = $this->language->getContentLanguageID();
     $item_id = $this->request->get['item_id'];
     $menu_item = null;
     $parent_id = array();
     $this->menu_items = $this->menu->getMenuItems();
     $this->_buildMenuTree('');
     if ($item_id) {
         unset($this->menu_tree[$item_id]);
     }
     foreach ($this->menu_tree as $item) {
         $parent_id[$item['item_id']] = $item['text'];
     }
     foreach ($this->columns as $column) {
         if (isset($this->request->post[$column])) {
             $this->data[$column] = $this->request->post[$column];
         } elseif (!empty($menu_item)) {
             $this->data[$column] = $menu_item[$column];
         } else {
             $this->data[$column] = '';
         }
     }
     if (!$item_id) {
         $this->data['action'] = $this->html->getSecureURL('design/menu/insert');
         $this->data['heading_title'] = $this->language->get('text_insert') . ' ' . $this->language->get('heading_title');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         //get menu item details
         $this->data = array_merge($this->data, $this->menu->getMenuItem($item_id));
         $this->data['action'] = $this->html->getSecureURL('design/menu/update', '&item_id=' . $item_id);
         $this->data['heading_title'] = $this->language->get('text_edit') . $this->language->get('heading_title');
         $this->data['update'] = $this->html->getSecureURL('listing_grid/menu/update_field', '&id=' . $item_id);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: ', 'current' => true));
     $form->setForm(array('form_name' => 'menuFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'menuFrm', 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"', 'action' => $this->data['action']));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save')));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel')));
     $this->data['form']['fields']['item_id'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'item_id', 'value' => $this->data['item_id'], 'required' => true, 'attr' => $item_id ? 'disabled' : ''));
     $this->data['form']['fields']['item_text'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'item_text[' . $language_id . ']', 'value' => $this->data['item_text'][$language_id], 'required' => true, 'style' => 'large-field'));
     $this->data['form']['fields']['item_url'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'item_url', 'value' => $this->data['item_url'], 'style' => 'large-field', 'help_url' => $this->gen_help_url('item_url')));
     $this->data['form']['fields']['parent_id'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'parent_id', 'options' => array_merge(array('' => $this->language->get('text_none')), $parent_id), 'value' => $this->data['parent_id'], 'style' => 'medium-field'));
     $this->data['form']['fields']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'value' => $this->data['sort_order'], 'style' => 'small-field'));
     $this->data['form']['fields']['item_icon'] = $form->getFieldHtml(array('type' => 'resource', 'name' => 'item_icon', 'resource_path' => htmlspecialchars($this->data['item_icon'], ENT_COMPAT, 'UTF-8'), 'resource_id' => $this->data['item_icon_rl_id'], 'rl_type' => 'image'));
     //adds scripts for RL work
     $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'storefront_menu_item', 'object_id' => $this->request->get['item_id'], 'types' => array('image'), 'onload' => true, 'mode' => 'single'));
     $this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
     $this->loadModel('catalog/category');
     $categories = $this->model_catalog_category->getCategories(0);
     $options = array('' => $this->language->get('text_select'));
     foreach ($categories as $c) {
         if (!$c['status']) {
             continue;
         }
         $options[$c['category_id']] = $c['name'];
     }
     $this->data['form']['fields']['link_category'] = $this->html->buildElement(array('type' => 'selectbox', 'name' => 'menu_categories', 'options' => $options, 'style' => 'no-save large-field'));
     $acm = new AContentManager();
     $results = $acm->getContents();
     $options = array('' => $this->language->get('text_select'));
     foreach ($results as $c) {
         if (!$c['status']) {
             continue;
         }
         $options[$c['content_id']] = $c['title'];
     }
     $this->data['form']['fields']['link_page'] = $this->html->buildElement(array('type' => 'selectbox', 'name' => 'menu_information', 'options' => $options, 'style' => 'no-save large-field'));
     $this->data['button_link'] = $this->html->buildElement(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('text_link')));
     $this->view->batchAssign($this->language->getASet());
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('help_url', $this->gen_help_url('menu_edit'));
     $this->processTemplate('pages/design/menu_form.tpl');
 }