/**
  * Check then return multilingual fields for database interaction
  *
  * @return array Multilingual fields
  */
 public function getTranslationsFieldsChild()
 {
     parent::validateFieldsLang();
     $fieldsArray = array('title', 'url');
     $fields = array();
     $languages = Language::getLanguages(false);
     $defaultLanguage = (int) Configuration::get('PS_LANG_DEFAULT');
     foreach ($languages as $language) {
         $fields[$language['id_lang']]['id_lang'] = (int) $language['id_lang'];
         $fields[$language['id_lang']][self::$definition['primary']] = (int) $this->id;
         foreach ($fieldsArray as $field) {
             if (!Validate::isTableOrIdentifier($field)) {
                 die(Tools::displayError());
             }
             if (isset($this->{$field}[$language['id_lang']]) and !empty($this->{$field}[$language['id_lang']])) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']], true);
             } elseif (in_array($field, $this->fieldsRequiredLang)) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage], true);
             } else {
                 $fields[$language['id_lang']][$field] = '';
             }
         }
     }
     return $fields;
 }
 /**
  * Check then return multilingual fields for database interaction
  *
  * @return array Multilingual fields
  */
 public function getTranslationsFieldsChild()
 {
     parent::validateFieldsLang();
     $fieldsArray = array('name', 'link');
     $fields = array();
     $languages = Language::getLanguages(false);
     $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     foreach ($languages as $language) {
         $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
         $fields[$language['id_lang']][$this->identifier] = intval($this->id);
         foreach ($fieldsArray as $field) {
             if (!Validate::isTableOrIdentifier($field)) {
                 die(Tools::displayError());
             }
             /* Check fields validity */
             if (isset($this->{$field}[$language['id_lang']]) and !empty($this->{$field}[$language['id_lang']])) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
             } elseif (in_array($field, $this->fieldsRequiredLang)) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
             } else {
                 $fields[$language['id_lang']][$field] = '';
             }
         }
     }
     return $fields;
 }
Beispiel #3
0
 public function getTranslationsFieldsChild()
 {
     parent::validateFieldsLang();
     $fieldsArray = array('meta_title', 'meta_description', 'meta_keywords', 'link_rewrite');
     $fields = array();
     $languages = Language::getLanguages(false);
     $defaultLanguage = (int) Configuration::get('PS_LANG_DEFAULT');
     foreach ($languages as $language) {
         $fields[$language['id_lang']]['id_lang'] = (int) $language['id_lang'];
         $fields[$language['id_lang']][$this->identifier] = (int) $this->id;
         $fields[$language['id_lang']]['content'] = isset($this->content[$language['id_lang']]) ? pSQL($this->content[$language['id_lang']], true) : '';
         foreach ($fieldsArray as $field) {
             if (!Validate::isTableOrIdentifier($field)) {
                 die(Tools::displayError());
             }
             if (isset($this->{$field}[$language['id_lang']]) and !empty($this->{$field}[$language['id_lang']])) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
             } elseif (in_array($field, $this->fieldsRequiredLang)) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
             } else {
                 $fields[$language['id_lang']][$field] = '';
             }
         }
     }
     return $fields;
 }
    public function toggleStatus()
    {
        if (!Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
            die(Tools::displayError());
        }
        /* Change status to active/inactive */
        return Db::getInstance()->Execute('
		UPDATE `' . pSQL(_DB_PREFIX_ . $this->table) . '`
		SET `comment_status` = !`comment_status`
		WHERE `' . pSQL($this->identifier) . '` = ' . (int) $this->id);
    }
    public function __construct()
    {
        global $cookie;
        $this->table = 'message';
        $this->className = 'Message';
        $this->view = 'noActionColumn';
        $this->delete = true;
        $this->colorOnBackground = true;
        $start = 0;
        $this->_defaultOrderBy = 'date_add';
        /* Manage default params values */
        if (empty($limit)) {
            $limit = !isset($cookie->{$this->table . '_pagination'}) ? $this->_pagination[0] : ($limit = $cookie->{$this->table . '_pagination'});
        }
        if (!Validate::isTableOrIdentifier($this->table)) {
            die(Tools::displayError('Table name is invalid:') . ' "' . $this->table . '"');
        }
        if (empty($orderBy)) {
            $orderBy = Tools::getValue($this->table . 'Orderby', $this->_defaultOrderBy);
        } elseif ($orderBy == 'id_order') {
            $orderBy = 'm.id_order';
        }
        if (empty($orderWay)) {
            $orderWay = Tools::getValue($this->table . 'Orderway', 'ASC');
        }
        $limit = (int) Tools::getValue('pagination', $limit);
        $cookie->{$this->table . '_pagination'} = $limit;
        /* Check params validity */
        if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay) or !is_numeric($start) or !is_numeric($limit)) {
            die(Tools::displayError('get list params is not valid'));
        }
        if ($orderBy == 'id_order') {
            $orderBy = 'm.id_order';
        }
        /* Determine offset from current page */
        if ((isset($_POST['submitFilter' . $this->table]) or isset($_POST['submitFilter' . $this->table . '_x']) or isset($_POST['submitFilter' . $this->table . '_y'])) and !empty($_POST['submitFilter' . $this->table]) and is_numeric($_POST['submitFilter' . $this->table])) {
            $start = (int) ($_POST['submitFilter' . $this->table] - 1) * $limit;
        }
        $sql = 'SELECT SQL_CALC_FOUND_ROWS m.id_message, m.id_cart, m.id_employee, IF(m.id_order > 0, m.id_order, \'--\') id_order, m.message, m.private, m.date_add, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS customer,
		c.id_customer, count(m.id_message) nb_messages, (SELECT message FROM ' . _DB_PREFIX_ . 'message WHERE id_order = m.id_order ORDER BY date_add DESC LIMIT 1) last_message,
		(SELECT COUNT(m2.id_message) FROM ' . _DB_PREFIX_ . 'message m2 WHERE 1 AND m2.id_customer != 0 AND m2.id_order = m.id_order AND m2.id_message NOT IN 
		(SELECT mr2.id_message FROM ' . _DB_PREFIX_ . 'message_readed mr2 WHERE mr2.id_employee = ' . (int) $cookie->id_employee . ') GROUP BY m2.id_order) nb_messages_not_read_by_me
		FROM ' . _DB_PREFIX_ . 'message m
		LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.id_order = m.id_order)
		LEFT JOIN ' . _DB_PREFIX_ . 'customer c ON (c.id_customer = m.id_customer)
		GROUP BY m.id_order
		ORDER BY ' . (isset($orderBy) ? pSQL($orderBy) : 'date_add') . ' ' . (isset($orderWay) ? pSQL($orderWay) : 'DESC') . '
		LIMIT ' . (int) $start . ',' . (int) $limit;
        $this->_list = Db::getInstance()->ExecuteS($sql);
        $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `' . md5($sql) . '`');
        $this->fieldsDisplay = array('id_order' => array('title' => $this->l('Order ID'), 'align' => 'center', 'width' => 30), 'id_customer' => array('title' => $this->l('Customer ID'), 'align' => 'center', 'width' => 30), 'customer' => array('title' => $this->l('Customer'), 'width' => 100, 'filter_key' => 'customer', 'tmpTableFilter' => true), 'last_message' => array('title' => $this->l('Last message'), 'width' => 400, 'orderby' => false), 'nb_messages_not_read_by_me' => array('title' => $this->l('Unread message(s)'), 'width' => 30, 'align' => 'center'), 'nb_messages' => array('title' => $this->l('Number of messages'), 'width' => 30, 'align' => 'center'));
        parent::__construct();
    }
Beispiel #6
0
 public function update($nullValues = false)
 {
     $result = 1;
     $fields = $this->getTranslationsFieldsChild();
     foreach ($fields as $field) {
         foreach ($field as $key => $value) {
             if (!Validate::isTableOrIdentifier($key)) {
                 die(Tools::displayError());
             }
         }
         $mode = Db::getInstance()->getRow('SELECT `id_lang` FROM `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` WHERE `' . pSQL($this->identifier) . '` = ' . intval($this->id) . ' AND `id_lang` = ' . intval($field['id_lang']));
         $result *= !Db::getInstance()->NumRows() ? Db::getInstance()->AutoExecute(_DB_PREFIX_ . $this->table . '_lang', $field, 'INSERT') : Db::getInstance()->AutoExecute(_DB_PREFIX_ . $this->table . '_lang', $field, 'UPDATE', '`' . pSQL($this->identifier) . '` = ' . intval($this->id) . ' AND `id_lang` = ' . intval($field['id_lang']));
     }
     return $result;
 }
Beispiel #7
0
 public function deleteSelection($selection)
 {
     if (!is_array($selection) or !Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
         die(Tools::displayError());
     }
     foreach ($selection as $id) {
         $obj = new Currency((int) $id);
         $res[$id] = $obj->delete();
     }
     foreach ($res as $value) {
         if (!$value) {
             return false;
         }
     }
     return true;
 }
 protected function makeTranslationFields(&$fields, &$fieldsArray, $id_language)
 {
     $fields[$id_language]['id_lang'] = $id_language;
     $fields[$id_language][$this->identifier] = (int) $this->id;
     foreach ($fieldsArray as $field) {
         /* Check fields validity */
         if (!Validate::isTableOrIdentifier($field)) {
             die(Tools::displayError());
         }
         /* Copy the field, or the default language field if it's both required and empty */
         if (!$this->id_lang and isset($this->{$field}[$id_language]) and !empty($this->{$field}[$id_language]) or $this->id_lang and isset($this->{$field}) and !empty($this->{$field})) {
             $fields[$id_language][$field] = $this->id_lang ? pSQL($this->{$field}, true) : pSQL($this->{$field}[$id_language], true);
         } elseif (in_array($field, $this->fieldsRequiredLang)) {
             $fields[$id_language][$field] = $this->id_lang ? pSQL($this->{$field}, true) : pSQL($this->{$field}[Configuration::get('PS_LANG_DEFAULT')], true);
         } else {
             $fields[$id_language][$field] = '';
         }
     }
 }
 public function getTranslationsFieldsChild()
 {
     parent::validateFieldsLang();
     $fieldsArray = array('meta_title', 'meta_description', 'title', 'seo_url', 'meta_keywords');
     $fields = array();
     $languages = Language::getLanguages(false);
     $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     foreach ($languages as $language) {
         $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
         $fields[$language['id_lang']][$this->identifier] = intval($this->id);
         $fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']]) and !empty($this->description[$language['id_lang']])) ? pSQL($this->description[$language['id_lang']], true) : pSQL($this->description[$defaultLanguage], true);
         foreach ($fieldsArray as $field) {
             if (!Validate::isTableOrIdentifier($field)) {
                 die(Tools::displayError());
             }
             if (isset($this->{$field}[$language['id_lang']]) and !empty($this->{$field}[$language['id_lang']])) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
             } else {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
             }
         }
     }
     return $fields;
 }
Beispiel #10
0
 /**
  * Delete a state only if is not in use
  *
  * @return boolean
  */
 public function delete()
 {
     if (!Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
         die(Tools::displayError());
     }
     if (!$this->isUsed()) {
         /* Database deletion */
         $result = Db::getInstance()->Execute('DELETE FROM `' . pSQL(_DB_PREFIX_ . $this->table) . '` WHERE `' . pSQL($this->identifier) . '` = ' . (int) $this->id);
         if (!$result) {
             return false;
         }
         /* Database deletion for multilingual fields related to the object */
         if (method_exists($this, 'getTranslationsFieldsChild')) {
             Db::getInstance()->Execute('DELETE FROM `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` WHERE `' . pSQL($this->identifier) . '` = ' . (int) $this->id);
         }
         return $result;
     } else {
         return false;
     }
 }
 public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = null)
 {
     if (!Validate::isTableOrIdentifier($this->table)) {
         die('filter is corrupted');
     }
     if (empty($order_by)) {
         $order_by = Tools::getValue($this->table . 'Orderby', $this->_defaultOrderBy);
     }
     if (empty($order_way)) {
         $order_way = Tools::getValue($this->table . 'Orderway', 'ASC');
     }
     // Try and obtain getList arguments from $_GET
     $order_by = Tools::getValue($this->table . 'Orderby');
     $order_way = Tools::getValue($this->table . 'Orderway');
     // Validate the orderBy and orderWay fields
     switch ($order_by) {
         case 'filename':
         case 'filesize':
         case 'date':
         case 'age':
             break;
         default:
             $order_by = 'date';
     }
     switch ($order_way) {
         case 'asc':
         case 'desc':
             break;
         default:
             $order_way = 'desc';
     }
     if (empty($limit)) {
         $limit = !isset($this->context->cookie->{$this->table . '_pagination'}) ? $this->_pagination[0] : ($limit = $this->context->cookie->{$this->table . '_pagination'});
     }
     $limit = (int) Tools::getValue('pagination', $limit);
     $this->context->cookie->{$this->table . '_pagination'} = $limit;
     /* Determine offset from current page */
     if (!empty($_POST['submitFilter' . $this->list_id]) && is_numeric($_POST['submitFilter' . $this->list_id])) {
         $start = (int) $_POST['submitFilter' . $this->list_id] - 1 * $limit;
     }
     $this->_lang = (int) $id_lang;
     $this->_orderBy = $order_by;
     $this->_orderWay = strtoupper($order_way);
     $this->_list = array();
     // Find all the backups
     $dh = @opendir(PrestaShopBackup::getBackupPath());
     if ($dh === false) {
         $this->errors[] = $this->trans('Unable to open your backup directory', array(), 'Admin.AdvParameters.Notification');
         return;
     }
     while (($file = readdir($dh)) !== false) {
         if (preg_match('/^([_a-zA-Z0-9\\-]*[\\d]+-[a-z\\d]+)\\.sql(\\.gz|\\.bz2)?$/', $file, $matches) == 0) {
             continue;
         }
         $timestamp = (int) $matches[1];
         $date = date('Y-m-d H:i:s', $timestamp);
         $age = time() - $timestamp;
         if ($age < 3600) {
             $age = '< 1 ' . $this->trans('Hour', array(), 'Admin.Global');
         } elseif ($age < 86400) {
             $age = floor($age / 3600);
             $age = $age . ' ' . ($age == 1 ? $this->trans('Hour', array(), 'Admin.Global') : $this->trans('Hours', array(), 'Admin.Global'));
         } else {
             $age = floor($age / 86400);
             $age = $age . ' ' . ($age == 1 ? $this->trans('Day', array(), 'Admin.Global') : $this->trans('Days', array(), 'Admin.Global'));
         }
         $size = filesize(PrestaShopBackup::getBackupPath($file));
         $this->_list[] = array('filename' => $file, 'age' => $age, 'date' => $date, 'filesize' => number_format($size / 1000, 2) . ' Kb', 'timestamp' => $timestamp, 'filesize_sort' => $size);
     }
     closedir($dh);
     $this->_listTotal = count($this->_list);
     // Sort the _list based on the order requirements
     switch ($this->_orderBy) {
         case 'filename':
             $this->sort_by = 'filename';
             $sorter = 'strSort';
             break;
         case 'filesize':
             $this->sort_by = 'filesize_sort';
             $sorter = 'intSort';
             break;
         case 'age':
         case 'date':
             $this->sort_by = 'timestamp';
             $sorter = 'intSort';
             break;
     }
     usort($this->_list, array($this, $sorter));
     $this->_list = array_slice($this->_list, $start, $limit);
 }
Beispiel #12
0
 /**
  * Prepare multilingual fields for database insertion
  *
  * @param array $fieldsArray Multilingual fields to prepare
  * return array Prepared fields for database insertion
  */
 protected function getTranslationsFields($fieldsArray)
 {
     /* WARNING : Product do not use this function, so do not forget to report any modification if necessary */
     if (!Validate::isTableOrIdentifier($this->identifier)) {
         die(Tools::displayError());
     }
     $fields = array();
     $languages = Language::getLanguages();
     $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     foreach ($languages as $language) {
         $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
         $fields[$language['id_lang']][$this->identifier] = intval($this->id);
         foreach ($fieldsArray as $field) {
             /* Check fields validity */
             if (!Validate::isTableOrIdentifier($field)) {
                 die(Tools::displayError());
             }
             $htmlOK = $this->fieldsValidateLang[$field] == 'isCleanHtml';
             /* Copy the field, or the default language field if it's both required and empty */
             if (isset($this->{$field}[$language['id_lang']]) and !Tools::isEmpty($this->{$field}[$language['id_lang']])) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']], $htmlOK);
             } elseif (in_array($field, $this->fieldsRequiredLang)) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage], $htmlOK);
             } else {
                 $fields[$language['id_lang']][$field] = '';
             }
         }
     }
     return $fields;
 }
Beispiel #13
0
 public function getTranslationsFieldsChild()
 {
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         if (count($this->tables) == 1) {
             return;
         }
         parent::validateFieldsLang();
         $fields_array = array();
         $fields = array();
         $definition = $this->getDefinitionProperty();
         if (isset($definition)) {
             foreach ($definition['fields'] as $field_name => $field) {
                 if (is_array($this->{$field_name})) {
                     $fields_array[] = $field_name;
                 }
             }
         }
         foreach (Language::getLanguages(false) as $language) {
             $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
             $fields[$language['id_lang']][$this->identifier] = (int) $this->{$this->identifier};
             foreach ($fields_array as $field) {
                 if (!Validate::isTableOrIdentifier($field)) {
                     die(Tools::displayError());
                 }
                 if (isset($this->{$field}[$language['id_lang']]) && !empty($this->{$field}[$language['id_lang']])) {
                     $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
                 } elseif (in_array($field, $this->fieldsRequiredLang)) {
                     if ($this->{$field} != '') {
                         $fields[$language['id_lang']][$field] = pSQL($this->{$field}[(int) _PS_LANG_DEFAULT_]);
                     }
                 } else {
                     $fields[$language['id_lang']][$field] = '';
                 }
             }
         }
         return $fields;
     } else {
         $this->validateFieldsLang();
         $is_lang_multishop = $this->isLangMultishop();
         $fields = array();
         if ($this->id_lang === null) {
             foreach (Language::getLanguages(false) as $language) {
                 $fields[$language['id_lang']] = $this->formatFields(self::FORMAT_LANG, $language['id_lang']);
                 $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
                 if ($this->id_shop && $is_lang_multishop) {
                     $fields[$language['id_lang']]['id_shop'] = (int) $this->id_shop;
                 }
             }
         } else {
             $fields = array($this->id_lang => $this->formatFields(self::FORMAT_LANG, $this->id_lang));
             $fields[$this->id_lang]['id_lang'] = $this->id_lang;
             if ($this->id_shop && $is_lang_multishop) {
                 $fields[$this->id_lang]['id_shop'] = (int) $this->id_shop;
             }
         }
         return $fields;
     }
 }
Beispiel #14
0
 /**
  * Toggle object status in database
  *
  * return boolean Update result
  */
 public function toggle($key = 'active')
 {
     if (!Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
         die('Fatal error:Object not exist!');
         /* Object must have a variable called 'active' */
     } elseif (!array_key_exists($key, $this->fields)) {
         die('Fatal error:No field \'' . $key . '\'');
     }
     /* Update active status on object */
     $this->{$key} = $this->{$key} > 0 ? 0 : 1;
     /* Change status to active/inactive */
     return $this->update();
 }
Beispiel #15
0
    /**
     * Get the current objects' list form the database
     *
     * @param integer $id_lang Language used for display
     * @param string $order_by ORDER BY clause
     * @param string $_orderWay Order way (ASC, DESC)
     * @param integer $start Offset in LIMIT clause
     * @param integer $limit Row count in LIMIT clause
     */
    public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
    {
        /* Manage default params values */
        $use_limit = true;
        if ($limit === false) {
            $use_limit = false;
        } elseif (empty($limit)) {
            if (isset($this->context->cookie->{$this->table . '_pagination'}) && $this->context->cookie->{$this->table . '_pagination'}) {
                $limit = $this->context->cookie->{$this->table . '_pagination'};
            } else {
                $limit = $this->_pagination[1];
            }
        }
        if (!Validate::isTableOrIdentifier($this->table)) {
            throw new PrestaShopException(sprintf('Table name %s is invalid:', $this->table));
        }
        if (empty($order_by)) {
            if ($this->context->cookie->{$this->table . 'Orderby'}) {
                $order_by = $this->context->cookie->{$this->table . 'Orderby'};
            } elseif ($this->_orderBy) {
                $order_by = $this->_orderBy;
            } else {
                $order_by = $this->_defaultOrderBy;
            }
        }
        if (empty($order_way)) {
            if ($this->context->cookie->{$this->table . 'Orderway'}) {
                $order_way = $this->context->cookie->{$this->table . 'Orderway'};
            } elseif ($this->_orderWay) {
                $order_way = $this->_orderWay;
            } else {
                $order_way = $this->_defaultOrderWay;
            }
        }
        $limit = (int) Tools::getValue('pagination', $limit);
        $this->context->cookie->{$this->table . '_pagination'} = $limit;
        /* Check params validity */
        if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way) || !is_numeric($start) || !is_numeric($limit) || !Validate::isUnsignedId($id_lang)) {
            throw new PrestaShopException('get list params is not valid');
        }
        /* Determine offset from current page */
        if ((isset($_POST['submitFilter' . $this->table]) || isset($_POST['submitFilter' . $this->table . '_x']) || isset($_POST['submitFilter' . $this->table . '_y'])) && !empty($_POST['submitFilter' . $this->table]) && is_numeric($_POST['submitFilter' . $this->table])) {
            $start = ((int) $_POST['submitFilter' . $this->table] - 1) * $limit;
        }
        /* Cache */
        $this->_lang = (int) $id_lang;
        $this->_orderBy = strpos($order_by, '.') !== false ? substr($order_by, strpos($order_by, '.') + 1) : $order_by;
        $this->_orderWay = Tools::strtoupper($order_way);
        /* SQL table : orders, but class name is Order */
        $sql_table = $this->table == 'order' ? 'orders' : $this->table;
        // Add SQL shop restriction
        $select_shop = $join_shop = $where_shop = '';
        if ($this->shopLinkType) {
            $select_shop = ', shop.name as shop_name ';
            $join_shop = ' LEFT JOIN ' . _DB_PREFIX_ . $this->shopLinkType . ' shop
							ON a.id_' . $this->shopLinkType . ' = shop.id_' . $this->shopLinkType;
            $where_shop = Shop::addSqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
        }
        if ($this->multishop_context && Shop::isTableAssociated($this->table) && !empty($this->className)) {
            if (Shop::getContext() != Shop::CONTEXT_ALL || !$this->context->employee->isSuperAdmin()) {
                $test_join = !preg_match('#`?' . preg_quote(_DB_PREFIX_ . $this->table . '_shop') . '`? *sa#', $this->_join);
                if (Shop::isFeatureActive() && $test_join && Shop::isTableAssociated($this->table)) {
                    $this->_where .= ' AND a.' . $this->identifier . ' IN (
						SELECT sa.' . $this->identifier . '
						FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa
						WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
					)';
                }
            }
        }
        /* Query in order to get results with all fields */
        $lang_join = '';
        if ($this->lang) {
            $lang_join = 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`' . $this->identifier . '` = a.`' . $this->identifier . '` AND b.`id_lang` = ' . (int) $id_lang;
            if ($id_lang_shop) {
                if (!Shop::isFeatureActive()) {
                    $lang_join .= ' AND b.`id_shop` = 1';
                } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) {
                    $lang_join .= ' AND b.`id_shop` = ' . (int) $id_lang_shop;
                } else {
                    $lang_join .= ' AND b.`id_shop` = a.id_shop_default';
                }
            }
            $lang_join .= ')';
        }
        $having_clause = '';
        if (isset($this->_filterHaving) || isset($this->_having)) {
            $having_clause = ' HAVING ';
            if (isset($this->_filterHaving)) {
                $having_clause .= ltrim($this->_filterHaving, ' AND ');
            }
            if (isset($this->_having)) {
                $having_clause .= $this->_having . ' ';
            }
        }
        if (strpos($order_by, '.') > 0) {
            $order_by = explode('.', $order_by);
            $order_by = pSQL($order_by[0]) . '.`' . pSQL($order_by[1]) . '`';
        }
        $this->_listsql = '
		SELECT SQL_CALC_FOUND_ROWS
		' . ($this->_tmpTableFilter ? ' * FROM (SELECT ' : '') . '
		' . ($this->lang ? 'b.*, ' : '') . 'a.*' . (isset($this->_select) ? ', ' . $this->_select . ' ' : '') . $select_shop . '
		FROM `' . _DB_PREFIX_ . $sql_table . '` a
		' . $lang_join . '
		' . (isset($this->_join) ? $this->_join . ' ' : '') . '
		' . $join_shop . '
		WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . ($this->deleted ? 'AND a.`deleted` = 0 ' : '') . (isset($this->_filter) ? $this->_filter : '') . $where_shop . '
		' . (isset($this->_group) ? $this->_group . ' ' : '') . '
		' . $having_clause . '
		ORDER BY ' . ($order_by == $this->identifier ? 'a.' : '') . pSQL($order_by) . ' ' . pSQL($order_way) . ($this->_tmpTableFilter ? ') tmpTable WHERE 1' . $this->_tmpTableFilter : '') . ($use_limit === true ? ' LIMIT ' . (int) $start . ',' . (int) $limit : '');
        $this->_list = Db::getInstance()->executeS($this->_listsql);
        $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `' . _DB_PREFIX_ . $this->table . '`');
    }
Beispiel #16
0
 /**
  * Check then return multilingual fields for database interaction
  *
  * @return array Multilingual fields
  */
 public function getTranslationsFieldsChild()
 {
     self::validateFieldsLang();
     $fieldsArray = array('meta_description', 'meta_keywords', 'meta_title', 'link_rewrite', 'name', 'available_now', 'available_later');
     $fields = array();
     $languages = Language::getLanguages();
     $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     foreach ($languages as $language) {
         $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
         $fields[$language['id_lang']][$this->identifier] = intval($this->id);
         $fields[$language['id_lang']]['description'] = isset($this->description[$language['id_lang']]) ? pSQL($this->description[$language['id_lang']], true) : '';
         $fields[$language['id_lang']]['description_short'] = isset($this->description_short[$language['id_lang']]) ? pSQL($this->description_short[$language['id_lang']], true) : '';
         foreach ($fieldsArray as $field) {
             if (!Validate::isTableOrIdentifier($field)) {
                 die(Tools::displayError());
             }
             /* Check fields validity */
             if (isset($this->{$field}[$language['id_lang']]) and !empty($this->{$field}[$language['id_lang']])) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
             } elseif (in_array($field, $this->fieldsRequiredLang)) {
                 $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
             } else {
                 $fields[$language['id_lang']][$field] = '';
             }
         }
     }
     return $fields;
 }
 public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL)
 {
     global $cookie;
     if (!Validate::isTableOrIdentifier($this->table)) {
         die('filter is corrupted');
     }
     if (empty($orderBy)) {
         $orderBy = Tools::getValue($this->table . 'Orderby', $this->_defaultOrderBy);
     }
     if (empty($orderWay)) {
         $orderWay = Tools::getValue($this->table . 'Orderway', 'ASC');
     }
     // Try and obtain getList arguments from $_GET
     $orderBy = Tools::getValue($this->table . 'Orderby');
     $orderWay = Tools::getValue($this->table . 'Orderway');
     // Validate the orderBy and orderWay fields
     switch ($orderBy) {
         case 'filename':
         case 'filesize':
         case 'date':
         case 'age':
             break;
         default:
             $orderBy = 'date';
     }
     switch ($orderWay) {
         case 'asc':
         case 'desc':
             break;
         default:
             $orderWay = 'desc';
     }
     if (empty($limit)) {
         $limit = !isset($cookie->{$this->table . '_pagination'}) ? $this->_pagination[0] : ($limit = $cookie->{$this->table . '_pagination'});
     }
     $limit = intval(Tools::getValue('pagination', $limit));
     $cookie->{$this->table . '_pagination'} = $limit;
     /* Determine offset from current page */
     if (!empty($_POST['submitFilter' . $this->table]) and is_numeric($_POST['submitFilter' . $this->table])) {
         $start = intval($_POST['submitFilter' . $this->table] - 1) * $limit;
     }
     $this->_lang = intval($id_lang);
     $this->_orderBy = $orderBy;
     $this->_orderWay = strtoupper($orderWay);
     $this->_list = array();
     // Find all the backups
     $dh = @opendir(PS_ADMIN_DIR . '/backups/');
     if ($dh === false) {
         $this->_errors[] = Tools::displayError('Unable to open backup directory "') . addslashes(PS_ADMIN_DIR . '/backups/') . '"';
         return;
     }
     while (($file = readdir($dh)) !== false) {
         if (preg_match('/^([\\d]+-[a-z\\d]+)\\.sql(\\.gz|\\.bz2)?$/', $file, $matches) == 0) {
             continue;
         }
         $timestamp = intval($matches[1]);
         $date = date('Y-m-d h:i:s', $timestamp);
         $age = time() - $timestamp;
         if ($age < 3600) {
             $age = '< 1 ' . $this->l('hour');
         } else {
             if ($age < 86400) {
                 $age = floor($age / 3600);
                 $age = $age . ' ' . ($age == 1 ? $this->l('hour') : $this->l('hours'));
             } else {
                 $age = floor($age / 86400);
                 $age = $age . ' ' . ($age == 1 ? $this->l('day') : $this->l('days'));
             }
         }
         $size = filesize(PS_ADMIN_DIR . '/backups/' . $file);
         $this->_list[] = array('filename' => $file, 'age' => $age, 'date' => $date, 'filesize' => number_format($size / 1000, 2) . ' Kb', 'timestamp' => $timestamp, 'filesize_sort' => $size);
     }
     closedir($dh);
     $this->_listTotal = count($this->_list);
     // Sort the _list based on the order requirements
     switch ($this->_orderBy) {
         case 'filename':
             $this->_sortBy = 'filename';
             $sorter = 'str_sort';
             break;
         case 'filesize':
             $this->_sortBy = 'filesize_sort';
             $sorter = 'int_sort';
             break;
         case 'age':
         case 'date':
             $this->_sortBy = 'timestamp';
             $sorter = 'int_sort';
             break;
     }
     usort($this->_list, array($this, $sorter));
     $this->_list = array_slice($this->_list, $start, $limit);
 }
Beispiel #18
0
    /**
     * Get the current objects' list form the database
     *
     * @param integer $id_lang Language used for display
     * @param string $order_by ORDER BY clause
     * @param string $_orderWay Order way (ASC, DESC)
     * @param integer $start Offset in LIMIT clause
     * @param integer $limit Row count in LIMIT clause
     */
    public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
    {
        Hook::exec('action' . $this->controller_name . 'ListingFieldsModifier', array('select' => &$this->_select, 'join' => &$this->_join, 'where' => &$this->_where, 'group_by' => &$this->_groupBy, 'order_by' => &$this->_orderBy, 'order_way' => &$this->_orderWay, 'fields' => &$this->fields_list));
        if (!isset($this->list_id)) {
            $this->list_id = $this->table;
        }
        /* Manage default params values */
        $use_limit = true;
        if ($limit === false) {
            $use_limit = false;
        } elseif (empty($limit)) {
            if (isset($this->context->cookie->{$this->list_id . '_pagination'}) && $this->context->cookie->{$this->list_id . '_pagination'}) {
                $limit = $this->context->cookie->{$this->list_id . '_pagination'};
            } else {
                $limit = $this->_default_pagination;
            }
        }
        if (!Validate::isTableOrIdentifier($this->table)) {
            throw new PrestaShopException(sprintf('Table name %s is invalid:', $this->table));
        }
        $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
        if (empty($order_by)) {
            if ($this->context->cookie->{$prefix . $this->list_id . 'Orderby'}) {
                $order_by = $this->context->cookie->{$prefix . $this->list_id . 'Orderby'};
            } elseif ($this->_orderBy) {
                $order_by = $this->_orderBy;
            } else {
                $order_by = $this->_defaultOrderBy;
            }
        }
        if (empty($order_way)) {
            if ($this->context->cookie->{$prefix . $this->list_id . 'Orderway'}) {
                $order_way = $this->context->cookie->{$prefix . $this->list_id . 'Orderway'};
            } elseif ($this->_orderWay) {
                $order_way = $this->_orderWay;
            } else {
                $order_way = $this->_defaultOrderWay;
            }
        }
        $limit = (int) Tools::getValue($this->list_id . '_pagination', $limit);
        if (in_array($limit, $this->_pagination) && $limit != $this->_default_pagination) {
            $this->context->cookie->{$this->list_id . '_pagination'} = $limit;
        } else {
            unset($this->context->cookie->{$this->list_id . '_pagination'});
        }
        /* Check params validity */
        if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way) || !is_numeric($start) || !is_numeric($limit) || !Validate::isUnsignedId($id_lang)) {
            throw new PrestaShopException('get list params is not valid');
        }
        if (!isset($this->fields_list[$order_by]['order_key']) && isset($this->fields_list[$order_by]['filter_key'])) {
            $this->fields_list[$order_by]['order_key'] = $this->fields_list[$order_by]['filter_key'];
        }
        if (isset($this->fields_list[$order_by]) && isset($this->fields_list[$order_by]['order_key'])) {
            $order_by = $this->fields_list[$order_by]['order_key'];
        }
        /* Determine offset from current page */
        $start = 0;
        if ((int) Tools::getValue('submitFilter' . $this->list_id)) {
            $start = ((int) Tools::getValue('submitFilter' . $this->list_id) - 1) * $limit;
        } elseif (empty($start) && isset($this->context->cookie->{$this->list_id . '_start'}) && Tools::isSubmit('export' . $this->table)) {
            $start = $this->context->cookie->{$this->list_id . '_start'};
        }
        // Either save or reset the offset in the cookie
        if ($start) {
            $this->context->cookie->{$this->list_id . '_start'} = $start;
        } elseif (isset($this->context->cookie->{$this->list_id . '_start'})) {
            unset($this->context->cookie->{$this->list_id . '_start'});
        }
        /* Cache */
        $this->_lang = (int) $id_lang;
        $this->_orderBy = $order_by;
        if (preg_match('/[.!]/', $order_by)) {
            $order_by_split = preg_split('/[.!]/', $order_by);
            $order_by = bqSQL($order_by_split[0]) . '.`' . bqSQL($order_by_split[1]) . '`';
        } elseif ($order_by) {
            $order_by = '`' . bqSQL($order_by) . '`';
        }
        $this->_orderWay = Tools::strtoupper($order_way);
        /* SQL table : orders, but class name is Order */
        $sql_table = $this->table == 'order' ? 'orders' : $this->table;
        // Add SQL shop restriction
        $select_shop = $join_shop = $where_shop = '';
        if ($this->shopLinkType) {
            $select_shop = ', shop.name as shop_name ';
            $join_shop = ' LEFT JOIN ' . _DB_PREFIX_ . $this->shopLinkType . ' shop
							ON a.id_' . $this->shopLinkType . ' = shop.id_' . $this->shopLinkType;
            $where_shop = Shop::addSqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
        }
        if ($this->multishop_context && Shop::isTableAssociated($this->table) && !empty($this->className)) {
            if (Shop::getContext() != Shop::CONTEXT_ALL || !$this->context->employee->isSuperAdmin()) {
                $test_join = !preg_match('#`?' . preg_quote(_DB_PREFIX_ . $this->table . '_shop') . '`? *sa#', $this->_join);
                if (Shop::isFeatureActive() && $test_join && Shop::isTableAssociated($this->table)) {
                    $this->_where .= ' AND a.' . $this->identifier . ' IN (
						SELECT sa.' . $this->identifier . '
						FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa
						WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
					)';
                }
            }
        }
        /* Query in order to get results with all fields */
        $lang_join = '';
        if ($this->lang) {
            $lang_join = 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`' . $this->identifier . '` = a.`' . $this->identifier . '` AND b.`id_lang` = ' . (int) $id_lang;
            if ($id_lang_shop) {
                if (!Shop::isFeatureActive()) {
                    $lang_join .= ' AND b.`id_shop` = 1';
                } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) {
                    $lang_join .= ' AND b.`id_shop` = ' . (int) $id_lang_shop;
                } else {
                    $lang_join .= ' AND b.`id_shop` = a.id_shop_default';
                }
            }
            $lang_join .= ')';
        }
        $having_clause = '';
        if (isset($this->_filterHaving) || isset($this->_having)) {
            $having_clause = ' HAVING ';
            if (isset($this->_filterHaving)) {
                $having_clause .= ltrim($this->_filterHaving, ' AND ');
            }
            if (isset($this->_having)) {
                $having_clause .= $this->_having . ' ';
            }
        }
        do {
            $this->_listsql = '
			SELECT SQL_CALC_FOUND_ROWS
			' . ($this->_tmpTableFilter ? ' * FROM (SELECT ' : '');
            if ($this->explicitSelect) {
                foreach ($this->fields_list as $key => $array_value) {
                    // Add it only if it is not already in $this->_select
                    if (isset($this->_select) && preg_match('/[\\s]`?' . preg_quote($key, '/') . '`?\\s*,/', $this->_select)) {
                        continue;
                    }
                    if (isset($array_value['filter_key'])) {
                        $this->_listsql .= str_replace('!', '.', $array_value['filter_key']) . ' as ' . $key . ',';
                    } elseif ($key == 'id_' . $this->table) {
                        $this->_listsql .= 'a.`' . bqSQL($key) . '`,';
                    } elseif ($key != 'image' && !preg_match('/' . preg_quote($key, '/') . '/i', $this->_select)) {
                        $this->_listsql .= '`' . bqSQL($key) . '`,';
                    }
                }
                $this->_listsql = rtrim($this->_listsql, ',');
            } else {
                $this->_listsql .= ($this->lang ? 'b.*,' : '') . ' a.*';
            }
            $this->_listsql .= '
			' . (isset($this->_select) ? ', ' . rtrim($this->_select, ', ') : '') . $select_shop . '
			FROM `' . _DB_PREFIX_ . $sql_table . '` a
			' . $lang_join . '
			' . (isset($this->_join) ? $this->_join . ' ' : '') . '
			' . $join_shop . '
			WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . ($this->deleted ? 'AND a.`deleted` = 0 ' : '') . (isset($this->_filter) ? $this->_filter : '') . $where_shop . '
			' . (isset($this->_group) ? $this->_group . ' ' : '') . '
			' . $having_clause . '
			ORDER BY ' . (str_replace('`', '', $order_by) == $this->identifier ? 'a.' : '') . $order_by . ' ' . pSQL($order_way) . ($this->_tmpTableFilter ? ') tmpTable WHERE 1' . $this->_tmpTableFilter : '') . ($use_limit === true ? ' LIMIT ' . (int) $start . ',' . (int) $limit : '');
            $this->_list = Db::getInstance()->executeS($this->_listsql, true, false);
            if ($this->_list === false) {
                $this->_list_error = Db::getInstance()->getMsgError();
                break;
            }
            $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `' . _DB_PREFIX_ . $this->table . '`', false);
            if ($use_limit === true) {
                $start = (int) $start - (int) $limit;
                if ($start < 0) {
                    break;
                }
            } else {
                break;
            }
        } while (empty($this->_list));
        Hook::exec('action' . $this->controller_name . 'ListingResultsModifier', array('list' => &$this->_list, 'list_total' => &$this->_listTotal));
    }
Beispiel #19
0
 /**
  * @deprecated 1.5.0.1
  * @param array $fields
  * @param array $fields_array
  * @param int   $id_language
  *
  * @throws PrestaShopException
  */
 protected function makeTranslationFields(&$fields, &$fields_array, $id_language)
 {
     $fields[$id_language]['id_lang'] = $id_language;
     $fields[$id_language][$this->def['primary']] = (int) $this->id;
     if ($this->id_shop && $this->isLangMultishop()) {
         $fields[$id_language]['id_shop'] = (int) $this->id_shop;
     }
     foreach ($fields_array as $k => $field) {
         $html = false;
         $field_name = $field;
         if (is_array($field)) {
             $field_name = $k;
             $html = isset($field['html']) ? $field['html'] : false;
         }
         /* Check fields validity */
         if (!Validate::isTableOrIdentifier($field_name)) {
             throw new PrestaShopException('identifier is not table or identifier : ' . $field_name);
         }
         // Copy the field, or the default language field if it's both required and empty
         if (!$this->id_lang && isset($this->{$field_name}[$id_language]) && !empty($this->{$field_name}[$id_language]) || $this->id_lang && isset($this->{$field_name}) && !empty($this->{$field_name})) {
             $fields[$id_language][$field_name] = $this->id_lang ? pSQL($this->{$field_name}, $html) : pSQL($this->{$field_name}[$id_language], $html);
         } elseif (in_array($field_name, $this->fieldsRequiredLang)) {
             $fields[$id_language][$field_name] = pSQL($this->id_lang ? $this->{$field_name} : $this->{$field_name}[Configuration::get('PS_LANG_DEFAULT')], $html);
         } else {
             $fields[$id_language][$field_name] = '';
         }
     }
 }
Beispiel #20
0
    public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL)
    {
        parent::getList($id_lang, $orderBy, $orderWay, $start, $limit);
        global $cookie;
        /* Manage default params values */
        if (empty($limit)) {
            $limit = !isset($cookie->{$this->table . '_pagination'}) ? $this->_pagination[0] : ($limit = $cookie->{$this->table . '_pagination'});
        }
        if (!Validate::isTableOrIdentifier($this->table)) {
            die('filter is corrupted');
        }
        if (empty($orderBy)) {
            $orderBy = Tools::getValue($this->table . 'Orderby', 'id_' . $this->table);
        }
        if (empty($orderWay)) {
            $orderWay = Tools::getValue($this->table . 'Orderway', 'ASC');
        }
        $limit = intval(Tools::getValue('pagination', $limit));
        $cookie->{$this->table . '_pagination'} = $limit;
        /* Check params validity */
        if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay) or !is_numeric($start) or !is_numeric($limit) or !Validate::isUnsignedId($id_lang)) {
            die(Tools::displayError('get list params is not valid'));
        }
        /* Determine offset from current page */
        if ((isset($_POST['submitFilter' . $this->table]) or isset($_POST['submitFilter' . $this->table . '_x']) or isset($_POST['submitFilter' . $this->table . '_y'])) and !empty($_POST['submitFilter' . $this->table]) and is_numeric($_POST['submitFilter' . $this->table])) {
            $start = intval($_POST['submitFilter' . $this->table] - 1) * $limit;
        }
        /* Cache */
        $this->_lang = intval($id_lang);
        $this->_orderBy = $orderBy;
        $this->_orderWay = Tools::strtoupper($orderWay);
        /* SQL table : orders, but class name is Order */
        $sqlTable = $this->table == 'order' ? 'orders' : $this->table;
        /* Query in order to get results number */
        $queryTotal = Db::getInstance()->getRow('
		SELECT COUNT(a.`id_' . $this->table . '`) AS total
		FROM `' . _DB_PREFIX_ . $sqlTable . '` a
		' . ($this->lang ? 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`id_' . $this->table . '` = a.`id_' . $this->table . '` AND b.`id_lang` = ' . intval($id_lang) . ')' : '') . ' 
		' . (isset($this->_join) ? $this->_join . ' ' : '') . '
		WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . (($this->deleted or $this->table == 'currency') ? 'AND a.`deleted` = 0 ' : '') . $this->_filter . ' 
		' . (isset($this->_group) ? $this->_group . ' ' : '') . '
		' . (isset($this->addressType) ? 'AND a.id_' . strval($this->addressType) . ' != 0' : ''));
        $this->_listTotal = intval($queryTotal['total']);
        /* Query in order to get results with all fields */
        $this->_list = Db::getInstance()->ExecuteS('
		SELECT a.*' . ($this->lang ? ', b.*' : '') . (isset($this->_select) ? ', ' . $this->_select . ' ' : '') . ' 
		FROM `' . _DB_PREFIX_ . $sqlTable . '` a 
		' . ($this->lang ? 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`id_' . $this->table . '` = a.`id_' . $this->table . '` AND b.`id_lang` = ' . intval($id_lang) . ')' : '') . ' 
		' . (isset($this->_join) ? $this->_join . ' ' : '') . '
		WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . (($this->deleted or $this->table == 'currency') ? 'AND a.`deleted` = 0 ' : '') . $this->_filter . ' 
		' . (isset($this->_group) ? $this->_group . ' ' : '') . '
		' . (isset($this->addressType) ? 'AND a.id_' . strval($this->addressType) . ' != 0' : '') . '
		ORDER BY ' . ($orderBy == 'id_' . $this->table ? 'a.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . ' 
		LIMIT ' . intval($start) . ',' . intval($limit));
    }
Beispiel #21
0
    /**
     * Get the current objects' list form the database
     *
     * @param int $id_lang Language used for display
     * @param string $orderBy ORDER BY clause
     * @param string $_orderWay Order way (ASC, DESC)
     * @param int $start Offset in LIMIT clause
     * @param int $limit Row count in LIMIT clause
     */
    public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = false)
    {
        /* Manage default params values */
        if (empty($limit)) {
            $limit = !isset($this->context->cookie->{$this->table . '_pagination'}) ? $this->_pagination[1] : ($limit = $this->context->cookie->{$this->table . '_pagination'});
        }
        if (!Validate::isTableOrIdentifier($this->table)) {
            $this->_errors[] = Tools::displayError('Table name is invalid:') . ' "' . $this->table . '"';
        }
        if (empty($orderBy)) {
            $orderBy = $this->context->cookie->__get($this->table . 'Orderby') ? $this->context->cookie->__get($this->table . 'Orderby') : $this->_defaultOrderBy;
        }
        if (empty($orderWay)) {
            $orderWay = $this->context->cookie->__get($this->table . 'Orderway') ? $this->context->cookie->__get($this->table . 'Orderway') : 'ASC';
        }
        $limit = (int) Tools::getValue('pagination', $limit);
        $this->context->cookie->{$this->table . '_pagination'} = $limit;
        /* Check params validity */
        if (!Validate::isOrderBy($orderBy) || !Validate::isOrderWay($orderWay) || !is_numeric($start) || !is_numeric($limit) || !Validate::isUnsignedId($id_lang)) {
            die(Tools::displayError('get list params is not valid'));
        }
        /* Determine offset from current page */
        if ((isset($_POST['submitFilter' . $this->table]) || isset($_POST['submitFilter' . $this->table . '_x']) || isset($_POST['submitFilter' . $this->table . '_y'])) && !empty($_POST['submitFilter' . $this->table]) && is_numeric($_POST['submitFilter' . $this->table])) {
            $start = (int) ($_POST['submitFilter' . $this->table] - 1) * $limit;
        }
        /* Cache */
        $this->_lang = (int) $id_lang;
        $this->_orderBy = $orderBy;
        $this->_orderWay = Tools::strtoupper($orderWay);
        /* SQL table : orders, but class name is Order */
        $sqlTable = $this->table == 'order' ? 'orders' : $this->table;
        // Add SQL shop restriction
        $selectShop = $joinShop = $whereShop = '';
        if ($this->shopLinkType) {
            $selectShop = ', shop.name as shop_name ';
            $joinShop = ' LEFT JOIN ' . _DB_PREFIX_ . $this->shopLinkType . ' shop
							ON a.id_' . $this->shopLinkType . ' = shop.id_' . $this->shopLinkType;
            $whereShop = Shop::addSqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
        }
        $asso = Shop::getAssoTable($this->table);
        if ($asso !== false && $asso['type'] == 'shop') {
            $filterKey = $asso['type'];
            $idenfierShop = Shop::getContextListShopID();
        }
        $filterShop = '';
        if (isset($filterKey)) {
            if (!$this->_group) {
                $this->_group = 'GROUP BY a.' . pSQL($this->identifier);
            } elseif (!preg_match('#(\\s|,)\\s*a\\.`?' . pSQL($this->identifier) . '`?(\\s|,|$)#', $this->_group)) {
                $this->_group .= ', a.' . pSQL($this->identifier);
            }
            if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && !preg_match('#`?' . preg_quote(_DB_PREFIX_ . $this->table . '_' . $filterKey) . '`? *sa#', $this->_join)) {
                $filterShop = 'JOIN `' . _DB_PREFIX_ . $this->table . '_' . $filterKey . '` sa ON (sa.' . $this->identifier . ' = a.' . $this->identifier . ' AND sa.id_' . $filterKey . ' IN (' . implode(', ', $idenfierShop) . '))';
            }
        }
        ///////////////////////
        /* Query in order to get results with all fields */
        $sql = 'SELECT SQL_CALC_FOUND_ROWS
			' . ($this->_tmpTableFilter ? ' * FROM (SELECT ' : '') . '
			' . ($this->lang ? 'b.*, ' : '') . 'a.*' . (isset($this->_select) ? ', ' . $this->_select . ' ' : '') . $selectShop . '
			FROM `' . _DB_PREFIX_ . $sqlTable . '` a
			' . $filterShop . '
			' . ($this->lang ? 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`' . $this->identifier . '` = a.`' . $this->identifier . '` AND b.`id_lang` = ' . (int) $id_lang . ($id_lang_shop ? ' AND b.`id_shop`=' . (int) $id_lang_shop : '') . ')' : '') . '
			' . (isset($this->_join) ? $this->_join . ' ' : '') . '
			' . $joinShop . '
			WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . ($this->deleted ? 'AND a.`deleted` = 0 ' : '') . (isset($this->_filter) ? $this->_filter : '') . $whereShop . '
			' . (isset($this->_group) ? $this->_group . ' ' : '') . '
			' . (isset($this->_filterHaving) || isset($this->_having) ? 'HAVING ' : '') . (isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '') . (isset($this->_having) ? $this->_having . ' ' : '') . '
			ORDER BY ' . ($orderBy == $this->identifier ? 'a.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . ($this->_tmpTableFilter ? ') tmpTable WHERE 1' . $this->_tmpTableFilter : '') . '
			LIMIT ' . (int) $start . ',' . (int) $limit;
        $this->_list = Db::getInstance()->executeS($sql);
        $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() as `' . _DB_PREFIX_ . $this->table . '`');
    }
 /**
  * Delete several objects from database
  *
  * return boolean Deletion result
  */
 public function deleteSelection($selection)
 {
     if (!is_array($selection) or !Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
         die(Tools::displayError());
     }
     $result = true;
     foreach ($selection as $id) {
         $this->id = intval($id);
         $this->id_address = self::getManufacturerAddress();
         $result = $result and $this->delete();
     }
     return $result;
 }
Beispiel #23
0
    public function update($nullValues = false)
    {
        $this->clearCache();
        $result = 1;
        $fields = $this->getFieldsLang();
        foreach ($fields as $field) {
            foreach (array_keys($field) as $key) {
                if (!Validate::isTableOrIdentifier($key)) {
                    die(Tools::displayError());
                }
            }
            $sql = 'SELECT `id_lang` FROM `' . pSQL(_DB_PREFIX_ . $this->def['table']) . '_lang`
					WHERE `' . $this->def['primary'] . '` = ' . (int) $this->id . '
						AND `id_lang` = ' . (int) $field['id_lang'];
            $mode = Db::getInstance()->getRow($sql);
            $result &= !$mode ? Db::getInstance()->insert($this->def['table'] . '_lang', $field) : Db::getInstance()->update($this->def['table'] . '_lang', $field, '`' . $this->def['primary'] . '` = ' . (int) $this->id . ' AND `id_lang` = ' . (int) $field['id_lang']);
        }
        Hook::exec('actionFeatureSave', array('id_feature' => $this->id));
        return $result;
    }
Beispiel #24
0
 public function update($nullValues = false)
 {
     $this->clearCache();
     $result = 1;
     $fields = $this->getTranslationsFieldsChild();
     foreach ($fields as $field) {
         foreach (array_keys($field) as $key) {
             if (!Validate::isTableOrIdentifier($key)) {
                 die(Tools::displayError());
             }
         }
         $mode = Db::getInstance()->getRow('SELECT `id_lang` FROM `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` WHERE `' . pSQL($this->identifier) . '` = ' . (int) $this->id . ' AND `id_lang` = ' . (int) $field['id_lang']);
         $result *= !Db::getInstance()->NumRows() ? Db::getInstance()->AutoExecute(_DB_PREFIX_ . $this->table . '_lang', $field, 'INSERT') : Db::getInstance()->AutoExecute(_DB_PREFIX_ . $this->table . '_lang', $field, 'UPDATE', '`' . pSQL($this->identifier) . '` = ' . (int) $this->id . ' AND `id_lang` = ' . (int) $field['id_lang']);
     }
     Module::hookExec('afterSaveFeature', array('id_feature' => $this->id));
     return $result;
 }
Beispiel #25
0
 public function deleteSelection($selection)
 {
     if (!is_array($selection) or !Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
         die(Tools::displayError());
     }
     $result = true;
     foreach ($selection as $id) {
         $this->id = (int) $id;
         $result = $result and $this->delete();
     }
     Tools::generateHtaccess(dirname(__FILE__) . '/../.htaccess', (int) Configuration::get('PS_REWRITING_SETTINGS'), (int) Configuration::get('PS_HTACCESS_CACHE_CONTROL'), Configuration::get('PS_HTACCESS_SPECIFIC'));
     return $result;
 }
 /**
  * Build object
  *
  * @param int $id Existing object id in order to load object (optional)
  * @param null $db
  * @throws Exception
  */
 public function __construct($id = null, $db = null)
 {
     $id_lang = null;
     $id_shop = null;
     if (!ObjectModel::$db) {
         ObjectModel::$db = Db::getInstance();
     }
     $this->_db = $db ? $db : ObjectModel::$db;
     $this->def = ObjectModel::getDefinition($this);
     if (!Validate::isTableOrIdentifier($this->def['primary']) || !Validate::isTableOrIdentifier($this->def['table'])) {
         throw new Exception('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 . '_' . $this->getDb()->getDatabaseName();
         if (1 || !Cache::isStored($cache_id)) {
             $sql = new DbQuery();
             $sql->from($this->def['table'], 'a');
             $sql->where('a.' . $this->def['primary'] . ' = ' . (int) $id);
             // Get shop informations
             if ($object_datas = $this->getDb()->getRow($sql)) {
                 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;
                 }
             }
         }
     }
 }
Beispiel #27
0
    /**
     * Get the current objects' list form the database
     *
     * @param integer $id_lang Language used for display
     * @param string $orderBy ORDER BY clause
     * @param string $_orderWay Order way (ASC, DESC)
     * @param integer $start Offset in LIMIT clause
     * @param integer $limit Row count in LIMIT clause
     */
    public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL)
    {
        global $cookie;
        /* Manage default params values */
        if (empty($limit)) {
            $limit = !isset($cookie->{$this->table . '_pagination'}) ? $this->_pagination[1] : ($limit = $cookie->{$this->table . '_pagination'});
        }
        if (!Validate::isTableOrIdentifier($this->table)) {
            die(Tools::displayError('Table name is invalid:') . ' "' . $this->table . '"');
        }
        if (empty($orderBy)) {
            $orderBy = $cookie->__get($this->table . 'Orderby') ? $cookie->__get($this->table . 'Orderby') : $this->_defaultOrderBy;
        }
        if (empty($orderWay)) {
            $orderWay = $cookie->__get($this->table . 'Orderway') ? $cookie->__get($this->table . 'Orderway') : 'ASC';
        }
        $limit = (int) Tools::getValue('pagination', $limit);
        $cookie->{$this->table . '_pagination'} = $limit;
        /* Check params validity */
        if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay) or !is_numeric($start) or !is_numeric($limit) or !Validate::isUnsignedId($id_lang)) {
            die(Tools::displayError('get list params is not valid'));
        }
        /* Determine offset from current page */
        if ((isset($_POST['submitFilter' . $this->table]) or isset($_POST['submitFilter' . $this->table . '_x']) or isset($_POST['submitFilter' . $this->table . '_y'])) and !empty($_POST['submitFilter' . $this->table]) and is_numeric($_POST['submitFilter' . $this->table])) {
            $start = (int) ($_POST['submitFilter' . $this->table] - 1) * $limit;
        }
        /* Cache */
        $this->_lang = (int) $id_lang;
        $this->_orderBy = $orderBy;
        $this->_orderWay = Tools::strtoupper($orderWay);
        /* SQL table : orders, but class name is Order */
        $sqlTable = $this->table == 'order' ? 'orders' : $this->table;
        /* Query in order to get results with all fields */
        $sql = 'SELECT SQL_CALC_FOUND_ROWS
			' . ($this->_tmpTableFilter ? ' * FROM (SELECT ' : '') . '
			' . ($this->lang ? 'b.*, ' : '') . 'a.*' . (isset($this->_select) ? ', ' . $this->_select . ' ' : '') . '
			FROM `' . _DB_PREFIX_ . $sqlTable . '` a
			' . ($this->lang ? 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`' . $this->identifier . '` = a.`' . $this->identifier . '` AND b.`id_lang` = ' . (int) $id_lang . ')' : '') . '
			' . (isset($this->_join) ? $this->_join . ' ' : '') . '
			WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . ($this->deleted ? 'AND a.`deleted` = 0 ' : '') . (isset($this->_filter) ? $this->_filter : '') . '
			' . (isset($this->_group) ? $this->_group . ' ' : '') . '
			' . (isset($this->_filterHaving) || isset($this->_having) ? 'HAVING ' : '') . (isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '') . (isset($this->_having) ? $this->_having . ' ' : '') . '
			ORDER BY ' . ($orderBy == $this->identifier ? 'a.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . ($this->_tmpTableFilter ? ') tmpTable WHERE 1' . $this->_tmpTableFilter : '') . '
			LIMIT ' . (int) $start . ',' . (int) $limit;
        $this->_list = Db::getInstance()->ExecuteS($sql);
        $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `' . _DB_PREFIX_ . $this->table . '`');
    }
Beispiel #28
0
 public function deleteSelection($selection)
 {
     if (!is_array($selection) or !Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
         die(Tools::displayError());
     }
     $result = true;
     foreach ($selection as $id) {
         $this->id = (int) $id;
         $result &= $this->delete();
     }
     // If url_rewrite is not enabled, we don't need to regenerate .htaccess
     if (!Configuration::get('PS_REWRITING_SETTINGS')) {
         return true;
     }
     Tools::generateHtaccess(dirname(__FILE__) . '/../.htaccess', (int) Configuration::get('PS_REWRITING_SETTINGS'), (int) Configuration::get('PS_HTACCESS_CACHE_CONTROL'), Configuration::get('PS_HTACCESS_SPECIFIC'), (int) Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS'));
     return $result;
 }