vlotho

produit_mini.php

Jun 13th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.07 KB | None | 0 0
  1. <?php
  2. if (defined('PHPBOOST') !== true) exit;
  3.  
  4. function produit_mini($position, $block)
  5. {
  6.     global $PRODUIT_LANG;
  7.     //Chargement de la langue du module.
  8.     load_module_lang('produit');
  9.    
  10.     $tpl = new Template('produit/produit_mini.tpl');
  11.     import('core/menu_service');
  12.     MenuService::assign_positions_conditions($tpl, $block);
  13.    
  14.     $erreur = false;
  15.  
  16.     $action = (isset($_POST['action'])? $_POST['action']:null ); //  (isset($_GET['action'])? $_GET['action']:null )) ;
  17.     if($action !== null)
  18.     {
  19.         if(!in_array($action,array('Ajouter au panier', 'suppression', 'refresh')))
  20.         $erreur=true;
  21.  
  22.         //récuperation des variables en POST ou GET
  23.         $marque = (isset($_POST['marque'])? $_POST['marque']:null ); //  (isset($_GET['l'])? $_GET['l']:null )) ;
  24.         $ref = (isset($_POST['ref'])? $_POST['ref']:null ); //  (isset($_GET['l'])? $_GET['l']:null )) ;
  25.         $price = (isset($_POST['price'])? $_POST['price']:null ); //  (isset($_GET['p'])? $_GET['p']:null )) ;
  26.         $quantite = (isset($_POST['quantite'])? $_POST['quantite']:null ); //  (isset($_GET['q'])? $_GET['q']:null )) ;
  27.  
  28.         //Suppression des espaces verticaux
  29.         $marque = preg_replace('#\v#', '',$marque);
  30.         $ref = preg_replace('#\v#', '',$ref);
  31.         //On verifie que $price soit un float
  32.         $price = floatval($price);
  33.  
  34.         //On traite $quantite qui peut etre un entier simple ou un tableau d'entier
  35.    
  36.         if (is_array($quantite))
  37.         {
  38.             $QteArticle = array();
  39.             $i=0;
  40.             foreach ($quantite as $contenu)
  41.             {
  42.                 $QteArticle[$i++] = intval($contenu);
  43.             }
  44.         }
  45.         else
  46.             $quantite = intval($quantite);
  47.    
  48.     }
  49.  
  50.     if (!$erreur)
  51.     {
  52.         switch($action)
  53.         {
  54.             Case "Ajouter au panier":
  55.                 ajouterArticle($marque,$ref,$quantite,$price);
  56.                 break;
  57.  
  58.             Case "suppression":
  59.                 supprimerArticle($marque,$ref);
  60.                 break;
  61.  
  62.             Case "refresh" :
  63.                 for ($i = 0 ; $i < count($QteArticle) ; $i++)
  64.                 {
  65.                     modifierQTeArticle($_SESSION['panier']['marqueProduit'][$i],round($QteArticle[$i]));
  66.                 }
  67.                 break;
  68.  
  69.             Default:
  70.                 break;
  71.         }
  72.     }
  73.    
  74.     $nbArticles=count($_SESSION['panier']['marqueProduit']);
  75.    
  76.     $panier = array();
  77.     for ($i=0 ;$i < $nbArticles ; $i++)
  78.     {
  79.         $panier[] = array(
  80.             echo "<tr>",
  81.                 echo "<td>".htmlspecialchars($_SESSION['panier']['qteProduit'][$i])." x</td>",
  82.                 echo "<td>".htmlspecialchars($_SESSION['panier']['marqueProduit'][$i])."</ td>",
  83.                 echo "<td>".htmlspecialchars($_SESSION['panier']['refProduit'][$i])."</td>",
  84.                 echo "<td>".htmlspecialchars($_SESSION['panier']['prixProduit'][$i])."</td>",
  85.                 echo "<td><a href=\"".htmlspecialchars("produit_mini.php?action=suppression&marque=".rawurlencode($_SESSION['panier']['marqueProduit'][$i]))."\">XX</a></td>",
  86.             echo "</tr>"
  87.     }
  88.     $tpl->put('panier', $panier);
  89.  
  90.     $tpl->assign_vars(array(
  91.     'C_NB_ARTICLES' => $nbArticles,
  92.     'C_MONTANT_GLOBAL' => MontantGlobal(),
  93.     'L_PANIER_VIDE' => 'Votre panier est vide',
  94.     'C_NB_ARTICLES_NULL' => $nbArticles <= 0,
  95.     'C_CREATION_PANIER' => creationPanier(),
  96.     'L_CART' => $PRODUIT_LANG['panier'],
  97.     'L_ORDER' => $PRODUIT_LANG['order']
  98.     ));
  99.  
  100.     return $tpl->parse(TEMPLATE_STRING_MODE);
  101. }
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment