994 lines
39 KiB
PHP
Executable File
994 lines
39 KiB
PHP
Executable File
<?php
|
|
/*
|
|
* 2007-2013 PrestaShop
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
*
|
|
* @author PrestaShop SA <contact@prestashop.com>
|
|
* @copyright 2007-2013 PrestaShop SA
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
|
|
/**
|
|
* @since 1.5.0
|
|
* @version 1.2 (2012-03-14)
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
include_once(_PS_MODULE_DIR_.'devspefiltreproduit/filtreItem.php');
|
|
include_once(_PS_MODULE_DIR_.'devspefiltreproduit/filtreTheme.php');
|
|
|
|
class devspefiltreproduit extends Module
|
|
{
|
|
private $_html = '';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->name = 'devspefiltreproduit';
|
|
|
|
$this->version = '1';
|
|
$this->need_instance = 0;
|
|
$this->secure_key = Tools::encrypt($this->name);
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Gestion du filtre produits');
|
|
$this->description = $this->l('Administrer les filtres des produits');
|
|
}
|
|
|
|
/**
|
|
* @see Module::install()
|
|
*/
|
|
public function install()
|
|
{
|
|
/* Adds Module */
|
|
if (parent::install() && $this->registerHook('top') && $this->registerHook('actionShopDataDuplication'))
|
|
{
|
|
$res = $this->createTables();
|
|
|
|
return $res;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* @see Module::uninstall()
|
|
*/
|
|
public function uninstall()
|
|
{
|
|
/* Deletes Module */
|
|
if (parent::uninstall())
|
|
{
|
|
/* Deletes tables */
|
|
$res = $this->deleteTables();
|
|
/* Unsets configuration */
|
|
// $res &= Configuration::deleteByName('devspefiltreproduit_WIDTH');
|
|
// $res &= Configuration::deleteByName('devspefiltreproduit_HEIGHT');
|
|
// $res &= Configuration::deleteByName('devspefiltreproduit_SPEED');
|
|
// $res &= Configuration::deleteByName('devspefiltreproduit_PAUSE');
|
|
// $res &= Configuration::deleteByName('devspefiltreproduit_LOOP');
|
|
return $res;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Creates tables
|
|
*/
|
|
protected function createTables()
|
|
{
|
|
/* filtres */
|
|
$res = (bool)Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspefiltreproduit` (
|
|
`id_filtre_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`id_shop` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`id_filtre_item`, `id_shop`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
$res = (bool)Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspefiltreproduit_liaison` (
|
|
`id_filtre_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`id_product` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`id_filtre_item`, `id_product`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
|
|
/* filtres configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspefiltreproduit_item` (
|
|
`id_filtre_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`position` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
`id_theme` int(11) unsigned NOT NULL DEFAULT \'0\',
|
|
`active` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
|
PRIMARY KEY (`id_filtre_item`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
|
|
/* filtres lang configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspefiltreproduit_item_lang` (
|
|
`id_filtre_item` int(10) unsigned NOT NULL,
|
|
`id_lang` int(10) unsigned NOT NULL,
|
|
`title` varchar(255) NOT NULL,
|
|
`subtitle` varchar(255) NOT NULL,
|
|
`description` text NOT NULL,
|
|
`legend` varchar(255) NOT NULL,
|
|
`url` varchar(255) NOT NULL,
|
|
|
|
PRIMARY KEY (`id_filtre_item`,`id_lang`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* filtres configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspefiltreproduit_theme` (
|
|
`id_filtre_theme` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`id_filtre_parent` int(10) unsigned NOT NULL,
|
|
`position` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
`active` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
|
PRIMARY KEY (`id_filtre_theme`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
|
|
/* filtres lang configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspefiltreproduit_theme_lang` (
|
|
`id_filtre_theme` int(10) unsigned NOT NULL,
|
|
`id_lang` int(10) unsigned NOT NULL,
|
|
`title` varchar(255) NOT NULL,
|
|
|
|
PRIMARY KEY (`id_filtre_theme`,`id_lang`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* deletes tables
|
|
*/
|
|
protected function deleteTables()
|
|
{
|
|
$filtres = $this->getItemsfiltre();
|
|
foreach ($filtres as $filtre)
|
|
{
|
|
$to_del = new filtreItem($filtre['id_filtre']);
|
|
$to_del->delete();
|
|
}
|
|
return Db::getInstance()->execute('
|
|
DROP TABLE IF EXISTS `'._DB_PREFIX_.'devspefiltreproduit`, `'._DB_PREFIX_.'devspefiltreproduit_item`, `'._DB_PREFIX_.'devspefiltreproduit_item_lang`, `'._DB_PREFIX_.'devspefiltreproduit_theme`, `'._DB_PREFIX_.'devspefiltreproduit_theme_lang`;
|
|
');
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
$this->_html .= $this->headerHTML();
|
|
$this->_html .= '<h2>'.$this->displayName.'</h2>';
|
|
|
|
/* Validate & process */
|
|
if (Tools::isSubmit('submitfiltre') || Tools::isSubmit('delete_id_filtre') ||
|
|
Tools::isSubmit('submittheme') || Tools::isSubmit('delete_id_theme') ||
|
|
Tools::isSubmit('changeStatus'))
|
|
{
|
|
if ($this->_postValidation())
|
|
$this->_postProcess();
|
|
$this->_displayForm();
|
|
}
|
|
elseif (Tools::isSubmit('addfiltre') || (Tools::isSubmit('id_filtre') && $this->filtreExists((int)Tools::getValue('id_filtre'))))
|
|
$this->_displayAddItemForm();
|
|
elseif (Tools::isSubmit('addtheme') || (Tools::isSubmit('id_theme') && $this->filtreThemeExists((int)Tools::getValue('id_theme'))))
|
|
$this->_displayAddThemeForm();
|
|
else
|
|
$this->_displayForm();
|
|
|
|
return $this->_html;
|
|
}
|
|
|
|
private function _displayForm()
|
|
{
|
|
/* THEME filtre */
|
|
|
|
$filtres = $this->getItemsTheme();
|
|
|
|
$this->_html .= '<br /><br />';
|
|
|
|
/* Begin fieldset filtres */
|
|
$this->_html .= '
|
|
<fieldset>
|
|
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Gestion des thèmes').'</legend>
|
|
<strong>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addtheme">
|
|
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter un thème').'
|
|
</a>
|
|
</strong>';
|
|
|
|
/* Display notice if there are no filtres yet */
|
|
if (!$filtres)
|
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Aucun thème créé').'</p>';
|
|
else /* Display filtres */
|
|
{
|
|
$this->_html .= '
|
|
<div id="filtresContent" style="width: 700px; margin-top: 30px;">
|
|
<ul id="themes">';
|
|
foreach ($filtres as $filtre)
|
|
{
|
|
$this->_html .= '
|
|
<li id="filtres_'.$filtre['id_theme'].'">';
|
|
if($filtre['id_filtre_parent']==0)
|
|
$this->_html .= '<strong>Thème '.$filtre['id_theme'].'</strong> : '.$filtre['title']."";
|
|
else
|
|
$this->_html .= '<i>Thème '.$filtre['id_filtre_parent'].'</i> > <strong>Thème '.$filtre['id_theme'].'</strong> : '.$filtre['title'];
|
|
|
|
$this->_html .= '
|
|
<p style="float: right;margin:0;">'.
|
|
$this->displayStatus($filtre['id_theme'], $filtre['active']).'
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_theme='.(int)($filtre['id_theme']).'" title="'.$this->l('Edit').'"><img src="'._PS_ADMIN_IMG_.'edit.gif" alt="" /></a>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&delete_id_theme='.(int)($filtre['id_theme']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
|
|
</p>
|
|
</li>';
|
|
}
|
|
$this->_html .= '</ul></div>';
|
|
}
|
|
// End fieldset
|
|
$this->_html .= '</fieldset>';
|
|
|
|
|
|
|
|
/* ITEMS filtre */
|
|
|
|
/* Gets filtres */
|
|
$filtres = $this->getItemsfiltre();
|
|
|
|
$this->_html .= '<br /><br />';
|
|
|
|
/* Begin fieldset filtres */
|
|
$this->_html .= '
|
|
<fieldset>
|
|
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Gestion des filtres').'</legend>
|
|
<strong>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addfiltre">
|
|
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter un filtre').'
|
|
</a>
|
|
</strong>';
|
|
|
|
/* Display notice if there are no filtres yet */
|
|
if (!$filtres)
|
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Aucun idem créée').'</p>';
|
|
else /* Display filtres */
|
|
{
|
|
$this->_html .= '
|
|
<div id="filtresContent" style="width: 700px; margin-top: 30px;">
|
|
<ul id="filtres">';
|
|
foreach ($filtres as $filtre)
|
|
{
|
|
$this->_html .= '
|
|
<li id="filtres_'.$filtre['id_filtre'].'">
|
|
<strong>Thème '.$filtre['id_theme'].'</strong> : '.$filtre['title'].'
|
|
<p style="float: right;margin:0;">'.
|
|
$this->displayStatus($filtre['id_filtre'], $filtre['active']).'
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_filtre='.(int)($filtre['id_filtre']).'" title="'.$this->l('Edit').'"><img src="'._PS_ADMIN_IMG_.'edit.gif" alt="" /></a>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&delete_id_filtre='.(int)($filtre['id_filtre']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
|
|
</p>
|
|
</li>';
|
|
}
|
|
$this->_html .= '</ul></div>';
|
|
}
|
|
// End fieldset
|
|
$this->_html .= '</fieldset>';
|
|
}
|
|
|
|
private function _displayAddItemForm()
|
|
{
|
|
/* Sets filtre : depends if edited or added */
|
|
$filtre = null;
|
|
if (Tools::isSubmit('id_filtre') && $this->filtreExists((int)Tools::getValue('id_filtre')))
|
|
$filtre = new filtreItem((int)Tools::getValue('id_filtre'));
|
|
/* Checks if directory is writable */
|
|
// if (!is_writable('.'))
|
|
// $this->adminDisplayWarning(sprintf($this->l('Modules %s must be writable (CHMOD 755 / 777)'), $this->name));
|
|
|
|
/* Gets languages and sets which div requires translations */
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
$languages = Language::getLanguages(false);
|
|
$divLangName = 'title¤description';
|
|
$this->_html .= '<script type="text/javascript">id_language = Number('.$id_lang_default.');</script>';
|
|
|
|
/* Form */
|
|
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
|
|
/* Fieldset Upload */
|
|
// $this->_html .= '
|
|
// <fieldset class="width3" style="width:900px"
|
|
// <br />
|
|
// <legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" />1 - '.$this->l('Téléchargez votre image').'</legend>';
|
|
// /* Image */
|
|
// $this->_html .= '<label>'.$this->l('Selectionnez un fichier:').' * </label><div class="margin-form">';
|
|
// foreach ($languages as $language)
|
|
// {
|
|
// $this->_html .= '<div id="image_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">';
|
|
// $this->_html .= '<input type="file" name="image_'.$language['id_lang'].'" id="image_'.$language['id_lang'].'" size="80" value="'.(isset($filtre->image[$language['id_lang']]) ? $filtre->image[$language['id_lang']] : '').'"/>';
|
|
// /* Sets image as hidden in case it does not change */
|
|
// if ($filtre && $filtre->image[$language['id_lang']])
|
|
// $this->_html .= '<input type="hidden" name="image_old_'.$language['id_lang'].'" value="'.($filtre->image[$language['id_lang']]).'" id="image_old_'.$language['id_lang'].'" />';
|
|
// /* Display image */
|
|
// if ($filtre && $filtre->image[$language['id_lang']])
|
|
// $this->_html .= '<input type="hidden" name="has_picture" value="1" /><img src="'.__PS_BASE_URI__.'modules/'.$this->name.'/images/'.$filtre->image[$language['id_lang']].'" width="'.(Configuration::get('devspefiltreproduit_WIDTH')/2).'" height="'.(Configuration::get('devspefiltreproduit_HEIGHT')/2).'" alt=""/>';
|
|
// $this->_html .= '</div>';
|
|
// }
|
|
// $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'image', true);
|
|
// /* End Fieldset Upload */
|
|
// $this->_html .= '</fieldset><br /><br />';
|
|
|
|
|
|
/* Fieldset edit/add */
|
|
$this->_html .= '<fieldset class="width3" style="width:900px">';
|
|
if (Tools::isSubmit('addfiltre')) /* Configure legend */
|
|
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> 1 - '.$this->l('Ajouter un filtre de produit').'</legend>';
|
|
elseif (Tools::isSubmit('id_filtre')) /* Edit legend */
|
|
$this->_html .= '<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" />'.$this->l('Modifier le filtre').'</legend>';
|
|
/* Sets id filtre as hidden */
|
|
if ($filtre && Tools::getValue('id_filtre'))
|
|
$this->_html .= '<input type="hidden" name="id_filtre" value="'.$filtre->id.'" id="id_filtre" />';
|
|
/* Sets position as hidden */
|
|
$this->_html .= '<input type="hidden" name="position" value="'.(($filtre != null) ? ($filtre->position) : ($this->getNextPosition())).'" id="position" />';
|
|
|
|
$themes=$this->getItemsTheme(null);
|
|
// print_r($themes);
|
|
$les_themes='<select name="id_theme" id="id_theme" style="width:230px">';
|
|
foreach($themes as $row){
|
|
$les_themes.='<option value="'.$row['id_theme'].'" '.($filtre->id_theme==$row['id_theme']?'selected="selected"':'').'>Thème '.$row['id_theme'].' : '.$row['title'].'</option>';
|
|
}
|
|
$les_themes.='</select>';
|
|
|
|
/* theme parent */
|
|
$this->_html .= '<br /><label>'.$this->l('Thème parent :').' * </label><div class="margin-form">';
|
|
$this->_html .= '<div style="float: left;">'.$les_themes.'</div>';
|
|
$this->_html .= '</div><br /><br />';
|
|
/* Form content */
|
|
|
|
|
|
/* Form content */
|
|
/* Title */
|
|
$this->_html .= '<label>'.$this->l('Label du filtre').' * </label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="title_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="title_'.$language['id_lang'].'" id="title_'.$language['id_lang'].'" size="80" value="'.(isset($filtre->title[$language['id_lang']]) ? $filtre->title[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'title', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
/* Description */
|
|
$this->_html .= '
|
|
<div style="display:none">
|
|
<label>'.$this->l('Réponse :').' * </label>
|
|
<div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '<div id="description_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<textarea name="description_'.$language['id_lang'].'" rows="8" cols="77" style="padding:2px 3px">'.(isset($filtre->description[$language['id_lang']]) ? $filtre->description[$language['id_lang']] : '').'</textarea>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'description', true);
|
|
$this->_html .= '</div></div><div class="clear"></div><br />';
|
|
|
|
|
|
|
|
/* Active */
|
|
$this->_html .= '
|
|
<label for="active_on">'.$this->l('Active:').'</label>
|
|
<div class="margin-form">
|
|
<img src="../img/admin/enabled.gif" alt="Yes" title="Yes" />
|
|
<input type="radio" name="active_filtre" id="active_on" '.(($filtre && (isset($filtre->active) && (int)$filtre->active == 0)) ? '' : 'checked="checked" ').' value="1" />
|
|
<label class="t" for="active_on">'.$this->l('Yes').'</label>
|
|
<img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" />
|
|
<input type="radio" name="active_filtre" id="active_off" '.(($filtre && (isset($filtre->active) && (int)$filtre->active == 0)) ? 'checked="checked" ' : '').' value="0" />
|
|
<label class="t" for="active_off">'.$this->l('No').'</label>
|
|
</div>';
|
|
|
|
/* Save */
|
|
$this->_html .= '
|
|
<p style="padding-left:260px">
|
|
<input type="submit" class="button" name="submitfiltre" value="'.$this->l('Save').'" />
|
|
<a class="button" style="position:relative; padding:4px 3px; top:0" href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'">'.$this->l('Annuler').'</a>
|
|
</p>';
|
|
|
|
/* End of fieldset & form */
|
|
$this->_html .= '
|
|
<p>*'.$this->l('Champs obligatoire').'</p>
|
|
</fieldset>
|
|
</form>';
|
|
}
|
|
private function _displayAddThemeForm()
|
|
{
|
|
/* Sets filtre : depends if edited or added */
|
|
$filtre = null;
|
|
if (Tools::isSubmit('id_theme') && $this->filtreThemeExists((int)Tools::getValue('id_theme')))
|
|
$filtre = new filtreTheme((int)Tools::getValue('id_theme'));
|
|
// print_r($filtre);
|
|
/* Checks if directory is writable */
|
|
// if (!is_writable('.'))
|
|
// $this->adminDisplayWarning(sprintf($this->l('Modules %s must be writable (CHMOD 755 / 777)'), $this->name));
|
|
|
|
/* Gets languages and sets which div requires translations */
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
$languages = Language::getLanguages(false);
|
|
$divLangName = 'title';
|
|
$this->_html .= '<script type="text/javascript">id_language = Number('.$id_lang_default.');</script>';
|
|
|
|
/* Form */
|
|
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
|
|
/* Fieldset edit/add */
|
|
$this->_html .= '<fieldset class="width3" style="width:900px">';
|
|
if (Tools::getValue('addtheme')) /* Configure legend */
|
|
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter un thème').'</legend>';
|
|
elseif (Tools::getValue('id_theme')) /* Edit legend */
|
|
$this->_html .= '<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Modifier le thème').'</legend>';
|
|
/* Sets id filtre as hidden */
|
|
$id_filtre=0;
|
|
if ($filtre && Tools::getValue('id_theme')){
|
|
$id_filtre=$filtre->id;
|
|
$this->_html .= '<input type="hidden" name="id_theme" value="'.$filtre->id.'" id="id_theme" />';
|
|
}
|
|
/* Sets position as hidden */
|
|
$this->_html .= '<input type="hidden" name="position" value="'.(($filtre != null) ? ($filtre->position) : ($this->getNextPositionTheme())).'" id="position" />';
|
|
|
|
/* Form content */
|
|
|
|
$themes=$this->getItemsTheme(null,true);
|
|
// print_r($themes);
|
|
$les_themes='<select name="id_filtre_parent" id="id_filtre_parent" style="width:230px"><option value="0"> Aucun </option>';
|
|
foreach($themes as $row){
|
|
if($row['id_theme']!=$filtre->id)
|
|
$les_themes.='<option value="'.$row['id_theme'].'" '.($id_filtre==$row['id_theme']?'selected="selected"':'').'>Thème '.$row['id_theme'].' : '.$row['title'].'</option>';
|
|
}
|
|
$les_themes.='</select>';
|
|
|
|
/* theme parent */
|
|
$this->_html .= '<br /><div style="display:none"><label>'.$this->l('Thème parent :').' * </label><div class="margin-form">';
|
|
$this->_html .= '<div style="float: left;">'.$les_themes.'</div>';
|
|
$this->_html .= '</div><br /><br /></div>';
|
|
/* Form content */
|
|
|
|
/* Title */
|
|
$this->_html .= '<br /><label>'.$this->l('Nom du thème :').' * </label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="title_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="title_'.$language['id_lang'].'" id="title_'.$language['id_lang'].'" size="80" value="'.(isset($filtre->title[$language['id_lang']]) ? $filtre->title[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'title', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
|
|
/* Active */
|
|
$this->_html .= '
|
|
<label for="active_on">'.$this->l('Active:').'</label>
|
|
<div class="margin-form">
|
|
<img src="../img/admin/enabled.gif" alt="Yes" title="Yes" />
|
|
<input type="radio" name="active_theme" id="active_on" '.(($filtre && (isset($filtre->active) && (int)$filtre->active == 0)) ? '' : 'checked="checked" ').' value="1" />
|
|
<label class="t" for="active_on">'.$this->l('Yes').'</label>
|
|
<img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" />
|
|
<input type="radio" name="active_theme" id="active_off" '.(($filtre && (isset($filtre->active) && (int)$filtre->active == 0)) ? 'checked="checked" ' : '').' value="0" />
|
|
<label class="t" for="active_off">'.$this->l('No').'</label>
|
|
</div>';
|
|
|
|
/* Save */
|
|
$this->_html .= '
|
|
<p style="padding-left:260px">
|
|
<input type="submit" class="button" name="submittheme" value="'.$this->l('Save').'" />
|
|
<a class="button" style="position:relative; padding:4px 3px; top:0" href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'">'.$this->l('Annuler').'</a>
|
|
</p>';
|
|
|
|
/* End of fieldset & form */
|
|
$this->_html .= '
|
|
<p>*'.$this->l('Champs obligatoire').'</p>
|
|
</fieldset>
|
|
</form>';
|
|
}
|
|
|
|
private function _postValidation()
|
|
{
|
|
$errors = array();
|
|
|
|
if (Tools::isSubmit('changeStatus'))
|
|
{
|
|
if (!Validate::isInt(Tools::getValue('id_filtre')))
|
|
$errors[] = $this->l('Invalid filtre');
|
|
}
|
|
/* Validation for filtre */
|
|
elseif (Tools::isSubmit('submitfiltre'))
|
|
{
|
|
/* Checks state (active) */
|
|
if (!Validate::isInt(Tools::getValue('active_filtre')) || (Tools::getValue('active_filtre') != 0 && Tools::getValue('active_filtre') != 1))
|
|
$errors[] = $this->l('Invalid filtre state');
|
|
/* Checks position */
|
|
if (!Validate::isInt(Tools::getValue('position')) || (Tools::getValue('position') < 0))
|
|
$errors[] = $this->l('Invalid filtre position');
|
|
/* If edit : checks id_filtre */
|
|
if (Tools::isSubmit('id_filtre'))
|
|
{
|
|
if (!Validate::isInt(Tools::getValue('id_filtre')) && !$this->filtreExists(Tools::getValue('id_filtre')))
|
|
$errors[] = $this->l('Invalid id_filtre');
|
|
}
|
|
/* Checks title/url/legend/description/image */
|
|
$languages = Language::getLanguages(false);
|
|
foreach ($languages as $language)
|
|
{
|
|
if (Tools::strlen(Tools::getValue('title_'.$language['id_lang'])) > 255)
|
|
$errors[] = $this->l('The title is too long.');
|
|
// if (Tools::strlen(Tools::getValue('description_'.$language['id_lang'])) > 4000)
|
|
// $errors[] = $this->l('The description is too long.');
|
|
// if (Tools::getValue('image_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_'.$language['id_lang'])))
|
|
// $errors[] = $this->l('Invalid filename');
|
|
// if (Tools::getValue('image_old_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_old_'.$language['id_lang'])))
|
|
// $errors[] = $this->l('Invalid filename');
|
|
}
|
|
|
|
/* Checks title/url/legend/description for default lang */
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
if (Tools::strlen(Tools::getValue('title_'.$id_lang_default)) == 0)
|
|
$errors[] = $this->l('Label obligatoire');
|
|
// if (Tools::strlen(Tools::getValue('description_'.$id_lang_default)) == 0)
|
|
// $errors[] = $this->l('Description obligatoire');
|
|
// if (!Tools::isSubmit('has_picture') && (!isset($_FILES['image_'.$id_lang_default]) || empty($_FILES['image_'.$id_lang_default]['tmp_name'])))
|
|
// $errors[] = $this->l('The image is not set.');
|
|
// if (Tools::getValue('image_old_'.$id_lang_default) && !Validate::isFileName(Tools::getValue('image_old_'.$id_lang_default)))
|
|
// $errors[] = $this->l('The image is not set.');
|
|
} /* Validation for deletion */
|
|
elseif (Tools::isSubmit('delete_id_filtre') && (!Validate::isInt(Tools::getValue('delete_id_filtre')) || !$this->filtreExists((int)Tools::getValue('delete_id_filtre'))))
|
|
$errors[] = $this->l('Invalid id_filtre');
|
|
|
|
elseif (Tools::isSubmit('submittheme'))
|
|
{
|
|
/* Checks state (active) */
|
|
if (!Validate::isInt(Tools::getValue('active_theme')) || (Tools::getValue('active_theme') != 0 && Tools::getValue('active_theme') != 1))
|
|
$errors[] = $this->l('Invalid theme state');
|
|
/* Checks position */
|
|
if (!Validate::isInt(Tools::getValue('position')) || (Tools::getValue('position') < 0))
|
|
$errors[] = $this->l('Invalid theme position');
|
|
/* If edit : checks id_theme */
|
|
if (Tools::isSubmit('id_theme'))
|
|
{
|
|
if (!Validate::isInt(Tools::getValue('id_theme')) && !$this->filtreExists(Tools::getValue('id_theme')))
|
|
$errors[] = $this->l('Invalid id_theme');
|
|
}
|
|
/* Checks title/url/legend/description/image */
|
|
$languages = Language::getLanguages(false);
|
|
foreach ($languages as $language)
|
|
{
|
|
if (Tools::strlen(Tools::getValue('title_'.$language['id_lang'])) > 255)
|
|
$errors[] = $this->l('The title is too long.');
|
|
// if (Tools::strlen(Tools::getValue('description_'.$language['id_lang'])) > 4000)
|
|
// $errors[] = $this->l('The description is too long.');
|
|
// if (Tools::getValue('image_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_'.$language['id_lang'])))
|
|
// $errors[] = $this->l('Invalid filename');
|
|
// if (Tools::getValue('image_old_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_old_'.$language['id_lang'])))
|
|
// $errors[] = $this->l('Invalid filename');
|
|
}
|
|
|
|
/* Checks title/url/legend/description for default lang */
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
if (Tools::strlen(Tools::getValue('title_'.$id_lang_default)) == 0)
|
|
$errors[] = $this->l('Nom du thème obligatoire');
|
|
|
|
} /* Validation for deletion */
|
|
elseif (Tools::isSubmit('delete_id_theme') && (!Validate::isInt(Tools::getValue('delete_id_theme')) || !$this->filtreThemeExists((int)Tools::getValue('delete_id_theme'))))
|
|
$errors[] = $this->l('Invalid id_theme');
|
|
|
|
/* Display errors if needed */
|
|
if (count($errors))
|
|
{
|
|
$this->_html .= $this->displayError(implode('<br />', $errors));
|
|
return false;
|
|
}
|
|
|
|
/* Returns if validation is ok */
|
|
return true;
|
|
}
|
|
|
|
private function _postProcess()
|
|
{
|
|
$errors = array();
|
|
|
|
if (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_filtre'))
|
|
{
|
|
$filtre = new filtreItem((int)Tools::getValue('id_filtre'));
|
|
if ($filtre->active == 0)
|
|
$filtre->active = 1;
|
|
else
|
|
$filtre->active = 0;
|
|
$res = $filtre->update();
|
|
$this->clearCache();
|
|
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
|
}
|
|
/* Processes filtre */
|
|
elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_theme'))
|
|
{
|
|
$filtre = new filtreTheme((int)Tools::getValue('id_theme'));
|
|
if ($filtre->active == 0)
|
|
$filtre->active = 1;
|
|
else
|
|
$filtre->active = 0;
|
|
$res = $filtre->update();
|
|
$this->clearCache();
|
|
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
|
}
|
|
/* Processes filtre */
|
|
elseif (Tools::isSubmit('submitfiltre'))
|
|
{
|
|
/* Sets ID if needed */
|
|
if (Tools::getValue('id_filtre'))
|
|
{
|
|
$filtre = new filtreItem((int)Tools::getValue('id_filtre'));
|
|
if (!Validate::isLoadedObject($filtre))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_filtre'));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
$filtre = new filtreItem();
|
|
/* Sets position */
|
|
$filtre->position = (int)Tools::getValue('position');
|
|
$filtre->id_theme = (int)Tools::getValue('id_theme');
|
|
/* Sets active */
|
|
$filtre->active = (int)Tools::getValue('active_filtre');
|
|
|
|
/* Sets each langue fields */
|
|
$languages = Language::getLanguages(false);
|
|
foreach ($languages as $language)
|
|
{
|
|
$filtre->title[$language['id_lang']] = Tools::getValue('title_'.$language['id_lang']);
|
|
$filtre->description[$language['id_lang']] = Tools::getValue('description_'.$language['id_lang']);
|
|
|
|
// /* Uploads image and sets filtre */
|
|
// $type = strtolower(substr(strrchr($_FILES['image_'.$language['id_lang']]['name'], '.'), 1));
|
|
// $imagesize = array();
|
|
// $imagesize = @getimagesize($_FILES['image_'.$language['id_lang']]['tmp_name']);
|
|
// if (isset($_FILES['image_'.$language['id_lang']]) &&
|
|
// isset($_FILES['image_'.$language['id_lang']]['tmp_name']) &&
|
|
// !empty($_FILES['image_'.$language['id_lang']]['tmp_name']) &&
|
|
// !empty($imagesize) &&
|
|
// in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) &&
|
|
// in_array($type, array('jpg', 'gif', 'jpeg', 'png')))
|
|
// {
|
|
// $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
|
|
// $salt = sha1(microtime());
|
|
// if ($error = ImageManager::validateUpload($_FILES['image_'.$language['id_lang']]))
|
|
// $errors[] = $error;
|
|
// elseif (!$temp_name || !move_uploaded_file($_FILES['image_'.$language['id_lang']]['tmp_name'], $temp_name))
|
|
// return false;
|
|
// elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/images/'.Tools::encrypt($_FILES['image_'.$language['id_lang']]['name'].$salt).'.'.$type, null, null, $type))
|
|
// $errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
|
|
// if (isset($temp_name))
|
|
// @unlink($temp_name);
|
|
// $filtre->image[$language['id_lang']] = Tools::encrypt($_FILES['image_'.($language['id_lang'])]['name'].$salt).'.'.$type;
|
|
// }
|
|
// elseif (Tools::getValue('image_old_'.$language['id_lang']) != '')
|
|
// $filtre->image[$language['id_lang']] = Tools::getValue('image_old_'.$language['id_lang']);
|
|
}
|
|
|
|
/* Processes if no errors */
|
|
if (!$errors)
|
|
{
|
|
/* Adds */
|
|
if (!Tools::getValue('id_filtre'))
|
|
{
|
|
if (!$filtre->add())
|
|
$errors[] = $this->displayError($this->l('The filtre could not be added.'));
|
|
}
|
|
/* Update */
|
|
elseif (!$filtre->update())
|
|
$errors[] = $this->displayError($this->l('The filtre could not be updated.'));
|
|
$this->clearCache();
|
|
}
|
|
} /* Deletes */
|
|
elseif (Tools::isSubmit('delete_id_filtre'))
|
|
{
|
|
$filtre = new filtreItem((int)Tools::getValue('delete_id_filtre'));
|
|
$res = $filtre->delete();
|
|
$this->clearCache();
|
|
if (!$res)
|
|
$this->_html .= $this->displayError('Could not delete');
|
|
else
|
|
$this->_html .= $this->displayConfirmation($this->l('filtre deleted'));
|
|
}
|
|
elseif (Tools::isSubmit('submittheme'))
|
|
{
|
|
/* Sets ID if needed */
|
|
if (Tools::getValue('id_theme'))
|
|
{
|
|
$filtre = new filtreTheme((int)Tools::getValue('id_theme'));
|
|
if (!Validate::isLoadedObject($filtre))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_theme'));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
$filtre = new filtreTheme();
|
|
/* Sets position */
|
|
$filtre->id_filtre_parent = (int)Tools::getValue('id_filtre_parent');
|
|
|
|
$filtre->position = (int)Tools::getValue('position');
|
|
/* Sets active */
|
|
$filtre->active = (int)Tools::getValue('active_theme');
|
|
|
|
/* Sets each langue fields */
|
|
$languages = Language::getLanguages(false);
|
|
foreach ($languages as $language)
|
|
{
|
|
$filtre->title[$language['id_lang']] = Tools::getValue('title_'.$language['id_lang']);
|
|
}
|
|
|
|
/* Processes if no errors */
|
|
if (!$errors)
|
|
{
|
|
/* Adds */
|
|
if (!Tools::getValue('id_theme'))
|
|
{
|
|
$filtre->add();
|
|
// $errors[] = $this->displayError($this->l('Le thème ne peut être créé'));
|
|
}
|
|
/* Update */
|
|
elseif (!$filtre->update())
|
|
$errors[] = $this->displayError($this->l('Le thème n\'a pas été modifié'));
|
|
$this->clearCache();
|
|
}
|
|
} /* Deletes */
|
|
elseif (Tools::isSubmit('delete_id_theme'))
|
|
{
|
|
$filtre = new filtreTheme((int)Tools::getValue('delete_id_theme'));
|
|
$res = $filtre->delete();
|
|
$this->clearCache();
|
|
if (!$res)
|
|
$this->_html .= $this->displayError('Could not delete');
|
|
else
|
|
$this->_html .= $this->displayConfirmation($this->l('Thème supprimé'));
|
|
}
|
|
|
|
/* Display errors if needed */
|
|
if (count($errors))
|
|
$this->_html .= $this->displayError(implode('<br />', $errors));
|
|
elseif (Tools::isSubmit('submittheme') && Tools::getValue('id_theme'))
|
|
$this->_html .= $this->displayConfirmation($this->l('Thème updated'));
|
|
elseif (Tools::isSubmit('submittheme'))
|
|
$this->_html .= $this->displayConfirmation($this->l('Thème added'));
|
|
}
|
|
|
|
private function _prepareHook()
|
|
{
|
|
global $smarty;
|
|
$id_lang = $this->context->language->id;
|
|
$sql='
|
|
SELECT
|
|
th.`id_filtre_theme` as id_theme,
|
|
thl.`title` as theme_name,
|
|
f.`id_filtre_item` as id_filtre,
|
|
fl.`title` as filtre_name
|
|
|
|
FROM '._DB_PREFIX_.'devspefiltreproduit_theme th
|
|
LEFT JOIN '._DB_PREFIX_.'devspefiltreproduit_theme_lang thl ON (th.id_filtre_theme = thl.id_filtre_theme)
|
|
|
|
|
|
LEFT JOIN '._DB_PREFIX_.'devspefiltreproduit_item f on(f.id_theme=th.id_filtre_theme)
|
|
LEFT JOIN '._DB_PREFIX_.'devspefiltreproduit_item_lang fl on(f.id_filtre_item=fl.id_filtre_item)
|
|
|
|
|
|
WHERE thl.id_lang = '.(int)$id_lang.'
|
|
and fl.id_lang = '.(int)$id_lang.'
|
|
ORDER BY th.position,f.position
|
|
|
|
';
|
|
$productFiltres=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
|
|
$smarty->assign('productFiltres', $productFiltres);
|
|
|
|
return true;
|
|
}
|
|
|
|
public function hookTop()
|
|
{
|
|
if(!$this->_prepareHook())
|
|
return;
|
|
// echo "test";
|
|
// die();
|
|
// Check if not a mobile theme
|
|
/*
|
|
if ($this->context->getMobileDevice() != false)
|
|
return false;
|
|
|
|
// $this->context->controller->addJS($this->_path.'js/jquery.bxfiltrer.min.js');
|
|
$this->context->controller->addCSS($this->_path.'devspefiltreproduit.css');
|
|
$this->context->controller->addJS($this->_path.'js/devspefiltreproduit.js');
|
|
return $this->display(__FILE__, 'devspefiltreproduit.tpl', $this->getCacheId());
|
|
*/
|
|
}
|
|
|
|
public function clearCache()
|
|
{
|
|
// $this->_clearCache('devspefiltreproduit.tpl');
|
|
}
|
|
|
|
public function hookActionShopDataDuplication($params)
|
|
{
|
|
Db::getInstance()->execute('
|
|
INSERT IGNORE INTO '._DB_PREFIX_.'devspefiltreproduit (id_filtre_item, id_shop)
|
|
SELECT id_filtre_item, '.(int)$params['new_id_shop'].'
|
|
FROM '._DB_PREFIX_.'devspefiltreproduit
|
|
WHERE id_shop = '.(int)$params['old_id_shop']);
|
|
$this->clearCache();
|
|
}
|
|
|
|
public function headerHTML()
|
|
{
|
|
if (Tools::getValue('controller') != 'AdminModules' && Tools::getValue('configure') != $this->name)
|
|
return;
|
|
|
|
$this->context->controller->addJqueryUI('ui.sortable');
|
|
/* Style & js for fieldset 'filtres configuration' */
|
|
$html = '
|
|
<style>
|
|
#themes li,
|
|
#filtres li {
|
|
list-style: none;
|
|
margin: 0 0 4px 0;
|
|
padding: 10px;
|
|
background-color: #F4E6C9;
|
|
border: #CCCCCC solid 1px;
|
|
color:#000;
|
|
}
|
|
</style>
|
|
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/jquery-ui.will.be.removed.in.1.6.js"></script>
|
|
<script type="text/javascript">
|
|
$(function() {
|
|
var $myfiltres = $("#filtres");
|
|
$myfiltres.sortable({
|
|
opacity: 0.6,
|
|
cursor: "move",
|
|
update: function() {
|
|
var order = $(this).sortable("serialize") + "&action=updatefiltresPosition";
|
|
$.post("'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax_'.$this->name.'.php?secure_key='.$this->secure_key.'", order);
|
|
}
|
|
});
|
|
$myfiltres.hover(function() {
|
|
$(this).css("cursor","move");
|
|
},
|
|
function() {
|
|
$(this).css("cursor","auto");
|
|
});
|
|
var $mythemes = $("#themes");
|
|
$mythemes.sortable({
|
|
opacity: 0.6,
|
|
cursor: "move",
|
|
update: function() {
|
|
var order = $(this).sortable("serialize") + "&action=updatefiltresThemePosition";
|
|
$.post("'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax_'.$this->name.'.php?secure_key='.$this->secure_key.'", order);
|
|
}
|
|
});
|
|
$mythemes.hover(function() {
|
|
$(this).css("cursor","move");
|
|
},
|
|
function() {
|
|
$(this).css("cursor","auto");
|
|
});
|
|
});
|
|
</script>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
public function getNextPosition()
|
|
{
|
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
|
SELECT MAX(hss.`position`) AS `next_position`
|
|
FROM `'._DB_PREFIX_.'devspefiltreproduit_item` hss, `'._DB_PREFIX_.'devspefiltreproduit` hs
|
|
WHERE hss.`id_filtre_item` = hs.`id_filtre_item` AND hs.`id_shop` = '.(int)$this->context->shop->id
|
|
);
|
|
|
|
return (++$row['next_position']);
|
|
}
|
|
public function getNextPositionTheme()
|
|
{
|
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
|
SELECT MAX(hss.`position`) AS `next_position`
|
|
FROM `'._DB_PREFIX_.'devspefiltreproduit_theme` hss'
|
|
);
|
|
|
|
return (++$row['next_position']);
|
|
}
|
|
|
|
public function getItemsfiltre($active = null)
|
|
{
|
|
$this->context = Context::getContext();
|
|
$id_shop = $this->context->shop->id;
|
|
$id_lang = $this->context->language->id;
|
|
|
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT hs.`id_filtre_item` as id_filtre,
|
|
hss.`position`,
|
|
hss.`id_theme`,
|
|
hss.`active`,
|
|
hssl.`title`,
|
|
hssl.`description`
|
|
FROM '._DB_PREFIX_.'devspefiltreproduit hs
|
|
LEFT JOIN '._DB_PREFIX_.'devspefiltreproduit_item hss ON (hs.id_filtre_item = hss.id_filtre_item)
|
|
LEFT JOIN '._DB_PREFIX_.'devspefiltreproduit_item_lang hssl ON (hss.id_filtre_item = hssl.id_filtre_item)
|
|
WHERE (id_shop = '.(int)$id_shop.')
|
|
AND hssl.id_lang = '.(int)$id_lang.
|
|
($active ? ' AND hss.`active` = 1' : ' ').'
|
|
ORDER BY hss.position');
|
|
}
|
|
|
|
public function getItemsTheme($active = null,$zero=null)
|
|
{
|
|
$this->context = Context::getContext();
|
|
$id_shop = $this->context->shop->id;
|
|
$id_lang = $this->context->language->id;
|
|
|
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT hss.`id_filtre_theme` as id_theme,
|
|
hss.`position`,
|
|
hss.`active`,
|
|
hss.`id_filtre_parent`,
|
|
hssl.`title`
|
|
FROM '._DB_PREFIX_.'devspefiltreproduit_theme hss
|
|
LEFT JOIN '._DB_PREFIX_.'devspefiltreproduit_theme_lang hssl ON (hss.id_filtre_theme = hssl.id_filtre_theme)
|
|
WHERE hssl.id_lang = '.(int)$id_lang.
|
|
($active ? ' AND hss.`active` = 1' : ' ').
|
|
($zero ? ' AND hss.`id_filtre_parent` = 0' : ' ').'
|
|
ORDER BY hss.position');
|
|
}
|
|
|
|
public function displayStatus($id_filtre, $active)
|
|
{
|
|
$title = ((int)$active == 0 ? $this->l('Disabled') : $this->l('Enabled'));
|
|
$img = ((int)$active == 0 ? 'disabled.gif' : 'enabled.gif');
|
|
$html = '<a href="'.AdminController::$currentIndex.
|
|
'&configure='.$this->name.'
|
|
&token='.Tools::getAdminTokenLite('AdminModules').'
|
|
&changeStatus&id_filtre='.(int)$id_filtre.'" title="'.$title.'"><img src="'._PS_ADMIN_IMG_.''.$img.'" alt="" /></a>';
|
|
return $html;
|
|
}
|
|
|
|
public function filtreExists($id_filtre)
|
|
{
|
|
$req = 'SELECT hs.`id_filtre_item` as id_filtre
|
|
FROM `'._DB_PREFIX_.'devspefiltreproduit` hs
|
|
WHERE hs.`id_filtre_item` = '.(int)$id_filtre;
|
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
|
|
return ($row);
|
|
}
|
|
public function filtreThemeExists($id_theme)
|
|
{
|
|
$req = 'SELECT hs.`id_filtre_theme` as id_theme
|
|
FROM `'._DB_PREFIX_.'devspefiltreproduit_theme` hs
|
|
WHERE hs.`id_filtre_theme` = '.(int)$id_theme;
|
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
|
|
return ($row);
|
|
}
|
|
}
|