1161 lines
48 KiB
PHP
1161 lines
48 KiB
PHP
|
<?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_.'devspelivredor/livredorItem.php');
|
||
|
include_once(_PS_MODULE_DIR_.'devspelivredor/livredorTheme.php');
|
||
|
|
||
|
class devspeLivredor extends Module
|
||
|
{
|
||
|
private $_html = '';
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->name = 'devspelivredor';
|
||
|
|
||
|
$this->version = '1';
|
||
|
$this->need_instance = 0;
|
||
|
$this->secure_key = Tools::encrypt($this->name);
|
||
|
|
||
|
parent::__construct();
|
||
|
|
||
|
$this->displayName = $this->l('Gestion de la livre d\'or');
|
||
|
$this->description = $this->l('Administrer la livre d\'or');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @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('devspelivredor_WIDTH');
|
||
|
// $res &= Configuration::deleteByName('devspelivredor_HEIGHT');
|
||
|
// $res &= Configuration::deleteByName('devspelivredor_SPEED');
|
||
|
// $res &= Configuration::deleteByName('devspelivredor_PAUSE');
|
||
|
// $res &= Configuration::deleteByName('devspelivredor_LOOP');
|
||
|
return $res;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates tables
|
||
|
*/
|
||
|
protected function createTables()
|
||
|
{
|
||
|
/* livredors */
|
||
|
$res = (bool)Db::getInstance()->execute('
|
||
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspelivredor` (
|
||
|
`id_livredor_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||
|
`id_shop` int(10) unsigned NOT NULL,
|
||
|
PRIMARY KEY (`id_livredor_item`, `id_shop`)
|
||
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
||
|
');
|
||
|
|
||
|
/* livredors configuration */
|
||
|
$res &= Db::getInstance()->execute('
|
||
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspelivredor_item` (
|
||
|
`id_livredor_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\',
|
||
|
`age` int(11) unsigned NOT NULL DEFAULT \'0\',
|
||
|
`note` int(11) unsigned NOT NULL DEFAULT \'0\',
|
||
|
`active` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
||
|
`en_avant` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
||
|
PRIMARY KEY (`id_livredor_item`)
|
||
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
||
|
');
|
||
|
|
||
|
/* livredors lang configuration */
|
||
|
$res &= Db::getInstance()->execute('
|
||
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspelivredor_item_lang` (
|
||
|
`id_livredor_item` int(10) unsigned NOT NULL,
|
||
|
`id_lang` int(10) unsigned NOT NULL,
|
||
|
`prenom` varchar(255) NOT NULL,
|
||
|
`nom` varchar(255) NOT NULL,
|
||
|
`departement` varchar(255) NOT NULL,
|
||
|
`ville` varchar(255) NOT NULL,
|
||
|
`titre` varchar(255) NOT NULL,
|
||
|
`phrase` text NOT NULL,
|
||
|
|
||
|
PRIMARY KEY (`id_livredor_item`,`id_lang`)
|
||
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
||
|
');
|
||
|
/* livredors configuration */
|
||
|
$res &= Db::getInstance()->execute('
|
||
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspelivredor_theme` (
|
||
|
`id_livredor_theme` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||
|
`id_livredor_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_livredor_theme`)
|
||
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
||
|
');
|
||
|
|
||
|
/* livredors lang configuration */
|
||
|
$res &= Db::getInstance()->execute('
|
||
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspelivredor_theme_lang` (
|
||
|
`id_livredor_theme` int(10) unsigned NOT NULL,
|
||
|
`id_lang` int(10) unsigned NOT NULL,
|
||
|
`title` varchar(255) NOT NULL,
|
||
|
|
||
|
PRIMARY KEY (`id_livredor_theme`,`id_lang`)
|
||
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
||
|
');
|
||
|
|
||
|
return $res;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* deletes tables
|
||
|
*/
|
||
|
protected function deleteTables()
|
||
|
{
|
||
|
$livredors = $this->getItemslivredor();
|
||
|
foreach ($livredors as $livredor)
|
||
|
{
|
||
|
$to_del = new livredorItem($livredor['id_livredor']);
|
||
|
$to_del->delete();
|
||
|
}
|
||
|
return Db::getInstance()->execute('
|
||
|
DROP TABLE IF EXISTS `'._DB_PREFIX_.'devspelivredor`,
|
||
|
`'._DB_PREFIX_.'devspelivredor_item`,
|
||
|
`'._DB_PREFIX_.'devspelivredor_item_lang`,
|
||
|
`'._DB_PREFIX_.'devspelivredor_theme`,
|
||
|
`'._DB_PREFIX_.'devspelivredor_theme_lang`;
|
||
|
');
|
||
|
}
|
||
|
|
||
|
public function getContent()
|
||
|
{
|
||
|
$this->_html .= $this->headerHTML();
|
||
|
$this->_html .= '<h2>'.$this->displayName.'.</h2>';
|
||
|
|
||
|
/* Validate & process */
|
||
|
if (Tools::isSubmit('submitlivredor') || Tools::isSubmit('delete_id_livredor') ||
|
||
|
Tools::isSubmit('submittheme') || Tools::isSubmit('delete_id_theme') ||
|
||
|
Tools::isSubmit('changeStatus') ||
|
||
|
Tools::isSubmit('changeStatusEnavant'))
|
||
|
{
|
||
|
if ($this->_postValidation())
|
||
|
$this->_postProcess();
|
||
|
$this->_displayForm();
|
||
|
}
|
||
|
elseif (Tools::isSubmit('addlivredor') || (Tools::isSubmit('id_livredor') && $this->livredorExists((int)Tools::getValue('id_livredor'))))
|
||
|
$this->_displayAddItemForm();
|
||
|
elseif (Tools::isSubmit('addtheme') || (Tools::isSubmit('id_theme') && $this->livredorThemeExists((int)Tools::getValue('id_theme'))))
|
||
|
$this->_displayAddThemeForm();
|
||
|
else
|
||
|
$this->_displayForm();
|
||
|
|
||
|
return $this->_html;
|
||
|
}
|
||
|
|
||
|
private function _displayForm()
|
||
|
{
|
||
|
/* THEME livredor */
|
||
|
|
||
|
$livredors = $this->getItemsTheme();
|
||
|
|
||
|
$this->_html .= '<br /><br />';
|
||
|
|
||
|
/* Begin fieldset livredors */
|
||
|
$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 livredors yet */
|
||
|
if (!$livredors)
|
||
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Aucun thème créé').'</p>';
|
||
|
else /* Display livredors */
|
||
|
{
|
||
|
$this->_html .= '
|
||
|
<div id="livredorsContent" style="width: 700px; margin-top: 30px;">
|
||
|
<ul id="themes">';
|
||
|
foreach ($livredors as $livredor)
|
||
|
{
|
||
|
$this->_html .= '
|
||
|
<li id="livredors_'.$livredor['id_theme'].'">';
|
||
|
if($livredor['id_livredor_parent']==0)
|
||
|
$this->_html .= '<strong>Thème '.$livredor['id_theme'].'</strong> : '.$livredor['title']."";
|
||
|
else
|
||
|
$this->_html .= '<i>Thème '.$livredor['id_livredor_parent'].'</i> > <strong>Thème '.$livredor['id_theme'].'</strong> : '.$livredor['title'];
|
||
|
|
||
|
$this->_html .= '
|
||
|
<p style="float: right;margin:0;">'.
|
||
|
$this->displayStatus($livredor['id_theme'], $livredor['active']).'
|
||
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_theme='.(int)($livredor['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)($livredor['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 livredor */
|
||
|
|
||
|
/* Gets livredors */
|
||
|
$livredors = $this->getItemslivredor();
|
||
|
|
||
|
$this->_html .= '<br /><br />';
|
||
|
|
||
|
/* Begin fieldset livredors */
|
||
|
$this->_html .= '
|
||
|
<fieldset>
|
||
|
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Gestion des messages du livre d\'or').'</legend>
|
||
|
<strong>
|
||
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addlivredor">
|
||
|
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter un message').'
|
||
|
</a>
|
||
|
</strong>';
|
||
|
|
||
|
/* Display notice if there are no livredors yet */
|
||
|
if (!$livredors)
|
||
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Aucun message créé').'</p>';
|
||
|
else /* Display livredors */
|
||
|
{
|
||
|
$this->_html .= '
|
||
|
<div id="livredorsContent" style="width: 700px; margin-top: 30px;">
|
||
|
<ul id="livredors">';
|
||
|
foreach ($livredors as $livredor)
|
||
|
{
|
||
|
$this->_html .= '
|
||
|
<li id="livredors_'.$livredor['id_livredor'].'">
|
||
|
<strong>Thème '.$livredor['id_theme'].'</strong> : '.$livredor['titre'].' - '.$livredor['prenom'].' '.$livredor['nom'].' - Note : '.$livredor['note'].'
|
||
|
<p style="float: right;margin:0;">'.
|
||
|
$this->displayStatus($livredor['id_livredor'], $livredor['active']).
|
||
|
$this->displayStatusEnavant($livredor['id_livredor'], $livredor['en_avant']).'
|
||
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_livredor='.(int)($livredor['id_livredor']).'" 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_livredor='.(int)($livredor['id_livredor']).'" 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 livredor : depends if edited or added */
|
||
|
$livredor = null;
|
||
|
if (Tools::isSubmit('id_livredor') && $this->livredorExists((int)Tools::getValue('id_livredor')))
|
||
|
$livredor = new livredorItem((int)Tools::getValue('id_livredor'));
|
||
|
/* 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 = 'ville¤titre¤nom¤prenom¤departement¤phrase';
|
||
|
|
||
|
$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($livredor->image[$language['id_lang']]) ? $livredor->image[$language['id_lang']] : '').'"/>';
|
||
|
// /* Sets image as hidden in case it does not change */
|
||
|
// if ($livredor && $livredor->image[$language['id_lang']])
|
||
|
// $this->_html .= '<input type="hidden" name="image_old_'.$language['id_lang'].'" value="'.($livredor->image[$language['id_lang']]).'" id="image_old_'.$language['id_lang'].'" />';
|
||
|
// /* Display image */
|
||
|
// if ($livredor && $livredor->image[$language['id_lang']])
|
||
|
// $this->_html .= '<input type="hidden" name="has_picture" value="1" /><img src="'.__PS_BASE_URI__.'modules/'.$this->name.'/images/'.$livredor->image[$language['id_lang']].'" width="'.(Configuration::get('devspelivredor_WIDTH')/2).'" height="'.(Configuration::get('devspelivredor_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('addlivredor')) /* Configure legend */
|
||
|
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> 1 - '.$this->l('Ajouter un message dans le livre d\'or').'</legend>';
|
||
|
elseif (Tools::isSubmit('id_livredor')) /* Edit legend */
|
||
|
$this->_html .= '<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" />1 - '.$this->l('Modifier le message').'</legend>';
|
||
|
|
||
|
$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'].'" '.($livredor->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 />';
|
||
|
|
||
|
|
||
|
/* titre */
|
||
|
$this->_html .= '<label>'.$this->l('Note :').' * </label><div class="margin-form">';
|
||
|
$this->_html .= '
|
||
|
<div style="display:float: left;">
|
||
|
<span style="font-size:15px;color:#585A69;padding:0.2em 0 0;">
|
||
|
<input type="radio" name="note" value="1" '.(isset($livredor->note) && $livredor->note==1 ? 'checked="checked"' : '').'><sup style="vertical-align:middle;font-size:15px;color:#585A69;padding:0.2em 10px 0 4px;;font-weight:normal">1</sup>
|
||
|
<input type="radio" name="note" value="2" '.(isset($livredor->note) && $livredor->note==2 ? 'checked="checked"' : '').'><sup style="vertical-align:middle;font-size:15px;color:#585A69;padding:0.2em 10px 0 4px;;font-weight:normal">2</sup>
|
||
|
<input type="radio" name="note" value="3" '.(isset($livredor->note) && $livredor->note==3 ? 'checked="checked"' : '').'><sup style="vertical-align:middle;font-size:15px;color:#585A69;padding:0.2em 10px 0 4px;;font-weight:normal">3</sup>
|
||
|
<input type="radio" name="note" value="4" '.(isset($livredor->note) && $livredor->note==4 ? 'checked="checked"' : '').'><sup style="vertical-align:middle;font-size:15px;color:#585A69;padding:0.2em 10px 0 4px;;font-weight:normal">4</sup>
|
||
|
<input type="radio" name="note" value="5" '.(isset($livredor->note) && $livredor->note==5 ? 'checked="checked"' : '').'><sup style="vertical-align:middle;font-size:15px;color:#585A69;padding:0.2em 10px 0 4px;font-weight:normal">5</sup>
|
||
|
|
||
|
</span>
|
||
|
</div>';
|
||
|
$this->_html .= '</div><br /><br />';
|
||
|
|
||
|
/* titre */
|
||
|
$this->_html .= '<label>'.$this->l('Titre (ex: "GENIAL") :').' * </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="80" value="'.(isset($livredor->titre[$language['id_lang']]) ? $livredor->titre[$language['id_lang']] : '').'"/>
|
||
|
</div>';
|
||
|
}
|
||
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'titre', true);
|
||
|
$this->_html .= '</div><br /><br />';
|
||
|
|
||
|
|
||
|
/* phrase */
|
||
|
$this->_html .= '
|
||
|
<label>'.$this->l('Phrase :').' * </label>
|
||
|
<div class="margin-form">';
|
||
|
foreach ($languages as $language)
|
||
|
{
|
||
|
$this->_html .= '<div id="phrase_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
||
|
<textarea name="phrase_'.$language['id_lang'].'" rows="8" cols="77" style="padding:2px 3px">'.(isset($livredor->phrase[$language['id_lang']]) ? $livredor->phrase[$language['id_lang']] : '').'</textarea>
|
||
|
</div>';
|
||
|
}
|
||
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'phrase', true);
|
||
|
$this->_html .= '</div><div class="clear"></div><br />';
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
$this->_html .= '</fieldset>';
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/* Form content */
|
||
|
|
||
|
|
||
|
/* Form content */
|
||
|
|
||
|
$this->_html .= '<br/><br/><fieldset class="width3" style="width:900px">';
|
||
|
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> 2 - '.$this->l('Informations personnelles').'</legend>';
|
||
|
|
||
|
/* Sets id livredor as hidden */
|
||
|
if ($livredor && Tools::getValue('id_livredor'))
|
||
|
$this->_html .= '<input type="hidden" name="id_livredor" value="'.$livredor->id.'" id="id_livredor" />';
|
||
|
/* Sets position as hidden */
|
||
|
$this->_html .= '<input type="hidden" name="position" value="'.(($livredor != null) ? ($livredor->position) : ($this->getNextPosition())).'" id="position" />';
|
||
|
|
||
|
|
||
|
/* Prenom */
|
||
|
$this->_html .= '<label>'.$this->l('Prénom :').' * </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="prenom_'.$language['id_lang'].'" id="prenom_'.$language['id_lang'].'" size="80" value="'.(isset($livredor->prenom[$language['id_lang']]) ? $livredor->prenom[$language['id_lang']] : '').'"/>
|
||
|
</div>';
|
||
|
}
|
||
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'prenom', true);
|
||
|
$this->_html .= '</div><br /><br />';
|
||
|
|
||
|
/* nom */
|
||
|
$this->_html .= '<label>'.$this->l('Nom :').' * </label><div class="margin-form">';
|
||
|
foreach ($languages as $language)
|
||
|
{
|
||
|
$this->_html .= '
|
||
|
<div id="nom_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
||
|
<input type="text" name="nom_'.$language['id_lang'].'" id="nom_'.$language['id_lang'].'" size="80" value="'.(isset($livredor->nom[$language['id_lang']]) ? $livredor->nom[$language['id_lang']] : '').'"/>
|
||
|
</div>';
|
||
|
}
|
||
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'nom', true);
|
||
|
$this->_html .= '</div><br /><br />';
|
||
|
|
||
|
/* Age */
|
||
|
$this->_html .= '<label>'.$this->l('Age :').' * </label><div class="margin-form">';
|
||
|
$this->_html .= '
|
||
|
<div style="float: left;">
|
||
|
<input type="text" name="age" id="age" size="80" value="'.($livredor && isset($livredor->age) ? $livredor->age : '').'"/>
|
||
|
</div>';
|
||
|
$this->_html .= '</div><br /><br />';
|
||
|
|
||
|
/* Département */
|
||
|
$this->_html .= '<label>'.$this->l('Département :').' * </label><div class="margin-form">';
|
||
|
foreach ($languages as $language)
|
||
|
{
|
||
|
$this->_html .= '
|
||
|
<div id="age_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
||
|
<input type="text" name="departement_'.$language['id_lang'].'" id="departement_'.$language['id_lang'].'" size="80" value="'.(isset($livredor->departement[$language['id_lang']]) ? $livredor->departement[$language['id_lang']] : '').'"/>
|
||
|
</div>';
|
||
|
}
|
||
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'departement', true);
|
||
|
$this->_html .= '</div><br /><br />';
|
||
|
|
||
|
/* ville */
|
||
|
$this->_html .= '<label>'.$this->l('Ville :').' * </label><div class="margin-form">';
|
||
|
foreach ($languages as $language)
|
||
|
{
|
||
|
$this->_html .= '
|
||
|
<div id="ville_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
||
|
<input type="text" name="ville_'.$language['id_lang'].'" id="ville_'.$language['id_lang'].'" size="80" value="'.(isset($livredor->ville[$language['id_lang']]) ? $livredor->ville[$language['id_lang']] : '').'"/>
|
||
|
</div>';
|
||
|
}
|
||
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'ville', true);
|
||
|
$this->_html .= '</div><br /><br />';
|
||
|
|
||
|
|
||
|
$this->_html .= '</fieldset>';
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/* Form content */
|
||
|
|
||
|
/* Form content */
|
||
|
|
||
|
$this->_html .= '<br/><br/><fieldset class="width3" style="width:900px">';
|
||
|
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> 3 - '.$this->l('Sauvegarder').'</legend>';
|
||
|
|
||
|
/* Active */
|
||
|
$this->_html .= '
|
||
|
<label for="active_on">'.$this->l('Actif :').'</label>
|
||
|
<div class="margin-form">
|
||
|
<img src="../img/admin/enabled.gif" alt="Yes" title="Yes" />
|
||
|
<input type="radio" name="active_livredor" id="active_on" '.(($livredor && (isset($livredor->active) && (int)$livredor->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_livredor" id="active_off" '.(($livredor && (isset($livredor->active) && (int)$livredor->active == 0)) ? 'checked="checked" ' : '').' value="0" />
|
||
|
<label class="t" for="active_off">'.$this->l('No').'</label>
|
||
|
</div>';
|
||
|
/* Active */
|
||
|
$this->_html .= '
|
||
|
<label for="en_avant_on">'.$this->l('En avant :').'</label>
|
||
|
<div class="margin-form">
|
||
|
<img src="../img/admin/enabled.gif" alt="Yes" title="Yes" />
|
||
|
<input type="radio" name="en_avant_livredor" id="en_avant_on" '.(($livredor && (isset($livredor->en_avant) && (int)$livredor->en_avant == 0)) ? '' : 'checked="checked" ').' value="1" />
|
||
|
<label class="t" for="en_avant_on">'.$this->l('Yes').'</label>
|
||
|
<img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" />
|
||
|
<input type="radio" name="en_avant_livredor" id="en_avant_off" '.(($livredor && (isset($livredor->en_avant) && (int)$livredor->en_avant == 0)) ? 'checked="checked" ' : '').' value="0" />
|
||
|
<label class="t" for="en_avant_off">'.$this->l('No').'</label>
|
||
|
</div>';
|
||
|
|
||
|
/* Save */
|
||
|
$this->_html .= '
|
||
|
<p style="padding-left:260px">
|
||
|
<input type="submit" class="button" name="submitlivredor" 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 livredor : depends if edited or added */
|
||
|
$livredor = null;
|
||
|
if (Tools::isSubmit('id_theme') && $this->livredorThemeExists((int)Tools::getValue('id_theme')))
|
||
|
$livredor = new livredorTheme((int)Tools::getValue('id_theme'));
|
||
|
// print_r($livredor);
|
||
|
/* 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 livredor as hidden */
|
||
|
$id_livredor=0;
|
||
|
if ($livredor && Tools::getValue('id_theme')){
|
||
|
$id_livredor=$livredor->id;
|
||
|
$this->_html .= '<input type="hidden" name="id_theme" value="'.$livredor->id.'" id="id_theme" />';
|
||
|
}
|
||
|
/* Sets position as hidden */
|
||
|
$this->_html .= '<input type="hidden" name="position" value="'.(($livredor != null) ? ($livredor->position) : ($this->getNextPositionTheme())).'" id="position" />';
|
||
|
|
||
|
/* Form content */
|
||
|
|
||
|
$themes=$this->getItemsTheme(null,true);
|
||
|
// print_r($themes);
|
||
|
$les_themes='<select name="id_livredor_parent" id="id_livredor_parent" style="width:230px"><option value="0"> Aucun </option>';
|
||
|
foreach($themes as $row){
|
||
|
if($row['id_theme']!=$livredor->id)
|
||
|
$les_themes.='<option value="'.$row['id_theme'].'" '.($id_livredor==$row['id_theme']?'selected="selected"':'').'>Thème '.$row['id_theme'].' : '.$row['title'].'</option>';
|
||
|
}
|
||
|
$les_themes.='</select>';
|
||
|
|
||
|
/* theme parent */
|
||
|
$this->_html .= '<div style="display:none"><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 /></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($livredor->title[$language['id_lang']]) ? $livredor->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" '.(($livredor && (isset($livredor->active) && (int)$livredor->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" '.(($livredor && (isset($livredor->active) && (int)$livredor->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_livredor')))
|
||
|
$errors[] = $this->l('Invalid livredor');
|
||
|
}
|
||
|
/* Validation for livredor */
|
||
|
elseif (Tools::isSubmit('changeStatusEnavant'))
|
||
|
{
|
||
|
if (!Validate::isInt(Tools::getValue('id_livredor')))
|
||
|
$errors[] = $this->l('Invalid livredor');
|
||
|
}
|
||
|
/* Validation for livredor */
|
||
|
elseif (Tools::isSubmit('submitlivredor'))
|
||
|
{
|
||
|
/* Checks state (active) */
|
||
|
if (!Validate::isInt(Tools::getValue('active_livredor')) || (Tools::getValue('active_livredor') != 0 && Tools::getValue('active_livredor') != 1))
|
||
|
$errors[] = $this->l('Invalid "active" state');
|
||
|
if (!Validate::isInt(Tools::getValue('en_avant_livredor')) || (Tools::getValue('en_avant_livredor') != 0 && Tools::getValue('en_avant_livredor') != 1))
|
||
|
$errors[] = $this->l('Invalid "en avant" state');
|
||
|
/* Checks position */
|
||
|
if (!Validate::isInt(Tools::getValue('position')) || (Tools::getValue('position') < 0))
|
||
|
$errors[] = $this->l('Invalid livredor position');
|
||
|
/* If edit : checks id_livredor */
|
||
|
if (Tools::isSubmit('id_livredor'))
|
||
|
{
|
||
|
if (!Validate::isInt(Tools::getValue('id_livredor')) && !$this->livredorExists(Tools::getValue('id_livredor')))
|
||
|
$errors[] = $this->l('Invalid id_livredor');
|
||
|
}
|
||
|
/* Checks title/url/legend/phrase/image */
|
||
|
$languages = Language::getLanguages(false);
|
||
|
foreach ($languages as $language)
|
||
|
{
|
||
|
|
||
|
if (Tools::strlen(Tools::getValue('phrase_'.$language['id_lang'])) > 255)
|
||
|
$errors[] = $this->l('La phrase est trop longue');
|
||
|
// if (Tools::strlen(Tools::getValue('phrase_'.$language['id_lang'])) > 4000)
|
||
|
// $errors[] = $this->l('The phrase 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/phrase 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 obligatoire');
|
||
|
if (Tools::strlen(Tools::getValue('phrase_'.$id_lang_default)) == 0)
|
||
|
$errors[] = $this->l('La phrase obligatoire');
|
||
|
if (Tools::strlen(Tools::getValue('prenom_'.$id_lang_default)) == 0)
|
||
|
$errors[] = $this->l('Le prénom obligatoire');
|
||
|
if (Tools::strlen(Tools::getValue('nom_'.$id_lang_default)) == 0)
|
||
|
$errors[] = $this->l('Le nom obligatoire');
|
||
|
if (Tools::strlen(Tools::getValue('note')) == 0)
|
||
|
$errors[] = $this->l('La note 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_livredor') && (!Validate::isInt(Tools::getValue('delete_id_livredor')) || !$this->livredorExists((int)Tools::getValue('delete_id_livredor'))))
|
||
|
$errors[] = $this->l('Invalid id_livredor');
|
||
|
|
||
|
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->livredorExists(Tools::getValue('id_theme')))
|
||
|
$errors[] = $this->l('Invalid id_theme');
|
||
|
}
|
||
|
/* Checks title/url/legend/phrase/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('phrase_'.$language['id_lang'])) > 4000)
|
||
|
// $errors[] = $this->l('The phrase 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/phrase 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->livredorExists((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('changeStatusEnavant') && Tools::isSubmit('id_livredor'))
|
||
|
{
|
||
|
|
||
|
$livredor = new livredorItem((int)Tools::getValue('id_livredor'));
|
||
|
|
||
|
if ($livredor->en_avant == 0){
|
||
|
Db::getInstance()->execute('update '._DB_PREFIX_.'devspelivredor_item set en_avant=0');
|
||
|
$livredor->en_avant = 1;
|
||
|
}else
|
||
|
$livredor->en_avant = 0;
|
||
|
$res = $livredor->update();
|
||
|
$this->clearCache();
|
||
|
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
||
|
}
|
||
|
/* Processes livredor */
|
||
|
elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_livredor'))
|
||
|
{
|
||
|
$livredor = new livredorItem((int)Tools::getValue('id_livredor'));
|
||
|
if ($livredor->active == 0)
|
||
|
$livredor->active = 1;
|
||
|
else
|
||
|
$livredor->active = 0;
|
||
|
$res = $livredor->update();
|
||
|
$this->clearCache();
|
||
|
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
||
|
}
|
||
|
/* Processes livredor */
|
||
|
elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_theme'))
|
||
|
{
|
||
|
$livredor = new livredorTheme((int)Tools::getValue('id_theme'));
|
||
|
if ($livredor->active == 0)
|
||
|
$livredor->active = 1;
|
||
|
else
|
||
|
$livredor->active = 0;
|
||
|
$res = $livredor->update();
|
||
|
$this->clearCache();
|
||
|
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
||
|
}
|
||
|
/* Processes livredor */
|
||
|
elseif (Tools::isSubmit('submitlivredor'))
|
||
|
{
|
||
|
/* Sets ID if needed */
|
||
|
if (Tools::getValue('id_livredor'))
|
||
|
{
|
||
|
$livredor = new livredorItem((int)Tools::getValue('id_livredor'));
|
||
|
if (!Validate::isLoadedObject($livredor))
|
||
|
{
|
||
|
$this->_html .= $this->displayError($this->l('Invalid id_livredor'));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
$livredor = new livredorItem();
|
||
|
/* Sets position */
|
||
|
$livredor->position = (int)Tools::getValue('position');
|
||
|
$livredor->id_theme = (int)Tools::getValue('id_theme');
|
||
|
/* Sets active */
|
||
|
$livredor->active = (int)Tools::getValue('active_livredor');
|
||
|
$livredor->en_avant = (int)Tools::getValue('en_avant_livredor');
|
||
|
|
||
|
/* Sets each langue fields */
|
||
|
$languages = Language::getLanguages(false);
|
||
|
foreach ($languages as $language)
|
||
|
{
|
||
|
|
||
|
$livredor->prenom[$language['id_lang']] = Tools::getValue('prenom_'.$language['id_lang']);
|
||
|
$livredor->nom[$language['id_lang']] = Tools::getValue('nom_'.$language['id_lang']);
|
||
|
$livredor->departement[$language['id_lang']] = Tools::getValue('departement_'.$language['id_lang']);
|
||
|
$livredor->ville[$language['id_lang']] = Tools::getValue('ville_'.$language['id_lang']);
|
||
|
$livredor->titre[$language['id_lang']] = Tools::getValue('titre_'.$language['id_lang']);
|
||
|
$livredor->phrase[$language['id_lang']] = Tools::getValue('phrase_'.$language['id_lang']);
|
||
|
$livredor->note = Tools::getValue('note');
|
||
|
$livredor->age = Tools::getValue('age');
|
||
|
|
||
|
// /* Uploads image and sets livredor */
|
||
|
// $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);
|
||
|
// $livredor->image[$language['id_lang']] = Tools::encrypt($_FILES['image_'.($language['id_lang'])]['name'].$salt).'.'.$type;
|
||
|
// }
|
||
|
// elseif (Tools::getValue('image_old_'.$language['id_lang']) != '')
|
||
|
// $livredor->image[$language['id_lang']] = Tools::getValue('image_old_'.$language['id_lang']);
|
||
|
}
|
||
|
|
||
|
/* Processes if no errors */
|
||
|
if (!$errors)
|
||
|
{
|
||
|
/* Adds */
|
||
|
if($livredor->en_avant==1)
|
||
|
Db::getInstance()->execute('update '._DB_PREFIX_.'devspelivredor_item set en_avant=0');
|
||
|
|
||
|
if (!Tools::getValue('id_livredor'))
|
||
|
{
|
||
|
if (!$livredor->add())
|
||
|
$errors[] = $this->displayError($this->l('The livredor could not be added.'));
|
||
|
}
|
||
|
/* Update */
|
||
|
elseif (!$livredor->update())
|
||
|
$errors[] = $this->displayError($this->l('The livredor could not be updated.'));
|
||
|
|
||
|
$this->clearCache();
|
||
|
}
|
||
|
} /* Deletes */
|
||
|
elseif (Tools::isSubmit('delete_id_livredor'))
|
||
|
{
|
||
|
$livredor = new livredorItem((int)Tools::getValue('delete_id_livredor'));
|
||
|
$res = $livredor->delete();
|
||
|
$this->clearCache();
|
||
|
if (!$res)
|
||
|
$this->_html .= $this->displayError('Could not delete');
|
||
|
else
|
||
|
$this->_html .= $this->displayConfirmation($this->l('livredor deleted'));
|
||
|
}
|
||
|
elseif (Tools::isSubmit('submittheme'))
|
||
|
{
|
||
|
/* Sets ID if needed */
|
||
|
if (Tools::getValue('id_theme'))
|
||
|
{
|
||
|
$livredor = new livredorTheme((int)Tools::getValue('id_theme'));
|
||
|
if (!Validate::isLoadedObject($livredor))
|
||
|
{
|
||
|
$this->_html .= $this->displayError($this->l('Invalid id_theme'));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
$livredor = new livredorTheme();
|
||
|
/* Sets position */
|
||
|
$livredor->id_livredor_parent = (int)Tools::getValue('id_livredor_parent');
|
||
|
|
||
|
$livredor->position = (int)Tools::getValue('position');
|
||
|
/* Sets active */
|
||
|
$livredor->active = (int)Tools::getValue('active_theme');
|
||
|
|
||
|
/* Sets each langue fields */
|
||
|
$languages = Language::getLanguages(false);
|
||
|
foreach ($languages as $language)
|
||
|
{
|
||
|
$livredor->title[$language['id_lang']] = Tools::getValue('title_'.$language['id_lang']);
|
||
|
}
|
||
|
|
||
|
/* Processes if no errors */
|
||
|
if (!$errors)
|
||
|
{
|
||
|
/* Adds */
|
||
|
if (!Tools::getValue('id_theme'))
|
||
|
{
|
||
|
$livredor->add();
|
||
|
// $errors[] = $this->displayError($this->l('Le thème ne peut être créé'));
|
||
|
}
|
||
|
/* Update */
|
||
|
elseif (!$livredor->update())
|
||
|
$errors[] = $this->displayError($this->l('Le thème n\'a pas été modifié'));
|
||
|
$this->clearCache();
|
||
|
}
|
||
|
} /* Deletes */
|
||
|
elseif (Tools::isSubmit('delete_id_theme'))
|
||
|
{
|
||
|
$livredor = new livredorTheme((int)Tools::getValue('delete_id_theme'));
|
||
|
$res = $livredor->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()
|
||
|
{
|
||
|
if (!$this->isCached('devspelivredor.tpl', $this->getCacheId()))
|
||
|
{
|
||
|
// $livredorr = array(
|
||
|
// 'width' => Configuration::get('devspelivredor_WIDTH'),
|
||
|
// 'height' => Configuration::get('devspelivredor_HEIGHT'),
|
||
|
// 'speed' => Configuration::get('devspelivredor_SPEED'),
|
||
|
// 'pause' => Configuration::get('devspelivredor_PAUSE'),
|
||
|
// 'loop' => Configuration::get('devspelivredor_LOOP'),
|
||
|
// );
|
||
|
|
||
|
$livredors = $this->getItemslivredor(true);
|
||
|
if (!$livredors)
|
||
|
return false;
|
||
|
|
||
|
$this->smarty->assign('devspelivredor_item', $livredors);
|
||
|
// $this->smarty->assign('devspelivredor', $livredorr);
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public function hookTop()
|
||
|
{
|
||
|
// if(!$this->_prepareHook())
|
||
|
// return;
|
||
|
|
||
|
// Check if not a mobile theme
|
||
|
/*
|
||
|
if ($this->context->getMobileDevice() != false)
|
||
|
return false;
|
||
|
|
||
|
// $this->context->controller->addJS($this->_path.'js/jquery.bxlivredorr.min.js');
|
||
|
$this->context->controller->addCSS($this->_path.'devspelivredor.css');
|
||
|
$this->context->controller->addJS($this->_path.'js/devspelivredor.js');
|
||
|
return $this->display(__FILE__, 'devspelivredor.tpl', $this->getCacheId());
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
public function clearCache()
|
||
|
{
|
||
|
$this->_clearCache('devspelivredor.tpl');
|
||
|
}
|
||
|
|
||
|
public function hookActionShopDataDuplication($params)
|
||
|
{
|
||
|
Db::getInstance()->execute('
|
||
|
INSERT IGNORE INTO '._DB_PREFIX_.'devspelivredor (id_livredor_item, id_shop)
|
||
|
SELECT id_livredor_item, '.(int)$params['new_id_shop'].'
|
||
|
FROM '._DB_PREFIX_.'devspelivredor
|
||
|
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 'livredors configuration' */
|
||
|
$html = '
|
||
|
<style>
|
||
|
#themes li,
|
||
|
#livredors 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 $mylivredors = $("#livredors");
|
||
|
$mylivredors.sortable({
|
||
|
opacity: 0.6,
|
||
|
cursor: "move",
|
||
|
update: function() {
|
||
|
var order = $(this).sortable("serialize") + "&action=updatelivredorsPosition";
|
||
|
$.post("'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax_'.$this->name.'.php?secure_key='.$this->secure_key.'", order);
|
||
|
}
|
||
|
});
|
||
|
$mylivredors.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=updatelivredorsThemePosition";
|
||
|
$.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_.'devspelivredor_item` hss, `'._DB_PREFIX_.'devspelivredor` hs
|
||
|
WHERE hss.`id_livredor_item` = hs.`id_livredor_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_.'devspelivredor_theme` hss'
|
||
|
);
|
||
|
|
||
|
return (++$row['next_position']);
|
||
|
}
|
||
|
|
||
|
public function getItemslivredor($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_livredor_item` as id_livredor,
|
||
|
hss.`position`,
|
||
|
hss.`id_theme`,
|
||
|
hss.`active`,
|
||
|
hss.`en_avant`,
|
||
|
hss.`note`,
|
||
|
hss.`age`,
|
||
|
hssl.`prenom`,
|
||
|
hssl.`nom`,
|
||
|
hssl.`nom`,
|
||
|
hssl.`departement`,
|
||
|
hssl.`ville`,
|
||
|
hssl.`titre`,
|
||
|
|
||
|
|
||
|
hssl.`phrase`
|
||
|
FROM '._DB_PREFIX_.'devspelivredor hs
|
||
|
LEFT JOIN '._DB_PREFIX_.'devspelivredor_item hss ON (hs.id_livredor_item = hss.id_livredor_item)
|
||
|
LEFT JOIN '._DB_PREFIX_.'devspelivredor_item_lang hssl ON (hss.id_livredor_item = hssl.id_livredor_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_livredor_theme` as id_theme,
|
||
|
hss.`position`,
|
||
|
hss.`active`,
|
||
|
hss.`id_livredor_parent`,
|
||
|
hssl.`title`
|
||
|
FROM '._DB_PREFIX_.'devspelivredor_theme hss
|
||
|
LEFT JOIN '._DB_PREFIX_.'devspelivredor_theme_lang hssl ON (hss.id_livredor_theme = hssl.id_livredor_theme)
|
||
|
WHERE hssl.id_lang = '.(int)$id_lang.
|
||
|
($active ? ' AND hss.`active` = 1' : ' ').
|
||
|
($zero ? ' AND hss.`id_livredor_parent` = 0' : ' ').'
|
||
|
ORDER BY hss.position');
|
||
|
}
|
||
|
|
||
|
public function displayStatusEnavant($id_livredor, $en_avant)
|
||
|
{
|
||
|
$title = ((int)$en_avant == 0 ? $this->l('Mettre ce message en avant') : $this->l('Ce message est mis en avant'));
|
||
|
$img = ((int)$en_avant == 0 ? 'en_avant_off.jpg' : 'en_avant_on.jpg');
|
||
|
$html = '<a href="'.AdminController::$currentIndex.
|
||
|
'&configure='.$this->name.'
|
||
|
&token='.Tools::getAdminTokenLite('AdminModules').'
|
||
|
&changeStatusEnavant&id_livredor='.(int)$id_livredor.'" title="'.$title.'"><img src="'._PS_ADMIN_IMG_.''.$img.'" alt="'.$title.'" style="width:16px"/></a>';
|
||
|
return $html;
|
||
|
}
|
||
|
public function displayStatus($id_livredor, $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_livredor='.(int)$id_livredor.'" title="'.$title.'"><img src="'._PS_ADMIN_IMG_.''.$img.'" alt="" /></a>';
|
||
|
return $html;
|
||
|
}
|
||
|
|
||
|
public function livredorExists($id_livredor)
|
||
|
{
|
||
|
$req = 'SELECT hs.`id_livredor_item` as id_livredor
|
||
|
FROM `'._DB_PREFIX_.'devspelivredor` hs
|
||
|
WHERE hs.`id_livredor_item` = '.(int)$id_livredor;
|
||
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
|
||
|
return ($row);
|
||
|
}
|
||
|
public function livredorThemeExists($id_theme)
|
||
|
{
|
||
|
$req = 'SELECT hs.`id_livredor_theme` as id_theme
|
||
|
FROM `'._DB_PREFIX_.'devspelivredor_theme` hs
|
||
|
WHERE hs.`id_livredor_theme` = '.(int)$id_theme;
|
||
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
|
||
|
return ($row);
|
||
|
}
|
||
|
}
|