* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6890 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class Envoimoinscher extends Module { private $_html = ''; private $_postErrors = array(); public $_errors = array(); public $packaging = array('Pli' => 'Pli', 'Colis' => 'Colis', 'Encombrant' => 'Objet lourd', 'Palette' => 'Palette'); const INSTALL_SQL_FILE = 'install.sql'; function __construct() { global $cookie; $this->name = 'envoimoinscher'; $this->tab = 'shipping_logistics'; $this->version = '1.0'; $this->limited_countries = array('fr'); $this->needRange = true; parent::__construct (); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Envoimoinscher'); $this->description = $this->l('Find the best price for your shipment. Compare and order carriers offers at negotiated rates.'); if (self::isInstalled($this->name)) { $warning = array(); //Check config and display warning if (!Configuration::get('EMC_WIDTH')) $warning[] .= $this->l('\'Width\'').' '; if (!Configuration::get('EMC_HEIGHT')) $warning[] .= $this->l('\'Height\'').' '; if (!Configuration::get('EMC_DEPTH')) $warning[] .= $this->l('\'Depth\'').' '; if (!Configuration::get('EMC_ORDER_STATE')) $warning[] .= $this->l('\'Order state\'').' '; if (!Configuration::get('EMC_CARRIER')) $warning[] .= $this->l('\'Carrier\'').' '; if (!Configuration::get('EMC_ORDER_PAST_STATE')) $warning[] .= $this->l('\'Order past state\'').' '; if (!Configuration::get('EMC_SEND_STATE')) $warning[] .= $this->l('\'Send order state\'').' '; if (!Configuration::get('EMC_DELIVERY_STATE')) $warning[] .= $this->l('\'Delivered order state\'').' '; if (count($warning)) $this->warning .= implode(' , ',$warning).$this->l('must be configured to use this module correctly').' '; } } /** * @see ModuleCore::install() */ public function install() { global $cookie; if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) return false; elseif (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) return false; $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql); $sql = preg_split("/;\s*[\r\n]+/", $sql); foreach ($sql AS $query) if ($query AND sizeof($query) AND !Db::getInstance()->Execute(trim($query))) return false; if (substr(_PS_VERSION_, 2, 3) <= 3.1) { if (!@copy(dirname(__FILE__).'/AdminEnvoiMoinsCher.gif', _PS_IMG_DIR_.'/t/AdminEnvoiMoinsCher.gif')) $this->_errors[] = $this->l('Please manually copy ') .dirname(__FILE__).'/AdminEnvoiMoinsCher.gif'.' in the '._PS_IMG_DIR_.'/t/AdminEnvoiMoinsCher.gif folder located in your admin directory.'; } if (!parent::install() OR !Configuration::updateValue('EMC_EMAILS', 1) OR !$this->registerHook('AdminOrder') OR !self::adminInstall() OR !Db::getInstance()->Execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'envoimoinscher` (`id_order` int(10) unsigned NOT NULL, `shipping_number` varchar(30) NOT NULL ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=latin1;')) return false; return true; } /** * Add new tab in administration */ private function adminInstall() { $tab = new Tab(); $tab->class_name = 'AdminEnvoiMoinsCher'; $tab->id_parent = 3; $tab->module = 'envoimoinscher'; $tab->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = $this->l('Envoimoinscher'); return $tab->add(); } /** * @see ModuleCore::uninstall() */ public function uninstall() { global $cookie; Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'envoimoinscher_contenu`'); $tab = new Tab(Tab::getIdFromClassName('AdminEnvoiMoinsCher')); if (!parent::uninstall() OR !$tab->delete() OR !$this->unregisterHook('AdminOrder')) return false; return true; } public function getContent() { $this->_html .= '

' . $this->l('Envoimoinscher').'

'; if (!empty($_POST) AND Tools::isSubmit('submitSave')) { $this->_postValidation(); if (!sizeof($this->_postErrors)) $this->_postProcess(); else { $nbErrors = sizeof($this->_postErrors); $this->_html .= '

'.($nbErrors > 1 ? $this->l('There are') : $this->l('There is')).' '.$nbErrors.' '.($nbErrors > 1 ? $this->l('errors') : $this->l('error')).'

    '; foreach ($this->_postErrors AS $err) $this->_html .= '
  1. - '.$err.'
  2. '; $this->_html .= '
'; } } $this->_displayForm(); return $this->_html; } private function _displayForm() { global $cookie; $genderTab = array(1 => 'M.', 2 => 'Mme', 9 => '', 0 => ''); $features = Feature::getFeatures($cookie->id_lang); $order_states = OrderState::getOrderStates($cookie->id_lang); $carriers = Carrier::getCarriers($cookie->id_lang); $countries = Country::getCountries($cookie->id_lang); $confs = Configuration::getMultiple(array('PS_SHOP_NAME', 'EMC_LOGIN', 'EMC_GENDER', 'EMC_LAST_NAME', 'EMC_FIRST_NAME', 'EMC_ADDRESS', 'EMC_ZIP_CODE', 'EMC_CITY', 'EMC_COUNTRY', 'EMC_PHONE', 'EMC_EMAIL')); $link = ''; $this->_html .= '
'.$link.'

'.$this->l('Create Envoimoinscher account:').'

'.$this->l('To create your account on Envoimoinscher, click the image below. You will go to a dedicated personal space where you will find the necessary tools for easy management of your shipments.').'

'.$this->l('Description').'

'.$this->l('This module allows you to compare carrier offers and online ordering services\' negotiated delivery rates.').'

'.$this->l('Please enter your Envoimoinscher username below. If you are not a customer Envoimoinscher, you can easily create an account by clicking').$link.' '.$this->l('here').'.


'.$this->l('Download Documentation').'

 
'.$this->l('Settings').'
*

' . $this->l('Choose width in the list') . '

 
*

' . $this->l('Choose Height in the list') . '

 
*

' . $this->l('Choose Depth in the list') . '

 

'. $this->l('Choose the default packaging.').'

 
'. self::selectNature(Tools::getValue('type_objet', Configuration::get('EMC_CONTENT'))). '

'. $this->l('Choose the default nature of content.').'

 
*

'. $this->l('Choose the order state to export to Envoi Moins Cher.').'

 
*

' . $this->l('Choose a carrier in the list') . '

 
*

'. $this->l('Choose the order state past.').'

 
*

'. $this->l('Choose the order state send.').'

 
'; //objet livré (pas géré actuellement) $this->_html .= '
*

'. $this->l('Choose the order state delivered.').'

 
'; $this->_html .= '

'.$this->l('Enables or disables sending mail from EMC');//.', '.$this->l('unless it informs the recipient that it is sent by default.').'

$this->_html .= '
 
*

' . $this->l('Set your EMC login') . '

 

----------------------------------------------------------------------------------------

'.$this->l('Sender Information').' :

M. Mme

' . $this->l('Select gender of sender') . '

 
*

' . $this->l('Set the Last Name of sender') . '

 
*

' . $this->l('Set the First name of sender') . '

 
*

' . $this->l('Set the Address of sender') . '

 
*

' . $this->l('Set the zip code of sender') . '

 
*

' . $this->l('Set the city of sender') . '

 
*

' . $this->l('Select the country of sender in the list') . '

 
*

' . $this->l('Set the Phone of sender').'

 
*

' . $this->l('Set the e-mail of sender').'

 
 
'; } private function _postValidation() { if (Tools::getValue('EMC_WIDTH') == 0) $this->_postErrors[] = $this->l('Width not specified'); if (Tools::getValue('EMC_HEIGHT') == 0) $this->_postErrors[] = $this->l('Height not specified'); if (Tools::getValue('EMC_DEPTH') == 0) $this->_postErrors[] = $this->l('Depth not specified'); if (Tools::getValue('EMC_ORDER_STATE') == 0) $this->_postErrors[] = $this->l('Order state not specified'); if (Tools::getValue('EMC_CARRIER') == 0) $this->_postErrors[] = $this->l('Carrier not specified'); if (Tools::getValue('EMC_ORDER_PAST_STATE') == 0) $this->_postErrors[] = $this->l('Order state "order past" not specified'); if (Tools::getValue('EMC_SEND_STATE') == 0) $this->_postErrors[] = $this->l('Order state send not specified'); if (Tools::getValue('EMC_DELIVERY_STATE') == 0) $this->_postErrors[] = $this->l('Order state delivery not specified'); if (Tools::getValue('EMC_LAST_NAME') == '') $this->_postErrors[] = $this->l('Last name not specified'); if (Tools::getValue('EMC_FIRST_NAME') == '') $this->_postErrors[] = $this->l('First name not specified'); if (Tools::getValue('EMC_ADDRESS') == '') $this->_postErrors[] = $this->l('Address not specified'); if (Tools::getValue('EMC_ZIP_CODE') == '') $this->_postErrors[] = $this->l('Zip Code not specified'); if (Tools::getValue('EMC_CITY') == '') $this->_postErrors[] = $this->l('City not specified'); if (Tools::getValue('EMC_COUNTRY') == '') $this->_postErrors[] = $this->l('Country not specified'); if (Tools::getValue('EMC_PHONE') == '') $this->_postErrors[] = $this->l('Phone not specified'); if (Tools::getValue('EMC_EMAIL') == '') $this->_postErrors[] = $this->l('E-mail not specified'); if (Tools::getValue('EMC_LOGIN') == '') $this->_postErrors[] = $this->l('Login not specified'); } private function _postProcess() { if (Configuration::updateValue('EMC_WIDTH', (int)(Tools::getValue('EMC_WIDTH'))) AND Configuration::updateValue('EMC_HEIGHT', (int)(Tools::getValue('EMC_HEIGHT'))) AND Configuration::updateValue('EMC_DEPTH', (int)(Tools::getValue('EMC_DEPTH'))) AND Configuration::updateValue('EMC_ORDER_STATE', (int)(Tools::getValue('EMC_ORDER_STATE'))) AND Configuration::updateValue('EMC_CARRIER', (int)(Tools::getValue('EMC_CARRIER'))) AND Configuration::updateValue('EMC_PACKAGING_DEFAULT', Tools::getValue('EMC_PACKAGING_DEFAULT')) AND Configuration::updateValue('EMC_GENDER', Tools::getValue('EMC_GENDER')) AND Configuration::updateValue('EMC_LAST_NAME', Tools::getValue('EMC_LAST_NAME')) AND Configuration::updateValue('EMC_FIRST_NAME', Tools::getValue('EMC_FIRST_NAME')) AND Configuration::updateValue('EMC_ADDRESS', Tools::getValue('EMC_ADDRESS')) AND Configuration::updateValue('EMC_ZIP_CODE', Tools::getValue('EMC_ZIP_CODE')) AND Configuration::updateValue('EMC_CITY', Tools::getValue('EMC_CITY')) AND Configuration::updateValue('EMC_COUNTRY', Tools::getValue('EMC_COUNTRY')) AND Configuration::updateValue('EMC_PHONE', Tools::getValue('EMC_PHONE')) AND Configuration::updateValue('EMC_EMAIL', Tools::getValue('EMC_EMAIL')) AND Configuration::updateValue('EMC_ORDER_PAST_STATE', Tools::getValue('EMC_ORDER_PAST_STATE')) AND Configuration::updateValue('EMC_SEND_STATE', Tools::getValue('EMC_SEND_STATE')) AND Configuration::updateValue('EMC_EMAILS', Tools::getValue('EMC_EMAILS')) AND Configuration::updateValue('EMC_LOGIN', Tools::getValue('EMC_LOGIN')) AND Configuration::updateValue('EMC_CONTENT', Tools::getValue('type_objet_')) AND Configuration::updateValue('EMC_DELIVERY_STATE', Tools::getValue('EMC_DELIVERY_STATE'))) { $dataSync = (($emc_login = Configuration::get('EMC_LOGIN')) ? '' : ''); $this->_html .= $this->displayConfirmation($this->l('Configuration updated').$dataSync); } else $this->_html .= '
nok '.$this->l('Settings failed').'
'; } static function selectNature($selected = '', $id = '') { $select = ''; return $select; } public function hookAdminOrder($params) { $order = new Order($params['id_order']); if ($order->id_carrier == Configuration::get('EMC_CARRIER')) { $return = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'envoimoinscher WHERE id_order = \''.(int)($order->id).'\' LIMIT 1'); if (isset($return[0]['shipping_number'])) { $html = '

'.$this->l('Envoimoinscher').''; $html .= ''.$this->l('Delivery Information').' :
'.(isset($return[0]['shipping_number']) ? '

--> '.$this->l('Follow shipping').'' : '

'.$this->l('No shipping number')).'

' .(isset($return[0]['shipping_number']) ?'

--> '.$this->l('Print delivery slips').'' : '

'.$this->l('No delivery slips number')).'

'; return $html; } } } public function lang($str) { switch($str) { case 'No order to export': return $this->l('No order to export'); break; case 'Please configure this module in order': return $this->l('Please configure this module in order'); break; case 'Change configuration': return $this->l('Change configuration'); break; case 'ID': return $this->l('ID'); break; case 'Name': return $this->l('Name'); break; case 'Total Cost': return $this->l('Total Cost'); break; case 'Total shipment': return $this->l('Total shipment'); break; case 'Date': return $this->l('Date'); break; case 'Packaging': return $this->l('Packaging'); break; case 'Nature of contents': return $this->l('Nature of contents'); break; case 'Detail': return $this->l('Detail'); break; case 'View': return $this->l('View'); break; case 'Send': return $this->l('Send'); break; case 'List of orders to export': return $this->l('List of orders to export'); break; } } }