314 lines
14 KiB
PHP
Executable File
314 lines
14 KiB
PHP
Executable File
<?php
|
|
class Statseasy extends Module{
|
|
|
|
/*
|
|
* Réalisé par Webbax
|
|
* http://www.webbax.ch
|
|
* contact@webbax.ch
|
|
*/
|
|
|
|
/* Correctifs
|
|
* V1.6.0 - 29.09.14
|
|
* - compatibilité Prestashop 1.6
|
|
* V1.6.1 - 10.10.14
|
|
* - déplacement des librairies
|
|
* - révision "castage" variables
|
|
*/
|
|
|
|
private $_html = '';
|
|
|
|
function __construct(){
|
|
$this->name = 'statseasy';
|
|
$this->tab = 'administration';
|
|
$this->author = 'Webbax';
|
|
$this->version = '1.6.1';
|
|
$this->module_key = '27612041d70e451f354bc9c8952a593b';
|
|
|
|
/* PS 1.6 */
|
|
$this->bootstrap = true;
|
|
$this->ps_version = Tools::substr(_PS_VERSION_,0,3);
|
|
|
|
parent::__construct();
|
|
$this->displayName = $this->l('Stats Easy');
|
|
$this->description = $this->l('Pour avoir une vue d\'ensemble des statistiques de votre boutique');
|
|
$this->description .= '<br/><span style="font-weight:bold;">'.$this->l('Module réalisé par').' Webbax</a>';
|
|
}
|
|
|
|
function install(){
|
|
|
|
Db::getInstance()->Execute("
|
|
CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."statseasy` (
|
|
`id_statseasy` int(11) NOT NULL AUTO_INCREMENT,
|
|
`type` text NOT NULL,
|
|
`value` text NOT NULL,
|
|
`id_shop` INT NOT NULL,
|
|
PRIMARY KEY (`id_statseasy`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;"
|
|
);
|
|
|
|
$shops = Shop::getShops();
|
|
foreach($shops as $shop){
|
|
if(!Shop::isFeatureActive()){$shop['id_shop']=0;} // 1 shop only
|
|
Configuration::updateValue('STATSEASY_NBTOP',5,false,null,$shop['id_shop']);
|
|
Configuration::updateValue('STATSEASY_NBCHARS_CUT',22,false,null,$shop['id_shop']);
|
|
}
|
|
|
|
if(!parent::install() || !$this->installModuleTab('AdminStatseasy','Stats Easy',19))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
function uninstall(){
|
|
Db::getInstance()->Execute('DROP TABLE if exists `'._DB_PREFIX_.'statseasy`');
|
|
if(!parent::uninstall() || !$this->uninstallModuleTab('AdminStatseasy'))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
function getContent(){
|
|
|
|
if($this->ps_version=='1.6'){
|
|
$this->_html .= '<link rel="stylesheet" type="text/css" href="'.$this->_path.'css/styles_1.6.css">';
|
|
}
|
|
|
|
// Configuration paramètres principaux du module
|
|
if(Tools::isSubmit('formConfiguration')){
|
|
$this->_html .= $this->msgConfirm($this->l('La configuration a été modifiée.'));
|
|
Configuration::updateValue('STATSEASY_NBTOP',Tools::getValue('nbtop'));
|
|
Configuration::updateValue('STATSEASY_NBCHARS_CUT',Tools::getValue('nbchars_cut'));
|
|
}
|
|
|
|
$this->_html.= '
|
|
<style>
|
|
hr{
|
|
color: #CCCCCC;
|
|
background-color: #CCCCCC;
|
|
height: 1px;
|
|
border: 0;
|
|
}
|
|
</style>';
|
|
|
|
// Commandes avec le statut payé
|
|
$res = Tools::getValue('orderStatesPaid');
|
|
if(Tools::isSubmit('submitOrderStatesPaid') && !empty($res)){
|
|
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_ .'statseasy WHERE `type`="orderStatesPaid" AND `id_shop`="'.pSQL($this->context->shop->id).'"');
|
|
foreach($res as $key=>$id_orderstate){
|
|
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_ .'statseasy (type,value,id_shop) VALUES ("orderStatesPaid","'.pSQL($id_orderstate).'","'.pSQL($this->context->shop->id).'")');
|
|
}
|
|
$this->_html .= $this->msgConfirm($this->l('Les status "payés" ont été sauvés.'));
|
|
}
|
|
// Commandes avec le statut en attente
|
|
$res = Tools::getValue('orderStatesWait');
|
|
if(Tools::isSubmit('submitOrderStatesWait')&& !empty($res)){
|
|
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_ .'statseasy WHERE `type`="orderStatesWait" AND `id_shop`="'.pSQL($this->context->shop->id).'"');
|
|
foreach($res as $key=>$id_orderstate){
|
|
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_ .'statseasy (type,value,id_shop) VALUES ("orderStatesWait","'.pSQL($id_orderstate).'","'.pSQL($this->context->shop->id).'")');
|
|
}
|
|
$this->_html .= $this->msgConfirm($this->l('Les status "en attentes" ont été sauvés.'));
|
|
}
|
|
// Commandes avec le statut supprimé
|
|
$res = Tools::getValue('orderStatesDel');
|
|
if(Tools::isSubmit('submitOrderStatesDel')&& !empty($res)){
|
|
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_ .'statseasy WHERE `type`="orderStatesDel" AND `id_shop`="'.pSQL($this->context->shop->id).'"');
|
|
foreach($res as $key=>$id_orderstate){
|
|
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_ .'statseasy (type,value,id_shop) VALUES ("orderStatesDel","'.pSQL($id_orderstate).'","'.pSQL($this->context->shop->id).'")');
|
|
}
|
|
$this->_html .= $this->msgConfirm($this->l('Les status "supprimés" ont été sauvés.'));
|
|
}
|
|
|
|
$this->_html.= '
|
|
<div id="stats_easy_conf" class="panel">
|
|
|
|
<fieldset>
|
|
<legend>Configuration</legend>
|
|
<form class="" action="'.$_SERVER['REQUEST_URI'].'" method="post" name="form_freenewsletter" id="form_freenewsletter">
|
|
<input type="hidden" value="freenewsletter" id="table" name="table">
|
|
<h2>'.$this->l('Général').'</h2>
|
|
<hr>
|
|
<div>
|
|
<label style="margin-right:5px;" for="nbtop">'.$this->l('Afficher le TOP').'</label>
|
|
<input type="text" style="width:25px;" maxlength="3" class="" name="nbtop" id="nbtop" value="'.Configuration::get('STATSEASY_NBTOP').'"> '.$this->l('du classement').'
|
|
</div>
|
|
<div style="margin-top:5px;">
|
|
<label style="margin-right:5px;" for="nbtop">'.$this->l('Couper la description produit dans l\'export PDF après').'</label>
|
|
<input type="text" style="width:25px;" maxlength="3" class="" name="nbchars_cut" id="nbchars_cut" value="'.Configuration::get('STATSEASY_NBCHARS_CUT').'"> '.$this->l('caractères').'
|
|
</div>
|
|
<div class="clear"></div>
|
|
<hr>
|
|
<div style="" id="div_formConfiguration">
|
|
<input type="submit" class="button btn btn-default" style="" value="'.$this->l('Sauver').'" name="formConfiguration">
|
|
</div>
|
|
</form>
|
|
</fieldset>';
|
|
|
|
// Configuration des statuts de commande
|
|
$orderStates = OrderState::getOrderStates($this->context->cookie->id_lang);
|
|
|
|
// Commandes avec le statut payé
|
|
$this->_html.= '
|
|
<br/>
|
|
<fieldset>
|
|
<legend>'.$this->l('Cochez les statuts équivalents à "payés"').'</legend>
|
|
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
|
|
|
|
<div class="warn alert alert-warning">'.
|
|
$this->l('Les status suivants sont recommandés d\'être cochés').' : '.'<br>- '.$this->l('Paiement accepté').'<br/>- '.$this->l('Préparation en cours').'<br/>- '.$this->l('Payé avec...').'<br/>- '.$this->l('Livré').'<br/>- '.$this->l('En cours de livraison').'<br/>- '.$this->l('Paiement à distance accepté').'
|
|
</div>';
|
|
|
|
$orderStatesChecked = Db::getInstance()->ExecuteS('SELECT value FROM '._DB_PREFIX_ .'statseasy WHERE type="orderStatesPaid" AND `id_shop`="'.pSQL($this->context->shop->id).'"');
|
|
$oSChecked = array();
|
|
foreach($orderStatesChecked as $orderStateChecked){$oSChecked[] = $orderStateChecked['value'];}
|
|
foreach($orderStates as $os){
|
|
if(in_array($os['id_order_state'],$oSChecked)){$checked='checked';}else{$checked='';}
|
|
$this->_html .= '<input type="checkbox" style="" class="" value="'.$os['id_order_state'].'" name="orderStatesPaid[]" '.$checked.'> '.$os['name'].'<br/>';
|
|
}
|
|
$this->_html .= '
|
|
<br/>
|
|
<input type="submit" class="button btn btn-default" style="" value="'.$this->l('Sauver la configuration').'" name="submitOrderStatesPaid">
|
|
</form>
|
|
</fieldset>';
|
|
|
|
// Commandes avec le statut en attente
|
|
$this->_html.= '
|
|
<br/>
|
|
<fieldset>
|
|
<legend>'.$this->l('Cochez les statuts équivalents à "en attente du paiement"').'</legend>
|
|
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
|
|
|
|
<div class="warn alert alert-warning">'.
|
|
$this->l('Les status suivants sont recommandés d\'être cochés').' : <br>- '.$this->l('En attente du paiement par...').'<br/>- '.$this->l('En attente de réapprovisionnement').'
|
|
</div>';
|
|
|
|
$orderStatesChecked = Db::getInstance()->ExecuteS('SELECT value FROM '._DB_PREFIX_ .'statseasy WHERE type="orderStatesWait" AND `id_shop`="'.pSQL($this->context->shop->id).'"');
|
|
$oSChecked = array();
|
|
foreach($orderStatesChecked as $orderStateChecked){$oSChecked[] = $orderStateChecked['value'];}
|
|
foreach($orderStates as $os){
|
|
if(in_array($os['id_order_state'],$oSChecked)){$checked='checked';}else{$checked='';}
|
|
$this->_html .= '<input type="checkbox" style="" class="" value="'.$os['id_order_state'].'" name="orderStatesWait[]" '.$checked.'> '.$os['name'].'<br/>';
|
|
}
|
|
$this->_html .= '
|
|
<br/>
|
|
<input type="submit" class="button btn btn-default" style="" value="'.$this->l('Sauver la configuration').'" name="submitOrderStatesWait">
|
|
</form>
|
|
</fieldset>';
|
|
|
|
// Commandes avec le statut supprimé
|
|
$this->_html.= '
|
|
<br/>
|
|
<fieldset>
|
|
<legend>'.$this->l('Cochez les statuts équivalents à "supprimé / remboursé"').'</legend>
|
|
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
|
|
|
|
<div class="warn alert alert-warning">'.
|
|
$this->l('Les status suivants sont recommandés d\'être cochés').' : <br>- '.$this->l('Annulé').'<br/>- '.$this->l('Remboursé').'<br/>- '.$this->l('Erreur de paiement').'
|
|
</div>';
|
|
$orderStatesChecked = Db::getInstance()->ExecuteS('SELECT value FROM '._DB_PREFIX_ .'statseasy WHERE type="orderStatesDel" AND `id_shop`="'.pSQL($this->context->shop->id).'"');
|
|
$oSChecked = array();
|
|
foreach($orderStatesChecked as $orderStateChecked){$oSChecked[] = $orderStateChecked['value'];}
|
|
foreach($orderStates as $os){
|
|
if(in_array($os['id_order_state'],$oSChecked)){$checked='checked';}else{$checked='';}
|
|
$this->_html .= '<input type="checkbox" style="" class="" value="'.$os['id_order_state'].'" name="orderStatesDel[]" '.$checked.'> '.$os['name'].'<br/>';
|
|
}
|
|
$this->_html .= '
|
|
<br/>
|
|
<input type="submit" class="button btn btn-default" style="" value="'.$this->l('Sauver la configuration').'" name="submitOrderStatesDel">
|
|
</form>
|
|
</fieldset>
|
|
|
|
</div>';
|
|
|
|
return $this->_html;
|
|
|
|
}
|
|
|
|
/*
|
|
* Installe un onglet
|
|
* @param string (nom de l'onglet class)
|
|
* @param string (nom de l'onglet fr)
|
|
* @param int (id_parent)
|
|
* @return -
|
|
*/
|
|
function installModuleTab($tabClass,$tabName,$idTabParent){
|
|
@copy(_PS_MODULE_DIR_.$this->name.'/logo.gif', _PS_IMG_DIR_.'t/'.$tabClass.'.gif');
|
|
$tab = new Tab();
|
|
$langs = Language::getLanguages();
|
|
foreach($langs as $lang){
|
|
$tab->name[$lang['id_lang']] = $tabName;
|
|
}
|
|
$tab->class_name = $tabClass;
|
|
$tab->module = $this->name;
|
|
$tab->id_parent = $idTabParent;
|
|
if(!$tab->save())
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Désinstalle un onglet
|
|
* @param string (nom de l'onglet class)
|
|
* @return -
|
|
*/
|
|
function uninstallModuleTab($tabClass){
|
|
$idTab = Tab::getIdFromClassName($tabClass);
|
|
if($idTab != 0){
|
|
$tab = new Tab($idTab);
|
|
$tab->delete();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function msgConfirm($msg){
|
|
return $this->displayConfirmation($msg);
|
|
}
|
|
|
|
function msgError($msg){
|
|
return $this->displayError($msg);
|
|
}
|
|
|
|
static function dateUsToFr($date,$delimiter='-'){
|
|
$arr = explode('-',$date);
|
|
$y = $arr[0];
|
|
$m = $arr[1];
|
|
$d = $arr[2];
|
|
return $d.'-'.$m.'-'.$y;
|
|
}
|
|
|
|
/*
|
|
* Retourne une chaine avec trait d'union
|
|
* @param string
|
|
* @return string
|
|
*/
|
|
static function hyphen($string){
|
|
$string = mb_strtolower($string,'UTF-8');
|
|
$string = str_replace(' ', '-', $string);
|
|
$string = str_replace(
|
|
array(
|
|
'à', 'â', 'ä', 'á', 'ã', 'å',
|
|
'î', 'ï', 'ì', 'í',
|
|
'ô', 'ö', 'ò', 'ó', 'õ', 'ø',
|
|
'ù', 'û', 'ü', 'ú',
|
|
'é', 'è', 'ê', 'ë',
|
|
'ç', 'ÿ', 'ñ',
|
|
),
|
|
array(
|
|
'a', 'a', 'a', 'a', 'a', 'a',
|
|
'i', 'i', 'i', 'i',
|
|
'o', 'o', 'o', 'o', 'o', 'o',
|
|
'u', 'u', 'u', 'u',
|
|
'e', 'e', 'e', 'e',
|
|
'c', 'y', 'n',
|
|
),
|
|
$string
|
|
);
|
|
$string = str_replace("'",'-',$string);
|
|
$string = str_replace('(','-',$string);
|
|
$string = str_replace(')','-',$string);
|
|
$string = str_replace('--','-',$string);
|
|
return $string;
|
|
}
|
|
|
|
}
|
|
?>
|