Exemple #1
0
 /**
  * @param AForm $form
  * @param int $download_id
  * @param int $product_id
  */
 private function _buildGeneralSubform($form, $download_id, $product_id)
 {
     if ($download_id) {
         $file_data = $this->model_catalog_download->getDownload($download_id);
         $this->_validateDownloadForm($file_data);
         $this->data['error'] = $this->error;
     } else {
         $file_data = array();
         $file_data['status'] = 1;
         //set status ON for new download by default
     }
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'downloadFrm', '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' => (int) $download_id ? $this->language->get('button_save') : $this->language->get('text_add'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id), 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $order_statuses = $this->model_localisation_order_status->getOrderStatuses();
     $this->data['date_added'] = dateISO2Display($file_data['date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
     $this->data['date_modified'] = dateISO2Display($file_data['date_modified'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
     $this->data['action'] = $this->html->getSecureURL('r/product/product/processDownloadForm', '&product_id=' . $product_id);
     $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'downloads', 'object_id' => '', 'types' => array('download')));
     $this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
     $this->data['form']['fields']['general']['resource'] = $form->getFieldHtml($props[] = array('type' => 'resource', 'name' => 'filename', 'resource_path' => htmlspecialchars($file_data['filename'], ENT_COMPAT, 'UTF-8'), 'rl_type' => 'download'));
     $rl = new AResource('download');
     $rl_dir = $rl->getTypeDir();
     $resource_id = $rl->getIdFromHexPath(str_replace($rl_dir, '', $file_data['filename']));
     if ($resource_id) {
         $this->data['preview']['href'] = $this->html->getSecureURL('common/resource_library/get_resource_preview', '&resource_id=' . $resource_id, true);
         $this->data['preview']['path'] = 'resources/' . $file_data['filename'];
     }
     $this->data['form']['fields']['general']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => 1, 'checked' => $file_data['status'] ? true : false, 'style' => 'btn_switch'));
     //check is download already shared
     if ($download_id) {
         $this->data['map_list'] = array();
         $file_data['map_list'] = (array) $this->model_catalog_download->getDownloadMapList($download_id);
         foreach ($file_data['map_list'] as $map_id => $map_name) {
             if ($map_id == $product_id) {
                 continue;
             }
             $this->data['map_list'][] = array('href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $map_id . '&download_id=' . $this->data['download_id'], true), 'text' => $map_name);
         }
         if (!sizeof($this->data['map_list'])) {
             $this->data['already_shared'] = false;
         } else {
             $this->data['already_shared'] = true;
         }
     }
     $this->data['delete_unmap_href'] = $this->html->getSecureURL('catalog/product_files', '&act=' . ($file_data['shared'] ? 'unmap' : 'delete') . '&product_id=' . $product_id . '&download_id=' . $this->data['download_id'], true);
     if ($product_id) {
         $this->data['form']['fields']['general']['shared'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'shared', 'value' => 1, 'checked' => $file_data['shared'] ? true : false, 'style' => 'btn_switch ' . ($this->data['already_shared'] ? 'disabled' : '')));
     }
     if ($file_data['shared']) {
         $this->data['text_attention_shared'] = $this->language->get('attention_shared');
     }
     $this->data['form']['fields']['general']['download_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'download_id', 'value' => $this->data['download_id']));
     $this->data['form']['fields']['general']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'name', 'value' => $file_data['name'], 'attr' => ' maxlength="64" '));
     $this->data['form']['fields']['general']['mask'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'mask', 'value' => $file_data['mask']));
     $this->data['form']['fields']['general']['activate'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate', 'value' => $file_data['activate'], 'options' => array('' => $this->language->get('text_select'), 'before_order' => $this->language->get('text_before_order'), 'immediately' => $this->language->get('text_immediately'), 'order_status' => $this->language->get('text_on_order_status'), 'manually' => $this->language->get('text_manually')), 'required' => true, 'style' => 'download_activate no-save'));
     $options = array('' => $this->language->get('text_select'));
     foreach ($order_statuses as $order_status) {
         $options[$order_status['order_status_id']] = $order_status['name'];
     }
     $this->data['form']['fields']['general']['activate'] .= $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate_order_status_id', 'value' => $file_data['activate_order_status_id'], 'options' => $options, 'required' => true, 'style' => ' no-save '));
     $this->data['form']['fields']['general']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'style' => 'small-field', 'value' => $file_data['sort_order']));
     $this->data['form']['fields']['general']['max_downloads'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'max_downloads', 'value' => $file_data['max_downloads'], 'style' => 'small-field'));
     $this->data['form']['fields']['general']['expire_days'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'expire_days', 'style' => 'small-field', 'value' => $file_data['expire_days']));
 }
 public function getDefaultSettings()
 {
     $result = array();
     if (isset($this->config->settings->item)) {
         foreach ($this->config->settings->item as $item) {
             if ((string) $item['id'] == $this->name . '_status') {
                 continue;
             }
             if (in_array((string) $item->type, array('checkboxgroup', 'multiselectbox'))) {
                 $value = (string) $item->default_value;
             } else {
                 $value = $this->registry->get('html')->convertLinks(htmlentities((string) $item->default_value, ENT_QUOTES, 'UTF-8'));
             }
             if ((string) $item->type == 'resource' && $value) {
                 $resource = new AResource((string) $item->resource_type);
                 $resource_id = $resource->getIdFromHexPath(str_replace((string) $item->resource_type, '', $value));
                 $resource_info = $resource->getResource($resource_id);
                 $value = (string) $item->resource_type . '/' . $resource_info['resource_path'];
             }
             $result[(string) $item['id']] = $value;
         }
     }
     return $result;
 }
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/files');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->loadModel('catalog/product');
     $this->loadModel('catalog/download');
     $product_id = $this->request->get['product_id'];
     if (!$product_id) {
         $this->redirect($this->html->getSecureURL('catalog/product'));
     }
     if (has_value($product_id) && $this->request->is_GET()) {
         $product_info = $this->model_catalog_product->getProduct($product_id);
         if (!$product_info) {
             $this->session->data['warning'] = $this->language->get('error_product_not_found');
             $this->redirect($this->html->getSecureURL('catalog/product'));
         }
         // remove
         if (has_value($this->request->get['act']) && $this->request->get['act'] == 'delete') {
             $download_info = $this->model_catalog_download->getDownload($this->request->get['download_id']);
             $map_list = $this->model_catalog_download->getDownloadMapList($this->request->get['download_id']);
             if (sizeof($map_list) == 1 && key($map_list) == $product_id || $download_info['shared'] != 1) {
                 $this->model_catalog_download->deleteDownload($this->request->get['download_id']);
             } else {
                 $this->model_catalog_download->unmapDownload($this->request->get['download_id'], $product_id);
             }
             $this->session->data['success'] = $this->language->get('text_success_remove');
             $this->redirect($this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id));
         }
     }
     //Downloads disabled. Warn user
     if (!$this->config->get('config_download')) {
         $this->error['warning'] = $this->html->convertLinks($this->language->get('error_downloads_disabled'));
     }
     if ($this->request->is_POST() && $this->_validateForm()) {
         foreach ($this->request->post['selected'] as $id) {
             $this->model_catalog_download->mapDownload($id, $product_id);
         }
         $this->session->data['success'] = $this->language->get('text_map_success');
         $this->redirect($this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id));
     }
     $this->view->assign('error_warning', $this->error['warning']);
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($product_id);
     $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/product'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/product/update', '&product_id=' . $product_id), 'text' => $this->language->get('text_edit') . ' ' . $this->language->get('text_product') . ' - ' . $this->data['product_description'][$this->session->data['content_language_id']]['name'], 'separator' => ' :: '));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id), 'text' => $this->language->get('tab_files'), 'separator' => ' :: ', 'current' => true));
     $this->data['active'] = 'files';
     //load tabs controller
     $tabs_obj = $this->dispatch('pages/catalog/product_tabs', array($this->data));
     $this->data['product_tabs'] = $tabs_obj->dispatchGetOutput();
     unset($tabs_obj);
     $this->loadModel('catalog/download');
     $this->data['downloads'] = array();
     $this->data['product_files'] = $this->model_catalog_download->getProductDownloadsDetails($product_id);
     $rl = new AResource('download');
     $rl_dir = $rl->getTypeDir();
     foreach ($this->data['product_files'] as &$file) {
         $resource_id = $rl->getIdFromHexPath(str_replace($rl_dir, '', $file['filename']));
         $resource_info = $rl->getResource($resource_id);
         $thumbnail = $rl->getResourceThumb($resource_id, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         if ($resource_info['resource_path']) {
             $file['icon'] = $this->html->buildResourceImage(array('url' => $thumbnail, 'width' => $this->config->get('config_image_grid_width'), 'height' => $this->config->get('config_image_grid_height'), 'attr' => 'alt="' . $resource_info['title'] . '"'));
         } else {
             $file['icon'] = $resource_info['resource_code'];
         }
         $file['status'] = $file['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled');
         $file['button_edit'] = $this->html->buildElement(array('type' => 'button', 'text' => $this->language->get('button_edit'), 'href' => $this->html->getSecureURL('r/product/product/buildDownloadForm', '&product_id=' . $product_id . '&download_id=' . $file['download_id'])));
         $map_list = $this->model_catalog_download->getDownloadMapList($file['download_id']);
         if (sizeof($map_list) == 1 && key($map_list) == $product_id || $file['shared'] != 1) {
             $text = $this->language->get('button_delete');
             $icon = 'fa-trash-o';
         } else {
             $text = $this->language->get('button_unmap');
             $icon = 'fa-chain-broken';
         }
         $file['button_delete'] = $this->html->buildElement(array('type' => 'button', 'text' => $text, 'href' => $this->html->getSecureURL('catalog/product_files', '&act=delete&product_id=' . $product_id . '&download_id=' . $file['download_id']), 'icon' => $icon));
         $orders_count = $this->model_catalog_download->getTotalOrdersWithProduct($product_id);
         if ($orders_count) {
             $file['push_to_customers'] = $this->html->buildElement(array('type' => 'button', 'name' => 'push_to_customers', 'text' => sprintf($this->language->get('text_push_to_orders'), $orders_count), 'title' => $this->language->get('text_push'), 'icon' => 'fa-share-alt-square', 'href' => $this->html->getSecureURL('catalog/product_files/pushToCustomers', '&product_id=' . $product_id . '&download_id=' . $file['download_id']), 'attr' => 'data-orders-count="' . $orders_count . '"'));
         }
     }
     unset($file);
     $this->data['button_add_file'] = $this->html->buildElement(array('type' => 'button', 'text' => $this->language->get('text_add_file'), 'href' => $this->html->getSecureURL('r/product/product/buildDownloadForm', '&product_id=' . $product_id)));
     if ($this->config->get('config_embed_status')) {
         $this->data['embed_url'] = $this->html->getSecureURL('common/do_embed/product', '&product_id=' . $product_id);
     }
     $this->addChild('pages/catalog/product_summary', 'summary_form', 'pages/catalog/product_summary.tpl');
     $this->view->assign('help_url', $this->gen_help_url('product_files'));
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/catalog/product_files.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function getHtml()
 {
     if (empty($this->rl_type)) {
         throw new AException(AC_ERR_LOAD, 'Error: Could not load HTML element of resource library. Resource type not given!');
     }
     $data = array('id' => $this->element_id, 'wrapper_id' => $this->element_id . '_wrapper', 'name' => $this->name, 'resource_path' => $this->resource_path, 'resource_id' => $this->resource_id, 'object_name' => $this->object_name, 'object_id' => $this->object_id, 'rl_type' => $this->rl_type, 'hide' => $this->hide ? true : false);
     if (!$data['resource_id'] && $data['resource_path']) {
         $path = ltrim($data['resource_path'], $data['rl_type'] . '/');
         $r = new AResource($data['rl_type']);
         $data['resource_id'] = $r->getIdFromHexPath($path);
     }
     if ($data['resource_id'] && !$data['resource_path']) {
         $r = new AResource($data['rl_type']);
         $info = $r->getResource($data['resource_id']);
         $data['resource_path'] = $data['rl_type'] . '/' . $info['resource_path'];
     }
     $this->view->batchAssign($data);
     return $this->view->fetch('form/resource.tpl');
 }
Exemple #5
0
 private function _getForm()
 {
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->request->get['download_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') {
         $download_info = $this->model_catalog_download->getDownload($this->request->get['download_id']);
     }
     $this->data['error'] = $this->error;
     $this->data['language_id'] = $this->config->get('storefront_language_id');
     $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/download'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['cancel'] = $this->html->getSecureURL('catalog/download');
     if (isset($download_info['filename'])) {
         if (is_file(DIR_RESOURCE . $download_info['filename'])) {
             $rm = new AResource('archive');
             $id = $rm->getIdFromHexPath(str_replace($rm->getTypeDir(), '', $download_info['filename']));
             $this->data['download_link'] = $this->html->getSecureURL('common/resource_library/get_resource_preview', '&resource_id=' . $id);
         }
         $this->data['filename'] = $download_info['filename'];
         $this->data['mask'] = $download_info['mask'];
     } else {
         $this->data['filename'] = '';
         $this->data['mask'] = '';
     }
     if (isset($this->request->get['download_id'])) {
         $this->data['show_update'] = TRUE;
     } else {
         $this->data['show_update'] = FALSE;
     }
     if (isset($this->request->post['remaining_count'])) {
         $this->data['remaining_count'] = $this->request->post['remaining_count'];
     } elseif (isset($download_info['remaining_count'])) {
         $this->data['remaining_count'] = $download_info['remaining_count'];
     } else {
         $this->data['remaining_count'] = 1;
     }
     if (isset($this->request->post['update'])) {
         $this->data['update'] = $this->request->post['update'];
     } else {
         $this->data['update'] = FALSE;
     }
     if (!isset($this->request->get['download_id'])) {
         $this->data['action'] = $this->html->getSecureURL('catalog/download/insert');
         $this->data['heading_title'] = $this->language->get('text_insert') . $this->language->get('text_download');
         $this->data['update'] = '';
         $download_info = array('download_id' => 0);
     } else {
         $this->data['action'] = $this->html->getSecureURL('catalog/download/update', '&download_id=' . $this->request->get['download_id']);
         $this->data['heading_title'] = $this->language->get('text_edit') . $this->language->get('text_download') . ' - ' . $download_info['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/download/update_field', '&id=' . $this->request->get['download_id']);
         $download_info = $this->model_catalog_download->getDownload($this->request->get['download_id']);
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: '));
     $this->view->assign('help_url', $this->gen_help_url('download_edit'));
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('language_id', $this->session->data['content_language_id']);
     $form_html = $this->dispatch('responses/product/product/buildDownloadForm', array($download_info, 'responses/catalog/download_form.tpl'));
     $this->view->assign('form', $form_html->dispatchGetOutput());
     $this->processTemplate('pages/catalog/download_form.tpl');
 }
 public function getSettingImage($rl_image)
 {
     $image_data = array();
     if (!has_value($rl_image)) {
         return array();
     }
     $resource = new AResource('image');
     if (is_numeric($rl_image)) {
         // consider this is a pure image resource ID
         $image_data = $resource->getResource($rl_image);
     } else {
         $image_data = $resource->getResource($resource->getIdFromHexPath(str_replace('image/', '', $rl_image)));
     }
     return $image_data;
 }
Exemple #7
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');
 }
    private function _json_response()
    {
        // json-response for jqgrid
        $this->loadLanguage('catalog/download');
        $this->loadModel('catalog/download');
        $excludes = $this->session->data['multivalue_excludes'];
        $grid_filter_params = array('name');
        // if need to show all downloads of product
        if ($this->request->get['product_id']) {
            $additional_filter_string = sizeof($excludes) ? "AND p2d.download_id NOT IN (" . implode(', ', $excludes) . ")" : '';
            if (isset($this->request->get['shared_only'])) {
                $additional_filter_string .= 'AND shared=1';
            }
            $filter_grid = new AFilter(array('method' => 'post', 'grid_filter_params' => $grid_filter_params, 'additional_filter_string' => $additional_filter_string));
            $results = $this->model_catalog_download->getProductDownloadsDetails($this->request->get['product_id'], $filter_grid->getFilterData());
            $total = sizeof($results);
        } else {
            //Prepare filter config
            $additional_filter_string = sizeof($excludes) ? " d.download_id NOT IN (" . implode(', ', $excludes) . ")" : '';
            if (isset($this->request->get['shared_only'])) {
                $additional_filter_string .= 'AND shared=1';
            }
            $filter_grid = new AFilter(array('method' => 'post', 'grid_filter_params' => $grid_filter_params, 'additional_filter_string' => $additional_filter_string));
            $total = $this->model_catalog_download->getTotalDownloads($filter_grid->getFilterData());
            $results = $this->model_catalog_download->getDownloads($filter_grid->getFilterData());
        }
        $response = new stdClass();
        $response->page = $filter_grid->getParam('page');
        $response->total = $filter_grid->calcTotalPages($total);
        $response->records = $total;
        $i = 0;
        $response->userdata = (object) array('page' => $page);
        $data_type = 'download_id';
        $rl = new AResource('download');
        $rl_dir = $rl->getTypeDir();
        if ($results) {
            foreach ($results as $result) {
                $resource_id = $rl->getIdFromHexPath(str_replace($rl_dir, '', $result['filename']));
                $resource_info = $rl->getResource($resource_id);
                $thumbnail = $rl->getResourceThumb($resource_id, 27, 27);
                if ($resource_info['resource_path']) {
                    $thumbnail = $this->html->buildResourceImage(array('url' => $thumbnail, 'width' => 27, 'height' => 27, 'attr' => 'alt="' . $resource_info['title'] . '"'));
                } else {
                    $thumbnail = $resource_info['resource_code'];
                }
                $response->rows[$i]['id'] = $result['download_id'];
                $response->rows[$i]['cell'] = array($thumbnail, $result['name'], '<a class="btn_action" href="JavaScript:void(0);"
						onclick="showPopup(\'' . $this->html->getSecureURL('catalog/download/update', '&' . $data_type . '=' . $result[$data_type]) . '\')" title="' . $this->language->get('text_view') . '">' . '<img height="27" src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_view.png" alt="' . $this->language->get('text_edit') . '" /></a>');
                $i++;
            }
        }
        $this->data['response'] = AJson::encode($response);
    }
Exemple #9
0
    public function edit()
    {
        //init controller data
        $this->extensions->hk_InitData($this, __FUNCTION__);
        $this->document->addScript($this->view->templateResource('/javascript/jquery/thickbox/thickbox-compressed.js'));
        $this->document->addStyle(array('href' => $this->view->templateResource('/javascript/jquery/thickbox/thickbox.css'), 'rel' => 'stylesheet', 'media' => 'screen'));
        $this->document->resetBreadcrumbs();
        $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
        $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
        $extension = $this->request->get['extension'];
        $this->loadLanguage('extension/extensions');
        $this->loadLanguage($extension . '/' . $extension);
        $store_id = (int) $this->config->get('config_store_id');
        if ($this->request->get_or_post('store_id')) {
            $store_id = $this->request->get_or_post('store_id');
        }
        $ext = new ExtensionUtils($extension, $store_id);
        $settings = $ext->getSettings();
        $extension_info = $this->extensions->getExtensionInfo($extension);
        if (!$extension_info) {
            // if extension is not installed yet - redirect to list
            $this->redirect($this->html->getSecureURL('extension/extensions'));
        }
        /** build aform with settings**/
        $result = array('resource_field_list' => array());
        // store switcher for default store Cntrol Panel only
        if (!$this->config->get('config_store_id')) {
            $stores = array();
            $stores[0] = $this->language->get('text_default');
            $this->loadModel('setting/store');
            $stores_arr = $this->model_setting_store->getStores();
            if (count($stores_arr) > 1) {
                foreach ($stores_arr as $res) {
                    $stores[$res['store_id']] = $res['alias'];
                }
                $switcher = array('name' => 'store_id', 'type' => 'selectbox', 'options' => $stores, 'value' => $store_id, 'note' => $this->language->get('tab_store'), 'style' => 'no-save');
            } else {
                $switcher = array('type' => 'hidden', 'name' => 'store_id', 'note' => ' ', 'value' => 0);
            }
        } else {
            $switcher = array('type' => 'hidden', 'name' => 'store_id', 'note' => ' ', 'value' => $store_id);
        }
        array_unshift($settings, $switcher);
        foreach ($settings as $item) {
            $data = array();
            if ($item['name'] == $extension . '_status') {
                $status = $item['value'];
            }
            $data['name'] = $item['name'];
            $data['type'] = $item['type'];
            $data['value'] = $item['value'];
            $data['required'] = (bool) $item['required'];
            if ($item['note']) {
                $data['note'] = $item['note'];
            } else {
                $note_text = $this->language->get($data['name']);
                // if text definition not found - seek it in default settings definitions
                if ($note_text == $data['name']) {
                    $new_text_key = str_replace($extension . '_', 'text_', $data['name']);
                    $note_text = $this->language->get($new_text_key);
                    if ($note_text == $new_text_key) {
                        $note_text = $this->language->get($new_text_key . '_' . $extension_info['type']);
                    }
                }
                $data['note'] = $note_text;
            }
            if ($item['style']) {
                $data['style'] = $item['style'];
            }
            if ($item['attr']) {
                $data['attr'] = $item['attr'];
            }
            if ($item['readonly']) {
                $data['readonly'] = $item['readonly'];
            }
            switch ($data['type']) {
                case 'selectbox':
                case 'multiselectbox':
                case 'checkboxgroup':
                    // if options need to extract from db
                    $data['options'] = $item['options'];
                    if ($item['model_rt'] != '') {
                        //force to load models even before extension is enabled
                        $this->loadModel($item['model_rt'], 'force');
                        $model = $this->{'model_' . str_replace("/", "_", $item['model_rt'])};
                        $method_name = $item['method'];
                        if (method_exists($model, $method_name)) {
                            $res = call_user_func(array($model, $method_name));
                            if ($res) {
                                $field1 = $item['field1'];
                                $field2 = $item['field2'];
                                foreach ($res as $opt) {
                                    $data['options'][$opt[$field1]] = $opt[$field2];
                                }
                            }
                        }
                    }
                    if ($data['type'] == 'checkboxgroup' || $data['type'] == 'multiselectbox') {
                        #custom settings for multivalue
                        $data['scrollbox'] = 'true';
                        if (substr($item['name'], -2) != '[]') {
                            $data['name'] = $item['name'] . "[]";
                        }
                    }
                    break;
                case 'resource':
                    $item['resource_type'] = (string) $item['resource_type'];
                    if (!$result['rl_scripts']) {
                        $scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => '', 'object_id' => '', 'types' => $item['resource_type'], 'mode' => 'url'));
                        $result['rl_scripts'] = $scripts->dispatchGetOutput();
                        unset($scripts);
                    }
                    //preview of resource
                    $resource = new AResource($item['resource_type']);
                    $resource_id = $resource->getIdFromHexPath(str_replace($item['resource_type'] . '/', '', $item['value']));
                    $preview = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'image', 'wrapper_id' => $item['name'], 'resource_id' => $resource_id, 'field' => $item['name']));
                    $item['value'] = $preview->dispatchGetOutput();
                    if ($data['value']) {
                        $data = array('note' => $data['note'], 'name' => $item['name'], 'type' => 'hidden');
                        if ($resource_id) {
                            $resource_info = $resource->getResource($resource_id);
                            $data['value'] = $item['resource_type'] . '/' . $resource_info['resource_path'];
                        }
                    }
                    $result['resource_field_list'][$item['name']]['value'] = $item['value'];
                    $result['resource_field_list'][$item['name']]['resource_type'] = $item['resource_type'];
                    $result['resource_field_list'][$item['name']]['resource_id'] = $resource_id;
                    break;
                default:
            }
            $item = HtmlElementFactory::create($data);
            $result['html'][$data['name']] = array('note' => $data['note'], 'value' => $item->getHtml());
        }
        // end building aform
        $this->data['settings'] = $result['html'];
        $this->data['resource_field_list'] = $result['resource_field_list'];
        $this->data['resource_edit_link'] = $this->data['resources_scripts'] = $result['rl_scripts'];
        $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension . '&store_id=' . $store_id);
        if (isset($this->request->get['restore']) && $this->request->get['restore']) {
            $this->extension_manager->editSetting($extension, $ext->getDefaultSettings());
            $this->cache->delete('settings.extension');
            $this->session->data['success'] = $this->language->get('text_restore_success');
            $this->redirect($this->data['target_url']);
        }
        if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->_validateSettings($extension, $store_id)) {
            foreach ($settings as $item) {
                if (!isset($this->request->post[$item['name']])) {
                    $this->request->post[$item['name']] = 0;
                }
            }
            $this->extension_manager->editSetting($extension, $this->request->post);
            $this->cache->delete('settings.extension');
            $this->session->data['success'] = $this->language->get('text_success');
            $this->redirect($this->data['target_url']);
        }
        $conflict_resources = $ext->validateResources();
        if (!empty($conflict_resources)) {
            ob_start();
            print_r($conflict_resources);
            $err = ob_get_clean();
            ADebug::warning('resources conflict', AC_ERR_USER_WARNING, $extension . ' Extension resources conflict detected.<br/><pre>' . $err . '</pre>');
        }
        $this->document->setTitle($this->language->get($extension . '_name'));
        $this->document->addBreadcrumb(array('href' => $this->data['target_url'], 'text' => $this->language->get($extension . '_name'), 'separator' => ' :: '));
        $this->data['heading_title'] = $this->language->get($extension . '_name');
        $this->data['text_version'] = $this->language->get('text_version');
        $this->data['text_installed_on'] = $this->language->get('text_installed_on');
        $this->data['text_date_added'] = $this->language->get('text_date_added');
        $this->data['text_license'] = $this->language->get('text_license');
        $this->data['text_dependency'] = $this->language->get('text_dependency');
        $this->data['text_configuration_settings'] = $this->language->get('text_configuration_settings');
        $this->data['button_back'] = $this->html->buildButton(array('name' => 'btn_back', 'text' => $this->language->get('text_back'), 'style' => 'button2'));
        $this->data['button_reload'] = $this->html->buildButton(array('name' => 'btn_reload', 'text' => $this->language->get('text_reload'), 'style' => 'button2'));
        $this->data['button_restore_defaults'] = $this->html->buildButton(array('name' => 'button_restore_defaults', 'text' => $this->language->get('button_restore_defaults'), 'style' => 'button2'));
        $this->data['button_save'] = $this->html->buildButton(array('name' => 'btn_save', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
        $this->data['button_save_green'] = $this->html->buildButton(array('name' => 'btn_save', 'text' => $this->language->get('button_save'), 'style' => 'button3'));
        $this->data['button_reset'] = $this->html->buildButton(array('name' => 'btn_reset', 'text' => $this->language->get('text_reset'), 'style' => 'button2'));
        $this->data['reload'] = $this->html->getSecureURL('extension/extensions/edit/', '&extension=' . $extension);
        $this->data['back'] = $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']);
        $this->data['update'] = $this->html->getSecureURL('listing_grid/extension/update', '&id=' . $extension . '&store_id=' . $store_id);
        $this->data['dependants_url'] = $this->html->getSecureURL('listing_grid/extension/dependants');
        $form = new AForm();
        $form->setForm(array('form_name' => 'editSettings'));
        $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'editSettings', 'attr' => 'confirm-exit="true"', 'action' => $this->html->getSecureURL('extension/extensions/edit/', '&action=save&extension=' . $extension . '&store_id=' . $store_id)));
        if (!$this->extension_manager->validateDependencies($extension, getExtensionConfigXml($extension))) {
            $this->error['warning'] = 'This extension cannot be enabled because required dependency missing or not enabled.';
        }
        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }
        if (isset($this->session->data['success'])) {
            $this->data['success'] = $this->session->data['success'];
            unset($this->session->data['success']);
        } else {
            $this->data['success'] = '';
        }
        if (isset($this->session->data['error'])) {
            $this->data['error_warning'] = $this->session->data['error'];
            unset($this->session->data['error']);
        } else {
            $this->data['error'] = '';
        }
        $icon_ext_img_url = HTTP_CATALOG . 'extensions/' . $extension . '/image/icon.png';
        $icon_ext_dir = DIR_EXT . $extension . '/image/icon.png';
        $icon = is_file($icon_ext_dir) ? $icon_ext_img_url : RDIR_TEMPLATE . 'image/default_extension.png';
        $extension_data = array('id' => $extension);
        $missing_extensions = $this->extensions->getMissingExtensions();
        if (!in_array($extension, $missing_extensions)) {
            $extension_data['icon'] = $icon;
            $extension_data['name'] = $this->language->get($extension . '_name');
            $extension_data['version'] = $extension_info['version'];
            $long_datetime_format = $this->language->get('date_format_long') . ' ' . $this->language->get('time_format');
            if ($extension_info['date_installed']) {
                $extension_data['installed'] = dateISO2Display($extension_info['date_installed'], $long_datetime_format);
            }
            if ($extension_info['create_date']) {
                $extension_data['create_date'] = dateISO2Display($extension_info['create_date'], $long_datetime_format);
            }
            $extension_data['license'] = $extension_info['license_key'];
            $extension_data['note'] = $ext->getConfig('note') ? $this->html->convertLinks($this->language->get($extension . '_note')) : '';
            $config = $ext->getConfig();
            if (!empty($config->preview->item)) {
                foreach ($config->preview->item as $item) {
                    if (!is_file(DIR_EXT . $extension . DIR_EXT_IMAGE . (string) $item)) {
                        continue;
                    }
                    $extension_data['preview'][] = HTTPS_EXT . $extension . DIR_EXT_IMAGE . (string) $item;
                }
            }
            if (isset($this->session->data['extension_updates'][$extension])) {
                $extension_data['upgrade'] = array('text' => $this->html->buildButton(array('id' => 'upgradenow', 'name' => 'btn_upgrade', 'text' => $this->language->get('button_upgrade'), 'style' => 'button1')), 'link' => AEncryption::addEncoded_stid($this->session->data['extension_updates'][$extension]['url']));
            }
            $extension_data['help'] = array('text' => $this->html->buildButton(array('name' => 'btn_help', 'text' => $this->language->get('text_help'), 'style' => 'button2')), 'ext_link' => $ext->getConfig('help_link'));
            if ($ext->getConfig('help_file')) {
                $extension_data['help']['file'] = true;
                $extension_data['help']['file_link'] = $this->html->getSecureURL('extension/extension/help', '&extension=' . $this->request->get['extension']);
                $this->data['text_more_help'] = $this->language->get('text_more_help');
            }
            $extension_data['dependencies'] = array();
            $extension_data['extensions'] = $this->extensions->getEnabledExtensions();
            $missing_extensions = $this->extensions->getMissingExtensions();
            $db_extensions = $this->extensions->getDbExtensions();
            if (isset($config->dependencies->item)) {
                foreach ($config->dependencies->item as $item) {
                    $id = (string) $item;
                    if (in_array($id, $db_extensions)) {
                        if (in_array($id, $missing_extensions)) {
                            $class = 'warning';
                            $action = str_replace('%EXT%', $id, $this->language->get('text_missing_extension')) . '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id) . '"
										onclick="return confirm(\'' . $this->language->get('text_delete_confirm') . '\')" title="' . $this->language->get('text_delete') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_delete.png" alt="' . $this->language->get('text_delete') . '" />' . '</a>';
                        } else {
                            if (!$this->config->has($id . '_status')) {
                                $class = 'attention';
                                $action = '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/install', '&extension=' . $id) . '"
								title="' . $this->language->get('text_install') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_install.png" alt="' . $this->language->get('text_install') . '" />' . '</a>' . '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id) . '"
									  onclick="return confirm(\'' . $this->language->get('text_delete_confirm') . '\')" title="' . $this->language->get('text_delete') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_delete.png" alt="' . $this->language->get('text_delete') . '" />' . '</a>';
                            } else {
                                $action = '<a id="action_edit_' . $id . '" target="_blank" class="btn_action"
												href="' . $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $id) . '"
												title="' . $this->language->get('text_edit') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_edit.png" alt="' . $this->language->get('text_edit') . '" /></a>';
                                if (!(bool) $item['required']) {
                                    $action .= '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/uninstall', '&extension=' . $id) . '"
									  onclick="return confirm(\'' . str_replace('%extension%', $id, $this->language->get('text_uninstall_confirm')) . '\')"
									  title="' . $this->language->get('text_uninstall') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_uninstall.png" alt="' . $this->language->get('text_uninstall') . '" />' . '</a>';
                                }
                            }
                        }
                    } else {
                        $action = '<a href="' . $this->html->getSecureURL('extension/extensions_store', '&extension=' . $id) . '" target="_blank">';
                        $action = str_replace('%extensions_store%', $action, $this->language->get('text_visit_repository'));
                    }
                    $extension_data['dependencies'][] = array('required' => (bool) $item['required'], 'id' => $id, 'status' => ($this->config->has($id . '_status') ? $this->language->get('text_installed') : $this->language->get('text_not_installed')) . ' (' . ($this->config->get($id . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled')) . ' )', 'action' => $action, 'class' => $class);
                    unset($class);
                }
            }
        } else {
            // if extension missing
            $extension_data['icon'] = $icon;
            $extension_data['name'] = str_replace('%EXT%', $extension, $this->language->get('text_missing_extension'));
        }
        // additional settings page
        if ($ext->getConfig('additional_settings') && $status) {
            $btn_param = array('name' => 'btn_addsett', 'text' => $this->language->get('text_additional_settings'), 'style' => 'button1');
            $this->data['add_sett']['link'] = $this->html->getSecureURL($ext->getConfig('additional_settings'));
            if ($store_id) {
                $this->loadModel('setting/store');
                $store_info = $this->model_setting_store->getStore($store_id);
                $this->data['add_sett']['link'] = $store_info['config_url'] . '?s=' . ADMIN_PATH . '&rt=' . $ext->getConfig('additional_settings');
                $this->data['add_sett']['onclick'] = 'onclick="return confirm(\'' . $this->language->get('additional_settings_confirm') . '\');"';
            }
            $this->data['add_sett']['text'] = $this->html->buildButton($btn_param);
        }
        $this->data['extension'] = $extension_data;
        $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension);
        $this->view->assign('help_url', $this->gen_help_url('extension_edit'));
        $template = 'pages/extension/extensions_edit.tpl';
        //#PR set custom templates for extension settings page.
        if (has_value((string) $config->custom_settings_template)) {
            //build path to template directory.
            $dir_template = DIR_EXT . $extension . DIR_EXT_ADMIN . DIR_EXT_TEMPLATE . $this->config->get('admin_template') . "/template/";
            $dir_template .= (string) $config->custom_settings_template;
            //validate template and report issue
            if (!file_exists($dir_template)) {
                $warning = new AWarning("Cannot load override template {$dir_template} in extension {$extension}!");
                $warning->toLog()->toDebug();
            } else {
                $template = $dir_template;
            }
        }
        $this->view->batchAssign($this->data);
        $this->processTemplate($template);
        //update controller data
        $this->extensions->hk_UpdateData($this, __FUNCTION__);
    }
Exemple #10
0
 /**
  * @param AForm $form
  * @param $data
  * @return array
  */
 private function _build_appearance($form, $data)
 {
     $ret_data = array();
     $ret_data['rl'] = $this->html->getSecureURL('common/resource_library', '&type=image&mode=url');
     $resource = new AResource('image');
     $ret_data['logo'] = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'image', 'wrapper_id' => 'config_logo', 'resource_id' => $resource->getIdFromHexPath(str_replace('image/', '', $data['config_logo'])), 'field' => 'config_logo'));
     $ret_data['logo'] = $ret_data['logo']->dispatchGetOutput();
     $ret_data['icon'] = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'image', 'wrapper_id' => 'config_icon', 'resource_id' => $resource->getIdFromHexPath(str_replace('image/', '', $data['config_icon'])), 'field' => 'config_icon'));
     $ret_data['icon'] = $ret_data['icon']->dispatchGetOutput();
     $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'store', 'object_id' => '0', 'types' => 'image', 'mode' => 'url'));
     $ret_data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
     $ret_data['form'] = array('fields' => $this->conf_mngr->getFormFields('appearance', $form, $data));
     return $ret_data;
 }
Exemple #11
0
 /**
  * @param array $file_data
  * @param string $tpl
  */
 public function buildDownloadForm($file_data, $tpl)
 {
     $this->data = array();
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/files');
     $this->loadModel('localisation/order_status');
     $this->loadModel('catalog/download');
     $product_id = $file_data['product_id'];
     $order_statuses = $this->model_localisation_order_status->getOrderStatuses();
     $this->data['date_added'] = dateISO2Display($file_data['date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
     $this->data['date_modified'] = dateISO2Display($file_data['date_modified'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
     $this->data['action'] = $this->html->getSecureURL('r/product/product/processDownloadForm', '&product_id=' . $product_id);
     $this->data['form_title'] = $this->language->get('text_edit') . '&nbsp;' . $this->language->get('text_product');
     $this->data['download_id'] = (int) $file_data['download_id'];
     if ($this->data['download_id']) {
         $form = new AForm('HS');
         $this->data['update'] = $this->html->getSecureURL('listing_grid/download/update_field', '&id=' . $this->data['download_id']);
     } else {
         $form = new AForm('HT');
     }
     $form->setForm(array('form_name' => 'downloadFrm' . $file_data['download_id'], 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'downloadFrm' . $file_data['download_id'], 'attr' => 'confirm-exit="true"', 'action' => $this->data['action']));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => (int) $this->data['download_id'] ? $this->language->get('button_save') : $this->language->get('text_add'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id), 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $rl = new AResource('download');
     $rl_dir = $rl->getTypeDir();
     $resource_id = $rl->getIdFromHexPath(str_replace($rl_dir, '', $file_data['filename']));
     $resource_info = $rl->getResource($resource_id);
     $thumbnail = $rl->getResourceThumb($resource_id, 30, 30);
     if ($resource_info['resource_path']) {
         $this->data['icon'] = $this->html->buildResourceImage(array('url' => $thumbnail, 'width' => 30, 'height' => 30, 'attr' => 'alt="' . $resource_info['title'] . '"'));
     } else {
         $this->data['icon'] = $resource_info['resource_code'];
     }
     if ($resource_id) {
         $this->data['preview']['href'] = $this->html->getSecureURL('common/resource_library/get_resource_preview', '&resource_id=' . $resource_id, true);
         $this->data['preview']['path'] = 'resources/' . $file_data['filename'];
     }
     $r = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'download', 'wrapper_id' => 'download_' . (int) $this->data['download_id'], 'resource_id' => $resource_id, 'field' => 'download_rl_path_' . $this->data['download_id']));
     $this->data['resource'] = $r->dispatchGetOutput();
     $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'downloads', 'object_id' => (int) $this->data['download_id'], 'types' => 'download', 'mode' => 'url'));
     $this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
     $this->data['form']['fields']['download_rl_path'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'download_rl_path_' . $this->data['download_id'], 'value' => htmlspecialchars($file_data['filename'], ENT_COMPAT, 'UTF-8')));
     $this->data['form']['fields']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => 1, 'checked' => $file_data['status'] ? true : false, 'style' => 'btn_switch'));
     $orders_count = $this->model_catalog_download->getTotalOrdersWithProduct($product_id);
     if ($orders_count) {
         $this->data['push_to_customers'] = $this->html->buildElement(array('type' => 'button', 'name' => 'push_to_customers', 'title' => sprintf($this->language->get('text_push_to_orders'), $orders_count), 'text' => $this->language->get('text_push'), 'href' => $this->html->getSecureURL('r/product/product/pushToCustomers', '&product_id=' . $product_id . '&download_id=' . $this->data['download_id']), 'style' => 'button2', 'attr' => 'data-orders-count="' . $orders_count . '"'));
     }
     $this->data['maplist'] = array();
     $file_data['map_list'] = (array) $file_data['map_list'];
     foreach ($file_data['map_list'] as $map_id => $map_name) {
         if ($map_id == $product_id) {
             continue;
         }
         $this->data['maplist'][] = array('href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $map_id . '&download_id=' . $this->data['download_id'], true), 'text' => $map_name);
     }
     if (!sizeof($this->data['maplist'])) {
         $this->data['already_shared'] = false;
     } else {
         $this->data['already_shared'] = true;
     }
     $this->data['delete_unmap_href'] = $this->html->getSecureURL('catalog/product_files', '&act=' . ($file_data['shared'] ? 'unmap' : 'delete') . '&product_id=' . $product_id . '&download_id=' . $this->data['download_id'], true);
     $this->data['form']['fields']['shared'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'shared', 'value' => $file_data['shared'], 'attr' => $this->data['already_shared'] ? ' disabled=disabled' : ''));
     if ($file_data['shared']) {
         $this->data['text_attention_shared'] = $this->language->get('attention_shared');
     }
     $this->data['form']['fields']['download_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'download_id', 'value' => $this->data['download_id']));
     $this->data['form']['fields']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'name', 'value' => $file_data['name'], 'attr' => ' maxlength="64" '));
     $this->data['form']['fields']['mask'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'mask', 'value' => $file_data['mask']));
     $this->data['form']['fields']['max_downloads'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'max_downloads', 'value' => $file_data['max_downloads'], 'style' => 'small-field'));
     $this->data['form']['fields']['activate'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate', 'value' => $file_data['activate'], 'options' => array('' => $this->language->get('text_select'), 'before_order' => $this->language->get('text_before_order'), 'immediately' => $this->language->get('text_immediately'), 'order_status' => $this->language->get('text_on_order_status'), 'manually' => $this->language->get('text_manually')), 'required' => true, 'style' => 'download_activate no-save'));
     $options = array('' => $this->language->get('text_select'));
     foreach ($order_statuses as $order_status) {
         $options[$order_status['order_status_id']] = $order_status['name'];
     }
     $this->data['form']['fields']['order_statuses'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate_order_status_id', 'value' => $file_data['activate_order_status_id'], 'options' => $options, 'required' => true, 'style' => 'no-save'));
     $this->data['form']['fields']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'style' => 'small-field', 'value' => $file_data['sort_order']));
     $this->data['form']['fields']['expire_days'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'expire_days', 'style' => 'small-field', 'value' => $file_data['expire_days']));
     /*
      * DOWNLOAD ATTRIBUTES PIECE OF FORM
      * */
     $attributes = $this->model_catalog_download->getDownloadAttributes($this->data['download_id']);
     $elements = HtmlElementFactory::getAvailableElements();
     $html_multivalue_elements = HtmlElementFactory::getMultivalueElements();
     $html_elements_with_options = HtmlElementFactory::getElementsWithOptions();
     if (!$attributes) {
         $attr_mng = new AAttribute_Manager('download_attribute');
         $attr_type_id = $attr_mng->getAttributeTypeID('download_attribute');
         $this->data['text_no_download_attributes_yet'] = sprintf($this->language->get('text_no_download_attributes_yet'), $this->html->getSecureURL('catalog/attribute/insert', '&attribute_type_id=' . $attr_type_id));
     } else {
         foreach ($attributes as $attribute) {
             $html_type = $elements[$attribute['element_type']]['type'];
             if (!$html_type || !$attribute['status']) {
                 continue;
             }
             $values = $value = array();
             //values that was setted
             if (in_array($attribute['element_type'], $html_elements_with_options) && $attribute['element_type'] != 'R') {
                 if (is_array($attribute['selected_values'])) {
                     foreach ($attribute['selected_values'] as $val) {
                         $value[$val] = $val;
                     }
                 } else {
                     $value = $attribute['selected_values'];
                 }
             } else {
                 if (isset($attribute['selected_values'])) {
                     $value = $attribute['selected_values'];
                     if ($attribute['element_type'] == 'R' && is_array($value)) {
                         $value = current($value);
                     }
                 } else {
                     $value = $attribute['values'][0]['value'];
                 }
             }
             // possible values
             foreach ($attribute['values'] as $val) {
                 $values[$val['attribute_value_id']] = $val['value'];
             }
             if (!in_array($attribute['element_type'], $html_multivalue_elements)) {
                 $option_name = 'attributes[' . $this->data['download_id'] . '][' . $attribute['attribute_id'] . ']';
             } else {
                 $option_name = 'attributes[' . $this->data['download_id'] . '][' . $attribute['attribute_id'] . '][' . $attribute['attribute_value_id'] . ']';
             }
             $disabled = '';
             $required = $attribute['required'];
             $option_data = array('type' => $html_type, 'name' => $option_name, 'value' => $value, 'options' => $values, 'required' => $required, 'attr' => $disabled, 'style' => 'large-field');
             if ($html_type == 'checkboxgroup') {
                 $option_data['scrollbox'] = true;
             }
             $this->data['entry_attribute_' . $this->data['download_id'] . '_' . $attribute['attribute_id']] = $attribute['name'];
             $this->data['attributes'][$this->data['download_id'] . '_' . $attribute['attribute_id']] = $form->getFieldHtml($option_data);
         }
     }
     // for new download - create form for mapping shared downloads to product
     if (!$file_data['download_id']) {
         if (!$this->registry->has('jqgrid_script')) {
             $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');
             //set flag to not include scripts/css twice
             $this->registry->set('jqgrid_script', true);
         }
         $form0 = new AForm('ST');
         $form0->setForm(array('form_name' => 'SharedFrm' . $file_data['download_id'], 'update' => $this->data['update']));
         $this->data['form0']['form_open'] = $form0->getFieldHtml(array('type' => 'form', 'name' => 'SharedFrm' . $file_data['download_id'], 'attr' => 'confirm-exit="true"', 'action' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id)));
         // exclude this product from multivalue list. why we need relate recursion?
         $this->session->data['multivalue_excludes']['product_id'] = $this->request->get['product_id'];
         $this->data['form0']['fields']['list_hidden'] = $form0->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('catalog/download_listing', '&shared_only=1&form_name=SharedFrm' . $file_data['download_id'] . '&multivalue_hidden_id=popup'), 'postvars' => '', 'return_to' => '', 'popup_height' => 708, 'text' => array('selected' => $this->language->get('text_count_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->view->batchAssign($this->data);
     $this->processTemplate($tpl);
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Exemple #12
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $language_id = $this->session->data['content_language_id'];
     $this->loadLanguage('design/menu');
     $this->loadModel('tool/image');
     $model = $this->model_tool_image;
     $page = $this->request->post['page'];
     // get the requested page
     if ((int) $page < 0) {
         $page = 0;
     }
     $limit = $this->request->post['rows'];
     // get how many rows we want to have into the grid
     $sidx = $this->request->post['sidx'];
     // get index row - i.e. user click to sort
     $sord = $this->request->post['sord'];
     // get the direction
     $search_str = '';
     //process custom search form
     $this->menu = new AMenu_Storefront();
     $menu_items = $this->menu->getMenuItems();
     $new_level = 0;
     $leafnodes = array();
     //get all leave menus
     $leafnodes = $this->menu->getLeafMenus();
     //build parent id
     $menu_parent_id = '';
     if ($this->request->get['parent_id']) {
         $menu_parent_id = $this->request->get['parent_id'];
     } else {
         if ($this->request->post['nodeid']) {
             $menu_parent_id = $this->request->post['nodeid'];
             $new_level = (int) $this->request->post["n_level"] + 1;
         }
     }
     if (!empty($menu_parent_id)) {
         $menu_items = $menu_items[$menu_parent_id];
     } else {
         $menu_items = $menu_items[""];
     }
     //sort
     $allowedSort = array('item_id', 'item_text', 'sort_order');
     $allowedDirection = array(SORT_ASC => 'asc', SORT_DESC => 'desc');
     if (!in_array($sidx, $allowedSort)) {
         $sidx = $allowedSort[0];
     }
     if (!in_array($sord, $allowedDirection)) {
         $sord = SORT_ASC;
     } else {
         $sord = array_search($sord, $allowedDirection);
     }
     $sort = array();
     $total = count($menu_items);
     $response = new stdClass();
     if ($total > 0) {
         foreach ($menu_items as $item) {
             if ($sidx == 'item_text') {
                 $sort[] = $item[$sidx][$language_id];
             } else {
                 $sort[] = $item[$sidx];
             }
         }
         array_multisort($sort, $sord, $menu_items);
         $total_pages = ceil($total / $limit);
         $results = array_slice($menu_items, ($page - 1) * -$limit, $limit);
         $i = 0;
         $resource = new AResource('image');
         foreach ($results as $result) {
             $resource_id = $resource->getIdFromHexPath(str_replace('image/', '', $result['item_icon']));
             $thumb = $resource->getResourceThumb($resource_id, (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'));
             $response->rows[$i]['id'] = $result['item_id'];
             $response->rows[$i]['cell'] = array(is_file(DIR_RESOURCE . $result['item_icon']) || empty($result['item_icon']) ? '<img src="' . $thumb . '" alt="" />' : $result['item_icon'], $result['item_id'], $result['item_text'][$language_id], $this->html->buildInput(array('name' => 'sort_order[' . $result['item_id'] . ']', 'value' => $result['sort_order'])), 'action', $new_level, $menu_parent_id ? $menu_parent_id : NULL, $result['item_id'] == $leafnodes[$result['item_id']] ? true : false, false);
             $i++;
         }
     } else {
         $total_pages = 0;
     }
     $response->page = $page;
     $response->total = $total_pages;
     $response->records = $total;
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($response));
 }