Ver Mensaje Individual
  #18 (permalink)  
Antiguo 18/03/2014, 09:17
Avatar de wolfmoon
wolfmoon
 
Fecha de Ingreso: octubre-2007
Mensajes: 189
Antigüedad: 16 años, 6 meses
Puntos: 2
Respuesta: Control de reservas y problema al imprimir variable via get

Yo te pongo el codigo por si acaso

en index.php

Código PHP:
Ver original
  1. <form name="form" action="carrito.php" method="get"/>
  2. <input id="datepicker" class="s" type="text" name="date" required />
  3. <input type="hidden" id="id" name="id" value="<?php echo $datos[0["albergue_id"]?>" />
  4. <input type="hidden" id="action" name="action" value="add" />
  5. <input type="hidden" name="url" value="<?php echo $url;?>" />
  6. <input type="submit" value="enviar" />

En carrito.php
Código PHP:
Ver original
  1. require_once '../application/Bootstrap.php';
  2. require_once ROOT . 'site/albergues.php';
  3. require_once ROOT . 'site/carro.php';
  4.  
  5. $config = new Carro();
  6. $obj = new Propiedades();
  7. $config->procesaCarro();
  8.  
  9. if(isset($_SESSION["carro"])):
  10.     $totalCoste = 0;
  11.     $Total = 0;
  12.  
  13. foreach($_SESSION["carro"] as $key=>$valor):
  14.                                            
  15.                                            
  16.                                            
  17. $fi = $obj->getRoomsId($key);
  18.                                                
  19. foreach($fi as $fila):
  20.   $id = $fila["albergue_id"];
  21.   $room = $fila["albergue_nombre"];
  22.   $precio = $fila["albergue_precio"];
  23.                                                    
  24. endforeach;
  25.                                                
  26. $coste = $precio * $valor;
  27. $totalCoste = $totalCoste + $coste;
  28. $Total = $Total + $valor;
  29.                                    
  30.     //AQUI EL CODIGO HTML
  31.        //CIERRO TODAS LOS CICLOS
  32.                                
  33. ?>
  34.  
  35.  
  36. Y en site/carro.php

Código PHP:
Ver original
  1. public function procesaCarro(){
  2.        
  3.         if(isset($_GET)){
  4.             $input_arr = array();
  5.             foreach ($_GET as $key => $input_arr) {
  6.                 $_GET[$key] = addslashes($this->limpiarCadena($input_arr));    
  7.             }
  8.         }
  9.            
  10.         if(isset($_GET['id'])){
  11.             $id = $_GET['id'];
  12.             $id = (int) $id;
  13.         }else{
  14.             $id = 1;
  15.         }
  16.        
  17.         if(isset($_GET["url"])) {
  18.             $url = $_GET["url"];
  19.         }
  20.        
  21.    
  22.        
  23.         if(!is_array($_SESSION["carro"]))
  24.             $_SESSION["carro"] = Array();
  25.            
  26.         if(isset($_GET['action']))
  27.             $action = $_GET['action'];
  28.         else
  29.             $action = '';
  30.            
  31.         switch ($action) {
  32.            
  33.             case 'add':
  34.            
  35.                 if(isset($_SESSION['carro'][$id])){
  36.                    
  37.                     $_SESSION['carro'][$id]++;
  38.                    
  39.                    
  40.                 }else
  41.                     $_SESSION['carro'][$id] = 1;
  42.            
  43.                 break;
  44.                
  45.             case 'remove':
  46.            
  47.                 if(isset($_SESSION['carro'][$id]))
  48.                 {
  49.                     $_SESSION['carro'][$id]--;
  50.                    
  51.                     if($_SESSION['carro'][$id] == 0)
  52.                         unset($_SESSION['carro'][$id]);
  53.                 }
  54.            
  55.                 break; 
  56.  
  57.             case 'removeProd':
  58.            
  59.                 if(isset($_SESSION['carro'][$id]))
  60.                 {
  61.                     unset($_SESSION['carro'][$id]);
  62.                 }
  63.            
  64.                 break;
  65.                
  66.             case 'empty':
  67.                
  68.                 unset($_SESSION['carro'][$id]);
  69.                
  70.                 break;     
  71.            
  72.         }
  73.            
  74.     }