name = 'modulecyber'; $this->tab = 'modulecyber'; $this->version = '1.0.0'; $this->author = 'Bastien'; $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); // $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Module cyber'); $this->description = $this->l('image + titre'); $this->confirmUninstall = $this->l('Êtes-vous sûr de vouloir désinstaller ce module cyber ?'); $this->templateFile = 'module:modulecyber/modulecyber.tpl'; } public function install(){ if(!parent::install() || !Configuration::updateValue('MON_IMAGE', '0') || !Configuration::updateValue('MON_TITRE', '0') || !$this->registerHook('header') || !$this->registerHook('displayFooterBefore')){ return false; } else{ return true; } } public function uninstall(){ if(!parent::uninstall() || !Configuration::deleteByName('MON_IMAGE') || !Configuration::deleteByName('MON_TITRE')){ return false; } else{ return true; } } public function getContent(){ return $this->postProcess().$this->renderForm(); } private function postProcess(){ if(Tools::isSubmit('submitConfImageTitre') && Configuration::updateValue('MON_IMAGE', $_POST['MON_IMAGE'])){ foreach (Language::getLanguages(false) as $lang) Configuration::updateValue('MON_TITRE', Tools::getValue('text_'.(int)$lang['id_lang']), true); return $this->displayConfirmation('Le champ a été enregistré'); } else{ return $this->displayError('Une erreur a été rencontrée'); } } public function getFormValues() { $fields_value = array(); // On charge le Texte sauvegardé dans la colonne "value" de la Table "ps_configuration" $MON_TITRE = Configuration::get('MON_TITRE'); foreach (Language::getLanguages(false) as $lang) // Si besoin d'utiliser la traduction $fields_value['text'][(int)$lang['id_lang']] = Tools::getValue('text_'.(int)$lang['id_lang'], ''); // On load le contenu du textarea ("text_X", text_1 pour FR) qui servira à charger le contenu du champ TINYMCE $fields_value['text'][(int)$lang['id_lang']] = $MON_TITRE; return $fields_value; } private function renderForm(){ $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $helper = new HelperForm(); $helper->submit_action = 'submitConfImageTitre'; $fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('Parametres'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => 'Votre image (url) :', 'name' => 'MON_IMAGE' ), 'MON_TITRE' => array( 'type' => 'hidden', 'name' => 'MON_TITRE' ), 'content' => array( 'type' => 'textarea', 'label' => $this->l('Texte du Champ'), 'lang' => true, 'name' => 'text', 'cols' => 40, 'rows' => 10, 'class' => 'rte', 'autoload_rte' => true, ) ), 'submit' => array( 'title' => 'Sauvegarder' ) ); $helper->module = $this; $helper->name_controller = 'demotutotinymce'; $helper->identifier = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); foreach (Language::getLanguages(false) as $lang) $helper->languages[] = array( 'id_lang' => $lang['id_lang'], 'iso_code' => $lang['iso_code'], 'name' => $lang['name'], 'is_default' => ($default_lang == $lang['id_lang'] ? 1 : 0) ); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; $helper->toolbar_scroll = true; $helper->title = $this->displayName; $helper->fields_value = $this->getFormValues(); $helper->fields_value['MON_IMAGE'] = Configuration::get('MON_IMAGE'); $helper->fields_value['MON_TITRE'] = Configuration::get('MON_TITRE'); return $helper->generateForm(array(array('form' => $fields_form))); } public function hookHeader(){ // Tools::registerJavascript( $this->context->controller->registerJavascript( 'js-imagetitre', 'modules/'.$this->name.'/js/app.js', [ 'media' => 'all', 'position' => 'bottom' ] ); $this->context->controller->registerStyleSheet( 'js-imagetitre', 'modules/'.$this->name.'/css/style.css', [ 'media' => 'all' ] ); } public function hookdisplayTop(){ global $smarty; $smarty->assign('cyber', array( 'titre' => Configuration::get('MON_TITRE'), 'image' => Configuration::get('MON_IMAGE'), )); return $this->display(__FILE__,'modulecyber.tpl'); } public function hookDisplayFooterBefore(){ global $smarty; $smarty->assign('cyber', array( 'titre' => Configuration::get('MON_TITRE'), 'image' => Configuration::get('MON_IMAGE'), 'monNom' => $this->l('Mon nom est Bastien') )); return $this->display(__FILE__,'modulecyber.tpl'); } }