<?PHP
/***************************************************/
/* I N C L U D E S */
/***************************************************/
require ("etc/myShop.cfg");
require (LIBRARIES . "db_mySQL.inc");
require (LIBRARIES . "bll_basket.inc");
require (LIBRARIES . "bll_user.inc");
require (LIBRARIES . "template.inc");
require (LIBRARIES . "format.inc");
/***************************************************/
if (!isset($act)) {
header ("Location: error.php?msg=Parametro%20action%20non%20presente.");
exit;
}
$t = new Template(TEMPLATES . "basket");
$bll_basket = new bll_basket();
$myArray = array( "basket_template" => "basket.ihtml",
"basket_row_template" => "basket_row.ihtml");
$t->set_file($myArray);
reset ($myArray);
if (empty($id_user)) $id_user = "";
$name_label = "Nome prodotto";
$description_label = "Descrizione prodotto";
$price_label = "Prezzo";
$quantity_label = "Quantità ";
$subtotal_label = "Subtotale";
$total_label = "Totale";
$header_message = "";
$total = "";
$tot_taxs = "";
$subtotal = "";
// Attivazione gestione sessione
session_start();
switch ($act) {
/****************************************************/
/* D E L E T E _ B A S K E T */
/****************************************************/
case "delete_basket":
$res = $bll_basket->deleteFromBasket(session_id(),$id_product);
header("Location:basket_operations.php?act=load_basket");
exit;
break;
/****************************************************/
/* A D D _ B A S K E T */
/****************************************************/
case "add_basket":
if (!isset($quantity)) {
$quantity = 1;
}
$res = $bll_basket->addToBasket(session_id(),$quantity,$id_product);
header("Location:basket_operations.php?act=load_basket");
exit;
break;
/****************************************************/
/* U P D A T E _ B A S K E T */
/****************************************************/
case "update_basket":
$vet_basket = array();
reset($HTTP_POST_VARS);
$i = 0;
while(list($key,$val) = each($HTTP_POST_VARS)) {
//prod_quantity_id_
if (substr($key,0,17) == "prod_quantity_id_"){
$vet_basket[$i][0] = trim(session_id());
$vet_basket[$i][1] = trim(substr($key,17));
$vet_basket[$i][2] = trim($val) ;
$i++;
}
}
/*
$vet_basket[$i][0] = trim($session_id);
$vet_basket[$i][1] = trim(substr($key,17)); // id product
$vet_basket[$i][2] = trim($val) ; // quantity
*/
if(count($vet_basket) > 0){
$resultset_basket = $bll_basket->changeQuantity($vet_basket);
}
//$resultset_basket = $bll_basket->get_basket_list($session_id);
header("Location:basket_operations.php?act=load_basket");
exit;
break;
/****************************************************/
/* L O A D _ B A S K E T */
/****************************************************/
case "load_basket":
/*
basket.id_product
tbl_product_info.name,
tbl_product_info.description
basket.qty
tbl_product_price.price
*/
$v_products = $bll_basket->get_basket_list(session_id());
if($v_products == 0){
$product_number = 0;
}else {
$product_number = count($v_products);
}
if ($product_number == 0) {
$t->set_var("BASKET_ROW", "");
$t->set_var("SUBMIT_OR_PRASE", "Nessun prodotto nel carrello");
} else {
$total = 0;
$prod_quantity_name = "prod_quantity_id_";
$t->set_var("SUBMIT_OR_PRASE" , "<input type=submit onSubmit=\"javascript:document.forms.formBasket.submit();\" value=\"Aggiorna il carrello\" ");
for ($i=0;$i<$product_number;$i++) {
$t->set_var("PROD_LINK" , "product_detail.php?id=".$v_products[$i]["id_product"]);
$t->set_var("PROD_NAME" , $v_products[$i]["name"]);
$t->set_var("PROD_DESCRIPTION" , $v_products[$i]["description"]);
$t->set_var("PROD_PRICE" , format_price($v_products[$i]["price"]));
$t->set_var("PROD_QUANTITY_NAME", $prod_quantity_name . $v_products[$i]["id_product"]);
$prod_quantity = $v_products[$i]["quantity"];
$t->set_var("PROD_QUANTITY" , $prod_quantity);
$prod_subtotal = $v_products[$i]["price"] * $prod_quantity;
$total = $total + $prod_subtotal;
$t->set_var("PROD_SUBTOTAL" , format_price($prod_subtotal));
$t->set_var("PROD_DELETE" , "$PHP_SELF?act=delete_basket&id_product=".$v_products[$i]["id_product"]);
$t->parse("BASKET_ROW" , "basket_row_template", true);
}
//CALCOLO DELLE TASSE
$tot_taxs = 0;
// Verifica sull'autentificazione dell'utente
if ($id_user != 0) {
$bll_user = new bll_user();
$a = $bll_user->get_user_info($id_user);
// Da modificare con id_state
$b = $bll_user->get_taxs(1);
// Tasse percentuali
if ($b["tax_value_perc"] !=0) {
$tot_taxs = $tot_taxs + $total * $b["tax_value_perc"];
}
// Tasse fisse
if ($b["tax_value_fix"] !=0) {
$tot_taxs = $tot_taxs + $b["tax_value_fix"];
}
}
//CALCOLO SUBTOTALE
$subtotal = $total + $tot_taxs;
}
break;
}
/*
*
* Valorizzazione del template del basket
*
*/
if ($product_number > 0) {
if ($id_user != 0) {
// Recupero informazioni utente
$header_message = "Benvenuto " . strtoupper($a["surname"]) . " " . strtoupper($a["name"]);
$t->set_var("ORDER_LINK" , "order.php");
} else {
$header_message = "Sei ancora anonimo. Tasse e sconti appariranno calcolati correttamente dopo che ti sarai registrato.";
$t->set_var("ORDER_LINK" , "login.php");
}
} else {
$t->set_var("ORDER_LINK" , "javascript:alert('Per procedere con l\'ordine si deve selezionare almeno un articolo.');");
}
$t->set_var("PROD_UPDATE" , "$PHP_SELF?act=update_basket");
$t->set_var("CART_CLEAR" , "$PHP_SELF?act=clear_basket");
$t->set_var("CART_CHECK_OUT" , "");
$t->set_var("HEADER_MESSAGE" , $header_message);
$t->set_var("NAME_LABEL" , $name_label);
$t->set_var("DESCRIPTION_LABEL" , $description_label);
$t->set_var("PRICE_LABEL" , $price_label);
$t->set_var("QUANTITY_LABEL" , $quantity_label);
$t->set_var("SUBTOTAL_LABEL" , $subtotal_label);
$t->set_var("TOTAL_LABEL" , $total_label);
$t->set_var("ADD_PRODUCT_LINK" , "categories_list.php");
$t->set_var("BACK_LINK" , "javascript:window.history.back();");
$t->set_var("BASKET_TOTAL" , format_price($total));
$t->set_var("BASKET_TOTAL_TAXS" , format_price($tot_taxs));
$t->set_var("BASKET_SUBTOTAL" , format_price($subtotal));
$t->aparse("cart" , "basket_template");
?>