334 lines
12 KiB
PHP
Executable File
334 lines
12 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Description of Marques
|
|
*
|
|
* @author Thibault
|
|
* @company Antadis
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
include_once(_PS_MODULE_DIR_.'marques/models/MarquesInfo.php');
|
|
|
|
class Marques extends Module{
|
|
|
|
/* CONSTRUCTEUR ET DECLARATION */
|
|
public function __construct(){
|
|
$this->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 .= '
|
|
<fieldset>
|
|
<br />
|
|
<legend><img src="'._PS_ADMIN_IMG_.'picture.gif" alt="" />'.$this->l('Logo des marques').'</legend>';
|
|
/* 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 .= '<div id="block_'.$compt.'" style="text-align:center;float: left;margin-left:20px;padding : 5px;border:1px solid #CCCCCC;background-color: #F8F8F8;">';
|
|
$this->_html .= '<img src="'.__PS_BASE_URI__.'modules/'.$this->name.'/img/'.$file.'">';
|
|
$this->_html .= '<br/>';
|
|
if($info){
|
|
$this->_html .= '<br/>';
|
|
$this->_html .= '<p style="text-align:left">';
|
|
$this->_html .= $this->l('Name :')." ".$info->title."<br/>";
|
|
$this->_html .= $this->l('Alt :')." ".$info->alt."<br/>";
|
|
$this->_html .= $this->l('Link :')." ".$info->link."<br/>";
|
|
$this->_html .= '</p>';
|
|
}
|
|
$this->_html .= '<br/>
|
|
<input type="hidden" id="link_'.$compt.'" name="link_'.$compt.'" value="'.$file.'" />
|
|
<input type="button" id="supp_'.$compt.'" name="supp" value="'.$this->l('Delete').'" />
|
|
';
|
|
$this->_html .= '</div>';
|
|
$compt++;
|
|
}
|
|
}
|
|
/* End Fieldset Upload */
|
|
$this->_html .= '</fieldset>
|
|
<script>
|
|
$(document).ready(function(){
|
|
$("[name=supp]").click(function(){
|
|
var id = $(this).attr("id");
|
|
var compt = id.split(\'_\');
|
|
id = compt[1];
|
|
var recup_link = $("#link_"+id).val();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "'. __PS_BASE_URI__ .'modules/marques/ajax/ajaxsupp.php?action=suppMarque",
|
|
cache: false,
|
|
dataType: "json",
|
|
data : {file : recup_link},
|
|
success : function(data)
|
|
{
|
|
$("#block_"+id).hide();
|
|
}
|
|
});
|
|
})
|
|
});
|
|
</script>
|
|
<br /><br />';
|
|
}
|
|
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 .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">';
|
|
|
|
/* Fieldset Upload */
|
|
$this->_html .= '
|
|
<fieldset class="width3" style="margin:auto">
|
|
<br />
|
|
<legend><img src="'._PS_ADMIN_IMG_.'photo_add.gif" alt="" />'.$this->l('Télécharger vos logos').'</legend>';
|
|
/* Image */
|
|
$this->_html .= '<label>'.$this->l('Name:').'</label><div class="margin-form">';
|
|
$this->_html .= '<input type="text" name="name_marques" id="name_marques" />';
|
|
$this->_html .= '</div>';
|
|
|
|
$this->_html .= '<label>'.$this->l('Attribut alt :').'</label><div class="margin-form">';
|
|
$this->_html .= '<input type="text" name="alt_marques" id="alt_marques" />';
|
|
$this->_html .= '</div>';
|
|
|
|
$this->_html .= '<label>'.$this->l('Lien :').'</label><div class="margin-form">';
|
|
$this->_html .= '<input type="text" name="link_marques" id="link_marques"/>';
|
|
$this->_html .= '</div>';
|
|
|
|
$this->_html .= '<label>'.$this->l('Choisir un fichier :').'</label><div class="margin-form">';
|
|
$this->_html .= '<input type="file" name="marques" id="marques" size="30" />';
|
|
$this->_html .= '<br />';
|
|
$this->_html .= '<i>' . $this->l('Extension de l\'image : jpg - jpeg - png - gif') . '</i>';
|
|
$this->_html .= '</div>';
|
|
|
|
$this->_html .= '
|
|
<p class="right">
|
|
<input type="submit" class="button" name="submitUpdateMarques" id="submitUpdateMarques" value="'.$this->l('Envoyer').'" />
|
|
</p>';
|
|
/* End Fieldset Upload */
|
|
$this->_html .= '</fieldset><br /><br />';
|
|
|
|
/* End of fieldset & form */
|
|
$this->_html .= '
|
|
</form>';
|
|
}
|
|
/**
|
|
*
|
|
* @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');
|
|
}
|
|
}
|
|
?>
|