ÿØÿàJFIF``ÿþxØ Dre4m Was Here
Dre4m Shell
Server IP : 109.234.164.53  /  Your IP : 216.73.216.110
Web Server : Apache
System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64
User : computer3 ( 1098)
PHP Version : 7.1.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/computer3/litsolide.com/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /home/computer3/litsolide.com/cart000000000.php
<?php
//****************************************************************************************//
//************************************* Configuration ************************************//
//****************************************************************************************//

// Chargement fichiers de configuration.
require('libs/Smarty.class.php');

// Demarrage du moteur TPL.
$smarty = new Smarty;

// Chargement des Fonctions Globals.
require('fonctions.php');

/*
echo '<pre>';
echo '<br /><br /><br /><br /><br />';
print_r($_SESSION);
echo '</pre>';	
*/


/* Correctif logo sur email */
if ($emailo >0) { $Mail_Logo = 'logo_email.png'; } else {$Mail_Logo = $Image_Logo ; }



// Ne fait pas apparaitre le panier dans la colonne Right
    $smarty->assign("noCart", '1');


$same_address= $_POST['same_address'];
    $smarty->assign("same", $same_address);

  $txt_discount= $_POST['txt_discount'];
  $txt_discount= $_POST['discount'];  
  if ($txt_discount=='') {  $txt_discount= $_POST['txt_discount']; }
  $smarty->assign("txt_discount", $txt_discount);


  $fidelite_taux= $_POST['fidelite_taux'];
  $fidelite_ttc= $_POST['fidelite_ttc'];

  $bienvenue_taux= $_POST['bienvenue_taux'];
  $bienvenue_ttc= $_POST['bienvenue_ttc'];

if ($bienvenue_taux =='') { $bienvenue_taux =0; }
if ($bienvenue_ttc =='') { $bienvenue_ttc =0; }

if ($fidelite_taux =='') { $fidelite_taux =0; }
if ($fidelite_ttc =='') { $fidelite_ttc =0; }

//////////////////////////////////////////////////////
   
$invoice_firstname = $_POST['invoice_firstname'];	
$invoice_firstname= strtoupper($invoice_firstname);
    $smarty->assign("invoice_firstname", $invoice_firstname);

$invoice_lastname= $_POST['invoice_lastname'];	
$invoice_lastname= strtoupper($invoice_lastname);
    $smarty->assign("invoice_lastname", $invoice_lastname);

$invoice_company= $_POST['invoice_company'];	
$invoice_company= strtoupper($invoice_company);	
    $smarty->assign("invoice_company", $invoice_company);

$invoice_city= $_POST['invoice_city'];	
$invoice_city= strtoupper($invoice_city);	
    $smarty->assign("invoice_city", $invoice_city);
	
$invoice_zip_code= $_POST['invoice_zip_code'];
    $smarty->assign("invoice_zip_code", $invoice_zip_code);
 
$invoice_phone= $_POST['invoice_phone'];
    $smarty->assign("invoice_phone", $invoice_phone);
    
$email= $_POST['email'];
    $smarty->assign("email", $email);
    
$invoice_address1= $_POST['invoice_address1'];
    $smarty->assign("invoice_address1", $invoice_address1);
    
$invoice_address2= $_POST['invoice_address2'];
    $smarty->assign("invoice_address2", $invoice_address2);
        
// recup id pays et retrouve le nom local du pays
$invoice_country = $_POST['invoice_country'];

if(empty($invoice_country)){ $invoice_country = '1'; }

$sqlii = $GLOBALS['bdd']->prepare('SELECT * FROM countries
	WHERE id = :invoice_country');
		$sqlii->execute(array('invoice_country' => $invoice_country));
			$resulti = $sqlii->fetch();
        $invoice_country_name = $resulti['localname'];
        
// Recup code transports colissimo
        $invoice_country_colissimo = $resulti['countries_colissimo'];
        $country_colissimo1 = $resulti['countries_colissimo'];

// Recup code transports chronopost
        $invoice_country_chronopost = $resulti['countries_chronopost'];
        $country_chronopost1 = $resulti['countries_chronopost'];
        
        $smarty->assign("invoice_country_colissimo", $invoice_country_colissimo);
        $smarty->assign("invoice_country_chronopost", $invoice_country_chronopost);

        $smarty->assign("invoice_country", $invoice_country);
        $smarty->assign("invoice_country_name", $invoice_country_name);

        $smarty->assign("country_colissimo1", $country_colissimo1);
        $smarty->assign("country_chronopost1", $country_chronopost1);


//////////////////////////////////////////////////////

$delivery_firstname = $_POST['delivery_firstname'];	
$delivery_firstname= strtoupper($delivery_firstname);
    $smarty->assign("delivery_firstname", $delivery_firstname);

$delivery_lastname= $_POST['delivery_lastname'];	
$delivery_lastname= strtoupper($delivery_lastname);
    $smarty->assign("delivery_lastname", $delivery_lastname);

$delivery_company= $_POST['delivery_company'];	
$delivery_company= strtoupper($delivery_company);	
    $smarty->assign("delivery_company", $delivery_company);

$delivery_city= $_POST['delivery_city'];	
$delivery_city= strtoupper($delivery_city);	
    $smarty->assign("delivery_city", $delivery_city);
	
$delivery_zip_code= $_POST['delivery_zip_code'];
    $smarty->assign("delivery_zip_code", $delivery_zip_code);
 
$delivery_phone= $_POST['delivery_phone'];
    $smarty->assign("delivery_phone", $delivery_phone);
 
$delivery_address1= $_POST['delivery_address1'];
    $smarty->assign("delivery_address1", $delivery_address1);
    
$delivery_address2= $_POST['delivery_address2'];
    $smarty->assign("delivery_address2", $delivery_address2);

// recup id pays et retrouve le nom local du pays


$delivery_country= $_POST['delivery_country'];
if(empty($delivery_country)){ $delivery_country = '1'; }

$sqlv = $GLOBALS['bdd']->prepare('SELECT * FROM countries
	WHERE id = :delivery_country');
		$sqlv->execute(array('delivery_country' => $delivery_country));
			$resultv = $sqlv->fetch();
			
        $delivery_country_name= $resultv['localname'];

/////////////////////////////////////////////////////////////////////

// Recup code transports colissimo
        $delivery_country_colissimo = $resultv['countries_colissimo'];
        $country_colissimo2 = $resultv['countries_colissimo'];

// Recup code transports chronopost
        $delivery_country_chronopost = $resultv['countries_chronopost'];
        $country_chronopost2 = $resultv['countries_chronopost'];
        
        $smarty->assign("delivery_country_colissimo", $delivery_country_colissimo);
        $smarty->assign("delivery_country_chronopost", $delivery_country_chronopost);
 
        $smarty->assign("delivery_country", $delivery_country);
        $smarty->assign("delivery_country_name", $delivery_country_name);

        $smarty->assign("country_colissimo2", $country_colissimo2);
        $smarty->assign("country_chronopost2", $country_chronopost2);

$country_colissimo = $country_colissimo1;
$country_chronopost = $country_chronopost1;

$valid = "1";
if($same_address=='0') {
if ($delivery_firstname == '' || $delivery_lastname == '' || $delivery_phone == '' || $delivery_address1 == '' || $delivery_city == '' || $delivery_zip_code == '') {
$valid = "0";
} else {
$country_colissimo = $country_colissimo2;
$country_chronopost = $country_chronopost2;
 }
}
        $smarty->assign("valid", $valid);
        $smarty->assign("country_colissimo", $country_colissimo);
        $smarty->assign("country_chronopost", $country_chronopost);

//****************************************************************************************//
//********************************* Information de pays **********************************//
//***************************************************************************************//

$sql = $GLOBALS['bdd']->prepare('SELECT * FROM countries
	WHERE status = 1
	ORDER BY localname ASC');
$sql->execute();
$pays = $sql->fetchAll();

  $smarty->assign("pays", $pays);  
  
//****************************************************************************************//
//************************************ css pour mails ************************************//
//****************************************************************************************//
 
   $thema = $GLOBALS['bdd']->query('SELECT * FROM info WHERE id = 1');
    $resulta = $thema->fetchAll();
	$fil = $resulta[0]['fil'] ;
	$tfil = $resulta[0]['tfil'] ;
 
//****************************************************************************************//
//************************************ Recherche cgv. ************************************//
//****************************************************************************************//
  
    $sql = $GLOBALS['bdd']->query('SELECT id, title, seo, content FROM cms 
	WHERE id = 1');
    $result = $sql->fetchAll();
    $smarty->assign("ccgv", $result[0]['content']);

// RGPD
    $sql = $GLOBALS['bdd']->query('SELECT id, title, seo, content FROM cms 
	WHERE id = 4');
    $result = $sql->fetchAll();
    $smarty->assign("confid", $result[0]['content']);
 
//****************************************************************************************//
//************************************ Code promotion ************************************//
//****************************************************************************************//

if(isset($_POST['discount'])) {
  $txt_discount= $_POST['discount'];

	$sql = $GLOBALS['bdd']->prepare('SELECT discount FROM discounts 
	WHERE discount_code = :discount_code AND :now BETWEEN date_start AND date_end');

	$sql->execute(array('discount_code' => $_POST['discount'],
		'now' => date("Y-m-d")));

	if($result = $sql->fetch()) {
		$discount['status'] = "OK";
		$discount['discount'] = $result['discount'];
        $smarty->assign("txt_discount", $txt_discount);

	} else {
		$discount['status'] = "error";
	}
}



//****************************************************************************************//
//************************************** bienvenue ***************************************//
//****************************************************************************************//

if(!empty($_SESSION['custo']['id'])) 
{
	   	  $smarty->assign("bienvenue", "0");
		  $smarty->assign("disc_pourc", "0");
		  $smarty->assign("disc_num", "0");

$nb_cde = 0;
$cptc = 0;



// Recherche si c est la 1ere cde du client
/*
	$sql = $GLOBALS['bdd']->prepare('SELECT customer FROM orders
		WHERE customer = :sSid ORDER BY id LIMIT 1');
	$sql->execute(array('sSid' => $_SESSION['custo']['id']));
	
     $columns = $sql->fetchAll();
     foreach ($columns as $col) {
     $cptc = $cptc + 1 ;
      }
    $nb_cde = $cptc;   
    $smarty->assign('nb_cde', $nb_cde);
*/     

/*************************************************************************************/
// Correction pour remise bienvenue si deja commandes mais annulees accorde la remise
/************************************************************************************/


	$sql = $GLOBALS['bdd']->prepare('SELECT o.*, os.status FROM orders o
        RIGHT JOIN order_status os
        ON os.id_order = o.id

		WHERE customer = :sSid 
        AND os.date_status = (SELECT MAX(date_status) FROM order_status
                                WHERE id_order = o.id)

ORDER BY o.id ASC');
	$sql->execute(array('sSid' => $_SESSION['custo']['id']));
	
     $columns = $sql->fetchAll();
     foreach ($columns as $col) {


if ($col['status'] <3) { 
     $cptc = $cptc + 1 ;
}

/*
echo"<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />-----------------------> id cde ".$col['id']."   status ".$col['status']." cpt ".$cptc;
echo"<br />";
*/
      }
    $nb_cde = $cptc;   
    $smarty->assign('nb_cde', $nb_cde);
 
/************************************************************************************/
/************************************************************************************/



if ($nb_cde < 1) {

// Fait la remise de bienvenue
/*****************************/
	// premiere remise dans la liste
	$sql = $GLOBALS['bdd']->prepare('SELECT * FROM bienvenue WHERE  :now BETWEEN date_start AND date_end 
           ORDER BY id LIMIT 1');
	       $sql->execute(array('now' => date("Y-m-d")));
		
		$resulta = $sql->fetch();  
        $disc_num = $resulta['discount'];
        $disc_pourc = $resulta['discount_pourcent'];
     }
  }
























//****************************************************************************************//
//************************************** fidelite ***************************************//
//****************************************************************************************//

if(!empty($_SESSION['custo']['id'])) 
{
	   	  $smarty->assign("fidelite", "0");
		  $smarty->assign("fidelite_pourc", "0");
		  $smarty->assign("fidelite_num", "0");

// Recherche si c est ok
if ($act_fidel >0){

if ($_SESSION['custo']['points'] >= $Ftot_cumul) { 
	if ($Fremise > 0) {
        $fidelite_num = "0";
        $fidelite_pourc = $Fremise;
  }

}
}
}




//****************************************************************************************//
//************************************* Vider le panier **********************************//
//****************************************************************************************//

if(isset($_POST['empty'])) {
	unset($_SESSION['cart']);

		$sql = $GLOBALS['bdd']->prepare('DELETE FROM cart_attributes_values 
		WHERE session = :session');
		$sql->execute(array('session' => $session));



//****************************************************************************************//
//********************************* Panier avec Groupage *********************************//
//****************************************************************************************//

if ($act_agp >0) { 
		// efface les session_group bdd 
		$bdd->exec("DELETE FROM " . $GLOBALS['db_table']['session_group'] . " WHERE session= '".$session."'");
}
//****************************************************************************************//

}













//****************************************************************************************//
//**************************************** Panier ****************************************//
//****************************************************************************************//

$products = array();
$carriers = array();
$total_ecoprix = 0;
$total = 0;
$weight = 0;
$stool = 0;
$tva_0 = 0;
$tva_1 = 0;
$tva_2 = 0;
$tva_3 = 0;
$discTotal = 0;
$nodiscTotal = 0;
$code_cumul = 0;
$code_bienvenue = 0;
$code_fidelite = 0;
$price=0;
$base_PROMO=0;
 

if(is_array($_SESSION['cart'])) {

		foreach ($_SESSION['cart'] as $num => $product) {	

//****************************************************************************************//
//********************************* Panier avec Groupage *********************************//
//****************************************************************************************//
if ($act_agp >0) { 

// repere dans la bdd si plusieur article idem pour le prix par lot

                                $tott =0;
								$requete2= $GLOBALS['bdd']->prepare('SELECT nombre FROM session_group WHERE session = :session AND product = :product ORDER BY product');
							    $requete2->execute(array('session' => $session,'product' => $product[0]['product']));
							      if ($row2 = $requete2->fetch()) {
							        do {

							   $tott = $tott + $row2['nombre'];
																			
							        }while ($row2 = $requete2->fetch());
							      } else {
							        echo 'Vide2 !!!';
							      }

//****************************************************************************************//
}












		foreach ($product[0] as $key => $value) {
		
			if ($key != 'product' && $key != 'quantity' && $key != 'Observ') {
				if(substr($value,0,1) == "#" || substr($value,0,3) == "rgb"){
					$value = '<div style="display: inline; padding-right: 16px; border: 1px solid black; background-color: ' . $value . ';"></div>';
				}


if ($gesto > 0) { 
				
				// Refait la presentation de la ligne
// nom attribut 
 $array_attrib=  explode('>', $value);
 $attrib1 = $array_attrib[0];
 $attrib2 = $array_attrib[1];
 $attrib3 = $array_attrib[2];   
 $array_attrib1=  explode(' : ', $attrib1);
 $attrib11 = $array_attrib1[0];
 $attrib12 = $array_attrib1[1];
 $attrib13 = $array_attrib1[2]; 
   
				$products[$num]['attribute'][$key] = $attrib11;
} else {
				$products[$num]['attribute'][$key] = $value;
}
			}
		}






		$sql = $GLOBALS['bdd']->prepare('SELECT seo, reference, date_dispo, ecoprix, stock, name, price, weight, discount, cle_tva FROM products 
		WHERE id = :id');
		$sql->execute(array('id' => $product[0]['product']));
		$result = $sql->fetch();
        $id_produit = $product[0]['product'];



//****************************************************************************************//
//********************************* Panier avec Groupage *********************************//
//****************************************************************************************//
if ($act_agp >0) { 


// Si groupage existant pour cet article prix par attribut unique
/***********************************************************/
$sql23 = $GLOBALS['bdd']->prepare('SELECT *, MIN(prix) AS pprix FROM lot_list 
WHERE nombre <= :quantitee AND id_produit = :id_produit ORDER BY nombre ASC LIMIT 1');
$sql23->execute(array('id_produit' => $product[0]['product'], 'quantitee' => $tott));
$result23 = $sql23->fetch();
$tarif_lot = $result23['pprix']; 


if ($tarif_lot >0){  
$result['price']= $tarif_lot;

} else {
$result['price'] = $result['price'];
}

/***********************************************************/

}
















// Si Pro. existant
/**********************************/

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){

if ($_SESSION['custo']['remise_pro'] >0){
$pro_remise = (100 - $_SESSION['custo']['remise_pro'])  / 100;
$result['price'] = $result['price'] * $pro_remise;    
}

          if ($result['cle_tva'] =='0') { $result['price'] = $result['price']; }
          if ($result['cle_tva'] =='1') { $result['price'] = $result['price'] / $ht__1; }
          if ($result['cle_tva'] =='2') { $result['price'] = $result['price'] / $ht__2; }
          if ($result['cle_tva'] =='3') { $result['price'] = $result['price'] / $ht__3; }
}




//****************************************************************************************//
//********************************* Panier sans Groupage *********************************//
//****************************************************************************************//

if ($act_agp <1) { 
if ($act_lot >0) {

// Si lot existant pour cet article
/**********************************/
		$sql23 = $GLOBALS['bdd']->prepare('SELECT *, MIN(prix) AS pprix FROM lot_list 
		WHERE nombre <= :quantitee AND id_produit = :id_produit ORDER BY nombre ASC LIMIT 1');
		$sql23->execute(array('id_produit' => $product[0]['product'], 'quantitee' => $product[0]['quantity']));
		$result23 = $sql23->fetch();
        $tarif = $result23['pprix']; 

if(empty($tarif )) { $result['price'] = $result['price'] ; 

} else { 

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){

if ($_SESSION['custo']['remise_pro'] >0){
$pro_remise = (100 - $_SESSION['custo']['remise_pro'])  / 100;
$tarif = $tarif * $pro_remise;    
}
          if ($result['cle_tva'] =='0') { $tarif = $tarif; }
          if ($result['cle_tva'] =='1') { $tarif = $tarif / $ht__1; }
          if ($result['cle_tva'] =='2') { $tarif = $tarif / $ht__2; }
          if ($result['cle_tva'] =='3') { $tarif = $tarif / $ht__3; }
}
$result['price'] = $tarif;
}

} else { 
$result['price'] = $result['price'] ;

}

/**********************************/
}
 







	    $price = $product[0]['quantity'] * ($result['price'] * (1 - $result['discount'] / 100));

		$products[$num]['name'] = substr($result['name'], 0, 65);
		$products[$num]['id'] = $product[0]['product'];
		$products[$num]['seo'] = $result['seo'];
		$products[$num]['stock'] = $result['stock'];
		$products[$num]['reference'] = $result['reference'];
		$products[$num]['discount'] = $result['discount'];
		$products[$num]['quantity'] = $product[0]['quantity'];
		$products[$num]['price'] = $result['price'] * (1 - $result['discount'] / 100);
		$products[$num]['total'] = $price;
		$price_base = $price;
		$products[$num]['date_dispo'] = $result['date_dispo'];













////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////                 PROMOS               ///////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////


// Pour calcul total de la ligne price
/*************************************/
	$price = $price; 
	$price2 = $price;
	$price3 = $price; 
	$price5 = $price; 

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){



          if ($result['cle_tva'] =='0') { $tva_0c = 0; }
          if ($result['cle_tva'] =='1') { $coef_1c = $T_1_valeur / 100;  $tva_1c =  $price * $coef_1c; }
          if ($result['cle_tva'] =='2') { $coef_2c = $T_2_valeur / 100;  $tva_2c =  $price * $coef_2c; }
          if ($result['cle_tva'] =='3') { $coef_3c = $T_3_valeur / 100;  $tva_3c =  $price * $coef_3c; }



 $base_PROMO= $price + $tva_1c + $tva_2c + $tva_3c ;

 $smarty->assign("base_PROMO", $base_PROMO);

} else {
 $base_PROMO = $price ;
}





////////////////////////////////////////////////
//Code Promo
///////////////////////////////////////////////

if($discount['status'] == "OK") {





	$remise_s_total	= $discount['discount'] * $base_PROMO / 100;
	$base_PROMO = $base_PROMO - $remise_s_total;
	$lecode_promo = $lecode_promo + $remise_s_total ;

 



}


////////////////////////////////////////////////
//Bienvenue
///////////////////////////////////////////////
 
if(!empty($_SESSION['custo']['id'])) 
{
if ($nb_cde < 1) {

	if ($disc_pourc > 0) {
		  $smarty->assign("bienvenue", "1");
		  $smarty->assign("disc_pourc", $disc_pourc);

	$remise_s_total	= $disc_pourc * $base_PROMO / 100;
	$base_PROMO = $base_PROMO - $remise_s_total;
	$code_bienvenue = $code_bienvenue + $remise_s_total ;

 

	   }
	 }     
}




////////////////////////////////////////////////
//fidelite
///////////////////////////////////////////////

if(!empty($_SESSION['custo']['id'])) 
{
if ($act_fidel >0){

if ($_SESSION['custo']['points'] >= $Ftot_cumul) { 
	if ($Fremise > 0) {
		  $smarty->assign("fidelite", "1");
		  $smarty->assign("fidelite_pourc", $Fremise);
		  
	$remise_s_total	= $Fremise * $base_PROMO/ 100;
	$base_PROMO = $base_PROMO - $remise_s_total;
	$code_fidelite = $code_fidelite + $remise_s_total ;

 

	   }
	 }     
}
}




////////////////////////////////////////////////////

		switch ($result['cle_tva']) {
			case 0:
if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){
				$tva_0b += $price3 * 0;
				$tva_0 += $price * 0;
} else {
				$tva_0 += $price5 * 0;
}
				break;



			case 1:
			    $coef1_2 = $T_1_valeur / 100; $coef1 = $coef1_2 + 1; 

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){
				$tva_1b +=  $price3 * $coef1_2;
				$tva_1 +=  $price * $coef1_2;

} else {
				$tva_1 += ($base_PROMO / $coef1) * $coef1_2;
}
				break;



			case 2:
			    $coef2_2 = $T_2_valeur / 100; $coef2 = $coef2_2 + 1; 

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){
				$tva_2b += $price3 * $coef2_2;
				$tva_2 += $price * $coef2_2;
} else {
				$tva_2 += ($base_PROMO  / $coef2) * $coef2_2;
}
				break;


			case 3:
			    $coef3_2 = $T_3_valeur / 100; $coef3 = $coef3_2 + 1; 

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){
				$tva_3b += $price3 * $coef3_2;
				$tva_3 += $price * $coef3_2;
} else {
				$tva_3 += ($base_PROMO / $coef3) * $coef3_2;
}
				break;
		}



		$total_ecoprix += $result['ecoprix'] * $product[0]['quantity'];
		$weight += $result['weight'] * $product[0]['quantity'];
		$total += $price;
 
 

	}
	

























////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Si vide on lui attribut le ID 1000
    $carrierChoix = $_POST['carrierChoix'];

	if(empty($carrierChoix)) {
		$sql = $GLOBALS['bdd']->prepare('SELECT c.id, c.name, c.picture, MIN(pl.price) AS price FROM carrier c 
		INNER JOIN price_list pl 
		ON c.id = pl.id_carrier 
		WHERE c.status = 1 AND pl.weight >= :weight AND (class1 = :class1 OR class2 = :class2)  
		GROUP BY c.id ');
		$sql->execute(array('weight' => $weight,
		                    'class1' => $country_colissimo,
		                    'class2' => $country_chronopost
		
		));
		
		$result = $sql->fetchAll();
		if(count($result) != 0) {
			$carriers[] = $result;
			sort($carriers[0]);
		}
			$carri = '1000';
		    $smarty->assign("carrierChoix", $carri);
	}

//////////////////////////////////////////////////////

// Si pas vide
// "lex" est la cl?dans la bdd pour enlevement au magasin (ID:2), pour france et etranger...

    $carrierChoix = $_POST['carrierChoix'];
	if(!empty($carrierChoix)) {
		$sql = $GLOBALS['bdd']->prepare('SELECT c.id, c.name, c.picture, MIN(pl.price) AS price FROM carrier c 
		INNER JOIN price_list pl 
		ON c.id = pl.id_carrier 
		WHERE c.status = 1 AND pl.weight >= :weight AND (class1 = :class1 OR class2 = :class2 OR class1 = :lex)  
		GROUP BY c.id ');
		
		$sql->execute(array('weight' => $weight,
		                    'class1' => $country_colissimo,
		                    'class2' => $country_chronopost,
		                    'lex' => 'X'
		
		));
		
		$result = $sql->fetchAll();
		if(count($result) != 0) {
			$carriers[] = $result;
			sort($carriers[0]);
		}
	}
}
		$smarty->assign("carrierChoix", $carrierChoix);

///////////////////////////////////////////////////////////////

     $carrierChoixA = $_POST['carrierChoixA'];
     $smarty->assign("carrierChoixA", $carrierChoixA);
 
     $carrierChoix = $_POST['carrierChoix'];


     $carrier_id = $_POST['carrieride'];

// $carrierChoix ==2 ==> enlebvement ?domicile
if ($carrierChoix =='2'){$carrier_id = $carrierChoix; }



// Trouve le nom du transporteur d apres le ID et la tva sur transport
    if($carrierChoix > 900){ $carrierChoix = $carrierChoixA ; }
        $sqla = $GLOBALS['bdd']->prepare('SELECT name, tva FROM carrier 
		WHERE id = :idop');
		$sqla->execute(array('idop' => $carrier_id));
		$resultaa = $sqla->fetch();
        $carrierNam = $resultaa['name'];
        $carrierTva = $resultaa['tva'];


//Fin Carriers ................................................ 























////////////////////////////////////////////////////

// echo '<pre>';
 // var_dump($carriers[0]);
// echo '</pre>';

	$smarty->assign("ssTotal", $total);
    $smarty->assign("discount", $discount);
    $smarty->assign("products", $products);
    $smarty->assign("carriers", $carriers[0]);
    $smarty->assign("tva_0", $tva_0);
    $smarty->assign("tva_1", $tva_1);
    $smarty->assign("tva_2", $tva_2);
    $smarty->assign("tva_3", $tva_3);
    $smarty->assign("tva_0b", $tva_0b);
    $smarty->assign("tva_1b", $tva_1b);
    $smarty->assign("tva_2b", $tva_2b);
    $smarty->assign("tva_3b", $tva_3b);

	$smarty->assign("code_fidelite", $code_fidelite);
	$smarty->assign("code_bienvenue", $code_bienvenue);  
    $smarty->assign("txt_discount", $txt_discount);  	
	$smarty->assign("lecode_promo", $lecode_promo);  


 



//****************************************************************************************//
//************************************ Adresses client ***********************************//
//****************************************************************************************//

if(!empty($_SESSION['custo']['id'])) 
{
	// Information de facturation
	$sql = $GLOBALS['bdd']->prepare('SELECT c.id_invoice_address, c.id_delivery_address, a.* FROM customers c
		INNER JOIN address a
		ON a.id = c.id_invoice_address
		WHERE c.id = :id');
	$sql->execute(array('id' => $_SESSION['custo']['id']));
	$invoice = $sql->fetch();
	  $smarty->assign("invoice", $invoice);

	// Information de livraison
	$sql = $GLOBALS['bdd']->prepare('SELECT c.id_delivery_address, a.* FROM customers c
		INNER JOIN address a
		ON a.id = c.id_delivery_address
		WHERE c.id = :id');

	$sql->execute(array('id' => $_SESSION['custo']['id']));
	$delivery = $sql->fetch();
	  $smarty->assign("delivery", $delivery);
}



//****************************************************************************************//
//************************************* Enregistrements **********************************//
//****************************************************************************************//


if (!empty($_POST['invoice_lastname'])) {

if(isset($_POST['submit'])) {
	// Enregistrement des adresses
	if(!isset($_SESSION['custo']['id'])) 
	{
		$sql = $GLOBALS['bdd']->prepare('INSERT INTO address (firstname, lastname, company, phone, address1, address2, city, zip_code, id_country, country) VALUES
			(:firstname, :lastname, :company, :phone, :address1, :address2, :city, :zip_code, :id_country, :country)');

	    $sql->execute(array('firstname' => $invoice_firstname,
					    	'lastname' => $invoice_lastname,
						    'company' => $invoice_company,
						    'phone' => $_POST['invoice_phone'],
						    'address1' => $_POST['invoice_address1'],
						    'address2' => $_POST['invoice_address2'],
						    'city' => $invoice_city,
					    	'zip_code' => $_POST['invoice_zip_code'],
						    'country' => $invoice_country_name,
						    'id_country' => $invoice_country));
						    
 
		$invoice['id_invoice_address'] = $GLOBALS['bdd']->lastInsertId();
		if($_POST['same_address'] == '0') 
		{
		
					$sql->execute(array('firstname' => $delivery_firstname,
								'lastname' => $delivery_lastname,
								'company' => $delivery_company,
								'phone' => $_POST['delivery_phone'],
								'address1' => $_POST['delivery_address1'],
								'address2' => $_POST['delivery_address2'],
								'city' => $delivery_city,
								'zip_code' => $_POST['delivery_zip_code'],
						        'id_country' => $delivery_country,
								'country' => $delivery_country_name));
		}

		$delivery['id_delivery_address'] = $GLOBALS['bdd']->lastInsertId();

// Newsletter commande rapide
  $newsletter_ok = ($_POST['newslet'] == 'on') ? 1 : 0;

if ($newsletter_ok > 0) { 
// V?ification si l'exp?iteur est pr?ent dans la base de donn?s Newsletter
	$sql = $GLOBALS['bdd']->prepare('SELECT * FROM fe_mail_user WHERE email = :email');

	$sql->execute(array('email' => $_POST['email']));
	$result = $sql->fetch();
	
	// Si non pr?ent, ?l'ajoute.
	if($result['email'] !== $_POST['email'])
	{
		$unsubscribe_code = substr(md5(trim($_POST['name']).trim($_POST['email'])), 0, 7);
		$sql = $GLOBALS['bdd']->prepare('INSERT INTO fe_mail_user (insert_date, id_user, id_cat, name, email, unsubscribe_code, time_unsubscribe, ip_unsubscribe, status) VALUES (:insert_date, :id_user, :id_cat, :name, :email, :unsubscribe_code, :time_unsubscribe, :ip_unsubscribe, :status)');
		$sql->execute(array('insert_date' => time(),
							'id_user' => '3',
							'id_cat' => '3',
							'name' =>  $_POST['invoice_firstname'],
							'email' => $_POST['email'],
							'unsubscribe_code' => $unsubscribe_code, 
							'time_unsubscribe' => '0',
							'ip_unsubscribe' => '0', 
							'status' => '0'));
	}
	else
	{
   }
 }		




 }


// Total frais de transport
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	

   if (is_numeric($_POST['discount_amount'])) { 
   $tt_remise_disc = $_POST['discount_amount'];
   }

   $tt_remise = $bienvenue_ttc + $fidelite_ttc;
   $total_remises = $tt_remise_disc + $tt_remise;

//   $totalbrut = $_POST['sub_total'] - $total_remises;
   
   $frais_transp = $_POST['ppprice'] ;	

// Si plusieurs remises il se peut que le total soit inferieur au sub_total donc frais de liv mini = 0 
  if ($frais_transp <= '0') { $frais_transp ='0'; }


////////////////////////////////////////////////////////////////////////////////////////////////////////////	

    $codeSuivi = substr(md5(time().trim($_POST['invoice_lastname']).trim($_POST['email'])), 0, 7);

////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////////////////////////////////////////////////////////////////////////////////////	


// Enregistrement de la commande
/*******************************/
$frais_transp22 = $frais_transp;

 

if ($txt_discount ==''){$txt_discount =' ';}


	
if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){

$lesub_total = $_POST['total'] - $frais_transp;






	$sql = $GLOBALS['bdd']->prepare('INSERT INTO orders(total_ecoprix, date_insere, id_order, payment, customer, email, invoice_address, delivery_address, sub_total, carrier, carrier_price, px_transport, discount, txt_discount,  bienvenue_taux, bienvenue_ttc,  fidelite_taux, fidelite_ttc, txt_tva0, txt_tva1, txt_tva2, txt_tva3, tva_0, tva_1, tva_2, tva_3, total)
		VALUES (:total_ecoprix, :date_insere, :id_order, :payment, :customer, :email, :invoice_address, :delivery_address, :sub_total, :carrier, :carrier_price, :px_transport, :discount, :txt_discount, :bienvenue_taux, :bienvenue_ttc, :fidelite_taux, :fidelite_ttc, :txt_tva0, :txt_tva1, :txt_tva2, :txt_tva3, :tva_0, :tva_1, :tva_2, :tva_3, :total)');
 
	$sql->execute(array('date_insere' => date('Y-m-d'),
						'id_order' => $codeSuivi,
						'payment' => $_POST['payment'],
						'customer' => (isset($_SESSION['custo']['id']) ? $_SESSION['custo']['id'] : 0),
						'email' => $_POST['email'],
						'invoice_address' => $invoice['id_invoice_address'],
						'delivery_address' => ($_POST['same_address'] == '0' ? $delivery['id_delivery_address'] : $invoice['id_invoice_address']),

						'sub_total' => $lesub_total,
						'discount' => (isset($_POST['discount_amount']) ? $_POST['discount_amount'] : 0),


						'carrier' => $carrierNam,
						'carrier_price' => $carrierTva,
						'txt_discount' => $txt_discount,
						'bienvenue_taux' => $bienvenue_taux,
						'bienvenue_ttc' => $bienvenue_ttc,
						'fidelite_taux' => $fidelite_taux,
						'fidelite_ttc' => $fidelite_ttc,
						'px_transport' => $frais_transp22,
						'total_ecoprix' => $total_ecoprix,

						'txt_tva0' => $T_0_text,
						'txt_tva1' => $T_1_text,
						'txt_tva2' => $T_2_text,
						'txt_tva3' => $T_3_text,						

						'tva_0' => (isset($_POST['tva_0']) ? $_POST['tva_0'] : 0),
						'tva_1' => (isset($_POST['tva_1']) ? $_POST['tva_1'] : 0),
						'tva_2' => (isset($_POST['tva_2']) ? $_POST['tva_2'] : 0),
						'tva_3' => (isset($_POST['tva_3']) ? $_POST['tva_3'] : 0),
						'total' => $_POST['total']));

} else {

	
	$sql = $GLOBALS['bdd']->prepare('INSERT INTO orders(total_ecoprix, date_insere, id_order, payment, customer, email, invoice_address, delivery_address, sub_total, carrier, carrier_price, px_transport, discount, txt_discount,  bienvenue_taux, bienvenue_ttc,  fidelite_taux, fidelite_ttc, txt_tva0, txt_tva1, txt_tva2, txt_tva3, tva_0, tva_1, tva_2, tva_3, total)
		VALUES (:total_ecoprix, :date_insere, :id_order, :payment, :customer, :email, :invoice_address, :delivery_address, :sub_total, :carrier, :carrier_price, :px_transport, :discount, :txt_discount, :bienvenue_taux, :bienvenue_ttc, :fidelite_taux, :fidelite_ttc, :txt_tva0, :txt_tva1, :txt_tva2, :txt_tva3, :tva_0, :tva_1, :tva_2, :tva_3, :total)');
 
	$sql->execute(array('date_insere' => date('Y-m-d'),
						'id_order' => $codeSuivi,
						'payment' => $_POST['payment'],
						'customer' => (isset($_SESSION['custo']['id']) ? $_SESSION['custo']['id'] : 0),
						'email' => $_POST['email'],
						'invoice_address' => $invoice['id_invoice_address'],
						'delivery_address' => ($_POST['same_address'] == '0' ? $delivery['id_delivery_address'] : $invoice['id_invoice_address']),
						'sub_total' => $_POST['sub_total'],
						'carrier' => $carrierNam,
						'carrier_price' => $carrierTva,
						'discount' => (isset($_POST['discount_amount']) ? $_POST['discount_amount'] : 0),
						'txt_discount' => $txt_discount,
						'bienvenue_taux' => $bienvenue_taux,
						'bienvenue_ttc' => $bienvenue_ttc,

						'fidelite_taux' => $fidelite_taux,
						'fidelite_ttc' => $fidelite_ttc,
						'px_transport' => $frais_transp,
						'total_ecoprix' => $total_ecoprix,

						'txt_tva0' => $T_0_text,
						'txt_tva1' => $T_1_text,
						'txt_tva2' => $T_2_text,
						'txt_tva3' => $T_3_text,						

						'tva_0' => (isset($_POST['tva_0']) ? $_POST['tva_0'] : 0),
						'tva_1' => (isset($_POST['tva_1']) ? $_POST['tva_1'] : 0),
						'tva_2' => (isset($_POST['tva_2']) ? $_POST['tva_2'] : 0),
						'tva_3' => (isset($_POST['tva_3']) ? $_POST['tva_3'] : 0),
						'total' => $_POST['total']));
}






	$id_order = $GLOBALS['bdd']->lastInsertId();
    $totalCde = $_POST['total'];

	// Enregistrement du statut de la commande
	$sql = $GLOBALS['bdd']->prepare('INSERT INTO order_status(id_order, date_status, status)
		VALUES (:order, :date_status, :status)');

	$sql->execute(array('order' => $id_order,
						'date_status' => date('Y-m-d H:i:s'),
						'status' => 0));



////////////////////////////////////////////////////////////////////////////////////////////////////////////	

	// Enregistrement des produits du panier
    /**************************************/

	if(is_array($_SESSION['cart'])) {
	
		$recap = '<table style="width:100%;background:#fff;color:#000;font-size:10pt;font-weight:bold;border:1px solid #ccc" cellspacing="1">
	<tr>
		<td align="center" style="background:#ccc;border:1px solid #ccc">Produit(s)</td>
		<td align="center" style="background:#ccc;border:1px solid #ccc" width="10%">Quantit&eacute;</td>

		<td align="center" style="background:#ccc;border:1px solid #ccc" width="14%">Prix Unit TTC</td>
		<td align="center" style="background:#ccc;border:1px solid #ccc" width="14%">Total  TTC</td>
	</tr>

';




		$insertOrdersProducts = $GLOBALS['bdd']->prepare('INSERT INTO orders_products(id_order, id_product, attributes, discount, price, quantity, observations,date_dispo)
		VALUES (:id_order, :id_product, :attributes, :discount, :price, :quantity, :observations, :date_dispo)');

//////////////////////////////////////////////////////////////////
////// Si ATTRIBUTS
/*
On recupere les donnees de la session : 
1- le libell?pour l'affichage du panier et enregistrement de l attribut dans cde
2- les IDs value de l attribut pour le decompte stock par attribut
3- les stocks dispos des valeurs
4- Id product =$id_product
*/
/////////////////////////////////////////////////////////////////


		foreach ($_SESSION['cart'] as $num => $product) {
			$attributes = '';
			$obs_art= '';
			$avec_attribut = 0;
			foreach ($product[0] as $key => $value) {

 
// observations article
if ($key == 'Observ') {
// 3 - Reprend les infos
		 $obs_art = $value; // valeur de l observation
}	
 

 
if ($gesto > 0) { 
if ($key != 'product' && $key != 'quantity' && $key != 'Dispo' && $key != 'Observ') {

// 1 - Trouve le libelle de la valeur pour l affichage et l email confirmation
 $array_attrib=  explode('>', $value);
 $attrib1 = $array_attrib[0];
 $attrib2 = $array_attrib[1];
 $attrib3 = $array_attrib[2];   
	 $attributes .= $attrib1; // Libell?OK
	
// 1 1 - Trouve le ID de la valeur : Tail40 bleu vert>N.10>Stock:4 
 $array_attrib=  explode('>', $value);
 $attrib1 = $array_attrib[0];
 $attrib2 = $array_attrib[1];
 $attrib3 = $array_attrib[2];   
 $attrib2= str_replace("N.", "", $attrib2);
	$id_valeur = $attrib2; // ID Value OK

if (!empty($attributes)) { $avec_attribut = 1; } 
}
	

if ($key == 'Dispo') {
// 2 - Reprend pour le stock dispo pour decompte
		 $stock_dispo = $value; // Dispo OK
}	
				



} else {
// Si pas stock actif
		 if ($key != 'product' && $key != 'quantity' && $key != 'Dispo' && $key != 'Observ') {
		 $attributes .= $key . ' : ' . $value . ', ';
     }	
  }	
}		                                           	
			$sql = $GLOBALS['bdd']->prepare('SELECT reference, date_dispo, name, price, discount, stock FROM products 
			WHERE id = :id');
			$sql->execute(array('id' => $product[0]['product']));
				$result = $sql->fetch();
                $stock_prod = $result['stock'];
                
			$id_product = $product[0]['product'];
			$discount = $result['discount'];
			$quantity = $product[0]['quantity'];

// Si lot existant pour cet article
/**********************************/
		$sql23 = $GLOBALS['bdd']->prepare('SELECT *, MIN(prix) AS pprix FROM lot_list 
		WHERE nombre <= :quantitee AND id_produit = :id_produit ORDER BY nombre ASC LIMIT 1');
		$sql23->execute(array('id_produit' => $product[0]['product'], 'quantitee' => $product[0]['quantity']));
		$result23 = $sql23->fetch();
         $tarif = $result23['pprix']; 

if(empty($tarif )) { 

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){
if ($_SESSION['custo']['remise_pro'] >0){
$pro_remise = (100 - $_SESSION['custo']['remise_pro'])  / 100;
$result['price'] = $result['price'] * $pro_remise;    
 }
} else {
$result['price'] = $result['price'] ; 
}







} else { 

if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){

if ($_SESSION['custo']['remise_pro'] >0){
$pro_remise = (100 - $_SESSION['custo']['remise_pro'])  / 100;
$tarif = $tarif * $pro_remise;    
}

/*
          if ($result['cle_tva'] =='0') { $tarif = $tarif; }
          if ($result['cle_tva'] =='1') { $tarif = $tarif / $ht__1; }
          if ($result['cle_tva'] =='2') { $tarif = $tarif / $ht__2; }
          if ($result['cle_tva'] =='3') { $tarif = $tarif / $ht__3; }
*/
}

$result['price'] = $tarif;

}
/**********************************/


			$price = $result['price'] * (1 - $result['discount'] / 100);


			$insertOrdersProducts->execute(array(	'id_order' => $id_order,
													'id_product' => $id_product,
													'attributes' => $attributes,
													'discount' => $discount,
													'price' => $price,
													'quantity' => $quantity,
													'date_dispo' => $result['date_dispo'],
													'observations' => $obs_art));

													
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

if ($gesto > 0) {

// Si stock et attribut unique
if ($avec_attribut > 0) {

$new_stock = $stock_dispo - $quantity;

// Met a jour le stock attribut dans products_attributes_values
    $qid = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products_attributes_values'] . " 
    SET stock = :stock WHERE id_product = :id_product AND id_value = :id_value ");
    $qid->execute(array(  'stock' => $new_stock,
                        'id_product' => $id_product,
                        'id_value' => $id_valeur));

// Met a jour le stock dans products
  $new_stock_product = $stock_prod - $quantity;
  
$ishstock_fin ='';
if ($new_stock_product< 1) { $ishstock_fin ='1';  } else { $ishstock_fin ='0';  }

    $qid = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products'] . " 
    SET stock = :stock, hstock= :hstock WHERE id= :id");
    $qid->execute(array(  'stock' => $new_stock_product,
                          'hstock' => $ishstock_fin,    
                          'id' => $id_product));




if ($caisse_ok >0) { 
///////////////// 
// MISE A JOUR SUR LA CAISSE SI ATTRIBUTS

$num_attribut = '_'.$id_valeur;
// Trouve le id du produit caisse d apres la reference du produit site

			$sqlr = $GLOBALS_0['bdd']->prepare('SELECT id FROM products 
			WHERE id_product = :id_product AND num_attribut = :num_attribut');
			$sqlr->execute(array(
			
			'id_product' => $id_product,
			'num_attribut' => $num_attribut
			));
				$resultr = $sqlr->fetch();
                $id_caisse_stock = $resultr['id'];
                
// modifie stock sur la caisse principale

    $qid = $GLOBALS_1['bdd']->prepare("UPDATE " . $GLOBALS_1['db_table'][TABLE_STOCK] . " 
    SET stock = :stock WHERE id_product = :id_product");
    $qid->execute(array(  'stock' => $new_stock,
                          'id_product' => $id_caisse_stock));
                          
/////////////////
}

}





///////////////////////////////////////////////////

else {

// Met a jour le stock dans products
  $new_stock_product = $stock_prod - $quantity;
  
$ishstock_fin ='';
if ($new_stock_product< 1) { $ishstock_fin ='1';  } else { $ishstock_fin ='0';  }

    $qid = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products'] . " 
    SET stock = :stock, hstock= :hstock WHERE id= :id");
    $qid->execute(array(  'stock' => $new_stock_product,
                          'hstock' => $ishstock_fin,    
                          'id' => $id_product));



if ($caisse_ok >0) { 
///////////////// 
// MISE A JOUR SUR LA CAISSE 

// Trouve le ID product caisse d'apres le ID produit du site
			$sqlr = $GLOBALS_0['bdd']->prepare('SELECT id FROM products 
			WHERE id_product = :id_product');
			$sqlr->execute(array(
			'id_product' => $id_product));
				$resultat = $sqlr->fetch();
                $id_caisse_stock = $resultat['id'];

// Met le stock a jour sur la caisse

    $qid = $GLOBALS_1['bdd']->prepare("UPDATE " . $GLOBALS_1['db_table'][TABLE_STOCK] . " 
    SET stock = :stock WHERE id_product = :id_product");
    $qid->execute(array(  'stock' => $new_stock_product,
                          'id_product' => $id_caisse_stock));

///////////////////
} 
  }
}
        
        
        
        
        

//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

// Preparation emails

		$recap .= ' 
	<tr>
		<td align="left" style="background:#fff;padding:5px;border:1px solid #ccc">'. $result['name']. ' '.$result['reference'].' ' . $attributes . '';
            if($discount > 0){
			$recap .= ' (Remise de ' . number_format($discount, 2, ',', ' ') . ' % incluse)  ';
            }

if ($result['date_dispo'] > date("Y-m-d")){ 
$array_debut_us=explode("-", $result['date_dispo']);
$date_debut_fr=$array_debut_us[2]."-".$array_debut_us[1]."-".$array_debut_us[0];
$date_dispo_fr= str_replace('-','/', $date_debut_fr);
			$recap .= '<div style="color:#cc3300">' . $relicat_2 . ' '.$date_dispo_fr.'</div>';	
}

		$recap .= '
</td>
		<td align="center" width="10%" style="background:#fff;padding:5px;border:1px solid #ccc">'. $quantity . '</td>
		<td align="center" width="12%" style="background:#fff;padding:5px;border:1px solid #ccc">'. number_format($price, 2, ',', ' ') . '</td>
		<td align="center" width="12%" style="background:#fff;padding:5px;border:1px solid #ccc">' . number_format(($price * $quantity), 2, ',', ' ') . ' &euro;</td>
	</tr>

';





		}
	}
// Fin enregistrement


			$recap .='</table>';


///////////////////////////////////////////////
////////////////////////////////////////////////
//fidelite enregistrement customer
///////////////////////////////////////////////
///////////////////////////////////////////////

if(!empty($_SESSION['custo']['id'])) 
{


if ($act_fidel >0){
if ($Fremise > 0) {

if ($_SESSION['custo']['points'] >= $Ftot_cumul) { 

// solde sur acquis - solde cumul (ex 1000)
   $solde_s_acquis = $_SESSION['custo']['points'] - $Ftot_cumul;

// Panier en cours
   $Fpanier = $_POST['sub_total'] * $Fval_point ;
   $Fpanier = number_format($Fpanier);

// Total nouveau credit
   $NFcredit = $Fpanier + $solde_s_acquis;

	   } else {

// Panier en cours
   $Fpanier = $_POST['sub_total'] * $Fval_point ;
   $Fpanier  = floor($Fpanier); // arrondi entier inferieur si virgule


// Total nouveau credit
   $NFcredit = $Fpanier + $_SESSION['custo']['points'];
       }


// Enregistre le solde dans customer

			$sql = $GLOBALS['bdd']->prepare('UPDATE customers
				SET points = :points 
				WHERE id = :customer');

			$sql->execute(array('points' => $NFcredit,
								'customer' => $_SESSION['custo']['id']));

   }
  }

}
////////////////////////////////////////////////////




	unset($_SESSION['cart']);
	
		$sql = $GLOBALS['bdd']->prepare('DELETE FROM cart_attributes_values 
		WHERE session = :session');
		$sql->execute(array('session' => $session));
//////////////////////////////////////////////////////////

	// Mails de confirmation
	require('includes/phpmailer/class.phpmailer.php');



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////// E M A I L /////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

$msg ='<html lang="fr"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>';

$msg .='<div align="center" style="padding-top:20px;padding-bottom:20px;width:100%;background:#fff;font-size:12pt">
<table style="background-color: #ffffff; border: 1px solid #CCC; border-radius: 6px; outline: medium none; padding: 20px; width: 300px;;font-size:12pt;-webkit-box-shadow: 5px 5px 15px 5px #ccc; box-shadow: 5px 5px 15px 5px #ccc;font-family: Calibri,Candara,Segoe,Segoe UI,Optima,Arial,sans-serif;" cellspacing="0">
<tbody><tr><td style="text-align: center; vertical-align: top;font-size:12pt" colspan="5">';


/* Correctif logo sur email */
    $msg .='<img src="'.$wwwroot.'templates/shop/img/'.$Mail_Logo.'" style="margin:10px; max-width:300px">';


$msg .='</td></tr>';

$msg .='<tr><td style="text-align: center; vertical-align: top;font-size:12pt" colspan="5">
<table style="width: 100%;">
<tbody><tr><td style="width: 100%; text-align: left; vertical-align: middle;font-size:12pt;line-height:16pt" colspan="2">
Bonjour ' . $invoice_firstname. ' ' . $invoice_lastname . ',
<br /><br />Votre commande du <b>' . date('d/m/Y') . ' Num. ' . $id_order . '</b> a bien &eacute;t&eacute; enregistr&eacute;e. 
<br />Vous pouvez suivre le traitement de votre colis en cliquant sur le num&eacute;ro de suivi ci-dessous depuis votre compte client.
</td>
</tr>
<tr>
<td style="text-align: left;font-size:11pt" colspan="6">
<b>Num&eacute;ro de suivi : <a href="'.$shop_url.'/suivi-de-commande-' . $codeSuivi . '">' . $codeSuivi . '</a></b><br /><br />
</td>
</tr>
</tbody>
</table>';

$msg .='
<table style="width: 620px; height: 407px; margin-left: auto; margin-right: auto;">
<tbody><tr><td style="text-align: center;" colspan="6" width="100%">
<table border="0" width="100%" cellspacing="4"><tr>
		<td align="left" width="50%" style="background:#ccc;font-size:12pt;font-weight:bold;padding:5px 20px 5px 20px">Informations de livraison :</td>
		<td align="left" width="50%" style="background:#ccc;font-size:12pt;font-weight:bold;padding:5px 20px 5px 20px">Informations de facturation :</td>
	</tr>
	<tr>';


if ($carrierChoix =='2'){
$msg .='
<td align="left"  style="height:130px;border:1px solid #ccc;border-radius:2px;padding:10px;font-size:12pt"><b>Enl&egrave;vement par vos soins</b><br />';
$msg .= '<br /><b>'.$shop_title.'<br />'.$shop_company.'</b><br />'.$shop_address.'<br />'.$shop_zip_code.'&nbsp;'.$shop_town.'</b>';
$msg .= '</td>';
} 

else if (($delivery_lastname !=='') AND ($carrierChoix !=='2')) {

$msg .='
<td align="left"  style="height:130px;border:1px solid #ccc;border-radius:2px;padding:10px;font-size:12pt">' . $delivery_firstname . ' ' . $delivery_lastname . '<br />';
if (!empty($delivery_company)){$msg .= '' . $delivery_company . '<br />';}
$msg .= '' . $_POST['delivery_address1'] . '<br>';
if (!empty($_POST['delivery_address2'])){$msg .= '' . $_POST['delivery_address2'] . '<br>';}
$msg .= '' . $_POST['delivery_zip_code'] . ' ' . $_POST['delivery_city'] . '<br>' . $delivery_country_name . '<br>' . $_POST['delivery_phone'] . '<br>';
$msg .= '</td>';

} else if (($delivery_lastname =='') AND ($carrierChoix !=='2')) {

$msg .= '<td align="left" style="height:130px;border:1px solid #ccc;border-radius:2px;padding:10px;font-size:12pt">' . $invoice_firstname . ' ' . $invoice_lastname . '<br />';
if (!empty($invoice_company))
				{
					$msg .= '' . $invoice_company . '<br>';
				}
$msg .= '' . $_POST['invoice_address1'] . '<br>';
if (!empty($_POST['invoice_address2']))
				{
					$msg .= '' . $_POST['invoice_address2'] . '<br>';
				}
$msg .= '' . $_POST['invoice_zip_code'] . ' ' . $_POST['invoice_city'] . '<br>
				' . $invoice_country_name . '<br>
				' . $_POST['invoice_phone'] . '<br>';
$msg .= '</td>';

} else 
{}

$msg .= '<td align="left" style="height:130px;border:1px solid #ccc;border-radius:2px;padding:10px;font-size:12pt">' . $invoice_firstname . ' ' . $invoice_lastname . '<br />';
if (!empty($invoice_company))
				{
					$msg .= '' . $invoice_company . '<br>';
				}
$msg .= '' . $_POST['invoice_address1'] . '<br>';
if (!empty($_POST['invoice_address2']))
				{
					$msg .= '' . $_POST['invoice_address2'] . '<br>';
				}
$msg .= '' . $_POST['invoice_zip_code'] . ' ' . $_POST['invoice_city'] . '<br>
				' . $invoice_country_name . '<br>
				' . $_POST['invoice_phone'] . '<br>';
$msg .= '</td>';


if ($carrierChoix !=='2'){
$msg .= '</tr>
	<tr>
		<td align="left" colspan="2"><b>Mode de livraison : ' . $carrierNam . '</b></td>
	</tr>';
}
$msg .= '
</table>
</td>
</tr>';

$msg .= '
<tr>
<td style="text-align: center;" colspan="6">
<p style="font-size:12pt; padding:10px;"><b>R&eacute;capitulatif de la commande</b></p>
</td>
</tr>
<tr>
<td style="text-align: center;" colspan="6">';
$msg .= $recap;

/********************************************************************************************/

$msg .= '<div style="font-size:12pt; padding:0"><br /><b>Total de votre commande</b><br />';


if ($act_pro >0 AND $_SESSION['custo']['cle_pro'] >0){
$msg .='<br />Sous-total HT : ' . number_format($_POST['sub_total'], 2, ',', ' ') . ' &euro; <br /> ';
} else {
$msg .='<br />Sous-total TTC : ' . number_format($_POST['sub_total'], 2, ',', ' ') . ' &euro; <br /> ';
}

$lecode_promo = $_POST['lecode_promo'];



	if($lecode_promo >0){
    $msg .= 'Remise code PROMO s/TTC : '.number_format($lecode_promo, 2, ',', ' ').' &euro;<br>';
    }
	if($bienvenue_taux >0){
    $msg .= 'Remise de bienvenue s/TTC ('.number_format($bienvenue_taux, 2, ',', ' ').'%) : '.number_format($bienvenue_ttc, 2, ',', ' ').' &euro;<br>';
    }
	if($fidelite_taux >0){
    $msg .= 'Remise de fid&eacute;lit&eacute; s/TTC ('.number_format($fidelite_taux, 2, ',', ' ').'%) : '.number_format($fidelite_ttc, 2, ',', ' ').' &euro;<br>';
    }
	$msg .= 'Frais de livraison : ' . number_format($frais_transp22, 2, ',', ' ') . ' &euro;<br>';
	$msg .= '<br /><b>Total TTC : ' . number_format($_POST['total'], 2, ',', ' ') . ' &euro;</b><br>';
	$msg .= '<b>Mode paiement : ' . $_POST['payment'] . '</b> ';


$msg .='</div></td></tr><tr><td style="text-align: left;" colspan="6">&nbsp;</td></tr>
<tr>
<td style="text-align: left;font-size:12pt;line-height:16pt" colspan="6">
Sachez que votre commande est bien en traitement au moment o&ugrave; vous lisez ce 
mail. Si vous avez des questions, vous pouvez nous contacter au '.$shop_phone.'</td>
</tr>
<tr>
<td style="text-align: left;font-size:12pt;line-height:16pt" colspan="6">
<br />Merci de votre confiance.';


$msg .= '<br /><br /><b>'.$shop_title.'</b><br /><a href="'.$shop_url.'">'.$shop_url.'</a><br /><br />'.$shop_company.'<br />'.$shop_address.'<br />'.$shop_zip_code.'&nbsp;'.$shop_town.'<br />'.$shop_email_contact.'</b>
</td></tr><tr><td style="text-align: left;" colspan="6"><p>&nbsp;</p></td></tr><tr><td style="text-align: center;" colspan="6"><table border="0" width="100%" cellspacing="5">	
</table>
</td>
</tr>
<tr>';
 
$msg .= '<td style="text-align: center; vertical-align: middle;" colspan="6">';
if ($facebook !=="") { 
$msg .= '
<a title="Voir notre page Facebook" href="'.$facebook.'" target="_blank">
<img src="templates/shop/img/facebook.png" alt="" border="0" /></a>&nbsp;&nbsp;&nbsp;';
}
if ($instagram!=="") { 
$msg .= '
<a title="Voir notre page Instagram" href="'.$instagram.'" target="_blank">
<img src="templates/shop/img/instagram.png" alt="" border="0" /></a>&nbsp;&nbsp;&nbsp;';
}
if ($twitter!=="") { 
$msg .= '
<a title="Voir notre page Twitter" href="'.$twitter.'" target="_blank">
<img src="templates/shop/img/twitter.png" alt="" border="0" /></a>';
}
$msg .= '</td>';


$msg .= '
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;" colspan="6">&nbsp;</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;" colspan="6">
<div align="center"><span style="font-size: 8pt; color: #999999;"><span style="font-family: Verdana,Arial,Helvetica,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; background-color: #ffffff;">
<br />Conform&eacute;ment &agrave; la Loi Informatique et Libert&eacute;s, vous disposez d\'un droit d\'acc&egrave;s de rectification <br />et d\'opposition en vous adressant &agrave; :</span></span>';

$msg .= '
 <span style="color: #999999; font-family: Tahoma; font-size: 10pt;">'.$shop_company.' - adresse de correspondance : <br /></span><span style="color: #999999;">'.$shop_address.' - '.$shop_zip_code.'&nbsp;'.$shop_town.'</span></span></span></div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
';

$msg .='</body>
	</html>';

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////// E M A I L /////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	// Envoi message au client.
	$mail2 = new PHPMailer();
	$mail2->IsMail();
	$mail2->AddReplyTo($shop_email_contact, $shop_company);
	$mail2->AddAddress($_POST['email']);
	$mail2->SetFrom($shop_email_rappel, $shop_company);
	$mail2->Subject = "Confirmation de votre commande depuis le site " . $shop_title;
	$mail2->MsgHTML($msg);

	// Envoi message a l'administrateur du site.
	$mail = new PHPMailer();
	$mail->IsMail();
	$mail->AddReplyTo($_POST['email'], $_POST['invoice_lastname']);
	$mail->AddAddress($shop_email_rappel);
	$mail->SetFrom($_POST['email'], $_POST['invoice_lastname']);
	$mail->Subject = "Commande depuis le site " . $shop_title;
	$mail->MsgHTML($msg);


	if($mail->Send() & $mail2->Send())
	{
		$smarty->assign("emails_status", 'OK');
	} else {
		$smarty->assign("emails_status", 'erreur');
	}



 





$idCommande = $id_order;
$prixTotal = $totalCde ;





// Redirection pour le paiement////////////////////////////////////////////////
/*****************************************************************************/


//Si avis type 1
/****************/
 
if ($act_avis =='1'){

	switch ($_POST['payment']) {
	
		case 'Paypal':
			echo '<script language="javascript">document.location.href="avis_paypal.php?&id=' . $codeSuivi . '&commandeid='.$idCommande.'"</script>';
			break;


 
		 		case 'cb':
	/******************************************************************************/
	// 	Paiement par CB
	/******************************************************************************/
	 	$requete = $bdd->prepare("INSERT INTO transactions (transaction_id, transaction_commande_id, transaction_total, transaction_statut) 
	 		VALUES (:transaction_id, :transaction_commande_id, :transaction_total, :transaction_statut)");
	 	$requete->execute(array(
	 		'transaction_id' => $idCommande,
	 		'transaction_commande_id' => $idCommande,
	 		'transaction_total' => stripslashes($prixTotal),
	 		'transaction_statut' => null
	 		));

	 	$idTransaction = $bdd->lastInsertId();
        $prixTotal = number_format($prixTotal,2); 
  
        echo'
        <form name="xxxl" action="./avis_cb.php" method="post">
        <input type="hidden" name="commandeid" value="' . $idCommande . '">
        <input type="hidden" name="email" value="' . $_POST['email'] . '">
        <input type="hidden" name="total" value="' . $prixTotal. '">
        <input type="hidden" name="id" value="'.$codeSuivi.'">

        <script type="text/javascript"> 
        document.xxxl.submit(); //on envoie le formulaire  
        </script> 
        </form>'; 
     	break;
 
	
		case 'Cheque':
	        echo '<script language="javascript">document.location.href="avis_check.php?id=' . $codeSuivi . '"</script>';
			break;



		case 'Virement':
			echo '<script language="javascript">document.location.href="avis_transfer.php?id=' . $codeSuivi . '"</script>';
			break;
	}






} else {


//Si pas avis
/****************/

	switch ($_POST['payment']) {
	
		case 'Paypal':
			echo '<script language="javascript">document.location.href="paypal.php?id=' . $codeSuivi . '&commandeid='.$idCommande.'"</script>';
			break;

 
		 		case 'cb':
	/******************************************************************************/
	// 	Paiement par CB
	/******************************************************************************/

/* 
	 	$requete = $bdd->prepare("INSERT INTO transactions (transaction_id, transaction_commande_id, transaction_total, transaction_statut) 
	 		VALUES (:transaction_id, :transaction_commande_id, :transaction_total, :transaction_statut)");
	 	$requete->execute(array(
	 		'transaction_id' => $idCommande,
	 		'transaction_commande_id' => $idCommande,
	 		'transaction_total' => stripslashes($prixTotal),
	 		'transaction_statut' => null
	 		));

 	 	$idTransaction = $bdd->lastInsertId();
        $prixTotal = number_format($prixTotal,2); 

 
        echo'
        <form name="xxxl" action="./LCL_payment/index.php" method="POST">
        <input type="hidden" name="commandeid" value="' . $idCommande . '">
        <input type="hidden" name="email" value="' . $_POST['email'] . '">
        <input type="hidden" name="total" value="' . $prixTotal. '">

        <script type="text/javascript"> 
        document.xxxl.submit(); //on envoie le formulaire  
        </script> 
        </form>'; 
*/
$prixTotal = number_format($prixTotal,2); 
//  $wwwrequest = "https://www.litsolide.com/CA/Paiement_Hmac.php?commandeid=" . $idCommande . "&email=".$_POST['email']."&total=" . $prixTotal; 

   $wwwrequest = "https://www.litsolide.com/CA/Paiement_Hmac.php?commandeid=" . $idCommande . "&email=".$_POST['email']."&total=" . $prixTotal; 
   header("Location: $wwwrequest");








     	break;
 

	
		case 'Cheque':
	      echo '<script language="javascript">document.location.href="check.php?id=' . $codeSuivi . '"</script>';
			break;



		case 'Virement':
			echo '<script language="javascript">document.location.href="transfer.php?id=' . $codeSuivi . '"</script>';
			break;
	}
}



}
}


//****************************************************************************************//
//*************************************** CMS ACCUEIL ************************************//
//****************************************************************************************//

$id_page = $page_panier;
if ($id_page >0) {
// Page CMS   
    $sqlpm = $GLOBALS['bdd']->query('SELECT title, content FROM cms 
	WHERE id = '.$id_page.'');
    $com = $sqlpm->fetch();
	$page_content= $com['content'];
} else {
	$page_content="";
}	
    $smarty->assign("page_content", $page_content);
    $smarty->assign("id_page", $id_page);



//*************************************** Affichage **************************************//
  $smarty->display('cart.tpl');
?>  

Anon7 - 2022
AnonSec Team