private static function getProductByIdParcel($id_parcel) { return Db::getInstance()->executeS(' SELECT `id_product`, `id_product_attribute` FROM `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '` WHERE `id_parcel`=' . (int) $id_parcel); }
function homeslider_stripslashes_field($field) { $quotes = array('"\\\'"', '"\'"'); $dquotes = array('\'\\\\"\'', '\'"\''); $backslashes = array('"\\\\\\\\"', '"\\\\"'); return '`' . bqSQL($field) . '` = replace(replace(replace(`' . bqSQL($field) . '`, ' . $quotes[0] . ', ' . $quotes[1] . '), ' . $dquotes[0] . ', ' . $dquotes[1] . '), ' . $backslashes[0] . ', ' . $backslashes[1] . ')'; }
public function __construct($name = null) { if ($this->name == null) { $this->name = $this->id; } if ($this->name != null) { if (self::$modulesCache === null) { self::$modulesCache = array(); $db = Db::getInstance(); $result = $db->ExecuteS('SELECT * FROM `' . bqSQL(_DB_PREFIX_ . $this->table) . '`', false); while ($row = $db->nextRow($result)) { self::$modulesCache[$row['name']] = $row; } } if (isset(self::$modulesCache[$this->name])) { $this->active = true; $this->id = self::$modulesCache[$this->name]['id_module']; foreach (self::$modulesCache[$this->name] as $key => $value) { if (property_exists($this, $key)) { $this->{$key} = $value; } } $this->_path = __PS_BASE_URI__ . 'modules/' . $this->name . '/'; } } }
public function getData() { $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $this->query = 'SELECT SQL_CALC_FOUND_ROWS cr.code, ocr.name, COUNT(ocr.id_cart_rule) as total, ROUND(SUM(o.total_paid_real) / o.conversion_rate,2) as ca FROM ' . _DB_PREFIX_ . 'order_cart_rule ocr LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_order = ocr.id_order LEFT JOIN ' . _DB_PREFIX_ . 'cart_rule cr ON cr.id_cart_rule = ocr.id_cart_rule WHERE o.valid = 1 ' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . ' AND o.invoice_date BETWEEN ' . $this->getDate() . ' GROUP BY ocr.id_cart_rule'; if (Validate::IsName($this->_sort)) { $this->query .= ' ORDER BY `' . bqSQL($this->_sort) . '`'; if (isset($this->_direction) && (Tools::strtoupper($this->_direction) == 'ASC' || Tools::strtoupper($this->_direction) == 'DESC')) { $this->query .= ' ' . pSQL($this->_direction); } } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) { $this->query .= ' LIMIT ' . (int) $this->_start . ', ' . (int) $this->_limit; } $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query); foreach ($values as &$value) { $value['ca'] = Tools::displayPrice($value['ca'], $currency); } $this->_values = $values; $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); }
protected function getFilterQuery($keys_array = array(), $table) { $sql = ''; foreach ($keys_array as $key) { if ($this->context->cookie->__isset($table . 'Filter_' . $key)) { $value = $this->context->cookie->{$table . 'Filter_' . $key}; if (Validate::isSerializedArray($value)) { $date = $this->module_instance->unSerialize($value); if (!empty($date[0])) { $sql .= '`' . bqSQL($key) . '` > "' . pSQL($date[0]) . '" AND '; } if (!empty($date[1])) { $sql .= '`' . bqSQL($key) . '` < "' . pSQL($date[1]) . '" AND '; } } else { if ($value != '') { $sql .= '`' . bqSQL($key) . '` LIKE "%' . pSQL($value) . '%" AND '; } } } } if ($sql) { $sql = ' HAVING ' . Tools::substr($sql, 0, -4); } // remove 'AND ' from the end of query return $sql; }
public function getData() { $this->_totalCount = $this->getTotalCount(); $this->query = 'SELECT m.name, SUM(od.product_quantity) as quantity, ROUND(SUM(od.product_quantity * od.product_price) / c.conversion_rate, 2) as sales FROM ' . _DB_PREFIX_ . 'order_detail od LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = od.product_id) LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.id_order = od.id_order) LEFT JOIN ' . _DB_PREFIX_ . 'currency c ON (c.id_currency = o.id_currency) LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) WHERE o.invoice_date BETWEEN ' . $this->getDate() . ' ' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . ' AND o.valid = 1 AND m.id_manufacturer IS NOT NULL GROUP BY p.id_manufacturer'; if (Validate::IsName($this->_sort)) { $this->query .= ' ORDER BY `' . bqSQL($this->_sort) . '`'; if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) { $this->query .= ' ' . $this->_direction; } } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) { $this->query .= ' LIMIT ' . (int) $this->_start . ', ' . (int) $this->_limit; } $this->_values = Db::getInstance()->executeS($this->query); }
protected function getFilterQuery($keys_array = array(), $table) { $sql = ''; foreach ($keys_array as $key) { if ($this->context->cookie->{$table . 'Filter_' . $key} !== '' && $this->context->cookie->{$table . 'Filter_' . $key} !== false) { $value = $this->context->cookie->{$table . 'Filter_' . $key}; if ($key == 'id_manifest') { $sql .= '`id_manifest` ' . ($value ? '!=' : '=') . ' "0" AND '; } elseif (is_array(Tools::jsonDecode($value))) { $date = Tools::jsonDecode($value); $date = array_filter($date); if (!$date) { continue; } if (!empty($date[0])) { $sql .= '`' . bqSQL($key) . '` > "' . pSQL($date[0]) . '" AND '; } if (!empty($date[1])) { $sql .= '`' . bqSQL($key) . '` < "' . pSQL($date[1]) . '" AND '; } } else { $sql .= '`' . bqSQL($key) . '` LIKE "%' . pSQL($value) . '%" AND '; } } } if ($sql) { $sql = ' HAVING ' . Tools::substr($sql, 0, -4); } // remove 'AND ' from the end of query return $sql; }
/** * Load ObjectModel * @param $id * @param $id_lang * @param $entity ObjectModel * @param $entity_defs * @param $id_shop * @param $should_cache_objects * @throws PrestaShopDatabaseException */ public function load($id, $id_lang, $entity, $entity_defs, $id_shop, $should_cache_objects) { // Load object from database if object id is present $cache_id = 'objectmodel_' . $entity_defs['classname'] . '_' . (int) $id . '_' . (int) $id_shop . '_' . (int) $id_lang; if (!$should_cache_objects || !Cache::isStored($cache_id)) { $sql = new DbQuery(); $sql->from($entity_defs['table'], 'a'); $sql->where('a.`' . bqSQL($entity_defs['primary']) . '` = ' . (int) $id); // Get lang informations if ($id_lang && isset($entity_defs['multilang']) && $entity_defs['multilang']) { $sql->leftJoin($entity_defs['table'] . '_lang', 'b', 'a.`' . bqSQL($entity_defs['primary']) . '` = b.`' . bqSQL($entity_defs['primary']) . '` AND b.`id_lang` = ' . (int) $id_lang); if ($id_shop && !empty($entity_defs['multilang_shop'])) { $sql->where('b.`id_shop` = ' . (int) $id_shop); } } // Get shop informations if (Shop::isTableAssociated($entity_defs['table'])) { $sql->leftJoin($entity_defs['table'] . '_shop', 'c', 'a.`' . bqSQL($entity_defs['primary']) . '` = c.`' . bqSQL($entity_defs['primary']) . '` AND c.`id_shop` = ' . (int) $id_shop); } if ($object_datas = Db::getInstance()->getRow($sql)) { if (!$id_lang && isset($entity_defs['multilang']) && $entity_defs['multilang']) { $sql = 'SELECT * FROM `' . bqSQL(_DB_PREFIX_ . $entity_defs['table']) . '_lang` WHERE `' . bqSQL($entity_defs['primary']) . '` = ' . (int) $id . ($id_shop && $entity->isLangMultishop() ? ' AND `id_shop` = ' . (int) $id_shop : ''); if ($object_datas_lang = Db::getInstance()->executeS($sql)) { foreach ($object_datas_lang as $row) { foreach ($row as $key => $value) { if ($key != $entity_defs['primary'] && array_key_exists($key, $entity)) { if (!isset($object_datas[$key]) || !is_array($object_datas[$key])) { $object_datas[$key] = array(); } $object_datas[$key][$row['id_lang']] = $value; } } } } } $entity->id = (int) $id; foreach ($object_datas as $key => $value) { if (array_key_exists($key, $entity)) { $entity->{$key} = $value; } else { unset($object_datas[$key]); } } if ($should_cache_objects) { Cache::store($cache_id, $object_datas); } } } else { $object_datas = Cache::retrieve($cache_id); if ($object_datas) { $entity->id = (int) $id; foreach ($object_datas as $key => $value) { $entity->{$key} = $value; } } } }
public function delete($table, $where = false, $limit = false) { if ($this->_link) { $query = 'DELETE FROM `' . bqSQL($table) . '`' . ($where ? ' WHERE ' . $where : '') . ($limit ? ' LIMIT ' . (int) $limit : ''); $res = mysql_query($query); return $res; } return false; }
protected static function _getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group) { $select = '(IF (NOW() >= `from` AND NOW() <= `to`, 1, 0) + '; foreach (array_reverse(SpecificPrice::getPriority((int) $id_product)) as $k => $field) { if ($field != 'id_shop') { $select .= ' IF (`' . bqSQL($field) . '` = ' . (int) ${$field} . ', ' . pow(2, $k + 1) . ', 0) + '; } } return rtrim($select, ' +') . ') `score`'; }
public static function insert($all_data) { $to_insert = array(); if (is_array($all_data) && count($all_data)) { foreach ($all_data as $key => $data) { $to_insert[bqSQL($key)] = pSQL($data); } } Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_delivery_time_options', $to_insert, 'INSERT'); }
public function postProcess() { global $currentIndex; if (isset($_POST['submitDatabase' . $this->table])) { if ($this->tabAccess['edit'] === '1') { foreach ($this->_fieldsDatabase as $field => $values) { if (isset($values['required']) and $values['required']) { if (($value = Tools::getValue($field)) == false and (string) $value != '0') { $this->_errors[] = Tools::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools::displayError('is required.'); } } } if (!sizeof($this->_errors)) { /* Datas are not saved in database but in config/settings.inc.php */ $settings = array(); foreach ($_POST as $k => $value) { if ($value) { $settings['_' . Tools::strtoupper($k) . '_'] = $value; } } rewriteSettingsFile(NULL, NULL, $settings); Tools::redirectAdmin($currentIndex . '&conf=6' . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } if (Tools::isSubmit('submitEngine')) { if (!isset($_POST['tablesBox']) or !sizeof($_POST['tablesBox'])) { $this->_errors[] = Tools::displayError('You did not select any tables'); } else { $available_engines = $this->_getEngines(); $tables_status = $this->_getTablesStatus(); $tables_engine = array(); foreach ($tables_status as $table) { $tables_engine[$table['Name']] = $table['Engine']; } $engineType = pSQL(Tools::getValue('engineType')); /* Datas are not saved in database but in config/settings.inc.php */ $settings = array('_MYSQL_ENGINE_' => $engineType); rewriteSettingsFile(NULL, NULL, $settings); foreach ($_POST['tablesBox'] as $table) { if ($engineType == $tables_engine[$table]) { $this->_errors[] = $table . ' ' . $this->l('is already in') . ' ' . $engineType; } else { if (!Db::getInstance()->Execute('ALTER TABLE `' . bqSQL($table) . '` ENGINE=`' . bqSQL($engineType) . '`')) { $this->_errors[] = $this->l('Can\'t change engine for') . ' ' . $table; } else { echo '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Engine change of') . ' ' . $table . ' ' . $this->l('to') . ' ' . $engineType . '</div>'; } } } } } }
function update_order_canada() { $sql = 'SHOW TABLES LIKE \'' . _DB_PREFIX_ . 'order_tax\''; $table = Db::getInstance()->ExecuteS($sql); if (!count($table)) { Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'order_tax` ( `id_order` int(11) NOT NULL, `tax_name` varchar(40) NOT NULL, `tax_rate` decimal(6,3) NOT NULL, `amount` decimal(20,6) NOT NULL ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8'); $address_field = Configuration::get('PS_TAX_ADDRESS_TYPE'); $sql = 'SELECT `id_order` FROM `' . _DB_PREFIX_ . 'orders` o LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON (a.`id_address` = o.`' . bqSQL($address_field) . '`) LEFT JOIN `' . _DB_PREFIX_ . 'country` c ON (c.`id_country` = a.`id_country`) WHERE c.`iso_code` = "CA"'; $id_order_list = Db::getInstance()->ExecuteS($sql); $values = ''; foreach ($id_order_list as $id_order) { $amount = array(); $id_order = $id_order['id_order']; $order = new Order((int) $id_order); if (!Validate::isLoadedObject($order)) { continue; } $products = $order->getProducts(); foreach ($products as $product) { if (!array_key_exists($product['tax_name'], $amount)) { $amount[$product['tax_name']] = array('amount' => 0, 'rate' => $product['tax_rate']); } if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { $total_product = $product['product_price'] * $product['product_quantity']; $amount_tmp = Tools::ps_round($total_product * ($product['tax_rate'] / 100), 2); $amount[$product['tax_name']]['amount'] += Tools::ps_round($total_product * ($product['tax_rate'] / 100), 2); } else { $total_product = $product['product_price'] * $product['product_quantity']; $amount_tmp = Tools::ps_round($total_product - $total_product / (1 + $product['tax_rate'] / 100), 2); $amount[$product['tax_name']]['amount'] += Tools::ps_round($total_product - $total_product / (1 + $product['tax_rate'] / 100), 2); } } foreach ($amount as $tax_name => $tax_infos) { $values .= '(' . (int) $order->id . ', \'' . pSQL($tax_name) . '\', \'' . pSQL($tax_infos['rate']) . '\', ' . (double) $tax_infos['amount'] . '),'; } unset($order); } if (!empty($values)) { $values = rtrim($values, ","); Db::getInstance()->Execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_tax` (id_order, tax_name, tax_rate, amount) VALUES ' . $values); } } }
protected static function _getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group) { $select = '('; $now = date('Y-m-d H:i:s'); $select .= ' IF (\'' . $now . '\' >= `from` AND \'' . $now . '\' <= `to`, ' . pow(2, 0) . ', 0) + '; $priority = SpecificPrice::getPriority($id_product); foreach (array_reverse($priority) as $k => $field) { $select .= ' IF (`' . bqSQL($field) . '` = ' . (int) ${$field} . ', ' . pow(2, $k + 1) . ', 0) + '; } return rtrim($select, ' +') . ') AS `score`'; }
/** * Returns image type definitions * * @param string|null Image type * @return array Image type definitions */ public static function getImagesTypes($type = null) { if (!isset(self::$images_types_cache[$type])) { $where = 'WHERE 1'; if (!empty($type)) { $where .= ' AND `' . bqSQL($type) . '` = 1 '; } $query = 'SELECT * FROM `' . _DB_PREFIX_ . 'image_type` ' . $where . ' ORDER BY `name` ASC'; self::$images_types_cache[$type] = Db::getInstance()->executeS($query); } return self::$images_types_cache[$type]; }
public static function replace($data) { $to_insert = array(); foreach ($data as $key => $value) { $to_insert[bqSQL($key)] = pSQL($value); } if (version_compare(_PS_VERSION_, '1.5', '>')) { Db::getInstance()->insert('ebay_category_condition_configuration', $to_insert, false, false, Db::REPLACE); } else { Db::getInstance()->execute('REPLACE INTO `' . _DB_PREFIX_ . 'ebay_category_condition_configuration` (`' . implode('` , `', array_keys($to_insert)) . '`) VALUES (\'' . implode('\', \'', $to_insert) . '\')'); } }
public static function getAllData($filter = '', $limit = '', $order_by = '', $order_way = '') { if (!in_array($order_by, self::$available_order_by)) { $order_by = self::DEFAULT_ORDER_BY; } if (!in_array($order_way, self::$available_order_way)) { $order_way = self::DEFAULT_ORDER_WAY; } return DB::getInstance()->executeS(' SELECT `id_postcode`, `postcode`, `region`, `city`, `address` FROM `' . _DB_PREFIX_ . _DPDGROUP_POSTCODE_DB_ . '` ' . $filter . 'ORDER BY `' . bqSQL($order_by) . '` ' . pSQL($order_way) . $limit); }
public function getList($order_by, $order_way, $filter, $start, $pagination) { $order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC'; return Db::getInstance()->executeS(' SELECT m.`id_manifest_ws` AS `id_manifest_ws`, COUNT(p.`id_parcel`) AS `count_parcels`, COUNT(DISTINCT m.`id_package_ws`) AS `count_orders`, m.`date_add` AS `date_add` FROM `' . _DB_PREFIX_ . _DPDPOLAND_MANIFEST_DB_ . '` m LEFT JOIN `' . _DB_PREFIX_ . _DPDPOLAND_PARCEL_DB_ . '` p ON (p.`id_package_ws` = m.`id_package_ws`) GROUP BY `id_manifest_ws` ' . $filter . ' ORDER BY `' . bqSQL($order_by) . '` ' . pSQL($order_way) . ($start !== null && $pagination !== null ? ' LIMIT ' . (int) $start . ', ' . (int) $pagination : '')); }
public function getData() { $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $date_between = $this->getDate(); $array_date_between = explode(' AND ', $date_between); $this->query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name, ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold, IFNULL(stock.quantity, 0) as quantity, IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold, ROUND(IFNULL(IFNULL(SUM(od.product_quantity), 0) / (1 + LEAST(TO_DAYS(' . $array_date_between[1] . '), TO_DAYS(NOW())) - GREATEST(TO_DAYS(' . $array_date_between[0] . '), TO_DAYS(product_shop.date_add))), 0), 2) as averageQuantitySold, ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold, ( SELECT IFNULL(SUM(pv.counter), 0) FROM ' . _DB_PREFIX_ . 'page pa LEFT JOIN ' . _DB_PREFIX_ . 'page_viewed pv ON pa.id_page = pv.id_page LEFT JOIN ' . _DB_PREFIX_ . 'date_range dr ON pv.id_date_range = dr.id_date_range WHERE pa.id_object = p.id_product AND pa.id_page_type = ' . (int) Page::getPageTypeByName('product') . ' AND dr.time_start BETWEEN ' . $date_between . ' AND dr.time_end BETWEEN ' . $date_between . ' ) AS totalPageViewed, product_shop.active FROM ' . _DB_PREFIX_ . 'product p ' . Shop::addSqlAssociation('product', 'p') . ' LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = ' . (int) $this->getLang() . ' ' . Shop::addSqlRestrictionOnLang('pl') . ') LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON od.product_id = p.id_product LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON od.id_order = o.id_order ' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . ' ' . Product::sqlStock('p', 0) . ' WHERE o.valid = 1 AND o.invoice_date BETWEEN ' . $date_between . ' GROUP BY od.product_id'; if (Validate::IsName($this->_sort)) { $this->query .= ' ORDER BY `' . bqSQL($this->_sort) . '`'; if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) { $this->query .= ' ' . $this->_direction; } } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) { $this->query .= ' LIMIT ' . (int) $this->_start . ', ' . (int) $this->_limit; } $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query); foreach ($values as &$value) { $value['avgPriceSold'] = Tools::displayPrice($value['avgPriceSold'], $currency); $value['totalPriceSold'] = Tools::displayPrice($value['totalPriceSold'], $currency); } unset($value); $this->_values = $values; $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); }
/** * Returns image type definitions * * @param string|null Image type * @param bool $order_by_size * @return array Image type definitions * @throws PrestaShopDatabaseException */ public static function getImagesTypes($type = null, $order_by_size = false) { if (!isset(self::$images_types_cache[$type])) { $where = 'WHERE 1'; if (!empty($type)) { $where .= ' AND `' . bqSQL($type) . '` = 1 '; } if ($order_by_size) { $query = 'SELECT * FROM `' . _DB_PREFIX_ . 'image_type` ' . $where . ' ORDER BY `width` DESC, `height` DESC, `name`ASC'; } else { $query = 'SELECT * FROM `' . _DB_PREFIX_ . 'image_type` ' . $where . ' ORDER BY `name` ASC'; } self::$images_types_cache[$type] = Db::getInstance()->executeS($query); } return self::$images_types_cache[$type]; }
public function __construct($id = NULL, $id_lang = NULL) { $this->def = ObjectModel::getDefinition($this); // Check if the id configuration is set in the configuration_lang table. // Otherwise configuration is not set as translated configuration. if ($id !== null) { $id_translated = Db::getInstance()->executeS(' SELECT `' . bqSQL($this->def['primary']) . '` FROM `' . bqSQL(_DB_PREFIX_ . $this->def['table']) . '_lang` WHERE `' . bqSQL($this->def['primary']) . '`=' . (int) $id . ' LIMIT 0,1 '); if (empty($id_translated)) { $id = null; } } parent::__construct($id, $id_lang); }
public static function insertOrUpdate($product_id, $data) { if (!count($data)) { return; } $to_insert = array(); $fields_strs = array(); foreach ($data as $key => $value) { $to_insert[bqSQL($key)] = pSQL($value); $fields_strs[] = '`' . bqSQL($key) . '` = ' . pSQL($value); } $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'ebay_product_configuration` (`id_product`, `' . implode('`,`', array_keys($to_insert)) . '`) VALUES (' . (int) $product_id . ', ' . implode(',', $to_insert) . ') ON DUPLICATE KEY UPDATE '; $sql .= implode(',', $fields_strs); return Db::getInstance()->execute($sql); }
public function postProcess() { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); return; } /* PrestaShop demo mode*/ if (Tools::isSubmit('submitAddaccess') and $action = Tools::getValue('action') and $id_tab = (int) Tools::getValue('id_tab') and $id_profile = (int) Tools::getValue('id_profile') and $this->tabAccess['edit'] == 1) { if ($id_tab == -1 and $action == 'all' and (int) Tools::getValue('perm') == 0) { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'access` SET `view` = ' . (int) Tools::getValue('perm') . ', `add` = ' . (int) Tools::getValue('perm') . ', `edit` = ' . (int) Tools::getValue('perm') . ', `delete` = ' . (int) Tools::getValue('perm') . ' WHERE `id_profile` = ' . (int) $id_profile . ' AND `id_tab` != 31'); } elseif ($id_tab == -1 and $action == 'all') { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'access` SET `view` = ' . (int) Tools::getValue('perm') . ', `add` = ' . (int) Tools::getValue('perm') . ', `edit` = ' . (int) Tools::getValue('perm') . ', `delete` = ' . (int) Tools::getValue('perm') . ' WHERE `id_profile` = ' . (int) $id_profile); } elseif ($id_tab == -1) { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'access` SET `' . bqSQL($action) . '` = ' . (int) Tools::getValue('perm') . ' WHERE `id_profile` = ' . (int) $id_profile); } elseif ($action == 'all') { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'access` SET `view` = ' . (int) Tools::getValue('perm') . ', `add` = ' . (int) Tools::getValue('perm') . ', `edit` = ' . (int) Tools::getValue('perm') . ', `delete` = ' . (int) Tools::getValue('perm') . ' WHERE `id_tab` = ' . (int) $id_tab . ' AND `id_profile` = ' . (int) $id_profile); } else { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'access` SET `' . bqSQL($action) . '` = ' . (int) Tools::getValue('perm') . ' WHERE `id_tab` = ' . (int) $id_tab . ' AND `id_profile` = ' . (int) $id_profile); } } }
/** * @see DbCore::set_db() */ public function set_db($db_name) { return $this->link->query('USE `' . bqSQL($db_name) . '`'); }
public function getLastElementsForNotify($element) { $element = bqSQL($element); $max = Db::getInstance()->getValue(' SELECT MAX(`id_' . $element . '`) as `id_' . $element . '` FROM `' . _DB_PREFIX_ . $element . ($element == 'order' ? 's' : '') . '`'); // if no rows in table, set max to 0 if ((int) $max < 1) { $max = 0; } return (int) $max; }
/** * Execute a DELETE query * * @param string $table Name of the table to delete * @param string $where WHERE clause on query * @param int $limit Number max of rows to delete * @param bool $use_cache Use cache or not * @return bool */ public function delete($table, $where = '', $limit = 0, $use_cache = true) { $this->result = false; $sql = 'DELETE FROM `' . bqSQL($table) . '`' . ($where ? ' WHERE ' . $where : '') . ($limit ? ' LIMIT ' . (int) $limit : ''); $res = $this->query($sql); if ($use_cache && $this->is_cache_enabled) { Cache::getInstance()->deleteQuery($sql); } return (bool) $res; }
/** * Return the list of shop by id * * @param int $id * @param string $identifier * @param string $table * @return array */ public static function getShopById($id, $identifier, $table) { return Db::getInstance()->executeS(' SELECT `id_shop`, `' . bqSQL($identifier) . '` FROM `' . _DB_PREFIX_ . bqSQL($table) . '_shop` WHERE `' . bqSQL($identifier) . '` = ' . (int) $id); }
/** * This tricky method generates a SQL clause to check if ranged data are overloaded by multishop * * @since 1.5.0 * * @param string $range_table Range table * * @return string SQL quoer to get the delivery range table in this Shop(Group) */ public static function sqlDeliveryRangeShop($range_table, $alias = 'd') { if (Shop::getContext() == Shop::CONTEXT_ALL) { $where = 'AND d2.id_shop IS NULL AND d2.id_shop_group IS NULL'; } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) { $where = 'AND ((d2.id_shop_group IS NULL OR d2.id_shop_group = ' . Shop::getContextShopGroupID() . ') AND d2.id_shop IS NULL)'; } else { $where = 'AND (d2.id_shop = ' . Shop::getContextShopID() . ' OR (d2.id_shop_group = ' . Shop::getContextShopGroupID() . ' AND d2.id_shop IS NULL) OR (d2.id_shop_group IS NULL AND d2.id_shop IS NULL))'; } $sql = 'AND ' . $alias . '.id_delivery = ( SELECT d2.id_delivery FROM ' . _DB_PREFIX_ . 'delivery d2 WHERE d2.id_carrier = `' . bqSQL($alias) . '`.id_carrier AND d2.id_zone = `' . bqSQL($alias) . '`.id_zone AND d2.`id_' . bqSQL($range_table) . '` = `' . bqSQL($alias) . '`.`id_' . bqSQL($range_table) . '` ' . $where . ' ORDER BY d2.id_shop DESC, d2.id_shop_group DESC LIMIT 1 )'; return $sql; }
public function truncateTable($table) { switch ($table) { case 'customer': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'customer'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'customer_group'); break; case 'address': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'address'); break; case 'country': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'state'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'country'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'country_lang'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'country'); case 'group': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'customer_group'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'group_lang'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'group'); break; case 'combination': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_attribute'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_attribute_shop'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_attribute_combination'); break; case 'category': Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'category` WHERE id_category != 1'); Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'category_lang` WHERE id_category != 1'); Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'category` AUTO_INCREMENT = 2 '); foreach (scandir(_PS_CAT_IMG_DIR_) as $d) { if (preg_match('/^[0-9]+(\\-(.*))?\\.jpg$/', $d)) { unlink(_PS_CAT_IMG_DIR_ . $d); } } Image::clearTmpDir(); break; case 'product': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_shop'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'feature_product'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_lang'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'category_product'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_tag'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'image'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'image_lang'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_attribute'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_attribute_shop'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'product_attribute_combination'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'specific_price'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'specific_price_priority'); Image::deleteAllImages(_PS_PROD_IMG_DIR_); Image::clearTmpDir(); @mkdir(_PS_PROD_IMG_DIR_); break; case 'manufacturer': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'manufacturer'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'manufacturer_lang'); foreach (scandir(_PS_MANU_IMG_DIR_) as $d) { if (preg_match('/^[0-9]+(\\-(.*))?\\.jpg$/', $d)) { unlink(_PS_MANU_IMG_DIR_ . $d); } } Image::clearTmpDir(); break; case 'Suppliers': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'supplier'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'supplier_lang'); foreach (scandir(_PS_SUPP_IMG_DIR_) as $d) { if (preg_match('/^[0-9]+(\\-(.*))?\\.jpg$/', $d)) { unlink(_PS_SUPP_IMG_DIR_ . $d); } } Image::clearTmpDir(); break; case 'attribute': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'attribute'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'attribute_lang'); break; case 'attributegroup': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'attribute_group'); Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'attribute_group_lang'); break; case 'currency': case 'customer': case 'zone': case 'state': Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . bqSQL($table) . '`'); break; } return true; }
public function getList($order_by, $order_way, $filter, $start, $pagination) { $order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC'; $id_shop = (int) Context::getContext()->shop->id; $id_lang = (int) Context::getContext()->language->id; if (version_compare(_PS_VERSION_, '1.5', '<')) { $countries = DB::getInstance()->executeS(' SELECT c.`id_country` AS `id_country`, cl.`name` AS `name`, c.`iso_code` AS `iso_code`, IF(dpdc.`enabled` IS NULL, 1, dpdc.`enabled`) AS `enabled` FROM `' . _DB_PREFIX_ . 'country` c LEFT JOIN `' . _DB_PREFIX_ . _DPDPOLAND_COUNTRY_DB_ . '` dpdc ON (dpdc.`id_country` = c.`id_country` AND dpdc.`id_shop` = "' . (int) $id_shop . '") LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (cl.`id_country` = c.`id_country` AND cl.`id_lang` = "' . (int) $id_lang . '")' . $filter . ($order_by && $order_way ? ' ORDER BY `' . bqSQL($order_by) . '` ' . pSQL($order_way) : '') . ($start !== null && $pagination !== null ? ' LIMIT ' . (int) $start . ', ' . (int) $pagination : '')); } else { $countries = DB::getInstance()->executeS(' SELECT c.`id_country` AS `id_country`, cl.`name` AS `name`, c.`iso_code` AS `iso_code`, IF(dpdc.`enabled` IS NULL, 1, dpdc.`enabled`) AS `enabled` FROM `' . _DB_PREFIX_ . 'country` c LEFT JOIN `' . _DB_PREFIX_ . _DPDPOLAND_COUNTRY_DB_ . '` dpdc ON (dpdc.`id_country` = c.`id_country` AND dpdc.`id_shop` = "' . (int) $id_shop . '") LEFT JOIN `' . _DB_PREFIX_ . 'country_shop` cs ON (cs.`id_country` = c.`id_country`) LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (cl.`id_country` = c.`id_country` AND cl.`id_lang` = "' . (int) $id_lang . '") WHERE cs.`id_shop` = "' . (int) $id_shop . '" ' . $filter . ($order_by && $order_way ? ' ORDER BY `' . bqSQL($order_by) . '` ' . pSQL($order_way) : '') . ($start !== null && $pagination !== null ? ' LIMIT ' . (int) $start . ', ' . (int) $pagination : '')); } if (!$countries) { $countries = array(); } return $countries; }