2232 lines
88 KiB
PHP
Executable File
2232 lines
88 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_.'devspediagnostic/diagnostic.php');
|
|
include_once(_PS_MODULE_DIR_.'devspediagnostic/condition.php');
|
|
include_once(_PS_MODULE_DIR_.'devspediagnostic/masquerquestion.php');
|
|
include_once(_PS_MODULE_DIR_.'devspediagnostic/substitution.php');
|
|
include_once(_PS_MODULE_DIR_.'devspediagnostic/reorientation.php');
|
|
|
|
class devspeDiagnostic extends Module
|
|
{
|
|
private $_html = '';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->name = 'devspediagnostic';
|
|
$this->version = '1';
|
|
$this->need_instance = 0;
|
|
$this->secure_key = Tools::encrypt($this->name);
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Gestion du diagnostic');
|
|
$this->description = $this->l('Administrer le diagnostic');
|
|
}
|
|
|
|
/**
|
|
* @see Module::install()
|
|
*/
|
|
public function install()
|
|
{
|
|
/* Adds Module */
|
|
if (parent::install() && $this->registerHook('actionShopDataDuplication'))
|
|
{
|
|
// /* Sets up configuration */
|
|
// $res = Configuration::updateValue('devspediagnostic_WIDTH', '535');
|
|
// $res &= Configuration::updateValue('devspediagnostic_HEIGHT', '300');
|
|
// $res &= Configuration::updateValue('devspediagnostic_SPEED', '500');
|
|
// $res &= Configuration::updateValue('devspediagnostic_PAUSE', '3000');
|
|
// $res &= Configuration::updateValue('devspediagnostic_LOOP', '1');
|
|
/* Creates tables */
|
|
$res = $this->createTables();
|
|
|
|
/* Adds samples */
|
|
// if ($res)
|
|
// $this->installSamples();
|
|
|
|
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('devspediagnostic_WIDTH');
|
|
// $res &= Configuration::deleteByName('devspediagnostic_HEIGHT');
|
|
// $res &= Configuration::deleteByName('devspediagnostic_SPEED');
|
|
// $res &= Configuration::deleteByName('devspediagnostic_PAUSE');
|
|
// $res &= Configuration::deleteByName('devspediagnostic_LOOP');
|
|
return $res;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Creates tables
|
|
*/
|
|
protected function createTables()
|
|
{
|
|
/* items */
|
|
$res = (bool)Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic` (
|
|
`id_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`id_shop` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`id_item`, `id_shop`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
|
|
/* items configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_items` (
|
|
`id_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`position` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
`active` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
|
PRIMARY KEY (`id_item`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* items lang configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_items_lang` (
|
|
`id_item` int(10) unsigned NOT NULL,
|
|
`id_lang` int(10) unsigned NOT NULL,
|
|
`question` varchar(255) NOT NULL,
|
|
`repA` varchar(255) NOT NULL,
|
|
`repB` varchar(255) NOT NULL,
|
|
`repC` varchar(255) NOT NULL,
|
|
`repD` varchar(255) NOT NULL,
|
|
`repE` varchar(255) NOT NULL,
|
|
`texterepA` text NOT NULL,
|
|
`texterepB` text NOT NULL,
|
|
`texterepC` text NOT NULL,
|
|
`texterepD` text NOT NULL,
|
|
`texterepE` text NOT NULL,
|
|
PRIMARY KEY (`id_item`,`id_lang`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* items configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_croisement` (
|
|
`id_item` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
`id_reponse` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
`id_product` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
PRIMARY KEY (`id_item`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* items configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_exclusion` (
|
|
`id_item` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
`id_reponse` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
`id_product` int(10) unsigned NOT NULL DEFAULT \'0\',
|
|
PRIMARY KEY (`id_item`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* items configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_conditions` (
|
|
`id_condition` int(11) NOT NULL AUTO_INCREMENT,
|
|
`id_question_1` int(11) NOT NULL,
|
|
`id_question_2` int(11) NOT NULL,
|
|
`id_question_3` int(11) NOT NULL,
|
|
`id_reponse_1` int(11) NOT NULL,
|
|
`id_reponse_2` int(11) NOT NULL,
|
|
`id_reponse_3` int(11) NOT NULL,
|
|
`id_product_1` int(11) NOT NULL,
|
|
`id_product_2` int(11) NOT NULL,
|
|
PRIMARY KEY (`id_condition`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* items configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_reorientations` (
|
|
`id_reorientation` int(11) NOT NULL AUTO_INCREMENT,
|
|
`id_question_1` int(11) NOT NULL,
|
|
`id_question_2` int(11) NOT NULL,
|
|
`id_reponse_1` int(11) NOT NULL,
|
|
`id_reponse_2` int(11) NOT NULL,
|
|
`id_product_1` int(11) NOT NULL,
|
|
PRIMARY KEY (`id_reorientation`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* items configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_masquerquestions` (
|
|
`id_masquerquestion` int(11) NOT NULL AUTO_INCREMENT,
|
|
`id_question_1` int(11) NOT NULL,
|
|
`id_question_2` int(11) NOT NULL,
|
|
`id_reponse_1` int(11) NOT NULL,
|
|
PRIMARY KEY (`id_masquerquestion`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
/* items configuration */
|
|
$res &= Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'devspediagnostic_substitutions` (
|
|
`id_substitution` int(11) NOT NULL AUTO_INCREMENT,
|
|
`id_product_1` int(11) NOT NULL,
|
|
`id_product_2` int(11) NOT NULL,
|
|
PRIMARY KEY (`id_substitution`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
|
|
');
|
|
|
|
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* deletes tables
|
|
*/
|
|
protected function deleteTables()
|
|
{
|
|
$items = $this->getitems();
|
|
foreach ($items as $item)
|
|
{
|
|
$to_del = new Diagnostic($item['id_item']);
|
|
$to_del->delete();
|
|
}
|
|
return Db::getInstance()->execute('
|
|
DROP TABLE IF EXISTS `'._DB_PREFIX_.'devspediagnostic`, `'._DB_PREFIX_.'devspediagnostic_items`, `'._DB_PREFIX_.'devspediagnostic_items_lang`, `'._DB_PREFIX_.'devspediagnostic_croisement`, `'._DB_PREFIX_.'devspediagnostic_exclusion`;
|
|
');
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
$languages = Language::getLanguages(false);
|
|
$iso = $this->context->language->iso_code;
|
|
$divLangName = 'cpara¤dd';
|
|
|
|
// xml loading
|
|
$xml = false;
|
|
if (file_exists($this->_xmlFile))
|
|
if (!$xml = @simplexml_load_file($this->_xmlFile))
|
|
$this->_html .= $this->displayError($this->l('Your text is empty.'));
|
|
|
|
// TinyMCE
|
|
if (version_compare(_PS_VERSION_, '1.4.0.0') >= 0)
|
|
$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();
|
|
</script>';
|
|
else
|
|
{
|
|
$this->_html .= '
|
|
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
|
|
<script type="text/javascript">
|
|
tinyMCE.init({
|
|
mode : "textareas",
|
|
theme : "advanced",
|
|
plugins : "safari,pagebreak,style,layer,table,advimage,advlink,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen",
|
|
theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
|
|
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,,|,forecolor,backcolor",
|
|
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,|,ltr,rtl,|,fullscreen",
|
|
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,pagebreak",
|
|
theme_advanced_toolbar_location : "top",
|
|
theme_advanced_toolbar_align : "left",
|
|
theme_advanced_statusbar_location : "bottom",
|
|
theme_advanced_resizing : false,
|
|
content_css : "'.__PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/global.css",
|
|
document_base_url : "'.__PS_BASE_URI__.'",
|
|
width: "600",
|
|
height: "auto",
|
|
font_size_style_values : "8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt",
|
|
template_external_list_url : "lists/template_list.js",
|
|
external_link_list_url : "lists/link_list.js",
|
|
external_image_list_url : "lists/image_list.js",
|
|
media_external_list_url : "lists/media_list.js",
|
|
elements : "nourlconvert",
|
|
entity_encoding: "raw",
|
|
convert_urls : false,
|
|
language : "'.(file_exists(_PS_ROOT_DIR_.'/js/tinymce/jscripts/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en').'"
|
|
});
|
|
id_language = Number('.(int)$this->context->language->id.');
|
|
</script>';
|
|
}
|
|
|
|
$this->_html .= $this->headerHTML();
|
|
|
|
/* Validate & process */
|
|
if (Tools::isSubmit('submititem') || Tools::isSubmit('delete_id_item') ||
|
|
Tools::isSubmit('submititem_bis') ||
|
|
Tools::isSubmit('changeStatus'))
|
|
{
|
|
if ($this->_postValidation())
|
|
$this->_postProcess();
|
|
$this->_html .= '<h2>'.$this->displayName.'</h2>';
|
|
$this->_displayForm();
|
|
}
|
|
elseif (Tools::getValue('type') && $this->itemExists((int)Tools::getValue('id_item'))){
|
|
|
|
if (Tools::isSubmit('formcroisement') || Tools::isSubmit('formexclusion')){
|
|
$this->_postProcessProducts(Tools::getValue('type'));
|
|
$this->_displayForm();
|
|
}else{
|
|
$this->_displayFormProducts(Tools::getValue('type'));
|
|
}
|
|
}elseif (Tools::isSubmit('additem') || (Tools::isSubmit('id_item') && $this->itemExists((int)Tools::getValue('id_item')))){
|
|
$this->_html .= '<h2>'.$this->displayName.'</h2>';
|
|
$this->_displayAddForm();
|
|
}elseif (Tools::getValue('addReorientation') || Tools::getValue('id_reorientation') || Tools::getValue('delete_id_reorientation')){
|
|
|
|
if (Tools::isSubmit('formreorientation') || Tools::getValue('delete_id_reorientation')){
|
|
$this->_postProcessReorientations();
|
|
$this->_displayForm();
|
|
$this->_displayFormConditionsList();
|
|
$this->_displayFormSubstitutionsList();
|
|
$this->_displayFormMasquerquestionList();
|
|
$this->_displayformreorientationList();
|
|
}else{
|
|
$this->_displayformreorientation();
|
|
}
|
|
}elseif (Tools::getValue('addCondition') || Tools::getValue('id_condition') || Tools::getValue('delete_id_condition')){
|
|
|
|
if (Tools::isSubmit('formconditions') || Tools::getValue('delete_id_condition')){
|
|
$this->_postProcessConditions();
|
|
$this->_displayForm();
|
|
$this->_displayFormConditionsList();
|
|
$this->_displayFormSubstitutionsList();
|
|
$this->_displayFormMasquerquestionList();
|
|
$this->_displayformreorientationList();
|
|
}else{
|
|
$this->_displayFormConditions();
|
|
}
|
|
}elseif (Tools::getValue('addSubstitution') || Tools::getValue('id_substitution') || Tools::getValue('delete_id_substitution')){
|
|
|
|
if (Tools::isSubmit('formsubstitutions') || Tools::getValue('delete_id_substitution')){
|
|
$this->_postProcessSubstitutions();
|
|
$this->_displayForm();
|
|
$this->_displayFormConditionsList();
|
|
$this->_displayFormSubstitutionsList();
|
|
$this->_displayFormMasquerquestionList();
|
|
$this->_displayformreorientationList();
|
|
}else{
|
|
$this->_displayFormSubtitutions();
|
|
}
|
|
}elseif (Tools::getValue('addMasquerquestion') || Tools::getValue('id_masquerquestion') || Tools::getValue('delete_id_substitution')){
|
|
|
|
if (Tools::isSubmit('formmasquerquestion') || Tools::getValue('delete_id_masquerquestion')){
|
|
$this->_postProcessMasquerquestions();
|
|
$this->_displayForm();
|
|
$this->_displayFormConditionsList();
|
|
$this->_displayFormSubstitutionsList();
|
|
$this->_displayFormMasquerquestionList();
|
|
$this->_displayformreorientationList();
|
|
}else{
|
|
$this->_displayFormMasquerquestions();
|
|
}
|
|
}else{
|
|
$this->_html .= '<h2>'.$this->displayName.'</h2>';
|
|
$this->_displayForm();
|
|
$this->_displayFormConditionsList();
|
|
$this->_displayFormSubstitutionsList();
|
|
$this->_displayFormMasquerquestionList();
|
|
$this->_displayformreorientationList();
|
|
}
|
|
|
|
return $this->_html;
|
|
}
|
|
|
|
private function _displayForm()
|
|
{
|
|
/* Gets items */
|
|
$items = $this->getitems();
|
|
|
|
/* Begin fieldset items */
|
|
$this->_html .= '
|
|
<fieldset>
|
|
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Gestion des questions du diagnostic').'</legend>
|
|
<strong style="display:none">
|
|
<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('Vous n\'avez aucune question enregistrée').'</p>';
|
|
else /* Display items */
|
|
{
|
|
$this->_html .= '
|
|
<div id="itemsContent" style="width: 700px; margin-top: 0px;">
|
|
<ul id="items">';
|
|
foreach ($items as $item)
|
|
{
|
|
$this->_html .= '
|
|
<li id="items_'.$item['id_item'].'">
|
|
<strong>#'.$item['id_item'].'</strong> '.$item['question'].'
|
|
<p style="float: right;margin:0;">
|
|
<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').'&type=croisement&id_item='.(int)($item['id_item']).'" title="'.$this->l('Croisements').'"><img src="'._PS_ADMIN_IMG_.'status_green.png" alt="" style="height:20px;width:20px" /></a>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&type=exclusion&id_item='.(int)($item['id_item']).'" title="'.$this->l('Exclusions').'"><img src="'._PS_ADMIN_IMG_.'status_orange.png" alt="" style="height:20px;width:20px" /></a>
|
|
</p>
|
|
</li>';
|
|
}
|
|
$this->_html .= '</ul></div>';
|
|
}
|
|
// End fieldset
|
|
$this->_html .= '</fieldset><br/><br/>';
|
|
}
|
|
private function _displayFormConditionsList()
|
|
{
|
|
/* Gets items */
|
|
$items = $this->getitemsConditions();
|
|
|
|
/* Begin fieldset items */
|
|
$this->_html .= '
|
|
<fieldset>
|
|
<legend>'.$this->l('Gestion des conditions de substitution de produits').'</legend>
|
|
<strong>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addCondition=1">
|
|
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter une condition').'
|
|
</a>
|
|
</strong>';
|
|
|
|
/* Display notice if there are no items yet */
|
|
if (!$items)
|
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Vous n\'avez aucune condition enregistrée').'</p>';
|
|
else /* Display items */
|
|
{
|
|
$this->_html .= '
|
|
<div id="itemsContent" style="width: 700px; margin-top: 0px;">
|
|
<ul id="items">';
|
|
foreach ($items as $item)
|
|
{
|
|
$this->_html .= '
|
|
<li id="items_'.$item['id_condition'].'">
|
|
<strong>
|
|
#'.$item['id_condition'].'</strong> :
|
|
Q'.$item['id_question_1'].' R'.$item['id_reponse_1'].'
|
|
'.($item['id_question_2']!=0?' et Q'.$item['id_question_2'].' R'.$item['id_reponse_2']:'').'
|
|
'.($item['id_question_3']!=0?' et Q'.$item['id_question_3'].' R'.$item['id_reponse_3']:'').'
|
|
, Produit #'.$item['id_product_1'].' remplace Produit #'.$item['id_product_2'].'
|
|
<p style="float: right;margin:0;">
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_condition='.(int)($item['id_condition']).'" 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_condition='.(int)($item['id_condition']).'" title="'.$this->l('Exclusions').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
|
|
</p>
|
|
</li>';
|
|
}
|
|
$this->_html .= '</ul></div>';
|
|
}
|
|
// End fieldset
|
|
$this->_html .= '</fieldset>';
|
|
}
|
|
private function _displayformreorientationList()
|
|
{
|
|
/* Gets items */
|
|
$items = $this->getitemsReorientations();
|
|
|
|
/* Begin fieldset items */
|
|
$this->_html .= '
|
|
<br/><br/><fieldset>
|
|
<legend>'.$this->l('Gestion des réorientations des réponses incohérentes').'</legend>
|
|
<strong>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addReorientation=1">
|
|
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter une condition de réorientation').'
|
|
</a>
|
|
</strong>';
|
|
|
|
/* Display notice if there are no items yet */
|
|
if (!$items)
|
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Vous n\'avez aucune condition de réorientation enregistrée').'</p>';
|
|
else /* Display items */
|
|
{
|
|
$this->_html .= '
|
|
<div id="itemsContent" style="width: 700px; margin-top: 0px;">
|
|
<ul id="items">';
|
|
foreach ($items as $item)
|
|
{
|
|
$this->_html .= '
|
|
<li id="items_'.$item['id_reorientation'].'">
|
|
<strong>
|
|
#'.$item['id_reorientation'].'</strong> :
|
|
Si Q'.$item['id_question_1'].' R'.$item['id_reponse_1'].'
|
|
'.($item['id_question_2']!=0?' et Q'.$item['id_question_2'].' R'.$item['id_reponse_2']:'').'
|
|
'.($item['id_question_3']!=0?' et Q'.$item['id_question_3'].' R'.$item['id_reponse_3']:'').'
|
|
réoriention pour : Q'.$item['id_question_4'].' R'.$item['id_reponse_4'].'
|
|
<p style="float: right;margin:0;">
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_reorientation='.(int)($item['id_reorientation']).'" 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_reorientation='.(int)($item['id_reorientation']).'" title="'.$this->l('Supprimer').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
|
|
</p>
|
|
</li>';
|
|
}
|
|
$this->_html .= '</ul></div>';
|
|
}
|
|
// End fieldset
|
|
$this->_html .= '</fieldset>';
|
|
}
|
|
private function _displayFormMasquerquestionList()
|
|
{
|
|
/* Gets items */
|
|
$items = $this->getitemsMasquerquestions();
|
|
|
|
/* Begin fieldset items */
|
|
$this->_html .= '
|
|
<br/><br/><fieldset>
|
|
<legend>'.$this->l('Gestion des questions à masquer selon la réponse').'</legend>
|
|
<strong>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addMasquerquestion=1">
|
|
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter une condition de masquage').'
|
|
</a>
|
|
</strong>';
|
|
|
|
/* Display notice if there are no items yet */
|
|
if (!$items)
|
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Vous n\'avez aucune condition enregistrée').'</p>';
|
|
else /* Display items */
|
|
{
|
|
$this->_html .= '
|
|
<div id="itemsContent" style="width: 700px; margin-top: 0px;">
|
|
<ul id="items">';
|
|
foreach ($items as $item)
|
|
{
|
|
$this->_html .= '
|
|
<li id="items_'.$item['id_masquerquestion'].'">
|
|
<strong>
|
|
#'.$item['id_masquerquestion'].'</strong> :
|
|
Si Q'.$item['id_question_1'].' R'.$item['id_reponse_1'].', alors Q'.$item['id_question_2'].' sera masquée
|
|
<p style="float: right;margin:0;">
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_masquerquestion='.(int)($item['id_masquerquestion']).'" 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_masquerquestion='.(int)($item['id_masquerquestion']).'" title="'.$this->l('Exclusions').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
|
|
</p>
|
|
</li>';
|
|
}
|
|
$this->_html .= '</ul></div>';
|
|
}
|
|
// End fieldset
|
|
$this->_html .= '</fieldset>';
|
|
}
|
|
private function _displayFormSubstitutionsList()
|
|
{
|
|
/* Gets items */
|
|
$items = $this->getitemsSubstitution();
|
|
|
|
/* Begin fieldset items */
|
|
$this->_html .= '
|
|
<br/><br/><fieldset>
|
|
<legend>'.$this->l('Gestion des substitution de produits dans un même rituel').'</legend>
|
|
<strong>
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addSubstitution=1">
|
|
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Ajouter une substitution').'
|
|
</a>
|
|
</strong>';
|
|
|
|
/* Display notice if there are no items yet */
|
|
if (!$items)
|
|
$this->_html .= '<p style="margin-left: 40px;">'.$this->l('Vous n\'avez aucune substitution enregistrée').'</p>';
|
|
else /* Display items */
|
|
{
|
|
$this->_html .= '
|
|
<div id="itemsContent" style="width: 700px; margin-top: 0px;">
|
|
<ul id="items">';
|
|
foreach ($items as $item)
|
|
{
|
|
$this->_html .= '
|
|
<li id="items_'.$item['id_substitution'].'">
|
|
<strong>
|
|
#'.$item['id_substitution'].'</strong> :
|
|
Le produit #'.$item['id_product_1'].' ne sera pas affiché, si il se trouve dans le même rituel que le produit #'.$item['id_product_2'].'
|
|
<p style="float: right;margin:0;">
|
|
<a href="'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_substitution='.(int)($item['id_substitution']).'" 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_substitution='.(int)($item['id_substitution']).'" title="'.$this->l('Exclusions').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
|
|
</p>
|
|
</li>';
|
|
}
|
|
$this->_html .= '</ul></div>';
|
|
}
|
|
// End fieldset
|
|
$this->_html .= '</fieldset>';
|
|
}
|
|
public function getProductsItems($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 id_product,id_lang,name
|
|
FROM '._DB_PREFIX_.'product_lang pl
|
|
WHERE pl.id_lang = '.(int)$id_lang.'
|
|
ORDER BY pl.id_product');
|
|
}
|
|
private function _displayFormProducts($table="croisement")
|
|
{
|
|
/* Sets item : depends if edited or added */
|
|
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
// devspediagnostic_croisement
|
|
|
|
|
|
$category14 = new Category(14, $id_lang_default);
|
|
$category14->products = $category14->getProducts($id_lang_default, 0, 100);
|
|
$category15 = new Category(15, $id_lang_default);
|
|
$category15->products = $category15->getProducts($id_lang_default, 0, 100);
|
|
$category16 = new Category(16, $id_lang_default);
|
|
$category16->products = $category16->getProducts($id_lang_default, 0, 100);
|
|
$category17 = new Category(17, $id_lang_default);
|
|
$category17->products = $category17->getProducts($id_lang_default, 0, 100);
|
|
|
|
$item = null;
|
|
if (Tools::isSubmit('id_item') && $this->itemExists((int)Tools::getValue('id_item')))
|
|
$item = new Diagnostic((int)Tools::getValue('id_item'));
|
|
|
|
$id_item=(int)$item->id;
|
|
$question=$item->question[$id_lang_default];
|
|
$repA=$item->repA[$id_lang_default];
|
|
$repB=$item->repB[$id_lang_default];
|
|
$repC=$item->repC[$id_lang_default];
|
|
$repD=$item->repD[$id_lang_default];
|
|
$repE=$item->repE[$id_lang_default];
|
|
if($repA!="")$max=1;
|
|
if($repB!="")$max=2;
|
|
if($repC!="")$max=3;
|
|
if($repD!="")$max=4;
|
|
if($repE!="")$max=5;
|
|
/* Form */
|
|
$this->_html .= '<div style="width:900px;margin:0 auto">';
|
|
if($table=="croisement")
|
|
$this->_html .= '<h2 style="text-align:center">Croisement des produits</h2><p>Les produits cochés apparaîtront dans le diagnostic (si ils ne sont pas exclus)';
|
|
else
|
|
$this->_html .= '<h2 style="text-align:center">Exclusion des produits</h2><p>Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)</p>';
|
|
$this->_html .= '<h3 style="text-align:center">Question : #'.$id_item.' : '.$question.'</h3>';
|
|
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
$this->_html .= '<input type="hidden" name="id_item" value="'.$id_item.'" id="id_item" />';
|
|
|
|
/* Fieldset edit/add */
|
|
for($i=1;$i<=$max;$i++){
|
|
|
|
if($i==1){$lettre="A";$rep=$repA;}
|
|
if($i==2){$lettre="B";$rep=$repB;}
|
|
if($i==3){$lettre="C";$rep=$repC;}
|
|
if($i==4){$lettre="D";$rep=$repD;}
|
|
if($i==5){$lettre="E";$rep=$repE;}
|
|
$this->_html .= '<fieldset class="width3" style="width:900px;margin:0 0 20px;">';
|
|
$this->_html .= '<legend>Réponse '.$lettre.' - '.$rep.'</legend>';
|
|
$this->_html .= '<input type="hidden" name="lettre[]" value="'.$lettre.'" />';
|
|
|
|
/* cat 14 */
|
|
$productsSelected14=array();
|
|
if($products14=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT id_product
|
|
FROM '._DB_PREFIX_.'devspediagnostic_'.$table.'
|
|
WHERE id_item = '.$id_item.'
|
|
and id_category=14
|
|
and id_reponse='.$i))
|
|
foreach($products14 as $id_product)
|
|
if(!in_array($id_product['id_product'],$productsSelected14))
|
|
$productsSelected14[]=$id_product['id_product'];
|
|
$this->_html .= '<div style="float: left;width:200px;padding:0 10px 0 0px;border-right:1Px solid #CCCED7;margin:0 10px 20px 0;"><label style="width:200px;text-align:left;">'.$category14->name.' * </label><br/><br/>';
|
|
foreach ($category14->products as $product)
|
|
{
|
|
$this->_html .= '
|
|
<input style="vertical-align:-2px" type="checkbox" name="products_'.$id_item.$lettre.'_14[]" id="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'" value="'.$product['id_product'].'" '.(in_array($product['id_product'],$productsSelected14)?'checked="checked"':'').'/>
|
|
<label for="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'_14" style="float:none;cursor:pointer;width:auto;font-weight:normal;">'.$product['name'].'</label><br/>';
|
|
}
|
|
$this->_html .= '</div>';
|
|
/* end cat 14 */
|
|
|
|
/* cat 15 */
|
|
$productsSelected15=array();
|
|
if($products15=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT id_product
|
|
FROM '._DB_PREFIX_.'devspediagnostic_'.$table.'
|
|
WHERE id_item = '.$id_item.'
|
|
and id_category=15
|
|
and id_reponse='.$i))
|
|
foreach($products15 as $id_product)
|
|
if(!in_array($id_product['id_product'],$productsSelected15))
|
|
$productsSelected15[]=$id_product['id_product'];
|
|
$this->_html .= '<div style="float: left;width:200px;padding:0 10px 0 0px;border-right:1Px solid #CCCED7;margin:0 10px 20px 0;"><label style="width:200px;text-align:left;">'.$category15->name.' * </label><br/><br/>';
|
|
foreach ($category15->products as $product)
|
|
{
|
|
$this->_html .= '
|
|
<input style="vertical-align:-2px" type="checkbox" name="products_'.$id_item.$lettre.'_15[]" id="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'_15" value="'.$product['id_product'].'" '.(in_array($product['id_product'],$productsSelected15)?'checked="checked"':'').'/>
|
|
<label for="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'_15" style="float:none;cursor:pointer;width:auto;font-weight:normal;">'.$product['name'].'</label><br/>';
|
|
}
|
|
$this->_html .= '</div>';
|
|
/* end cat 15 */
|
|
|
|
/* cat 16 */
|
|
$productsSelected16=array();
|
|
if($products16=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT id_product
|
|
FROM '._DB_PREFIX_.'devspediagnostic_'.$table.'
|
|
WHERE id_item = '.$id_item.'
|
|
and id_category=16
|
|
and id_reponse='.$i))
|
|
foreach($products16 as $id_product)
|
|
if(!in_array($id_product['id_product'],$productsSelected16))
|
|
$productsSelected16[]=$id_product['id_product'];
|
|
$this->_html .= '<div style="float: left;width:200px;padding:0 10px 0 0px;border-right:1Px solid #CCCED7;margin:0 10px 20px 0;"><label style="width:200px;text-align:left;">'.$category16->name.' * </label><br/><br/>';
|
|
foreach ($category16->products as $product)
|
|
{
|
|
$this->_html .= '
|
|
<input style="vertical-align:-2px" type="checkbox" name="products_'.$id_item.$lettre.'_16[]" id="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'_16" value="'.$product['id_product'].'" '.(in_array($product['id_product'],$productsSelected16)?'checked="checked"':'').'/>
|
|
<label for="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'_16" style="float:none;cursor:pointer;width:auto;font-weight:normal;">'.$product['name'].'</label><br/>';
|
|
}
|
|
$this->_html .= '</div>';
|
|
/* end cat 16 */
|
|
|
|
/* cat 17 */
|
|
$productsSelected17=array();
|
|
if($products17=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT id_product
|
|
FROM '._DB_PREFIX_.'devspediagnostic_'.$table.'
|
|
WHERE id_item = '.$id_item.'
|
|
and id_category=17
|
|
and id_reponse='.$i))
|
|
foreach($products17 as $id_product)
|
|
if(!in_array($id_product['id_product'],$productsSelected17))
|
|
$productsSelected17[]=$id_product['id_product'];
|
|
$this->_html .= '<div style="float: left;width:200px;padding:0 10px 0 0px;border-right:0;margin:0 0px 20px;"><label style="width:200px;text-align:left;">'.$category17->name.' * </label><br/><br/>';
|
|
foreach ($category17->products as $product)
|
|
{
|
|
$this->_html .= '
|
|
<input style="vertical-align:-2px" type="checkbox" name="products_'.$id_item.$lettre.'_17[]" id="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'_17" value="'.$product['id_product'].'" '.(in_array($product['id_product'],$productsSelected17)?'checked="checked"':'').'/>
|
|
<label for="products_rep'.$id_item.$lettre.'_'.$product['id_product'].'_17" style="float:none;cursor:pointer;width:auto;font-weight:normal;">'.$product['name'].'</label><br/>';
|
|
}
|
|
$this->_html .= '</div>';
|
|
/* end cat 16 */
|
|
$this->_html .= '</fieldset>';
|
|
}
|
|
|
|
/* Save */
|
|
$this->_html .= '
|
|
<p style="padding-left:0;clear:both;">
|
|
<input type="submit" class="button" name="form'.$table.'" 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 obligatoires').'</p>
|
|
</fieldset>
|
|
</form>';
|
|
$this->_html .= '</div>';
|
|
}
|
|
private function _displayFormConditions($table="conditions")
|
|
{
|
|
/* Sets item : depends if edited or added */
|
|
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
// devspediagnostic_croisement
|
|
|
|
|
|
$item = null;
|
|
if (Tools::getValue('id_condition'))
|
|
{
|
|
$condition = new Conditions((int)Tools::getValue('id_condition'));
|
|
$id_condition=(int)$condition->id;
|
|
$id_question_1=(int)$condition->id_question_1;
|
|
$id_question_2=(int)$condition->id_question_2;
|
|
$id_question_3=(int)$condition->id_question_3;
|
|
$id_reponse_1=(int)$condition->id_reponse_1;
|
|
$id_reponse_2=(int)$condition->id_reponse_2;
|
|
$id_reponse_3=(int)$condition->id_reponse_3;
|
|
$id_product_1=(int)$condition->id_product_1;
|
|
$id_product_2=(int)$condition->id_product_2;
|
|
}
|
|
else{
|
|
$id_condition='';
|
|
$id_question_1='';
|
|
$id_question_2='';
|
|
$id_question_3='';
|
|
$id_reponse_1='';
|
|
$id_reponse_2='';
|
|
$id_reponse_3='';
|
|
$id_product_1='';
|
|
$id_product_2='';
|
|
}
|
|
|
|
|
|
|
|
|
|
$products=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT distinct(pl.id_product ),pl.name
|
|
FROM '._DB_PREFIX_.'product_lang pl
|
|
left join '._DB_PREFIX_.'category_product cp on(cp.id_product=pl.id_product)
|
|
WHERE id_lang=1
|
|
and (cp.id_category=14
|
|
or cp.id_category=15
|
|
or cp.id_category=16
|
|
or cp.id_category=17)
|
|
|
|
order by name asc');
|
|
|
|
/* Form */
|
|
$this->_html .= '<div style="width:900px;margin:0 auto">';
|
|
// if($table=="conditions")
|
|
$this->_html .= '<h2 style="text-align:center">Conditions de substitution des produits</h2>
|
|
<p>Sélectionnez le numéro de question, le numéro de réponse puis quel produit remplacera quel produit.</p>
|
|
<p>Vous pouvez aussi combiner 2 questions et réponses.</p>';
|
|
// else
|
|
// $this->_html .= '<h2 style="text-align:center">Exclusion des produits</h2><p>Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)</p>';
|
|
|
|
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
$this->_html .= '<input type="hidden" name="id_condition" value="'.$id_condition.'" id="id_condition" />';
|
|
|
|
/* Fieldset edit/add */
|
|
|
|
// foreach($products as $row)
|
|
// if(!in_array($id_product['id_product'],$fullProducts))
|
|
// $fullProducts[]=$row;
|
|
// print_r($productsSelected);
|
|
|
|
$this->_html .= '<fieldset class="width3" style="width:900px;margin:0 0 20px;">';
|
|
if($id_condition!='')
|
|
$this->_html .= '<legend>Condition : #'.$id_condition.'</legend>';
|
|
else
|
|
$this->_html .= '<legend>Nouvelle condition de substitution</legend>';
|
|
|
|
/* cat 14 */
|
|
$this->_html .= '
|
|
<label style="width:162px;text-align:left;">Si Question</label>';
|
|
$this->_html .= '<select name="id_question_1" style="margin:0 10px 0 10px">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_1==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select>';
|
|
$this->_html .= '<select name="id_reponse_1">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_1==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select> <sup>*</sup>';
|
|
|
|
$this->_html .= '
|
|
<br style="clear:both"/><br style="clear:both"/><label style="width:162px;text-align:left;">(Et si ...) Question</label>';
|
|
$this->_html .= '<select name="id_question_2" style="margin:0 10px">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_2==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select> ';
|
|
$this->_html .= '<select name="id_reponse_2">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_2==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select>';
|
|
|
|
$this->_html .= '
|
|
<br style="clear:both"/><br style="clear:both"/><label style="width:162px;text-align:left;">(Et si ...) Question</label>';
|
|
$this->_html .= '<select name="id_question_3" style="margin:0 10px">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_3==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select> ';
|
|
$this->_html .= '<select name="id_reponse_3">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_3==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select>';
|
|
|
|
|
|
$this->_html .= '<br style="clear:both"><br/><label style="width:170px;text-align:left;">Alors le produit n° <sup>*</sup></label><div class="margin-form" style="padding-left:180px">';
|
|
$this->_html .= '<select name="id_product_1">
|
|
<option value="">...</option>';
|
|
foreach ($products as $product)
|
|
{
|
|
$this->_html .= '<option value="'.$product['id_product'].'" '.($id_product_1==$product['id_product']?'selected="selected"':'').'>#'.$product['id_product'].' '.$product['name'].'</option>';
|
|
}
|
|
$this->_html .= '</select></div>';
|
|
|
|
|
|
$this->_html .= '<br style="clear:both"><label style="width:170px;text-align:left;">remplacera le produit n° <sup>*</sup></label><div class="margin-form" style="padding-left:180px">';
|
|
$this->_html .= '<select name="id_product_2">
|
|
<option value="">...</option>';
|
|
foreach ($products as $product)
|
|
{
|
|
$this->_html .= '<option value="'.$product['id_product'].'" '.($id_product_2==$product['id_product']?'selected="selected"':'').'>#'.$product['id_product'].' '.$product['name'].'</option>';
|
|
}
|
|
$this->_html .= '</select>';
|
|
|
|
|
|
$this->_html .= '</div>';
|
|
/* end cat 16 */
|
|
$this->_html .= '</fieldset>';
|
|
|
|
|
|
/* Save */
|
|
$this->_html .= '
|
|
<p style="padding-left:0;clear:both;">
|
|
<input type="submit" class="button" name="form'.$table.'" 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 obligatoires').'</p>
|
|
</fieldset>
|
|
</form>';
|
|
$this->_html .= '</div>';
|
|
}
|
|
private function _displayformreorientation($table="reorientation")
|
|
{
|
|
/* Sets item : depends if edited or added */
|
|
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
// devspediagnostic_croisement
|
|
|
|
|
|
$item = null;
|
|
if (Tools::getValue('id_reorientation'))
|
|
{
|
|
$reorientation = new Reorientations((int)Tools::getValue('id_reorientation'));
|
|
$id_reorientation=(int)$reorientation->id;
|
|
$id_question_1=(int)$reorientation->id_question_1;
|
|
$id_question_2=(int)$reorientation->id_question_2;
|
|
$id_question_3=(int)$reorientation->id_question_3;
|
|
$id_question_4=(int)$reorientation->id_question_4;
|
|
$id_reponse_1=(int)$reorientation->id_reponse_1;
|
|
$id_reponse_2=(int)$reorientation->id_reponse_2;
|
|
$id_reponse_3=(int)$reorientation->id_reponse_3;
|
|
$id_reponse_4=(int)$reorientation->id_reponse_4;
|
|
$id_product_1=(int)$reorientation->id_product_1;
|
|
// echo $id_question_1;
|
|
// die();
|
|
}
|
|
else{
|
|
$id_reorientation='';
|
|
$id_question_1='';
|
|
$id_question_2='';
|
|
$id_question_3='';
|
|
$id_question_4='';
|
|
$id_reponse_1='';
|
|
$id_reponse_2='';
|
|
$id_reponse_3='';
|
|
$id_reponse_4='';
|
|
$id_product_1='';
|
|
}
|
|
|
|
|
|
|
|
|
|
$products=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT distinct(pl.id_product ),pl.name
|
|
FROM '._DB_PREFIX_.'product_lang pl
|
|
left join '._DB_PREFIX_.'category_product cp on(cp.id_product=pl.id_product)
|
|
WHERE id_lang=1
|
|
and (cp.id_category=14
|
|
or cp.id_category=15
|
|
or cp.id_category=16
|
|
or cp.id_category=17)
|
|
|
|
order by name asc');
|
|
|
|
/* Form */
|
|
$this->_html .= '<div style="width:900px;margin:0 auto">';
|
|
// if($table=="conditions")
|
|
$this->_html .= '<h2 style="text-align:center">Conditions de réorientation</h2>
|
|
<p>Sélectionnez les numéro de questions , les numéros de réponses incohérents (1) (2) (3) puis sélectionnez la "bonne" question réponse et réponse (4)</p>';
|
|
// else
|
|
// $this->_html .= '<h2 style="text-align:center">Exclusion des produits</h2><p>Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)</p>';
|
|
|
|
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
$this->_html .= '<input type="hidden" name="id_reorientation" value="'.$id_reorientation.'" id="id_reorientation" />';
|
|
|
|
/* Fieldset edit/add */
|
|
|
|
// foreach($products as $row)
|
|
// if(!in_array($id_product['id_product'],$fullProducts))
|
|
// $fullProducts[]=$row;
|
|
// print_r($productsSelected);
|
|
|
|
$this->_html .= '<fieldset class="width3" style="width:900px;margin:0 0 20px;">';
|
|
if($id_reorientation!='')
|
|
$this->_html .= '<legend>Réorientation : #'.$id_reorientation.'</legend>';
|
|
else
|
|
$this->_html .= '<legend>Nouvelle reorientation de substitution</legend>';
|
|
|
|
/* cat 14 */
|
|
$this->_html .= '
|
|
<div style="float: left;width:800px;padding:0 10px 0 0px;margin:0 10px 0px 0;">
|
|
<div style="float:left;widht:auto;margin:0 60px 0 0;">
|
|
<label style="width:auto;text-align:left;">Question (1) #</label>';
|
|
$this->_html .= '<select name="id_question_1" style="margin:0 20px 0 00px">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_1==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select>';
|
|
$this->_html .= '<select name="id_reponse_1">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_1==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select> <sup>*</sup>
|
|
</div>
|
|
<br style="clear:both;"/>
|
|
<br style="clear:both;"/>';
|
|
|
|
$this->_html .= '<div style="float:left;clear:both;width:400px;padding:0 0px 0 0px;margin:0 0px 0px 0;">
|
|
<label style="width:auto;text-align:left;">Question (2) #</label>';
|
|
$this->_html .= '<select name="id_question_2" style="margin:0 20px 0 0">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_2==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select>';
|
|
$this->_html .= '<select name="id_reponse_2">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_2==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select> <sup>*</sup>
|
|
</div>
|
|
<br style="clear:both;"/>
|
|
<br style="clear:both;"/>
|
|
';
|
|
$this->_html .= '<div style="float:left;clear:both;width:400px;padding:0 0px 0 0px;margin:0 0px 0px 0;">
|
|
<label style="width:auto;text-align:left;">Question (3) #</label>';
|
|
$this->_html .= '<select name="id_question_3" style="margin:0 20px 0 0">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_3==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select>';
|
|
$this->_html .= '<select name="id_reponse_3">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_3==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select> <sup>*</sup>
|
|
</div>';
|
|
$this->_html .= '
|
|
<br style="clear:both;"/>
|
|
<br style="clear:both;"/><div style="float:left;clear:both;width:400px;padding:0 0px 0 0px;margin:0 0px 0px 0;">
|
|
<label style="width:auto;text-align:left;">Question (4) #</label>';
|
|
$this->_html .= '<select name="id_question_4" style="margin:0 20px 0 0">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_4==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select>';
|
|
$this->_html .= '<select name="id_reponse_4">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_4==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select> <sup>*</sup>
|
|
</div>
|
|
</div>';
|
|
|
|
|
|
// $this->_html .= '<div style="display:none"><br style="clear:both"><br/><div style="float: left;width:auto;padding:0 10px 0 0px;margin:0 10px 20px 0;"><label style="width:230px;text-align:left;">La réponse (1) devient la réponse </label><div class="margin-form" style="padding-left:244px">';
|
|
// $this->_html .= '<select name="id_product_1"><option value="6">Rép</option>';
|
|
// for($i=1;$i<6;$i++){
|
|
// if($i==1)$lettre="A";
|
|
// if($i==2)$lettre="B";
|
|
// if($i==3)$lettre="C";
|
|
// if($i==4)$lettre="D";
|
|
// if($i==5)$lettre="E";
|
|
// $this->_html .= '
|
|
// <option value="'.$i.'" '.($id_product_1==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
// }
|
|
// $this->_html .= '</select></div></div></div>';
|
|
|
|
/* end cat 16 */
|
|
$this->_html .= '</fieldset>';
|
|
|
|
|
|
/* Save */
|
|
$this->_html .= '
|
|
<p style="padding-left:0;clear:both;">
|
|
<input type="submit" class="button" name="form'.$table.'" 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 obligatoires').'</p>
|
|
</fieldset>
|
|
</form>';
|
|
$this->_html .= '</div>';
|
|
}
|
|
private function _displayFormMasquerquestions($table="masquerquestion")
|
|
{
|
|
/* Sets item : depends if edited or added */
|
|
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
// devspediagnostic_croisement
|
|
|
|
|
|
$item = null;
|
|
if (Tools::getValue('id_masquerquestion'))
|
|
{
|
|
$masquerquestion = new Masquerquestions((int)Tools::getValue('id_masquerquestion'));
|
|
$id_masquerquestion=(int)$masquerquestion->id;
|
|
$id_question_1=(int)$masquerquestion->id_question_1;
|
|
$id_question_2=(int)$masquerquestion->id_question_2;
|
|
$id_reponse_1=(int)$masquerquestion->id_reponse_1;
|
|
}
|
|
else{
|
|
$id_masquerquestion='';
|
|
$id_question_1='';
|
|
$id_question_2='';
|
|
$id_reponse_1='';
|
|
}
|
|
|
|
|
|
/* Form */
|
|
$this->_html .= '<div style="width:900px;margin:0 auto">';
|
|
// if($table=="conditions")
|
|
$this->_html .= '<h2 style="text-align:center">Question à masquer</h2>
|
|
<p>Sélectionnez le numéro de question, le numéro de réponse puis la question à masquer.</p>';
|
|
// else
|
|
// $this->_html .= '<h2 style="text-align:center">Exclusion des produits</h2><p>Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)</p>';
|
|
|
|
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
$this->_html .= '<input type="hidden" name="id_masquerquestion" value="'.$id_masquerquestion.'" id="id_masquerquestion" />';
|
|
|
|
/* Fieldset edit/add */
|
|
|
|
// foreach($products as $row)
|
|
// if(!in_array($id_product['id_product'],$fullProducts))
|
|
// $fullProducts[]=$row;
|
|
// print_r($productsSelected);
|
|
|
|
$this->_html .= '<fieldset class="width3" style="width:900px;margin:0 0 20px;">';
|
|
if($id_masquerquestion!='')
|
|
$this->_html .= '<legend>Condition : #'.$id_masquerquestion.'</legend>';
|
|
else
|
|
$this->_html .= '<legend>Nouvelle condition de masquage</legend>';
|
|
|
|
/* cat 14 */
|
|
$this->_html .= '
|
|
<div style="float: left;width:800px;padding:0 10px 0 0px;margin:0 10px 0px 0;">
|
|
<div style="float:left;widht:auto;margin:0 60px 0 0;">
|
|
<label style="width:auto;text-align:left;">Si Question : </label>';
|
|
$this->_html .= '<select name="id_question_1" style="margin:0 10px 0 10px">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_1==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select>';
|
|
$this->_html .= '<select name="id_reponse_1">
|
|
<option value="">Rép</option>';
|
|
for($i=1;$i<6;$i++){
|
|
if($i==1)$lettre="A";
|
|
if($i==2)$lettre="B";
|
|
if($i==3)$lettre="C";
|
|
if($i==4)$lettre="D";
|
|
if($i==5)$lettre="E";
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_reponse_1==$i?'selected="selected"':'').'>'.$lettre.'</option>';
|
|
}
|
|
$this->_html .= '</select>
|
|
</div>';
|
|
|
|
$this->_html .= '<div style="clear:both;width:400px;padding:0 0px 0 0px;margin:0 0px 0px 0;">
|
|
<br/><label style="width:auto;text-align:left;"> Question à masquer : </label>';
|
|
$this->_html .= '<select name="id_question_2" style="margin:0 20px">
|
|
<option value=""> n° </option>';
|
|
for($i=1;$i<16;$i++)
|
|
$this->_html .= '
|
|
<option value="'.$i.'" '.($id_question_2==$i?'selected="selected"':'').'>'.$i.'</option>';
|
|
$this->_html .= '</select>
|
|
</div>';
|
|
|
|
|
|
$this->_html .= '</div>';
|
|
/* end cat 16 */
|
|
$this->_html .= '</fieldset>';
|
|
|
|
|
|
/* Save */
|
|
$this->_html .= '
|
|
<p style="padding-left:0;clear:both;">
|
|
<input type="submit" class="button" name="form'.$table.'" 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 obligatoires').'</p>
|
|
</fieldset>
|
|
</form>';
|
|
$this->_html .= '</div>';
|
|
}
|
|
private function _displayFormSubtitutions($table="substitutions")
|
|
{
|
|
/* Sets item : depends if edited or added */
|
|
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
// devspediagnostic_croisement
|
|
|
|
|
|
$item = null;
|
|
if (Tools::getValue('id_substitution'))
|
|
{
|
|
$substitution = new Substitutions((int)Tools::getValue('id_substitution'));
|
|
$id_substitution=(int)$substitution->id;
|
|
$id_product_1=(int)$substitution->id_product_1;
|
|
$id_product_2=(int)$substitution->id_product_2;
|
|
}
|
|
else{
|
|
$id_substitution='';
|
|
$id_product_1='';
|
|
$id_product_2='';
|
|
}
|
|
|
|
|
|
|
|
|
|
$products=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT distinct(pl.id_product ),pl.name
|
|
FROM '._DB_PREFIX_.'product_lang pl
|
|
left join '._DB_PREFIX_.'category_product cp on(cp.id_product=pl.id_product)
|
|
WHERE id_lang=1
|
|
and (cp.id_category=14
|
|
or cp.id_category=15
|
|
or cp.id_category=16
|
|
or cp.id_category=17)
|
|
|
|
order by name asc');
|
|
|
|
/* Form */
|
|
$this->_html .= '<div style="width:900px;margin:0 auto">';
|
|
// if($table=="conditions")
|
|
$this->_html .= '<h2 style="text-align:center">Substitution des produits dans un même rituel</h2>';
|
|
// <p>Si le produit 1 se trouve dans le même rituel que le produit 2, alors le produit 1 ne s\'affichera pas</p>
|
|
// else
|
|
// $this->_html .= '<h2 style="text-align:center">Exclusion des produits</h2><p>Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)</p>';
|
|
|
|
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
$this->_html .= '<input type="hidden" name="id_substitution" value="'.$id_substitution.'" id="id_substitution" />';
|
|
|
|
/* Fieldset edit/add */
|
|
|
|
// foreach($products as $row)
|
|
// if(!in_array($id_product['id_product'],$fullProducts))
|
|
// $fullProducts[]=$row;
|
|
// print_r($productsSelected);
|
|
|
|
$this->_html .= '<fieldset class="width3" style="width:900px;margin:0 0 20px;">';
|
|
if($id_substitution!='')
|
|
$this->_html .= '<legend>Substitution : #'.$id_substitution.'</legend>';
|
|
else
|
|
$this->_html .= '<legend>Nouvelle substitution de produits dans un même rituel</legend>';
|
|
|
|
$this->_html .= '<br style="clear:both"><br/><div style="float: left;width:100%;padding:0px;margin:0 0px 20px 0;"><label style="width:110px;text-align:left;">Le produit n° <sup>*</sup></label><div class="margin-form" style="padding-left:120px">';
|
|
$this->_html .= '<select name="id_product_1">
|
|
<option value="">...</option>';
|
|
foreach ($products as $product)
|
|
{
|
|
$this->_html .= '<option value="'.$product['id_product'].'" '.($id_product_1==$product['id_product']?'selected="selected"':'').'>#'.$product['id_product'].' '.$product['name'].'</option>';
|
|
}
|
|
$this->_html .= '</select>
|
|
<label style="text-align:left;width:auto;float:none;margin:0 0 0 40px">ne sera pas affiché </label>
|
|
</div>';
|
|
|
|
|
|
$this->_html .= '<br style="clear:both">
|
|
|
|
<br/>
|
|
<br/>
|
|
<div style="clear:both;padding:0 10px 0 0px;margin:0 10px 20px 0;">
|
|
<label style="width:110px;text-align:left;">Si le produit n° : </label>
|
|
<div class="margin-form" style="padding-left:120px">';
|
|
$this->_html .= '<select name="id_product_2">
|
|
<option value="">...</option>';
|
|
foreach ($products as $product)
|
|
{
|
|
$this->_html .= '<option value="'.$product['id_product'].'" '.($id_product_2==$product['id_product']?'selected="selected"':'').'>#'.$product['id_product'].' '.$product['name'].'</option>';
|
|
}
|
|
$this->_html .= '</select><label style="width:auto;float:none;text-align:left;width:auto;margin:0 0 0 40px"> se trouve dans le même rituel </label></div>';
|
|
|
|
|
|
$this->_html .= '</div>
|
|
|
|
|
|
';
|
|
|
|
/* end cat 16 */
|
|
$this->_html .= '</fieldset>';
|
|
|
|
|
|
/* Save */
|
|
$this->_html .= '
|
|
<p style="padding-left:0;clear:both;">
|
|
<input type="submit" class="button" name="form'.$table.'" 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 .= '
|
|
</fieldset>
|
|
</form>';
|
|
$this->_html .= '</div>';
|
|
}
|
|
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 Diagnostic((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 = 'iimage¤image¤title¤url¤legend¤description';
|
|
$divLangName = 'questionn¤repAA¤repBB¤repCC¤repDD¤repEE¤texterepA¤texterepB¤texterepC¤texterepD¤texterepE';
|
|
$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::isSubmit('additem')) /* Configure legend */
|
|
$this->_html .= '<legend><'.$this->l('Question').'</legend>';
|
|
elseif (Tools::isSubmit('id_item')) /* Edit legend */
|
|
$this->_html .= '<legend>'.$this->l('Modification de la question').' #'.$item->id.'</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" />';
|
|
|
|
/* Form content */
|
|
|
|
/* Title */
|
|
$this->_html .= '<label>'.$this->l('Titre :').' * </label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="questionn_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="question_'.$language['id_lang'].'" id="question_'.$language['id_lang'].'" size="70" value="'.(isset($item->question[$language['id_lang']]) ? $item->question[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'questionn', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
/* repA */
|
|
$this->_html .= '<label>'.$this->l('Réponse A :').' * </label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="repAA_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="repA_'.$language['id_lang'].'" id="repA_'.$language['id_lang'].'" size="70" value="'.(isset($item->repA[$language['id_lang']]) ? $item->repA[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repAA', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
$this->_html .= '
|
|
<label style="width:160px">'.$this->l('Texte Popin A :').' </label>
|
|
<div class="margin-form" style="padding-left:160px">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '<div id="texterepA_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<textarea class="rte" name="texterepA_'.$language['id_lang'].'" rows="10" cols="29">'.(isset($item->texterepA[$language['id_lang']]) ? $item->texterepA[$language['id_lang']] : '').'</textarea>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepA', true);
|
|
$this->_html .= '</div><div class="clear"></div><br />';
|
|
|
|
/* repB */
|
|
$this->_html .= '<label>'.$this->l('Réponse B :').' * </label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="repBB_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="repB_'.$language['id_lang'].'" id="repB_'.$language['id_lang'].'" size="70" value="'.(isset($item->repB[$language['id_lang']]) ? $item->repB[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repBB', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
$this->_html .= '
|
|
<label style="width:160px">'.$this->l('Texte Popin B :').' </label>
|
|
<div class="margin-form" style="padding-left:160px">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '<div id="texterepB_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<textarea class="rte" name="texterepB_'.$language['id_lang'].'" rows="10" cols="29">'.(isset($item->texterepB[$language['id_lang']]) ? $item->texterepB[$language['id_lang']] : '').'</textarea>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepB', true);
|
|
$this->_html .= '</div><div class="clear"></div><br />';
|
|
|
|
|
|
/* repC */
|
|
$this->_html .= '<label>'.$this->l('Réponse C :').'</label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="repCC_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="repC_'.$language['id_lang'].'" id="repC_'.$language['id_lang'].'" size="70" value="'.(isset($item->repC[$language['id_lang']]) ? $item->repC[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repCC', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
$this->_html .= '
|
|
<label style="width:160px">'.$this->l('Texte Popin C :').' </label>
|
|
<div class="margin-form" style="padding-left:160px">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '<div id="texterepC_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<textarea class="rte" name="texterepC_'.$language['id_lang'].'" rows="10" cols="29">'.(isset($item->texterepC[$language['id_lang']]) ? $item->texterepC[$language['id_lang']] : '').'</textarea>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepC', true);
|
|
$this->_html .= '</div><div class="clear"></div><br />';
|
|
|
|
/* repD */
|
|
$this->_html .= '<label>'.$this->l('Réponse D :').' </label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="repDD_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="repD_'.$language['id_lang'].'" id="repD_'.$language['id_lang'].'" size="70" value="'.(isset($item->repD[$language['id_lang']]) ? $item->repD[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repDD', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
$this->_html .= '
|
|
<label style="width:160px">'.$this->l('Texte Popin D :').' </label>
|
|
<div class="margin-form" style="padding-left:160px">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '<div id="texterepD_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<textarea class="rte" name="texterepD_'.$language['id_lang'].'" rows="10" cols="29">'.(isset($item->texterepD[$language['id_lang']]) ? $item->texterepD[$language['id_lang']] : '').'</textarea>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepD', true);
|
|
$this->_html .= '</div><div class="clear"></div><br />';
|
|
|
|
|
|
/* repE */
|
|
$this->_html .= '<label>'.$this->l('Réponse E :').' </label><div class="margin-form">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '
|
|
<div id="repEE_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<input type="text" name="repE_'.$language['id_lang'].'" id="repE_'.$language['id_lang'].'" size="70" value="'.(isset($item->repE[$language['id_lang']]) ? $item->repE[$language['id_lang']] : '').'"/>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repEE', true);
|
|
$this->_html .= '</div><br /><br />';
|
|
|
|
$this->_html .= '
|
|
<label style="width:160px">'.$this->l('Texte Popin E :').' </label>
|
|
<div class="margin-form" style="padding-left:160px">';
|
|
foreach ($languages as $language)
|
|
{
|
|
$this->_html .= '<div id="texterepE_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
|
|
<textarea class="rte" name="texterepE_'.$language['id_lang'].'" rows="10" cols="29">'.(isset($item->texterepE[$language['id_lang']]) ? $item->texterepE[$language['id_lang']] : '').'</textarea>
|
|
</div>';
|
|
}
|
|
$this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepE', true);
|
|
$this->_html .= '</div><div class="clear"></div><br />';
|
|
|
|
|
|
/* Active */
|
|
$this->_html .= '
|
|
<div style="display:none"><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_item" id="active_on" checked="checked value="1" checked="checked" />
|
|
<label class="t" for="active_on">'.$this->l('Yes').'</label>
|
|
</div></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 oblgiatoires').'</p>
|
|
</fieldset>
|
|
</form>';
|
|
}
|
|
|
|
private function _postValidation()
|
|
{
|
|
$errors = array();
|
|
|
|
/* Validation for itemz configuration */
|
|
if (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('question_'.$language['id_lang'])) > 255)
|
|
$errors[] = $this->l('The title is too long.');
|
|
}
|
|
|
|
/* Checks title/url/legend/description for default lang */
|
|
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
if (Tools::strlen(Tools::getValue('question_'.$id_lang_default)) == 0)
|
|
$errors[] = $this->l('The title is not set.');
|
|
} /* 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 itemz */
|
|
if (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_item'))
|
|
{
|
|
$item = new Diagnostic((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 Diagnostic((int)Tools::getValue('id_item'));
|
|
if (!Validate::isLoadedObject($item))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_item'));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
$item = new Diagnostic();
|
|
/* Sets position */
|
|
$item->position = (int)Tools::getValue('position');
|
|
// $item->id_product = (int)Tools::getValue('id_product');
|
|
/* Sets active */
|
|
$item->active = 1;
|
|
|
|
/* Sets each langue fields */
|
|
$languages = Language::getLanguages(false);
|
|
foreach ($languages as $language)
|
|
{
|
|
$item->question[$language['id_lang']] = Tools::getValue('question_'.$language['id_lang']);
|
|
$item->repA[$language['id_lang']] = Tools::getValue('repA_'.$language['id_lang']);
|
|
$item->repB[$language['id_lang']] = Tools::getValue('repB_'.$language['id_lang']);
|
|
$item->repC[$language['id_lang']] = Tools::getValue('repC_'.$language['id_lang']);
|
|
$item->repD[$language['id_lang']] = Tools::getValue('repD_'.$language['id_lang']);
|
|
$item->repE[$language['id_lang']] = Tools::getValue('repE_'.$language['id_lang']);
|
|
$item->texterepA[$language['id_lang']] = Tools::getValue('texterepA_'.$language['id_lang']);
|
|
$item->texterepB[$language['id_lang']] = Tools::getValue('texterepB_'.$language['id_lang']);
|
|
$item->texterepC[$language['id_lang']] = Tools::getValue('texterepC_'.$language['id_lang']);
|
|
$item->texterepD[$language['id_lang']] = Tools::getValue('texterepD_'.$language['id_lang']);
|
|
$item->texterepE[$language['id_lang']] = Tools::getValue('texterepE_'.$language['id_lang']);
|
|
}
|
|
// print_r($item);
|
|
|
|
/* 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 Diagnostic((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'));
|
|
}
|
|
private function _postProcessConditions()
|
|
{
|
|
$errors = array();
|
|
|
|
/* Processes itemz */
|
|
if (Tools::isSubmit('formconditions'))
|
|
{
|
|
// $item = new ConditioQn((int)Tools::getValue('id_condition'));
|
|
// $res = $item->update();
|
|
// $this->clearCache();
|
|
// $this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
|
|
|
/* Sets ID if needed */
|
|
if (Tools::getValue('id_condition'))
|
|
{
|
|
$item = new Conditions((int)Tools::getValue('id_condition'));
|
|
if (!Validate::isLoadedObject($item))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_condition'));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
$item = new Conditions();
|
|
// $item->active = 1;
|
|
|
|
/* Sets each langue fields */
|
|
// $languages = Language::getLanguages(false);
|
|
// foreach ($languages as $language)
|
|
// {
|
|
$item->id_question_1 = Tools::getValue('id_question_1');
|
|
$item->id_question_2 = Tools::getValue('id_question_2');
|
|
$item->id_question_3 = Tools::getValue('id_question_3');
|
|
$item->id_reponse_1 = Tools::getValue('id_reponse_1');
|
|
$item->id_reponse_2 = Tools::getValue('id_reponse_2');
|
|
$item->id_reponse_3 = Tools::getValue('id_reponse_3');
|
|
$item->id_product_1 = Tools::getValue('id_product_1');
|
|
$item->id_product_2 = Tools::getValue('id_product_2');
|
|
// }
|
|
// print_r($errors);
|
|
// die();
|
|
/* Processes if no errors */
|
|
if (!$errors)
|
|
{
|
|
/* Adds */
|
|
if (!Tools::getValue('id_condition'))
|
|
{
|
|
if (!$item->add())
|
|
$errors[] = $this->displayError($this->l('The item could not be added.'));
|
|
// echo Tools::getValue('id_condition');
|
|
// echo "test";
|
|
// die();
|
|
}
|
|
/* Update */
|
|
elseif (!$item->update())
|
|
$errors[] = $this->displayError($this->l('The item could not be updated.'));
|
|
$this->clearCache();
|
|
}
|
|
} /* Deletes */
|
|
elseif (Tools::getValue('delete_id_condition'))
|
|
{
|
|
$item = new Conditions((int)Tools::getValue('delete_id_condition'));
|
|
$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('formconditions') && Tools::getValue('id_condition'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item updated'));
|
|
elseif (Tools::isSubmit('formconditions'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item added'));
|
|
}
|
|
private function _postProcessReorientations()
|
|
{
|
|
$errors = array();
|
|
|
|
/* Processes itemz */
|
|
if (Tools::isSubmit('formreorientation'))
|
|
{
|
|
// $item = new ConditioQn((int)Tools::getValue('id_reorientation'));
|
|
// $res = $item->update();
|
|
// $this->clearCache();
|
|
// $this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
|
|
|
/* Sets ID if needed */
|
|
if (Tools::getValue('id_reorientation'))
|
|
{
|
|
$item = new reorientations((int)Tools::getValue('id_reorientation'));
|
|
if (!Validate::isLoadedObject($item))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_reorientation'));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
$item = new reorientations();
|
|
// $item->active = 1;
|
|
|
|
/* Sets each langue fields */
|
|
// $languages = Language::getLanguages(false);
|
|
// foreach ($languages as $language)
|
|
// {
|
|
$item->id_question_1 = Tools::getValue('id_question_1');
|
|
$item->id_question_2 = Tools::getValue('id_question_2');
|
|
$item->id_reponse_1 = Tools::getValue('id_reponse_1');
|
|
$item->id_reponse_2 = Tools::getValue('id_reponse_2');
|
|
$item->id_question_3 = Tools::getValue('id_question_3');
|
|
$item->id_question_4 = Tools::getValue('id_question_4');
|
|
$item->id_reponse_3 = Tools::getValue('id_reponse_3');
|
|
$item->id_reponse_4 = Tools::getValue('id_reponse_4');
|
|
// }
|
|
// print_r($errors);
|
|
// die();
|
|
/* Processes if no errors */
|
|
if (!$errors)
|
|
{
|
|
/* Adds */
|
|
if (!Tools::getValue('id_reorientation'))
|
|
{
|
|
if (!$item->add())
|
|
$errors[] = $this->displayError($this->l('The item could not be added.'));
|
|
// echo Tools::getValue('id_reorientation');
|
|
// echo "test";
|
|
// die();
|
|
}
|
|
/* Update */
|
|
elseif (!$item->update())
|
|
$errors[] = $this->displayError($this->l('The item could not be updated.'));
|
|
$this->clearCache();
|
|
}
|
|
} /* Deletes */
|
|
elseif (Tools::getValue('delete_id_reorientation'))
|
|
{
|
|
$item = new reorientations((int)Tools::getValue('delete_id_reorientation'));
|
|
$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('formreorientation') && Tools::getValue('id_reorientation'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item updated'));
|
|
elseif (Tools::isSubmit('formreorientation'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item added'));
|
|
}
|
|
private function _postProcessMasquerquestions()
|
|
{
|
|
$errors = array();
|
|
|
|
/* Processes itemz */
|
|
if (Tools::isSubmit('formmasquerquestion'))
|
|
{
|
|
// $item = new ConditioQn((int)Tools::getValue('id_condition'));
|
|
// $res = $item->update();
|
|
// $this->clearCache();
|
|
// $this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
|
|
|
/* Sets ID if needed */
|
|
if (Tools::getValue('id_masquerquestion'))
|
|
{
|
|
$item = new Masquerquestions((int)Tools::getValue('id_masquerquestion'));
|
|
if (!Validate::isLoadedObject($item))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_masquerquestion'));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
$item = new Masquerquestions();
|
|
// $item->active = 1;
|
|
|
|
/* Sets each langue fields */
|
|
// $languages = Language::getLanguages(false);
|
|
// foreach ($languages as $language)
|
|
// {
|
|
$item->id_question_1 = Tools::getValue('id_question_1');
|
|
$item->id_question_2 = Tools::getValue('id_question_2');
|
|
$item->id_reponse_1 = Tools::getValue('id_reponse_1');
|
|
if($item->id_question_1==$item->id_question_2){
|
|
$errors[] = $this->displayError($this->l('Les questions doivent être différentes'));
|
|
return;
|
|
}
|
|
|
|
// }
|
|
// print_r($errors);
|
|
// die();
|
|
/* Processes if no errors */
|
|
if (!$errors)
|
|
{
|
|
/* Adds */
|
|
if (!Tools::getValue('id_masquerquestion'))
|
|
{
|
|
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::getValue('delete_id_masquerquestion'))
|
|
{
|
|
$item = new Masquerquestions((int)Tools::getValue('delete_id_masquerquestion'));
|
|
$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('formmasquerquestions') && Tools::getValue('id_masquerquestion'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item updated'));
|
|
elseif (Tools::isSubmit('formmasquerquestions'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item added'));
|
|
}
|
|
private function _postProcessSubstitutions()
|
|
{
|
|
$errors = array();
|
|
|
|
/* Processes itemz */
|
|
if (Tools::isSubmit('formsubstitutions'))
|
|
{
|
|
// $item = new ConditioQn((int)Tools::getValue('id_condition'));
|
|
// $res = $item->update();
|
|
// $this->clearCache();
|
|
// $this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
|
|
|
|
/* Sets ID if needed */
|
|
if (Tools::getValue('id_substitution'))
|
|
{
|
|
$item = new Substitutions((int)Tools::getValue('id_substitution'));
|
|
if (!Validate::isLoadedObject($item))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_substitution'));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
$item = new Substitutions();
|
|
|
|
$item->id_product_1 = Tools::getValue('id_product_1');
|
|
$item->id_product_2 = Tools::getValue('id_product_2');
|
|
if($item->id_product_1 == $item->id_product_2){
|
|
$this->_html .= $this->displayError($this->l('Les produits doivent être différents'));
|
|
return;
|
|
}
|
|
/* Processes if no errors */
|
|
if (!$errors)
|
|
{
|
|
/* Adds */
|
|
if (!Tools::getValue('id_substitution'))
|
|
{
|
|
if (!$item->add())
|
|
$errors[] = $this->displayError($this->l('The item could not be added.'));
|
|
// echo Tools::getValue('id_condition');
|
|
// echo "test";
|
|
// die();
|
|
}
|
|
/* Update */
|
|
elseif (!$item->update())
|
|
$errors[] = $this->displayError($this->l('The item could not be updated.'));
|
|
$this->clearCache();
|
|
}
|
|
} /* Deletes */
|
|
elseif (Tools::getValue('delete_id_substitution'))
|
|
{
|
|
$item = new Substitutions((int)Tools::getValue('delete_id_substitution'));
|
|
$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('formsubstitutions') && Tools::getValue('id_substitution'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item updated'));
|
|
elseif (Tools::isSubmit('formsubstitutions'))
|
|
$this->_html .= $this->displayConfirmation($this->l('item added'));
|
|
}
|
|
private function _postProcessProducts($type="croisement")
|
|
{
|
|
$errors = array();
|
|
|
|
// products_'.$id_item.$lettre.'[]
|
|
|
|
/* Processes item */
|
|
if (Tools::isSubmit('form'.$type) && $type=="croisement" || $type=="exclusion")
|
|
{
|
|
/* Sets ID if needed */
|
|
if (Tools::getValue('id_item'))
|
|
{
|
|
$item = new Diagnostic((int)Tools::getValue('id_item'));
|
|
if (!Validate::isLoadedObject($item))
|
|
{
|
|
$this->_html .= $this->displayError($this->l('Invalid id_item'));
|
|
return;
|
|
}
|
|
$id_item=(int)Tools::getValue('id_item');
|
|
$lettres=Tools::getValue('lettre');
|
|
foreach($lettres as $lettre){
|
|
if($lettre=="A")$id_reponse=1;
|
|
if($lettre=="B")$id_reponse=2;
|
|
if($lettre=="C")$id_reponse=3;
|
|
if($lettre=="D")$id_reponse=4;
|
|
if($lettre=="E")$id_reponse=5;
|
|
Db::getInstance()->execute('delete from '._DB_PREFIX_.'devspediagnostic_'.$type.' where id_item='.$id_item.' and id_reponse='.$id_reponse);
|
|
// echo 'delete from '._DB_PREFIX_.'devspediagnostic_'.$type.' where id_item='.$id_item.' and id_reponse='.$id_reponse;
|
|
// echo '<br/>';
|
|
// CAT 14
|
|
for($i=14;$i<=17;$i++){
|
|
$produits=array();
|
|
if($products=$_POST['products_'.$id_item.$lettre.'_'.$i])
|
|
foreach($products as $id_product){
|
|
// if(!in_array($id_product,$produits)){
|
|
// $produits[]=(int)$id_product;
|
|
Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'devspediagnostic_'.$type.' (id_item,id_reponse, id_product,id_category) values ('.$id_item.','.$id_reponse.','.$id_product.','.$i.')');
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
$this->_html .= $this->displayConfirmation($this->l('Mise à jour effectuée'));
|
|
// die();
|
|
// products_'.$id_item.$lettre.'[];
|
|
}
|
|
else{
|
|
// $item = new Diagnostic();
|
|
$this->_html .= $this->displayError($this->l('Invalid id_item'));
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function _prepareHook()
|
|
{
|
|
if (!$this->isCached('devspediagnostic.tpl', $this->getCacheId()))
|
|
{
|
|
$items = $this->getitems(true);
|
|
if (!$items)
|
|
return false;
|
|
|
|
$this->smarty->assign('devspediagnostic_items', $items);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function hookDisplayHome()
|
|
{
|
|
/*
|
|
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.bxitemz.min.js');
|
|
$this->context->controller->addCSS($this->_path.'devspediagnostic.css');
|
|
$this->context->controller->addJS($this->_path.'js/devspediagnostic.js');
|
|
return $this->display(__FILE__, 'devspediagnostic.tpl', $this->getCacheId());
|
|
*/
|
|
}
|
|
|
|
public function clearCache()
|
|
{
|
|
$this->_clearCache('devspediagnostic.tpl');
|
|
}
|
|
|
|
public function hookActionShopDataDuplication($params)
|
|
{
|
|
Db::getInstance()->execute('
|
|
INSERT IGNORE INTO '._DB_PREFIX_.'devspediagnostic (id_item, id_shop)
|
|
SELECT id_item, '.(int)$params['new_id_shop'].'
|
|
FROM '._DB_PREFIX_.'devspediagnostic
|
|
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 'items configuration' */
|
|
$html = '
|
|
<style>
|
|
#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" src="'.__PS_BASE_URI__.'js/jquery/jquery-ui.will.be.removed.in.1.6.js"></script>
|
|
<script type="text/javascript">
|
|
/*$(function() {
|
|
var $myitems = $("#items");
|
|
$myitems.sortable({
|
|
opacity: 0.6,
|
|
cursor: "move",
|
|
update: function() {
|
|
var order = $(this).sortable("serialize") + "&action=updateitemsPosition";
|
|
// alert(order);
|
|
$.post("'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax_'.$this->name.'.php?secure_key='.$this->secure_key.'", order);
|
|
}
|
|
});
|
|
$myitems.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_.'devspediagnostic_items` hss');
|
|
|
|
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 hss.`id_item` as id_item,
|
|
hss.`position`,
|
|
hss.`active`,
|
|
hssl.`question`,
|
|
hssl.`repA`,
|
|
hssl.`repB`,
|
|
hssl.`repC`,
|
|
hssl.`repD`,
|
|
hssl.`repE`,
|
|
hssl.`texterepA`,
|
|
hssl.`texterepB`,
|
|
hssl.`texterepC`,
|
|
hssl.`texterepD`,
|
|
hssl.`texterepE`
|
|
FROM '._DB_PREFIX_.'devspediagnostic_items hss
|
|
LEFT JOIN '._DB_PREFIX_.'devspediagnostic_items_lang hssl ON (hss.id_item = hssl.id_item)
|
|
WHERE hssl.id_lang = '.(int)$id_lang.'
|
|
ORDER BY hss.position asc');
|
|
// ($active ? ' AND hss.`active` = 1' : ' ')
|
|
}
|
|
public function getitemsMasquerquestions($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 *
|
|
FROM '._DB_PREFIX_.'devspediagnostic_masquerquestions
|
|
ORDER BY id_masquerquestion asc');
|
|
// ($active ? ' AND hss.`active` = 1' : ' ')
|
|
}
|
|
public function getitemsConditions($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 *
|
|
FROM '._DB_PREFIX_.'devspediagnostic_conditions
|
|
ORDER BY id_condition asc');
|
|
// ($active ? ' AND hss.`active` = 1' : ' ')
|
|
}
|
|
public function getitemsReorientations($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 *
|
|
FROM '._DB_PREFIX_.'devspediagnostic_reorientations
|
|
ORDER BY id_reorientation asc');
|
|
// ($active ? ' AND hss.`active` = 1' : ' ')
|
|
}
|
|
public function getitemsSubstitution($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 *
|
|
FROM '._DB_PREFIX_.'devspediagnostic_substitutions
|
|
ORDER BY id_substitution asc');
|
|
// ($active ? ' AND hss.`active` = 1' : ' ')
|
|
}
|
|
|
|
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 hss.`id_item` as id_item
|
|
FROM `'._DB_PREFIX_.'devspediagnostic_items` hss
|
|
WHERE hss.`id_item` = '.(int)$id_item;
|
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
|
|
return ($row);
|
|
}
|
|
}
|