garancia/modules/boixmenugarancia/boixmenugarancia.php
2016-10-10 15:24:25 +02:00

746 lines
26 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_.'boixmenugarancia/Boixgarancia.php');
class boixmenugarancia extends Module
{
private $_html = '';
public function __construct()
{
$this->name = 'boixmenugarancia';
$this->version = '1';
$this->need_instance = 0;
$this->secure_key = Tools::encrypt($this->name);
parent::__construct();
$this->displayName = $this->l('Gestion du nouveau menu');
$this->description = $this->l('Administrer le nouveau menu');
}
/**
* @see Module::install()
*/
public function install()
{
/* Adds Module */
if (parent::install() && $this->registerHook('displayTop') && $this->registerHook('actionShopDataDuplication'))
{
$res = $this->createTables();
return $res;
}
return false;
}
/**
* Adds samples
*/
/**
* @see Module::uninstall()
*/
public function uninstall()
{
/* Deletes Module */
if (parent::uninstall())
{
/* Deletes tables */
$res = $this->deleteTables();
/* Unsets configuration */
// $res &= Configuration::deleteByName('boixmenugarancia_WIDTH');
// $res &= Configuration::deleteByName('boixmenugarancia_HEIGHT');
// $res &= Configuration::deleteByName('boixmenugarancia_SPEED');
// $res &= Configuration::deleteByName('boixmenugarancia_PAUSE');
// $res &= Configuration::deleteByName('boixmenugarancia_LOOP');
return $res;
}
return false;
}
/**
* Creates tables
*/
protected function createTables()
{
/* items */
// $res = (bool)Db::getInstance()->execute('
// CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'boixmenugarancia` (
// `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
// `id_shop` int(10) unsigned NOT NULL,
// PRIMARY KEY (`id`, `id_shop`)
// ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
// ');
/* items configuration */
// $res &= Db::getInstance()->execute('
// CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'boixmenugarancia_items` (
// `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
// `colonne` int(10) unsigned NOT NULL DEFAULT \'0\',
// `position` int(10) unsigned NOT NULL DEFAULT \'0\',
// `type` varchar(255) NOT NULL,
// `id_selected` varchar(255) NOT NULL,
// `active` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
// PRIMARY KEY (`id`)
// ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
// ');
/* items lang configuration */
// $res &= Db::getInstance()->execute('
// CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'boixmenugarancia_items_lang` (
// `id` int(10) unsigned NOT NULL,
// `id_lang` int(10) unsigned NOT NULL,
// `titre` varchar(255) NOT NULL,
// PRIMARY KEY (`id`,`id_lang`)
// ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
// ');
return true;
return $res;
}
/**
* deletes tables
*/
protected function deleteTables()
{
// $items = $this->getitems();
// foreach ($items as $item)
// {
// $to_del = new Boixgarancia($item['id_item']);
// $to_del->delete();
// }
// return Db::getInstance()->execute('
// DROP TABLE IF EXISTS `'._DB_PREFIX_.'boixmenugarancia`, `'._DB_PREFIX_.'boixmenugarancia_items`, `'._DB_PREFIX_.'boixmenugarancia_items_lang`;
// ');
return true;
}
public function getContent()
{
$this->_html .= $this->headerHTML();
$this->_html .= '<h2>'.$this->displayName.'</h2>';
/* Validate & process */
if (Tools::isSubmit('submititem') || Tools::isSubmit('delete_id_item') ||
Tools::isSubmit('submititemr') ||
Tools::isSubmit('changeStatus'))
{
if ($this->_postValidation())
$this->_postProcess();
$this->_displayForm();
}
elseif (Tools::isSubmit('additem') || (Tools::isSubmit('id_item') && $this->itemExists((int)Tools::getValue('id_item'))))
$this->_displayAddForm();
else
$this->_displayForm();
return $this->_html;
}
private function _displayForm()
{
/* Gets items */
$items = $this->getitems();
$this->_html .= '<br /><br />';
/* Begin fieldset items */
$this->_html .= '
<fieldset>
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Liste des items').'</legend>
<strong>
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&additem">
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter un item').'
</a>
</strong>';
/* Display notice if there are no items yet */
if (!$items)
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Aucun item créé').'</p>';
else /* Display items */
{
$this->_html .= '
<div id="itemsContent" style="width: 720px; margin-top: 30px;">
<div style="width:350px;float:left;">
<b>Nos gammes et produits</b>
<br/>&nbsp;
<ul id="items">';
foreach ($items as $item)
{
if($item['colonne']==1)
$this->_html .= '
<li id="items_'.$item['id_item'].'">
<strong>'.$item['titre'].'</strong>
<p style="float: right">'.
$this->displayStatus($item['id_item'], $item['active']).'
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_item='.(int)($item['id_item']).'" 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_item='.(int)($item['id_item']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
</p>
<div style="clear:both"></div>
</li>';
}
$this->_html .= '</ul>
<br/>
</div>
<div style="width:350px;float:right">
<b>Vos besoins</b>
<br/>&nbsp;
<ul id="items2">';
foreach ($items as $item)
{
if($item['colonne']==2)
$this->_html .= '
<li id="items_'.$item['id_item'].'">
<strong>'.$item['titre'].'</strong>
<p style="float: right">
'.
$this->displayStatus($item['id_item'], $item['active']).'
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_item='.(int)($item['id_item']).'" 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_item='.(int)($item['id_item']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
</p>
<div style="clear:both"></div>
</li>';
}
$this->_html .= '</ul></div>';
}
// End fieldset
$this->_html .= '</fieldset>';
}
private function _displayAddForm()
{
/* Sets item : depends if edited or added */
$item = null;
if (Tools::isSubmit('id_item') && $this->itemExists((int)Tools::getValue('id_item')))
$item = new Boixgarancia((int)Tools::getValue('id_item'));
/* 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 = 'titre';
$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" onsubmit="return checkIdSelected()">';
/* Fieldset edit/add */
$this->_html .= '<fieldset class="width3">';
if (Tools::isSubmit('additem')) /* Configure legend */
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter un lien').'</legend>';
elseif (Tools::isSubmit('id_item')) /* Edit legend */
$this->_html .= '<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Modifier un lien').'</legend>';
/* Sets id item as hidden */
if ($item && Tools::getValue('id_item'))
$this->_html .= '<input type="hidden" name="id_item" value="'.$item->id.'" id="id_item" />';
/* Sets position as hidden */
$this->_html .= '<input type="hidden" name="position" value="'.(($item != null) ? ($item->position) : ($this->getNextPosition())).'" id="position" />';
$this->_html .= '<input type="hidden" name="id_selected" value="'.($item->id_selected != null ? $item->id_selected : '').'" id="id_selected" />';
/* Form content */
/* Title */
$this->_html .= '<br />';
$this->_html .= '
<label for="colonne_1">'.$this->l('Colonne :').'</label>
<div class="margin-form">
<img src="../img/admin/enabled.gif" alt="Nos gammes et produits" title="Nos gammes et produits" />
<input type="radio" name="colonne" id="colonne_1" '.(($item && (isset($item->colonne) && (int)$item->colonne == 1)) ? 'checked="checked" ' : '').' value="1" />
<label class="t" for="colonne_1">'.$this->l('Nos gammes et produits').'</label>
<input type="radio" name="colonne" id="colonne_2" '.(($item && (isset($item->colonne) && (int)$item->colonne == 2)) ? 'checked="checked" ' : '').' value="2" />
<label class="t" for="colonne_2">'.$this->l('Vos besoins').'</label>
</div>';
$blockCategTree= Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT distinct(p.`id_product`), pl.`name`, cl.`name` AS category_name
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_product` = p.`id_product`
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = 1)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = 1)
where cl.id_category!=12
and cl.id_category!=13
and cl.id_category!=14
and cl.id_category!=15
and cl.id_category!=16
and cl.id_category!=17
ORDER BY pl.name asc'
);
$fiches_categories= Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT distinct(cl.`id_category`), cl.`name`
FROM `'._DB_PREFIX_.'category_lang` cl
where cl.`id_lang` = 1
and cl.id_category!=12
and cl.id_category!=13
and cl.id_category!=1
and cl.id_category!=2
and cl.id_category!=14
and cl.id_category!=15
and cl.id_category!=16
and cl.id_category!=17
ORDER BY cl.name asc'
);
// $categories=
// $cms=
$this->_html .= '
<label for="colonne_1">'.$this->l('Type de lien :').'</label>
<div class="margin-form">
<select id="type" name="type" onchange="javascript:changeFiche(this.value)">
<option value="">Etape 1 : Choisissez un type de lien</option>
<option value="fiche_produit" '.(($item && (isset($item->type) && $item->type == 'fiche_produit')) ? 'selected="selected" ' : '').'>Fiche produit</option>
<option value="fiche_categorie" '.(($item && (isset($item->type) && $item->type == 'fiche_categorie')) ? 'selected="selected" ' : '').'>Gamme ou Catégorie</option>
</select>
</div>';
$cate_default="";
$this->_html .= '
<div id="fiche_produit" class="fiches '.(($item && (isset($item->type) && $item->type == 'fiche_produit')) ? '' : 'hide').'">
<label for="colonne_1">'.$this->l('Fiche produit :').'</label>
<div class="margin-form">
<select name="fiche_produit">
<option value="">Etape 2 : Choisissez une fiche produit</option>';
foreach ($blockCategTree AS $rows){
$this->_html .='<option value="'.$rows['id_product'].'" '.(($item && (isset($item->type) && $item->type == 'fiche_produit' && (int)$item->id_selected == $rows['id_product'])) ? 'selected="selected" ' : '').'>'.$rows['name'].'</option>';
}
$this->_html .= '
</select>
</div>
</div>
';
$this->_html .= '
<div id="fiche_categorie" class="fiches '.(($item && (isset($item->type) && $item->type == 'fiche_categorie')) ? '' : 'hide').'">
<label for="colonne_1">'.$this->l('Gamme ou Catégorie :').'</label>
<div class="margin-form">
<select name="fiche_categorie">
<option value="">Etape 2 : Choisissez une gamme ou une catégorie</option>';
foreach ($fiches_categories AS $rows){
$this->_html .='<option value="'.$rows['id_category'].'" '.(($item && (isset($item->type) && $item->type == 'fiche_categorie' && (int)$item->id_selected == $rows['id_category'])) ? 'selected="selected" ' : '').'>'.$rows['name'].'</option>';
}
// </optgroup>
$this->_html .= '
</select>
</div>
</div>
';
$this->_html .= '<br /><label>'.$this->l('Titre du lien * (optionnel) :').'</label><div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '
<div id="titre_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
<input type="text" name="titre_'.$language['id_lang'].'" id="titre_'.$language['id_lang'].'" size="30" value="'.(isset($item->titre[$language['id_lang']]) ? $item->titre[$language['id_lang']] : '').'"/>
</div>';
}
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'titre', true);
$this->_html .= '<br style="clear:both" /><i>* Si vous laissez vide, le nom "complet" du produit sera affiché<br /></div>';
/* 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_item" id="active_on" '.(($item && (isset($item->active) && (int)$item->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_item" id="active_off" '.(($item && (isset($item->active) && (int)$item->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="submititem" 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 recquis').'</p>
</fieldset>
</form>';
}
private function _postValidation()
{
$errors = array();
/* Validation for itemr configuration */
if (Tools::isSubmit('submititemr'))
{
if (!Validate::isInt(Tools::getValue('boixmenugarancia_SPEED')) || !Validate::isInt(Tools::getValue('boixmenugarancia_PAUSE')) ||
!Validate::isInt(Tools::getValue('boixmenugarancia_WIDTH')) || !Validate::isInt(Tools::getValue('boixmenugarancia_HEIGHT')))
$errors[] = $this->l('Invalid values');
} /* Validation for status */
elseif (Tools::isSubmit('changeStatus'))
{
if (!Validate::isInt(Tools::getValue('id_item')))
$errors[] = $this->l('Invalid item');
}
/* Validation for item */
elseif (Tools::isSubmit('submititem'))
{
/* Checks state (active) */
if (!Validate::isInt(Tools::getValue('active_item')) || (Tools::getValue('active_item') != 0 && Tools::getValue('active_item') != 1))
$errors[] = $this->l('Invalid item state');
/* Checks position */
if (!Validate::isInt(Tools::getValue('position')) || (Tools::getValue('position') < 0))
$errors[] = $this->l('Invalid item position');
/* If edit : checks id_item */
if (Tools::isSubmit('id_item'))
{
if (!Validate::isInt(Tools::getValue('id_item')) && !$this->itemExists(Tools::getValue('id_item')))
$errors[] = $this->l('Invalid id_item');
}
/* Checks title/url/legend/description/image */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
if (Tools::strlen(Tools::getValue('titre_'.$language['id_lang'])) > 255)
$errors[] = $this->l('Le titre est trop long');
}
/* Checks title/url/legend/description for default lang */
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
if (Tools::strlen(Tools::getValue('titre_'.$id_lang_default)) == 0)
$errors[] = $this->l('Le titre est vide.');
} /* Validation for deletion */
elseif (Tools::isSubmit('delete_id_item') && (!Validate::isInt(Tools::getValue('delete_id_item')) || !$this->itemExists((int)Tools::getValue('delete_id_item'))))
$errors[] = $this->l('Invalid id_item');
/* 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();
/* Processes itemr */
if (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_item'))
{
$item = new Boixgarancia((int)Tools::getValue('id_item'));
if ($item->active == 0)
$item->active = 1;
else
$item->active = 0;
$res = $item->update();
$this->clearCache();
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
}
/* Processes item */
elseif (Tools::isSubmit('submititem'))
{
/* Sets ID if needed */
if (Tools::getValue('id_item'))
{
$item = new Boixgarancia((int)Tools::getValue('id_item'));
if (!Validate::isLoadedObject($item))
{
$this->_html .= $this->displayError($this->l('Invalid id_item'));
return;
}
}
else
$item = new Boixgarancia();
/* Sets position */
$item->position = (int)Tools::getValue('position');
/* Sets active */
$item->active = (int)Tools::getValue('active_item');
/* Sets each langue fields */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
$item->titre[$language['id_lang']] = Tools::getValue('titre_'.$language['id_lang']);
$item->type = Tools::getValue('type');
$colonne=(int)Tools::getValue('colonne');
if($colonne==0 || $colonne=="")
$colonne=1;
$item->colonne = $colonne;
$item->id_selected = Tools::getValue('id_selected');
}
/* Processes if no errors */
if (!$errors)
{
/* Adds */
if (!Tools::getValue('id_item'))
{
if (!$item->add())
$errors[] = $this->displayError($this->l('The item could not be added.'));
}
/* Update */
elseif (!$item->update())
$errors[] = $this->displayError($this->l('The item could not be updated.'));
$this->clearCache();
}
} /* Deletes */
elseif (Tools::isSubmit('delete_id_item'))
{
$item = new Boixgarancia((int)Tools::getValue('delete_id_item'));
$res = $item->delete();
$this->clearCache();
if (!$res)
$this->_html .= $this->displayError('Could not delete');
else
$this->_html .= $this->displayConfirmation($this->l('item deleted'));
}
/* Display errors if needed */
if (count($errors))
$this->_html .= $this->displayError(implode('<br />', $errors));
elseif (Tools::isSubmit('submititem') && Tools::getValue('id_item'))
$this->_html .= $this->displayConfirmation($this->l('item updated'));
elseif (Tools::isSubmit('submititem'))
$this->_html .= $this->displayConfirmation($this->l('item added'));
}
public function hookDisplayTop()
{
// if($_SERVER["REMOTE_ADDR"]== "81.242.138.126"){
// $items = $this->getitems();
// $this->smarty->assign("menu_garancia",$items);
// }
}
public function clearCache()
{
}
public function hookActionShopDataDuplication($params)
{
Db::getInstance()->execute('
INSERT IGNORE INTO '._DB_PREFIX_.'boixmenugarancia (id, id_shop)
SELECT id, '.(int)$params['new_id_shop'].'
FROM '._DB_PREFIX_.'boixmenugarancia
WHERE id_shop = '.(int)$params['old_id_shop']);
}
public function headerHTML()
{
if (Tools::getValue('controller') != 'AdminModules' && Tools::getValue('configure') != $this->name)
return;
// $this->context->controller->addJqueryUI('ui.datepicker');
/*$this->_html .= '
<script type="text/javascript">
// $(document).ready(function() {
// if ($("#datepicker").length > 0)
// $("#datepicker").datepicker({
// prevText: "",
// nextText: "",
// dateFormat: "yy-mm-dd"
// });
// });
</script>';*/
$this->_html .= '
<script type="text/javascript">
var iso = \''.(file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en').'\' ;
var pathCSS = \''._THEME_CSS_DIR_.'\' ;
var ad = \''.dirname($_SERVER['PHP_SELF']).'\' ;
</script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce.inc.js"></script>
<script language="javascript" type="text/javascript">
id_language = Number('.(int)$this->context->language->id.');
tinySetup();
function changeFiche(id){
$(".fiches").hide();
$("#"+id).show();
}
function checkIdSelected(){
var type=$("#type").val();
var titre=$("#"+type+" option:selected").html();
var id_selected=$("#"+type+" select").val();
$("#id_selected").attr("value",id_selected);
var titre_personnalised_1=$("input#titre_1").val();
var titre_personnalised_2=$("input#titre_2").val();
if(titre_personnalised_1=="")
$("input#titre_1").attr("value",titre);
if(titre_personnalised_2=="")
$("input#titre_2").attr("value",titre);
return true;
}
$(document).ready(function() {
$(".fiches.hide").hide();
$(".thickbox").fancybox();
});
</script> ';
$this->context->controller->addJqueryUI('ui.sortable');
/* Style & js for fieldset 'slides configuration' */
$html = '
<style>
#items2 li,
#items 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">
$(function() {
var $mySlides = $("#items");
$mySlides.sortable({
opacity: 0.6,
cursor: "move",
update: function() {
var order = $(this).sortable("serialize") + "&action=updateSlidesPosition";
$.post("'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax_'.$this->name.'.php?secure_key='.$this->secure_key.'", order);
}
});
$mySlides.hover(function() {
$(this).css("cursor","move");
},
function() {
$(this).css("cursor","auto");
});
var $mySlides2 = $("#items2");
$mySlides2.sortable({
opacity: 0.6,
cursor: "move",
update: function() {
var order = $(this).sortable("serialize") + "&action=updateSlidesPosition";
$.post("'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax_'.$this->name.'.php?secure_key='.$this->secure_key.'", order);
}
});
$mySlides2.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_.'boixmenugarancia_items` hss, `'._DB_PREFIX_.'boixmenugarancia` hs
WHERE hss.`id` = hs.`id` AND hs.`id_shop` = '.(int)$this->context->shop->id
);
return (++$row['next_position']);
}
public function getitems($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` as id_item,
hss.`position`,
hss.`active`,
hssl.`titre`,
hss.`type`,
hss.`id_selected`,
hss.`colonne`
FROM '._DB_PREFIX_.'boixmenugarancia hs
LEFT JOIN '._DB_PREFIX_.'boixmenugarancia_items hss ON (hs.id = hss.id)
LEFT JOIN '._DB_PREFIX_.'boixmenugarancia_items_lang hssl ON (hss.id = hssl.id)
WHERE hssl.id_lang = '.(int)$id_lang.
($active ? ' AND hss.`active` = 1' : ' ').'
ORDER BY colonne asc, hss.position asc');
}
public function displayStatus($id_item, $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_item='.(int)$id_item.'" title="'.$title.'"><img src="'._PS_ADMIN_IMG_.''.$img.'" alt="" /></a>';
return $html;
}
public function itemExists($id_item)
{
$req = 'SELECT hs.`id` as id_item
FROM `'._DB_PREFIX_.'boixmenugarancia` hs
WHERE hs.`id` = '.(int)$id_item;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
return ($row);
}
}