<?php
$new_quantity1=0;
if(isSet($_POST['action']))
{
switch($_POST['action'])
{
case"add":
$id_utente=$_SESSION['code'];
$id_item=$_POST['idProprieta'];
$quantity=$_POST['quantity'];
$check=mysql_query("select * from rel where id_utente='$id_utente' and id_item='$id_item'");
if($rows=mysql_fetch_array($check))
{
$new_quantity=$rows['amount'];
$new_quantity +=1;
mysql_query("update rel set amount='$new_quantity'");
break;
}
else
{
$quantity=$_POST['quantity'];
mysql_query("insert into rel values ('$id_utente' , '$id_item' , '$quantity')");
break;
}
case"delete";
$id_utente=$_SESSION['code'];
$id_item=$_POST['id_item'];
mysql_query("delete from rel where id_item='$id_item' AND id_utente='$id_utente'");
break;
case"update";
$id_utente=$_SESSION['code'];
$id_item=$_REQUEST['id_item'];
$new_quantity=$_REQUEST['new_quantity'];
mysql_query("update rel set amount='$new_quantity' where id_item='$id_item' and id_utente='$id_utente'");
break;
}
}
$tot=0;
$tot_price=0;
$num_items=0;
echo "<table border='1' width='60%' cellpadding='0' cellspacing='0'><tr><td bgcolor='#999999' >Prodotto</td><td bgcolor='#999999'>Quantita</td><td bgcolor='#999999'> Prezzo €</td><td bgcolor='#999999'> Totale </td><td bgcolor='#999999'>Elimina</td></tr>";
$item_rel=mysql_query("select * from rel where id_utente='$id_utente'");
while($rows=mysql_fetch_array($item_rel))
{
$id_item=$rows['id_item'];
$amount=$rows['amount'];
$num_items += $amount;
$proprieta=mysql_query("select * from proprieta where idProprieta='$id_item'");
$row_proprieta=mysql_fetch_array($proprieta);
$idProprieta=$row_proprieta['idProprieta'];
$modello=$row_proprieta['modello'];
$cilindrata=$row_proprieta['cilindrata'];
$prezzo=$row_proprieta['prezzo'];
$tot=$amount * $prezzo;
$tot_price += $tot;
?>
</h1>
<tr><td valign="top"><div align='left'><font face='Verdana, Arial, Helvetica, sans-serif'><?php echo "$modello"; ?></font></div></td>
<td valign="top"><form action="cart.php" method="post">
<input type="hidden" name="action" value="update">
<input type="hidden" name="id_item" value="<?php echo $idProprieta; ?>" >
<input type="text" name="new_quantity" value="<?php echo $amount; ?>" size=6 maxlenght=6 align="right" >
<br>
<input name="Aggiorna" type="submit" value="Aggiorna"> </form>
</td ><td valign="top"><div align='center'><font face='Verdana, Arial, Helvetica, sans-serif'><?php echo $prezzo; ?> €</font></div></td>
</td><td valign="top"><div align='center'><strong><font face='Verdana, Arial, Helvetica, sans-serif'><?php echo $tot; ?></font></strong></div></td>
<td valign="top" align="center"><form action="cart.php" method="post">
<input type="hidden" name="action" value="delete" >
<input type="hidden" name="id_item" value="<?php echo $idProprieta; ?>" >
<input type="image" src="http://forum.mrwebmaster.it/images/button_delete.gif">
</form>
</td>
</tr>
<?php
}
echo "<tr cellpadding='3'><td></td><td></td><td></td><td></td><td></td></tr>";
echo "<tr><td>Articoli</td><td>$num_items</td><td><b>Prezzo totale :</td><td align='center'><b> $tot_price € </b></td><td>.</td></tr>";
echo "</table>";
echo "Ci sono $num_items elementi nel carrello";
mysql_close($connection);
?>
<a href="javascript:history.go(-1);">Back</a>