Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from Common-Services Co., Ltd.
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe Common-Services Co., Ltd.
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @package SoNice Retour
* @author Alexandre D.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @license Commercial license
* Support by mail : support.sonice@common-services.com
*/
class SoColissimoCurlParser
{
public $curl_response = null;
public $label_binary = null;
public $cn23_binary = null;
public $has_label = false;
public function __construct($curl_response)
{
$this->curl_response = $curl_response;
if (preg_match('/<label>[\w\W].*<\/label>/', $curl_response)) {
$this->has_label = true;
}
}
public function parse()
{
if ($this->label_binary || $this->cn23_binary) {
return ($this);
}
$response_to_parse = $this->curl_response;
$response_to_parse = preg_replace('/--uu[\s\S].*/', '', $response_to_parse);
// Sometimes the flag "s" causes error, solution is to remove it.
$response_to_parse = preg_replace('/<soap[\s\S.*].*Envelope>/s', '', $response_to_parse);
$response_to_parse = trim(preg_replace('/^Content[\s\S].*/m', '', $response_to_parse));
// if ($this->has_label)
// {
// $response_to_parse = explode('%PDF', $response_to_parse);
//
// $this->label_binary = trim($response_to_parse[0]);
// $this->cn23_binary = '%PDF'.$response_to_parse[1];
// }
// else
$this->label_binary = $response_to_parse;
return ($this);
}
public function getLabelBinary()
{
return ($this->label_binary);
}
public function getCN23Binary()
{
return ($this->cn23_binary);
}
}

View File

@@ -0,0 +1,271 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from Common-Services Co., Ltd.
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe Common-Services Co., Ltd.
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @package SoNice Retour
* @author Alexandre D.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @license Commercial license
* Support by mail : support.sonice@common-services.com
*/
require_once(dirname(__FILE__).'/../sonice_retour.php');
require_once(dirname(__FILE__).'/SoColissimoCurlParser.php');
abstract class SoColissimoWebService extends SoNice_Retour
{
/** Supervision link to check web service availability */
const WS_SUPERVISION = 'http://ws.colissimo.fr/supervisionWSShipping/supervision.jsp';
const SCE_WS = 'https://ws.colissimo.fr/sls-ws/SlsServiceWS';
const SCE_WS_TELINTRANS = 'http://pfi.telintrans.fr/sls-ws/SlsServiceWS';
/** @var mixed The web service response */
public $response = null;
/** @var SoColissimoCurlParser */
public $raw_response;
public $origin_request;
public $error = null;
public $request;
public $module_conf;
public $carrier_conf;
/** @var array Contains options for the soap client connection */
protected $debug = false;
public function __construct($demo = false)
{
parent::__construct();
$this->demo = $demo ? $demo : Configuration::get('ETIQUETAGE_RETURN_TEST');
$this->module_conf = unserialize(Configuration::get(
'ETIQUETAGE_RETURN_CONF',
null,
$this->context->shop->id_shop_group,
$this->context->shop->id
));
}
public function l($string, $specific = false, $locale = null)
{
if (!$specific) {
$specific = basename(__FILE__, '.php');
}
if (class_exists('Translate')) {
return Translate::getModuleTranslation(get_parent_class(), $string, $specific);
}
return parent::l($string, $specific);
}
private function _fillXML($params, &$sls_generate_label, &$document)
{
$requires_cdata = array(
'Description', 'instructions', 'commercialName', 'companyName', 'lastName', 'firstName',
'line0', 'line1', 'line2', 'line3', 'city'
);
foreach ($params as $key => $value) {
if (is_numeric($key)) {
// only happens with articles
$key = 'article';
}
if (!is_array($value)) {
if ($value) {
if (in_array($key, $requires_cdata)) {
$tmp_element = $document->createElement($key);
$tmp_element->appendChild($document->createCDATASection($value));
} else {
$tmp_element = $document->createElement($key, $value);
}
$sls_generate_label->appendChild($tmp_element);
}
} else {
$new_child = $document->createElement($key);
$sls_generate_label->appendChild($new_child);
$this->_fillXML($value, $new_child, $document);
}
}
}
protected function _callWS($params)
{
$document = new DOMDocument('1.0', 'utf-8');
$document->formatOutput = true;
$document->preserveWhiteSpace = true;
$soap_envelope = $document->createElement('soap:Envelope');
$soap_envelope->setAttribute('xmlns:soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$soap_envelope->setAttribute('xmlns:sls', 'http://sls.ws.coliposte.fr');
$soap_body = $document->createElement('soap:Body');
$sls_generate_label = $document->createElement('sls:generateLabel');
$sls_generate_label_request = $document->createElement('generateLabelRequest');
$soap_envelope->appendChild($soap_body);
$soap_body->appendChild($sls_generate_label);
$sls_generate_label->appendChild($sls_generate_label_request);
$document->appendChild($soap_envelope);
$this->_fillXML($params, $sls_generate_label_request, $document);
$request = $document->saveXML();
// var_dump($this->xmlpp($request));die;
$this->origin_request = $request;
$this->request = $request;
$headers = array(
'Accept-Encoding: gzip,deflate',
'Content-Type: text/xml; charset="utf-8"',
'SOAPAction: ""'
);
$webservice_url = array_key_exists('dev_mode', $this->module_conf) && $this->module_conf['dev_mode'] ?
self::SCE_WS_TELINTRANS : self::SCE_WS;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $webservice_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_VERBOSE, true);
// IF demo() ELSE webservice() ENDIF
if ($this->demo) {
$result = Tools::file_get_contents(dirname(__FILE__).'/../functions/raw_response.txt');
} else {
$result = curl_exec($ch);
}
$this->raw_response = new SoColissimoCurlParser($result);
$result = $this->xmldata($result);
if ($result === false) {
echo nl2br(print_r(curl_getinfo($ch), true));
echo 'Request';
print('<pre>'.print_r(htmlentities($request, ENT_QUOTES, 'UTF-8'), true).'</pre>');
echo 'cURL error number:'.curl_errno($ch).'\n<br/>';
echo 'cURL error message:'.curl_error($ch).'\n<br/>';
curl_close($ch);
throw new Exception(curl_error($ch));
}
curl_close($ch);
return ($result);
}
public function xmldata($page)
{
if (empty($page)) {
printf('%s(#%d): empty string passed to the function', basename(__FILE__), __LINE__);
return (false);
}
// On some system the following regexp failed because the response is too long
// Minimize the response by removing header at beginning and kepping enough text to catch the XML code.
$page = Tools::substr($page, 100, 1250);
preg_match('/<soap:Envelope[\s\S]*soap:Envelope>/', $page, $page);
$page = reset($page);
$page = $this->xmlpp($page);
// remove namespaces
$page = preg_replace('/xmlns[^=]*="[^"]*"/i', '', $page);
$page = preg_replace('/[a-zA-Z0-9]+:([a-zA-Z0-9]+[ =>])/', '$1', $page);
// filters
$page = str_replace(array("\n", "\r", "\t"), '', $page);
$page = trim(str_replace('"', "'", $page));
$xml = simplexml_load_string($page, null, LIBXML_NOCDATA);
if (!$xml instanceof SimpleXMLElement) {
printf('%s(#%d): invalid string passed to the function: "%s"', basename(__FILE__), __LINE__, $page);
return (false);
}
return ($xml);
}
/**
* Check the availability of ColiPoste web services
*
* @return boolean Supervision status
*/
public static function webServiceSupervision()
{
$supervision = Tools::file_get_contents(self::WS_SUPERVISION);
if (preg_match('/\[OK\]/', $supervision)) {
return (true);
}
return (false);
}
public function xmlpp($xml, $html_output = false)
{
$xml_obj = new SimpleXMLElement($xml);
$level = 4;
$indent = 0;
$pretty = array();
$xml = explode("\n", preg_replace('/>\s*</', ">\n<", $xml_obj->asXML()));
if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
$pretty[] = array_shift($xml);
}
foreach ($xml as $el) {
if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
$pretty[] = str_repeat(' ', $indent).$el;
$indent += $level;
} else {
if (preg_match('/^<\/.+>$/', $el)) {
$indent -= $level;
}
if ($indent < 0) {
$indent += $level;
}
$pretty[] = str_repeat(' ', $indent).$el;
}
}
$xml = implode("\n", $pretty);
if ($html_output) {
$xml = htmlentities($xml);
}
return $xml;
}
}

View File

@@ -0,0 +1,336 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from Common-Services Co., Ltd.
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe Common-Services Co., Ltd.
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @package SoNice Retour
* @author Alexandre D.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @license Commercial license
* Support by mail : support.sonice@common-services.com
*/
class SoNiceEtiquetageValidate
{
public static $country_calling_codes = array(
'AF' => '93',
'AL' => '355',
'DZ' => '213',
'AD' => '376',
'AO' => '244',
'AQ' => '672',
'AR' => '54',
'AM' => '374',
'AW' => '297',
'AU' => '61',
'AT' => '43',
'AZ' => '994',
'BH' => '973',
'BD' => '880',
'BY' => '375',
'BE' => '32',
'BZ' => '501',
'BJ' => '229',
'BT' => '975',
'BO' => '591',
'BQ' => '599',
'BA' => '387',
'BW' => '267',
'BV' => '47',
'BR' => '55',
'IO' => '246',
'BN' => '673',
'BG' => '359',
'BF' => '226',
'BI' => '257',
'KH' => '855',
'CM' => '237',
'CA' => '1',
'CV' => '238',
'CF' => '236',
'TD' => '235',
'CL' => '56',
'CN' => '86',
'CX' => '61',
'CC' => '61',
'CO' => '57',
'KM' => '269',
'CG' => '242',
'CD' => '243',
'CK' => '682',
'CR' => '506',
'HR' => '385',
'CU' => '53',
'CW' => '599',
'CY' => '357',
'CZ' => '420',
'CI' => '225',
'DK' => '45',
'DJ' => '253',
'EC' => '593',
'EG' => '20',
'SV' => '503',
'GQ' => '240',
'ER' => '291',
'EE' => '372',
'ET' => '251',
'FK' => '500',
'FO' => '298',
'FJ' => '679',
'FI' => '358',
'FR' => '33',
'GF' => '594',
'PF' => '689',
'TF' => '262',
'GA' => '241',
'GM' => '220',
'GE' => '995',
'DE' => '49',
'GH' => '233',
'GI' => '350',
'GR' => '30',
'GL' => '299',
'GP' => '590',
'GT' => '502',
'GG' => '44',
'GN' => '224',
'GW' => '245',
'GY' => '592',
'HT' => '509',
'HM' => '672',
'HN' => '504',
'HK' => '852',
'HU' => '36',
'IS' => '354',
'IN' => '91',
'ID' => '62',
'IR' => '98',
'IQ' => '964',
'IE' => '353',
'IM' => '44',
'IL' => '972',
'IT' => '39',
'JP' => '81',
'JE' => '44',
'JO' => '962',
'KZ' => '7',
'KE' => '254',
'KI' => '686',
'KP' => '850',
'KR' => '82',
'KW' => '965',
'KG' => '996',
'LA' => '856',
'LV' => '371',
'LB' => '961',
'LS' => '266',
'LR' => '231',
'LY' => '218',
'LI' => '423',
'LT' => '370',
'LU' => '352',
'MO' => '853',
'MK' => '389',
'MG' => '261',
'MW' => '265',
'MY' => '60',
'MV' => '960',
'ML' => '223',
'MT' => '356',
'MH' => '692',
'MQ' => '596',
'MR' => '222',
'MU' => '230',
'YT' => '262',
'MX' => '52',
'FM' => '691',
'MD' => '373',
'MC' => '33',
'MN' => '976',
'ME' => '382',
'MA' => '212',
'MZ' => '258',
'MM' => '95',
'NA' => '264',
'NR' => '674',
'NP' => '977',
'NL' => '31',
'NC' => '687',
'NZ' => '64',
'NI' => '505',
'NE' => '227',
'NG' => '234',
'NU' => '683',
'NF' => '672',
'NO' => '47',
'OM' => '968',
'PK' => '92',
'PW' => '680',
'PS' => '970',
'PA' => '507',
'PG' => '675',
'PY' => '595',
'PE' => '51',
'PH' => '63',
'PN' => '870',
'PL' => '48',
'PT' => '351',
'PR' => '1',
'QA' => '974',
'RO' => '40',
'RU' => '7',
'RW' => '250',
'RE' => '262',
'BL' => '590',
'MF' => '590',
'PM' => '508',
'WS' => '685',
'SM' => '378',
'ST' => '239',
'SA' => '966',
'SN' => '221',
'SC' => '248',
'SL' => '232',
'SG' => '65',
'SK' => '421',
'SI' => '386',
'SB' => '677',
'SO' => '252',
'ZA' => '27',
'GS' => '500',
'SS' => '211',
'ES' => '34',
'LK' => '94',
'SD' => '249',
'SR' => '597',
'SJ' => '47',
'SZ' => '268',
'SE' => '46',
'CH' => '41',
'SY' => '963',
'TW' => '886',
'TJ' => '992',
'TZ' => '255',
'TH' => '66',
'TL' => '670',
'TG' => '228',
'TK' => '690',
'TO' => '676',
'TN' => '216',
'TR' => '90',
'TM' => '993',
'TV' => '688',
'UG' => '256',
'UA' => '380',
'AE' => '971',
'GB' => '44',
'US' => '1',
'UY' => '598',
'UZ' => '998',
'VU' => '678',
'VE' => '58',
'VN' => '84',
'WF' => '681',
'EH' => '212',
'YE' => '967',
'ZM' => '260',
'ZW' => '263',
'AX' => '358'
);
public static $format_codification = array(
'A' => '/[^a-zA-Z ]/',
'AN' => '/[^[:print:]]|[\"]/',
'CP' => '/[^a-zA-Z0-9]/',
'N' => '/[^-0-9.]/',
// ^((\+|00)([0-9]{1,3})\s?|0)[067]{1,2}(\s?\d{2}){4}$
'TP' => '/[^+0-9]/'
);
public static function sanitize($data, $format, $element = null, $iso_country = null)
{
$data_format = preg_replace('/[^a-zA-Z]/', '', $format);
switch ($data_format) {
case 'A':
case 'AN':
case 'CP':
case 'N':
case 'TP':
$data_min_length = 0;
$data_max_length = 999;
$data_length = explode('..', preg_replace('/[^0-9\.\-]/', '', $format));
if (count($data_length) == 1 && $data_length[0]) {
$data_min_length = $data_max_length = (int)$data_length[0];
} elseif (count($data_length) == 2) {
$data_min_length = (int)$data_length[0];
$data_max_length = (int)$data_length[1];
}
if (mb_detect_encoding((string)$data) != 'UTF-8') {
iconv('ISO-8859-15', 'UTF-8//TRANSLIT', $data);
}
$data = mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');
$searches = array('&szlig;', '&(..)lig;', '&([aouAOU])uml;', '&(.)[^;]*;');
$replacements = array('ss', '\\1', '\\1e', '\\1');
foreach ($searches as $key => $search) {
$data = mb_ereg_replace($search, $replacements[$key], $data);
}
$data = preg_replace(self::$format_codification[$data_format], ' ', $data); // replace space by empty string
if (Tools::strlen($data) < $data_min_length) {
die(sprintf(
'Error with the element ['.$element.'] : String ["%s"] is too short ! Minimum length is %d.',
$data,
$data_min_length
));
}
$data = Tools::substr(str_replace(':', '', $data), 0, $data_max_length);
break;
case 'B':
$data = (int)(bool)$data;
break;
default:
die('Error with the element ['.$element.'] : Unknown format : '.$data_format);
}
// Phone | change 0033661123456 to +33661123456
if ($data_format == 'TP') {
if ($iso_country && Tools::strlen($iso_country) == 2 && Tools::strtoupper($iso_country) == 'FR') {
$data = preg_replace('/^\+33/', '0', $data);
} else {
$data = preg_replace('/^00/', '+', $data);
if ($iso_country && Tools::strlen($iso_country) == 2 && $data && $data[0] != '+' && isset(self::$country_calling_codes[$iso_country])) {
$data = '+'.self::$country_calling_codes[$iso_country].Tools::substr($data, 1);
}
// Check belgium phone number, must start by +324
if ($iso_country && Tools::strlen($iso_country) == 2 && Tools::strtoupper($iso_country) == 'BE' && Tools::substr($data, 0, 4) != '+324') {
$data = null;
}
}
}
return $data;
}
}

View File

@@ -0,0 +1,653 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from Common-Services Co., Ltd.
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe Common-Services Co., Ltd.
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @package SoNice Retour
* @author Alexandre D.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @license Commercial license
* Support by mail : support.sonice@common-services.com
*/
require_once(_PS_MODULE_DIR_.'sonice_retour/classes/SoColissimoWebService.php');
require_once(_PS_MODULE_DIR_.'sonice_retour/classes/SoNiceEtiquetageValidate.php');
final class SoNiceRetourPDF extends SoColissimoWebService
{
const FUNCTION_WS = 'getLetterColissimo';
const SCE_TABLE = 'so_return_label';
public $ps15x;
public $id_lang;
public $protocol;
public $url;
public $path;
public $product_list;
public $id_order_details_to_return;
public $order;
public $customer;
public $address;
public $params;
protected $need_cn23 = array(
'FR', 'BE', 'MC', 'AD', 'NL', 'DE', 'GB', 'LU', 'ES', 'PT', 'AT', 'CZ', 'HU', 'SK', 'SI', 'LT', 'LV', 'EE'
);
public function __construct($id_order, $id_order_details)
{
if (!is_null($id_order)) {
$this->order = new Order((int)$id_order);
}
if (!is_null($id_order_details)) {
$this->id_order_details_to_return = $id_order_details;
}
if (Validate::isLoadedObject($this->order)) {
$this->customer = new Customer((int)$this->order->id_customer);
$this->product_list = $this->order->getProductsDetail();
$this->address = new Address((int)$this->order->id_address_delivery);
$relais = false;
if ($this->ps15x && (Module::isEnabled('soflexibilite') || Module::isEnabled('soliberte'))) {
$soflexibilite_relays = Configuration::getMultiple(array(
'SOFLEXIBILITE_A2P_ID',
'SOFLEXIBILITE_BPR_ID',
'SOLIBERTE_A2P_ID',
'SOLIBERTE_BPR_ID'
));
if (strpos($this->address->alias, 'So Colissimo') !== false
&& in_array($this->order->id_carrier, $soflexibilite_relays)) {
$relais = true;
}
}
if ($this->ps15x && Module::isEnabled('chronopost')) {
$chronopost_relais = Configuration::get('CHRONORELAIS_CARRIER_ID');
if (strpos($this->address->alias, 'ChronoRelais') !== false
&& $this->order->id_carrier == $chronopost_relais) {
$relais = true;
}
}
if ($this->ps15x && Module::isEnabled('dpdfrance')) {
$relais = (bool)Db::getInstance()->getValue(
'SELECT `relay_id`
FROM `'._DB_PREFIX_.'dpdfrance_shipping`
WHERE `id_customer` = '.(int)$this->order->id_customer.'
AND `id_cart` = '.(int)$this->order->id_cart.'
AND `id_carrier` = '.(int)$this->order->id_carrier
);
}
if ($relais) {
// si l'adresse de livraison correspond a un relais on utilise l'adresse de facturation sur l'etiquette
$this->address = new Address((int)$this->order->id_address_invoice);
}
Context::getContext()->shop = new Shop($this->order->id_shop);
}
parent::__construct();
$this->path = _PS_MODULE_DIR_.'sonice_retour/';
$this->protocol = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
$this->url = $this->protocol.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').
__PS_BASE_URI__.'modules/sonice_retour/';
$this->ps15x = version_compare(_PS_VERSION_, '1.5', '>=');
if (version_compare(_PS_VERSION_, '1.5', '>=')) {
$this->id_lang = (int)Context::getContext()->language->id;
$this->context = Context::getContext();
} else {
require_once(dirname(__FILE__).'/../backward_compatibility/backward.php');
$this->context = Context::getContext();
$this->id_lang = (int)Context::getContext()->language->id;
$this->context->shop->id = null;
$this->context->shop->id_shop_group = null;
}
}
public function l($string, $specific = false, $locale = null)
{
if (!$specific) {
$specific = basename(__FILE__, '.php');
}
if (class_exists('Translate')) {
return Translate::getModuleTranslation(get_parent_class(), $string, $specific);
}
return parent::l($string, $specific);
}
/**
* Call Coliposte Web Service
*
* @return bool
*/
public function callWS($login = null, $pwd = null, $params = null)
{
if (!$this->webServiceSupervision()) {
$this->error = new StdClass();
$this->error->errorID = 'SoNiceRetourPDF line '.__LINE__;
$this->error->error = $this->l(
'Network Supervision Failed. The Coliposte web service is currently having some trouble or is in maintenance. Please try again in a moment.'
);
return (false);
}
try {
if (is_array($params) && count($params)) {
$parameters = $params;
} else {
$parameters = $this->_getParams();
if ($login && $pwd) {
$parameters['letter']['password'] = $pwd;
$parameters['letter']['contractNumber'] = $login;
}
}
$this->response = parent::_callWS($parameters);
} catch (Exception $e) {
$this->error = new StdClass();
$this->error->errorID = 'SoNiceRetourPDF line '.__LINE__;
$this->error->error = sprintf('%s : %s', $e->getLine(), $e->getMessage());
return (false);
}
return (true);
}
public function getFormattedResponse()
{
$result = array();
$result['errorID'] = null;
$result['error'] = null;
$result['PdfUrl'] = null;
if (!$this->response instanceof SimpleXMLElement) {
$result['errorID'] = 'SoNiceRetourPDF #'.__LINE__;
$result['error'] = $this->l('The result does not have an XML format.');
return ($result);
}
$elements = $this->response->xpath('//Envelope/Body/generateLabelResponse/*');
if (!isset($elements[0]) || !isset($elements[0]->messages)) {
$result['errorID'] = 'SoNiceRetourPDF line '.__LINE__;
$result['error'] = 'Wrong Message';
if (isset($elements[0]->faultcode) && isset($elements[0]->faultstring)) {
echo '<pre>'.print_r($elements, true).'</pre>';
}
return ($result);
}
if ($elements[0]->messages->type == 'ERROR') {
$result['errorID'] = $elements[0]->messages->id;
$result['error'] = $elements[0]->messages->messageContent;
return ($result);
}
$result['parcelNumber'] = (string)$elements[0]->labelResponse->parcelNumber;
if ($this->demo) {
$result['parcelNumber'] = '8R'.abs(rand(1000000, 9999999)).abs(rand(100, 999));
}
// Download label
if ($this->demo) {
$result['PdfUrl'] = $this->url.'functions/demo_retour.pdf';
} elseif (isset($elements[0]->labelResponse->pdfUrl) && Tools::strlen((string)$elements[0]->labelResponse->pdfUrl)) {
$label = Tools::file_get_contents(str_replace('&amp;', '&', (string)$elements[0]->labelResponse->pdfUrl));
if (file_put_contents($this->path.'download/'.$result['parcelNumber'].'.pdf', $label)) {
$result['PdfUrl'] = str_replace('&amp;', '&', (string)$elements[0]->labelResponse->pdfUrl);
}
} elseif (!isset($elements[0]->labelResponse->pdfUrl)) {
$label = $this->raw_response->parse()->getLabelBinary();
if (!file_put_contents($this->path.'download/'.$result['parcelNumber'].'.pdf', $label)) {
echo $this->l('ERROR, unable to save label on the server. Please check the access permission of the folder ').
_PS_MODULE_DIR_.'sonice_retour/download/';
}
} else {
$result['errorID'] = 'SoNiceRetourPDF line '.__LINE__;
$result['error'] = 'No PDF from Coliposte to download...';
}
return ($result);
}
/**
* Fill the parameters for the web service
*
* @return array
*/
private function _getParams()
{
$date_deposite = new DateTime();
if (!Tools::strlen($this->module_conf['ContractNumber']) || !Tools::strlen($this->module_conf['Password']) ||
!Tools::strlen($this->module_conf['companyName']) || !Tools::strlen($this->module_conf['Line2']) ||
!Tools::strlen($this->module_conf['PostalCode']) || !Tools::strlen($this->module_conf['City'])) {
die($this->l('You need to configure the module with your login and address details.'));
}
if (Tools::strlen($this->module_conf['deposit_date'])) {
$date_deposite->modify('+'.(int)$this->module_conf['deposit_date'].' Day');
}
$order_total_weight = (float)$this->order->getTotalWeight();
if (!$order_total_weight || $order_total_weight < 0.01) {
$order_total_weight = 0.01;
}
if ($order_total_weight > 30) {
$order_total_weight /= 1000;
}
$phone_mobile = $this->address->phone_mobile;
if (!preg_match('/^((\+|00)([0-9]{1,3})\s?|0)[067]{1,2}(\s?\d{2}){4}$/', $phone_mobile)) {
$phone_mobile = $this->address->phone_mobile;
}
// For senderParcelRef
// If no id_return is given then we get the new one that should be created
$parcel_ref = (int)Tools::getValue('id_return') ?: (int)Db::getInstance()->getValue(
'SELECT 1 + IFNULL((
SELECT `id_order_return` AS `id_order_return`
FROM `'._DB_PREFIX_.'order_return`
ORDER BY `id_order_return` DESC
LIMIT 1),
0)'
);
$this->updateSenderAddress();
$this->updateAddresseeAddress();
$total_shipping_fee = version_compare(_PS_VERSION_, '1.5', '>=') ?
$this->order->total_shipping_tax_incl : $this->order->total_shipping;
$total_shipping_fee = Tools::ps_round($total_shipping_fee, 2);
$params = array(
'contractNumber' => SoNiceEtiquetageValidate::sanitize($this->module_conf['ContractNumber'], 'N6', 'contractNumber'),
'password' => SoNiceEtiquetageValidate::sanitize($this->module_conf['Password'], 'AN6..15', 'password'),
'outputFormat' => array(
'x' => 0,
'y' => 0,
'outputPrintingType' => 'PDF_A4_300dpi',
'returnType' => $this->module_conf['returnType']
),
'letter' => array(
'service' => array(
'productCode' => (Tools::strtoupper(Country::getIsoById((int)$this->address->id_country)) == 'FR' ? 'CORE' : 'CORI'),
'depositDate' => $date_deposite->format('Y-m-d'),
'transportationAmount' => SoNiceEtiquetageValidate::sanitize($total_shipping_fee * 100, 'N', 'transportationAmount'),
'totalAmount' => SoNiceEtiquetageValidate::sanitize($total_shipping_fee * 100, 'N', 'totalAmount'), // International
'orderNumber' => SoNiceEtiquetageValidate::sanitize($this->order->id, 'N0..30', 'orderNumber'),
'commercialName' => SoNiceEtiquetageValidate::sanitize($this->module_conf['companyName'], 'AN', 'commercialName'),
),
'parcel' => array(
'insuranceValue' => null,
'weight' => SoNiceEtiquetageValidate::sanitize($order_total_weight, 'N', 'weight'),
'nonMachinable' => false,
'instructions' => null,
'pickupLocationId' => null,
),
'customsDeclarations' => $this->getCustomsDeclarations(),
'sender' => array(
'senderParcelRef' => SoNiceEtiquetageValidate::sanitize('RET'.$parcel_ref, 'AN', 'senderParcelRef'),
'address' => array(
'companyName' => SoNiceEtiquetageValidate::sanitize($this->address->company, 'AN0..35', 'sender::companyName'),
'lastName' => SoNiceEtiquetageValidate::sanitize($this->address->lastname, 'A0..35', 'sender::lastname'),
'firstName' => SoNiceEtiquetageValidate::sanitize($this->address->firstname, 'A0..35', 'sender::firstname'),
'line0' => SoNiceEtiquetageValidate::sanitize($this->address->address2, 'AN0..35', 'sender::line0'),
// OCARAT utilisation de line1 pour indiquer le nom de l'expediteur si son adresse contient un nom de societe
'line1' => SoNiceEtiquetageValidate::sanitize(
(!empty($this->address->company) ?
'(' . $this->address->lastname . ' ' . $this->address->firstname . ')' :
null
),
'AN0..35',
'sender::line1'
),
'line2' => SoNiceEtiquetageValidate::sanitize($this->address->address1, 'AN1..35', 'sender::line2'),
'line3' => null,
'countryCode' => SoNiceEtiquetageValidate::sanitize(Country::getIsoById((int)$this->address->id_country), 'A2', 'sender::countryCode'),
'city' => SoNiceEtiquetageValidate::sanitize($this->address->city, 'AN1..35', 'sender::city'),
'zipCode' => SoNiceEtiquetageValidate::sanitize($this->address->postcode, 'AN0..9', 'sender::zipCode'),
'phoneNumber' => Tools::strlen($this->address->phone) > 5
? SoNiceEtiquetageValidate::sanitize($this->address->phone, 'TP0..15', 'sender::phoneNumber', Country::getIsoById((int)$this->address->id_country))
: null,
'mobileNumber' => $phone_mobile
? SoNiceEtiquetageValidate::sanitize($phone_mobile, 'TP0..15', 'sender::mobileNumber', Country::getIsoById((int)$this->address->id_country))
: SoNiceEtiquetageValidate::sanitize($this->address->phone_mobile, 'TP0..15', 'sender::mobileNumber', Country::getIsoById((int)$this->address->id_country)),
'doorCode1' => null,
'doorCode2' => null,
'email' => SoNiceEtiquetageValidate::sanitize($this->customer->email, 'AN0..80', 'sender::email'),
'intercom' => null
)
),
'addressee' => array(
'address' => array(
'companyName' => SoNiceEtiquetageValidate::sanitize($this->module_conf['companyName'], 'AN0..35', 'addressee::companyName'),
'lastName' => SoNiceEtiquetageValidate::sanitize($this->module_conf['Name'], 'A0..35', 'addressee::lastname'),
'firstName' => SoNiceEtiquetageValidate::sanitize($this->module_conf['Surname'], 'A0..29', 'addressee::firstname'),
'line0' => SoNiceEtiquetageValidate::sanitize($this->module_conf['Line0'], 'AN0..35', 'addressee::line0'),
'line1' => null,
'line2' => SoNiceEtiquetageValidate::sanitize($this->module_conf['Line2'], 'AN1..35', 'addressee::line2'),
'line3' => null,
'countryCode' => Country::getIsoById(Configuration::get('PS_SHOP_COUNTRY_ID')) ?: 'FR',
'city' => SoNiceEtiquetageValidate::sanitize($this->module_conf['City'], 'AN1..35', 'addressee::city'),
'zipCode' => SoNiceEtiquetageValidate::sanitize($this->module_conf['PostalCode'], 'AN0..9', 'addressee::zipCode'),
'phoneNumber' => SoNiceEtiquetageValidate::sanitize($this->module_conf['phoneNumber'], 'TP0..15', 'addressee::phoneNumber'),
'mobileNumber' => null,
'doorCode1' => null,
'doorCode2' => null,
'email' => SoNiceEtiquetageValidate::sanitize($this->module_conf['Mail'], 'AN0..80', 'addressee::email'),
'intercom' => null,
'language' => 'FR',
)
)
)
);
$this->validateParameters($params);
return ($params);
}
private function updateAddresseeAddress()
{
$product = (array)$this->order->getProducts();
$product = reset($product);
$id_warehouse = array_key_exists('id_warehouse', $product) ?
$product['id_warehouse'] : 0;
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $id_warehouse) {
$warehouse = new Warehouse($id_warehouse) ;
if (Validate::isLoadedObject($warehouse)) {
if ($id_address = (int)$warehouse->id_address) {
$address = new Address($id_address);
if (Validate::isLoadedObject($address)) {
$this->module_conf['companyName'] = $warehouse->name;
$this->module_conf['Line2'] = $address->address1;
$this->module_conf['Line0'] = $address->address2;
$this->module_conf['countryCode'] = Country::getIsoById($address->id_country);
$this->module_conf['city'] = $address->city;
$this->module_conf['zipCode'] = $address->postcode;
$this->module_conf['phoneNumber'] = $address->phone;
$this->module_conf['mobileNumber'] = $address->phone_mobile;
}
}
}
}
}
private function updateSenderAddress()
{
$relay = Db::getInstance()->getRow(
'SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int)$this->order->id_cart.'
AND `id_customer` = '.(int)$this->order->id_customer
);
if ($relay && count($relay)) {
$invoice_address = new Address($this->order->id_address_invoice);
if (Validate::isLoadedObject($invoice_address)) {
$this->address = $invoice_address;
// $this->address->company = $relay['cecompanyname'];
// $this->address->firstname = isset($relay['cefirstname']) && $relay['cefirstname'] ?
// Tools::ucfirst($relay['cefirstname']) : Tools::ucfirst($relay['prfirstname']);
// $this->address->lastname = isset($relay['cename']) && $relay['cename'] ?
// Tools::ucfirst($relay['cename']) : Tools::ucfirst($this->address->lastname);
// $this->address->address1 = isset($relay['praddress1']) && $relay['praddress1'] ?
// Tools::ucfirst($relay['praddress1']) : Tools::ucfirst($this->address->address1);
// $this->address->address2 = isset($relay['praddress2']) && $relay['praddress2'] ?
// Tools::ucfirst($relay['praddress2']) : Tools::ucfirst($this->address->address2);
// $this->address->postcode = isset($relay['przipcode']) && $relay['przipcode'] ?
// Tools::ucfirst($relay['przipcode']) : Tools::ucfirst($this->address->postcode);
// $this->address->city = isset($relay['prtown']) && $relay['prtown'] ?
// Tools::ucfirst($relay['prtown']) : Tools::ucfirst($this->address->city);
//
// if (isset($relay['cecountry']) && Tools::strlen($relay['cecountry']) == 2) {
// $id_country = Country::getByIso($relay['cecountry']);
// if ($this->address->id_country !== $id_country) {
// $this->address->id_country = $id_country;
// $this->address->country = Country::getNameById($this->order->id_lang, $id_country);
// }
// }
}
}
}
private function validateParameters(&$params)
{
// Lastname missing
// Marketplace order for instance
if (!isset($params['letter']['sender']['address']['lastName']) || !$params['letter']['sender']['address']['lastName']) {
if (strpos($params['letter']['sender']['address']['firstName'], 'co')) {
$full_name = explode('co', $params['letter']['sender']['address']['firstName']);
$full_name = explode(' ', reset($full_name));
$params['letter']['sender']['address']['firstName'] = array_shift($full_name);
$params['letter']['sender']['address']['lastName'] = implode(' ', $full_name);
} else {
$full_name = explode(' ', $params['letter']['sender']['address']['firstName']);
$params['letter']['sender']['address']['firstName'] = array_shift($full_name);
$params['letter']['sender']['address']['lastName'] = implode(' ', $full_name);
}
}
// Firstname missing
if (!isset($params['letter']['sender']['address']['firstName']) || !$params['letter']['sender']['address']['firstName'] ||
Tools::strlen($params['letter']['sender']['address']['firstName']) < 2) {
if (strpos($params['letter']['sender']['address']['lastName'], ' co ')) {
$full_name = explode('co', $params['letter']['sender']['address']['lastName']);
$full_name = explode(' ', reset($full_name));
$params['letter']['sender']['address']['lastName'] = array_shift($full_name);
$params['letter']['sender']['address']['firstName'] = implode(' ', $full_name);
} else {
$full_name = explode(' ', $params['letter']['sender']['address']['lastName']);
$params['letter']['sender']['address']['lastName'] = array_shift($full_name);
$params['letter']['sender']['address']['firstName'] = implode(' ', $full_name);
}
}
// If COLI and no shipping fee then set it to 1EUR
if (isset($params['letter']['service']['productCode']) &&
in_array($params['letter']['service']['productCode'], array('CORI'))) {
$params['letter']['service']['transportationAmount'] = max(
100,
(int)$params['letter']['service']['transportationAmount']
);
$params['letter']['service']['totalAmount'] = max(
100,
(int)$params['letter']['service']['totalAmount']
);
}
}
private function getCustomsDeclarations()
{
$customs_declarations = null;
$address_country = Tools::strtoupper(Country::getIsoById((int)$this->address->id_country));
$currency = new Currency($this->order->id_currency);
if (in_array($address_country, $this->need_cn23)) {
return $customs_declarations;
}
if (!Validate::isLoadedObject($currency)) {
$currency = new stdClass();
$currency->iso_code = 'EUR';
}
// Invoice number missing fix
// In case of external ERP, etc.
if (!$this->order->invoice_number) {
$this->order->invoice_number = sprintf('%06s', $this->order->id);
}
$articles = array();
foreach ($this->order->getProducts() as $id_product => $product) {
if ($product['product_price'] == 0) {
$product['product_price'] = 1;
}
$articles[$id_product] = array(
'description' => SoNiceEtiquetageValidate::sanitize(
Tools::substr(str_replace(',', '', strip_tags($product['product_name'])), 0, 63),
'AN1..64'
),
'quantity' => (int)SoNiceEtiquetageValidate::sanitize($product['product_quantity'], 'N'),
'weight' => ($product['product_weight'] >= 0.01) ?
(float)SoNiceEtiquetageValidate::sanitize($product['product_weight'], 'N') : 0.01,
'value' => (float)SoNiceEtiquetageValidate::sanitize($product['product_price'], 'N'),
'hsCode' => 123456, // TODO SoNiceEtiquetageHsCode::getProductHsCode($product['product_id']),
'originCountry' => $address_country,
'currency' => $currency->iso_code,
'artref' => $product['product_reference'],
'originalIdent' => 'A'
);
if (isset($this->module_conf['weight_unit']) && $this->module_conf['weight_unit'] == 'g') {
$articles[$id_product]['weight'] /= 1000;
}
}
$articles['category'] = array(
'value' => 6 // Retour de marchandise
);
$articles['original'] = array(
'originalIdent' => 'A',
'originalInvoiceNumber' => $this->order->invoice_number,
'originalInvoiceDate' => date('Y-m-d', strtotime($this->order->invoice_date)),
'originalParcelNumber' => $this->order->shipping_number
);
$invoice_format = '%1$s%2$06d';
if (Configuration::get(
'PS_INVOICE_USE_YEAR',
null,
$this->context->shop->id_shop_group,
$this->context->shop->id
)) {
$invoice_format = Configuration::get(
'PS_INVOICE_YEAR_POS',
null,
$this->context->shop->id_shop_group,
$this->context->shop->id
) ? '%1$s%3$s/%2$06d' : '%1$s%2$06d/%3$s';
}
$customs_declarations = array(
'includeCustomsDeclarations' => true,
'contents' => $articles,
'invoiceNumber' => sprintf(
$invoice_format,
Configuration::get(
'PS_INVOICE_PREFIX',
null,
$this->context->shop->id_shop_group,
$this->context->shop->id
),
$this->order->invoice_number
),
'licenceNumber' => null,
'certificatNumber' => null
);
return ($customs_declarations);
}
public static function getParcelNumberByIdOrder($id_order)
{
if (!is_int($id_order)) {
return (false);
}
return (Db::getInstance()->getValue('SELECT `parcel_number` FROM '._DB_PREFIX_.self::SCE_TABLE.' WHERE `id_order` = '.(int)$id_order));
}
public static function getLabelInformationByIdOrder($id_order)
{
if (!is_int($id_order)) {
return (false);
}
$data = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.self::SCE_TABLE.' WHERE `id_order` = '.(int)$id_order);
if (!is_array($data) || !count($data) || !$data) {
return (false);
}
return ($data[0]);
}
public static function getIdOrderByParcelNumber($parcel_number)
{
if (!$parcel_number) {
return (false);
}
return ((int)Db::getInstance()->getValue('SELECT `id_order` FROM '._DB_PREFIX_.self::SCE_TABLE.' WHERE `parcel_number` = "'.$parcel_number.'"'));
}
public static function deleteLabelByIdOrder($id_order)
{
if (!$id_order) {
return (false);
}
return (Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'sonice_etq_label WHERE `id_order` = '.(int)$id_order));
}
public static function getIdOrderCarrierByOrderId($id_order)
{
if (!$id_order) {
return (false);
}
return (Db::getInstance()->getValue('SELECT `id_order_carrier` FROM `'._DB_PREFIX_.'order_carrier` WHERE `id_order` = '.(int)$id_order));
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from Common-Services Co., Ltd.
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe Common-Services Co., Ltd.
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @package SoNice Retour
* @author Alexandre D.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @license Commercial license
* Support by mail : support.sonice@common-services.com
*/
class SoNiceRetourTools
{
public static function cleanup()
{
$now = time();
$output_dir = _PS_MODULE_DIR_.'sonice_retour/download/';
if (!is_dir($output_dir)) {
return null;
}
$files_pdf = glob($output_dir.'*.pdf');
$files_prn = glob($output_dir.'*.prn');
$files = array_merge($files_pdf, $files_prn);
if (!is_array($files) || !count($files)) {
return null;
}
// Sort by date
foreach ($files as $file) {
if (filemtime($file) < $now - (86400 * 31)) {
unlink($file);
}
}
}
public static function moduleIsInstalled($module_name)
{
if (method_exists('Module', 'isInstalled')) {
return (Module::isInstalled($module_name));
} else {
Db::getInstance()->executeS(
'SELECT `id_module`
FROM `'._DB_PREFIX_.'module`
WHERE `name` = \''.pSQL($module_name).'\''
);
return (bool)Db::getInstance()->numRows();
}
}
public static function arrayMapCastInteger($value)
{
return (int)$value;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

Binary file not shown.

View File

@@ -0,0 +1,240 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL SMC
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe SMC
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL SMC est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @author Debusschere A.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @package Shared
* @license Commercial license
*/
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* Class generating configuration message
*/
class ConfigureMessage
{
const _MESSAGE_ = '<div class="%s">%s</div>';
const _DEBUG_ = '<div class="%s"><pre>%s</pre></div>';
const _CLASS_ERROR_15_ = 'error';
const _CLASS_WARNING_15_ = 'warn';
const _CLASS_SUCCESS_15_ = 'conf';
const _CLASS_INFO_15_ = 'info hint';
const _CLASS_ERROR_16_ = 'alert alert-danger';
const _CLASS_WARNING_16_ = 'alert alert-warning';
const _CLASS_SUCCESS_16_ = 'alert alert-success';
const _CLASS_INFO_16_ = 'alert alert-info';
protected static $msg_list = array();
protected static $has_error_msg = false;
protected static $has_warning_msg = false;
protected static $has_success_msg = false;
protected static $has_info_msg = false;
/**
* Generate the HTML code corresponding to an error message
*
* @param String $msg
* return void|null
*/
public static function error($msg = 'Error')
{
if (is_array($msg) && count($msg)) {
foreach ($msg as $ps_error) {
self::error($ps_error);
}
return null;
}
$error_msg = null;
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$error_msg = sprintf(self::_MESSAGE_, self::_CLASS_ERROR_15_, $msg);
} else {
$error_msg = '<div class="bootstrap">'.sprintf(self::_MESSAGE_, self::_CLASS_ERROR_16_, $msg).'</div>';
}
self::$has_error_msg = true;
self::$msg_list[] = $error_msg;
}
/**
* Generate the HTML code corresponding to a warning message
*
* @param String $msg
*/
public static function warning($msg = 'Warning')
{
$warning_msg = null;
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$warning_msg = sprintf(self::_MESSAGE_, self::_CLASS_WARNING_15_, $msg);
} else {
$warning_msg = '<div class="bootstrap">'.sprintf(self::_MESSAGE_, self::_CLASS_WARNING_16_, $msg).'</div>';
}
self::$has_warning_msg = true;
self::$msg_list[] = $warning_msg;
}
/**
* Generate the HTML code corresponding to a success message
*
* @param String $msg
*/
public static function success($msg = 'Success')
{
$success_msg = null;
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$success_msg = sprintf(self::_MESSAGE_, self::_CLASS_SUCCESS_15_, $msg);
} else {
$success_msg = '<div class="bootstrap">'.sprintf(self::_MESSAGE_, self::_CLASS_SUCCESS_16_, $msg).'</div>';
}
self::$has_success_msg = true;
self::$msg_list[] = $success_msg;
}
/**
* Generate the HTML code corresponding to an information message
*
* @param String $msg
*/
public static function info($msg = 'Success')
{
$info_msg = null;
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$info_msg = sprintf(self::_MESSAGE_, self::_CLASS_INFO_15_, $msg);
} else {
$info_msg = '<div class="bootstrap">'.sprintf(self::_MESSAGE_, self::_CLASS_INFO_16_, $msg).'</div>';
}
self::$has_info_msg = true;
self::$msg_list[] = $info_msg;
}
/**
* Generate the HTML code corresponding to a debug message
*
* @param String $msg
*/
public static function debug($msg = 'Debug')
{
$info_msg = null;
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$info_msg = sprintf(self::_DEBUG_, self::_CLASS_INFO_15_, $msg);
} else {
$info_msg = '<div class="bootstrap">'.sprintf(self::_DEBUG_, self::_CLASS_INFO_16_, $msg).'</div>';
}
self::$msg_list[] = $info_msg;
}
/**
* Return the html code of all messages to be displayed
*
* @return String
*/
public static function display()
{
$html = '';
if (count(self::$msg_list)) {
foreach (self::$msg_list as $msg) {
$html .= $msg;
}
}
return ($html);
}
/**
* Return the list of message
*
* @return Array
*/
public static function getMessageList()
{
return (self::$msg_list);
}
/**
* Return true if the message list contain at least 1 error message
*
* @return Boolean
*/
public static function hasErrorMessage()
{
return (self::$has_error_msg);
}
/**
* Return true if the message list contain at least 1 warning message
*
* @return Boolean
*/
public static function hasWarningMessage()
{
return (self::$has_warning_msg);
}
/**
* Return true if the message list contain at least 1 success message
*
* @return Boolean
*/
public static function hasSuccessMessage()
{
return (self::$has_success_msg);
}
/**
* Return true if the message list contain at least 1 information message
*
* @return Boolean
*/
public static function hasInfoMessage()
{
return (self::$has_info_msg);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL SMC
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe SMC
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL SMC est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @author Debusschere A.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @package Shared
* @license Commercial license
*/
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* Class generating configuration tabs
*/
class ConfigureTab
{
public static function generateTabs($tab_list, $module_name = '')
{
// $protocol = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
if (!Tools::strlen($module_name)) {
$module_name = self::getModuleName();
}
// commented out by O.B. on 2015-03-10: cause cross domain redirection issue
// $url = $protocol.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').
// __PS_BASE_URI__.'modules/'.$module_name.'/';
$url = __PS_BASE_URI__.'modules/'.$module_name.'/';
$context = Context::getContext();
$context->smarty->assign(array(
'tab_list' => $tab_list,
'img_dir' => $url.'views/img/shared/tab/',
'module_url' => $url,
'module_name' => $module_name,
'ps16x' => version_compare(_PS_VERSION_, '1.6', '>='),
'ps15x' => version_compare(_PS_VERSION_, '1.5', '>='),
'has_line' => self::hasLine($tab_list),
'line_number' => self::getLineNumber($tab_list)
));
$html = $context->smarty->fetch(dirname(__FILE__).'/../../views/templates/admin/shared/tabs.tpl');
return ($html);
}
public static function getModuleName($addslash = false)
{
$e = new Exception();
$trace = $e->getTrace();
$caller = $trace[2];
if (!isset($caller['class'])) {
return (false);
}
return (Tools::strtolower($caller['class']).($addslash ? '/' : ''));
}
public static function hasLine($tab_list)
{
if (is_array($tab_list) && count($tab_list)) {
foreach ($tab_list as $tab) {
if (isset($tab['line']) && $tab['line']) {
return (true);
}
}
}
return (false);
}
public static function getLineNumber($tab_list)
{
$line_number = array();
if (is_array($tab_list) && count($tab_list)) {
foreach ($tab_list as $tab) {
if (isset($tab['line']) && $tab['line']) {
$line_number[$tab['line']] = 1;
}
}
}
return (count($line_number));
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,131 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL SMC
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden.
* In order to obtain a license, please contact us: contact@common-services.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe SMC
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL SMC est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
* ...........................................................................
*
* @author Debusschere A.
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @package Shared
* @license Commercial license
*/
/**
* Class generating module tabs
*/
class CommonServicesTab extends Tab
{
const ADD = 'a';
const REMOVE = 'd';
const UPDATE = 'u';
public static function setup($action, $class, $name, $parent, $debug = false)
{
switch ($action) {
case self::ADD:
if (!Tab::getIdFromClassName($class)) {
if (!self::installModuleTab($class, $name, $parent)) {
if ($debug) {
printf('%s(#%d): Unable to install: %s', basename(__FILE__), __LINE__, $class);
}
return false;
}
}
break;
case self::UPDATE:
if (self::Setup(self::REMOVE, $class, $name, $parent, $debug)) {
return (self::Setup(self::ADD, $class, $name, $parent, $debug));
}
break;
case self::REMOVE:
if (Tab::getIdFromClassName($class)) {
if (!self::uninstallModuleTab($class)) {
if ($debug) {
printf('%s(#%d): Unable to uninstall: %s', basename(__FILE__), __LINE__, $class);
}
return false;
}
}
break;
}
return true;
}
private static function installModuleTab($tabClass, $tabName, $tabParent)
{
$module = self::getModuleName();
$pass = true;
$tabNameLang = array();
foreach (Language::getLanguages() as $language) {
$tabNameLang[$language['id_lang']] = $tabName;
}
$tab = new Tab();
$tab->name = $tabNameLang;
$tab->class_name = $tabClass;
$tab->module = $module;
$tab->id_parent = Tab::getIdFromClassName($tabParent);
// For Prestashop 1.2
if (version_compare(_PS_VERSION_, '1.3', '<')) {
$pass = $tab->add();
} else {
$pass = $tab->save();
}
return ($pass);
}
public static function getModuleName()
{
$trace = debug_backtrace();
$caller = $trace[4];
if (!isset($caller['class'])) {
return (false);
} else {
return (Tools::strtolower($caller['class']));
}
}
private static function uninstallModuleTab($tabClass)
{
$pass = true;
$idTab = Tab::getIdFromClassName($tabClass);
// Big Bug PS 1.4 - cached entry is not removed on delete() ...
if (version_compare(_PS_VERSION_, '1.5.5', '<')) {
if (isset(Tab::$_getIdFromClassName[Tools::strtolower($tabClass)])) {
unset(Tab::$_getIdFromClassName[Tools::strtolower($tabClass)]);
}
if (isset(Tab::$_getIdFromClassName[($tabClass)])) {
unset(Tab::$_getIdFromClassName[($tabClass)]);
}
}
if ($idTab != 0) {
$tab = new Tab($idTab);
$pass = $tab->delete();
}
return ($pass);
}
}