/** * Formats a value * * @param mixed $value * @param int $type * @param bool $with_quotes * @param bool $purify * @param bool $allow_null * @return mixed */ public static function formatValue($value, $type, $with_quotes = false, $purify = true, $allow_null = false) { if ($allow_null && $value === null) { return array('type' => 'sql', 'value' => 'NULL'); } switch ($type) { case self::TYPE_INT: return (int) $value; case self::TYPE_BOOL: return (int) $value; case self::TYPE_FLOAT: return (double) str_replace(',', '.', $value); case self::TYPE_DATE: if (!$value) { return '0000-00-00'; } if ($with_quotes) { return '\'' . pSQL($value) . '\''; } return pSQL($value); case self::TYPE_HTML: if ($purify) { $value = Tools::purifyHTML($value); } if ($with_quotes) { return '\'' . pSQL($value, true) . '\''; } return pSQL($value, true); case self::TYPE_SQL: if ($with_quotes) { return '\'' . pSQL($value, true) . '\''; } return pSQL($value, true); case self::TYPE_NOTHING: return $value; case self::TYPE_STRING: default: if ($with_quotes) { return '\'' . pSQL($value) . '\''; } return pSQL($value); } }
protected function filterVar($value) { if (version_compare(_PS_VERSION_, '1.6.0.7', '>=') === true) { return Tools::purifyHTML($value); } else { return filter_var($value, FILTER_SANITIZE_STRING); } }
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(Tools::purifyHTML($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; }
public function getOptionValue($key, $field) { $value = Tools::getValue($key, Configuration::get($key)); if (!Validate::isCleanHtml($value)) { $value = Configuration::get($key); } if (isset($field['defaultValue']) && !$value) { $value = $field['defaultValue']; } return Tools::purifyHTML($value); }
public function saveSubMenuItem() { $languages = $this->getAllLanguage(); $moduleId = Tools::getValue('moduleId', 0); $menuId = Tools::getValue('menuId', 0); $rowId = Tools::getValue('rowId', 0); $groupId = Tools::getValue('groupId', 0); $parentId = Tools::getValue('parentId', 0); $itemId = Tools::getValue('id', 0); $names = Tools::getValue('names', array()); $custom_class = Tools::getValue('custom_class', ''); $display_name = Tools::getValue('item_display_name', 1); $link_type = Tools::getValue('link_type', 'CUSTOMLINK|0'); $product_id = Tools::getValue('product_id', 0); $links = Tools::getValue('links', array()); $menu_type = Tools::getValue('menu_type', 'link'); $module_name = ''; $hook_name = ''; $images = ''; $alts = ''; $htmls = ''; $icon = Tools::getValue('icon', ''); //$_POST['icon']; $icon_active = Tools::getValue('icon_active', ''); //$_POST['icon_active']; $response = new stdClass(); $defaultName = ''; $defaultAlt = ''; $defaultHtml = ''; $defaultLink = ''; if ($moduleId > 0 && $rowId > 0 && $groupId > 0 & $parentId > 0) { if ($itemId == 0) { $maxOrdering = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue("Select MAX(ordering) From " . _DB_PREFIX_ . "megaboxs_menuitem Where `parent_id` = " . $parentId); if ($maxOrdering > 0) { $maxOrdering++; } else { $maxOrdering = 1; } $arrInsert = array('parent_id' => $parentId, 'module_id' => $moduleId, 'menu_id' => $menuId, 'row_id' => $rowId, 'group_id' => $groupId, 'menu_type' => $menu_type, 'link_type' => $link_type, 'custom_class' => $custom_class, 'display_name' => $display_name, 'status' => 1, 'module_name' => $module_name, 'hook_name' => $hook_name, 'product_id' => $product_id, 'icon' => $icon, 'icon_active' => $icon_active, 'ordering' => $maxOrdering); if ($icon) { if (strpos($icon, '.') === false) { $arrInsert['icon'] = $icon; } else { if (strpos($icon, 'http') !== false) { $arrInsert['icon'] = $icon; } else { if (file_exists($this->pathImage . 'temps/' . $icon)) { if (copy($this->pathImage . 'temps/' . $icon, $this->pathImage . 'icons/' . $icon)) { $arrInsert['icon'] = $icon; } unlink($this->pathImage . 'temps/' . $icon); } } } } if ($icon_active) { if (strpos($icon_active, '.') === false) { $arrInsert['icon_active'] = $icon_active; } else { if (strpos($icon_active, 'http') !== false) { $arrInsert['icon_active'] = $icon_active; } else { if (file_exists($this->pathImage . 'temps/' . $icon_active)) { if (copy($this->pathImage . 'temps/' . $icon_active, $this->pathImage . 'icons/' . $icon_active)) { $arrInsert['icon_active'] = $icon_active; } unlink($this->pathImage . 'temps/' . $icon_active); } } } } if (Db::getInstance(_PS_USE_SQL_SLAVE_)->insert('megaboxs_menuitem', $arrInsert)) { $insertId = Db::getInstance(_PS_USE_SQL_SLAVE_)->Insert_ID(); if ($languages) { $insertDatas = array(); foreach ($languages as $index => $language) { $name = pSQL($names[$index]); if (!$defaultName) { $defaultName = $name; } if (!$name) { $name = $defaultName; } $alt = pSQL($names[$index]); if (!$defaultAlt) { $defaultAlt = $alt; } if (!$name) { $name = $defaultAlt; } $html = Tools::purifyHTML($htmls[$index]); if (!$defaultHtml) { $defaultHtml = $html; } if (!$html) { $html = $defaultHtml; } $link = pSQL($links[$index]); if (!$defaultLink) { $defaultLink = $link; } if (!$link) { $link = $defaultLink; } $image = pSQL($images[$index]); if ($images[$index]) { if (strpos($image, 'http') !== false) { $insertDatas[] = array('menuitem_id' => $insertId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => $image, 'imageAlt' => $alt, 'html' => $html); } else { if (file_exists($this->pathImage . 'temps/' . $image)) { if (copy($this->pathImage . 'temps/' . $image, $this->pathImage . $image)) { unlink($this->pathImage . 'temps/' . $image); $insertDatas[] = array('menuitem_id' => $insertId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => $image, 'imageAlt' => $alt, 'html' => $html); } else { $insertDatas[] = array('menuitem_id' => $insertId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => '', 'imageAlt' => $alt, 'html' => $html); } } else { $insertDatas[] = array('menuitem_id' => $insertId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => '', 'imageAlt' => $alt, 'html' => $html); } } } else { $insertDatas[] = array('menuitem_id' => $insertId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => '', 'imageAlt' => $alt, 'html' => $html); } } if ($insertDatas) { Db::getInstance(_PS_USE_SQL_SLAVE_)->insert('megaboxs_menuitem_lang', $insertDatas); } } $response->status = '1'; $response->msg = $this->l("Add new menu item Success!"); } else { $response->status = '0'; $response->msg = $this->l("Add new menu item not Success!"); } } else { $item = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow("Select * From " . _DB_PREFIX_ . "megaboxs_menuitem Where id = " . $itemId); //Db::getInstance(_PS_USE_SQL_SLAVE_)->execute("Update "._DB_PREFIX_."megaboxs_menuitem Set `menu_type` = '".$menu_type."', `link_type` = '".$link_type."', `custom_class`='".$custom_class."', `display_name` = '".$display_name."', `module_name`='".$module_name."', `hook_name`='".$hook_name."', `product_id` = '".$product_id."' Where id = ".$itemId); $arrUpdate = array('menu_type' => $menu_type, 'link_type' => $link_type, 'custom_class' => $custom_class, 'display_name' => $display_name, 'module_name' => $module_name, 'hook_name' => $hook_name, 'product_id' => $product_id, 'icon' => $item['icon'], 'icon_active' => $item['icon_active']); if ($icon) { if (strpos($icon, '.') === false) { $arrUpdate['icon'] = $icon; if ($item['icon'] && file_exists($this->pathImage . 'icons/' . $item['icon'])) { unlink($this->pathImage . 'icons/' . $item['icon']); } } else { if (strpos($icon, 'http') !== false) { $arrUpdate['icon'] = $icon; if ($item['icon'] && file_exists($this->pathImage . 'icons/' . $item['icon'])) { unlink($this->pathImage . 'icons/' . $item['icon']); } } else { if (file_exists($this->pathImage . 'temps/' . $icon)) { if (copy($this->pathImage . 'temps/' . $icon, $this->pathImage . 'icons/' . $icon)) { $arrUpdate['icon'] = $icon; if ($item['icon'] && file_exists($this->pathImage . 'icons/' . $item['icon'])) { unlink($this->pathImage . 'icons/' . $item['icon']); } } unlink($this->pathImage . 'temps/' . $icon); } } } } else { $arrUpdate['icon'] = ''; if ($item['icon'] && file_exists($this->pathImage . 'icons/' . $item['icon'])) { unlink($this->pathImage . 'icons/' . $item['icon']); } } if ($icon_active) { if (strpos($icon_active, '.') === false) { $arrUpdate['icon_active'] = $icon_active; if ($item['icon_active'] && file_exists($this->pathImage . 'icons/' . $item['icon_active'])) { unlink($this->pathImage . 'icons/' . $item['icon_active']); } } else { if (strpos($icon_active, 'http') !== false) { $arrUpdate['icon_active'] = $icon_active; if ($item['icon_active'] && file_exists($this->pathImage . 'icons/' . $item['icon_active'])) { unlink($this->pathImage . 'icons/' . $item['icon_active']); } } else { if (file_exists($this->pathImage . 'temps/' . $icon_active)) { if (copy($this->pathImage . 'temps/' . $icon_active, $this->pathImage . 'icons/' . $icon_active)) { $arrUpdate['icon_active'] = $icon_active; if ($item['icon_active'] && file_exists($this->pathImage . 'icons/' . $item['icon_active'])) { unlink($this->pathImage . 'icons/' . $item['icon_active']); } } unlink($this->pathImage . 'temps/' . $icon_active); } } } } else { $arrUpdate['icon_active'] = ''; if ($item['icon_active'] && file_exists($this->pathImage . 'icons/' . $item['icon_active'])) { unlink($this->pathImage . 'icons/' . $item['icon_active']); } } Db::getInstance(_PS_USE_SQL_SLAVE_)->update('megaboxs_menuitem', $arrUpdate, "`id`='{$itemId}'"); if ($languages) { $insertDatas = array(); foreach ($languages as $index => $language) { $name = pSQL($names[$index]); if (!$defaultName) { $defaultName = $name; } if (!$name) { $name = $defaultName; } $alt = pSQL($names[$index]); if (!$defaultAlt) { $defaultAlt = $alt; } if (!$name) { $name = $defaultAlt; } $html = Tools::purifyHTML($htmls[$index]); if (!$defaultHtml) { $defaultHtml = $html; } if (!$html) { $html = $defaultHtml; } $link = pSQL($links[$index]); if (!$defaultLink) { $defaultLink = $link; } if (!$link) { $link = $defaultLink; } $check = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow("Select * From " . _DB_PREFIX_ . "megaboxs_menuitem_lang Where menuitem_id = " . $itemId . " AND `id_lang` = " . $language->id); $image = pSQL($images[$index]); if ($image) { if (strpos($image, 'http') !== false) { if ($check) { Db::getInstance(_PS_USE_SQL_SLAVE_)->execute("Update " . _DB_PREFIX_ . "megaboxs_menuitem_lang Set `name` = '" . $name . "', `link` = '" . $link . "', `image` = '" . $image . "', `imageAlt` = '" . $alt . "', `html` = '" . $html . "' Where `menuitem_id` = {$itemId} AND `id_lang` = " . $language->id); } else { $insertDatas[] = array('menuitem_id' => $itemId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => $image, 'imageAlt' => $alt, 'html' => $html); } } else { if (file_exists($this->pathImage . 'temps/' . $image)) { if (copy($this->pathImage . 'temps/' . $image, $this->pathImage . $image)) { unlink($this->pathImage . 'temps/' . $image); if ($check) { if ($check['image'] && file_exists($this->pathImage . $check['image'])) { unlink($this->pathImage . $check['image']); } Db::getInstance(_PS_USE_SQL_SLAVE_)->execute("Update " . _DB_PREFIX_ . "megaboxs_menuitem_lang Set `name` = '" . $name . "', `link` = '" . $link . "', `image` = '" . $image . "', `imageAlt` = '" . $alt . "', `html` = '" . $html . "' Where `menuitem_id` = {$itemId} AND `id_lang` = " . $language->id); } else { $insertDatas[] = array('menuitem_id' => $itemId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => $image, 'imageAlt' => $alt, 'html' => $html); } } else { if ($check) { Db::getInstance(_PS_USE_SQL_SLAVE_)->execute("Update " . _DB_PREFIX_ . "megaboxs_menuitem_lang Set `name` = '" . $name . "', `link` = '" . $link . "', `imageAlt` = '" . $alt . "', `html` = '" . $html . "' Where `menuitem_id` = {$itemId} AND `id_lang` = " . $language->id); } else { $insertDatas[] = array('menuitem_id' => $itemId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => '', 'imageAlt' => $alt, 'html' => $html); } } } else { if ($check) { Db::getInstance(_PS_USE_SQL_SLAVE_)->execute("Update " . _DB_PREFIX_ . "megaboxs_menuitem_lang Set `name` = '" . $name . "', `link` = '" . $link . "', `imageAlt` = '" . $alt . "', `html` = '" . $html . "' Where `menuitem_id` = {$itemId} AND `id_lang` = " . $language->id); } else { $insertDatas[] = array('menuitem_id' => $itemId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => '', 'imageAlt' => $alt, 'html' => $html); } } } } else { if ($check) { Db::getInstance(_PS_USE_SQL_SLAVE_)->execute("Update " . _DB_PREFIX_ . "megaboxs_menuitem_lang Set `name` = '" . $name . "', `link` = '" . $link . "', `image` = '', `imageAlt` = '" . $alt . "', `html` = '" . $html . "' Where `menuitem_id` = {$itemId} AND `id_lang` = " . $language->id); } else { $insertDatas[] = array('menuitem_id' => $itemId, 'id_lang' => $language->id, 'name' => $name, 'link' => $link, 'image' => '', 'imageAlt' => $alt, 'html' => $html); } } if ($insertDatas) { Db::getInstance(_PS_USE_SQL_SLAVE_)->insert('megaboxs_menuitem', $insertDatas); } } } $response->status = 1; $response->msg = $this->l("Update menu item success!"); } } else { $response->status = '0'; $response->msg = $this->l('Module or Row or Group not found'); } die(Tools::jsonEncode($response)); }
/** * This method is used to write translation for mails. * This writes subject translation files * (in root/mails/lang_choosen/lang.php or root/_PS_THEMES_DIR_/mails/lang_choosen/lang.php) * and mails files. */ protected function submitTranslationsMails() { $arr_mail_content = array(); $arr_mail_path = array(); if (Tools::getValue('core_mail')) { $arr_mail_content['core_mail'] = Tools::getValue('core_mail'); // Get path of directory for find a good path of translation file if (!$this->theme_selected) { $arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['dir']; } else { $arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['override']['dir']; } } if (Tools::getValue('module_mail')) { $arr_mail_content['module_mail'] = Tools::getValue('module_mail'); // Get path of directory for find a good path of translation file if (!$this->theme_selected) { $arr_mail_path['module_mail'] = $this->translations_informations['modules']['dir'] . '{module}/mails/' . $this->lang_selected->iso_code . '/'; } else { $arr_mail_path['module_mail'] = $this->translations_informations['modules']['override']['dir'] . '{module}/mails/' . $this->lang_selected->iso_code . '/'; } } // Save each mail content foreach ($arr_mail_content as $group_name => $all_content) { foreach ($all_content as $type_content => $mails) { foreach ($mails as $mail_name => $content) { $module_name = false; $module_name_pipe_pos = stripos($mail_name, '|'); if ($module_name_pipe_pos) { $module_name = substr($mail_name, 0, $module_name_pipe_pos); if (!Validate::isModuleName($module_name)) { throw new PrestaShopException(sprintf(Tools::displayError('Invalid module name "%s"'), Tools::safeOutput($module_name))); } $mail_name = substr($mail_name, $module_name_pipe_pos + 1); if (!Validate::isTplName($mail_name)) { throw new PrestaShopException(sprintf(Tools::displayError('Invalid mail name "%s"'), Tools::safeOutput($mail_name))); } } if ($type_content == 'html') { $content = Tools::htmlentitiesUTF8($content); $content = htmlspecialchars_decode($content); // replace correct end of line $content = str_replace("\r\n", PHP_EOL, $content); $title = ''; if (Tools::getValue('title_' . $group_name . '_' . $mail_name)) { $title = Tools::getValue('title_' . $group_name . '_' . $mail_name); } $string_mail = $this->getMailPattern(); $content = str_replace(array('#title', '#content'), array($title, $content), $string_mail); // Magic Quotes shall... not.. PASS! if (_PS_MAGIC_QUOTES_GPC_) { $content = stripslashes($content); } } if (Validate::isCleanHTML($content)) { $path = $arr_mail_path[$group_name]; if ($module_name) { $path = str_replace('{module}', $module_name, $path); } if (!file_exists($path) && !mkdir($path, 0777, true)) { throw new PrestaShopException(sprintf(Tools::displayError('Directory "%s" cannot be created'), dirname($path))); } file_put_contents($path . $mail_name . '.' . $type_content, Tools::purifyHTML($content)); } else { throw new PrestaShopException(Tools::displayError('Your HTML email templates cannot contain JavaScript code.')); } } } } // Update subjects $array_subjects = array(); if (($subjects = Tools::getValue('subject')) && is_array($subjects)) { $array_subjects['core_and_modules'] = array('translations' => array(), 'path' => $arr_mail_path['core_mail'] . 'lang.php'); foreach ($subjects as $subject_translation) { $array_subjects['core_and_modules']['translations'] = array_merge($array_subjects['core_and_modules']['translations'], $subject_translation); } } if (!empty($array_subjects)) { foreach ($array_subjects as $infos) { $this->writeSubjectTranslationFile($infos['translations'], $infos['path']); } } if (Tools::isSubmit('submitTranslationsMailsAndStay')) { $this->redirect(true); } else { $this->redirect(); } }
/** * Update configuration key and value into database (automatically insert if key does not exist) * * @param string $key Key * @param mixed $values $values is an array if the configuration is multilingual, a single string else. * @param boolean $html Specify if html is authorized in value * @param int $id_shop_group * @param int $id_shop * @return boolean Update result */ public static function updateValue($key, $values, $html = false, $id_shop_group = null, $id_shop = null) { if (!Validate::isConfigName($key)) { die(sprintf(Tools::displayError('[%s] is not a valid configuration key'), $key)); } if ($id_shop === null || !Shop::isFeatureActive()) { $id_shop = Shop::getContextShopID(true); } if ($id_shop_group === null || !Shop::isFeatureActive()) { $id_shop_group = Shop::getContextShopGroupID(true); } if (!is_array($values)) { $values = array($values); } if ($html) { $html = Tools::purifyHTML($html); } $result = true; foreach ($values as $lang => $value) { $stored_value = Configuration::get($key, $lang, $id_shop_group, $id_shop); // if there isn't a $stored_value, we must insert $value if (!is_numeric($value) && $value === $stored_value || is_numeric($value) && $value == $stored_value && Configuration::hasKey($key, $lang)) { continue; } // If key already exists, update value if (Configuration::hasKey($key, $lang, $id_shop_group, $id_shop)) { if (!$lang) { // Update config not linked to lang $result &= Db::getInstance()->update(self::$definition['table'], array('value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s')), '`name` = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop), 1, true); } else { // Update multi lang $sql = 'UPDATE `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '_lang` cl SET cl.value = \'' . pSQL($value, $html) . '\', cl.date_upd = NOW() WHERE cl.id_lang = ' . (int) $lang . ' AND cl.`' . bqSQL(self::$definition['primary']) . '` = ( SELECT c.`' . bqSQL(self::$definition['primary']) . '` FROM `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '` c WHERE c.name = \'' . pSQL($key) . '\'' . Configuration::sqlRestriction($id_shop_group, $id_shop) . ')'; $result &= Db::getInstance()->execute($sql); } } else { if (!($configID = Configuration::getIdByName($key, $id_shop_group, $id_shop))) { $newConfig = new Configuration(); $newConfig->name = $key; if ($id_shop) { $newConfig->id_shop = (int) $id_shop; } if ($id_shop_group) { $newConfig->id_shop_group = (int) $id_shop_group; } if (!$lang) { $newConfig->value = $value; } $result &= $newConfig->add(true, true); $configID = $newConfig->id; } if ($lang) { $result &= Db::getInstance()->insert(self::$definition['table'] . '_lang', array(self::$definition['primary'] => $configID, 'id_lang' => (int) $lang, 'value' => pSQL($value, $html), 'date_upd' => date('Y-m-d H:i:s'))); } } } Configuration::set($key, $values, $id_shop_group, $id_shop); return $result; }
/** * Send a mail when a customer return an order. * * @param array $params Hook params. */ public function hookActionOrderReturn($params) { if (!$this->return_slip || empty($this->return_slip)) { return; } $context = Context::getContext(); $id_lang = (int) $context->language->id; $id_shop = (int) $context->shop->id; $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_COLOR'), $id_lang, null, $id_shop); // Shop iso $iso = Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT')); $order = new Order((int) $params['orderReturn']->id_order); $customer = new Customer((int) $params['orderReturn']->id_customer); $delivery = new Address((int) $order->id_address_delivery); $invoice = new Address((int) $order->id_address_invoice); $order_date_text = Tools::displayDate($order->date_add); if ($delivery->id_state) { $delivery_state = new State((int) $delivery->id_state); } if ($invoice->id_state) { $invoice_state = new State((int) $invoice->id_state); } $order_return_products = OrderReturn::getOrdersReturnProducts($params['orderReturn']->id, $order); $items_table = ''; foreach ($order_return_products as $key => $product) { $url = $context->link->getProductLink($product['product_id']); $items_table .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['product_reference'] . '</td> <td style="padding:0.6em 0.4em;"> <strong><a href="' . $url . '">' . $product['product_name'] . '</a> </strong> </td> <td style="padding:0.6em 0.4em; text-align:center;">' . (int) $product['product_quantity'] . '</td> </tr>'; } $template_vars = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => MailAlert::getFormatedAddress($delivery, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>')), '{invoice_block_html}' => MailAlert::getFormatedAddress($invoice, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>')), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => $order->reference, '{shop_name}' => $configuration['PS_SHOP_NAME'], '{date}' => $order_date_text, '{items}' => $items_table, '{message}' => Tools::purifyHTML($params['orderReturn']->question)); // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails); foreach ($merchant_mails as $merchant_mail) { // Default language $mail_id_lang = $id_lang; $mail_iso = $iso; // Use the merchant lang if he exists as an employee $results = Db::getInstance()->executeS(' SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'employee` WHERE `email` = \'' . pSQL($merchant_mail) . '\' '); if ($results) { $user_iso = Language::getIsoById((int) $results[0]['id_lang']); if ($user_iso) { $mail_id_lang = (int) $results[0]['id_lang']; $mail_iso = $user_iso; } } $dir_mail = false; if (file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/return_slip.txt') && file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/return_slip.html')) { $dir_mail = dirname(__FILE__) . '/mails/'; } if (file_exists(_PS_MAIL_DIR_ . $mail_iso . '/return_slip.txt') && file_exists(_PS_MAIL_DIR_ . $mail_iso . '/return_slip.html')) { $dir_mail = _PS_MAIL_DIR_; } if ($dir_mail) { Mail::Send($mail_id_lang, 'return_slip', sprintf(Mail::l('New return from order #%d - %s', $mail_id_lang), $order->id, $order->reference), $template_vars, $merchant_mail, null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, $dir_mail, null, $id_shop); } } }
/** * Format product description by removing potential hazardous code * @param string $desc description to be cleaned */ public static function formatDescription($desc) { if (method_exists('Tools', 'purifyHTML')) { $desc = Tools::purifyHTML($desc); } return $desc; }