Example #1
0
 public function initContent()
 {
     $log = null;
     $this->display_header = false;
     $this->display_footer = false;
     parent::initContent();
     $transaction = Tools::getValue('transaction');
     if (Tools::isEmpty($transaction)) {
         die(Tools::displayError('Wrong use of the HTTP notifications. Please set up your sofortüberweisung.de notification to call this URL only with POST method.'));
     }
     $orderState = _PS_OS_PAYMENT_;
     $baseDir = dirname(__FILE__);
     $useSSL = true;
     // Get class instance
     $su = new Sofortueberweisung();
     // Set order state to "awaiting payment"
     $orderState = Configuration::get('_SU_OS_OK_');
     $cartId = 0;
     // Check incoming response
     if ($su->checkResponse($_POST, $log)) {
         // Get cartId from the response
         $cartId = (int) Tools::getValue('user_variable_0');
         // Get the cart object
         $cart = new Cart($cartId);
         // Get the customer object
         $customer = new Customer((int) $cart->id_customer);
         // Get order sum
         $orderSum = (double) Tools::getValue('amount');
         $currency_special = $cart->id_currency;
         $message = 'Payment through Sofortüberweisung.de - Transaction-ID: ' . $transaction . ' ';
         $secure_key = $customer->secure_key;
         // Create order
         $su->updateOrder($cartId, $orderState, $orderSum, $message, $currency_special, $secure_key);
     }
 }
Example #2
0
 public function getView($params, $synchrone)
 {
     $form = new Form($this->fields, $params);
     $title = '';
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         $access_key = isset($params['access_key']) && !empty($params['access_key']) ? Tools::saltHash($params['access_key']) : 'NULL';
         // Create Game
         $game = Game::create(F::i('Session')->getMid(), $params['name'], $access_key);
         Tools::redirect('?action=wait_game&game=' . $game->g_id);
     } else {
         // Generate form
         $view = View::setFile('formular', View::HTML_FILE);
         $errors = $form->getErrors();
         // Errors in the filling
         if (!empty($errors)) {
             $view->setSwitch('form_errors', TRUE);
             foreach ($errors as $field => $error) {
                 $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
             }
         }
         $view->setValue('form', $form->getHTML(F::i('Lang')->getKey('Create'), '#', 'POST', 'tabbed_form'));
         $title = F::i('Lang')->getKey('title_new_game');
     }
     return parent::setBody($view, $title);
 }
 public function initContent()
 {
     parent::initContent();
     //EJEMPLO;APELLIDO2-EJEMPLO&COTITULAR=033333333P;COTITU-EJEMPLO;COTITU-APE1-
     //EJEMPLO;COTITU-APE2-EJEMPLO
     //$code =
     $cart = $this->context->cart;
     include dirname(__FILE__) . '/cripto.php';
     //		$url= 'http://prufrc.ebiosphere.com/WebComercios/Online/index.jsp?';
     $url = 'https://comercios.fracciona.com/Online/index.jsp?';
     $url .= encriptar('NPEDIDO') . '=' . encriptar($this->context->cookie->cod_frac) . '&';
     $url .= encriptar('IMPORTE') . '=';
     $url .= encriptar($cart->getOrderTotal(true, Cart::BOTH)) . '&';
     $url .= encriptar('CODVENDEDOR') . '=';
     $url .= encriptar(Configuration::get('FRACC_CODE')) . '&';
     $url .= encriptar('TITULAR') . '=' . encriptar(Tools::getValue('dni')) . ';';
     $url .= encriptar(Tools::getValue('nombre')) . ';' . encriptar(Tools::getValue('apellidoFirst')) . ';';
     $url .= encriptar(Tools::getValue('apellidoLast')) . '&';
     $url .= encriptar('EMAIL') . '=' . encriptar(Tools::getValue('email'));
     if (!Tools::isEmpty(Tools::getValue('nombre2'))) {
         $url .= encriptar('&COTITULAR') . '=' . encriptar(Tools::getValue('dni2')) . ';';
         $url .= encriptar(Tools::getValue('nombre2')) . ';' . encriptar(Tools::getValue('apellidoFirst2')) . ';';
         $url .= encriptar(Tools::getValue('apellidoLast2')) . '&' . encriptar(Tools::getValue('email2'));
     }
     //echo $url;
     Tools::redirect($url);
 }
Example #4
0
 public function getView($params, $synchrone)
 {
     $form = new Form(self::getFields(), $params);
     $view = View::setFile('chatbox', View::JSON_FILE);
     $fields = Chatbox::getFields();
     if (F::i('Session')->isConnected()) {
         $fields['name']['disabled'] = TRUE;
     }
     $errors = $form->getErrors();
     if (!Tools::isEmpty($errors)) {
         foreach ($errors as $field => $msg) {
             $view->setGroupValues('error', array('field' => $field, 'errmsg' => $msg));
         }
     }
     // If Submitting
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         // TODO Sauvegarde du pseudo en cookie
         // Enregistrement des données
         if (F::i('Session')->isConnected()) {
             $m_name = '';
         } else {
             $m_name = $params['name'];
             self::setNickname($m_name);
         }
         F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_chatbox_messages (m_id, m_name, mes_content) VALUES (?, ?, ?)', array(F::i('Session')->getMid(), $m_name, $params['content']));
         // Et sortie
         return;
     }
     // Recuperation des derniers messages
     $sql = 'SELECT mes.m_name, m.m_login, mes.m_id, mes_content, UNIX_TIMESTAMP(mes_date) AS mes_date FROM !prefix_chatbox_messages mes, !prefix_members m WHERE m.m_id = mes.m_id';
     $array = array();
     // si une date est donnée, tous les messages depuis cette date
     if (isset($params['since'])) {
         $sql .= ' AND mes_date > FROM_UNIXTIME(?)';
         $array[] = $params['since'];
     }
     // sinon, limiter à _LIMIT_LAST_CHATBOX messages
     $sql .= ' ORDER BY mes_date DESC';
     if (!isset($params['since'])) {
         $sql .= ' LIMIT ?';
         $array[] = _LIMIT_LAST_CHATBOX;
     }
     // Generation d'un pseudo si non connecté et pseudo non fourni
     // Si connecté, verouiller le pseudo
     $result = F::i(_DBMS_SYS)->query($sql, $array);
     // Recover messages and switch the order to get the last _LIMIT_LAST_CHATBOX messages but the last at the end.
     $messages = array();
     for ($i = 0; $i < $result->getNumRows(); $i++) {
         $obj = $result->getObject();
         $messages[] = array('author_mid' => $obj->m_id, 'author_name' => $obj->m_id == _ID_VISITOR ? $obj->m_name : $obj->m_login, 'content' => htmlentities($obj->mes_content, ENT_QUOTES, 'UTF-8', TRUE), 'date' => $obj->mes_date);
     }
     $messages = array_reverse($messages);
     for ($i = 0; $i < count($messages); $i++) {
         $view->setGroupValues('message', $messages[$i]);
     }
     return $view->getContent();
 }
 protected function processGetContent()
 {
     $id = Tools::getValue('PromotionId');
     if ($id == '0' || Tools::isEmpty($id)) {
         exit;
     }
     $promotion = new Promotion();
     $promotion->getById($id);
     $fields = $promotion->getAsArray();
     echo json_encode($fields);
     exit;
 }
 public function returnPaymentConfiguration($params)
 {
     $this->context = Context::getContext();
     if (!Tools::isEmpty($params['objOrder']) && $params['objOrder']->module === 'pagseguro') {
         $this->context->smarty->assign(array('total_to_pay' => Tools::displayPrice($params['objOrder']->total_paid, $this->context->currency->id, false), 'status' => 'ok', 'id_order' => (int) $params['objOrder']->id));
         if (isset($params['objOrder']->reference) && !Tools::isEmpty($params['objOrder']->reference)) {
             $this->context->smarty->assign('reference', $params['objOrder']->reference);
         }
     } else {
         $this->context->smarty->assign('status', 'failed');
     }
 }
Example #7
0
 public function __construct($id_service, $filename = false)
 {
     $this->name = Tools::isEmpty($this->name) ? 'Unknown Export Engine' : $this->name;
     if (Validate::isUnsignedId($id_service)) {
         $this->service_id = (int) $id_service;
         if (!$filename) {
             $filename = sha1($this->getServiceName() . _COOKIE_KEY_);
         }
         $this->filename = _PS_ROOT_DIR_ . '/modules/moussiqfree/export/' . $filename . '.' . $this->extension;
         self::$_link = new Link();
         self::$_serviceData = self::getCsvDefaults((int) $id_service);
     }
 }
 public function widgetShow($params)
 {
     global $smarty, $cookie;
     $linkTpl = '
     <a href="%1$s" class="widgetctooltip%4$s" rel="cms_%3$d">%2$s</a>';
     $additionalParams = '';
     foreach (self::$_additionalParams as $prefix => $param) {
         if (isset($params[$param])) {
             $additionalParams .= ' ' . $prefix . $params[$param];
         }
     }
     $cms = self::getShortCMSInfo($params['id'], $cookie->id_lang);
     if (!Tools::isEmpty($cms['meta_title'])) {
         $widgetPath = $this->widgetUri();
         $this->setCss($widgetPath . 'css/style.css');
         $this->setJs($widgetPath . 'js/tooltip.js');
         $link = new Link();
         return sprintf($linkTpl, $link->getCMSLink($params['id'], $cms['link_rewrite']), $cms['meta_title'], $params['id'], $additionalParams);
     }
 }
 public function preProcess()
 {
     //parent::preProcess();
     $id = Tools::getValue('PromotionId');
     if ($id == '0' || Tools::isEmpty($id)) {
         exit;
     }
     $promotion = new Promotion();
     $promotion->getById($id);
     //promotion list navigation
     $navi_url = "promotionlist.php?type=" . $promotion->Type;
     $navi_name = $promotion->Type == Promotion::$TYPE_PROMOTION ? 'Promotion List' : 'Event List';
     $this->brandNavi[] = array("name" => $navi_name, "url" => $navi_url);
     //promotoin detail navigation
     $navi_url = $this->php_self . "?PromotionId=" . $id;
     $navi_name = $promotion->Title;
     $this->brandNavi[] = array("name" => $promotion->Title, "url" => $navi_url, "nolang" => 1);
     $fields = $promotion->getAsArray();
     $fields['Content'] = urldecode($fields['Content']);
     self::$smarty->assign("data", $fields);
 }
Example #10
0
 public function getView($params, $synchrone)
 {
     $form = new Form($this->fields, $params);
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         // Register
         $salt = Tools::generateSalt();
         $password = Tools::saltHash($params['password'], $salt);
         $error = FALSE;
         try {
             F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_members (m_login, m_password, m_email, m_salt, m_auth) VALUES (?, ?, ?, ?, ?)', array($params['login'], $password, $params['email'], $salt, _AUTH_MEMBER));
         } catch (DBMSError $e) {
             // Login already given
             $error = TRUE;
         }
         if (!$error) {
             $view = View::setFile('info', View::HTML_FILE);
             $view->setValue('L_message', F::i('Lang')->getKey('register_successful'));
             $view->setValue('U_ok', '?');
             F::i('Session')->connect($params['login'], $params['password']);
         } else {
             $view = View::setFile('error', View::HTML_FILE);
             $view->setValue('l_message', F::i('Lang')->getKey('login_taken'));
             $view->setValue('u_ok', '?');
         }
     } else {
         $view = View::setFile('formular', View::HTML_FILE);
         $errors = $form->getErrors();
         // Errors in the filling
         if (!empty($errors)) {
             $view->setSwitch('form_errors', TRUE);
             foreach ($errors as $field => $error) {
                 $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
             }
         }
         $view->setValue('form', $form->getHTML(F::i('Lang')->getKey('register'), '#', 'POST', 'tabbed_form'));
     }
     return parent::setBody($view);
 }
 public function processProductAttribute()
 {
     // Don't process if the combination fields have not been submitted
     if (!Combination::isFeatureActive() || !Tools::getValue('attribute_combination_list')) {
         return;
     }
     if (Validate::isLoadedObject($product = $this->object)) {
         if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null)) {
             $this->errors[] = Tools::displayError('Attribute price required.');
         }
         if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list'))) {
             $this->errors[] = Tools::displayError('You must add at least one attribute.');
         }
         if (!count($this->errors)) {
             if (!isset($_POST['attribute_wholesale_price'])) {
                 $_POST['attribute_wholesale_price'] = 0;
             }
             if (!isset($_POST['attribute_price_impact'])) {
                 $_POST['attribute_price_impact'] = 0;
             }
             if (!isset($_POST['attribute_weight_impact'])) {
                 $_POST['attribute_weight_impact'] = 0;
             }
             if (!isset($_POST['attribute_ecotax'])) {
                 $_POST['attribute_ecotax'] = 0;
             }
             if (Tools::getValue('attribute_default')) {
                 $product->deleteDefaultAttributes();
             }
             // Change existing one
             if (($id_product_attribute = (int) Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true))) {
                 if ($this->tabAccess['edit'] === '1') {
                     if ($this->isProductFieldUpdated('available_date_attribute') && !Validate::isDateFormat(Tools::getValue('available_date_attribute'))) {
                         $this->errors[] = Tools::displayError('Invalid date format.');
                     } else {
                         $product->updateAttribute((int) $id_product_attribute, $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_ean13'), $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false);
                         StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
                         StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You do not have permission to add here.');
                 }
             } else {
                 if ($this->tabAccess['add'] === '1') {
                     if ($product->productAttributeExists(Tools::getValue('attribute_combination_list'))) {
                         $this->errors[] = Tools::displayError('This combination already exists.');
                     } else {
                         $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), 0, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), null, Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'));
                         StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
                         StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('Edit here.');
                 }
             }
             if (!count($this->errors)) {
                 $combination = new Combination((int) $id_product_attribute);
                 $combination->setAttributes(Tools::getValue('attribute_combination_list'));
                 $product->checkDefaultAttributes();
             }
             if (!count($this->errors)) {
                 if (!$product->cache_default_attribute) {
                     Product::updateDefaultAttribute($product->id);
                 }
             }
         }
     }
 }
 /**
  * Check if PagSeguro order status already exists on database
  * @param String $status
  * @return boolean
  */
 private function _checkIfOrderStatusExists($id_lang, $status_name)
 {
     if (Tools::isEmpty($this->list_states)) {
         return true;
     }
     $save = true;
     foreach ($this->list_states as $state) {
         if ($state['id_lang'] == $id_lang && $state['name'] == $status_name) {
             $save = false;
         }
     }
     return $save;
 }
    protected function addItem()
    {
        $title = Tools::getValue('item_title');
        $content = Tools::getValue('item_html');
        if (!Validate::isCleanHtml($title, (int) Configuration::get('PS_ALLOW_HTML_IFRAME')) || !Validate::isCleanHtml($content, (int) Configuration::get('PS_ALLOW_HTML_IFRAME'))) {
            $this->context->smarty->assign('error', $this->l('Invalid content'));
            return false;
        }
        if (!($current_order = (int) Db::getInstance()->getValue('
			SELECT item_order + 1
			FROM `' . _DB_PREFIX_ . 'themeconfigurator`
			WHERE
				id_shop = ' . (int) $this->context->shop->id . '
				AND id_lang = ' . (int) Tools::getValue('id_lang') . '
				AND hook = \'' . pSQL(Tools::getValue('item_hook')) . '\'
				ORDER BY item_order DESC'))) {
            $current_order = 1;
        }
        $image_w = is_numeric(Tools::getValue('item_img_w')) ? (int) Tools::getValue('item_img_w') : '';
        $image_h = is_numeric(Tools::getValue('item_img_h')) ? (int) Tools::getValue('item_img_h') : '';
        if (!empty($_FILES['item_img']['name'])) {
            if (!($image = $this->uploadImage($_FILES['item_img'], $image_w, $image_h))) {
                return false;
            }
        } else {
            $image = '';
            $image_w = '';
            $image_h = '';
        }
        if (!Db::getInstance()->Execute('
			INSERT INTO `' . _DB_PREFIX_ . 'themeconfigurator` (
					`id_shop`, `id_lang`, `item_order`, `title`, `title_use`, `hook`, `url`, `target`, `image`, `image_w`, `image_h`, `html`, `active`
			) VALUES (
					\'' . (int) $this->context->shop->id . '\',
					\'' . (int) Tools::getValue('id_lang') . '\',
					\'' . (int) $current_order . '\',
					\'' . pSQL($title) . '\',
					\'' . (int) Tools::getValue('item_title_use') . '\',
					\'' . pSQL(Tools::getValue('item_hook')) . '\',
					\'' . pSQL(Tools::getValue('item_url')) . '\',
					\'' . (int) Tools::getValue('item_target') . '\',
					\'' . pSQL($image) . '\',
					\'' . pSQL($image_w) . '\',
					\'' . pSQL($image_h) . '\',
					\'' . pSQL($this->filterVar($content), true) . '\',
					1)')) {
            if (!Tools::isEmpty($image)) {
                $this->deleteImage($image);
            }
            $this->context->smarty->assign('error', $this->l('An error occurred while saving data.'));
            return false;
        }
        $this->context->smarty->assign('confirmation', $this->l('New item successfully added.'));
        return true;
    }
Example #14
0
 /**
  * Validate a single field
  *
  * @since 1.5.0.1
  * @param string   $field        Field name
  * @param mixed    $value        Field value
  * @param int|null $id_lang      Language ID
  * @param array    $skip         Array of fields to skip.
  * @param bool     $human_errors If true, uses more descriptive, translatable error strings.
  *
  * @return true|string True or error message string.
  * @throws PrestaShopException
  */
 public function validateField($field, $value, $id_lang = null, $skip = array(), $human_errors = false)
 {
     static $ps_lang_default = null;
     static $ps_allow_html_iframe = null;
     if ($ps_lang_default === null) {
         $ps_lang_default = Configuration::get('PS_LANG_DEFAULT');
     }
     if ($ps_allow_html_iframe === null) {
         $ps_allow_html_iframe = (int) Configuration::get('PS_ALLOW_HTML_IFRAME');
     }
     $this->cacheFieldsRequiredDatabase();
     $data = $this->def['fields'][$field];
     // Check if field is required
     $required_fields = isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array();
     if (!$id_lang || $id_lang == $ps_lang_default) {
         if (!in_array('required', $skip) && (!empty($data['required']) || in_array($field, $required_fields))) {
             if (Tools::isEmpty($value)) {
                 if ($human_errors) {
                     return sprintf(Tools::displayError('The %s field is required.'), $this->displayFieldName($field, get_class($this)));
                 } else {
                     return 'Property ' . get_class($this) . '->' . $field . ' is empty';
                 }
             }
         }
     }
     // Default value
     if (!$value && !empty($data['default'])) {
         $value = $data['default'];
         $this->{$field} = $value;
     }
     // Check field values
     if (!in_array('values', $skip) && !empty($data['values']) && is_array($data['values']) && !in_array($value, $data['values'])) {
         return 'Property ' . get_class($this) . '->' . $field . ' has bad value (allowed values are: ' . implode(', ', $data['values']) . ')';
     }
     // Check field size
     if (!in_array('size', $skip) && !empty($data['size'])) {
         $size = $data['size'];
         if (!is_array($data['size'])) {
             $size = array('min' => 0, 'max' => $data['size']);
         }
         $length = Tools::strlen($value);
         if ($length < $size['min'] || $length > $size['max']) {
             if ($human_errors) {
                 if (isset($data['lang']) && $data['lang']) {
                     $language = new Language((int) $id_lang);
                     return sprintf(Tools::displayError('The field %1$s (%2$s) is too long (%3$d chars max, html chars including).'), $this->displayFieldName($field, get_class($this)), $language->name, $size['max']);
                 } else {
                     return sprintf(Tools::displayError('The %1$s field is too long (%2$d chars max).'), $this->displayFieldName($field, get_class($this)), $size['max']);
                 }
             } else {
                 return 'Property ' . get_class($this) . '->' . $field . ' length (' . $length . ') must be between ' . $size['min'] . ' and ' . $size['max'];
             }
         }
     }
     // Check field validator
     if (!in_array('validate', $skip) && !empty($data['validate'])) {
         if (!method_exists('Validate', $data['validate'])) {
             throw new PrestaShopException('Validation function not found. ' . $data['validate']);
         }
         if (!empty($value)) {
             $res = true;
             if (Tools::strtolower($data['validate']) == 'iscleanhtml') {
                 if (!call_user_func(array('Validate', $data['validate']), $value, $ps_allow_html_iframe)) {
                     $res = false;
                 }
             } else {
                 if (!call_user_func(array('Validate', $data['validate']), $value)) {
                     $res = false;
                 }
             }
             if (!$res) {
                 if ($human_errors) {
                     return sprintf(Tools::displayError('The %s field is invalid.'), $this->displayFieldName($field, get_class($this)));
                 } else {
                     return 'Property ' . get_class($this) . '->' . $field . ' is not valid';
                 }
             }
         }
     }
     return true;
 }
Example #15
0
            if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
                $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
            }
        }
    }
}
/* Trying to redefine HTTP_HOST if empty (on some webservers...) */
if (!isset($_SERVER['HTTP_HOST']) || empty($_SERVER['HTTP_HOST'])) {
    $_SERVER['HTTP_HOST'] = @getenv('HTTP_HOST');
}
$context = Context::getContext();
/* Initialize the current Shop */
try {
    $context->shop = Shop::initialize();
    $context->theme = new Theme((int) $context->shop->id_theme);
    if ((Tools::isEmpty($theme_name = $context->shop->getTheme()) || !Validate::isLoadedObject($context->theme)) && !defined('_PS_ADMIN_DIR_')) {
        throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.'));
    }
} catch (PrestaShopException $e) {
    $e->displayMessage();
}
define('_THEME_NAME_', $theme_name);
define('__PS_BASE_URI__', $context->shop->getBaseURI());
/* Include all defines related to base uri and theme name */
require_once dirname(__FILE__) . '/defines_uri.inc.php';
global $_MODULES;
$_MODULES = array();
define('_PS_PRICE_DISPLAY_PRECISION_', Configuration::get('PS_PRICE_DISPLAY_PRECISION'));
define('_PS_PRICE_COMPUTE_PRECISION_', _PS_PRICE_DISPLAY_PRECISION_);
if (Configuration::get('PS_USE_HTMLPURIFIER')) {
    require_once _PS_TOOL_DIR_ . 'htmlpurifier/HTMLPurifier.standalone.php';
Example #16
0
 /**
  * Check for multilingual fields validity before database interaction
  */
 public function validateFieldsLang($die = true, $errorReturn = false)
 {
     $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
     foreach ($this->fieldsRequiredLang as $fieldArray) {
         if (!is_array($this->{$fieldArray})) {
             continue;
         }
         if (!$this->{$fieldArray} or !sizeof($this->{$fieldArray}) or $this->{$fieldArray}[$defaultLanguage] !== '0' and empty($this->{$fieldArray}[$defaultLanguage])) {
             if ($die) {
                 die(Tools::displayError() . ' (' . get_class($this) . '->' . $fieldArray . ' ' . Tools::displayError('is empty for default language') . ')');
             }
             return $errorReturn ? get_class($this) . '->' . $fieldArray . ' ' . Tools::displayError('is empty for default language') : false;
         }
     }
     foreach ($this->fieldsSizeLang as $fieldArray => $size) {
         if (!is_array($this->{$fieldArray})) {
             continue;
         }
         foreach ($this->{$fieldArray} as $k => $value) {
             if (Tools::strlen($value) > $size) {
                 if ($die) {
                     die(Tools::displayError() . ' (' . get_class($this) . '->' . $fieldArray . ' ' . Tools::displayError('length >') . ' ' . $size . ' ' . Tools::displayError('for language') . ')');
                 }
                 return $errorReturn ? get_class($this) . '->' . $fieldArray . ' ' . Tools::displayError('length >') . ' ' . $size . ' ' . Tools::displayError('for language') : false;
             }
         }
     }
     $validate = new Validate();
     foreach ($this->fieldsValidateLang as $fieldArray => $method) {
         if (!is_array($this->{$fieldArray})) {
             continue;
         }
         foreach ($this->{$fieldArray} as $k => $value) {
             if (!method_exists($validate, $method)) {
                 die(Tools::displayError('validation function not found') . ' ' . $method);
             } elseif (!Tools::isEmpty($value) and !call_user_func(array('Validate', $method), $value)) {
                 if ($die) {
                     die(Tools::displayError() . ' (' . get_class($this) . '->' . $fieldArray . ' = ' . $value . ' ' . Tools::displayError('for language') . ' ' . $k . ')');
                 }
                 return $errorReturn ? get_class($this) . '->' . $fieldArray . ' = ' . $value . ' ' . Tools::displayError('for language') . ' ' . $k : false;
             }
         }
     }
     return true;
 }
 protected function generateInfosData()
 {
     if (!(int) Validate::isLoadedObject(Module::getInstanceByName('blockcmsinfo')) || !Module::isEnabled('blockcmsinfo') || !Module::isInstalled('blockcmsinfo')) {
         return;
     }
     $delimiter = ';';
     $line = array();
     $titles = array();
     $new_path = new Sampledatainstall();
     $f = fopen($new_path->sendPath() . 'output/infos.vsc', 'w');
     foreach ($this->info_fields as $field => $array) {
         $titles[] = $array['label'];
     }
     fputcsv($f, $titles, $delimiter, '"');
     $infos = $this->getAllInfos();
     if ($infos) {
         if (!class_exists('InfoBlock')) {
             return;
         }
         foreach ($infos as $info) {
             $i = new InfoBlock($info, $this->use_lang);
             foreach ($this->info_fields as $field => $array) {
                 $line[$field] = property_exists('InfoBlock', $field) && !is_array($i->{$field}) && !Tools::isEmpty($i->{$field}) ? $i->{$field} : '';
             }
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
     }
     fclose($f);
 }
Example #18
0
 public static function urlToNotificationPS16()
 {
     $urlToNotification = self::getNotificationUrl();
     return Tools::isEmpty($urlToNotification) ? self::getDefaultNotificationUrlPS15() : $urlToNotification;
 }
 /**
  * Validate a single field
  *
  * @param string $field Field name
  * @param mixed $value Field value
  * @param array $skip
  * @param bool $human_errors
  * @return bool|string
  * @throws Exception
  */
 public function validateField($field, $value, $skip = array(), $human_errors = false)
 {
     $data = $this->def['fields'][$field];
     if (!in_array('required', $skip) && !empty($data['required'])) {
         if (Tools::isEmpty($value)) {
             if ($human_errors) {
                 return sprintf(Tools::displayError('The %s field is required.'), $this->displayFieldName($field, get_class($this)));
             } else {
                 return 'Property ' . get_class($this) . '->' . $field . ' is empty';
             }
         }
     }
     // Default value
     if (!$value && !empty($data['default'])) {
         $value = $data['default'];
         $this->{$field} = $value;
     }
     // Check field values
     if (!in_array('values', $skip) && !empty($data['values']) && is_array($data['values']) && !in_array($value, $data['values'])) {
         return 'Property ' . get_class($this) . '->' . $field . ' has bad value (allowed values are: ' . implode(', ', $data['values']) . ')';
     }
     // Check field size
     if (!in_array('size', $skip) && !empty($data['size'])) {
         $size = $data['size'];
         if (!is_array($data['size'])) {
             $size = array('min' => 0, 'max' => $data['size']);
         }
         $length = Tools::strlen($value);
         if ($length < $size['min'] || $length > $size['max']) {
             if ($human_errors) {
                 return sprintf(Tools::displayError('The %1$s field is too long (%2$d chars max).'), $this->displayFieldName($field, get_class($this)), $size['max']);
             } else {
                 return 'Property ' . get_class($this) . '->' . $field . ' length (' . $length . ') must be between ' . $size['min'] . ' and ' . $size['max'];
             }
         }
     }
     // Check field validator
     if (!in_array('validate', $skip) && !empty($data['validate'])) {
         if (!method_exists('Validate', $data['validate'])) {
             throw new Exception('Validation function not found. ' . $data['validate']);
         }
         if (!empty($value)) {
             $res = true;
             if (Tools::strtolower($data['validate']) == 'iscleanhtml') {
                 if (!call_user_func(array('Validate', $data['validate']), $value, 0)) {
                     $res = false;
                 }
             } else {
                 if (!call_user_func(array('Validate', $data['validate']), $value)) {
                     $res = false;
                 }
             }
             if (!$res) {
                 if ($human_errors) {
                     return sprintf(Tools::displayError('Le champs %s est invalide.'), $this->displayFieldName($field, get_class($this)));
                 } else {
                     return 'La propriété ' . get_class($this) . '->' . $field . ' (' . $value . ') est invalide';
                 }
             }
         }
     }
     return true;
 }
Example #20
0
 public static function delPromotion($pid)
 {
     if (Tools::isEmpty($pid)) {
         return;
     }
     Db::getInstance()->Execute('update `' . _DB_PREFIX_ . 'Promotion` set IsDelete = 1 WHERE `PromotionId` = ' . (int) $pid);
 }
Example #21
0
    public static function getAttributesColorList(array $products, $have_stock = true)
    {
        if (!count($products)) {
            return array();
        }
        $id_lang = Context::getContext()->language->id;
        $check_stock = !Configuration::get('PS_DISP_UNAVAILABLE_ATTR');
        if (!($res = Db::getInstance()->executeS('
			SELECT pa.`id_product`, a.`color`, pac.`id_product_attribute`, ' . ($check_stock ? 'SUM(IF(stock.`quantity` > 0, 1, 0))' : '0') . ' qty, a.`id_attribute`, al.`name`, IF(color = "", a.id_attribute, color) group_by
			FROM `' . _DB_PREFIX_ . 'product_attribute` pa
			' . Shop::addSqlAssociation('product_attribute', 'pa') . ($check_stock ? Product::sqlStock('pa', 'pa') : '') . '
			JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.`id_product_attribute` = product_attribute_shop.`id_product_attribute`)
			JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
			JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int) $id_lang . ')
			JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (a.id_attribute_group = ag.`id_attribute_group`)
			WHERE pa.`id_product` IN (' . implode(array_map('intval', $products), ',') . ') AND ag.`is_color_group` = 1
			GROUP BY pa.`id_product`, a.`id_attribute`, `group_by`
			' . ($check_stock ? 'HAVING qty > 0' : '') . '
			ORDER BY a.`position` ASC;'))) {
            return false;
        }
        $colors = array();
        foreach ($res as $row) {
            if (Tools::isEmpty($row['color']) && !@filemtime(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) {
                continue;
            }
            $colors[(int) $row['id_product']][] = array('id_product_attribute' => (int) $row['id_product_attribute'], 'color' => $row['color'], 'id_product' => $row['id_product'], 'name' => $row['name'], 'id_attribute' => $row['id_attribute']);
        }
        return $colors;
    }
Example #22
0
            $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
            if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
                $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
            }
        }
    }
}
/* Trying to redefine HTTP_HOST if empty (on some webservers...) */
if (!isset($_SERVER['HTTP_HOST']) || empty($_SERVER['HTTP_HOST'])) {
    $_SERVER['HTTP_HOST'] = @getenv('HTTP_HOST');
}
$context = Context::getContext();
/* Initialize the current Shop */
try {
    $context->shop = Shop::initialize();
    if (Tools::isEmpty($theme_name = $context->shop->getTheme()) && !defined('_PS_ADMIN_DIR_')) {
        throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.'));
    }
} catch (PrestaShopException $e) {
    $e->displayMessage();
}
define('_THEME_NAME_', $theme_name);
define('__PS_BASE_URI__', $context->shop->getBaseURI());
/* Include all defines related to base uri and theme name */
require_once dirname(__FILE__) . '/defines_uri.inc.php';
global $_MODULES;
$_MODULES = array();
/* Load configuration */
Configuration::loadConfiguration();
/* Load all languages */
Language::loadLanguages();
Example #23
0
    public function getView($params, $synchrone)
    {
        $search_form = new Form($this->search_fields, $params);
        $access_form = new Form($this->access_fields, $params);
        $title = '';
        $insert = TRUE;
        try {
            if (!isset($params['game'])) {
                throw new Exception('No Game given');
            }
            $game = new Game($params['game']);
            if ($game->isIn(F::i('Session')->getMid())) {
                throw new Exception('Already In');
            }
        } catch (Exception $e) {
            $insert = FALSE;
        }
        if ($insert) {
            if ($game->g_access_key == 'NULL' || $access_form->isSubmitting() && Tools::isEmpty($access_form->getErrors()) && $game->g_access_key == Tools::saltHash($params['access_key'])) {
                $game->insert(F::i('Session')->getMid());
                Tools::redirect('?action=wait_game&game=' . $game->g_id);
            } else {
                // CHECK
                if ($access_form->isSubmitting()) {
                    // Error
                    die('bad access key');
                } else {
                    $view = View::setFile('formular', View::HTML_FILE);
                    $errors = $access_form->getErrors();
                    // Errors in the filling
                    if (!empty($errors)) {
                        $view->setSwitch('form_errors', TRUE);
                        foreach ($errors as $field => $error) {
                            $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
                        }
                    }
                    $view->setValue('form', $access_form->getHTML(F::i('Lang')->getKey('access_key'), '#', 'POST', 'tabbed_form'));
                }
            }
        } else {
            $sql = 'SELECT g.g_id, g_name, TIMESTAMPDIFF(HOUR, g_start, NOW()) AS lifetime, COUNT(*) AS g_total_players, m_login AS g_owner 
					FROM !prefix_members m, !prefix_games AS g, !prefix_players AS p 
					WHERE g.m_id = m.m_id 
						AND p.g_id = g.g_id 
						AND g.g_id NOT IN (
							SELECT g_id FROM !prefix_players WHERE m_id = ?
						)';
            $array = array(F::i('Session')->getMid());
            // If search is defined, add condition
            if (isset($params['search'])) {
                $sql .= ' AND g_name LIKE ?';
                $array[] = '%' . $params['search'] . '%';
            }
            $sql .= ' GROUP BY g.g_id ORDER BY g_start DESC';
            // Get all the games
            $result = F::i(_DBMS_SYS)->query($sql, $array);
            $view = View::setFile('list_games', View::HTML_FILE);
            $view->setValue('form', $search_form->getHTML('', '#', 'POST', 'inline'));
            if ($result->getNumRows() == 0) {
                $view->setSwitch('no_games', TRUE);
            }
            for ($i = 0; $i < $result->getNumRows(); $i++) {
                $obj = $result->getObject();
                $view->setGroupValues('games', array('link' => '?action=join_game&game=' . $obj->g_id, 'name' => stripslashes($obj->g_name), 'total_players' => $obj->g_total_players, 'owner' => $obj->g_owner, 'lifetime' => $obj->lifetime));
            }
            $title = F::i('Lang')->getKey('title_join_game');
        }
        return parent::setBody($view);
    }
Example #24
0
 private function processAccountRequestForm()
 {
     if (!Tools::isSubmit('submit_account_request')) {
         return false;
     }
     // Check inputs validity
     if (Tools::isEmpty(Tools::getValue('lastname')) || !Validate::isName(Tools::getValue('lastname'))) {
         $this->account_request_form_errors[] = $this->l('Field "lastname" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('firstname')) || !Validate::isName(Tools::getValue('firstname'))) {
         $this->account_request_form_errors[] = $this->l('Field "firstname" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('email')) || !Validate::isEmail(Tools::getValue('email'))) {
         $this->account_request_form_errors[] = $this->l('Field "e-mail" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('phone')) || !Validate::isPhoneNumber(Tools::getValue('phone'))) {
         $this->account_request_form_errors[] = $this->l('Field "phone number" is not valide');
     }
     if (Tools::isEmpty(Tools::getValue('shop_name')) || !Validate::isGenericName(Tools::getValue('shop_name'))) {
         $this->account_request_form_errors[] = $this->l('Field "shop name" is not valide');
     }
     if (!is_numeric(Tools::getValue('packages_per_year')) || Tools::getValue('packages_per_year') <= 0) {
         $this->account_request_form_errors[] = $this->l('Field "packages per year" is not valide');
     }
     if (!is_numeric(Tools::getValue('package_weight')) || Tools::getValue('package_weight') <= 0) {
         $this->account_request_form_errors[] = $this->l('Field "average weight of a package" is not valide');
     }
     // Validation error dont send mail
     if (count($this->account_request_form_errors)) {
         return false;
     }
     return true;
 }
 public function getDefaultRedirectionUrl()
 {
     return Tools::isEmpty(Util::getRedirectUrl()) ? Util::getDefaultRedirectUrlPS15() : Util::getRedirectUrl();
 }
Example #26
0
 /**
  * Generate name 
  * @param type $value
  * @return string
  */
 private function _generateName($value)
 {
     $name = '';
     $cont = 0;
     $customer = explode(' ', $value);
     foreach ($customer as $first) {
         if (!Tools::isEmpty($first)) {
             if ($cont == 0) {
                 $name .= $first;
                 $cont++;
             } else {
                 $name .= ' ' . $first;
             }
         }
     }
     return $name;
 }
Example #27
0
 public function processProductAttribute()
 {
     // Don't process if the combination fields have not been submitted
     if (!Combination::isFeatureActive() || !Tools::getValue('attribute_combination_list')) {
         return;
     }
     if (Validate::isLoadedObject($product = $this->object)) {
         if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null)) {
             $this->errors[] = Tools::displayError('The price attribute is required.');
         }
         if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list'))) {
             $this->errors[] = Tools::displayError('You must add at least one attribute.');
         }
         $array_checks = array('reference' => 'isReference', 'supplier_reference' => 'isReference', 'location' => 'isReference', 'ean13' => 'isEan13', 'upc' => 'isUpc', 'wholesale_price' => 'isPrice', 'price' => 'isPrice', 'ecotax' => 'isPrice', 'quantity' => 'isInt', 'weight' => 'isUnsignedFloat', 'unit_price_impact' => 'isPrice', 'default_on' => 'isBool', 'minimal_quantity' => 'isUnsignedInt', 'available_date' => 'isDateFormat');
         foreach ($array_checks as $property => $check) {
             if (Tools::getValue('attribute_' . $property) !== false && !call_user_func(array('Validate', $check), Tools::getValue('attribute_' . $property))) {
                 $this->errors[] = sprintf(Tools::displayError('Field %s is not valid'), $property);
             }
         }
         if (!count($this->errors)) {
             if (!isset($_POST['attribute_wholesale_price'])) {
                 $_POST['attribute_wholesale_price'] = 0;
             }
             if (!isset($_POST['attribute_price_impact'])) {
                 $_POST['attribute_price_impact'] = 0;
             }
             if (!isset($_POST['attribute_weight_impact'])) {
                 $_POST['attribute_weight_impact'] = 0;
             }
             if (!isset($_POST['attribute_ecotax'])) {
                 $_POST['attribute_ecotax'] = 0;
             }
             if (Tools::getValue('attribute_default')) {
                 $product->deleteDefaultAttributes();
             }
             // Change existing one
             if (($id_product_attribute = (int) Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true))) {
                 if ($this->tabAccess['edit'] === '1') {
                     if ($this->isProductFieldUpdated('available_date_attribute') && (Tools::getValue('available_date_attribute') != '' && !Validate::isDateFormat(Tools::getValue('available_date_attribute')))) {
                         $this->errors[] = Tools::displayError('Invalid date format.');
                     } else {
                         $product->updateAttribute((int) $id_product_attribute, $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_ean13'), $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false);
                         StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
                         StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You do not have permission to add this.');
                 }
             } else {
                 if ($this->tabAccess['add'] === '1') {
                     if ($product->productAttributeExists(Tools::getValue('attribute_combination_list'))) {
                         $this->errors[] = Tools::displayError('This combination already exists.');
                     } else {
                         $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), 0, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), null, Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'), array(), Tools::getValue('available_date_attribute'));
                         StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
                         StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('edit here.');
                 }
             }
             if (!count($this->errors)) {
                 $combination = new Combination((int) $id_product_attribute);
                 $combination->setAttributes(Tools::getValue('attribute_combination_list'));
                 // images could be deleted before
                 $id_images = Tools::getValue('id_image_attr');
                 if (!empty($id_images)) {
                     $combination->setImages($id_images);
                 }
                 $product->checkDefaultAttributes();
                 if (Tools::getValue('attribute_default')) {
                     Product::updateDefaultAttribute((int) $product->id);
                     if (isset($id_product_attribute)) {
                         $product->cache_default_attribute = (int) $id_product_attribute;
                     }
                     if ($available_date = Tools::getValue('available_date_attribute')) {
                         $product->setAvailableDate($available_date);
                     }
                 }
             }
         }
     }
 }
 private function processCombinations()
 {
     ${"GLOBALS"}["eihxllnsogy"] = "product";
     if (!Combination::isFeatureActive() || !Tools::getIsset("attribute")) {
         return;
     }
     if (Validate::isLoadedObject(${${"GLOBALS"}["eihxllnsogy"]} = $this->object)) {
         if ($this->isProductFieldUpdated("attribute_price") && (!Tools::getIsset("attribute_price") || Tools::getIsset("attribute_price") == null)) {
             $this->errors[] = Tools::displayError("Attribute price required.");
         }
         if (!Tools::getIsset("attribute_combination_list") || Tools::isEmpty(Tools::getValue("attribute_combination_list"))) {
             $this->errors[] = Tools::displayError("You must add at least one attribute.");
         }
         if (!count($this->errors)) {
             if (!isset($_POST["attribute_wholesale_price"])) {
                 $_POST["attribute_wholesale_price"] = 0;
             }
             if (!isset($_POST["attribute_price_impact"])) {
                 $_POST["attribute_price_impact"] = 0;
             }
             if (!isset($_POST["attribute_weight_impact"])) {
                 $_POST["attribute_weight_impact"] = 0;
             }
             if (!isset($_POST["attribute_ecotax"])) {
                 $_POST["attribute_ecotax"] = 0;
             }
             if (Tools::getValue("attribute_default")) {
                 $product->deleteDefaultAttributes();
             }
             if (${${"GLOBALS"}["tbhwjssdhx"]} = (int) Tools::getValue("id_product_attribute")) {
                 ${"GLOBALS"}["cpvnlwngne"] = "id_product_attribute";
                 if ($product->productAttributeExists(Tools::getValue("attribute_combination_list"), (int) ${${"GLOBALS"}["cpvnlwngne"]})) {
                     $this->errors[] = Tools::displayError("This attribute already exists.");
                 } else {
                     if ($this->isProductFieldUpdated("available_date_attribute") && !Validate::isDateFormat(Tools::getValue("available_date_attribute"))) {
                         $this->errors[] = Tools::displayError("Invalid date format.");
                     } else {
                         $product->updateAttribute((int) ${${"GLOBALS"}["tbhwjssdhx"]}, $this->isProductFieldUpdated("attribute_wholesale_price") ? Tools::getValue("attribute_wholesale_price") : null, $this->isProductFieldUpdated("attribute_price_impact") ? Tools::getValue("attribute_price") * Tools::getValue("attribute_price_impact") : null, $this->isProductFieldUpdated("attribute_weight_impact") ? Tools::getValue("attribute_weight") * Tools::getValue("attribute_weight_impact") : null, $this->isProductFieldUpdated("attribute_unit_impact") ? Tools::getValue("attribute_unity") * Tools::getValue("attribute_unit_impact") : null, $this->isProductFieldUpdated("attribute_ecotax") ? Tools::getValue("attribute_ecotax") : null, Tools::getValue("id_image_attr"), Tools::getValue("attribute_reference"), Tools::getValue("attribute_ean13"), $this->isProductFieldUpdated("attribute_default") ? Tools::getValue("attribute_default") : null, Tools::getValue("attribute_location"), Tools::getValue("attribute_upc"), $this->isProductFieldUpdated("attribute_minimal_quantity") ? Tools::getValue("attribute_minimal_quantity") : null, $this->isProductFieldUpdated("available_date_attribute") ? Tools::getValue("available_date_attribute") : null, false);
                     }
                 }
             } else {
                 ${"GLOBALS"}["bxevjsn"] = "id_product_attribute";
                 if ($product->productAttributeExists(Tools::getValue("attribute_combination_list"))) {
                     $this->errors[] = Tools::displayError("This combination already exists.");
                 } else {
                     ${${"GLOBALS"}["bxevjsn"]} = $product->addCombinationEntity(Tools::getValue("attribute_wholesale_price"), Tools::getValue("attribute_price") * Tools::getValue("attribute_price_impact"), Tools::getValue("attribute_weight") * Tools::getValue("attribute_weight_impact"), Tools::getValue("attribute_unity") * Tools::getValue("attribute_unit_impact"), Tools::getValue("attribute_ecotax"), 0, Tools::getValue("id_image_attr"), Tools::getValue("attribute_reference"), null, Tools::getValue("attribute_ean13"), Tools::getValue("attribute_default"), Tools::getValue("attribute_location"), Tools::getValue("attribute_upc"), Tools::getValue("attribute_minimal_quantity"));
                 }
             }
             if (!count($this->errors)) {
                 ${"GLOBALS"}["gdohtzw"] = "id_product_attribute";
                 $qqxwhsfpb = "id_images";
                 ${${"GLOBALS"}["yedtbmwbugs"]} = new Combination((int) ${${"GLOBALS"}["gdohtzw"]});
                 $combination->setAttributes(Tools::getValue("attribute_combination_list"));
                 ${$qqxwhsfpb} = Tools::getValue("id_image_attr");
                 if (!empty(${${"GLOBALS"}["cynhhztd"]})) {
                     $combination->setImages(${${"GLOBALS"}["cynhhztd"]});
                 }
                 $product->checkDefaultAttributes();
                 if (Tools::getValue("attribute_default")) {
                     Product::updateDefaultAttribute((int) $product->id);
                     $yihcjzfqycuf = "available_date";
                     $jcuzacll = "id_product_attribute";
                     ${"GLOBALS"}["yhkmhfis"] = "id_product_attribute";
                     ${"GLOBALS"}["uxbmswdpvwp"] = "available_date";
                     if (isset(${${"GLOBALS"}["yhkmhfis"]})) {
                         $product->cache_default_attribute = (int) ${$jcuzacll};
                     }
                     if (${$yihcjzfqycuf} = Tools::getValue("available_date_attribute")) {
                         $product->setAvailableDate(${${"GLOBALS"}["uxbmswdpvwp"]});
                     }
                 }
             }
             if (!count($this->errors)) {
                 if (!$product->cache_default_attribute) {
                     Product::updateDefaultAttribute($product->id);
                 }
             }
         }
     }
 }
Example #29
0
 public function hookDisplayTop($param)
 {
     $this->user_groups = $this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $this->page_name = Dispatcher::getInstance()->getController();
     if (!$this->isCached('blocktopmenu.tpl', $this->getCacheId())) {
         if (Tools::isEmpty($this->_menu)) {
             $this->makeMenu();
         }
         $shop_id = (int) $this->context->shop->id;
         $shop_group_id = Shop::getGroupFromShop($shop_id);
         $this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH', null, $shop_group_id, $shop_id));
         $this->smarty->assign('MENU', $this->_menu);
         $this->smarty->assign('this_path', $this->_path);
     }
     $html = $this->display(__FILE__, 'blocktopmenu.tpl', $this->getCacheId());
     return $html;
 }
Example #30
0
 /**
  * Check for fields validity before database interaction
  */
 public function validateFields($die = true, $errorReturn = false)
 {
     $fieldsRequired = array_merge($this->fieldsRequired, isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array());
     foreach ($fieldsRequired as $field) {
         if (Tools::isEmpty($this->{$field}) and !is_numeric($this->{$field})) {
             if ($die) {
                 die(Tools::displayError() . ' (' . Tools::safeOutput(get_class($this)) . ' -> ' . Tools::safeOutput($field) . ' is empty)');
             }
             return $errorReturn ? get_class($this) . ' -> ' . $field . ' is empty' : false;
         }
     }
     foreach ($this->fieldsSize as $field => $size) {
         if (isset($this->{$field}) and Tools::strlen($this->{$field}) > $size) {
             if ($die) {
                 die(Tools::displayError() . ' (' . Tools::safeOutput(get_class($this)) . ' -> ' . Tools::safeOutput($field) . ' Length ' . Tools::safeOutput($size) . ')');
             }
             return $errorReturn ? get_class($this) . ' -> ' . $field . ' Length ' . $size : false;
         }
     }
     $validate = new Validate();
     foreach ($this->fieldsValidate as $field => $method) {
         if (!method_exists($validate, $method)) {
             die(Tools::displayError('Validation function not found.') . ' ' . $method);
         } elseif (!empty($this->{$field}) and !call_user_func(array('Validate', $method), $this->{$field})) {
             if ($die) {
                 die(Tools::displayError() . ' (' . Tools::safeOutput(get_class($this)) . ' -> ' . Tools::safeOutput($field) . ' = ' . Tools::safeOutput($this->{$field}) . ')');
             }
             return $errorReturn ? get_class($this) . ' -> ' . $field . ' = ' . $this->{$field} : false;
         }
     }
     return true;
 }