<?php
/*
 *
 * Copyright (c) ATRAGENE SARL
 * @website: www.atragene.com
 * @email: contact@atragene.com
 * @author: olivier.lemaitre@atragene.com
 * @company: Atragene Conseil
 * @version: 1.7.4
 * @date: 03/12/2015
 *
 */

class ControllerShippingEnvoismoinscher extends Controller { 
	
        private $error = array();
		private $nb_dim = 5; //nombre de lignes du tableau dimensions
		private $nb_range = 3; //nombre de lignes du tableau forfaits
		private $version_platform = VERSION;
		private $platform = 'opencart';
		private $version_lib = '1.1.4';
		
        public function index() {  

                /* Initialisation EMC */ 
                require_once(DIR_SYSTEM.'library/emc/WebService.php');
                require_once(DIR_SYSTEM.'library/emc/Carrier.php');
                require_once(DIR_SYSTEM.'library/emc/CarriersList.php');
                require_once(DIR_SYSTEM.'library/emc/ContentCategory.php');
                require_once(DIR_SYSTEM.'library/emc/Country.php');
                require_once(DIR_SYSTEM.'library/emc/ListPoints.php');
                require_once(DIR_SYSTEM.'library/emc/OrderStatus.php');
                require_once(DIR_SYSTEM.'library/emc/ParcelPoint.php');
                require_once(DIR_SYSTEM.'library/emc/Quotation.php');
                require_once(DIR_SYSTEM.'library/emc/Service.php');
                require_once(DIR_SYSTEM.'library/emc/User.php');
                
                $userData = array(
                        "login" => $this->config->get('envoismoinscher_login'),
                        "password" => $this->config->get('envoismoinscher_pwd'),
                        "api_key" => $this->config->get('envoismoinscher_key')
                );

                $from = array(
					"pays" => str_replace("FX", "FR", $this->config->get('envoismoinscher_iso')),
					"code_postal" => $this->config->get('envoismoinscher_cp'),
					"type" => "entreprise",
					"societe" => $this->config->get('envoismoinscher_brand'),
					"ville" => $this->config->get('envoismoinscher_town'),
					"adresse" => $this->config->get('envoismoinscher_adress'), 
					"civilite" => $this->config->get('envoismoinscher_civility'),
					"prenom" => $this->config->get('envoismoinscher_firstName'),
					"nom" => $this->config->get('envoismoinscher_lastName'),
					"email" => $this->config->get('envoismoinscher_mail'),
					"tel" => $this->config->get('envoismoinscher_phone'),
					"infos" => $this->config->get('envoismoinscher_adressComplement')
				);
		
                /* Initialisation Opencart */ 
                $this->load->language('shipping/envoismoinscher');
		$this->document->setTitle($this->language->get('heading_title'));
		$this->load->model('setting/setting');
				 
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
                    $this->model_setting_setting->editSetting('envoismoinscher', $this->request->post);	
                    $this->session->data['success'] = $this->language->get('text_success');					
                    $this->redirect($this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL'));
		}
		
		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_enabled'] = $this->language->get('text_enabled');
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_all_zones'] = $this->language->get('text_all_zones');
		$this->data['text_none'] = $this->language->get('text_none');

// ------------------------
// Captions
// ------------------------
		$this->data['entry_caption_id'] = $this->language->get('entry_caption_id');
		$this->data['entry_caption_address'] = $this->language->get('entry_caption_address');
		$this->data['entry_caption_envois'] = $this->language->get('entry_caption_envois');
		$this->data['entry_caption_transport'] = $this->language->get('entry_caption_transport');
		$this->data['entry_caption_dimension'] = $this->language->get('entry_caption_dimension');
		$this->data['entry_caption_tabassurance'] = $this->language->get('entry_caption_tabassurance');
		$this->data['entry_caption_frais'] = $this->language->get('entry_caption_frais');
		$this->data['entry_caption_order'] = $this->language->get('entry_caption_order');
		$this->data['entry_caption_order_sent'] = $this->language->get('entry_caption_order_sent');
		$this->data['entry_OffresEconomiques'] = $this->language->get('entry_OffresEconomiques');
		$this->data['entry_OffresEconomiques_help'] = $this->language->get('entry_OffresEconomiques_help');
		$this->data['entry_Expressistes'] = $this->language->get('entry_Expressistes');
		$this->data['entry_Expressistes_help'] = $this->language->get('entry_Expressistes_help');

// ------------------------
// Identifiants et paramètres
// ------------------------
		
		$this->data['entry_link_help'] = $this->language->get('entry_link_help');
		$this->data['entry_link_key'] = $this->language->get('entry_link_key');
		$this->data['entry_login'] = $this->language->get('entry_login');
		$this->data['entry_pwd'] = $this->language->get('entry_pwd');
		$this->data['entry_key'] = $this->language->get('entry_key');
		$this->data['entry_environment'] = $this->language->get('entry_environment');
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');

// ------------------------
// Entrées Adresse d'enlèvement
// ------------------------
		$this->data['entry_civility'] = $this->language->get('entry_civility');
		$this->data['entry_firstName'] = $this->language->get('entry_firstName');
		$this->data['entry_lastName'] = $this->language->get('entry_lastName');
		$this->data['entry_brand'] = $this->language->get('entry_brand');
		$this->data['entry_adress'] = $this->language->get('entry_adress');
		$this->data['entry_cp'] = $this->language->get('entry_cp');
		$this->data['entry_town'] = $this->language->get('entry_town');
		$this->data['entry_iso'] = $this->language->get('entry_iso');
		$this->data['entry_phone'] = $this->language->get('entry_phone');
		$this->data['entry_mail'] = $this->language->get('entry_mail');
		$this->data['entry_adressComplement'] = $this->language->get('entry_adressComplement');
		$this->data['entry_dispoDeb'] = $this->language->get('entry_dispoDeb');
		$this->data['entry_dispoEnd'] = $this->language->get('entry_dispoEnd');

// ------------------------
// Vos Envois
// ------------------------
		$this->data['entry_type_send'] = $this->language->get('entry_type_send');
		$this->data['entry_min_weight'] = $this->language->get('entry_min_weight');
		$this->data['entry_max_weight'] = $this->language->get('entry_max_weight');
		$this->data['entry_default_weight'] = $this->language->get('entry_default_weight');
                    $this->data['entry_default_weight_help'] = $this->language->get('entry_default_weight_help');
		$this->data['entry_nature_send'] = $this->language->get('entry_nature_send');
                    $this->data['entry_nature_send_help'] = $this->language->get('entry_nature_send_help');
		$this->data['entry_use_description'] = $this->language->get('entry_use_description');
		$this->data['entry_embal_send'] = $this->language->get('entry_embal_send');
		$this->data['entry_date_recup'] = $this->language->get('entry_date_recup');
                    $this->data['entry_date_recup_help'] = $this->language->get('entry_date_recup_help');
		$this->data['entry_date_recup2'] = $this->language->get('entry_date_recup2');
                    $this->data['entry_date_recup2_help'] = $this->language->get('entry_date_recup2_help');
		$this->data['entry_cmd_passed'] = $this->language->get('entry_cmd_passed');
		$this->data['entry_day_plus'] = $this->language->get('entry_day_plus');
		$this->data['entry_and'] = $this->language->get('entry_and');
		$this->data['entry_mode_send'] = $this->language->get('entry_mode_send');
                    $this->data['entry_mode_send_help'] = $this->language->get('entry_mode_send_help');
		$this->data['entry_pass_cmd'] = $this->language->get('entry_pass_cmd');
		$this->data['entry_send_cmd'] = $this->language->get('entry_send_cmd');
		$this->data['entry_arrive_cmd'] = $this->language->get('entry_arrive_cmd');
		$this->data['entry_suppr_cmd'] = $this->language->get('entry_suppr_cmd');
		$this->data['entry_client_particulier'] = $this->language->get('entry_client_particulier');
                    $this->data['entry_client_particulier_help'] = $this->language->get('entry_client_particulier_help');
		$this->data['entry_multicolis'] = $this->language->get('entry_multicolis');
                    $this->data['entry_multicolis_help'] = $this->language->get('entry_multicolis_help');
		$this->data['entry_assurance'] = $this->language->get('entry_assurance');
                    $this->data['entry_assurance_help'] = $this->language->get('entry_assurance_help');
		$this->data['entry_price'] = $this->language->get('entry_price');
		$this->data['entry_mail_setting'] = $this->language->get('entry_mail_setting');
			
						$this->data['entry_mail_slip'] = $this->language->get('entry_mail_slip');
						$this->data['entry_mail_notification'] = $this->language->get('entry_mail_notification');
						$this->data['entry_mail_bill'] = $this->language->get('entry_mail_bill');
						
			/* Help Tooltip - Label Infobulle Vos Envois */
			$this->data['help_type_send'] = $this->language->get('help_type_send');
			$this->data['help_default_weight'] = $this->language->get('help_default_weight');
			$this->data['help_nature_send'] = $this->language->get('help_nature_send');
			$this->data['help_date_recup'] = $this->language->get('help_date_recup');
			$this->data['help_date_recup2'] = $this->language->get('help_date_recup2');
			$this->data['help_mode_send'] = $this->language->get('help_mode_send');
			$this->data['help_client_particulier'] = $this->language->get('help_client_particulier');
			$this->data['help_multicolis'] = $this->language->get('help_multicolis');
			$this->data['help_assurance'] = $this->language->get('help_assurance');
			
			/* Liste déroulante */
			//emballage
			$this->data['entry_packing'] = $this->language->get('entry_packing');
			$this->data['entry_packing_box'] = $this->language->get('entry_packing_box');
			$this->data['entry_packing_case'] = $this->language->get('entry_packing_case');
			$this->data['entry_packing_vat'] = $this->language->get('entry_packing_vat');
			$this->data['entry_packing_isothermal_packaging'] = $this->language->get('entry_packing_isothermal_packaging');
			$this->data['entry_packing_cover'] = $this->language->get('entry_packing_cover');
			$this->data['entry_packing_trunk'] = $this->language->get('entry_packing_trunk');
			$this->data['entry_packing_bag'] = $this->language->get('entry_packing_bag');
			$this->data['entry_packing_tube'] = $this->language->get('entry_packing_tube');
			//fermeture
			$this->data['entry_locking'] = $this->language->get('entry_locking');
			$this->data['entry_locking_adhesive'] = $this->language->get('entry_locking_adhesive');
			$this->data['entry_locking_tape'] = $this->language->get('entry_locking_tape');
			$this->data['entry_locking_staples'] = $this->language->get('entry_locking_staples');
			$this->data['entry_locking_nails'] = $this->language->get('entry_locking_nails');
			$this->data['entry_locking_gluing'] = $this->language->get('entry_locking_gluing');
			$this->data['entry_locking_strapping_tape'] = $this->language->get('entry_locking_strapping_tape');
			$this->data['entry_locking_strap'] = $this->language->get('entry_locking_strap');
			$this->data['entry_locking_staples_and_strapping'] = $this->language->get('entry_locking_staples_and_strapping');
			$this->data['entry_locking_nails_and_strapping'] = $this->language->get('entry_locking_nails_and_strapping');
			//fixation
			$this->data['entry_attachment'] = $this->language->get('entry_attachment');
			$this->data['entry_attachment_without'] = $this->language->get('entry_attachment_without');
			$this->data['entry_attachment_transparent'] = $this->language->get('entry_attachment_transparent');
			$this->data['entry_attachment_opaque'] = $this->language->get('entry_attachment_opaque');
			$this->data['entry_attachment_opaque_and_webbing'] = $this->language->get('entry_attachment_opaque_and_webbing');
			$this->data['entry_attachment_transparent_and_webbing'] = $this->language->get('entry_attachment_transparent_and_webbing');
			$this->data['entry_attachment_strapping'] = $this->language->get('entry_attachment_strapping');
			//materiaux
			$this->data['entry_material'] = $this->language->get('entry_material');
			$this->data['entry_material_cardboard'] = $this->language->get('entry_material_cardboard');
			$this->data['entry_material_wood'] = $this->language->get('entry_material_wood');
			$this->data['entry_material_opaque'] = $this->language->get('entry_material_opaque');
			$this->data['entry_material_transparent'] = $this->language->get('entry_material_transparent');
			$this->data['entry_material_metal'] = $this->language->get('entry_material_metal');
			$this->data['entry_material_paper'] = $this->language->get('entry_material_paper');
			$this->data['entry_material_reinforced_paper'] = $this->language->get('entry_material_reinforced_paper');
			$this->data['entry_material_plastic_and_cardboard'] = $this->language->get('entry_material_plastic_and_cardboard');
			$this->data['entry_material_plastic'] = $this->language->get('entry_material_plastic');
			$this->data['entry_material_opaque_plastic'] = $this->language->get('entry_material_opaque_plastic');
			$this->data['entry_material_transparent_plastic'] = $this->language->get('entry_material_transparent_plastic');
			$this->data['entry_material_polystyrene'] = $this->language->get('entry_material_polystyrene');
			//protections
			$this->data['entry_protection'] = $this->language->get('entry_protection');
			$this->data['entry_protection_without'] = $this->language->get('entry_protection_without');
			$this->data['entry_protection_paper'] = $this->language->get('entry_protection_paper');
			$this->data['entry_protection_plastic'] = $this->language->get('entry_protection_plastic');
			$this->data['entry_protection_cardboard'] = $this->language->get('entry_protection_cardboard');
			$this->data['entry_protection_air'] = $this->language->get('entry_protection_air');
			$this->data['entry_protection_foam'] = $this->language->get('entry_protection_foam');
			$this->data['entry_protection_bottle_cardboard'] = $this->language->get('entry_protection_bottle_cardboard');
			$this->data['entry_protection_bottle_foam'] = $this->language->get('entry_protection_bottle_foam');
			$this->data['entry_protection_padding'] = $this->language->get('entry_protection_padding');
			$this->data['entry_protection_foam_plate'] = $this->language->get('entry_protection_foam_plate');
			$this->data['entry_protection_polystyrene'] = $this->language->get('entry_protection_polystyrene');
			$this->data['entry_protection_wedge_cushion'] = $this->language->get('entry_protection_wedge_cushion');
			$this->data['entry_protection_bubbles'] = $this->language->get('entry_protection_bubbles');
			
// ------------------------
// Vos Transporteurs
// ------------------------
		$this->data['entry_ChronoInternationalClassic'] = $this->language->get('entry_ChronoInternationalClassic');
		$this->data['entry_ChronoRelais'] = $this->language->get('entry_ChronoRelais');
		$this->data['entry_Chrono13'] = $this->language->get('entry_Chrono13');
		$this->data['entry_Chrono18'] = $this->language->get('entry_Chrono18');
		$this->data['entry_EASY'] = $this->language->get('entry_EASY');
		$this->data['entry_ColissimoAccess'] = $this->language->get('entry_ColissimoAccess');
		$this->data['entry_ColissimoExpert'] = $this->language->get('entry_ColissimoExpert');
		$this->data['entry_CpourToi'] = $this->language->get('entry_CpourToi');
		$this->data['entry_CpourToiEurope'] = $this->language->get('entry_CpourToiEurope');
		$this->data['entry_RelaisColis'] = $this->language->get('entry_RelaisColis');

		$this->data['entry_ExpressWorldwide'] = $this->language->get('entry_ExpressWorldwide');
		$this->data['entry_InternationalEconomy'] = $this->language->get('entry_InternationalEconomy');
		$this->data['entry_InternationalPriority'] = $this->language->get('entry_InternationalPriority');
		$this->data['entry_ExpressStandard'] = $this->language->get('entry_ExpressStandard');
		$this->data['entry_ExpressStandardInterColisMarch'] = $this->language->get('entry_ExpressStandardInterColisMarch');
		$this->data['entry_ExpressStandardInterPlisDSVC'] = $this->language->get('entry_ExpressStandardInterPlisDSVC');
		$this->data['entry_ExpressNational'] = $this->language->get('entry_ExpressNational');
		$this->data['entry_EconomyExpressInternational'] = $this->language->get('entry_EconomyExpressInternational');
		$this->data['entry_ExpressInternationalColis'] = $this->language->get('entry_ExpressInternationalColis');
		$this->data['entry_ExpressSaver'] = $this->language->get('entry_ExpressSaver');
		$this->data['entry_Standard'] = $this->language->get('entry_Standard');
                
		$this->data['entry_ShippingStatus'] = $this->language->get('entry_ShippingStatus');
		$this->data['entry_ShippingPrice'] = $this->language->get('entry_ShippingPrice');
		$this->data['entry_ShippingUrl'] = $this->language->get('entry_ShippingUrl');
                    $this->data['entry_ShippingUrl_help'] = $this->language->get('entry_ShippingUrl_help');
		$this->data['entry_DroppOffPoint'] = $this->language->get('entry_DroppOffPoint');
		$this->data['entry_SelectDroppOffPoint'] = $this->language->get('entry_SelectDroppOffPoint');
                $this->data['entry_PostOffice'] = $this->language->get('entry_PostOffice');
		$this->data['entry_Home'] = $this->language->get('entry_Home');
		$this->data['entry_ShippingDescription'] = $this->language->get('entry_ShippingDescription');

		$this->data['text_yes'] = $this->language->get('text_yes');
		$this->data['text_no'] = $this->language->get('text_no');
		
		$this->data['entry_manutention'] = $this->language->get('entry_manutention');
		
// ------------------------
// Dimensions
// ------------------------
		$this->data['entry_dimensions'] = $this->language->get('entry_dimensions');
		$this->data['entry_dimensions_desc'] = $this->language->get('entry_dimensions_desc');
		$this->data['entry_dim_width'] = $this->language->get('entry_dim_width');
		$this->data['entry_dim_height'] = $this->language->get('entry_dim_height');
		$this->data['entry_dim_lenght'] = $this->language->get('entry_dim_lenght');
		$this->data['entry_dim_weight'] = $this->language->get('entry_dim_weight');
		
// ------------------------
// Assurance
// ------------------------
		$this->data['entry_tabassurance'] = $this->language->get('entry_tabassurance');
		$this->data['entry_tabassurance_desc'] = $this->language->get('entry_tabassurance_desc');

		
// ------------------------
// Frais
// ------------------------
		$this->data['entry_frais'] = $this->language->get('entry_frais');
		$this->data['entry_frais_desc'] = $this->language->get('entry_frais_desc');
		$this->data['entry_range_low'] = $this->language->get('entry_range_low');
		$this->data['entry_range_high'] = $this->language->get('entry_range_high');
		$this->data['entry_range_price'] = $this->language->get('entry_range_price');
		
// ------------------------
// Les Commandes
// ------------------------
		$this->data['entry_idCmd'] = $this->language->get('entry_idCmd');
		$this->data['entry_dateCmd'] = $this->language->get('entry_dateCmd');
		$this->data['entry_nomCliCmd'] = $this->language->get('entry_nomCliCmd');
		$this->data['entry_societeCmd'] = $this->language->get('entry_societeCmd');
		$this->data['entry_transCmd'] = $this->language->get('entry_transCmd');
		$this->data['entry_statusCmd'] = $this->language->get('entry_statusCmd');
		$this->data['entry_lienCmd'] = $this->language->get('entry_lienCmd');
		$this->data['entry_viewCmd'] = $this->language->get('entry_viewCmd');
		$this->data['entry_statuspending'] = $this->language->get('entry_statuspending');
		$this->data['entry_statusshipped'] = $this->language->get('entry_statusshipped');

// Boutons
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');
		$this->data['entry_butt_send'] = $this->language->get('entry_butt_send');
		
	//Message d'attente et erreur
		$this->data['entry_wait_mess'] = $this->language->get('entry_wait_mess');
		$this->data['error_relai_point'] = $this->language->get('error_relai_point');
		$this->data['error_mess_emc1'] = $this->language->get('error_mess_emc1');
		$this->data['error_mess_emc2'] = $this->language->get('error_mess_emc2');
		
// ------------------------
// Affichage des erreurs
// ------------------------
 		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}

		if (isset($this->error['login'])) {
			$this->data['error_login'] = $this->error['login'];
		} else {
			$this->data['error_login'] = '';
		}

		if (isset($this->error['pwd'])) {
			$this->data['error_pwd'] = $this->error['pwd'];
		} else {
			$this->data['error_pwd'] = '';
		}

		if (isset($this->error['key'])) {
			$this->data['error_key'] = $this->error['key'];
		} else {
			$this->data['error_key'] = '';
		}

		if (isset($this->error['environment'])) {
			$this->data['error_environment'] = $this->error['environment'];
		} else {
			$this->data['error_environment'] = '';
		}

		if (isset($this->error['firstName'])) {
			$this->data['error_firstName'] = $this->error['firstName'];
		} else {
			$this->data['error_firstName'] = '';
		}

		if (isset($this->error['lastName'])) {
			$this->data['error_lastName'] = $this->error['lastName'];
		} else {
			$this->data['error_lastName'] = '';
		}

		if (isset($this->error['brand'])) {
			$this->data['error_brand'] = $this->error['brand'];
		} else {
			$this->data['error_brand'] = '';
		}

		if (isset($this->error['civility'])) {
			$this->data['error_civility'] = $this->error['civility'];
		} else {
			$this->data['error_civility'] = '';
		}

		if (isset($this->error['mail'])) {
			$this->data['error_mail'] = $this->error['mail'];
		} else {
			$this->data['error_mail'] = '';
		}

		if (isset($this->error['adress'])) {
			$this->data['error_adress'] = $this->error['adress'];
		} else {
			$this->data['error_adress'] = '';
		}

		if (isset($this->error['cp'])) {
			$this->data['error_cp'] = $this->error['cp'];
		} else {
			$this->data['error_cp'] = '';
		}

		if (isset($this->error['town'])) {
			$this->data['error_town'] = $this->error['town'];
		} else {
			$this->data['error_town'] = '';
		}

		if (isset($this->error['iso'])) {
			$this->data['error_iso'] = $this->error['iso'];
		} else {
			$this->data['error_iso'] = '';
		}

		if (isset($this->error['dispoDeb'])) {
			$this->data['error_dispoDeb'] = $this->error['dispoDeb'];
		} else {
			$this->data['error_dispoDeb'] = '';
		}

		if (isset($this->error['dispoEnd'])) {
			$this->data['error_dispoEnd'] = $this->error['dispoEnd'];
		} else {
			$this->data['error_dispoEnd'] = '';
		}

		if (isset($this->error['phone'])) {
			$this->data['error_phone'] = $this->error['phone'];
		} else {
			$this->data['error_phone'] = '';
		}
                
		if (isset($this->error['typeSend'])) {
			$this->data['error_typeSend'] = $this->error['typeSend'];
		} else {
			$this->data['error_typeSend'] = '';
		}

		if (isset($this->error['minWeight'])) {
			$this->data['error_minWeight'] = $this->error['minWeight'];
		} else {
			$this->data['error_minWeight'] = '';
		}

		if (isset($this->error['maxWeight'])) {
			$this->data['error_maxWeight'] = $this->error['maxWeight'];
		} else {
			$this->data['error_maxWeight'] = '';
		}

		if (isset($this->error['natureSend'])) {
			$this->data['error_natureSend'] = $this->error['natureSend'];
		} else {
			$this->data['error_natureSend'] = '';
		}

                // Erreurs Envoi Moins Cher
                $error_emc = "";

  		$this->data['breadcrumbs'] = array();
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_shipping'),
			'href'      => $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('shipping/envoismoinscher', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
		$this->data['action'] = $this->url->link('shipping/envoismoinscher', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['cancel'] = $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL'); 
		
// ------------------------
// Récuperation identifiant
// ------------------------
                
		if (isset($this->request->post['envoismoinscher_login'])) {
			$this->data['envoismoinscher_login'] = $this->request->post['envoismoinscher_login'];
		} else {
			$this->data['envoismoinscher_login'] = $this->config->get('envoismoinscher_login');
		}

		if (isset($this->request->post['envoismoinscher_pwd'])) {
			$this->data['envoismoinscher_pwd'] = $this->request->post['envoismoinscher_pwd'];
		} else {
			$this->data['envoismoinscher_pwd'] = $this->config->get('envoismoinscher_pwd');
		}

		if (isset($this->request->post['envoismoinscher_key'])) {
			$this->data['envoismoinscher_key'] = $this->request->post['envoismoinscher_key'];
		} else {
			$this->data['envoismoinscher_key'] = $this->config->get('envoismoinscher_key');
		}

                // Environement
		if (isset($this->request->post['envoismoinscher_environment'])) {
			$this->data['envoismoinscher_environment'] = $this->request->post['envoismoinscher_environment'];
		} else {
			$this->data['envoismoinscher_environment'] = $this->config->get('envoismoinscher_environment');
		}
                
                // Environement : menu déroulant
			$this->data['environment_menu'] = array();

			$this->data['environment_menu'][] = array(
				'value' => 'test',
				'text'  => $this->language->get('text_environment_test')
			);

			$this->data['environment_menu'][] = array(
				'value' => 'prod',
				'text'  => $this->language->get('text_environment_prod')
			);

		if (isset($this->request->post['envoismoinscher_status'])) {
			$this->data['envoismoinscher_status'] = $this->request->post['envoismoinscher_status'];
		} else {
			$this->data['envoismoinscher_status'] = $this->config->get('envoismoinscher_status');
		}
                
			$this->data['status_menu'] = array();
			$this->data['status_menu'][] = array(
                        'value' => '0',
                        'text'  => $this->language->get('text_status_dis')
                );
                $this->data['status_menu'][] = array(
				'value' => '1',
				'text'  => $this->language->get('text_status_ena')
			);
		
		if (isset($this->request->post['envoismoinscher_sort_order'])) {
			$this->data['envoismoinscher_sort_order'] = $this->request->post['envoismoinscher_sort_order'];
		} else {
			$this->data['envoismoinscher_sort_order'] = $this->config->get('envoismoinscher_sort_order');
		}
		
// ------------------------
// Adresse d'enlèvement
// ------------------------

	// Menu déroulant civilité
		if (isset($this->request->post['envoismoinscher_civility'])) {
			$this->data['envoismoinscher_civility'] = $this->request->post['envoismoinscher_civility'];
		} else {
			$this->data['envoismoinscher_civility'] = $this->config->get('envoismoinscher_civility');
		}
		//definition du menu déroulant
				$this->data['civility_menu'] = array();

				$this->data['civility_menu'][] = array(
					'value' => 'M',
					'text'  => $this->language->get('text_civility_m')
				);

				$this->data['civility_menu'][] = array(
					'value' => 'Mme',
					'text'  => $this->language->get('text_civility_mme')
				);

				$this->data['civility_menu'][] = array(
					'value' => 'Mlle',
					'text'  => $this->language->get('text_civility_mlle')
				);

		if (isset($this->request->post['envoismoinscher_firstName'])) {
			$this->data['envoismoinscher_firstName'] = $this->request->post['envoismoinscher_firstName'];
		} else {
			$this->data['envoismoinscher_firstName'] = $this->config->get('envoismoinscher_firstName');
		}

		if (isset($this->request->post['envoismoinscher_lastName'])) {
			$this->data['envoismoinscher_lastName'] = $this->request->post['envoismoinscher_lastName'];
		} else {
			$this->data['envoismoinscher_lastName'] = $this->config->get('envoismoinscher_lastName');
		}

		if (isset($this->request->post['envoismoinscher_brand'])) {
			$this->data['envoismoinscher_brand'] = $this->request->post['envoismoinscher_brand'];
		} else {
			$this->data['envoismoinscher_brand'] = $this->config->get('envoismoinscher_brand');
		}

		if (isset($this->request->post['envoismoinscher_adress'])) {
			$this->data['envoismoinscher_adress'] = $this->request->post['envoismoinscher_adress'];
		} else {
			$this->data['envoismoinscher_adress'] = $this->config->get('envoismoinscher_adress');
		}

		if (isset($this->request->post['envoismoinscher_cp'])) {
			$this->data['envoismoinscher_cp'] = $this->request->post['envoismoinscher_cp'];
		} else {
			$this->data['envoismoinscher_cp'] = $this->config->get('envoismoinscher_cp');
		}

		if (isset($this->request->post['envoismoinscher_town'])) {
			$this->data['envoismoinscher_town'] = $this->request->post['envoismoinscher_town'];
		} else {
			$this->data['envoismoinscher_town'] = $this->config->get('envoismoinscher_town');
		}

		if (isset($this->request->post['envoismoinscher_iso'])) {
			$this->data['envoismoinscher_iso'] = $this->request->post['envoismoinscher_iso'];
		} else {
			$this->data['envoismoinscher_iso'] = $this->config->get('envoismoinscher_iso');
		}


		if (isset($this->request->post['envoismoinscher_phone'])) {
			$this->data['envoismoinscher_phone'] = $this->request->post['envoismoinscher_phone'];
		} else if ($this->config->get('envoismoinscher_phone') == '') {
			$this->data['envoismoinscher_phone'] = $this->config->get('config_telephone');
		} else {
			$this->data['envoismoinscher_phone'] = $this->config->get('envoismoinscher_phone');
		}

		if (isset($this->request->post['envoismoinscher_mail'])) {
			$this->data['envoismoinscher_mail'] = $this->request->post['envoismoinscher_mail'];
		} else if ($this->config->get('envoismoinscher_mail') == '') {
			$this->data['envoismoinscher_mail'] = $this->config->get('config_email');
		} else {
			$this->data['envoismoinscher_mail'] = $this->config->get('envoismoinscher_mail');
		}

		if (isset($this->request->post['envoismoinscher_adressComplement'])) {
			$this->data['envoismoinscher_adressComplement'] = $this->request->post['envoismoinscher_adressComplement'];
		} else {
			$this->data['envoismoinscher_adressComplement'] = $this->config->get('envoismoinscher_adressComplement');
		}

		if (isset($this->request->post['envoismoinscher_dispoDeb'])) {
			$this->data['envoismoinscher_dispoDeb'] = $this->request->post['envoismoinscher_dispoDeb'];
		} else {
			$this->data['envoismoinscher_dispoDeb'] = $this->config->get('envoismoinscher_dispoDeb');
		}
				//definition du menu déroulant
				$this->data['dispoDeb_menu'] = array();

				$this->data['dispoDeb_menu'][] = array(
					'value' => '01',
					'text'  => $this->language->get('text_dispoDeb_1200')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '02',
					'text'  => $this->language->get('text_dispoDeb_1215')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '03',
					'text'  => $this->language->get('text_dispoDeb_1230')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '04',
					'text'  => $this->language->get('text_dispoDeb_1245')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '05',
					'text'  => $this->language->get('text_dispoDeb_1300')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '06',
					'text'  => $this->language->get('text_dispoDeb_1315')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '07',
					'text'  => $this->language->get('text_dispoDeb_1330')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '08',
					'text'  => $this->language->get('text_dispoDeb_1345')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '09',
					'text'  => $this->language->get('text_dispoDeb_1400')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '10',
					'text'  => $this->language->get('text_dispoDeb_1415')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '11',
					'text'  => $this->language->get('text_dispoDeb_1430')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '12',
					'text'  => $this->language->get('text_dispoDeb_1445')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '13',
					'text'  => $this->language->get('text_dispoDeb_1500')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '14',
					'text'  => $this->language->get('text_dispoDeb_1515')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '15',
					'text'  => $this->language->get('text_dispoDeb_1530')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '16',
					'text'  => $this->language->get('text_dispoDeb_1545')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '17',
					'text'  => $this->language->get('text_dispoDeb_1600')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '18',
					'text'  => $this->language->get('text_dispoDeb_1615')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '19',
					'text'  => $this->language->get('text_dispoDeb_1630')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '20',
					'text'  => $this->language->get('text_dispoDeb_1645')
				);

				$this->data['dispoDeb_menu'][] = array(
					'value' => '21',
					'text'  => $this->language->get('text_dispoDeb_1700')
				);


		if (isset($this->request->post['envoismoinscher_dispoEnd'])) {
			$this->data['envoismoinscher_dispoEnd'] = $this->request->post['envoismoinscher_dispoEnd'];
		} else {
			$this->data['envoismoinscher_dispoEnd'] = $this->config->get('envoismoinscher_dispoEnd');
		}
				//definition du menu déroulant
				$this->data['dispoEnd_menu'] = array();

				$this->data['dispoEnd_menu'][] = array(
					'value' => '01',
					'text'  => $this->language->get('text_dispoEnd_1700')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '02',
					'text'  => $this->language->get('text_dispoEnd_1715')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '03',
					'text'  => $this->language->get('text_dispoEnd_1730')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '04',
					'text'  => $this->language->get('text_dispoEnd_1745')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '05',
					'text'  => $this->language->get('text_dispoEnd_1800')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '06',
					'text'  => $this->language->get('text_dispoEnd_1815')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '07',
					'text'  => $this->language->get('text_dispoEnd_1830')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '08',
					'text'  => $this->language->get('text_dispoEnd_1845')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '09',
					'text'  => $this->language->get('text_dispoEnd_1900')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '10',
					'text'  => $this->language->get('text_dispoEnd_1915')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '11',
					'text'  => $this->language->get('text_dispoEnd_1930')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '12',
					'text'  => $this->language->get('text_dispoEnd_1945')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '13',
					'text'  => $this->language->get('text_dispoEnd_2000')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '14',
					'text'  => $this->language->get('text_dispoEnd_2015')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '15',
					'text'  => $this->language->get('text_dispoEnd_2030')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '16',
					'text'  => $this->language->get('text_dispoEnd_2045')
				);

				$this->data['dispoEnd_menu'][] = array(
					'value' => '17',
					'text'  => $this->language->get('text_dispoEnd_2100')
				);


// ------------------------
// Vos envois
// ------------------------
                                
		if (isset($this->request->post['envoismoinscher_typeSend'])) {
			$this->data['envoismoinscher_typeSend'] = $this->request->post['envoismoinscher_typeSend'];
		} else {
			$this->data['envoismoinscher_typeSend'] = $this->config->get('envoismoinscher_typeSend');
		}
                
                //definition du menu déroulant
                $this->data['typeSend_menu'] = array();

                $this->data['typeSend_menu'][] = array(
                        'value' => 1,
                        'text'  => $this->language->get('text_type_send_colis')
                );
                $this->data['typeSend_menu'][] = array(
                        'value' => 2,
                        'text'  => $this->language->get('text_type_send_encombrant')
                );
                $this->data['typeSend_menu'][] = array(
                        'value' => 3,
                        'text'  => $this->language->get('text_type_send_palette')
                );
                $this->data['typeSend_menu'][] = array(
                        'value' => 4,
                        'text'  => $this->language->get('text_type_send_pli')
                );

		// ///////////////////////
		// Définition des poids min et max pour affichage des offres EnvoiMoinsCher en FRONT END
		// ///////////////////////
                
                //Poids min
		if (isset($this->request->post['envoismoinscher_minWeight'])) {
			$this->data['envoismoinscher_minWeight'] = $this->request->post['envoismoinscher_minWeight'];
		} else {
			$this->data['envoismoinscher_minWeight'] = $this->config->get('envoismoinscher_minWeight');
		}
                
                //Poids max
		if (isset($this->request->post['envoismoinscher_maxWeight'])) {
			$this->data['envoismoinscher_maxWeight'] = $this->request->post['envoismoinscher_maxWeight'];
		} else {
			$this->data['envoismoinscher_maxWeight'] = $this->config->get('envoismoinscher_maxWeight');
		}
                
                //Poids par défaut
		if (isset($this->request->post['envoismoinscher_defaultWeight'])) {
			$this->data['envoismoinscher_defaultWeight'] = $this->request->post['envoismoinscher_defaultWeight'];
		} else {
			$this->data['envoismoinscher_defaultWeight'] = $this->config->get('envoismoinscher_defaultWeight');
		}
                
		// ///////////////////////
		// Nature de la commande
		// ///////////////////////
                // Initialisation de la classe chargée de récupérer les catégories 
                $contentCl = new Env_ContentCategory(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
				$contentCl->setPlatformParams($this->platform, $this->version_platform, $this->version_lib);
                $contentCl->setEnv($this->config->get('envoismoinscher_environment'));
                // Cette méthode permet de récupérer la liste des catégories
                $contentCl->getCategories();
                // Celle-ci charge la liste des catégories de contenus (sous-catégories)
                $contentCl->getContents(); 
		if (isset($this->request->post['envoismoinscher_natureSend'])) {
                    $this->data['envoismoinscher_natureSend'] = $this->request->post['envoismoinscher_natureSend'];
		} else {
                    $this->data['envoismoinscher_natureSend'] = $this->config->get('envoismoinscher_natureSend');
		}
                
                //definition du menu déroulant
                $this->data['natureSend_menu'] = array();

                if(!$contentCl->curlError && !$contentCl->respError) {
                    foreach($contentCl->categories as $c => $category) { 

                            $this->data['natureSend_menu'][] = array(
                                    'name' => $category['label']
                            );

                            foreach($contentCl->contents[$category['code']] as $ch => $child) { 
                                    $this->data['natureSend_menu'][] = array(
                                            'value' => $child['code'],
                                            'text'  => $child['label']
                                    );
                            }
                    }
                } else {
                    $this->data['natureSend_menu'][] = array(
                        'value' => 10100,
                        'text'  => 'Documents sans valeur commerciale'
                    );
                }

                if (isset($this->request->post['envoismoinscher_check_natureSend'])) {
			$this->data['envoismoinscher_check_natureSend'] = $this->request->post['envoismoinscher_check_natureSend'];
		} else {
			$this->data['envoismoinscher_check_natureSend'] = $this->config->get('envoismoinscher_check_natureSend');
		}
                
		// ///////////////////////
                // Option type d'emballage
		// ///////////////////////
                
		if (isset($this->request->post['envoismoinscher_embalSend'])) {
			$this->data['envoismoinscher_embalSend'] = $this->request->post['envoismoinscher_embalSend'];
		} else {
			$this->data['envoismoinscher_embalSend'] = $this->config->get('envoismoinscher_embalSend');
		}	
                //définition du menu déroulant
                $this->data['embalSend_menu'][] = array(
                        'value' => '1-Boîte',
                        'text'  => 'Boîte'
                );
                $this->data['embalSend_menu'][] = array(
                        'value' => '17-Tube',
                        'text'  => 'Tube'
                );
                
		// ///////////////////////
                // Option client particulier
		// ///////////////////////

                if (isset($this->request->post['envoismoinscher_clientParticulier'])) {
			$this->data['envoismoinscher_clientParticulier'] = $this->request->post['envoismoinscher_clientParticulier'];
		} else {
			$this->data['envoismoinscher_clientParticulier'] = $this->config->get('envoismoinscher_clientParticulier');
		}	
                //définition du menu déroulant
                $this->data['clientParticulier_menu'][] = array(
                        'value' => '0',
                        'text'  => $this->language->get('text_status_dis')
                );
                $this->data['clientParticulier_menu'][] = array(
                        'value' => '1',
                        'text'  => $this->language->get('text_status_ena')
                );

		// ///////////////////////
		// Option multi-colis
		// ///////////////////////
                
		if (isset($this->request->post['envoismoinscher_multicolis'])) {
			$this->data['envoismoinscher_multicolis'] = $this->request->post['envoismoinscher_multicolis'];
		} else {
			$this->data['envoismoinscher_multicolis'] = $this->config->get('envoismoinscher_multicolis');
		}	
                
                // EMC V1 - 2015-06-24 : Set to 0
                $this->data['envoismoinscher_multicolis'] = 0;
                
                //définition du menu déroulant
                $this->data['multicolis_menu'][] = array(
                        'value' => '0',
                        'text'  => $this->language->get('text_status_dis')
                );
                $this->data['multicolis_menu'][] = array(
                        'value' => '1',
                        'text'  => $this->language->get('text_status_ena')
                );

		// ///////////////////////
		// Option assurance
		// ///////////////////////
                
		if (isset($this->request->post['envoismoinscher_assurance'])) {
			$this->data['envoismoinscher_assurance'] = $this->request->post['envoismoinscher_assurance'];
		} else {
			$this->data['envoismoinscher_assurance'] = $this->config->get('envoismoinscher_assurance');
		}	
                //définition du menu déroulant
                $this->data['assurance_menu'][] = array(
                        'value' => 'false',
                        'text'  => $this->language->get('text_status_dis')
                );
                $this->data['assurance_menu'][] = array(
                        'value' => 'true',
                        'text'  => $this->language->get('text_status_ena')
                );

		// ///////////////////////
		// Type de prix
		// ///////////////////////
                
		if (isset($this->request->post['envoismoinscher_price'])) {
			$this->data['envoismoinscher_price'] = $this->request->post['envoismoinscher_price'];
		} else {
			$this->data['envoismoinscher_price'] = $this->config->get('envoismoinscher_price');
		}
                
		// ///////////////////////
		// Email settings
		// ///////////////////////
                
                if (isset($this->request->post['envoismoinscher_check_mail1'])) {
			$this->data['envoismoinscher_check_mail1'] = $this->request->post['envoismoinscher_check_mail1'];
		} else {
			$this->data['envoismoinscher_check_mail1'] = $this->config->get('envoismoinscher_check_mail1');
		}
                if (isset($this->request->post['envoismoinscher_check_mail2'])) {
			$this->data['envoismoinscher_check_mail2'] = $this->request->post['envoismoinscher_check_mail2'];
		} else {
			$this->data['envoismoinscher_check_mail2'] = $this->config->get('envoismoinscher_check_mail2');
		}
                if (isset($this->request->post['envoismoinscher_check_mail3'])) {
			$this->data['envoismoinscher_check_mail3'] = $this->request->post['envoismoinscher_check_mail3'];
		} else {
			$this->data['envoismoinscher_check_mail3'] = $this->config->get('envoismoinscher_check_mail3');
		}
                
		// ///////////////////////
		// Option date de récupération
		// ///////////////////////
                
		if (isset($this->request->post['envoismoinscher_dateRecup'])) {
			$this->data['envoismoinscher_dateRecup'] = $this->request->post['envoismoinscher_dateRecup'];
		} else {
			$this->data['envoismoinscher_dateRecup'] = $this->config->get('envoismoinscher_dateRecup');
		}
		if (isset($this->request->post['envoismoinscher_dateRecupH1'])) {
			$this->data['envoismoinscher_dateRecupH1'] = $this->request->post['envoismoinscher_dateRecupH1'];
		} else {
			$this->data['envoismoinscher_dateRecupH1'] = $this->config->get('envoismoinscher_dateRecupH1');
		}
			//definition du menu déroulant
				$this->data['dateRecupH1_menu'] = array();
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '01',
					'text'  => $this->language->get('text_dateRecup_1')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '02',
					'text'  => $this->language->get('text_dateRecup_2')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '03',
					'text'  => $this->language->get('text_dateRecup_3')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '04',
					'text'  => $this->language->get('text_dateRecup_4')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '05',
					'text'  => $this->language->get('text_dateRecup_5')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '06',
					'text'  => $this->language->get('text_dateRecup_6')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '07',
					'text'  => $this->language->get('text_dateRecup_7')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '08',
					'text'  => $this->language->get('text_dateRecup_8')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '09',
					'text'  => $this->language->get('text_dateRecup_9')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '10',
					'text'  => $this->language->get('text_dateRecup_10')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '11',
					'text'  => $this->language->get('text_dateRecup_11')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '12',
					'text'  => $this->language->get('text_dateRecup_12')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '13',
					'text'  => $this->language->get('text_dateRecup_13')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '14',
					'text'  => $this->language->get('text_dateRecup_14')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '15',
					'text'  => $this->language->get('text_dateRecup_15')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '16',
					'text'  => $this->language->get('text_dateRecup_16')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '17',
					'text'  => $this->language->get('text_dateRecup_17')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '18',
					'text'  => $this->language->get('text_dateRecup_18')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '19',
					'text'  => $this->language->get('text_dateRecup_19')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '20',
					'text'  => $this->language->get('text_dateRecup_20')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '21',
					'text'  => $this->language->get('text_dateRecup_21')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '22',
					'text'  => $this->language->get('text_dateRecup_22')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '23',
					'text'  => $this->language->get('text_dateRecup_23')
				);
				$this->data['dateRecupH1_menu'][] = array(
					'value' => '24',
					'text'  => $this->language->get('text_dateRecup_24')
				);
		if (isset($this->request->post['envoismoinscher_dateRecupH2'])) {
			$this->data['envoismoinscher_dateRecupH2'] = $this->request->post['envoismoinscher_dateRecupH2'];
		} else {
			$this->data['envoismoinscher_dateRecupH2'] = $this->config->get('envoismoinscher_dateRecupH2');
		}
			//definition du menu déroulant
				$this->data['dateRecupH2_menu'] = array();
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '01',
					'text'  => $this->language->get('text_dateRecup_1')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '02',
					'text'  => $this->language->get('text_dateRecup_2')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '03',
					'text'  => $this->language->get('text_dateRecup_3')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '04',
					'text'  => $this->language->get('text_dateRecup_4')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '05',
					'text'  => $this->language->get('text_dateRecup_5')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '06',
					'text'  => $this->language->get('text_dateRecup_6')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '07',
					'text'  => $this->language->get('text_dateRecup_7')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '08',
					'text'  => $this->language->get('text_dateRecup_8')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '09',
					'text'  => $this->language->get('text_dateRecup_9')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '10',
					'text'  => $this->language->get('text_dateRecup_10')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '11',
					'text'  => $this->language->get('text_dateRecup_11')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '12',
					'text'  => $this->language->get('text_dateRecup_12')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '13',
					'text'  => $this->language->get('text_dateRecup_13')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '14',
					'text'  => $this->language->get('text_dateRecup_14')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '15',
					'text'  => $this->language->get('text_dateRecup_15')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '16',
					'text'  => $this->language->get('text_dateRecup_16')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '17',
					'text'  => $this->language->get('text_dateRecup_17')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '18',
					'text'  => $this->language->get('text_dateRecup_18')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '19',
					'text'  => $this->language->get('text_dateRecup_19')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '20',
					'text'  => $this->language->get('text_dateRecup_20')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '21',
					'text'  => $this->language->get('text_dateRecup_21')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '22',
					'text'  => $this->language->get('text_dateRecup_22')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '23',
					'text'  => $this->language->get('text_dateRecup_23')
				);
				$this->data['dateRecupH2_menu'][] = array(
					'value' => '24',
					'text'  => $this->language->get('text_dateRecup_24')
				);

		if (isset($this->request->post['envoismoinscher_dateRecup2'])) {
			$this->data['envoismoinscher_dateRecup2'] = $this->request->post['envoismoinscher_dateRecup2'];
		} else {
			$this->data['envoismoinscher_dateRecup2'] = $this->config->get('envoismoinscher_dateRecup2');
		}
		if (isset($this->request->post['envoismoinscher_dateRecup2H1'])) {
			$this->data['envoismoinscher_dateRecup2H1'] = $this->request->post['envoismoinscher_dateRecup2H1'];
		} else {
			$this->data['envoismoinscher_dateRecup2H1'] = $this->config->get('envoismoinscher_dateRecup2H1');
		}
			//definition du menu déroulant
				$this->data['dateRecup2H1_menu'] = array();
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '01',
					'text'  => $this->language->get('text_dateRecup_1')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '02',
					'text'  => $this->language->get('text_dateRecup_2')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '03',
					'text'  => $this->language->get('text_dateRecup_3')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '04',
					'text'  => $this->language->get('text_dateRecup_4')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '05',
					'text'  => $this->language->get('text_dateRecup_5')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '06',
					'text'  => $this->language->get('text_dateRecup_6')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '07',
					'text'  => $this->language->get('text_dateRecup_7')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '08',
					'text'  => $this->language->get('text_dateRecup_8')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '09',
					'text'  => $this->language->get('text_dateRecup_9')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '10',
					'text'  => $this->language->get('text_dateRecup_10')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '11',
					'text'  => $this->language->get('text_dateRecup_11')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '12',
					'text'  => $this->language->get('text_dateRecup_12')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '13',
					'text'  => $this->language->get('text_dateRecup_13')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '14',
					'text'  => $this->language->get('text_dateRecup_14')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '15',
					'text'  => $this->language->get('text_dateRecup_15')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '16',
					'text'  => $this->language->get('text_dateRecup_16')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '17',
					'text'  => $this->language->get('text_dateRecup_17')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '18',
					'text'  => $this->language->get('text_dateRecup_18')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '19',
					'text'  => $this->language->get('text_dateRecup_19')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '20',
					'text'  => $this->language->get('text_dateRecup_20')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '21',
					'text'  => $this->language->get('text_dateRecup_21')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '22',
					'text'  => $this->language->get('text_dateRecup_22')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '23',
					'text'  => $this->language->get('text_dateRecup_23')
				);
				$this->data['dateRecup2H1_menu'][] = array(
					'value' => '24',
					'text'  => $this->language->get('text_dateRecup_24')
				);
		if (isset($this->request->post['envoismoinscher_dateRecup2H2'])) {
			$this->data['envoismoinscher_dateRecup2H2'] = $this->request->post['envoismoinscher_dateRecup2H2'];
		} else {
			$this->data['envoismoinscher_dateRecup2H2'] = $this->config->get('envoismoinscher_dateRecup2H2');
		}
			//definition du menu déroulant
				$this->data['dateRecup2H2_menu'] = array();
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '01',
					'text'  => $this->language->get('text_dateRecup_1')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '02',
					'text'  => $this->language->get('text_dateRecup_2')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '03',
					'text'  => $this->language->get('text_dateRecup_3')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '04',
					'text'  => $this->language->get('text_dateRecup_4')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '05',
					'text'  => $this->language->get('text_dateRecup_5')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '06',
					'text'  => $this->language->get('text_dateRecup_6')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '07',
					'text'  => $this->language->get('text_dateRecup_7')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '08',
					'text'  => $this->language->get('text_dateRecup_8')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '09',
					'text'  => $this->language->get('text_dateRecup_9')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '10',
					'text'  => $this->language->get('text_dateRecup_10')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '11',
					'text'  => $this->language->get('text_dateRecup_11')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '12',
					'text'  => $this->language->get('text_dateRecup_12')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '13',
					'text'  => $this->language->get('text_dateRecup_13')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '14',
					'text'  => $this->language->get('text_dateRecup_14')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '15',
					'text'  => $this->language->get('text_dateRecup_15')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '16',
					'text'  => $this->language->get('text_dateRecup_16')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '17',
					'text'  => $this->language->get('text_dateRecup_17')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '18',
					'text'  => $this->language->get('text_dateRecup_18')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '19',
					'text'  => $this->language->get('text_dateRecup_19')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '20',
					'text'  => $this->language->get('text_dateRecup_20')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '21',
					'text'  => $this->language->get('text_dateRecup_21')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '22',
					'text'  => $this->language->get('text_dateRecup_22')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '23',
					'text'  => $this->language->get('text_dateRecup_23')
				);
				$this->data['dateRecup2H2_menu'][] = array(
					'value' => '24',
					'text'  => $this->language->get('text_dateRecup_24')
				);


		// ///////////////////////
		// Option mode de l'envoi en masse
		// ///////////////////////
                
		if (isset($this->request->post['envoismoinscher_modeSend'])) {
			$this->data['envoismoinscher_modeSend'] = $this->request->post['envoismoinscher_modeSend'];
		} else {
			$this->data['envoismoinscher_modeSend'] = $this->config->get('envoismoinscher_modeSend');
		}
                
                // EMC V1 - 2015-06-24 : Set to 0 (w/o verification)
                $this->data['envoismoinscher_modeSend'] = 0;
                
                //définition du menu déroulant
                 $this->data['modeSend_menu'][] = array(
                        'value' => '0',
                        'text'  => 'Sans vérification des envois'
                );
               $this->data['modeSend_menu'][] = array(
                        'value' => '1',
                        'text'  => 'Avec vérification de chaque envoi'
                );


		// ///////////////////////
		// Option état des commandes
		// ///////////////////////
                
                //définition du menu déroulant
                $orderStatus = $this->db->query("SELECT order_status_id, name FROM ".DB_PREFIX."order_status");

		if (isset($this->request->post['envoismoinscher_passCmd'])) {
			$this->data['envoismoinscher_passCmd'] = $this->request->post['envoismoinscher_passCmd'];
		} else {
			$this->data['envoismoinscher_passCmd'] = $this->config->get('envoismoinscher_passCmd');
		}	
		$this->data['passCmd_menu'] = $orderStatus;


		if (isset($this->request->post['envoismoinscher_sendCmd'])) {
			$this->data['envoismoinscher_sendCmd'] = $this->request->post['envoismoinscher_sendCmd'];
		} else {
			$this->data['envoismoinscher_sendCmd'] = $this->config->get('envoismoinscher_sendCmd');
		}	
		$this->data['sendCmd_menu'] = $orderStatus;


		if (isset($this->request->post['envoismoinscher_arriveCmd'])) {
			$this->data['envoismoinscher_arriveCmd'] = $this->request->post['envoismoinscher_arriveCmd'];
		} else {
			$this->data['envoismoinscher_arriveCmd'] = $this->config->get('envoismoinscher_arriveCmd');
		}	
		$this->data['arriveCmd_menu'] = $orderStatus;


		if (isset($this->request->post['envoismoinscher_supprCmd'])) {
			$this->data['envoismoinscher_supprCmd'] = $this->request->post['envoismoinscher_supprCmd'];
		} else {
			$this->data['envoismoinscher_supprCmd'] = $this->config->get('envoismoinscher_supprCmd');
		}		
		$this->data['supprCmd_menu'] = $orderStatus;

// ------------------------
// Vos transporteurs
// ------------------------

            function array_msort($array, $cols)
            {
                $colarr = array();
                foreach ($cols as $col => $order) {
                    $colarr[$col] = array();
                    foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); }
                }
                $eval = 'array_multisort(';
                foreach ($cols as $col => $order) {
                    $eval .= '$colarr[\''.$col.'\'],'.$order.',';
                }
                $eval = substr($eval,0,-1).');';
                eval($eval);
                $ret = array();
                foreach ($colarr as $col => $arr) {
                    foreach ($arr as $k => $v) {
                        $k = substr($k,1);
                        if (!isset($ret[$k])) $ret[$k] = $array[$k];
                        $ret[$k][$col] = $array[$k][$col];
                    }
                }
                return $ret;
            }
            
            /* Initialisation de la classe chargée de récupérer les transporteurs disponibles */
            $lcCl = new Env_CarriersList(array("user" => $userData['login'], "pass" => $userData['password'], "key" => $userData['api_key']));
			$lcCl->setPlatformParams($this->platform, $this->version_platform, $this->version_lib);
            $lcCl->setEnv($this->config->get('envoismoinscher_environment')); 

            $lcCl->loadCarriersList("Opencart", $this->version_platform);
            $family = array(
                "1" => "Economique",
                "2" => "Expressiste"
            );
            $zone = array(
                "1" => "France",
                "2" => "International",
                "3" => "Europe"
            );
            $this->data['parcel_pickup_point'] = array(
                "0" => $this->language->get('text_non'),
                "1" => $this->language->get('text_oui')
            );
            $this->data['parcel_dropoff_point'] = array(
                "0" => $this->language->get('text_non'),
                "1" => $this->language->get('text_oui')
            );
            
            // Etat d'activation du transporteur 
            $this->data['carrier_status'] = array();
            $this->data['carrier_status'][] = array(
                'value' => '0',
                'text'  => $this->language->get('text_trans_dis')
            );
            $this->data['carrier_status'][] = array(
                'value' => '1',
                'text'  => $this->language->get('text_trans_ena')
            );

            // Type de prix du transporteur 
            $this->data['carrier_price'] = array();
            $this->data['carrier_price'][] = array(
                'value' => '0',
                'text'  => $this->language->get('text_trans_real')
            );
            $this->data['carrier_price'][] = array(
                'value' => '1',
                'text'  => $this->language->get('text_trans_scale')
            );

            // Récupération des transporteurs 
            /* If there is no errors, we get the datas */
            $carriers_tmp = array();
            if(!$lcCl->curlError && !$lcCl->respError) {                
                $carriers_tmp = array_msort($lcCl->carriers, array('family'=>SORT_ASC, 'ope_code'=>SORT_ASC, 'srv_code'=>SORT_ASC));
            }elseif($lcCl->respError) { /* Cas d'erreur */
                $error_emc = $error_emc."La requête n'est pas valide : ";
                foreach($lcCl->respErrorsList as $m => $message) { 
                    $error_emc = $error_emc."<br />".$message['message'];
                }
            }else{
                $error_emc = $error_emc."<b>Une erreur pendant l'envoi de la requête </b> : ".$cotCl->curlErrorText; 
            }
            
            foreach ($carriers_tmp as $carrier_tmp) {
                
                $ope_code = $carrier_tmp['ope_code'];
                $ope_name = $carrier_tmp['ope_name'];
                $srv_code = $carrier_tmp['srv_code'];
                $srv_name = $carrier_tmp['srv_name'];
                $carrier_label_store = $carrier_tmp['label_store'];
                $carrier_description = $carrier_tmp['description'];
                $carrier_family = $carrier_tmp['family'];
                $carrier_parcel_pickup_point = $carrier_tmp['parcel_pickup_point'];
                $carrier_parcel_dropoff_point = $carrier_tmp['parcel_dropoff_point'];

                if ($carrier_family == 1) {
                    $this->data['carriers_list_eco'][] = $srv_code;
                }else{
                    $this->data['carriers_list_exp'][] = $srv_code;
                }
                
                $this->data['srv_code'][$srv_code]['name'] = $ope_name." - <b>".$srv_name."</b>";
				
                if (isset($this->request->post[$srv_code])) {
                    $this->data['srv_code'][$srv_code]['status'] = $this->request->post[$srv_code];
                    $this->data['srv_code'][$srv_code]['price'] = $this->request->post[$srv_code.'_price'];
                    $this->data['srv_code'][$srv_code]['url'] = $this->request->post[$srv_code.'_url'];
				} else {
                    $this->data['srv_code'][$srv_code]['status'] = $this->config->get($srv_code);
                    $this->data['srv_code'][$srv_code]['price'] = $this->config->get($srv_code.'_price');
                    $this->data['srv_code'][$srv_code]['url'] = $this->config->get($srv_code.'_url');
				}
                
                $this->data['srv_code'][$srv_code]['parcel_pickup_point'] = $carrier_parcel_pickup_point;
                $this->data['srv_code'][$srv_code]['parcel_dropoff_point'] = $carrier_parcel_dropoff_point;
              
                if ($carrier_parcel_dropoff_point == 1) {
                    
                    /* Préparation, envoi de la requête à l'API et reception de la réponse */
                    $lpCl = new Env_ListPoints(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
					$lpCl->setPlatformParams($this->platform, $this->version_platform, $this->version_lib);
                    $lpCl->setEnv($this->config->get('envoismoinscher_environment'));
                    $params = array('srv_code' => $srv_code, 'pays' => $from['pays'], 'cp' => $from['code_postal'], 'ville' => $from['ville']);
                    $lpCl->getListPoints($ope_code, $params);

                    // Récupération des points relais de dépôt (Enlèvement chez le commerçant) 
                    /* If there is no errors, we get the datas */
                    if(!$lpCl->curlError && !$lpCl->respError) { 
                        $this->data['srv_code'][$srv_code]['listpoints'] = array();
                        foreach($lpCl->listPoints as $point){
                            $this->data['srv_code'][$srv_code]['listpoints'][] = array(
                                'value' => $point['code'],
                                'text'  => $point['name'].' - '.$point['address'].' - '.$point['zipcode'].' - '.$point['city']
                            );
                         }
                    }elseif($lpCl->respError) { /* Cas d'erreur */
                        $error_emc = $error_emc."La requête [".$srv_code."] n'est pas valide : ";
                            foreach($lpCl->respErrorsList as $m => $message) { 
                                $error_emc = $error_emc.$message['message']."<br /><br />";
                            }
                    }else{
                        $error_emc = $error_emc."<b>Une erreur s'est produite pendant l'envoi de la requête pour le transporteur [ <b>".$srv_code."</b> ] </b> : ".$lpCl->curlErrorText."<br />"; 
                    }
                }
                
				if (isset($this->request->post[$srv_code.'_depot'])) {            
							$this->data['srv_code'][$srv_code]['depot'] = $this->request->post[$srv_code.'_depot'];	
				} else {             
							if (!($this->config->get($srv_code.'_depot'))) {                       
								$this->data['srv_code'][$srv_code]['depot'] = "";
							} else {
								$this->data['srv_code'][$srv_code]['depot'] = $this->config->get($srv_code.'_depot');
							}
				}
                
                $this->data['srv_code'][$srv_code]['description'] = $carrier_label_store;
				$this->data['srv_code'][$srv_code]['delai'] = $carrier_description;
				
				//Prix par transporteur
				if (isset($this->request->post[$srv_code.'_frais_base'])) {
					$this->data[$srv_code.'_frais_base'] = $this->request->post[$srv_code.'_frais_base'];
				} else {
					$this->data[$srv_code.'_frais_base'] = $this->config->get($srv_code.'_frais_base');
				}	
				
					//définition du menu déroulant
					$this->data[$srv_code.'frais_menu'][] = array(
							'value' => 'weight',
							'text'  => $this->language->get('text_frais_base_weight')
					);
					$this->data[$srv_code.'frais_menu'][] = array(
							'value' => 'price',
							'text'  => $this->language->get('text_frais_base_price')
					);
						
				$this->data['nb_range'] = $this->nb_range;
				
				for ($i=1; $i <= $this->nb_range; $i++){
					if (isset($this->request->post[$srv_code.'_range_low_'.$i])) {
						$this->data[$srv_code.'_range_low_'.$i] = $this->request->post[$srv_code.'_range_low_'.$i];
					} else {
						$this->data[$srv_code.'_range_low_'.$i] = $this->config->get($srv_code.'_range_low_'.$i);
					}
					if (isset($this->request->post[$srv_code.'envoismoinscher_range_high_'.$i])) {
						$this->data[$srv_code.'_range_high_'.$i] = $this->request->post[$srv_code.'_range_high_'.$i];
					} else {
						$this->data[$srv_code.'_range_high_'.$i] = $this->config->get($srv_code.'_range_high_'.$i);
					}
					if (isset($this->request->post[$srv_code.'envoismoinscher_range_price_'.$i])) {
						$this->data[$srv_code.'_range_price_'.$i] = $this->request->post[$srv_code.'_range_price_'.$i];
					} else {
						$this->data[$srv_code.'_range_price_'.$i] = $this->config->get($srv_code.'_range_price_'.$i);
					}
				}
			
			}

// ------------------------
// Dimensions
// ------------------------
		$this->data['nb_dim'] = $this->nb_dim;
		for ($i=1; $i <= $this->nb_dim; $i++){
			if (isset($this->request->post['envoismoinscher_dim_weight_'.$i])) {
				$this->data['envoismoinscher_dim_weight_'.$i] = $this->request->post['envoismoinscher_dim_weight_'.$i];
			} else {
				$this->data['envoismoinscher_dim_weight_'.$i] = $this->config->get('envoismoinscher_dim_weight_'.$i);
			}
			if (isset($this->request->post['envoismoinscher_dim_lenght_'.$i])) {
				$this->data['envoismoinscher_dim_lenght_'.$i] = $this->request->post['envoismoinscher_dim_lenght_'.$i];
			} else {
				$this->data['envoismoinscher_dim_lenght_'.$i] = $this->config->get('envoismoinscher_dim_lenght_'.$i);
			}
			if (isset($this->request->post['envoismoinscher_dim_width_'.$i])) {
				$this->data['envoismoinscher_dim_width_'.$i] = $this->request->post['envoismoinscher_dim_width_'.$i];
			} else {
				$this->data['envoismoinscher_dim_width_'.$i] = $this->config->get('envoismoinscher_dim_width_'.$i);
			}
			if (isset($this->request->post['envoismoinscher_dim_height_'.$i])) {
				$this->data['envoismoinscher_dim_height_'.$i] = $this->request->post['envoismoinscher_dim_height_'.$i];
			} else {
				$this->data['envoismoinscher_dim_height_'.$i] = $this->config->get('envoismoinscher_dim_height_'.$i);
			}					
		}

// ------------------------
// Assurance
// ------------------------
		if (isset($this->request->post['envoismoinscher_assurance_emballage'])) {
			$this->data['envoismoinscher_assurance_emballage'] = $this->request->post['envoismoinscher_assurance_emballage'];
		} else {
			$this->data['envoismoinscher_assurance_emballage'] = $this->config->get('envoismoinscher_assurance_emballage');
		}
		if (isset($this->request->post['envoismoinscher_assurance_fermeture'])) {
			$this->data['envoismoinscher_assurance_fermeture'] = $this->request->post['envoismoinscher_assurance_fermeture'];
		} else {
			$this->data['envoismoinscher_assurance_fermeture'] = $this->config->get('envoismoinscher_assurance_fermeture');
		}
		if (isset($this->request->post['envoismoinscher_assurance_fixation'])) {
			$this->data['envoismoinscher_assurance_fixation'] = $this->request->post['envoismoinscher_assurance_fixation'];
		} else {
			$this->data['envoismoinscher_assurance_fixation'] = $this->config->get('envoismoinscher_assurance_fixation');
		}
		if (isset($this->request->post['envoismoinscher_assurance_materiau'])) {
			$this->data['envoismoinscher_assurance_materiau'] = $this->request->post['envoismoinscher_assurance_materiau'];
		} else {
			$this->data['envoismoinscher_assurance_materiau'] = $this->config->get('envoismoinscher_assurance_materiau');
		}
		if (isset($this->request->post['envoismoinscher_assurance_protection'])) {
			$this->data['envoismoinscher_assurance_protection'] = $this->request->post['envoismoinscher_assurance_protection'];
		} else {
			$this->data['envoismoinscher_assurance_protection'] = $this->config->get('envoismoinscher_assurance_protection');
		}
                
// ------------------------
// Frais
// ------------------------
		if (isset($this->request->post['envoismoinscher_frais_base'])) {
			$this->data['envoismoinscher_frais_base'] = $this->request->post['envoismoinscher_frais_base'];
		} else {
			$this->data['envoismoinscher_frais_base'] = $this->config->get('envoismoinscher_frais_base');
		}	
                //définition du menu déroulant
                $this->data['frais_menu'][] = array(
                        'value' => 'weight',
                        'text'  => $this->language->get('text_frais_base_weight')
                );
                $this->data['frais_menu'][] = array(
                        'value' => 'price',
                        'text'  => $this->language->get('text_frais_base_price')
                );

		$this->data['nb_range'] = $this->nb_range;
		for ($i=1; $i <= $this->nb_range; $i++){
			if (isset($this->request->post['envoismoinscher_range_low_'.$i])) {
				$this->data['envoismoinscher_range_low_'.$i] = $this->request->post['envoismoinscher_range_low_'.$i];
			} else {
				$this->data['envoismoinscher_range_low_'.$i] = $this->config->get('envoismoinscher_range_low_'.$i);
			}
			if (isset($this->request->post['envoismoinscher_range_high_'.$i])) {
				$this->data['envoismoinscher_range_high_'.$i] = $this->request->post['envoismoinscher_range_high_'.$i];
			} else {
				$this->data['envoismoinscher_range_high_'.$i] = $this->config->get('envoismoinscher_range_high_'.$i);
			}
			if (isset($this->request->post['envoismoinscher_range_price_'.$i])) {
				$this->data['envoismoinscher_range_price_'.$i] = $this->request->post['envoismoinscher_range_price_'.$i];
			} else {
				$this->data['envoismoinscher_range_price_'.$i] = $this->config->get('envoismoinscher_range_price_'.$i);
			}
		}

// ------------------------
// Les commandes
// ------------------------
                
		$like = 'envoismoinscher%';
		
                        // Les commandes non-envoyées
			$tempOrder = $this->data['orderEMC'] = $this->db->query(
				"SELECT order_id, date_added, shipping_firstname, shipping_lastname, shipping_company, shipping_method, o.order_status_id, name 
				FROM `".DB_PREFIX."order` o, `".DB_PREFIX."order_status` s 
				WHERE o.order_status_id = s.order_status_id 
                                AND s.language_id = '" . (int)$this->config->get('config_language_id') . "' 
				AND shipping_code LIKE '".$like."' 
				AND o.order_status_id < 2 
				ORDER BY date_added desc "
			);		
			$i=0;
                        $tabOrderInfo = array();
			foreach ($tempOrder->rows as $orderEMC1) {
				$tabOrderInfo[$i] = $orderEMC1;
				$tabOrderInfo[$i]['url'] = $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $orderEMC1['order_id'], 'SSL');
				$i++; 
			}
                        if (isset($tabOrderInfo)) {
                            $this->data['orderEMC'] = $tabOrderInfo;
                        }
                        
                        // Les commandes envoyées
			$tempOrder2 = $this->data['orderEMCsent'] = $this->db->query(
				"SELECT order_id, date_added, shipping_firstname, shipping_lastname, shipping_company, shipping_method, o.order_status_id, name 
				FROM `".DB_PREFIX."order` o, `".DB_PREFIX."order_status` s 
				WHERE o.order_status_id = s.order_status_id 
                                AND s.language_id = '" . (int)$this->config->get('config_language_id') . "' 
				AND shipping_code LIKE '".$like."' 
				AND o.order_status_id > 1 
				ORDER BY date_added desc "
			);		
			$i=0;
                        $tabOrderInfo2 = array();
			foreach ($tempOrder2->rows as $orderEMC1sent) {
				$tabOrderInfo2[$i] = $orderEMC1sent;
				$tabOrderInfo2[$i]['url'] = $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $orderEMC1sent['order_id'], 'SSL');
				$i++; 
			}
                        if (isset($tabOrderInfo2)) {
                            $this->data['orderEMCsent'] = $tabOrderInfo2;
                        }
                        
                        $this->data['token'] = $this->session->data['token'];
				
// ------------------------
// 
// ------------------------	
                        
                $this->data['error_emc'] = $error_emc;
                
// ------------------------
// 
// ------------------------	
                        
		$this->template = 'shipping/envoismoinscher.tpl';
		$this->children = array(
			'common/header',
			'common/footer'
		);
				
		$this->response->setOutput($this->render());
	}

// ------------------------
// Fonction Get Order
// ------------------------
        
	public function getOrder () {
            
            if(isset($_GET['order_id']) && $_GET['order_id'] > 0) {
                
                $order_id = $_GET['order_id'];
                
		// Informations sur l'expéditeur et le destinataire 
		$userData = array(
			"login" => $this->config->get('envoismoinscher_login'),
			"password" => $this->config->get('envoismoinscher_pwd'),
			"api_key" => $this->config->get('envoismoinscher_key')
		);

		require_once(DIR_SYSTEM.'library/emc/WebService.php');
		require_once(DIR_SYSTEM.'library/emc/Carrier.php');
		require_once(DIR_SYSTEM.'library/emc/CarriersList.php');
		require_once(DIR_SYSTEM.'library/emc/ContentCategory.php');
		require_once(DIR_SYSTEM.'library/emc/Country.php');
		require_once(DIR_SYSTEM.'library/emc/ListPoints.php');
		require_once(DIR_SYSTEM.'library/emc/OrderStatus.php');
		require_once(DIR_SYSTEM.'library/emc/ParcelPoint.php');
		require_once(DIR_SYSTEM.'library/emc/Quotation.php');
		require_once(DIR_SYSTEM.'library/emc/Service.php');
		require_once(DIR_SYSTEM.'library/emc/User.php');
                   
		$infos = $this->db->query("SELECT * FROM `".DB_PREFIX."order` WHERE order_id = ".$order_id);
		
		$from = array(
			"pays" => str_replace("FX", "FR", $this->config->get('envoismoinscher_iso')),
			"code_postal" => $this->config->get('envoismoinscher_cp'),
			"type" => "entreprise",
			"societe" =>  $this->config->get('envoismoinscher_brand'),
			"ville" =>  $this->config->get('envoismoinscher_town'),
			"adresse" =>  $this->config->get('envoismoinscher_adress'), 
			"civilite" =>  $this->config->get('envoismoinscher_civility'),
			"prenom" =>  $this->config->get('envoismoinscher_firstName'),
			"nom" =>  $this->config->get('envoismoinscher_lastName'),
			"email" =>  $this->config->get('envoismoinscher_mail'),
			"tel" =>  $this->config->get('envoismoinscher_phone'),
			"infos" =>  $this->config->get('envoismoinscher_adressComplement')
		);
		
		$country = $this->db->query("SELECT iso_code_2 FROM ".DB_PREFIX."country WHERE country_id = ".$infos->row['shipping_country_id']);
		$company = $this->db->query("SELECT store_id FROM ".DB_PREFIX."customer WHERE customer_id = ".$infos->row['customer_id']);
                
		if (isset($infos->row['shipping_company']) && $infos->row['shipping_company'] && ($this->config->get('envoismoinscher_clientParticulier') == 0 )) {
			$compagny_test ='entreprise';
		} else {
			$compagny_test = 'particulier';
		}

		$to = array(
			"pays" => str_replace("FX", "FR", $country->row['iso_code_2']),
			"code_postal" => $infos->row['shipping_postcode'],
			"type" => $compagny_test,
			"societe" => $infos->row['shipping_company'],
			"ville" => $infos->row['shipping_city'],
			"adresse" => $infos->row['shipping_address_1'],
			"civilite" => "",
			"prenom" => $infos->row['shipping_firstname'],
			"nom" => $infos->row['shipping_lastname'], 
			"email" => $infos->row['email'],
			"tel" => $infos->row['telephone'],
			"infos" => ""
		);
                
		// Informations sur la cotation
                $shipping_service_array = explode(' - ',$infos->row['shipping_method']);
                $shipping_service_code = $shipping_service_array[1]; // ex: [service] => ChronoRelais
                  
                $shipping_array = explode('.',$infos->row['shipping_code']);
                $shipping_operator_code = $shipping_array[1]; // ex: [operateur] => CHRP
                $shipping_service_delivery_code = $shipping_array[2]; // ex: [retrait.pointrelais] => CHRP-0421R
                $shipping_depot_pointrelais = $this->config->get($shipping_service_code.'_depot');
                $shipping_collection_type = "";
                $shipping_delivery_type = "";
                
                // Contruction du tableau de produits du panier
                $query = "SELECT product_id, quantity FROM `".DB_PREFIX."order_product` WHERE order_id =".$order_id;
                $product = $this->db->query($query);

                // Initialisation des variables
                $arrayListeProduits = array();
                $arrayListeProduitsMono = array();
                $arrayListeProduitsMulti = array();
                $pid = 1;
                $code_valeur = 0;
                $product_description = '';
                $product_description_tmp = '';
                $product_number = 0;

                // Initialisation de la variable proforma
                $arrayListeProduitsProforma = array();

                // Initialisation des variables multicolis
                $poids_total = 0;
                $poids_total_tmp = 0;
                $longueur_correspondance = 0; 
                $largeur_correspondance = 0;
                $hauteur_correspondance = 0;
                
		// Table de correspondance des dimensions en fonction du poids des articles
                $arrayCorrespondancepoidsdimensions = array();
                for ($i=1; $i<= $this->nb_dim; $i++){
                    $dim_poids = $this->config->get('envoismoinscher_dim_weight_'.$i);
                    if ( $dim_poids != ''){ 
                        array_push($arrayCorrespondancepoidsdimensions, array(
                            'poids' => $this->config->get('envoismoinscher_dim_weight_'.$i),
                            'longueur' => $this->config->get('envoismoinscher_dim_lenght_'.$i),
                            'largeur' => $this->config->get('envoismoinscher_dim_width_'.$i),
                            'hauteur' => $this->config->get('envoismoinscher_dim_height_'.$i)
                        ));
                    }
                }

                foreach($product->rows as $k => $v) {

                   for($p = 1; $p <= $v['quantity']; $p++) {
                                    
                       $product_id = $v['product_id'];
                       
                       $query = "SELECT * FROM `".DB_PREFIX."product` p, `".DB_PREFIX."product_description` d WHERE p.product_id = d.product_id AND p.product_id =".$product_id." AND d.language_id = ".(int)$this->config->get('config_language_id');
                       $product = $this->db->query($query);

                       $product_description = $product->row['name'];
                       $product_description_tmp = $product_description.";".$product_description_tmp;
                       
                       $poids_unite = $product->row['weight_class_id'];
                       $poids_classe = $this->db->query("SELECT * FROM `".DB_PREFIX."weight_class` WHERE weight_class_id =".$poids_unite);
                       $poids_taux = $poids_classe->row['value'];
                       $poids = $product->row['weight']/$poids_taux;
                                
                       // Cas poids non-renseigné : prendre de la poids par défaut
                       if (!$poids)
                           $poids = $this->config->get('envoismoinscher_defaultWeight');
                                    
                       $dimension_unite = $product->row['length_class_id'];
                       $dimension_classe = $this->db->query("SELECT * FROM `".DB_PREFIX."length_class` WHERE length_class_id =".$dimension_unite);
                       $dimension_cm = $this->db->query("SELECT * FROM `".DB_PREFIX."length_class_description` d, `".DB_PREFIX."length_class` c WHERE d.length_class_id = c.length_class_id AND unit = 'cm'");
                       if (isset($dimension_cm->row['value'])){
                           $dimension_cm_taux = $dimension_cm->row['value'];
                       }else{
                           $dimension_cm_taux = 1;
                       }
                       
                       $dimension_taux = $dimension_classe->row['value'];
                       $longueur = $product->row['length']*$dimension_cm_taux/$dimension_taux; 
                       $largeur = $product->row['width']*$dimension_cm_taux/$dimension_taux; 
                       $hauteur = $product->row['height']*$dimension_cm_taux/$dimension_taux;
                       
                       if (!($longueur) || !($largeur) || !($hauteur)) {
                           
                            // Cas Multi-colis : récupération des dimensions depuis la table de correspondance
                            foreach($arrayCorrespondancepoidsdimensions as $u => $d) {

                                if ($poids < $d['poids']) {

                                    $longueur = $d['longueur']; 
                                    $largeur = $d['largeur'];
                                    $hauteur = $d['hauteur'];
                                }
                            }
                       }
                       
                       $prix = $product->row['price'];
                       $code_valeur = $code_valeur+$prix;

                        // Cas Multi-colis : construction du tableau de colis
                        $arrayListeProduitsMulti[$pid] = array(
                            "poids" => $poids, 
                            "longueur" => $longueur, 
                            "largeur" => $largeur,
                            "hauteur" => $hauteur
                        );

                        // Construct Proforma information array
                        $arrayListeProduitsProforma[$pid] = array(
                            "description_en" => $product_description, 
                            "description_fr" => $product_description, 
                            "origine" => $from["pays"], 
                            "nombre" => 1,
                            "valeur" => $prix,
                            "poids" => $poids-0.01
                        );

                        $poids_total_tmp = $poids_total_tmp+$poids;
                        $pid++;
                        $product_number++;
                    }
                }
                        
                // Cas Mono-colis : récupération des dimensions depuis la table de correspondance
                foreach($arrayCorrespondancepoidsdimensions as $k => $v) {

                    if ($poids_total_tmp < $v['poids'] && $poids_total == 0) {

                        $poids_total = $poids_total_tmp;
                        $longueur_correspondance = $v['longueur']; 
                        $largeur_correspondance = $v['largeur'];
                        $hauteur_correspondance = $v['hauteur'];
                    }
                }

                // Cas Mono-colis : construction du tableau de colis
                $arrayListeProduitsMono[1] = array(
                    "poids" => $poids_total, 
                    "longueur" => $longueur_correspondance, 
                    "largeur" => $largeur_correspondance,
                    "hauteur" => $hauteur_correspondance
                );

                if ($this->config->get('envoismoinscher_multicolis')) {
                    $arrayListeProduits = $arrayListeProduitsMulti;
                }else{
                    $arrayListeProduits = $arrayListeProduitsMono;
                }  
                
                // Option Assurance: true uniquement si mode envoi en masse configuré "sans vérification" (envoismoinscher_modeSend == 0)
                if ($this->config->get('envoismoinscher_assurance') == "true" && $this->config->get('envoismoinscher_modeSend') == 0) {
                    $assurance_selected = "true";
                }else{
                    $assurance_selected = "false";
                }
                
                // Paramétrage quotInfo
		$quotInfo = array(
                    
                    "collecte" => date("Y-m-d"), 
                    "delai" => "aucun",  
                    "reference_externe" => $order_id,
                    "code_contenu" => $this->config->get('envoismoinscher_natureSend'),
                    "type_emballage.emballage" => $this->config->get('envoismoinscher_embalSend'),
                    "service" => $shipping_service_code,
                    "operateur" => $shipping_operator_code,
                    "collection_type" => $shipping_collection_type,// "DROPOFF_POINT", "COMPANY",
                    "delivery_type" => $shipping_delivery_type, // "PICKUP_POINT", "HOME",
                    "depot.pointrelais" => $shipping_depot_pointrelais, // "CHRP-0803R",
                    "retrait.pointrelais" => $shipping_service_delivery_code, 
                    "colis.description" => $product_description_tmp,
                    "colis.valeur" => $code_valeur,
                    "disponibilite.HDE" => $this->config->get('envoismoinscher_dispoDeb'), //"09:00", 
                    "disponibilite.HLE" => $this->config->get('envoismoinscher_dispoEnd'), //"19:00",
                    "raison" => "sale", // 'sale' => 'sale', 'repair' => 'repr', 'return' => 'rtrn', 'gift' => 'gift', 'sample' => 'smpl' , 'personnal' => 'prsu', 'document' => 'icdt', 'other' => 'othr'
                    "assurance.selected" => $assurance_selected
		);
                
		$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
		$cotCl->setPerson("expediteur", $from);
		$cotCl->setPerson("destinataire", $to);
		$cotCl->setPlatformParams($this->platform, $this->version_platform, $this->version_lib);
		$cotCl->setEnv($this->config->get('envoismoinscher_environment')); 
		$cotCl->setType("colis", $arrayListeProduits);
                if($to["pays"] != "FR") {
                    $cotCl->setProforma($arrayListeProduitsProforma);
                }
                $json = array();
                
		$orderPassed = $cotCl->makeOrder($quotInfo, true);

                if(!$cotCl->curlError && !$cotCl->respError) {
                
		  if($orderPassed) {
                      
                      $emc_reference = $cotCl->order['ref'];
                      $emc_bordereau = $cotCl->order['labels'][0];
                      
                      $json['success'] = "L'envoi a été correctement réalisé sous la référence : ".$emc_reference;
                      $order_status_id = 3; // Status = 'Shipped'
                      $notify = 0;
                      $comment = $json['success'].".<br>Pour télécharger le bordereau au format PDF, veuillez cliquer sur le lien suivant : ><a href=\"".$emc_bordereau."\">PDF</a><";
                      // Update order status
                      $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int)$order_status_id . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
                      // Insert order EMC reference in comment for the vendor
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (isset($notify) ? (int)$notify : 0) . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
                      
                      $notify = 1;
                      // Insert following order link in comment for the customer
                      $comment = "Votre commande a été expédiée. Pour suivre l'expédition de la commande, veuillez cliquer sur le lien suivant : ><a href=\"http://www.envoimoinscher.com/suivi-colis.html?reference=".$emc_reference."\">suivi de l'expédition</a><";
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (isset($notify) ? (int)$notify : 0) . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
		  }
		  else {

                      $json['error'] = "L'envoi n'a pas été correctement réalisé. Une erreur s'est produite.";
                      $order_status_id = 1; // Status = 'Pending'
                      $notify = 0;
                      $comment = $json['error'];
                      
                      // Insert order EMC reference in comment
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (isset($notify) ? (int)$notify : 0) . "', comment = '" . $this->db->escape(strip_tags($comment)) . "', date_added = NOW()");
		  }
		}
		elseif($cotCl->respError) {

                    $tmp = "La requête n'est pas valide : ";
                  
		  foreach($cotCl->respErrorsList as $m => $message) { 

                      $tmp = $tmp."<br />".$message['message'];
		  }
                  $json['error'] = $tmp;
                      $order_status_id = 1; // Status = 'Pending'
                      $notify = 0;
                      $comment = $json['error'];
                      // Insert order EMC reference in comment
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (isset($notify) ? (int)$notify : 0) . "', comment = '" . $this->db->escape(strip_tags($comment)) . "', date_added = NOW()");
		}
		else {

                    $json['error'] = "<b>Une erreur pendant l'envoi de la requête </b> : ".$cotCl->curlErrorText;
                      $order_status_id = 1; // Status = 'Pending'
                      $notify = 0;
                      $comment = $json['error'];
                      // Insert order EMC reference in comment
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (isset($notify) ? (int)$notify : 0) . "', comment = '" . $this->db->escape(strip_tags($comment)) . "', date_added = NOW()");
		}
		$this->response->setOutput(json_encode($json));
                
            }else{
                echo "Order_id undefined";
            }
	}

// ------------------------
// Vérification des champ vides ou non
// ------------------------		

        private function validate() {
                
                $error_message = "";
            
		if (!$this->user->hasPermission('modify', 'shipping/envoismoinscher')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		if (!$this->request->post['envoismoinscher_login']) {
			$this->error['login'] = $this->language->get('error_login');
		}
		if (!$this->request->post['envoismoinscher_pwd']) {
			$this->error['pwd'] = $this->language->get('error_pwd');
		}
		if (!$this->request->post['envoismoinscher_key']) {
			$this->error['key'] = $this->language->get('error_key');
		}
		if (!$this->request->post['envoismoinscher_environment']) {
			$this->error['environment'] = $this->language->get('error_environment');
		}
		if (!$this->request->post['envoismoinscher_civility']) {
			$this->error['civility'] = $this->language->get('error_civility');
		}
		if (!$this->request->post['envoismoinscher_lastName']) {
			$this->error['lastName'] = $this->language->get('error_lastName');
		}
		if (!$this->request->post['envoismoinscher_firstName']) {
			$this->error['firstName'] = $this->language->get('error_firstName');
		}
		if (!$this->request->post['envoismoinscher_brand']) {
			$this->error['brand'] = $this->language->get('error_brand');
		}
		if (!$this->request->post['envoismoinscher_phone']) {
			$this->error['phone'] = $this->language->get('error_phone');
		}
		if (!$this->request->post['envoismoinscher_adress']) {
			$this->error['adress'] = $this->language->get('error_adress');
		}
		if (!$this->request->post['envoismoinscher_cp']) {
			$this->error['cp'] = $this->language->get('error_cp');
		}
		if (!$this->request->post['envoismoinscher_town']) {
			$this->error['town'] = $this->language->get('error_town');
		}
		if (!$this->request->post['envoismoinscher_mail']) {
			$this->error['mail'] = $this->language->get('error_mail');
		}
		if (!$this->request->post['envoismoinscher_dispoDeb']) {
			$this->error['dispoDeb'] = $this->language->get('error_dispoDeb');
		}
		if (!$this->request->post['envoismoinscher_dispoEnd']) {
			$this->error['dispoEnd'] = $this->language->get('error_dispoEnd');
		}
		if (!$this->request->post['envoismoinscher_typeSend']) {
			$this->error['typeSend'] = $this->language->get('error_typeSend');
		}
		if (!$this->request->post['envoismoinscher_minWeight']) {
			$this->error['minWeight'] = $this->language->get('error_minWeight');
		}
		if (!$this->request->post['envoismoinscher_maxWeight']) {
			$this->error['maxWeight'] = $this->language->get('error_maxWeight');
		}
		if (!$this->request->post['envoismoinscher_natureSend']) {
			$this->error['natureSend'] = $this->language->get('error_natureSend');
		}
                    
		if (!$this->error) {
			return true;
		} else {
			return false;
		}	
	}
}
?>