示例#1
0
 public function download()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if ($this->user->canAccess('tool/files')) {
         $filename = str_replace(array('../', '..\\', '\\', '/'), '', $this->request->get['filename']);
         if ($this->request->get['attribute_type'] == 'field') {
             $this->loadModel('tool/file_uploads');
             $attribute_data = $this->model_tool_file_uploads->getField($this->request->get['attribute_id']);
         } elseif (strpos($this->request->get['attribute_type'], 'AForm:') === 0) {
             // for aform fields
             $form_info = explode(':', $this->request->get['attribute_type']);
             $aform = new AForm('ST');
             $aform->loadFromDb($form_info[1]);
             $attribute_data = $aform->getField($form_info[2]);
         } elseif ($this->request->get['order_option_id']) {
             $this->loadModel('sale/order');
             $attribute_data = $this->model_sale_order->getOrderOption($this->request->get['order_option_id']);
             $attribute_data['settings'] = unserialize($attribute_data['settings']);
         } else {
             $am = new AAttribute($this->request->get['attribute_type']);
             $attribute_data = $am->getAttribute($this->request->get['attribute_id']);
         }
         if (has_value($attribute_data['settings']['directory'])) {
             $file = DIR_APP_SECTION . 'system/uploads/' . $attribute_data['settings']['directory'] . '/' . $filename;
         } else {
             $file = DIR_APP_SECTION . 'system/uploads/' . $filename;
         }
         if (file_exists($file)) {
             header('Content-Description: File Transfer');
             header('Content-Type: application/x-gzip');
             header('Content-Disposition: attachment; filename=' . $filename);
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate');
             header('Pragma: public');
             header('Content-Length: ' . filesize($file));
             ob_end_clean();
             flush();
             readfile($file);
             exit;
         } else {
             echo 'Error: File ' . $file . ' does not exists!';
             exit;
         }
     } else {
         return $this->dispatch('error/permission');
     }
 }
 public function __construct($attribute_type = '', $language_id = 0)
 {
     parent::__construct($attribute_type, $language_id);
     if (!IS_ADMIN) {
         // forbid for non admin calls
         throw new AException(AC_ERR_LOAD, 'Error: permission denied to access class AAttribute_Manager');
     }
 }
示例#3
0
 /**
  * StyleValue constructor
  *
  * @param $key string Klíč
  * @param $value mixed Hodnota
  */
 public function __construct($key, $value)
 {
     parent::__construct($key, $value);
 }
示例#4
0
 public function main()
 {
     $error_msg = array();
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if ($this->request->server['REQUEST_METHOD'] == 'GET' && isset($this->request->get['product_id'])) {
         if (isset($this->request->get['option'])) {
             $option = $this->request->get['option'];
         } else {
             $option = array();
         }
         if (isset($this->request->get['quantity'])) {
             $quantity = $this->request->get['quantity'];
         } else {
             $quantity = 1;
         }
         unset($this->session->data['shipping_methods']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['payment_methods']);
         unset($this->session->data['payment_method']);
         $this->cart->add($this->request->get['product_id'], $quantity, $option);
         $this->redirect($this->html->getSecureURL('checkout/cart'));
     } else {
         if ($this->request->server['REQUEST_METHOD'] == 'POST') {
             //if this is coupon, validate and apply
             if (isset($this->request->post['coupon']) && $this->_validateCoupon()) {
                 $this->session->data['coupon'] = $this->request->post['coupon'];
                 $this->data['success'] = $this->session->data['success'] = $this->language->get('text_coupon_success');
                 //process data
                 $this->extensions->hk_ProcessData($this);
             }
             if ($this->error['error_warning']) {
                 $error_msg[] = $this->error['error_warning'];
             }
             if (isset($this->request->post['quantity'])) {
                 if (!is_array($this->request->post['quantity'])) {
                     $this->loadModel('catalog/product');
                     $product_id = $this->request->post['product_id'];
                     if (isset($this->request->post['option'])) {
                         $options = $this->request->post['option'];
                     } else {
                         $options = array();
                     }
                     if (has_value($this->request->files['option']['name'])) {
                         $am = new AAttribute('product_option');
                         $fm = new AFile();
                         foreach ($this->request->files['option']['name'] as $id => $name) {
                             $attribute_data = $am->getAttributeByProductOptionId($id);
                             $file_path_info = $fm->getUploadFilePath($attribute_data['settings']['directory'], $name);
                             $options[$id] = $file_path_info['name'];
                             if ($text_errors = $this->model_catalog_product->validateProductOptions($product_id, $options)) {
                                 $this->session->data['error'] = implode('<br>', $text_errors);
                                 $this->redirect($_SERVER['HTTP_REFERER']);
                             } elseif (!has_value($name)) {
                                 continue;
                             }
                             $file_data = array('option_id' => $id, 'name' => $file_path_info['name'], 'path' => $file_path_info['path'], 'type' => $this->request->files['option']['type'][$id], 'tmp_name' => $this->request->files['option']['tmp_name'][$id], 'error' => $this->request->files['option']['error'][$id], 'size' => $this->request->files['option']['size'][$id]);
                             $file_errors = $fm->validateFileOption($attribute_data['settings'], $file_data);
                             if (has_value($file_errors)) {
                                 $this->session->data['error'] = implode('<br/>', $file_errors);
                                 $this->redirect($_SERVER['HTTP_REFERER']);
                             } else {
                                 $result = move_uploaded_file($file_data['tmp_name'], $file_path_info['path']);
                                 if (!$result || $this->request->files['package_file']['error']) {
                                     $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['option']['error'][$id]);
                                     $this->redirect($_SERVER['HTTP_REFERER']);
                                 }
                             }
                             $dataset = new ADataset('file_uploads', 'admin');
                             $dataset->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $file_path_info['name'], 'type' => $file_data['type'], 'section' => 'product_option', 'section_id' => $attribute_data['attribute_id'], 'path' => $file_path_info['path']));
                         }
                     }
                     if ($text_errors = $this->model_catalog_product->validateProductOptions($product_id, $options)) {
                         $this->session->data['error'] = $text_errors;
                         //send options values back via _GET
                         $url = '&' . http_build_query(array('option' => $this->request->post['option']));
                         $this->redirect($this->html->getSecureURL('product/product', '&product_id=' . $this->request->post['product_id'] . $url));
                     }
                     $this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $options);
                 } else {
                     foreach ($this->request->post['quantity'] as $key => $value) {
                         $this->cart->update($key, $value);
                     }
                 }
                 unset($this->session->data['shipping_methods']);
                 unset($this->session->data['shipping_method']);
                 unset($this->session->data['payment_methods']);
                 unset($this->session->data['payment_method']);
                 #upate min and max
                 $this->cart->setMinQty();
                 $this->cart->setMaxQty();
             }
             if (isset($this->request->post['remove'])) {
                 foreach (array_keys($this->request->post['remove']) as $key) {
                     $this->cart->remove($key);
                 }
             }
             if (isset($this->request->post['redirect'])) {
                 $this->session->data['redirect'] = $this->request->post['redirect'];
             }
             if (isset($this->request->post['quantity']) || isset($this->request->post['remove'])) {
                 unset($this->session->data['shipping_methods']);
                 unset($this->session->data['shipping_method']);
                 unset($this->session->data['payment_methods']);
                 unset($this->session->data['payment_method']);
                 $this->redirect($this->html->getSecureURL('checkout/cart'));
             }
         }
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/cart'), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator')));
     if ($this->cart->hasProducts()) {
         if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
             $error_msg[] = $this->language->get('error_stock');
         }
         $this->loadModel('tool/seo_url');
         $products = array();
         $resource = new AResource('image');
         $form = new AForm();
         $form->setForm(array('form_name' => 'cart'));
         $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'cart', 'action' => $this->html->getSecureURL('checkout/cart')));
         $cart_products = $this->cart->getProducts();
         foreach ($cart_products as $result) {
             $option_data = array();
             $thumbnail = $resource->getMainThumb('products', $result['product_id'], (int) $this->config->get('config_image_cart_width'), (int) $this->config->get('config_image_cart_height'), true);
             foreach ($result['option'] as $option) {
                 $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
             }
             $products[] = array('remove' => $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'remove[' . $result['key'] . ']')), 'key' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $thumbnail, 'option' => $option_data, 'quantity' => $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity[' . $result['key'] . ']', 'value' => $result['quantity'], 'attr' => ' size="3" ', 'style' => 'short')), 'stock' => $result['stock'], 'price' => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))), 'total' => $this->currency->format($this->tax->calculate($result['total'], $result['tax_class_id'], $this->config->get('config_tax'))), 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], true));
         }
         $this->data['products'] = $products;
         $this->data['form']['update'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_update')));
         $this->data['form']['checkout'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'checkout', 'text' => $this->language->get('button_checkout'), 'style' => 'button'));
         if ($this->config->get('config_cart_weight')) {
             $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class'));
         } else {
             $this->data['weight'] = FALSE;
         }
         $display_totals = $this->cart->buildTotalDisplay();
         $this->data['totals'] = $display_totals['total_data'];
         if (isset($this->session->data['redirect'])) {
             $this->data['continue'] = str_replace('&amp;', '&', $this->session->data['redirect']);
             unset($this->session->data['redirect']);
         } else {
             $this->data['continue'] = $this->html->getURL('index/home');
         }
         $this->data['form']['continue_shopping'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'continue_shopping', 'text' => $this->language->get('button_shopping'), 'style' => 'button', 'href' => $this->data['continue']));
         $this->data['checkout'] = $this->html->getSecureURL('checkout/shipping');
         #Check if order total max/min is set and met
         $cf_total_min = $this->config->get('total_order_minimum');
         $cf_total_max = $this->config->get('total_order_maximum');
         if (!$this->cart->hasMinRequirement()) {
             $this->data['form']['checkout'] = '';
             $error_msg[] = sprintf($this->language->get('error_order_minimum'), $this->currency->format($cf_total_min));
         }
         if (!$this->cart->hasMaxRequirement()) {
             $this->data['form']['checkout'] = '';
             $error_msg[] = sprintf($this->language->get('error_order_maximum'), $this->currency->format($cf_total_max));
         }
         //prepare coupon display
         if ($this->config->get('config_coupon_on_cart_page')) {
             $this->view->assign('coupon_status', $this->config->get('coupon_status'));
             $action = $this->html->getSecureURL('checkout/cart');
             $coupon_form = $this->dispatch('blocks/coupon_codes', array('action' => $action));
             $this->view->assign('coupon_form', $coupon_form->dispatchGetOutput());
         }
         if ($this->config->get('config_shipping_tax_estimate')) {
             $form = new AForm();
             $form->setForm(array('form_name' => 'estimate'));
             $this->data['form_estimate']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'estimate', 'action' => $this->html->getSecureURL('checkout/cart')));
             $this->data['estimates_enabled'] = true;
         }
         //try to get shipping address details if we have them
         $country_id = $this->config->get('config_country_id');
         if ($this->session->data['shipping_address_id']) {
             $this->loadModel('account/address');
             $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
             $postcode = $shipping_address['postcode'];
             $country_id = $shipping_address['country_id'];
             $zone_id = $shipping_address['zone_id'];
         }
         // use default address of customer for estimate form whe shipping address is unknown
         if (!$zone_id && $this->customer->isLogged()) {
             $this->loadModel('account/address');
             $payment_address = $this->model_account_address->getAddress($this->customer->getAddressId());
             $postcode = $payment_address['postcode'];
             $country_id = $payment_address['country_id'];
             $zone_id = $payment_address['zone_id'];
         }
         if ($this->request->post['postcode']) {
             $postcode = $this->request->post['postcode'];
         }
         if ($this->request->post['country'][0]) {
             $country_id = $this->request->post['country'][0];
         }
         if ($this->request->post['country_zones'][0]) {
             $zone_id = $this->request->post['country_zones'][0];
         }
         if ($zone_id) {
             $this->loadModel('localisation/zone');
             $zone_data = $this->model_localisation_zone->getZone($zone_id);
         }
         $this->data['form_estimate']['postcode'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'postcode', 'value' => $postcode, 'style' => 'short'));
         $this->data['form_estimate']['country_zones'] = $form->getFieldHtml(array('type' => 'zones', 'name' => 'country', 'submit_mode' => 'id', 'value' => $country_id, 'zone_name' => $zone_data['name'], 'zone_value' => $zone_id));
         $this->data['form_estimate']['submit'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_text_estimate')));
         $this->view->assign('error_warning', $error_msg);
         $this->view->setTemplate('pages/checkout/cart.tpl');
     } else {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = HtmlElementFactory::create(array('name' => 'continue', 'type' => 'button', 'text' => $this->language->get('button_continue'), 'href' => $this->html->getURL('index/home'), 'style' => 'button'));
         $this->view->setTemplate('pages/error/not_found.tpl');
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 /**
  * @param int $download_id
  * @param string $mode - can be "full" - all download attributes (with empty values too),
  * "to_customer" - download atributes with values that allowed to display for customers,
  * "to_display"  - all download atributes with values
  * @return array
  */
 public function getDownloadAttributesValues($download_id, $mode = 'full')
 {
     if (!(int) $download_id) {
         return array();
     }
     $output = array();
     $attr = new AAttribute('download_attribute');
     $attributes = $attr->getAttributes();
     $ids = array();
     foreach ($attributes as &$attribute) {
         if ($mode == 'to_customer') {
             $attribute['settings'] = unserialize($attribute['settings']);
             if (!$attribute['settings']['show_to_customer']) {
                 continue;
             }
         }
         $ids[] = (int) $attribute['attribute_id'];
         $attribute['attribute_values'] = $attr->getAttributeValues($attribute['attribute_id']);
     }
     unset($attribute);
     if ($ids) {
         $result = $this->db->query("SELECT dav.attribute_id, dav.attribute_value_ids as value\n\t\t\t\t\t\t\t\t\t\t  FROM " . $this->db->table('download_attribute_values') . " dav\n\t\t\t\t\t\t\t\t\t\t  LEFT JOIN " . $this->db->table('global_attributes') . " ga\n\t\t\t\t\t\t\t\t\t\t        ON ga.attribute_id = dav.attribute_id\n\t\t\t\t\t\t\t\t\t\t  WHERE dav.attribute_id IN (" . implode(',', $ids) . ") AND dav.download_id = '" . $download_id . "'\n\t\t\t\t\t\t\t\t\t\t  ORDER BY ga.sort_order ASC");
         $attributes_with_options = HtmlElementFactory::getElementsWithOptions();
         foreach ($result->rows as $row) {
             if (!in_array($row['attribute_id'], $ids)) {
                 continue;
             }
             $row['value'] = unserialize($row['value']);
             if (in_array($attributes[$row['attribute_id']]['element_type'], $attributes_with_options)) {
                 foreach ($attributes[$row['attribute_id']]['attribute_values'] as $values) {
                     if (is_array($row['value']) && in_array($values['attribute_value_id'], $row['value'])) {
                         // do not include empty value for display for customer
                         if (!$row['value'] && in_array($mode, array('to_customer', 'to_display'))) {
                             continue 1;
                         }
                         $output[$attributes[$row['attribute_id']]['name']][] = $values['value'];
                     } elseif (!is_array($row['value']) && $values['attribute_value_id'] == $row['value']) {
                         // do not include empty value for display for customer
                         if (!$row['value'] && in_array($mode, array('to_customer', 'to_display'))) {
                             continue 1;
                         }
                         $output[$attributes[$row['attribute_id']]['name']] = $values['value'];
                     }
                 }
             } else {
                 // do not include empty value for display for customer or admin display
                 if (!has_value($row['value']) && in_array($mode, array('to_customer', 'to_display'))) {
                     continue;
                 }
                 $output[$attributes[$row['attribute_id']]['name']] = $row['value'];
                 // for checkbox value show text yes or no
                 if ($attributes[$row['attribute_id']]['element_type'] == 'C') {
                     $output[$attributes[$row['attribute_id']]['name']] = $row['value'] ? $this->language->get('text_yes') : $this->language->get('text_no');
                 }
             }
         }
     }
     return $output;
 }
示例#6
0
 /**
  * NameValuePair constructor
  *
  * @param $key string Klíč
  * @param $value mixed Hodnota
  * @param bool $escape True, pokud se má hodnota escapovat, jinak false
  */
 public function __construct($key, $value, $escape = true)
 {
     parent::__construct($key, $value, $escape);
 }