Beispiel #1
0
 /**
  * @param AForm $form
  */
 private function _buildAttributesSubform($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['form']['fields']['attributes']['no_attr'] = 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'];
                 }
             }
             $checked = false;
             if ($attribute['element_type'] == 'C') {
                 if ($value) {
                     $checked = true;
                     //if value of attribute presents
                 } else {
                     $value = 1;
                 }
             }
             if ($attribute['element_type'] == 'S') {
                 $values[''] = $this->language->get('text_select');
                 // give ability to select nothing for selectbox
             }
             // 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;
             }
             if ($html_type == 'checkbox') {
                 $option_data['checked'] = $checked;
                 $option_data['style'] .= ' btn_switch';
             }
             $this->data['entry_' . $attribute['attribute_id']] = $attribute['name'];
             $this->data['form']['fields']['attributes'][$attribute['attribute_id']] = $form->getFieldHtml($option_data);
         }
     }
 }
Beispiel #2
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') . ' ' . $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__);
 }