186 lines
5.5 KiB
PHP
186 lines
5.5 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to a commercial license from EURL ébewè - www.ebewe.net
|
|
* Use, copy, modification or distribution of this source file without written
|
|
* license agreement from the EURL ébewè is strictly forbidden.
|
|
* In order to obtain a license, please contact us: contact@ebewe.net
|
|
* ...........................................................................
|
|
* INFORMATION SUR LA LICENCE D'UTILISATION
|
|
*
|
|
* L'utilisation de ce fichier source est soumise a une licence commerciale
|
|
* concedee par la societe EURL ébewè - www.ebewe.net
|
|
* Toute utilisation, reproduction, modification ou distribution du present
|
|
* fichier source sans contrat de licence ecrit de la part de la EURL ébewè est
|
|
* expressement interdite.
|
|
* Pour obtenir une licence, veuillez contacter la EURL ébewè a l'adresse: contact@ebewe.net
|
|
* ...........................................................................
|
|
*
|
|
* @author Paul MORA
|
|
* @copyright Copyright (c) 2011-2018 EURL ébewè - www.ebewe.net - Paul MORA
|
|
* @license Commercial license
|
|
* @package Postaldeliv
|
|
* Support by mail : contact@ebewe.net
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Loading Models
|
|
*/
|
|
require_once(_PS_MODULE_DIR_.'postaldeliv/models/PostalDeliv.php');
|
|
|
|
class Postaldeliv extends Module
|
|
{
|
|
/**
|
|
* DB file
|
|
*/
|
|
const INSTALL_SQL_FILE = 'install.sql';
|
|
const UNINSTALL_SQL_FILE = 'uninstall.sql';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->name = 'postaldeliv';
|
|
$this->tab = 'shipping_logistics';
|
|
$this->version = '2.1.10';
|
|
$this->author = 'ébewè';
|
|
$this->need_instance = 0;
|
|
$this->module_key = 'ccc93a38bc63cb123994eed42f533a5c';
|
|
parent::__construct();
|
|
$this->displayName = $this->l('Postal Deliv');
|
|
$this->description = $this->l('Delivery by postal code');
|
|
}
|
|
|
|
/**
|
|
* Install Module
|
|
*
|
|
**/
|
|
public function install()
|
|
{
|
|
if (!parent::install()
|
|
|| !$this->registerHook('actionCarrierUpdate')
|
|
|| !$this->registerHook('displayBackOfficeHeader')
|
|
|| !$this->installModuleTab(
|
|
'AdminPostalDeliv',
|
|
array((int)Configuration::get('PS_LANG_DEFAULT')=>'Postal Deliv'),
|
|
'AdminParentShipping'
|
|
)
|
|
|| !$this->__executeSql(self::INSTALL_SQL_FILE)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Uninstall Module
|
|
*
|
|
**/
|
|
public function uninstall()
|
|
{
|
|
if (!parent::uninstall()
|
|
|| !$this->uninstallModuleTab('AdminPostalDeliv')
|
|
|| !$this->__executeSql(self::UNINSTALL_SQL_FILE)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* install Tab
|
|
*
|
|
* @param mixed $tabClass
|
|
* @param mixed $tabName
|
|
* @param mixed $idTabParent
|
|
* @return bool $pass
|
|
*/
|
|
private function installModuleTab($tabClass, $tabName, $idTabParent)
|
|
{
|
|
$idTab = Tab::getIdFromClassName($idTabParent);
|
|
$pass = true;
|
|
$tab = new Tab();
|
|
$tab->name = $tabName;
|
|
$tab->class_name = $tabClass;
|
|
$tab->module = $this->name;
|
|
$tab->id_parent = $idTab;
|
|
$pass = $tab->save();
|
|
|
|
return $pass;
|
|
}
|
|
|
|
/**
|
|
* uninstall Tab
|
|
*
|
|
* @param mixed $tabClass
|
|
* @return bool $pass
|
|
*/
|
|
private function uninstallModuleTab($tabClass)
|
|
{
|
|
$pass = true;
|
|
@unlink(_PS_IMG_DIR_.'t/'.$tabClass.'.gif');
|
|
$idTab = Tab::getIdFromClassName($tabClass);
|
|
if ($idTab != 0) {
|
|
$tab = new Tab($idTab);
|
|
$pass = $tab->delete();
|
|
}
|
|
return $pass;
|
|
}
|
|
|
|
/**
|
|
* Create / Remove Table
|
|
*/
|
|
private function __executeSql($file)
|
|
{
|
|
if (!file_exists(dirname(__FILE__) . '/sql/' . $file)) {
|
|
return false;
|
|
} elseif (!$sql = Tools::file_get_contents(dirname(__FILE__).'/sql/'.$file)) {
|
|
return false;
|
|
}
|
|
$sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
|
|
// Insert default template data
|
|
$sql = str_replace('THE_FIRST_DEFAULT', serialize(array('width' => 1, 'height' => 1)), $sql);
|
|
$sql = str_replace('FLY_IN_DEFAULT', serialize(array('width' => 1, 'height' => 1)), $sql);
|
|
$sql = preg_split("/;\s*[\r\n]+/", trim($sql));
|
|
|
|
foreach ($sql as $query) {
|
|
if (!Db::getInstance()->execute(trim($query))) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function hookDisplayBackOfficeHeader()
|
|
{
|
|
if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true
|
|
&& Tools::getValue('controller') == 'AdminPostalDeliv') {
|
|
$this->context->controller->addJquery();
|
|
$this->context->controller->addJs($this->_path.'views/js/postaldeliv.js');
|
|
$this->context->controller->addCss($this->_path.'views/css/postaldeliv.css');
|
|
}
|
|
}
|
|
|
|
public function hookActionCarrierUpdate($params)
|
|
{
|
|
$result = Db::getInstance()->getValue('
|
|
SELECT MAX(id_carrier)
|
|
FROM `'._DB_PREFIX_.'carrier`');
|
|
|
|
Db::getInstance()->Execute('
|
|
UPDATE `'._DB_PREFIX_.'postaldeliv`
|
|
SET `id_carrier`='.(int)$result.'
|
|
WHERE `id_carrier`='.(int)$params['id_carrier']);
|
|
}
|
|
|
|
/**
|
|
* Admin page
|
|
*/
|
|
public function getContent()
|
|
{
|
|
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminPostalDeliv'));
|
|
}
|
|
}
|