<?php
session_start();
if (!isset($_SESSION["user_id"]) || $_SESSION["user_id"]==null):
    print "<script>alert(\"Acceso Invalido!\");
    window.location='login.php';</script>";
endif;
if ($_SESSION["user_at"] < 2):
    print "<script>alert(\"Sin Acceso a Transaccion!\");
    window.location='vt000.php';</script>";
endif;
include_once ("lib/fpdf/funci.php");
$coalm = $_SESSION["user_al"];
$conex = conectar();
date_default_timezone_set('America/La_Paz');
if(!isset($_POST["codigo"])) return;
$codigo = $_POST["codigo"];
$canti = $_POST["canti"];
$rowid = mysql_query("SELECT * FROM vtart WHERE vtartcart = '$codigo' and vtartcalm = '$coalm'");
$producto = mysql_fetch_array($rowid);
if (mysql_num_rows($rowid) > 0):
   if ($producto[vtartcant] < $canti or $canti <= 0):
      header("Location: vt111.php?status=5");
      exit;
   endif;
   $indice = false;
   for ($i=0; $i < count($_SESSION["carrito"]); $i++): 
       if ($_SESSION["carrito"][$i][vtartcart] === $codigo):
          $indice = $i;
	  break;
       endif;
   endfor;
   if ($indice === FALSE):
      $producto[mican] = $canti;
      $producto[total] = $producto[vtartpven] * $producto[mican];
      array_push($_SESSION["carrito"], $producto);
   else:
      $_SESSION["carrito"][$indice][mican] = $_SESSION["carrito"][$indice][mican] + $canti;
      $_SESSION["carrito"][$indice][total] = $_SESSION["carrito"][$indice][mican] * $_SESSION["carrito"][$indice][vtartpven];
   endif;
   header("Location: vt111.php");
else:
   header("Location: vt111.php?status=4");
endif;
?>
