public function block_info()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('design/blocks');
     //load specific template/page/layout
     $template = $this->request->get['template'];
     $page_id = $this->request->get['page_id'];
     $layout_id = $this->request->get['layout_id'];
     $lm = new ALayoutManager($template, $page_id, $layout_id);
     //acccept 2 type of ids. Number based and custom [block]_[custom_block]
     $custom_block_id = $this->request->get['block_id'];
     if (preg_match("/(\\d+)_(\\d+)/", $custom_block_id, $match)) {
         //take last postion of id for custom block
         $block_id = $match[1];
         $custom_block_id = $match[2];
     } else {
         if (is_numeric($custom_block_id)) {
             $block_id = $custom_block_id;
             $custom_block_id = 0;
         } else {
             //error
             $this->load->library('json');
             $this->response->addJSONHeader();
             $this->response->setOutput(AJson::encode(array('error' => 'Incorrect Block ID')));
             return null;
         }
     }
     $info = $lm->getBlockInfo((int) $block_id);
     foreach ($info as &$i) {
         $i['block_date_added'] = dateISO2Display($i['block_date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
     }
     //expect only 1 block details per layout
     $this->data = array_merge($info[0], $this->data);
     $this->data['block_info'] = $info;
     //get specific description
     if ($custom_block_id > 0) {
         $descr = $lm->getBlockDescriptions((int) $custom_block_id);
         $language_id = $this->language->getContentLanguageID();
         $this->data['title'] = $descr[$language_id]['title'];
         $this->data['description'] = $descr[$language_id]['description'];
         //detect edit URL and build button
         if ($this->data['block_txt_id'] == 'html_block' || $this->data['block_txt_id'] == 'listing_block') {
             $edit_url = $this->html->getSecureURL('design/blocks/edit', '&custom_block_id=' . $custom_block_id);
         } else {
             if ($this->data['block_txt_id'] == 'banner_block') {
                 $edit_url = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id);
             } else {
                 //just list all
                 $edit_url = $this->html->getSecureURL('design/blocks');
             }
         }
         $this->data['block_edit'] = $edit_url;
         $this->data['allow_edit'] = 'true';
     } else {
         //get details from language for static blocks from storefront
         $alang = new ALanguage($this->registry, $this->language->getContentLanguageCode(), 0);
         $alang->load($this->data['controller'], 'silent');
         $this->data['title'] = $alang->get('heading_title');
         $this->data['title'] = $this->data['title'] == 'heading_title' ? $this->data['block_txt_id'] : $this->data['title'];
     }
     $this->data['blocks_layouts'] = $lm->getBlocksLayouts($block_id, $custom_block_id);
     $this->data['text_edit'] = $this->language->get('text_edit');
     $this->data['text_close'] = $this->language->get('text_close');
     //update controller data
     $this->view->batchAssign($this->data);
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->processTemplate('responses/design/block_details.tpl');
 }
예제 #2
0
 private function _getBlockForm()
 {
     if (isset($this->session->data['warning'])) {
         $this->data['error_warning'] = $this->session->data['warning'];
         $this->session->data['warning'] = '';
     } else {
         $this->data['error_warning'] = '';
     }
     $this->load->library('json');
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $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/blocks'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['cancel'] = $this->html->getSecureURL('design/blocks');
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     // need to get data of custom listing
     $options_list = array();
     if ($custom_block_id) {
         $lm = new ALayoutManager();
         $block_info = $lm->getBlockDescriptions($custom_block_id);
         $language_id = $this->session->data['content_language_id'];
         if (!isset($block_info[$language_id])) {
             $language_id = key($block_info);
         }
         foreach ($block_info[$language_id] as $k => $v) {
             $this->data[$k] = $v;
         }
         $content = $block_info[$this->language->getContentLanguageID()]['content'];
         if ($content) {
             $content = unserialize($content);
         } else {
             $content = current($block_info);
             $content = unserialize($content['content']);
         }
         $this->data['banner_group_name'] = $content['banner_group_name'];
         $lm = new AListingManager($this->request->get['custom_block_id']);
         $list = $lm->getCustomList();
         $options_list = array();
         if ($list) {
             foreach ($list as $row) {
                 $options_list[(int) $row['id']] = array();
             }
             $ids = array_keys($options_list);
             $assigned_banners = $this->model_extension_banner_manager->getBanners(array('subsql_filter' => 'b.banner_id IN (' . implode(', ', $ids) . ')'));
             $rm = new AResourceManager();
             $rm->setType('image');
             foreach ($assigned_banners as $banner) {
                 $id = $banner['banner_id'];
                 if (in_array($id, $ids)) {
                     $thumbnail = $rm->getMainThumb('banners', $banner['banner_id'], (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), false);
                     $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i>&nbsp;';
                     $options_list[$id] = array('image' => $icon, 'id' => $id, 'name' => $banner['name'], 'sort_order' => (int) $banner['sort_order']);
                 }
             }
         }
     }
     if (!$custom_block_id) {
         $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/insert_block');
         $this->data['form_title'] = $this->language->get('text_create_block');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id);
         $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->data['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/blocks_grid/update_field', '&custom_block_id=' . $custom_block_id);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['form_title'], 'separator' => ' :: ', 'current' => true));
     $form->setForm(array('form_name' => 'BannerBlockFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'BannerBlockFrm', 'action' => $this->data['action'], 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"'));
     $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 ($custom_block_id) {
         $this->data['form']['fields']['block_status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_status', 'value' => $this->data['status'], 'style' => 'btn_switch'));
         $this->data['form']['text']['block_status'] = $this->html->convertLinks($this->language->get('entry_block_status'));
         $this->data['form']['fields']['block_status_note'] = '';
         $this->data['form']['text']['block_status_note'] = $this->html->convertLinks($this->language->get('entry_block_status_note'));
     }
     $this->data['form']['fields']['block_name'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'block_id', 'value' => $this->data['block_id']));
     $this->data['form']['fields']['block_name'] .= $form->getFieldHtml(array('type' => 'input', 'name' => 'block_name', 'value' => $this->data['name'], 'required' => true));
     $this->data['form']['text']['block_name'] = $this->language->get('entry_block_name');
     $this->data['form']['fields']['block_title'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'block_title', 'required' => true, 'value' => $this->data['title']));
     $this->data['form']['text']['block_title'] = $this->language->get('entry_block_title');
     // list of templates for block
     $tmpl_ids = $this->extensions->getInstalled('template');
     $tmpl_ids[] = 'default';
     $this->data['block_wrappers'] = array();
     foreach ($tmpl_ids as $tmpl_id) {
         // for tpls of block that stores in db
         $layout_manager = new ALayoutManager($tmpl_id);
         $block = $layout_manager->getBlockByTxtId('banner_block');
         $block_templates = (array) $layout_manager->getBlockTemplates($block['block_id']);
         foreach ($block_templates as $item) {
             if ($item['template']) {
                 $this->data['block_wrappers'][$item['template']] = $item['template'];
             }
         }
         //Automatic block template selection mode based on parent is limited to 1 template per location
         //To extend, allow custom block's template to be selected to suppress automatic selection
         //for tpls that stores in main.php (other extensions templates)
         $ext_tpls = $this->extensions->getExtensionTemplates();
         foreach ($ext_tpls as $section) {
             foreach ($section as $s => $tpls) {
                 if ($s != 'storefront') {
                     continue;
                 }
                 foreach ($tpls as $tpl) {
                     if (isset($this->data['block_wrappers'][$tpl]) || strpos($tpl, 'blocks/banner_block/') === false) {
                         continue;
                     }
                     $this->data['block_wrappers'][$tpl] = $tpl;
                 }
             }
         }
         $tpls = glob(DIR_STOREFRONT . 'view/*/template/blocks/banner_block/*.tpl');
         foreach ($tpls as $tpl) {
             $pos = strpos($tpl, 'blocks/banner_block/');
             $tpl = substr($tpl, $pos);
             if (!isset($this->data['block_wrappers'][$tpl])) {
                 $this->data['block_wrappers'][$tpl] = $tpl;
             }
         }
     }
     ksort($this->data['block_wrappers']);
     array_unshift($this->data['block_wrappers'], $this->language->get('text_automatic'));
     if ($this->data['block_wrapper'] && !isset($this->data['block_wrappers'][$this->data['block_wrapper']])) {
         $this->data['block_wrappers'] = array_merge(array($this->data['block_wrapper'] => $this->data['block_wrapper']), $this->data['block_wrappers']);
     }
     $this->data['form']['fields']['block_wrapper'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'block_wrapper', 'options' => $this->data['block_wrappers'], 'value' => $this->data['block_wrapper'], 'help_url' => $this->gen_help_url('block_wrapper')));
     $this->data['form']['text']['block_wrapper'] = $this->language->get('entry_block_wrapper');
     $this->data['form']['fields']['block_framed'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_framed', 'value' => $this->data['block_framed'], 'style' => 'btn_switch', 'help_url' => $this->gen_help_url('block_framed')));
     $this->data['form']['text']['block_framed'] = $this->language->get('entry_block_framed');
     $this->data['form']['fields']['block_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'block_description', 'value' => $this->data['description'], 'attr' => ' style="height: 50px;"'));
     $this->data['form']['text']['block_description'] = $this->language->get('entry_block_description');
     // groups of banners
     $this->loadModel('extension/banner_manager');
     $result = $this->model_extension_banner_manager->getBannerGroups();
     $groups = array('0' => $this->language->get('text_select'));
     if ($result) {
         foreach ($result as $row) {
             $groups[$row['banner_group_name']] = $row['banner_group_name'];
         }
     }
     $this->data['form']['fields']['banner_group_name'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'banner_group_name', 'options' => $groups, 'value' => $this->data['banner_group_name'], 'style' => 'no-save'));
     $this->data['form']['text']['banner_group_name'] = $this->language->get('entry_banner_group_name');
     $this->data['form']['text']['listed_banners'] = $this->language->get('entry_banners_selected');
     //load only prior saved products
     $this->data['banners'] = array();
     $this->data['form']['fields']['listed_banners'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'block_banners[]', 'value' => $ids, 'options' => $options_list, 'style' => 'no-save chosen', 'ajax_url' => $this->html->getSecureURL('listing_grid/banner_manager/banners'), 'placeholder' => $this->language->get('text_select_from_lookup')));
     $this->view->batchAssign($this->language->getASet());
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('language_code', $this->session->data['language']);
     $this->view->assign('help_url', $this->gen_help_url('banner_edit'));
     $this->view->assign('rl', $this->html->getSecureURL('common/resource_library', '&object_name=banners&type=image&mode=url'));
     $this->processTemplate('pages/extension/banner_manager_block_form.tpl');
 }
예제 #3
0
 public function block_info()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('design/blocks');
     //load specific template/page/layout
     $template = $this->request->get['template'];
     $page_id = $this->request->get['page_id'];
     $layout_id = $this->request->get['layout_id'];
     $lm = new ALayoutManager($template, $page_id, $layout_id);
     //acccept 2 type of ids. Number based and custom [block]_[custom_block]
     $custom_block_id = $this->request->get['block_id'];
     if (preg_match("/(\\d+)_(\\d+)/", $custom_block_id, $match)) {
         //take last postion of id for custom block
         $block_id = $match[1];
         $custom_block_id = $match[2];
     } else {
         //error
         $this->load->library('json');
         $this->response->addJSONHeader();
         $this->response->setOutput(AJson::encode(array('error' => 'Incorrect Block ID')));
         return null;
     }
     $info = $lm->getBlockInfo((int) $block_id);
     //expect only 1 block details per layout
     $this->data = array_merge($info[0], $this->data);
     //get specific description
     if ($custom_block_id > 0) {
         $descr = $lm->getBlockDescriptions((int) $custom_block_id);
         $language_id = $this->language->getContentLanguageID();
         $this->data['block_id'] = $block_id;
         $this->data['custom_block_id'] = $custom_block_id;
         $this->data['title'] = $descr[$language_id]['title'];
         $this->data['description'] = $descr[$language_id]['description'];
         //detect edit URL and build button
         if ($this->data['block_txt_id'] == 'html_block' || $this->data['block_txt_id'] == 'listing_block') {
             $edit_url = $this->html->getSecureURL('design/blocks/edit', '&custom_block_id=' . $custom_block_id);
         } else {
             if ($this->data['block_txt_id'] == 'banner_block') {
                 $edit_url = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id);
             } else {
                 //just list all
                 $edit_url = $this->html->getSecureURL('design/blocks');
             }
         }
         $this->data['block_edit_brn'] = $this->html->buildButton(array('type' => 'button', 'name' => 'btn_edit', 'id' => 'btn_edit', 'text' => $this->language->get('text_edit'), 'href' => $edit_url, 'target' => '_new', 'style' => 'button1'));
         $this->data['allow_edit'] = 'true';
     } else {
         //get details from language for static blocks from storefront
         $alang = new ALanguage($this->registry, $language_id, 0);
         $alang->load($this->data['controller'], 'silent');
         $this->data['title'] = $alang->get('heading_title');
         $this->data['title'] = $this->data['title'] == 'heading_title' ? $this->data['block_txt_id'] : $this->data['title'];
         $this->data['description'] = $this->language->get('text_controller') . ": " . $this->data['controller'];
         $this->data['description'] .= "<br/>" . $this->language->get('text_templates') . ": ";
         $this->data['description'] .= "<br/>" . str_replace(',', '<br/>', $this->data['templates']);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($this->data));
 }
 public function getCustomListingSubForm()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->load->library('json');
     $lm = new ALayoutManager();
     $form_name = has_value($this->request->get['form_name']) ? $this->request->get['form_name'] : 'BlockFrm';
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     $listing_datasource = $this->request->post_or_get('listing_datasource');
     // need to get data of custom listing
     if ($custom_block_id) {
         $content = $lm->getBlockDescriptions($custom_block_id);
         $content = $content[$this->language->getContentLanguageID()]['content'];
         $content = unserialize($content);
         if ($content['listing_datasource'] == $listing_datasource) {
             $lm = new AListingManager($custom_block_id);
             $list = $lm->getCustomList();
             $options_list = array();
             if ($list) {
                 foreach ($list as $row) {
                     $options_list[(int) $row['id']] = array();
                 }
                 $ids = array_keys($options_list);
                 switch ($listing_datasource) {
                     case 'custom_products':
                         $this->loadModel('catalog/product');
                         $filter = array('subsql_filter' => 'p.product_id in (' . implode(',', $ids) . ')');
                         $results = $this->model_catalog_product->getProducts($filter);
                         $id_name = 'product_id';
                         $rl_object_name = 'products';
                         break;
                     case 'custom_categories':
                         $this->loadModel('catalog/category');
                         $filter = array('subsql_filter' => 'c.category_id in (' . implode(',', $ids) . ')');
                         $results = $this->model_catalog_category->getCategoriesData($filter);
                         $id_name = 'category_id';
                         $rl_object_name = 'categories';
                         break;
                     case 'custom_manufacturers':
                         $this->loadModel('catalog/manufacturer');
                         $filter = array('subsql_filter' => 'm.manufacturer_id in (' . implode(',', $ids) . ')');
                         $results = $this->model_catalog_manufacturer->getManufacturers($filter);
                         $id_name = 'manufacturer_id';
                         $rl_object_name = 'manufacturers';
                         break;
                 }
                 $rm = new AResourceManager();
                 $rm->setType('image');
                 foreach ($results as $item) {
                     $id = $item[$id_name];
                     if (in_array($id, $ids)) {
                         $thumbnail = $rm->getMainThumb($rl_object_name, $id, (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), false);
                         $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i>&nbsp;';
                         $options_list[$id] = array('image' => $icon, 'id' => $id, 'name' => $item['name'], 'meta' => $item['model'], 'sort_order' => (int) $item['sort_order']);
                     }
                 }
             }
         }
     }
     switch ($listing_datasource) {
         case 'custom_products':
             $ajax_url = $this->html->getSecureURL('r/product/product/products');
             break;
         case 'custom_categories':
             $ajax_url = $this->html->getSecureURL('r/listing_grid/category/categories');
             break;
         case 'custom_manufacturers':
             $ajax_url = $this->html->getSecureURL('r/listing_grid/manufacturer/manufacturers');
             break;
     }
     $form = new AForm('ST');
     $form->setForm(array('form_name' => $form_name));
     $multivalue_html = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'selected[]', 'value' => $ids, 'options' => $options_list, 'style' => 'chosen', 'ajax_url' => $ajax_url, 'placeholder' => $this->language->get('text_select_from_lookup')));
     $this->view->assign('multivalue_html', $multivalue_html);
     $this->view->assign('form_name', $form_name);
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->processTemplate('responses/design/block_custom_listing_subform.tpl');
 }
예제 #5
0
 private function _getBlockForm()
 {
     if (isset($this->session->data['warning'])) {
         $this->data['error_warning'] = $this->session->data['warning'];
         $this->session->data['warning'] = '';
     } else {
         $this->data['error_warning'] = '';
     }
     $this->load->library('json');
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $locale = $this->session->data['language'];
     if (!file_exists(DIR_ROOT . '/' . RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js')) {
         $locale = 'en';
     }
     $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js');
     $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.jqGrid.min.js');
     $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/plugins/jquery.grid.fluid.js');
     $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.ba-bbq.min.js');
     $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/grid.history.js');
     $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/blocks'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['cancel'] = $this->html->getSecureURL('design/blocks');
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     // need to get data of custom listing
     $listing_data = array();
     if ($custom_block_id) {
         $lm = new ALayoutManager();
         $block_info = $lm->getBlockDescriptions($custom_block_id);
         $language_id = $this->session->data['content_language_id'];
         if (!isset($block_info[$language_id])) {
             $language_id = key($block_info);
         }
         foreach ($block_info[$language_id] as $k => $v) {
             $this->data[$k] = $v;
         }
         $content = $block_info[$this->session->data['content_language_id']]['content'];
         if ($content) {
             $content = unserialize($content);
         } else {
             $content = current($block_info);
             $content = unserialize($content['content']);
         }
         $this->data['banner_group_name'] = $content['banner_group_name'];
         $lm = new AListingManager($this->request->get['custom_block_id']);
         $list = $lm->getCustomList();
         if ($list) {
             foreach ($list as $row) {
                 $listing_data[$row['id']] = array('status' => true, 'sort_order' => $row['sort_order']);
             }
         }
     }
     if (!$custom_block_id) {
         $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/insert_block');
         $this->data['form_title'] = $this->language->get('text_create_block');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id);
         $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->data['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/blocks_grid/update_field', '&custom_block_id=' . $custom_block_id);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['form_title'], 'separator' => ' :: '));
     $form->setForm(array('form_name' => 'BannerBlockFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'BannerBlockFrm', '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 ($custom_block_id) {
         $this->data['form']['fields']['block_status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_status', 'value' => $this->data['status'], 'style' => 'btn_switch'));
         $this->data['form']['text']['block_status'] = $this->html->convertLinks($this->language->get('entry_block_status'));
         $this->data['form']['fields']['block_status_note'] = '';
         $this->data['form']['text']['block_status_note'] = $this->html->convertLinks($this->language->get('entry_block_status_note'));
     }
     $this->data['form']['fields']['block_name'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'block_id', 'value' => $this->data['block_id']));
     $this->data['form']['fields']['block_name'] .= $form->getFieldHtml(array('type' => 'input', 'name' => 'block_name', 'value' => $this->data['name'], 'required' => true));
     $this->data['form']['text']['block_name'] = $this->language->get('entry_block_name');
     $this->data['form']['fields']['block_title'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'block_title', 'required' => true, 'value' => $this->data['title']));
     $this->data['form']['text']['block_title'] = $this->language->get('entry_block_title');
     // list of templates for block
     $tmpl_ids = $this->extensions->getInstalled('template');
     $tmpl_ids[] = 'default';
     $tmpl_ids[] = 'default_html5';
     $this->data['block_wrappers'] = array();
     foreach ($tmpl_ids as $tmpl_id) {
         // for tpls of block that stores in db
         $layout_manager = new ALayoutManager($tmpl_id);
         $block = $layout_manager->getBlockByTxtId('banner_block');
         $block_templates = (array) $layout_manager->getBlockTemplates($block['block_id']);
         foreach ($block_templates as $item) {
             if ($item['template']) {
                 $this->data['block_wrappers'][$item['template']] = $item['template'];
             }
         }
         //Automatic block template selection mode based on parent is limited to 1 template per location
         //To extend, allow custom block's template to be selected to suppress automatic selection
         //for tpls that stores in main.php (other extensions templates)
         $ext_tpls = $this->extensions->getExtensionTemplates();
         foreach ($ext_tpls as $section) {
             foreach ($section as $s => $tpls) {
                 if ($s != 'storefront') {
                     continue;
                 }
                 foreach ($tpls as $tpl) {
                     if (isset($this->data['block_wrappers'][$tpl]) || strpos($tpl, 'blocks/banner_block/') === false) {
                         continue;
                     }
                     $this->data['block_wrappers'][$tpl] = $tpl;
                 }
             }
         }
         $tpls = glob(DIR_STOREFRONT . 'view/*/template/blocks/banner_block/*.tpl');
         foreach ($tpls as $tpl) {
             $pos = strpos($tpl, 'blocks/banner_block/');
             $tpl = substr($tpl, $pos);
             if (!isset($this->data['block_wrappers'][$tpl])) {
                 $this->data['block_wrappers'][$tpl] = $tpl;
             }
         }
     }
     ksort($this->data['block_wrappers']);
     array_unshift($this->data['block_wrappers'], $this->language->get('text_automatic'));
     if ($this->data['block_wrapper'] && !isset($this->data['block_wrappers'][$this->data['block_wrapper']])) {
         $this->data['block_wrappers'] = array_merge(array($this->data['block_wrapper'] => $this->data['block_wrapper']), $this->data['block_wrappers']);
     }
     $this->data['form']['fields']['block_wrapper'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'block_wrapper', 'options' => $this->data['block_wrappers'], 'value' => $this->data['block_wrapper'], 'help_url' => $this->gen_help_url('block_wrapper')));
     $this->data['form']['text']['block_wrapper'] = $this->language->get('entry_block_wrapper');
     $this->data['form']['fields']['block_framed'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_framed', 'value' => $this->data['block_framed'], 'style' => 'btn_switch', 'help_url' => $this->gen_help_url('block_framed')));
     $this->data['form']['text']['block_framed'] = $this->language->get('entry_block_framed');
     $this->data['form']['fields']['block_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'block_description', 'value' => $this->data['description'], 'attr' => ' style="height: 50px;"'));
     $this->data['form']['text']['block_description'] = $this->language->get('entry_block_description');
     // groups of banners
     $this->loadModel('extension/banner_manager');
     $result = $this->model_extension_banner_manager->getBannerGroups();
     $groups = array('0' => $this->language->get('text_select'));
     if ($result) {
         foreach ($result as $row) {
             $groups[$row['banner_group_name']] = $row['banner_group_name'];
         }
     }
     $this->data['form']['fields']['banner_group_name'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'banner_group_name', 'options' => $groups, 'value' => $this->data['banner_group_name'], 'style' => 'no-save'));
     $this->data['form']['text']['banner_group_name'] = $this->language->get('entry_banner_group_name');
     //single banners
     $this->data['form']['fields']['listed_banners'] = $form->getFieldHtml(array('id' => 'popup', 'type' => 'multivalue', 'name' => 'popup', 'title' => $this->language->get('text_select_from_list'), 'selected' => $listing_data ? AJson::encode($listing_data) : "{}", 'content_url' => $this->html->getSecureUrl('listing_grid/banner_manager/getlisting', '&custom_block_id=' . $custom_block_id), 'return_to' => '', 'no_save' => $custom_block_id ? false : true, 'text' => array('selected' => $this->language->get('text_selected'), 'edit' => $this->language->get('text_save_edit'), 'apply' => $this->language->get('text_apply'), 'save' => $this->language->get('button_save'), 'reset' => $this->language->get('button_reset'))));
     $this->data['form']['text']['listed_banners'] = $this->language->get('entry_banners_selected');
     $this->view->batchAssign($this->language->getASet());
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('language_code', $this->session->data['language']);
     $this->view->assign('help_url', $this->gen_help_url('banner_edit'));
     $this->view->assign('rl', $this->html->getSecureURL('common/resource_library', '&object_name=banners&type=image&mode=url'));
     $this->processTemplate('pages/extension/banner_manager_block_form.tpl');
 }
예제 #6
0
 private function _getBlockForm()
 {
     if (isset($this->session->data['warning'])) {
         $this->data['error_warning'] = $this->session->data['warning'];
         $this->session->data['warning'] = '';
     } else {
         $this->data['error_warning'] = '';
     }
     $this->load->library('json');
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $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/blocks'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['cancel'] = $this->html->getSecureURL('design/blocks');
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     // need to get data of custom listing
     $listing_data = array();
     if ($custom_block_id) {
         $lm = new ALayoutManager();
         $block_info = $lm->getBlockDescriptions($custom_block_id);
         $language_id = $this->language->getContentLanguageID();
         if (!isset($block_info[$language_id])) {
             $language_id = key($block_info);
         }
         foreach ($block_info[$language_id] as $k => $v) {
             $this->data[$k] = $v;
         }
         $content = $block_info[$this->language->getContentLanguageID()]['content'];
         if ($content) {
             $content = unserialize($content);
         } else {
             $content = current($block_info);
             $content = unserialize($content['content']);
         }
         $this->data['form_id'] = $content['form_id'];
         $lm = new AListingManager($this->request->get['custom_block_id']);
         $list = $lm->getCustomList();
         if ($list) {
             foreach ($list as $row) {
                 $listing_data[$row['id']] = array('status' => true, 'sort_order' => $row['sort_order']);
             }
         }
     }
     if (!$custom_block_id) {
         $this->data['action'] = $this->html->getSecureURL('tool/forms_manager/insert_block');
         $this->data['form_title'] = $this->language->get('text_create_block', 'forms_manager/forms_manager');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('tool/forms_manager/edit_block', '&custom_block_id=' . $custom_block_id);
         $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->data['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/blocks_grid/update_field', '&custom_block_id=' . $custom_block_id);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['form_title'], 'separator' => ' :: ', 'current' => true));
     $form->setForm(array('form_name' => 'CustomFormBlockFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'CustomFormBlockFrm', 'action' => $this->data['action'], 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"'));
     $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 ($custom_block_id) {
         $this->data['form']['fields']['block_status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_status', 'value' => $this->data['status'], 'style' => 'btn_switch'));
         $this->data['entry_block_status_note'] = $this->html->convertLinks($this->language->get('entry_block_status_note'));
         $this->data['form']['fields']['block_status_note'] = '';
         $this->data['entry_block_status_note'] = $this->html->convertLinks($this->language->get('entry_block_status_note'));
     }
     $this->data['form']['fields']['block_name'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'block_id', 'value' => $this->data['block_id']));
     $this->data['form']['fields']['block_name'] .= $form->getFieldHtml(array('type' => 'input', 'name' => 'block_name', 'value' => $this->data['name'], 'required' => true));
     $this->data['form']['text']['block_name'] = $this->language->get('entry_block_name');
     $this->data['form']['fields']['block_title'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'block_title', 'required' => true, 'value' => $this->data['title']));
     $this->data['form']['text']['block_title'] = $this->language->get('entry_block_title');
     // list of templates for block
     $tmpl_ids = $this->extensions->getInstalled('template');
     array_unshift($tmpl_ids, (string) $this->session->data['layout_params']['tmpl_id']);
     $this->data['block_wrappers'] = array();
     foreach ($tmpl_ids as $tmpl_id) {
         $layout_manager = new ALayoutManager($tmpl_id);
         $block = $layout_manager->getBlockByTxtId('custom_form_block');
         $block_templates = (array) $layout_manager->getBlockTemplates($block['block_id']);
         foreach ($block_templates as $item) {
             $this->data['block_wrappers'][$item['template']] = $item['template'];
         }
     }
     array_unshift($this->data['block_wrappers'], 'Default');
     $this->data['form']['fields']['block_wrapper'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'block_wrapper', 'options' => $this->data['block_wrappers'], 'value' => $this->data['block_wrapper'], 'help_url' => $this->gen_help_url('block_wrapper')));
     $this->data['form']['text']['block_wrapper'] = $this->language->get('entry_block_wrapper');
     $this->data['form']['fields']['block_framed'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_framed', 'value' => $this->data['block_framed'], 'style' => 'btn_switch', 'help_url' => $this->gen_help_url('block_framed')));
     $this->data['form']['text']['block_framed'] = $this->language->get('entry_block_framed');
     $this->data['form']['fields']['block_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'block_description', 'value' => $this->data['description'], 'attr' => ' style="height: 50px;"'));
     $this->data['form']['text']['block_description'] = $this->language->get('entry_block_description');
     $result = $this->model_tool_forms_manager->getForms(array('filter' => array('status' => 1)));
     $forms = array();
     if ($result) {
         foreach ($result as $row) {
             $forms[$row['form_id']] = $row['form_name'];
         }
     }
     $this->data['form']['fields']['form'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'form_id', 'options' => $forms, 'value' => $this->data['form_id'], 'style' => 'no-save', 'attr' => 'multiple="multiple"'));
     $this->data['form']['text']['form'] = $this->language->get('text_form');
     $this->data['note'] = sprintf($this->language->get('note_edit_layout'), $this->html->getSecureURL('design/layout'), $this->html->getSecureURL('tool/forms_manager'));
     $this->view->batchAssign($this->language->getASet());
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('language_code', $this->session->data['language']);
     $this->view->assign('help_url', $this->gen_help_url('form_block_edit'));
     $this->processTemplate('pages/tool/forms_manager_block_form.tpl');
 }
 public function edit()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->setTitle($this->language->get('heading_title'));
     if (is_int(strpos($this->request->get['custom_block_id'], '_'))) {
         $t = explode('_', $this->request->get['custom_block_id']);
         $custom_block_id = $t[1];
     } else {
         $custom_block_id = (int) $this->request->get['custom_block_id'];
     }
     // now need to know what custom block is this
     $lm = new ALayoutManager();
     $blocks = $lm->getAllBlocks();
     foreach ($blocks as $block) {
         if ($block['custom_block_id'] == $custom_block_id) {
             $block_txt_id = $block['block_txt_id'];
             break;
         }
     }
     $layout = new ALayoutManager();
     // saving
     if ($this->request->is_POST() && $this->_validateForm()) {
         switch ($block_txt_id) {
             case 'listing_block':
                 $content = array('listing_datasource' => $this->request->post['listing_datasource']);
                 $listing_manager = new AListingManager($custom_block_id);
                 // need to check previous listing_datasource of that block
                 $block_info = $lm->getBlockDescriptions($custom_block_id);
                 $block_info = current($block_info);
                 $block_info['content'] = unserialize($block_info['content']);
                 // if datasource changed - drop custom list
                 if ($block_info['content']['listing_datasource'] != $content['listing_datasource']) {
                     $listing_manager->deleteCustomListing();
                 }
                 if (strpos($content['listing_datasource'], 'custom_') !== FALSE) {
                     if ($this->request->post['selected']) {
                         $listing_manager->deleteCustomListing();
                         $k = 0;
                         foreach ($this->request->post['selected'] as $id) {
                             $listing_manager->saveCustomListItem(array('listing_datasource' => $content['listing_datasource'], 'id' => $id, 'limit' => $this->request->post['limit'], 'sort_order' => $k));
                             $k++;
                         }
                     }
                 } else {
                     if ($content['listing_datasource'] == 'media') {
                         $content['resource_type'] = $this->request->post['resource_type'];
                     }
                     $content['limit'] = $this->request->post['limit'];
                 }
                 $content = serialize($content);
                 break;
             case 'html_block':
                 $content = $this->request->post['block_content'];
                 break;
             default:
                 $this->redirect($this->html->getSecureURL('design/blocks'));
                 break;
         }
         $layout->saveBlockDescription(0, $custom_block_id, array('name' => $this->request->post['block_name'], 'title' => $this->request->post['block_title'], 'description' => $this->request->post['block_description'], 'content' => $content, 'block_wrapper' => $this->request->post['block_wrapper'], 'block_framed' => (int) $this->request->post['block_framed'], 'language_id' => $this->session->data['content_language_id']));
         $layout->editBlockStatus((int) $this->request->post['block_status'], 0, $custom_block_id);
         $this->session->data['success'] = $this->language->get('text_success');
         $this->redirect($this->html->getSecureURL('design/blocks/edit', '&custom_block_id=' . $custom_block_id));
     }
     // end of saving
     $info = $layout->getBlockDescriptions($custom_block_id);
     if (isset($info[$this->session->data['content_language_id']])) {
         $info = $info[$this->session->data['content_language_id']];
     } else {
         $info = current($info);
         unset($info['name'], $info['title'], $info['description']);
     }
     foreach ($info as $k => $v) {
         $this->data[$k] = $v;
     }
     $this->data['tabs'][0] = array('href' => '', 'text' => $this->language->get('text_' . $block_txt_id), 'active' => true);
     switch ($block_txt_id) {
         case 'listing_block':
             $this->_getListingForm();
             break;
         case 'html_block':
         default:
             $this->_getHTMLForm();
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }