/** * Test the Language class. * * @return void * @access public */ public function testLanguage() { $l = new Language(); $this->assertEquals($l->getLanguage('eng'), 'English'); $this->assertEquals($l->getLanguage('??'), 'Unknown'); $this->assertEquals($l->getCode('English'), 'eng'); $this->assertEquals($l->getCode('???'), false); }
/** * override method: get list image from articles. */ function getListByParameters($params, $pparams) { global $smarty, $cookie; $numberOFAr = $params->get("custom-num", 5); $list = array(); $id_lang = $cookie->id_lang; $curLang = Language::getLanguage(intval($cookie->id_lang)); $lofiso_code = $curLang["iso_code"]; for ($i = 1; $i <= $numberOFAr; $i++) { $index = $i - 1; $name = 'gci_' . $id_lang . "-" . $i; $list[$index]["name"] = $params->get($name . "-title", ""); //if($params->get($id_lang."-".$i."-type","")) $list[$index]["classicon"] = "lof-" . $params->get($name . "-type", "") . " " . "lof-" . $params->get($name . "-type", "") . $lofiso_code; $list[$index]["link"] = $params->get($name . "-link", ""); $list[$index]["price"] = $params->get($name . "-price", ""); $list[$index]["image"] = $params->get($name . "-image", ""); $list[$index]["mainImge"] = $list[$index]["image"]; $list[$index]["thumbImge"] = $list[$index]["image"]; if ($list[$index]["thumbImge"]) { if ($params->get("cre_thumb", 1)) { $list[$index] = $this->generateImages($list[$index], $params); } } $list[$index]["description"] = $params->get($name . "-desc", ""); if ($list[$index]["name"] != "") { $list[$index]["name"] = $list[$index]["name"]; } if ($list[$index]['link']) { $list[$index]['link'] = $this->addhttp($list[$index]['link']); $list[$index]['description'] = $list[$index]['description'] . "<a href='" . $list[$index]['link'] . "' title='" . $list[$index]['title'] . "' >" . $params->get('readmore_txt', '[More...]') . "</a>"; } } return $list; }
public function getContent() { $output = '<h2>' . $this->displayName . '</h2>'; if (Tools::isSubmit('submit' . $this->name)) { foreach ($this->custom_attributes as $i => $value) { Configuration::updateValue($value, Tools::getValue($value)); } $output .= $this->displayConfirmation($this->l('Settings updated')); } $output .= $this->renderForm(); $shop_url = (Configuration::get('PS_SSL_ENABLED') ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__; $default_lang_name = Language::getLanguage($this->id_lang); $default_lang_name = $default_lang_name['name']; $output .= ' <fieldset class="space"> <legend><img src="../img/admin/unknown.gif" alt="" class="middle" />' . $this->l('Help') . '</legend> <h2>' . $this->l('Registration') . '</h2> <p>' . $this->l('Register your price list on site') . ' <a class="action_module" href="http://partner.market.yandex.ru/">http://partner.market.yandex.ru</a><br/><br/> ' . $this->l('Use the following address as a price list address') . ':<br/> <div> <a style="padding: 5px; border: 1px solid;" class="action_module" href="' . $shop_url . 'modules/yamarketdealers/">' . $shop_url . 'modules/yamarketdealers/</a> </div> </p> <h2>' . $this->l('Miscellaneous') . '</h2> <p>' . $this->l('When filling the attribute name fields, it is necessary to use default shop language') . '. ' . $this->l('Current default shop language: ') . $default_lang_name . '</p> <p class="warn"> ' . $this->l('When using vendor.model offer type, make sure you have filled the manufacturer name field for all your products') . '. </p> </fieldset>'; return $output; }
public function __construct(Language $language = null, $dbInstanceKey = null) { parent::__construct($dbInstanceKey); if ($language === null) { $shortName = false; if (isset($_GET['language']) && $this->languageExists($_GET['language'])) { $shortName = $_GET['language']; } elseif (isset($_SESSION['language']) && $this->languageExists($_SESSION['language'])) { $shortName = $_SESSION['language']; } elseif (isset($_COOKIE['language']) && $this->languageExists($_COOKIE['language'])) { $shortName = $_COOKIE['language']; } if ($shortName !== false) { $language = Language::getLanguage($shortName); } else { $language = $this->getDefaultLanguage(); } } if ($language instanceof Language) { $this->language = $language; $this->setLanguage($language); } else { throw new InvalidArgumentException("Argument should be instanse of Language"); } }
public function __construct($id = null, $id_lang = null, $id_shop = null) { parent::__construct($id, null, $id_shop); if (!is_null($id_lang)) { $this->id_lang = (int) (Language::getLanguage($id_lang) !== false) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'); } if ($this->id) { $this->associated_shops = $this->getAssociatedShops(); } $this->image_dir = _PS_EMPLOYEE_IMG_DIR_; }
public function __construct() { $this->name = 'themeconfigurator'; $this->tab = 'front_office_features'; $this->version = '0.3'; $this->bootstrap = true; $this->secure_key = Tools::encrypt($this->name); $this->default_language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT')); $this->languages = Language::getLanguages(); $this->author = 'PrestaShop'; parent::__construct(); $this->displayName = $this->l('Theme configurator'); $this->description = $this->l('Configure the main elements of your theme.'); $this->module_path = _PS_MODULE_DIR_ . $this->name . '/'; $this->uploads_path = _PS_MODULE_DIR_ . $this->name . '/img/'; $this->admin_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/admin/'; $this->hooks_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/hooks/'; }
public function __construct($id = null, $id_lang = null) { parent::__construct($id); if (!is_null($id_lang)) { $this->id_lang = (int) (Language::getLanguage($id_lang) !== false) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'); } if ($this->id_customer) { if (isset(Context::getContext()->customer) && Context::getContext()->customer->id == $this->id_customer) { $customer = Context::getContext()->customer; } else { $customer = new Customer((int) $this->id_customer); } Cart::$_customer = $customer; if ((!$this->secure_key || $this->secure_key == '-1') && $customer->secure_key) { $this->secure_key = $customer->secure_key; $this->save(); } } $this->setTaxCalculationMethod(); }
public function __construct() { $this->name = 'ptsthemepanel'; $this->tab = 'front_office_features'; $this->version = '1.6.0'; $this->bootstrap = true; $this->secure_key = Tools::encrypt($this->name); $this->default_language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT')); $this->languages = Language::getLanguages(); $this->author = 'PrestaBrain'; parent::__construct(); $this->displayName = $this->l('PTS Theme Control Panel'); $this->description = $this->l('Configure the main elements of your theme.'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); $this->module_path = _PS_MODULE_DIR_ . $this->name . '/'; $this->uploads_path = _PS_MODULE_DIR_ . $this->name . '/img/'; $this->admin_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/admin/'; $this->hooks_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/hooks/'; $this->theme_name = Context::getContext()->shop->getTheme(); $this->themes = $this->getThemes(); $this->is_showed = $this->isOwnTheme(); }
public function __construct() { $this->name = 'tmhtmlcontent'; // Defines module name $this->tab = 'other'; // Defines module tab name/module category in the admin panel $this->author = 'TemplateMonster'; // Defines module author $this->version = '1.0'; // Defines module version $this->secure_key = Tools::encrypt($this->name); $this->_defaultLanguage = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT')); $this->_languages = Language::getLanguages(); parent::__construct(); $this->displayName = $this->l('TM HTML content'); $this->desctiption = $this->l('Module for HTML content with images and links.'); // Paths $this->module_path = _PS_MODULE_DIR_ . $this->name . '/'; $this->uploads_path = _PS_MODULE_DIR_ . $this->name . '/images/'; $this->admin_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/admin/'; $this->hooks_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/hooks/'; }
/** * Get cookie content */ public function update($nullValues = false) { if (isset($_COOKIE[$this->_name])) { /* Decrypt cookie content */ $content = $this->_cipherTool->decrypt($_COOKIE[$this->_name]); //printf("\$content = %s<br />", $content); /* Get cookie checksum */ $tmpTab = explode('¤', $content); array_pop($tmpTab); $content_for_checksum = implode('¤', $tmpTab) . '¤'; $checksum = crc32($this->_salt . $content_for_checksum); //printf("\$checksum = %s<br />", $checksum); /* Unserialize cookie content */ $tmpTab = explode('¤', $content); foreach ($tmpTab as $keyAndValue) { $tmpTab2 = explode('|', $keyAndValue); if (count($tmpTab2) == 2) { $this->_content[$tmpTab2[0]] = $tmpTab2[1]; } } /* Blowfish fix */ if (isset($this->_content['checksum'])) { $this->_content['checksum'] = (int) $this->_content['checksum']; } //printf("\$this->_content['checksum'] = %s<br />", $this->_content['checksum']); //die(); /* Check if cookie has not been modified */ if (!isset($this->_content['checksum']) || $this->_content['checksum'] != $checksum) { $this->logout(); } if (!isset($this->_content['date_add'])) { $this->_content['date_add'] = date('Y-m-d H:i:s'); } } else { $this->_content['date_add'] = date('Y-m-d H:i:s'); } //checks if the language exists, if not choose the default language if (!$this->_standalone && !Language::getLanguage((int) $this->id_lang)) { $this->id_lang = Configuration::get('PS_LANG_DEFAULT'); // set detect_language to force going through Tools::setCookieLanguage to figure out browser lang $this->detect_language = true; } }
protected function supplyOrdersImportOne($info, $force_ids, $current_line, $validateOnly = false) { // sets default values if needed AdminImportController::setDefaultValues($info); // if an id is set, instanciates a supply order with this id if possible if (array_key_exists('id', $info) && (int) $info['id'] && SupplyOrder::exists((int) $info['id'])) { $supply_order = new SupplyOrder((int) $info['id']); } elseif (array_key_exists('reference', $info) && $info['reference'] && SupplyOrder::exists(pSQL($info['reference']))) { $supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['reference'])); } else { // new supply order $supply_order = new SupplyOrder(); } // gets parameters $id_supplier = (int) $info['id_supplier']; $id_lang = (int) $info['id_lang']; $id_warehouse = (int) $info['id_warehouse']; $id_currency = (int) $info['id_currency']; $reference = pSQL($info['reference']); $date_delivery_expected = pSQL($info['date_delivery_expected']); $discount_rate = (double) $info['discount_rate']; $is_template = (bool) $info['is_template']; $error = ''; // checks parameters if (!Supplier::supplierExists($id_supplier)) { $error = sprintf($this->l('Supplier ID (%d) is not valid (at line %d).'), $id_supplier, $current_line + 1); } if (!Language::getLanguage($id_lang)) { $error = sprintf($this->l('Lang ID (%d) is not valid (at line %d).'), $id_lang, $current_line + 1); } if (!Warehouse::exists($id_warehouse)) { $error = sprintf($this->l('Warehouse ID (%d) is not valid (at line %d).'), $id_warehouse, $current_line + 1); } if (!Currency::getCurrency($id_currency)) { $error = sprintf($this->l('Currency ID (%d) is not valid (at line %d).'), $id_currency, $current_line + 1); } if (empty($supply_order->reference) && SupplyOrder::exists($reference)) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!empty($supply_order->reference) && ($supply_order->reference != $reference && SupplyOrder::exists($reference))) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!Validate::isDateFormat($date_delivery_expected)) { $error = sprintf($this->l('Date format (%s) is not valid (at line %d). It should be: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } elseif (new DateTime($date_delivery_expected) <= new DateTime('yesterday')) { $error = sprintf($this->l('Date (%s) cannot be in the past (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } if ($discount_rate < 0 || $discount_rate > 100) { $error = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100')); } if ($supply_order->id > 0 && !$supply_order->isEditable()) { $error = sprintf($this->l('Supply Order (%d) is not editable (at line %d).'), $supply_order->id, $current_line + 1); } // if no errors, sets supply order if (empty($error)) { // adds parameters $info['id_ref_currency'] = (int) Currency::getDefaultCurrency()->id; $info['supplier_name'] = pSQL(Supplier::getNameById($id_supplier)); if ($supply_order->id > 0) { $info['id_supply_order_state'] = (int) $supply_order->id_supply_order_state; $info['id'] = (int) $supply_order->id; } else { $info['id_supply_order_state'] = 1; } // sets parameters AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order); // updatesd($supply_order); $res = false; if ((int) $supply_order->id && ($supply_order->exists((int) $supply_order->id) || $supply_order->exists($supply_order->reference))) { $res = $validateOnly || $supply_order->update(); } else { $supply_order->force_id = (bool) $force_ids; $res = $validateOnly || $supply_order->add(); } // errors if (!$res) { $this->errors[] = sprintf($this->l('Supply Order could not be saved (at line %d).'), $current_line + 1); } } else { $this->errors[] = $error; } }
public function display() { global $cookie; $currency = Currency::getCurrency(Configuration::get('PS_CURRENCY_DEFAULT')); $language = Language::getLanguage(intval($cookie->id_lang)); $iso = $language['iso_code']; $dateBetween = ModuleGraph::getDateBetween(); $sales = self::getSales($dateBetween); $carts = self::getCarts($dateBetween); $records = self::getRecords($dateBetween); echo ' <div style="float: left">'; $this->displayCalendar(); $this->displayMenu(false); $this->displayEngines(); $this->displaySearch(); echo ' </div> <div style="float: left; margin-left: 40px;"> <fieldset class="width3"><legend><img src="../img/admin/tab-stats.gif" /> ' . $this->l('Help') . '</legend> <p>' . $this->l('Use the calendar on the left to select the time period.') . '</p> <p>' . $this->l('All available statistic modules are displayed in the Navigation list beneath the calendar.') . '</p> <p>' . $this->l('In the Settings sub-tab, you can also customize the Stats tab to fit your needs and resources, change the graph rendering engine, and adjust the database settings.') . '</p> </fieldset> <br /><br /> <fieldset class="width3"><legend><img src="../img/admin/___info-ca.gif" style="vertical-align: middle" /> ' . $this->l('Sales') . '</legend> <table> <tr><td style="font-weight: bold">' . $this->l('Total placed orders') . '</td><td style="padding-left: 20px">' . $sales['orders'] . '</td></tr> <tr><td style="font-weight: bold">' . $this->l('Total products sold') . '</td><td style="padding-left: 20px">' . $sales['products'] . '</td></tr> </table> <table cellspacing="0" cellpadding="0" class="table space"> <tr> <th style="width: 150px"></th> <th style="width: 180px; text-align: center; font-weight: bold">' . $this->l('total paid with tax') . '</th> <th style="width: 220px; text-align: center; font-weight: bold">' . $this->l('total products not incl. tax') . '</th> </tr> <tr> <th style="font-weight: bold">' . $this->l('Sales turnover') . '</th> <td align="right">' . Tools::displayPrice($sales['ttc'], $currency) . '</td> <td align="right">' . Tools::displayPrice($sales['ht'], $currency) . '</td> </tr> <tr> <th style="font-weight: bold">' . $this->l('Largest order') . '</th> <td align="right">' . Tools::displayPrice($sales['maxttc'], $currency) . '</td> <td align="right">' . Tools::displayPrice($sales['maxht'], $currency) . '</td> </tr> <tr> <th style="font-weight: bold">' . $this->l('Smallest order') . '</th> <td align="right">' . Tools::displayPrice($sales['minttc'], $currency) . '</td> <td align="right">' . Tools::displayPrice($sales['minht'], $currency) . '</td> </tr> </table> </fieldset> <br /><br /> <fieldset class="width3"><legend><img src="../img/admin/products.gif" style="vertical-align: middle" /> ' . $this->l('Carts') . '</legend> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 150px"></th> <th style="width: 180px; text-align: center; font-weight: bold">' . $this->l('Products total all tax inc.') . '</th> </tr> <tr> <th style="font-weight: bold">' . $this->l('Average cart') . '</th> <td align="right">' . Tools::displayPrice($carts['average'], $currency) . '</td> </tr> <tr> <th style="font-weight: bold">' . $this->l('Largest cart') . '</th> <td align="right">' . Tools::displayPrice($carts['highest'], $currency) . '</td> </tr> <tr> <th style="font-weight: bold">' . $this->l('Smallest cart') . '</th> <td align="right">' . Tools::displayPrice($carts['lowest'], $currency) . '</td> </tr> </table> </fieldset>'; if (strtolower($cookie->stats_granularity) != 'd' and $records and is_array($records)) { echo ' <br /><br /> <fieldset class="width3"><legend><img src="../img/admin/medal.png" style="vertical-align: middle" />' . $this->l('Records') . '</legend> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 150px"></th> <th style="width: 100px; text-align: center; font-weight: bold">' . $this->l('date') . '</th> <th style="width: 120px; text-align: center; font-weight: bold">' . $this->l('with tax') . '</th> <th style="width: 180px; text-align: center; font-weight: bold">' . $this->l('only products not incl. tax') . '</th> </tr>'; if (strtolower($cookie->stats_granularity) == 'y') { echo ' <tr> <th style="font-weight: bold">' . $this->l('Best month') . '</th> <td align="right">' . $this->displayDate($records['bestmonth']['date'], $iso) . '</td> <td align="right">' . Tools::displayPrice($records['bestmonth']['totalttc'], $currency) . '</td> <td align="right">' . Tools::displayPrice($records['bestmonth']['totalht'], $currency) . '</td> </tr> <tr> <th style="font-weight: bold">' . $this->l('Worst month') . '</th> <td align="right">' . $this->displayDate($records['worstmonth']['date'], $iso) . '</td> <td align="right">' . Tools::displayPrice($records['worstmonth']['totalttc'], $currency) . '</td> <td align="right">' . Tools::displayPrice($records['worstmonth']['totalht'], $currency) . '</td> </tr>'; } echo ' <tr> <th style="font-weight: bold">' . $this->l('Best day') . '</th> <td align="right">' . $this->displayDate($records['bestday']['date'], $iso) . '</td> <td align="right">' . Tools::displayPrice($records['bestday']['totalttc'], $currency) . '</td> <td align="right">' . Tools::displayPrice($records['bestday']['totalht'], $currency) . '</td> </tr> <tr> <th style="font-weight: bold">' . $this->l('Worst day') . '</th> <td align="right">' . $this->displayDate($records['worstday']['date'], $iso) . '</td> <td align="right">' . Tools::displayPrice($records['worstday']['totalttc'], $currency) . '</td> <td align="right">' . Tools::displayPrice($records['worstday']['totalht'], $currency) . '</td> </tr> </table> </fieldset>'; } echo ' </div> <div class="clear"></div>'; }
/** * Builds the object * * @param int|null $id If specified, loads and existing object from DB (optional). * @param int|null $id_lang Required if object is multilingual (optional). * @param int|null $id_shop ID shop for objects with multishop tables. * * @throws PrestaShopDatabaseException * @throws PrestaShopException */ public function __construct($id = null, $id_lang = null, $id_shop = null) { $class_name = get_class($this); if (!isset(ObjectModel::$loaded_classes[$class_name])) { $this->def = ObjectModel::getDefinition($class_name); $this->setDefinitionRetrocompatibility(); if (!Validate::isTableOrIdentifier($this->def['primary']) || !Validate::isTableOrIdentifier($this->def['table'])) { throw new PrestaShopException('Identifier or table format not valid for class ' . $class_name); } ObjectModel::$loaded_classes[$class_name] = get_object_vars($this); } else { foreach (ObjectModel::$loaded_classes[$class_name] as $key => $value) { $this->{$key} = $value; } } if ($id_lang !== null) { $this->id_lang = Language::getLanguage($id_lang) !== false ? $id_lang : Configuration::get('PS_LANG_DEFAULT'); } if ($id_shop && $this->isMultishop()) { $this->id_shop = (int) $id_shop; $this->get_shop_from_context = false; } if ($this->isMultishop() && !$this->id_shop) { $this->id_shop = Context::getContext()->shop->id; } if ($id) { $entity_mapper = Adapter_ServiceLocator::get("Adapter_EntityMapper"); $entity_mapper->load($id, $id_lang, $this, $this->def, $this->id_shop, self::$cache_objects); } }
public function __construct() { // need to set this in constructor to allow translation TSBuyerProtection::$payments_type = array('DIRECT_DEBIT' => $this->l('Direct debit'), 'CREDIT_CARD' => $this->l('Credit Card'), 'INVOICE' => $this->l('Invoice'), 'CASH_ON_DELIVERY' => $this->l('Cash on delivery'), 'PREPAYMENT' => $this->l('Prepayment'), 'CHEQUE' => $this->l('Cheque'), 'PAYBOX' => $this->l('Paybox'), 'PAYPAL' => $this->l('PayPal'), 'CASH_ON_PICKUP' => $this->l('Cash on pickup'), 'FINANCING' => $this->l('Financing'), 'LEASING' => $this->l('Leasing'), 'T_PAY' => $this->l('T-Pay'), 'CLICKANDBUY' => $this->l('Click&Buy'), 'GIROPAY' => $this->l('Giropay'), 'GOOGLE_CHECKOUT' => $this->l('Google Checkout'), 'SHOP_CARD' => $this->l('Online shop payment card'), 'DIRECT_E_BANKING' => $this->l('DIRECTebanking.com'), 'MONEYBOOKERS' => $this->l('moneybookers.com'), 'OTHER' => $this->l('Other method of payment')); $this->tab_name = $this->l('Trusted Shops quality seal and buyer protection'); $this->site_url = Tools::htmlentitiesutf8('http://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__); TSBPException::setTranslationObject($this); if (!method_exists('Tools', 'jsonDecode') || !method_exists('Tools', 'jsonEncode')) { $this->warnings[] = $this->l('Json functions must be implemented in your php version'); } else { foreach ($this->available_languages as $iso => $lang) { if ($lang === '') { $this->available_languages[$iso] = Language::getLanguage(Language::getIdByIso($iso)); } TSBuyerProtection::$CERTIFICATE[strtoupper($iso)] = (array) Tools::jsonDecode(Tools::htmlentitiesDecodeUTF8(Configuration::get(TSBuyerProtection::PREFIX_TABLE . 'CERTIFICATE_' . strtoupper($iso)))); } if (TSBuyerProtection::$SHOPSW === NULL) { TSBuyerProtection::$SHOPSW = Configuration::get(TSBuyerProtection::PREFIX_TABLE . 'SHOPSW'); TSBuyerProtection::$ET_CID = Configuration::get(TSBuyerProtection::PREFIX_TABLE . 'ET_CID'); TSBuyerProtection::$ET_LID = Configuration::get(TSBuyerProtection::PREFIX_TABLE . 'ET_LID'); TSBuyerProtection::$DEFAULT_LANG = (int) Configuration::get('PS_LANG_DEFAULT'); TSBuyerProtection::$CAT_ID = (int) Configuration::get(TSBuyerProtection::PREFIX_TABLE . 'CAT_ID'); TSBuyerProtection::$ENV_API = Configuration::get(TSBuyerProtection::PREFIX_TABLE . 'ENV_API'); } } }
/** * view() - Метод рендеринга приложения, * включает в шаблон объекты и отображает их * @access public final * @return application */ public final function view() { /** * Импортирую параметры в шаблон */ $breadcrumbs = $this->__setBreadcrumbs($this->APPLICATION->GetCurPage()); /** * Устанавливаю CSS стили для каталога */ $this->APPLICATION->SetAdditionalCSS($this->_CONFIG['CSS_PATH'] . '/autocat.css'); /** * Устанавливаю JavaScript */ $this->APPLICATION->AddHeadScript($this->_CONFIG['JQUERY_PATH'] . '/jquery.min.js'); // подключаю jQuery Google $this->APPLICATION->AddHeadScript($this->_CONFIG['JS_PATH'] . '/autocat.js'); // главный скрипт Init /** * Устанавливаю переменные в шаблон */ $this->_setobj('breadcrumbs', $breadcrumbs); // загружаем крошки $this->_setobj('config', $this->_CONFIG); // загружаем конфигурации //$this->_setobj('version', $this->__getVersion()); // информация о сервисе if (empty($this->GET_data)) { $this->APPLICATION->SetTitle(Language::getLanguage('TITLE')); // заголовок по умолчанию $marks = $this->_getManufacturers(); //DEBUG::deBug($marks); $this->_setobj('marks', $marks); // загружаем марки из Сессии if ($this->_CONFIG['ENABLE_CACHE']) { if (!$this->_CACHE->isCached()) { /** * Если страница не закэширована * Если страницы разные, то будем их заменять */ $this->_CACHE->setCachePage($this->__templateBuffer()); // устанавливаем ее в кэш } else { /** * Достаем из кэша */ $this->_CACHE->getCachePage(); } } else { $this->__includeTemplate($this->_TEMPLATE); } // подключаем шаблон } else { /** * Если передаются $_GET параметры, * то каталог подгружает следующие шаблоны */ //DEBUG::deBug($this->GET_data); $this->_TEMPLATE = $this->GET_data['view']; // присваиваю шаблону значение из GET if (!empty($this->GET_data['manufacturer_id'])) { /** * Определяю по каким параметрам загружать страницу */ $this->_TITLE = ucwords($this->GET_data['manufacturer_id']); // получаю TITLE $this->_manuId = $this->_getManufacturerID($this->GET_data['manufacturer_id']); // загружаю модели $cars = (array) $this->_getModels($this->_manuId); // ID производителя try { if (!isset($this->GET_data['model_id'])) { /** * 2ая страница (Загрузка моделей) */ if (!$this->_manuId) { $this->_TITLE = ucwords(Language::getLanguage('CATEGORY_NOT_FOUND')); // заголовок $this->APPLICATION->SetTitle($this->_TITLE); // устанавливаю заголовок throw new Exception(Language::getLanguage('CATEGORY_NOT_FOUND')); // выбрасываю исключение } } else { if (isset($this->GET_data['parts_id'])) { if (isset($this->GET_data['kit_id'])) { if (isset($this->GET_data['prod_id'])) { /** * 6ая страница (Карточка товара) */ $article = explode("_", $this->GET_data['prod_id']); // разбиваю URL //Debug::deBug($this->_getDocument($article[1],$article[0])); $cars = (array) $this->_getFlyCard($this->_getDocument((int) $article[1], (int) $article[0])); // загружаю карточку товар //Debug::deBug($cars); $_getProductName = $this->_getProductName(); //Debug::deBug($_getProductName); $this->_setobj('brand', $_getProductName['brand']); // устанавливаю значение для брэнда $this->_setobj('article', $_getProductName['article']); // устанавливаю значение для артикула $this->_TITLE = ucwords($_getProductName['title']); // получаю TITLE if (!is_array($cars) || empty($cars)) { $this->_TITLE = ucwords(Language::getLanguage('PRODUCT_NOT_FOUND')); // заголовок $this->APPLICATION->SetTitle($this->_TITLE); // устанавливаю заголовок throw new Exception(Language::getLanguage('PRODUCT_NOT_FOUND')); // выбрасываю исключение } } else { /** * 5ая страница (Выгрузка таблицы запчастей , после древовидного меню) */ $cars = $this->_getListPostitionTable($this->GET_data['kit_id'], $this->GET_data['parts_id']); // загружаю список запчастей $this->_TITLE = ucwords($this->__getEngineName()); // получаю TITLE //Debug::deBug($cars); if (!is_array($cars) || empty($cars)) { $this->_TITLE = ucwords(Language::getLanguage('KIT_NOT_FOUND')); // заголовок $this->APPLICATION->SetTitle($this->_TITLE); // устанавливаю заголовок throw new Exception(Language::getLanguage('KIT_NOT_FOUND')); // выбрасываю исключение } } } else { /** * 4ая страница (Выгрузка дерева списка комплектующих) */ $cars = $this->_getEnginePartsTree($this->GET_data['parts_id']); // загружаю список комплектующих $this->_TITLE = Language::getLanguage('PARTS_FOR_MODEL'); $this->_TITLE .= ucwords($this->GET_data['manufacturer_id'] . ' ' . $this->GET_data['model_id']); // получаю TITLE //Debug::deBug($cars); if (!is_array($cars) || empty($cars)) { $this->_TITLE = ucwords(Language::getLanguage('PARTS_NOT_FOUND')); // заголовок $this->APPLICATION->SetTitle($this->_TITLE); // устанавливаю заголовок throw new Exception(Language::getLanguage('PARTS_NOT_FOUND')); // выбрасываю исключение } } } else { /** * 3ая страница (Загрузка модификаций моделей) */ $this->_modelId = $this->_getModelID($this->GET_data['model_id']); // загружаю модификации $this->_TITLE = ucwords($this->GET_data['model_id']); // получаю TITLE $cars = (array) $this->_getModifications($this->_manuId, $this->_modelId); // получаю модификации if (!$this->_modelId) { $this->_TITLE = ucwords(Language::getLanguage('MODEL_NOT_FOUND')); // заголовок $this->APPLICATION->SetTitle($this->_TITLE); // устанавливаю заголовок throw new Exception(Language::getLanguage('MODEL_NOT_FOUND')); // выбрасываю исключение } } } $this->APPLICATION->SetTitle($this->_TITLE); // устанавливаю заголовок $this->_setobj('title', $this->_TITLE); // устанавливаю заголовокв шаблон $this->_setobj('url', $this->GET_data); // передаю параметры для URL $this->_setobj('models', $cars); // загружаем данные SOAP в шаблон if ($this->_CONFIG['ENABLE_CACHE']) { if ($this->_CONFIG['ENABLE_CACHE']) { if (!$this->_CACHE->isCached()) { /** * Если страница не закэширована * Если страницы разные, то будем их заменять */ $this->_CACHE->setCachePage($this->__templateBuffer()); // устанавливаем ее в кэш } else { /** * Достаем из кэша */ $this->_CACHE->getCachePage(); } } else { $this->__includeTemplate($this->_TEMPLATE); } // подключаем шаблон } else { $this->__includeTemplate($this->_TEMPLATE); } // подключаем шаблон } catch (Exception $e) { /** * Выбрасываю скромное исключение */ echo $e->getMessage(); } } else { $this->__setRedirect('/'); } // выкидываем } }
/** * Process posting data */ public function postProcess() { $languages = Language::getLanguages(false); $current_theme = Theme::getThemeInfo($this->context->shop->id_theme); //$theme_arr['theme_id'] = $theme->id; // $theme_arr['theme_name'] = $theme->name; // $theme_arr['theme_directory'] = $theme->directory; if (Tools::isSubmit('submitnewOption')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); $addaction = false; } else { $option = new Options(); $addaction = true; } $option->column = Tools::getValue('colselected'); $option->theme = strtolower($current_theme['theme_name']); $option->alias = Tools::getValue('alias'); $option->active = (int) Tools::getValue('active'); $name_set = false; $option_name = Tools::getValue('option_name'); if (strlen($option_name) > 0) { $name_set = true; $option->name = $option_name; } if (!$name_set) { $lang_title = Language::getLanguage($this->context->language->id); $this->errors[] = Tools::displayError('This item title field is required'); } if (strlen($option->alias) > 0) { if (OvicLayoutControl::isAvailablebyAlias($option->alias) > 0) { $this->errors[] = Tools::displayError('Alias is avaiable in database'); } } else { $this->errors[] = Tools::displayError('This item alias field is required'); } if (isset($_FILES['option_img']) && strlen($_FILES['option_img']['name']) > 0) { $img_name = time() . $_FILES['option_img']['name']; $img_name = preg_replace('/[^A-Za-z0-9\\-.]/', '', $img_name); // Removes special chars. //_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $this->name .DIRECTORY_SEPARATOR $main_name = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'oviclayoutcontrol' . DIRECTORY_SEPARATOR . 'thumbnails' . DIRECTORY_SEPARATOR . $img_name; if (!move_uploaded_file($_FILES['option_img']['tmp_name'], $main_name)) { $this->errors[] = Tools::displayError('An error occurred during the image upload.'); } else { $option->image = $img_name; if (Tools::getValue('old_img') != '') { $filename = Tools::getValue('old_img'); if (file_exists(_PS_MODULE_DIR_ . 'oviclayoutcontrol/thumbnails/' . $filename)) { @unlink(_PS_MODULE_DIR_ . 'oviclayoutcontrol/thumbnails/' . $filename); } } } } else { $option->image = Tools::getValue('old_img'); } if (!count($this->errors)) { if ($addaction) { if (!$option->add()) { $this->errors[] = Tools::displayError('An error occurred while saving data.'); } else { if (Tools::getIsset('id_copy_option')) { $id_copy_option = (int) Tools::getValue('id_copy_option'); $source_option = new Options($id_copy_option); OvicLayoutControl::copyHookModule($source_option, $option); OvicLayoutControl::copyOptionStyle($source_option, $option); } else { OvicLayoutControl::registerDefaultHookModule($option->id); } } } else { if (!$option->update()) { $this->errors[] = Tools::displayError('An error occurred while update data.'); } } if (!count($this->errors)) { Tools::redirectAdmin(self::$currentIndex . '&conf=3&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('changeactive')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); $option->active = !$option->active; if (!$option->update()) { $this->errors[] = Tools::displayError('Could not change'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=5&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('removeoption')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); if (!$option->delete()) { $this->errors[] = Tools::displayError('An error occurred during deletion'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=1&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('submitMultiSave')) { $id_option = (int) Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $fonts = array(); foreach (OvicLayoutControl::$OptionFonts as $font) { $fonts[$font] = Tools::getValue($font); } $colors = array(); foreach (OvicLayoutControl::$OptionColors as $color) { $colors[$color] = Tools::getValue($color); } $option = new Options($id_option); $where = "`theme` = '" . $option->theme . "' AND `alias` = '" . $option->alias . "'"; $sql = 'SELECT `alias` FROM `' . _DB_PREFIX_ . 'ovic_options_style` WHERE ' . $where; if (Db::getInstance()->getRow($sql)) { $result = Db::getInstance()->update('ovic_options_style', array('color' => Tools::jsonEncode($colors), 'font' => Tools::jsonEncode($fonts)), $where); } else { // Register module in hook $result = Db::getInstance()->insert('ovic_options_style', array('theme' => $option->theme, 'alias' => $option->alias, 'color' => Tools::jsonEncode($colors), 'font' => Tools::jsonEncode($fonts))); } if ($result) { Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . Tools::getValue('token') . '&view=detail&id_option=' . $id_option); } else { $this->errors[] = Tools::displayError('An error occurred while saving data.'); } } } parent::postProcess(); }
public function getContent() { $output = '<h2>' . $this->displayName . '</h2>'; if (Tools::isSubmit('submit' . $this->name)) { foreach ($this->custom_attributes as $i => $value) { Configuration::updateValue($value, Tools::getValue($value)); } // Categories $selected_cats = array(); foreach (Tools::getValue('categoryBox') as $row) { $selected_cats[] = $row; } $this->excluded_cats = array(); foreach ($this->all_cats as $cat) { if (!in_array($cat, $selected_cats)) { $this->excluded_cats[] = $cat; } } Configuration::updateValue('TOPSHOP_EXCLUDED_CATS', implode(',', $this->excluded_cats)); $output .= $this->displayConfirmation($this->l('Settings updated')); } $output .= $this->renderForm(); $shop_url = (Configuration::get('PS_SSL_ENABLED') ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__; $default_lang_name = Language::getLanguage($this->id_lang); $default_lang_name = $default_lang_name['name']; $output .= ' <fieldset class="space"> <legend><img src="../img/admin/unknown.gif" alt="" class="middle" />' . $this->l('Help') . '</legend> <br> <div> <a style="padding: 5px; border: 1px solid;" class="action_module" href="' . $shop_url . 'modules/topshop/">' . $shop_url . 'modules/topshop/</a> </div> </p> <h2>' . $this->l('Miscellaneous') . '</h2> <p>' . $this->l('When filling the attribute name fields, it is necessary to use default shop language') . '. ' . $this->l('Current default shop language: ') . $default_lang_name . '</p> <p class="warn"> ' . $this->l('When using vendor.model offer type, make sure you have filled the manufacturer name field for all your products') . '. </p> </fieldset>'; return $output; }
/** * Display date regarding to language preferences * * @param string $date Date to display format UNIX * @param integer $id_lang Language id * @param boolean $full With time or not (optional) * @return string Date */ public static function displayDate($date, $id_lang, $full = false, $separator = '-') { if (!$date or !($time = strtotime($date))) { return $date; } if (!Validate::isDate($date) or !Validate::isBool($full)) { die(self::displayError('Invalid date')); } $language = Language::getLanguage((int) $id_lang); return date($full ? $language['date_format_full'] : $language['date_format_lite'], $time); }
/** * @since 1.5.0 */ public function supplyOrdersImport() { // opens CSV & sets locale $this->receiveTab(); $handle = $this->openCsvFile(); AdminImportController::setLocale(); // main loop, for each supply orders to import for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); ++$current_line) { // if convert requested if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); // sets default values if needed AdminImportController::setDefaultValues($info); // if an id is set, instanciates a supply order with this id if possible if (array_key_exists('id', $info) && (int) $info['id'] && SupplyOrder::exists((int) $info['id'])) { $supply_order = new SupplyOrder((int) $info['id']); } elseif (array_key_exists('reference', $info) && $info['reference'] && SupplyOrder::exists(pSQL($info['reference']))) { $supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['reference'])); } else { // new supply order $supply_order = new SupplyOrder(); } // gets parameters $id_supplier = (int) $info['id_supplier']; $id_lang = (int) $info['id_lang']; $id_warehouse = (int) $info['id_warehouse']; $id_currency = (int) $info['id_currency']; $reference = pSQL($info['reference']); $date_delivery_expected = pSQL($info['date_delivery_expected']); $discount_rate = (double) $info['discount_rate']; $is_template = (bool) $info['is_template']; $error = ''; // checks parameters if (!Supplier::supplierExists($id_supplier)) { $error = sprintf($this->l('Supplier ID (%d) is not valid (at line %d).'), $id_supplier, $current_line + 1); } if (!Language::getLanguage($id_lang)) { $error = sprintf($this->l('Lang ID (%d) is not valid (at line %d).'), $id_lang, $current_line + 1); } if (!Warehouse::exists($id_warehouse)) { $error = sprintf($this->l('Warehouse ID (%d) is not valid (at line %d).'), $id_warehouse, $current_line + 1); } if (!Currency::getCurrency($id_currency)) { $error = sprintf($this->l('Currency ID (%d) is not valid (at line %d).'), $id_currency, $current_line + 1); } if (empty($supply_order->reference) && SupplyOrder::exists($reference)) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!empty($supply_order->reference) && ($supply_order->reference != $reference && SupplyOrder::exists($reference))) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!Validate::isDateFormat($date_delivery_expected)) { $error = sprintf($this->l('Date (%s) is not valid (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } elseif (new DateTime($date_delivery_expected) <= new DateTime('yesterday')) { $error = sprintf($this->l('Date (%s) cannot be in the past (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } if ($discount_rate < 0 || $discount_rate > 100) { $error = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100')); } if ($supply_order->id > 0 && !$supply_order->isEditable()) { $error = sprintf($this->l('Supply Order (%d) is not editable (at line %d).'), $supply_order->id, $current_line + 1); } // if no errors, sets supply order if (empty($error)) { // adds parameters $info['id_ref_currency'] = (int) Currency::getDefaultCurrency()->id; $info['supplier_name'] = pSQL(Supplier::getNameById($id_supplier)); if ($supply_order->id > 0) { $info['id_supply_order_state'] = (int) $supply_order->id_supply_order_state; $info['id'] = (int) $supply_order->id; } else { $info['id_supply_order_state'] = 1; } // sets parameters AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order); // updatesd($supply_order); $res = true; if ((int) $supply_order->id && ($supply_order->exists((int) $supply_order->id) || $supply_order->exists($supply_order->reference))) { $res &= $supply_order->update(); } else { $supply_order->force_id = (bool) Tools::getValue('forceIDs'); $res &= $supply_order->add(); } // errors if (!$res) { $this->errors[] = sprintf($this->l('Supply Order could not be saved (at line %d).'), $current_line + 1); } } else { $this->errors[] = $error; } } // closes $this->closeCsvFile($handle); }
/** * Build object * * @param integer $id Existing object id in order to load object (optional) * @param integer $id_lang Required if object is multilingual (optional) */ public function __construct($id = null, $id_lang = null) { if ($id_lang != null && Language::getLanguage((int) $id_lang)) { $this->id_lang = (int) $id_lang; } elseif ($id_lang != null) { $this->id_lang = _PS_LANG_DEFAULT_; } /* Connect to database and check SQL table/identifier */ if (!Validate::isTableOrIdentifier($this->identifier . $this->table)) { die(Tools::displayError()); } /* Load object from database if object id is present */ if ($id) { $this->identifier = pSQL($this->identifier); if (!isset(self::$_cache[$this->table][(int) $id][(int) $id_lang])) { self::$_cache[$this->table][(int) $id][(int) $id_lang] = Db::getInstance()->getRow(' SELECT * FROM `' . _DB_PREFIX_ . $this->table . '` a ' . ($id_lang ? 'LEFT JOIN `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` b ON (a.`' . $this->identifier . '` = b.`' . $this->identifier . '` AND `id_lang` = ' . (int) $id_lang . ')' : '') . ' WHERE a.`' . $this->identifier . '` = ' . (int) $id); } $result = self::$_cache[$this->table][(int) $id][(int) $id_lang]; if ($result) { $this->id = (int) $id; foreach ($result as $key => $value) { if (key_exists($key, $this)) { $this->{$key} = $value; } } /* Join multilingual tables */ if (!$id_lang && method_exists($this, 'getTranslationsFieldsChild')) { $result = Db::getInstance()->ExecuteS(' SELECT * FROM `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` WHERE `' . $this->identifier . '` = ' . (int) $id); if ($result) { foreach ($result as $row) { foreach ($row as $key => $value) { if (key_exists($key, $this) && $key != $this->identifier) { if (!is_array($this->{$key})) { $this->{$key} = array(); } $this->{$key}[(int) $row['id_lang']] = $value; } } } } } } } if (!isset(self::$fieldsRequiredDatabase)) { self::$fieldsRequiredDatabase = array(); if ($fields = $this->getfieldsRequiredDatabase(true)) { foreach ($fields as $row) { self::$fieldsRequiredDatabase[$row['object_name']][(int) $row['id_required_field']] = pSQL($row['field_name']); } } } }
/** * Get cookie content */ function update($nullValues = false) { if (isset($_COOKIE[$this->_name])) { /* Decrypt cookie content */ $content = $this->_cipherTool->decrypt($_COOKIE[$this->_name]); /* Get cookie checksum */ $mbStrValue = 1 << 1 & ini_get('mbstring.func_overload') ? 1 : 2; $checksum = crc32($this->_iv . substr($content, 0, strrpos($content, '¤') + $mbStrValue)); /* Unserialize cookie content */ $tmpTab = explode('¤', $content); foreach ($tmpTab as $keyAndValue) { $tmpTab2 = explode('|', $keyAndValue); if (sizeof($tmpTab2) == 2) { $this->_content[$tmpTab2[0]] = $tmpTab2[1]; } } /* Blowfish fix */ if (isset($this->_content['checksum'])) { $this->_content['checksum'] = (int) $this->_content['checksum']; } /* Check if cookie has not been modified */ if (!isset($this->_content['checksum']) or $this->_content['checksum'] != $checksum) { $this->logout(); } if (!isset($this->_content['date_add'])) { $this->_content['date_add'] = date('Y-m-d H:i:s'); } } else { $this->_content['date_add'] = date('Y-m-d H:i:s'); } //checks if the language exists, if not choose the default language if (!Language::getLanguage((int) $this->id_lang)) { $this->id_lang = Configuration::get('PS_LANG_DEFAULT'); } }
/** * Build object * * @param int $id Existing object id in order to load object (optional) * @param int $id_lang Required if object is multilingual (optional) * @param int $id_shop ID shop for objects with multishop on langs */ public function __construct($id = null, $id_lang = null, $id_shop = null) { if (!ObjectModel::$db) { ObjectModel::$db = Db::getInstance(); } $this->def = ObjectModel::getDefinition($this); $this->setDefinitionRetrocompatibility(); if ($id_lang !== null) { $this->id_lang = Language::getLanguage($id_lang) !== false ? $id_lang : Configuration::get('PS_LANG_DEFAULT'); } if ($id_shop && $this->isMultishop()) { $this->id_shop = (int) $id_shop; $this->get_shop_from_context = false; } if ($this->isMultishop() && !$this->id_shop) { $this->id_shop = Context::getContext()->shop->id; } if (!Validate::isTableOrIdentifier($this->def['primary']) || !Validate::isTableOrIdentifier($this->def['table'])) { throw new PrestaShopException('Identifier or table format not valid for class ' . get_class($this)); } if ($id) { // Load object from database if object id is present $cache_id = 'objectmodel_' . $this->def['classname'] . '_' . (int) $id . '_' . (int) $this->id_shop . '_' . (int) $id_lang; if (!Cache::isStored($cache_id)) { $sql = new DbQuery(); $sql->from($this->def['table'], 'a'); $sql->where('a.' . $this->def['primary'] . ' = ' . (int) $id); // Get lang informations if ($id_lang) { $sql->leftJoin($this->def['table'] . '_lang', 'b', 'a.' . $this->def['primary'] . ' = b.' . $this->def['primary'] . ' AND b.id_lang = ' . (int) $id_lang); if ($this->id_shop && !empty($this->def['multilang_shop'])) { $sql->where('b.id_shop = ' . $this->id_shop); } } // Get shop informations if (Shop::isTableAssociated($this->def['table'])) { $sql->leftJoin($this->def['table'] . '_shop', 'c', 'a.' . $this->def['primary'] . ' = c.' . $this->def['primary'] . ' AND c.id_shop = ' . (int) $this->id_shop); } if ($object_datas = ObjectModel::$db->getRow($sql)) { if (!$id_lang && isset($this->def['multilang']) && $this->def['multilang']) { $sql = 'SELECT * FROM `' . pSQL(_DB_PREFIX_ . $this->def['table']) . '_lang` WHERE `' . bqSQL($this->def['primary']) . '` = ' . (int) $id . ($this->id_shop && $this->isLangMultishop() ? ' AND `id_shop` = ' . $this->id_shop : ''); if ($object_datas_lang = ObjectModel::$db->executeS($sql)) { foreach ($object_datas_lang as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != $this->def['primary']) { if (!isset($object_datas[$key]) || !is_array($object_datas[$key])) { $object_datas[$key] = array(); } $object_datas[$key][$row['id_lang']] = $value; } } } } } Cache::store($cache_id, $object_datas); } } else { $object_datas = Cache::retrieve($cache_id); } if ($object_datas) { $this->id = (int) $id; foreach ($object_datas as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } }
private function _handleNewSlide() { $languages = Language::getLanguages(false); $id_lang = (int) Tools::getValue('language'); $lang = Language::getLanguage($id_lang); $id_shop = (int) $this->context->shop->id; $lastSlideID = Db::getInstance()->ExecuteS('SELECT id_slide, id_order FROM `' . _DB_PREFIX_ . 'minic_slider` WHERE id_lang = ' . $id_lang . ' AND id_shop = ' . $id_shop . ' ORDER BY id_slide DESC LIMIT 1'); $currentSlideID = $lastSlideID ? $lastSlideID[0]['id_slide'] + 1 : 1; $currentOrderID = $lastSlideID ? $lastSlideID[0]['id_order'] + 1 : 1; if (empty($_FILES['image']['name'])) { $this->context->smarty->assign('error', $this->l('Image needed, please choose one.')); return false; } $image = $this->_resizer($_FILES['image'], Tools::getValue('imageName')); if (!$image) { return false; } $insert = Db::getInstance()->Execute(' INSERT INTO `' . _DB_PREFIX_ . 'minic_slider` ( id_shop, id_lang, id_order, lang_iso, title, url, target, image, alt, caption ) VALUES ( "' . $id_shop . '", "' . (int) Tools::getValue('language') . '", "' . $currentOrderID . '", "' . $lang['iso_code'] . '", "' . Tools::getValue('title') . '", "' . Tools::getValue('url') . '", "' . (int) Tools::getValue('target') . '", "' . $image . '", "' . Tools::getValue('alt') . '", "' . pSQL(Tools::getValue('caption'), true) . '") '); if (!$insert) { $this->_deleteImages($image); $this->context->smarty->assign('error', $this->l('An error occured while saving data.')); return false; } $this->context->smarty->assign('confirmation', $this->l('New slide added successfull.')); }
public function getContent() { $output = ''; $errors = array(); $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); if (Tools::getValue('confirm_msg')) { $this->context->smarty->assign('confirmation', Tools::getValue('confirm_msg')); } if (Tools::isSubmit('submitnewItem')) { $id_item = (int) Tools::getValue('item_id'); if ($id_item && Validate::isUnsignedId($id_item)) { $new_item = new Item($id_item); } else { $new_item = new Item(); } $new_item->id_block = Tools::getValue('block_id'); $new_item->type = Tools::getValue('linktype'); $new_item->active = (int) Tools::getValue('active'); $itemtitle_set = false; foreach ($languages as $language) { $item_title = Tools::getValue('item_title_' . $language['id_lang']); if (strlen($item_title) > 0) { $itemtitle_set = true; } $new_item->title[$language['id_lang']] = $item_title; } if (!$itemtitle_set) { $lang_title = Language::getLanguage($this->context->language->id); if ($new_item->type == 'img') { $errors[] = 'This Alt text field is required at least in ' . $lang_title['name']; } else { $errors[] = 'This item title field is required at least in ' . $lang_title['name']; } } $new_item->class = Tools::getValue('custom_class'); if ($new_item->type == 'link') { $new_item->icon = Tools::getValue('item_icon'); $new_item->link = Tools::getValue('link_value'); } elseif ($new_item->type == 'img') { if (isset($_FILES['item_img']) && strlen($_FILES['item_img']['name']) > 0) { if (!($img_file = $this->moveUploadedImage($_FILES['item_img']))) { $errors[] = 'An error occurred during the image upload.'; } else { $new_item->icon = $img_file; if (Tools::getValue('old_img') != '') { $filename = Tools::getValue('old_img'); if (file_exists(dirname(__FILE__) . '/img/' . $filename)) { @unlink(dirname(__FILE__) . '/img/' . $filename); } } } } else { $new_item->icon = Tools::getValue('old_img'); } $new_item->link = Tools::getValue('link_value'); } elseif ($new_item->type == 'html') { foreach ($languages as $language) { $new_item->text[$language['id_lang']] = Tools::getValue('item_html_' . $language['id_lang']); } } if (!count($errors)) { if ($id_item && Validate::isUnsignedId($id_item)) { if (!$new_item->update()) { $errors[] = 'An error occurred while update data.'; } } else { if (!$new_item->add()) { $errors[] = 'An error occurred while saving data.'; } } if (!count($errors)) { if ($id_item && Validate::isUnsignedId($id_item)) { $this->context->smarty->assign('confirmation', $this->l('Item successfully updated.')); } else { $confirm_msg = $this->l('New item successfully added.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } } } } elseif (Tools::isSubmit('submit_del_item')) { $item_id = Tools::getValue('item_id'); if ($item_id && Validate::isUnsignedId($item_id)) { $subs = $this->getSupMenu($item_id); $del = true; if ($subs && count($subs) > 0) { } foreach ($subs as $sub) { $del &= $this->deleteSub($sub['id_sub']); } $item = new Item($item_id); if (!$item->delete() || !$del) { $errors[] = 'An error occurred while delete item.'; } else { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); $this->context->smarty->assign('confirmation', $this->l('Delete successful.')); } } } elseif (Tools::isSubmit('submitnewsub')) { $id_sub = Tools::getValue('id_sub'); if ($id_sub && Validate::isUnsignedId($id_sub)) { $sub = new Submenu($id_sub); } else { $sub = new Submenu(); } $sub->id_parent = Tools::getValue('id_parent'); $sub->width = Tools::getValue('subwidth'); $sub->class = Tools::getValue('sub_class'); $sub->active = Tools::getValue('active'); if ($id_sub && Validate::isUnsignedId($id_sub)) { if (!$sub->update()) { $errors[] = 'An error occurred while update data.'; } } else { if (!$sub->checkAvaiable()) { if (!$sub->add()) { $errors[] = 'An error occurred while saving data.'; } } else { $parent_item = new Item($sub->id_parent); $errors[] = $parent_item->title[$this->context->language->id] . ' already have a sub.'; } } if (!count($errors)) { if ($id_sub && Validate::isUnsignedId($id_sub)) { $this->context->smarty->assign('confirmation', $this->l('Submenu successfully updated.')); } else { $confirm_msg = $this->l('New sub successfully added.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } } } elseif (Tools::isSubmit('submit_del_sub')) { $id_sub = (int) Tools::getValue('id_sub'); if ($id_sub && Validate::isUnsignedId($id_sub)) { if (!$this->deleteSub($id_sub)) { $errors[] = 'An error occurred while delete sub menu.'; } else { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); $this->context->smarty->assign('confirmation', $this->l('Delete successful.')); } } } elseif (Tools::isSubmit('submitnewblock')) { $id_block = Tools::getValue('id_block'); if ($id_block && Validate::isUnsignedId($id_block)) { $block = new Block($id_block); } else { $block = new Block(); } $block->id_sub = Tools::getValue('id_sub'); $block->width = Tools::getValue('block_widh'); $block->class = Tools::getValue('block_class'); if ($id_block && Validate::isUnsignedId($id_block)) { if (!$block->update()) { $errors[] = 'An error occurred while update block.'; } } else { if (!$block->add()) { $errors[] = 'An error occurred while saving data.'; } } if (!count($errors)) { if ($id_block && Validate::isUnsignedId($id_block)) { $this->context->smarty->assign('confirmation', $this->l('Block successfully updated.')); } else { $confirm_msg = $this->l('New block successfully added.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } } } elseif (Tools::isSubmit('submit_del_block')) { $id_block = Tools::getValue('id_block'); if ($id_block && Validate::isUnsignedId($id_block)) { if (!$this->deleteBlock($id_block)) { $errors[] = 'An error occurred while delete block.'; } else { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); $this->context->smarty->assign('confirmation', $this->l('Delete successful.')); } } } elseif (Tools::isSubmit('changeactive')) { $id_item = (int) Tools::getValue('item_id'); if ($id_item && Validate::isUnsignedId($id_item)) { $item = new Item($id_item); $item->active = !$item->active; if (!$item->update()) { $errors[] = $this->displayError('Could not change'); } else { $confirm_msg = $this->l('Successfully updated.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } } } elseif (Tools::isSubmit('changestatus')) { $id_sub = (int) Tools::getValue('id_sub'); if ($id_sub && Validate::isUnsignedId($id_sub)) { $sub_menu = new Submenu($id_sub); $sub_menu->active = !$sub_menu->active; if (!$sub_menu->update()) { $errors[] = $this->displayError('Could not change'); } else { $confirm_msg = $this->l('Submenu successfully updated.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } } } $this->context->smarty->assign(array('admin_tpl_path' => $this->admin_tpl_path, 'postAction' => AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'))); if (count($errors) > 0) { if (isset($errors) && count($errors)) { $output .= $this->displayError(implode('<br />', $errors)); } } if (Tools::isSubmit('submit_edit_item') || Tools::isSubmit('submitnewItem') && count($errors) > 0) { $output .= $this->displayItemForm(); } elseif (Tools::isSubmit('submit_edit_sub')) { $output .= $this->displaySubForm(); } elseif (Tools::isSubmit('submit_new_block')) { $output .= $this->displayBlockForm(); } else { $output .= $this->displayForm(); } return $output; }
public function ajaxProcessAddAttachment() { if (isset($_FILES['attachment_file'])) { if ((int) $_FILES['attachment_file']['error'] === 1) { $_FILES['attachment_file']['error'] = array(); $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $upload_mb = min($max_upload, $max_post); $_FILES['attachment_file']['error'][] = sprintf($this->l('File %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>'); } $_FILES['attachment_file']['error'] = array(); $is_attachment_name_valid = false; $attachment_names = Tools::getValue('attachment_name'); $attachment_descriptions = Tools::getValue('attachment_description'); if (!isset($attachment_names) || !$attachment_names) { $attachment_names = array(); } if (!isset($attachment_descriptions) || !$attachment_descriptions) { $attachment_descriptions = array(); } foreach ($attachment_names as $lang => $name) { $language = Language::getLanguage((int) $lang); if (Tools::strlen($name) > 0) { $is_attachment_name_valid = true; } if (!Validate::isGenericName($name)) { $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid name for %s language'), $language['name']); } elseif (Tools::strlen($name) > 32) { $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('The name for %1s language is too long (%2d chars max).'), $language['name'], 32); } } foreach ($attachment_descriptions as $lang => $description) { $language = Language::getLanguage((int) $lang); if (!Validate::isCleanHtml($description)) { $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid description for %s language'), $language['name']); } } if (!$is_attachment_name_valid) { $_FILES['attachment_file']['error'][] = Tools::displayError('An attachment name is required.'); } if (empty($_FILES['attachment_file']['error'])) { if (is_uploaded_file($_FILES['attachment_file']['tmp_name'])) { if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) { $_FILES['attachment_file']['error'][] = sprintf($this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '')); } else { do { $uniqid = sha1(microtime()); } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid)); if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) { $_FILES['attachment_file']['error'][] = $this->l('File copy failed'); } @unlink($_FILES['attachment_file']['tmp_name']); } } else { $_FILES['attachment_file']['error'][] = Tools::displayError('The file is missing.'); } if (empty($_FILES['attachment_file']['error']) && isset($uniqid)) { $attachment = new Attachment(); foreach ($attachment_names as $lang => $name) { $attachment->name[(int) $lang] = $name; } foreach ($attachment_descriptions as $lang => $description) { $attachment->description[(int) $lang] = $description; } $attachment->file = $uniqid; $attachment->mime = $_FILES['attachment_file']['type']; $attachment->file_name = $_FILES['attachment_file']['name']; if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) { $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file extension'); } if (!Validate::isGenericName($attachment->file_name)) { $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file name'); } if (Tools::strlen($attachment->file_name) > 128) { $_FILES['attachment_file']['error'][] = Tools::displayError('The file name is too long.'); } if (empty($this->errors)) { $res = $attachment->add(); if (!$res) { $_FILES['attachment_file']['error'][] = Tools::displayError('This attachment was unable to be loaded into the database.'); } else { $_FILES['attachment_file']['id_attachment'] = $attachment->id; $_FILES['attachment_file']['filename'] = $attachment->name[$this->context->employee->id_lang]; $id_product = (int) Tools::getValue($this->identifier); $res = $attachment->attachProduct($id_product); if (!$res) { $_FILES['attachment_file']['error'][] = Tools::displayError('We were unable to associate this attachment to a product.'); } } } else { $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file'); } } } die(Tools::jsonEncode($_FILES)); } }
/** * Process posting data */ public function postProcess() { $errors = array(); $languages = Language::getLanguages(false); if (Tools::isSubmit('submitnewOption')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); $addaction = false; } else { $option = new Options(); $addaction = true; } $option->column = Tools::getValue('colselected'); $option->active = (int) Tools::getValue('active'); $name_set = false; foreach ($languages as $language) { $option_name = Tools::getValue('option_name_' . $language['id_lang']); if (strlen($option_name) > 0) { $name_set = true; } $option->name[$language['id_lang']] = $option_name; } if (!$name_set) { $lang_title = Language::getLanguage($this->context->language->id); $errors[] = Tools::displayError('This item title field is required at least in ' . $lang_title['name']); } if (isset($_FILES['option_img']) && strlen($_FILES['option_img']['name']) > 0) { $img_name = time() . $_FILES['option_img']['name']; $img_name = preg_replace('/[^A-Za-z0-9\\-.]/', '', $img_name); // Removes special chars. //_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $this->name .DIRECTORY_SEPARATOR $main_name = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'oviclayoutcontrol' . DIRECTORY_SEPARATOR . 'thumbnails' . DIRECTORY_SEPARATOR . $img_name; if (!move_uploaded_file($_FILES['option_img']['tmp_name'], $main_name)) { $errors[] = Tools::displayError('An error occurred during the image upload.'); } else { $option->image = $img_name; if (Tools::getValue('old_img') != '') { $filename = Tools::getValue('old_img'); if (file_exists(_PS_MODULE_DIR_ . 'oviclayoutcontrol/thumbnails/' . $filename)) { @unlink(_PS_MODULE_DIR_ . 'oviclayoutcontrol/thumbnails/' . $filename); } } } } else { $option->image = Tools::getValue('old_img'); } if (!count($errors)) { if ($addaction) { if (!$option->add()) { $errors[] = Tools::displayError('An error occurred while saving data.'); } else { if (Tools::getIsset('id_copy_option')) { $id_copy_option = Tools::getValue('id_copy_option'); OvicLayoutControl::copyHookModule($id_copy_option, $option->id); } else { OvicLayoutControl::registerDefaultHookModule($option->id); } } } else { if (!$option->update()) { $errors[] = Tools::displayError('An error occurred while update data.'); } } if (!count($errors)) { Tools::redirectAdmin(self::$currentIndex . '&conf=3&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('changeactive')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); $option->active = !$option->active; if (!$option->update()) { $errors[] = Tools::displayError('Could not change'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=5&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('removeoption')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); if (!$option->delete()) { $errors[] = Tools::displayError('An error occurred during deletion'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=1&token=' . Tools::getValue('token')); } } } else { $this->context->controller->errors = array_merge($this->context->controller->errors, $errors); } parent::postProcess(); }
public function filterLanguage() { $arr_languages = array(); $length_values = strlen($this->urlFragments['language']); // if just one language is asked if (is_numeric($this->urlFragments['language'])) { $arr_languages[] = (int) $this->urlFragments['language']; } elseif (strpos($this->urlFragments['language'], '[') === 0 && strpos($this->urlFragments['language'], ']') === $length_values - 1) { if (strpos($this->urlFragments['language'], '|') !== false xor strpos($this->urlFragments['language'], ',') !== false) { $params_values = str_replace(array(']', '['), '', $this->urlFragments['language']); // it's a list if (strpos($params_values, '|') !== false) { $list_enabled_lang = explode('|', $params_values); $arr_languages = $list_enabled_lang; } elseif (strpos($params_values, ',') !== false) { $range_enabled_lang = explode(',', $params_values); if (count($range_enabled_lang) != 2) { $this->setError(400, 'A range value for a language must contains only 2 values', 78); return false; } for ($i = $range_enabled_lang[0]; $i <= $range_enabled_lang[1]; $i++) { $arr_languages[] = $i; } } } else { if (preg_match('#\\[(\\d)+\\]#Ui', $this->urlFragments['language'], $match_lang)) { $arr_languages[] = $match_lang[1]; } } } else { $this->setError(400, 'language value is wrong', 79); return false; } $result = array_map('is_numeric', $arr_languages); if (array_search(false, $result, true)) { $this->setError(400, 'Language ID must be numeric', 80); return false; } foreach ($arr_languages as $key => $id_lang) { if (!Language::getLanguage($id_lang)) { unset($arr_languages[$key]); } } return $arr_languages; }
/** * @param Offer $obj * @throws Exception * @throws SmartyException */ public function initFormImages($obj) { $data = $this->createTemplate($this->tpl_form); if ((bool) $obj->id) { // if ($this->offer_exists_in_shop) { $data->assign('offer', $this->loadObject()); $count_images = Db::getInstance()->getValue(' SELECT COUNT(id_offer) FROM ' . _DB_PREFIX_ . 'offer_image WHERE id_offer = ' . (int) $obj->id); $images = AphOfferImage::getImages($this->context->language->id, $obj->id); foreach ($images as $k => $image) { $images[$k] = new AphOfferImage($image['id_image']); } if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP) { $current_shop_id = (int) $this->context->shop->id; } else { $current_shop_id = 0; } $language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT')); $image_uploader = new HelperImageUploader('file'); $image_uploader->setTemplateDirectory($this->tpl_dir . 'helpers/uploader/')->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminAphOffers') . '&ajax=1&id_offer=' . (int) $obj->id . '&action=addOfferImage')->setTemplate('ajax.tpl'); $data->assign(array('countImages' => $count_images, 'id_offer' => (int) Tools::getValue('id_offer'), 'images' => $images, 'iso_lang' => $language['iso_code'], 'token' => $this->token, 'table' => $this->table, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'currency' => $this->context->currency, 'current_shop_id' => $current_shop_id, 'languages' => $this->_languages, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'image_uploader' => $image_uploader->render())); $type = ImageType::getByNameNType('%', 'products', 'height'); if (isset($type['name'])) { $data->assign('imageType', $type['name']); } else { $data->assign('imageType', ImageType::getFormatedName('small')); } // } else { // $this->displayWarning($this->l('You must save the offer in this shop before adding images.')); // } } else { $this->displayWarning($this->l('You must save this offer before adding images.')); } $this->tpl_form_vars['custom_form'] = $data->fetch(); }
/** * Display date regarding to language preferences * * @param string $date Date to display format UNIX * @param integer $id_lang Language id * @param boolean $full With time or not (optional) * @return string Date */ public static function displayDate($date, $id_lang, $full = false, $separator = '-') { if (!$date or !strtotime($date)) { return $date; } if (!Validate::isDate($date) or !Validate::isBool($full)) { die(self::displayError('Invalid date')); } $tmpTab = explode($separator, substr($date, 0, 10)); $hour = ' ' . substr($date, -8); $language = Language::getLanguage((int) $id_lang); if ($language and strtolower($language['iso_code']) == 'fr') { return $tmpTab[2] . '-' . $tmpTab[1] . '-' . $tmpTab[0] . ($full ? $hour : ''); } else { return $tmpTab[0] . '-' . $tmpTab[1] . '-' . $tmpTab[2] . ($full ? $hour : ''); } }
public function getContent() { $output = ''; $errors = array(); if (Tools::getValue('confirm_msg')) { $output .= $this->displayConfirmation(Tools::getValue('confirm_msg')); } $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $lang_ul = '<ul class="dropdown-menu">'; foreach ($languages as $lg) { $lang_ul .= '<li><a href="javascript:hideOtherLanguage(' . $lg['id_lang'] . ');" tabindex="-1">' . $lg['name'] . '</a></li>'; } $lang_ul .= '</ul>'; $this->context->smarty->assign(array('postAction' => AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'), 'lang_ul' => $lang_ul, 'langguages' => array('default_lang' => $id_lang_default, 'all' => $languages, 'lang_dir' => _THEME_LANG_DIR_))); if (Tools::isSubmit('submitnewrow')) { $id_row = (int) Tools::getValue('id_row'); if ($id_row && Validate::isUnsignedId($id_row)) { $footer_row = new FRow($id_row); } else { $footer_row = new FRow(); } $footer_row->rclass = Tools::getValue('row_class'); $footer_row->active = (int) Tools::getValue('active'); if ($id_row && Validate::isUnsignedId($id_row)) { if (!$footer_row->update()) { $errors[] = 'An error occurred while update data.'; } else { $output .= $this->displayConfirmation('Row successfully updated'); } } else { if (!$footer_row->add()) { $errors[] = 'An error occurred while saving data.'; } else { $confirm_msg = $this->l('New row successfully added'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } } } elseif (Tools::isSubmit('submitSaveBlock')) { $id_block = (int) Tools::getValue('id_block'); if ($id_block && Validate::isUnsignedId($id_block)) { $block = new FBlock($id_block); } else { $block = new FBlock(); } $block->id_row = Tools::getValue('block_row'); $block->display_title = Tools::getValue('title_show'); $block->bclass = Tools::getValue('block_class'); $block->width = Tools::getValue('block_width'); $blocktitle_set = false; foreach ($languages as $language) { $blocktitle = Tools::getValue('blocktitle_' . $language['id_lang']); if (strlen($blocktitle) > 0) { $blocktitle_set = true; } $block->title[$language['id_lang']] = $blocktitle; } if (!$blocktitle_set) { $lang_title = Language::getLanguage($this->context->language->id); $errors[] = 'This block title field is required at least in ' . $lang_title['name']; } if (!count($errors)) { if ($id_block && Validate::isUnsignedId($id_block)) { if ($block->update()) { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); $output .= $this->displayConfirmation('Block Updated'); } else { $errors[] = 'An error occurred while saving block.'; } } else { if ($block->add()) { $confirm_msg = $this->l('Block successfully saved.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } else { $errors[] = 'An error occurred while update block.'; } } } } elseif (Tools::isSubmit('submitRemoveBlock')) { $block_id = Tools::getValue('id_block'); if ($this->deleteBlock($block_id)) { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); $output .= '<div class="alert alert-success">' . $this->l('Block deleted') . '</div>'; } else { $errors[] = 'An error occurred while delete block.'; } } elseif (Tools::isSubmit('submitSaveItem')) { $id_item = Tools::getValue('id_item'); if ($id_item && Validate::isUnsignedId($id_item)) { $id_item = Tools::getValue('id_item'); $item = new FItem($id_item); } else { $item = new FItem(); } $item->id_block = Tools::getValue('block_id'); $itemtitle_set = false; foreach ($languages as $language) { $item_title = Tools::getValue('itemtitle_' . $language['id_lang']); if (strlen($item_title) > 0) { $itemtitle_set = true; } $item->title[$language['id_lang']] = $item_title; } if (!$itemtitle_set) { $lang_title = Language::getLanguage($this->context->language->id); $errors[] = 'This item title field is required at least in ' . $lang_title['name']; } $item->display_title = Tools::getValue('title_show'); $item->itemtype = Tools::getValue('item_type'); switch ($item->itemtype) { case 'link': $item->target = Tools::getValue('target'); $item->content_key = Tools::getValue('linktype'); $k = 'id_' . trim($item->content_key); $item->content_value = Tools::getValue($k); break; case 'html': foreach ($languages as $language) { $item->text[$language['id_lang']] = Tools::getValue('htmlbody_' . $language['id_lang']); } break; case 'module': $item->content_key = Tools::getValue('module'); $item->content_value = Tools::getValue('hook'); break; } if (!count($errors)) { if ($id_item && Validate::isUnsignedId($id_item)) { if ($item->update()) { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); $output .= $this->displayConfirmation('Item Updated'); } else { $errors[] = 'An error occurred while update item.'; } } else { if ($item->add()) { $confirm_msg = $this->l('Item successfully saved.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } else { $errors[] = 'An error occurred while add new item.'; } } } } elseif (Tools::getValue('removeitem') == 1) { $id_item = Tools::getValue('id_item'); if ($id_item && Validate::isUnsignedId($id_item)) { $item = new FItem($id_item); if ($item->delete()) { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); $output .= $this->displayConfirmation('Item deleted'); } else { $errors[] = 'An error occurred while delete item.'; } } } elseif (Tools::isSubmit('changestatus')) { $id_row = (int) Tools::getValue('id_row'); if ($id_row && Validate::isUnsignedId($id_row)) { $f_row = new FRow($id_row); $f_row->active = !$f_row->active; if (!$f_row->update()) { $errors[] = 'An error occurred while chanage status.'; } else { $confirm_msg = $this->l('Row successfully updated.'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg); } } } elseif (Tools::isSubmit('submit_del_row')) { $id_row = (int) Tools::getValue('id_row'); if ($id_row && Validate::isUnsignedId($id_row)) { if (!$this->deleteRow($id_row)) { $errors[] = 'An error occurred while delete row.'; } else { $output .= $this->displayConfirmation('Delete successful'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('advfooter.tpl')); } } } if (count($errors) > 0) { if (isset($errors) && count($errors)) { $output .= $this->displayError(implode('<br />', $errors)); } } if (Tools::isSubmit('submitItem') || Tools::isSubmit('submitSaveItem') && count($errors) > 0) { return $output . $this->displayItemForm(); } elseif (Tools::isSubmit('submitBlock') || Tools::isSubmit('submitSaveBlock') && count($errors) > 0) { return $output . $this->displayBlockForm(); } elseif (Tools::isSubmit('submitRow')) { return $output . $this->displayRowForm(); } else { return $output . $this->displayForm(); } }