* @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 .= ' '; else { $this->_html .= ' '; } $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 .= '

'.$this->displayName.'

'; $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 .= '

'.$this->displayName.'

'; $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 .= '

'.$this->displayName.'

'; $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 .= '
'.$this->l('Gestion des questions du diagnostic').' '.$this->l('Ajouter un item').' '; /* Display notice if there are no items yet */ if (!$items) $this->_html .= '

'.$this->l('Vous n\'avez aucune question enregistrée').'

'; else /* Display items */ { $this->_html .= '
'; } // End fieldset $this->_html .= '


'; } private function _displayFormConditionsList() { /* Gets items */ $items = $this->getitemsConditions(); /* Begin fieldset items */ $this->_html .= '
'.$this->l('Gestion des conditions de substitution de produits').' '.$this->l('Ajouter une condition').' '; /* Display notice if there are no items yet */ if (!$items) $this->_html .= '

'.$this->l('Vous n\'avez aucune condition enregistrée').'

'; else /* Display items */ { $this->_html .= '
'; } // End fieldset $this->_html .= '
'; } private function _displayformreorientationList() { /* Gets items */ $items = $this->getitemsReorientations(); /* Begin fieldset items */ $this->_html .= '

'.$this->l('Gestion des réorientations des réponses incohérentes').' '.$this->l('Ajouter une condition de réorientation').' '; /* Display notice if there are no items yet */ if (!$items) $this->_html .= '

'.$this->l('Vous n\'avez aucune condition de réorientation enregistrée').'

'; else /* Display items */ { $this->_html .= '
'; } // End fieldset $this->_html .= '
'; } private function _displayFormMasquerquestionList() { /* Gets items */ $items = $this->getitemsMasquerquestions(); /* Begin fieldset items */ $this->_html .= '

'.$this->l('Gestion des questions à masquer selon la réponse').' '.$this->l('Ajouter une condition de masquage').' '; /* Display notice if there are no items yet */ if (!$items) $this->_html .= '

'.$this->l('Vous n\'avez aucune condition enregistrée').'

'; else /* Display items */ { $this->_html .= '
'; } // End fieldset $this->_html .= '
'; } private function _displayFormSubstitutionsList() { /* Gets items */ $items = $this->getitemsSubstitution(); /* Begin fieldset items */ $this->_html .= '

'.$this->l('Gestion des substitution de produits dans un même rituel').' '.$this->l('Ajouter une substitution').' '; /* Display notice if there are no items yet */ if (!$items) $this->_html .= '

'.$this->l('Vous n\'avez aucune substitution enregistrée').'

'; else /* Display items */ { $this->_html .= '
'; } // End fieldset $this->_html .= '
'; } 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 .= '
'; if($table=="croisement") $this->_html .= '

Croisement des produits

Les produits cochés apparaîtront dans le diagnostic (si ils ne sont pas exclus)'; else $this->_html .= '

Exclusion des produits

Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)

'; $this->_html .= '

Question : #'.$id_item.' : '.$question.'

'; $this->_html .= '
'; $this->_html .= ''; /* 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 .= '
'; $this->_html .= 'Réponse '.$lettre.' - '.$rep.''; $this->_html .= ''; /* 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 .= '


'; foreach ($category14->products as $product) { $this->_html .= '
'; } $this->_html .= '
'; /* 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 .= '


'; foreach ($category15->products as $product) { $this->_html .= '
'; } $this->_html .= '
'; /* 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 .= '


'; foreach ($category16->products as $product) { $this->_html .= '
'; } $this->_html .= '
'; /* 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 .= '


'; foreach ($category17->products as $product) { $this->_html .= '
'; } $this->_html .= '
'; /* end cat 16 */ $this->_html .= '
'; } /* Save */ $this->_html .= '

'.$this->l('Annuler').'

'; /* End of fieldset & form */ $this->_html .= '

*'.$this->l('Champs obligatoires').'

'; $this->_html .= '
'; } 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 .= '
'; // if($table=="conditions") $this->_html .= '

Conditions de substitution des produits

Sélectionnez le numéro de question, le numéro de réponse puis quel produit remplacera quel produit.

Vous pouvez aussi combiner 2 questions et réponses.

'; // else // $this->_html .= '

Exclusion des produits

Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)

'; $this->_html .= '
'; $this->_html .= ''; /* Fieldset edit/add */ // foreach($products as $row) // if(!in_array($id_product['id_product'],$fullProducts)) // $fullProducts[]=$row; // print_r($productsSelected); $this->_html .= '
'; if($id_condition!='') $this->_html .= 'Condition : #'.$id_condition.''; else $this->_html .= 'Nouvelle condition de substitution'; /* cat 14 */ $this->_html .= ' '; $this->_html .= ''; $this->_html .= ' *'; $this->_html .= '

'; $this->_html .= ' '; $this->_html .= ''; $this->_html .= '

'; $this->_html .= ' '; $this->_html .= ''; $this->_html .= '

'; $this->_html .= '
'; $this->_html .= '
'; $this->_html .= ''; $this->_html .= '
'; /* end cat 16 */ $this->_html .= '
'; /* Save */ $this->_html .= '

'.$this->l('Annuler').'

'; /* End of fieldset & form */ $this->_html .= '

*'.$this->l('Champs obligatoires').'

'; $this->_html .= '
'; } 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 .= '
'; // if($table=="conditions") $this->_html .= '

Conditions de réorientation

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)

'; // else // $this->_html .= '

Exclusion des produits

Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)

'; $this->_html .= '
'; $this->_html .= ''; /* Fieldset edit/add */ // foreach($products as $row) // if(!in_array($id_product['id_product'],$fullProducts)) // $fullProducts[]=$row; // print_r($productsSelected); $this->_html .= '
'; if($id_reorientation!='') $this->_html .= 'Réorientation : #'.$id_reorientation.''; else $this->_html .= 'Nouvelle reorientation de substitution'; /* cat 14 */ $this->_html .= '
'; $this->_html .= ''; $this->_html .= ' *


'; $this->_html .= '
'; $this->_html .= ''; $this->_html .= ' *


'; $this->_html .= '
'; $this->_html .= ''; $this->_html .= ' *
'; $this->_html .= '

'; $this->_html .= ''; $this->_html .= ' *
'; // $this->_html .= '


'; // $this->_html .= '
'; /* end cat 16 */ $this->_html .= '
'; /* Save */ $this->_html .= '

'.$this->l('Annuler').'

'; /* End of fieldset & form */ $this->_html .= '

*'.$this->l('Champs obligatoires').'

'; $this->_html .= '
'; } 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 .= '
'; // if($table=="conditions") $this->_html .= '

Question à masquer

Sélectionnez le numéro de question, le numéro de réponse puis la question à masquer.

'; // else // $this->_html .= '

Exclusion des produits

Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)

'; $this->_html .= '
'; $this->_html .= ''; /* Fieldset edit/add */ // foreach($products as $row) // if(!in_array($id_product['id_product'],$fullProducts)) // $fullProducts[]=$row; // print_r($productsSelected); $this->_html .= '
'; if($id_masquerquestion!='') $this->_html .= 'Condition : #'.$id_masquerquestion.''; else $this->_html .= 'Nouvelle condition de masquage'; /* cat 14 */ $this->_html .= '
'; $this->_html .= ''; $this->_html .= '
'; $this->_html .= '

'; $this->_html .= '
'; $this->_html .= '
'; /* end cat 16 */ $this->_html .= '
'; /* Save */ $this->_html .= '

'.$this->l('Annuler').'

'; /* End of fieldset & form */ $this->_html .= '

*'.$this->l('Champs obligatoires').'

'; $this->_html .= '
'; } 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 .= '
'; // if($table=="conditions") $this->_html .= '

Substitution des produits dans un même rituel

'; //

Si le produit 1 se trouve dans le même rituel que le produit 2, alors le produit 1 ne s\'affichera pas

// else // $this->_html .= '

Exclusion des produits

Les produits cochés ci-dessous n\'apparaîtront pas dans le diagnostic (annule le croisement)

'; $this->_html .= '
'; $this->_html .= ''; /* Fieldset edit/add */ // foreach($products as $row) // if(!in_array($id_product['id_product'],$fullProducts)) // $fullProducts[]=$row; // print_r($productsSelected); $this->_html .= '
'; if($id_substitution!='') $this->_html .= 'Substitution : #'.$id_substitution.''; else $this->_html .= 'Nouvelle substitution de produits dans un même rituel'; $this->_html .= '

'; $this->_html .= '
'; $this->_html .= '


'; $this->_html .= '
'; $this->_html .= '
'; /* end cat 16 */ $this->_html .= '
'; /* Save */ $this->_html .= '

'.$this->l('Annuler').'

'; /* End of fieldset & form */ $this->_html .= '
'; $this->_html .= '
'; } 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 .= ''; /* Form */ $this->_html .= '
'; /* Fieldset edit/add */ $this->_html .= '
'; if (Tools::isSubmit('additem')) /* Configure legend */ $this->_html .= '<'.$this->l('Question').''; elseif (Tools::isSubmit('id_item')) /* Edit legend */ $this->_html .= ''.$this->l('Modification de la question').' #'.$item->id.''; /* Sets id item as hidden */ if ($item && Tools::getValue('id_item')) $this->_html .= ''; /* Sets position as hidden */ $this->_html .= ''; /* Form content */ /* Title */ $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'questionn', true); $this->_html .= '


'; /* repA */ $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repAA', true); $this->_html .= '


'; $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepA', true); $this->_html .= '

'; /* repB */ $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repBB', true); $this->_html .= '


'; $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepB', true); $this->_html .= '

'; /* repC */ $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repCC', true); $this->_html .= '


'; $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepC', true); $this->_html .= '

'; /* repD */ $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repDD', true); $this->_html .= '


'; $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepD', true); $this->_html .= '

'; /* repE */ $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'repEE', true); $this->_html .= '


'; $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'texterepE', true); $this->_html .= '

'; /* Active */ $this->_html .= '
Yes
'; /* Save */ $this->_html .= '

'.$this->l('Annuler').'

'; /* End of fieldset & form */ $this->_html .= '

*'.$this->l('Champs oblgiatoires').'

'; } 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('
', $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('
', $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('
', $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('
', $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('
', $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('
', $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 '
'; // 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 = ' '; 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 = ''; 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); } }