name = 'marques'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'ANTADIS'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Affichage des marques'); $this->description = $this->l('Affiche les logos et liens sur les marques de façon aléatoire'); $this->confirmUninstall = $this->l('Etes vous sur ?'); } /* FONCTION D'INSTALLATION */ public function install(){ if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); if (!parent::install() || !$this->installDb() || !$this->registerHook('footer') || !$this->registerHook('centerAuth') || !$this->registerHook('displayHeader')){ $this->uninstall(); return false; } } /** * * @return boolean */ public function uninstall() { if(!parent::uninstall() || !$this->uninstallDb()){ return false; } return true; } /** * * @return boolean */ public function installDb(){ $prefix = _DB_PREFIX_ ; $engine = _MYSQL_ENGINE_; $statements = array(); $statements[] = sprintf('CREATE TABLE IF NOT EXISTS `%smarques_info` ( `id_marques_info` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255), `alt` varchar(255), `link` varchar(255), `name_marques` varchar(255), `date_add` datetime NOT NULL DEFAULT "0000-00-00 00:00:00", `date_upd` datetime NOT NULL DEFAULT "0000-00-00 00:00:00", PRIMARY KEY (`id_marques_info`) ) ENGINE=%s DEFAULT CHARSET=utf8 ;', $prefix, $engine ); return $this->uninstallDb() && $this->updateDb($statements); } /** * * @return boolean */ public function uninstallDb(){ $prefix = _DB_PREFIX_ ; $statements = array(); $statements[] = sprintf('DROP TABLE IF EXISTS `%smarques_info`;', $prefix ); $this->updateDb($statements); return $this->updateDb($statements); } /** * * @param array $statements * @return boolean */ public function updateDb($statements){ foreach($statements as $statement){ if( !Db::getInstance()->execute($statement)){ return false; } } return true; } /** CONFIGURATION **/ public function getContent(){ $this->_postProcess(); $languages = Language::getLanguages(false); foreach ($languages as $k => $language) $languages[$k]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT')); $helper = new HelperOptions(); $helper->module = $this; $helper->name_controller = 'marques'; $helper->id = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->languages = $languages; $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->allow_employee_form_lang = true; $helper->toolbar_scroll = true; $helper->toolbar_btn = $this->_initToolbar(); $helper->title = $this->displayName; $this->_displayAddForm(); $this->_displayMarques(); return $this->_html; } private function _displayMarques() { /* Fieldset Upload */ $this->_html .= '

'.$this->l('Logo des marques').''; /* Image */ $dirname = dirname(__FILE__).'/img/'; $dir = opendir($dirname); $compt = 0; while($file = readdir($dir)) { if($file != '.' && $file != '..' && !is_dir($dirname.$file)) { $info = MarquesInfo::getMarqueInfo($file); $this->_html .= '
'; $this->_html .= ''; $this->_html .= '
'; if($info){ $this->_html .= '
'; $this->_html .= '

'; $this->_html .= $this->l('Name :')." ".$info->title."
"; $this->_html .= $this->l('Alt :')." ".$info->alt."
"; $this->_html .= $this->l('Link :')." ".$info->link."
"; $this->_html .= '

'; } $this->_html .= '
'; $this->_html .= '
'; $compt++; } } /* End Fieldset Upload */ $this->_html .= '


'; } private function _displayAddForm() { /* Sets Slide : depends if edited or added */ /* Checks if directory is writable */ if (!is_writable('.')) $this->adminDisplayWarning(sprintf($this->l('Modules %s must be writable (CHMOD 755 / 777)'), $this->name)); /* Form */ $this->_html .= '
'; /* Fieldset Upload */ $this->_html .= '

'.$this->l('Télécharger vos logos').''; /* Image */ $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->l('Extension de l\'image : jpg - jpeg - png - gif') . ''; $this->_html .= '
'; $this->_html .= '

'; /* End Fieldset Upload */ $this->_html .= '


'; /* End of fieldset & form */ $this->_html .= '
'; } /** * * @return type */ private function _initToolbar(){ $this->toolbar_btn['save'] = array( 'href' => '#', 'desc' => $this->l('Save') ); return $this->toolbar_btn; } /* * TRAITEMENT DES DONNEES */ private function _postProcess(){ if (Tools::isSubmit('submitUpdateMarques')){ /* Uploads image and sets slide */ $type = strtolower(substr(strrchr($_FILES['marques']['name'], '.'), 1)); $imagesize = array(); $imagesize = @getimagesize($_FILES['marques']['tmp_name']); if (isset($_FILES['marques']) && isset($_FILES['marques']['tmp_name']) && !empty($_FILES['marques']['tmp_name']) && !empty($imagesize) && in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); $salt = sha1(microtime()); $file = Tools::encrypt($_FILES['marques']['name'].$salt); if ($error = ImageManager::validateUpload($_FILES['marques'])) $errors[] = $error; elseif (!$temp_name || !move_uploaded_file($_FILES['marques']['tmp_name'], $temp_name)) return false; elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/img/'.$file.'.'.$type, null, null, $type)) $errors[] = $this->displayError($this->l('An error occurred during the image upload process.')); else{ $info = new MarquesInfo(); $info->title = Tools::getValue('name_marques'); $info->link = Tools::getValue('link_marques'); $info->alt = Tools::getValue('alt_marques'); $info->name_marques = $file.'.'.$type; $info->add(); } if (isset($temp_name)) @unlink($temp_name); } } } /** GESTION DES HOOKS **/ /* GAUCHE */ public function hookDisplayLeftColumn($params){ $marques = new MarquesInfo(); $m = $marques::getAllMarques(); $this->context->smarty->assign( array( 'marques' => $m ) ); return $this->display(__FILE__, 'marques.tpl'); } /* FOOTER */ public function hookDisplayFooter($params){ return $this->hookDisplayLeftColumn($params); } public function hookCenterAuth($params){ return $this->hookDisplayLeftColumn($params); } /* CHARGEMENT HEADER */ public function hookDisplayHeader(){ $this->context->controller->addJS($this->_path.'views/js/jquery.carouFredSel-6.2.1-packed.js', 'all'); $this->context->controller->addCSS($this->_path.'views/css/slider.css', 'all'); } } ?>