bebeboutik/modules/lapostews/lapostews.php

312 lines
14 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
class LaPosteWS extends Module {
public $_html = '';
function __construct() {
$this->name = 'lapostews';
$this->tab = 'shipping_logistics';
$this->version = '1.0-2';
$this->author = 'Antadis';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('La Poste webservices');
$this->description = $this->l('Allows to manage parcels with La Poste via webservices');
}
function install() {
# Add admin tabs
$tabs_i18n = array(
'fr' => 'Gestion des envois',
'en' => 'Parcel management',
);
$t = new Tab();
$t->id_parent = (int) Tab::getIdFromClassName('AdminOrders');
$st->position = (int) Tab::getNewLastPosition($st->id_parent);
$t->active = TRUE;
$t->module = 'lapostews';
$t->class_name = 'AdminLaPosteWS';
foreach(Language::getLanguages() as $lang) {
if(isset($tabs_i18n[$lang['iso_code']])) {
$t->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']];
} else {
$t->name[$lang['id_lang']] = $tabs_i18n['en'];
}
}
$t->save();# Add admin tabs
$tabs_i18n = array(
'fr' => 'Bordereaux',
'en' => 'Summaries',
);
$t = new Tab();
$t->id_parent = (int) Tab::getIdFromClassName('AdminOrders');
$st->position = (int) Tab::getNewLastPosition($st->id_parent);
$t->active = TRUE;
$t->module = 'lapostews';
$t->class_name = 'AdminLaPosteSummary';
foreach(Language::getLanguages() as $lang) {
if(isset($tabs_i18n[$lang['iso_code']])) {
$t->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']];
} else {
$t->name[$lang['id_lang']] = $tabs_i18n['en'];
}
}
$t->save();
return Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'lapostews2` (
`id_order` INTEGER UNSIGNED NOT NULL,
`id_employee` INTEGER UNSIGNED NOT NULL,
`shipping_number` VARCHAR(64) NOT NULL,
`date_add` DATETIME NOT NULL,
PRIMARY KEY(`id_order`, `date_add`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
') && Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'lapostews_pr` (
`id_pr` VARCHAR(6) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`address1` VARCHAR(255) NOT NULL,
`address2` VARCHAR(255) NOT NULL,
`address3` VARCHAR(255) NOT NULL,
`address4` VARCHAR(255) NOT NULL,
`postcode` VARCHAR(6) NOT NULL,
`city` VARCHAR(255) NOT NULL,
`xcoords` VARCHAR(24) NOT NULL,
`ycoords` VARCHAR(24) NOT NULL,
`type` VARCHAR(6) NOT NULL,
`code1` VARCHAR(8) NOT NULL,
`code2` VARCHAR(8) NOT NULL,
PRIMARY KEY(`id_pr`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
') && parent::install();
}
public function uninstall() {
return Db::getInstance()->ExecuteS('DROP TABLE IF EXISTS `'._DB_PREFIX_.'lapostews2`') && Db::getInstance()->ExecuteS('DROP TABLE IF EXISTS `'._DB_PREFIX_.'lapostews_pr`') && parent::uninstall();
}
public function getContent() {
global $cookie;
if(Tools::isSubmit('submitUpdate')) {
Configuration::updateValue('LAPOSTEWS_CARRIERS', serialize(Tools::getValue('carriers', array())));
Configuration::updateValue('LAPOSTEWS_CONTRACT', Tools::getValue('contract'));
Configuration::updateValue('LAPOSTEWS_API_PASSWORD', Tools::getValue('apipassword'));
Configuration::updateValue('LAPOSTEWS_API_CONTRACT', Tools::getValue('apicontract'));
// Configuration::updateValue('LAPOSTEWS_API_PASSWORD2', Tools::getValue('apipassword2'));
// Configuration::updateValue('LAPOSTEWS_API_CONTRACT2', Tools::getValue('apicontract2'));
// Configuration::updateValue('LAPOSTEWS_API_PASSWORD_WSU', Tools::getValue('apipassword_wsu'));
// Configuration::updateValue('LAPOSTEWS_API_CONTRACT_WSU', Tools::getValue('apicontract_wsu'));
// Configuration::updateValue('LAPOSTEWS_WSU_ENABLE', Tools::getValue('mode_wsu'));
2016-01-04 12:49:26 +01:00
Configuration::updateValue('LAPOSTEWS_MODE', Tools::getValue('mode'));
Configuration::updateValue('LAPOSTEWS_COMMERCIALNAME', Tools::getValue('commercialname'));
Configuration::updateValue('LAPOSTEWS_SHIPPING_SITE', Tools::getValue('shippingsite'));
Configuration::updateValue('LAPOSTEWS_SHIPPING_SITE_CODE', Tools::getValue('shippingsite_code'));
Configuration::updateValue('LAPOSTEWS_SUMMARIES_COUNT', Tools::getValue('summaries_count'));
Configuration::updateValue('LAPOSTEWS_EXP_ADDR1', Tools::getValue('exp_addr1'));
Configuration::updateValue('LAPOSTEWS_EXP_ADDR2', Tools::getValue('exp_addr2'));
Configuration::updateValue('LAPOSTEWS_EXP_CITY', Tools::getValue('exp_city'));
Configuration::updateValue('LAPOSTEWS_EXP_COMPANY', Tools::getValue('exp_company'));
Configuration::updateValue('LAPOSTEWS_EXP_COUNTRY', Tools::getValue('exp_country'));
Configuration::updateValue('LAPOSTEWS_EXP_EMAIL', Tools::getValue('exp_email'));
Configuration::updateValue('LAPOSTEWS_EXP_FIRSTNAME', Tools::getValue('exp_firstname'));
Configuration::updateValue('LAPOSTEWS_EXP_LASTNAME', Tools::getValue('exp_lastname'));
Configuration::updateValue('LAPOSTEWS_EXP_PHONE', Tools::getValue('exp_phone'));
Configuration::updateValue('LAPOSTEWS_EXP_POSTALCODE', Tools::getValue('exp_postalcode'));
foreach(Tools::getValue('employee', array()) as $id_employee => $queue) {
Configuration::updateValue('LAPOSTEWS_EMPL_'.(int) $id_employee, $queue);
}
$this->_html = '<p class="conf">'.$this->l('Configuration updated successfully').'</p><br />';
}
$carriers = unserialize(Configuration::get('LAPOSTEWS_CARRIERS', serialize(array())));
$this->_html .= '
<form method="POST" action="">
<fieldset style="line-height: 1.5em;">
<legend>'.$this->l('Account settings').'</legend>
<p class="text">
<label for="commercialname">'.$this->l('Commercial name:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_COMMERCIALNAME').'" id="commercialname" name="commercialname" />
</p>
<p class="text">
<label for="contract">'.$this->l('Contract number:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_CONTRACT').'" id="contract" name="contract" />
</p>
</fieldset>
<br />
<fieldset style="line-height: 1.5em;">
<legend>'.$this->l('API settings').'</legend>
<p class="text">
<label for="apicontract">'.$this->l('Contract number:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_API_CONTRACT').'" id="apicontract" name="apicontract" />
</p>
<p class="text">
<label for="apipassword">'.$this->l('Password:').'</label>
<input type="password" value="'.Configuration::get('LAPOSTEWS_API_PASSWORD').'" id="apipassword" name="apipassword" />
</p>
<p class="text">
<label for="apicontract2">'.$this->l('Contract number:').' INTER</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_API_CONTRACT2').'" id="apicontract2" name="apicontract2" />
</p>
<p class="text">
<label for="apipassword2">'.$this->l('Password:').' INTER</label>
<input type="password" value="'.Configuration::get('LAPOSTEWS_API_PASSWORD2').'" id="apipassword2" name="apipassword2" />
</p>
<p class="text">
<label for="apicontract_wsu">'.$this->l('Contract number:').' WSU</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_API_CONTRACT_WSU').'" id="apicontract_wsu" name="apicontract_wsu" />
</p>
<p class="text">
<label for="apipassword_wsu">'.$this->l('Password:').' WSU</label>
<input type="password" value="'.Configuration::get('LAPOSTEWS_API_PASSWORD_WSU').'" id="apipassword_wsu" name="apipassword_wsu" />
</p>
2016-01-04 12:49:26 +01:00
<p class="radio">
<span style="font-weight: bold; float: left; text-align: right; width: 200px; padding: 0.2em 0.5em 0 0;">'.$this->l('Mode:').'</span>
<input type="radio" name="mode" id="mode_0" value="0"'.(Configuration::get('LAPOSTEWS_MODE')? '': ' checked="checked"').' /> <label for="mode_0" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('Test').'</label>
<input type="radio" name="mode" id="mode_1" value="1"'.(Configuration::get('LAPOSTEWS_MODE')? ' checked="checked"': '').' /> <label for="mode_1" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('Production').'</label>
</p>
<p class="radio">
<span style="font-weight: bold; float: left; text-align: right; width: 200px; padding: 0.2em 0.5em 0 0;">'.$this->l('Mode WSU:').'</span>
<input type="radio" name="mode_wsu" id="mode_wsu_0" value="1"'.((int)Configuration::get('LAPOSTEWS_WSU_ENABLE')==0? '': ' checked="checked"').' /> <label for="mode_wsu_0" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('activé').'</label>
<input type="radio" name="mode_wsu" id="mode_wsu_1" value="0"'.((int)Configuration::get('LAPOSTEWS_WSU_ENABLE')==0? ' checked="checked"': '').' /> <label for="mode_wsu_1" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('desactivé').'</label>
</p>
2016-01-04 12:49:26 +01:00
</fieldset>
<br />
<fieldset style="line-height: 1.5em;">
<legend>'.$this->l('Parcel sender details').'</legend>
<p class="text">
<label for="exp_company">'.$this->l('Company:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_COMPANY').'" id="exp_company" name="exp_company" />
</p>
<p class="text">
<label for="exp_firstname">'.$this->l('First name:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_FIRSTNAME').'" id="exp_firstname" name="exp_firstname" />
</p>
<p class="text">
<label for="exp_lastname">'.$this->l('Last name:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_LASTNAME').'" id="exp_lastname" name="exp_lastname" />
</p>
<p class="text">
<label for="exp_addr1">'.$this->l('Address 1:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_ADDR1').'" id="exp_addr1" name="exp_addr1" />
</p>
<p class="text">
<label for="exp_addr2">'.$this->l('Address 2:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_ADDR2').'" id="exp_addr2" name="exp_addr2" />
</p>
<p class="text">
<label for="exp_postalcode">'.$this->l('Postal code:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_POSTALCODE').'" id="exp_postalcode" name="exp_postalcode" />
</p>
<p class="text">
<label for="exp_city">'.$this->l('City:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_CITY').'" id="exp_city" name="exp_city" />
</p>
<p class="text">
<label for="exp_country">'.$this->l('Country:').'</label>
<select name="exp_country">';
foreach(Country::getCountries((int) $cookie->id_lang) as $country) {
$this->_html .= '<option value="'.$country['id_country'].'"'.(Configuration::get('LAPOSTEWS_EXP_COUNTRY') == $country['id_country']? ' selected="selected"': '').'>'.$country['name'].'</option>';
}
$this->_html .= '</select>
</p>
<p class="text">
<label for="exp_phone">'.$this->l('Phone:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_PHONE').'" id="exp_phone" name="exp_phone" />
</p>
<p class="select">
<label for="exp_email">'.$this->l('Email:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EXP_EMAIL').'" id="exp_email" name="exp_email" />
</p>
<p class="select">
<label for="shippingsite">'.$this->l('Shipping site:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_SHIPPING_SITE').'" id="shippingsite" name="shippingsite" />
</p>
<p class="select">
<label for="shippingsite_code">'.$this->l('Shipping site code:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_SHIPPING_SITE_CODE').'" id="shippingsite_code" name="shippingsite_code" />
</p>
<p class="select">
<label for="summaries_count">'.$this->l('Summaries counter:').'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_SUMMARIES_COUNT').'" id="summaries_count" name="summaries_count" />
</p>
</fieldset>
<br />
<fieldset style="line-height: 1.5em;">
<legend>'.$this->l('Carrier selection').'</legend>
<p>
';
foreach(Db::getInstance()->ExecuteS('
SELECT c.*
FROM `'._DB_PREFIX_.'carrier` c
') as $carrier) {
$this->_html .= '<input style="vertical-align: middle;" type="checkbox" name="carriers[]" value="'.$carrier['id_carrier'].'" id="carrier_'.$carrier['id_carrier'].'"'.(in_array($carrier['id_carrier'], $carriers)? ' checked="checked"': '').' /> <label style="'.($carrier['active'] && !$carrier['deleted']? 'font-weight: bold;': 'font-weight: normal;').'float: none; display: inline; width: auto;" for="carrier_'.$carrier['id_carrier'].'">'.$carrier['name'].'</label><br />';
}
$this->_html .= '</p>
</fieldset>
<br />
<fieldset style="line-height: 1.5em;">
<legend>'.$this->l('Queues configuration').'</legend>
';
foreach(Employee::getEmployees() as $employee) {
$this->_html .= '
<p class="text">
<label for="employee_'.(int) $employee['id_employee'].'">'.$employee['name'].'</label>
<input type="text" value="'.Configuration::get('LAPOSTEWS_EMPL_'.(int) $employee['id_employee']).'" id="employee_'.(int) $employee['id_employee'].'" name="employee['.(int) $employee['id_employee'].']" />
</p>';
}
$this->_html .= '</fieldset>
<br />
<p class="submit" style="margin-top: 10px;"><input type="submit" name="submitUpdate" class="button" value="'.$this->l('Submit').'" /></p>
</form>
<br /><br />
';
return $this->_html;
}
public function hookUpdateCarrier($params) {
$new_carrier_id = (int) Db::getInstance()->getValue('SELECT MAX(`id_carrier`) FROM `'._DB_PREFIX_.'carrier`');
$carriers = Configuration::get('LAPOSTEWS_CARRIERS');
if(in_array((int) $params['id_carrier'], $carriers)) {
$carriers[] = (int) $new_carrier_id;
Configuration::updateValue('LAPOSTEWS_CARRIERS', serialize($carriers));
}
}
}