164 lines
6.9 KiB
PHP
164 lines
6.9 KiB
PHP
|
<?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 So Colissimo Flexibilite
|
||
|
* @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.soflexibilite@common-services.com
|
||
|
*/
|
||
|
|
||
|
class SoFlexibiliteTools
|
||
|
{
|
||
|
|
||
|
public static function file_get_contents($url, $use_include_path = false, $stream_context = null, $curl_timeout = 30)
|
||
|
{
|
||
|
if ($stream_context == null && preg_match('/^https?:\/\//', $url)) {
|
||
|
if (preg_match('/^https:\/\//', $url)) {
|
||
|
$contextOptions = array(
|
||
|
'ssl' => array(
|
||
|
'verify_peer' => true,
|
||
|
'cafile' => sprintf('%s/%s', dirname(dirname(__FILE__)), 'cert/cacert.pem'),
|
||
|
)
|
||
|
);
|
||
|
} else {
|
||
|
$contextOptions = array();
|
||
|
}
|
||
|
|
||
|
$stream_context = @stream_context_create(array('http' => array('timeout' => $curl_timeout)), $contextOptions);
|
||
|
}
|
||
|
if (in_array(ini_get('allow_url_fopen'), array('On', 'on', '1')) || !preg_match('/^https?:\/\//', $url)) {
|
||
|
//TODO Validation: http://forge.prestashop.com/browse/PSCSX-7758
|
||
|
return file_get_contents($url, $use_include_path, $stream_context);
|
||
|
} elseif (function_exists('curl_init')) {
|
||
|
$curl = curl_init();
|
||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||
|
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
|
||
|
curl_setopt($curl, CURLOPT_TIMEOUT, $curl_timeout);
|
||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 2);
|
||
|
curl_setopt($curl, CURLOPT_CAINFO, sprintf('%s/%s', dirname(dirname(__FILE__)), 'cert/cacert.pem'));
|
||
|
if ($stream_context != null) {
|
||
|
$opts = stream_context_get_options($stream_context);
|
||
|
if (isset($opts['http']['method']) && Tools::strtolower($opts['http']['method']) == 'post') {
|
||
|
curl_setopt($curl, CURLOPT_POST, true);
|
||
|
if (isset($opts['http']['content'])) {
|
||
|
parse_str($opts['http']['content'], $post_data);
|
||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$content = curl_exec($curl);
|
||
|
curl_close($curl);
|
||
|
return $content;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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 copy($source, $destination, $stream_context = null)
|
||
|
{
|
||
|
if (is_null($stream_context) && !preg_match('/^https?:\/\//', $source)) {
|
||
|
return @copy($source, $destination);
|
||
|
}
|
||
|
return @file_put_contents($destination, Tools::file_get_contents($source, false, $stream_context));
|
||
|
}
|
||
|
|
||
|
|
||
|
public static function carrierIsEnabled($id_carrier)
|
||
|
{
|
||
|
return ((bool)Db::getInstance()->getValue('SELECT `active` FROM `'._DB_PREFIX_.'carrier` WHERE `id_carrier` = '.(int)$id_carrier));
|
||
|
}
|
||
|
|
||
|
public static function checkTables($compat_type = 1, $tables = array())
|
||
|
{
|
||
|
if ($compat_type == 1 && !isset($tables[_DB_PREFIX_.'socolissimo_delivery_info'])) {
|
||
|
$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'socolissimo_delivery_info` (
|
||
|
`id_cart` INT(10) NOT NULL,
|
||
|
`id_customer` INT(10) NOT NULL,
|
||
|
`delivery_mode` VARCHAR(3) NOT NULL,
|
||
|
`prid` TEXT(10) NOT NULL,
|
||
|
`prname` VARCHAR(64) NOT NULL,
|
||
|
`prfirstname` VARCHAR(64) NOT NULL,
|
||
|
`prcompladress` TEXT NOT NULL,
|
||
|
`pradress1` TEXT NOT NULL,
|
||
|
`pradress2` TEXT NOT NULL,
|
||
|
`pradress3` TEXT NOT NULL,
|
||
|
`pradress4` TEXT NOT NULL,
|
||
|
`przipcode` TEXT(10) NOT NULL,
|
||
|
`prtown` VARCHAR(64) NOT NULL,
|
||
|
`cecountry` VARCHAR(10) NOT NULL,
|
||
|
`cephonenumber` VARCHAR(15) NOT NULL,
|
||
|
`ceemail` VARCHAR(64) NOT NULL,
|
||
|
`cecompanyname` VARCHAR(64) NOT NULL,
|
||
|
`cedeliveryinformation` TEXT NOT NULL,
|
||
|
`cedoorcode1` VARCHAR(10) NOT NULL,
|
||
|
`cedoorcode2` VARCHAR(10) NOT NULL,
|
||
|
PRIMARY KEY (`id_cart`,`id_customer`)
|
||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
|
||
|
|
||
|
if (!Db::getInstance()->Execute($sql)) {
|
||
|
ConfigureMessage::error('Error while creating table socolissimo_delivery_info');
|
||
|
}
|
||
|
} elseif ($compat_type == 2 && !isset($tables[_DB_PREFIX_.'so_delivery'])) {
|
||
|
$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'so_delivery` (
|
||
|
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||
|
`order_id` INT(11) DEFAULT NULL,
|
||
|
`cart_id` INT(11) DEFAULT NULL,
|
||
|
`point_id` INT(11) NOT NULL,
|
||
|
`customer_id` INT(11) NOT NULL,
|
||
|
`firstname` VARCHAR(38) DEFAULT NULL,
|
||
|
`lastname` VARCHAR(38) DEFAULT NULL,
|
||
|
`company` VARCHAR(38) DEFAULT NULL,
|
||
|
`telephone` VARCHAR(10) DEFAULT NULL,
|
||
|
`email` VARCHAR(64) DEFAULT NULL,
|
||
|
`type` VARCHAR(3) DEFAULT NULL,
|
||
|
`libelle` VARCHAR(50) DEFAULT NULL,
|
||
|
`indice` VARCHAR(70) DEFAULT NULL,
|
||
|
`code_postal` VARCHAR(5) DEFAULT NULL,
|
||
|
`commune` VARCHAR(32) DEFAULT NULL,
|
||
|
`pays` VARCHAR(32) NOT NULL,
|
||
|
`adresse1` VARCHAR(38) DEFAULT NULL,
|
||
|
`adresse2` VARCHAR(38) DEFAULT NULL,
|
||
|
`lieudit` VARCHAR(38) DEFAULT NULL,
|
||
|
`informations` TEXT,
|
||
|
PRIMARY KEY (`id`),
|
||
|
UNIQUE KEY `u_order_id` (`order_id`),
|
||
|
UNIQUE KEY `u_cart_id` (`cart_id`)
|
||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10000000;';
|
||
|
|
||
|
if (!Db::getInstance()->Execute($sql)) {
|
||
|
ConfigureMessage::error('Error while creating table so_delivery');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|