la pagina è la seguente:
var $squery;
var $dati;
function connect() {
mysql_connect ($this->Host, $this->User, $this->Password) or die ($this->errore_server ());
mysql_select_db($this->Database);
}
function query($sql) {
$this->connect();
$this->squery = mysql_query($sql) or die ($this->errore_server ());
}
function query_prod($id) {
$sql = "SELECT * FROM ecom_prodotti WHERE prod_id='".$id."'";
$this->query($sql);
$this->next_record();
}
function next_record() {
$this->dati = mysql_fetch_array($this->squery, MYSQL_ASSOC);
return $this->dati;
}
function f($Field_Name) {
return $this->dati[strtolower($Field_Name)];
}
function p($Field_Name) {
print $this->f($Field_Name);
}
// funzione per errore server mysql
function errore_server() {
echo "Il database MySql sembra non rispondere...
MySql dice:
<font color=red>";
echo mysql_error();
echo "</font>
pregasi <a href=\"mailto:gianluca@writeme.com\">segnalare</a> il problema";
}
}
function eur($numero) {
return number_format($numero, 2, ',', '.');
}
function cat_nome($id) {
$db = new DB;
$sql="SELECT cat_nome FROM ecom_categorie WHERE cat_id='".$id."'";
$db->query($sql);
$db->next_record();
return $db->p("cat_nome");
}
function prod_nome($id) {
$db = new DB;
$sql="SELECT prod_nome FROM ecom_prodotti WHERE prod_id='".$id."'";
$db->query($sql);
$db->next_record();
return $db->p("prod_nome");
}
function prod_desc($id_prod) {
$desc = "";
$db = new DB;
$sql="SELECT * FROM ecom_prodotti WHERE prod_id='".$id_prod."'";
$db->query($sql);
$db->next_record();
$desc = $db->f("prod_nome");
$sql="SELECT cat_nome FROM ecom_categorie WHERE cat_id='".$db->f("cat_id")."'";
$db->query($sql);
$db->next_record();
$desc = $db->f("cat_nome")." ".$desc;
return $desc;
}
function conf_display($id) {
$db = new DB;
$sql="SELECT * FROM ecom_confezioni WHERE prod_id='".$id."' ORDER BY conf_order";
$db->query($sql);
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">\n";
while ($db->next_record()) {
echo "<tr class=\"text\" bgcolor=\"#FFFF99\">\n";
echo "<td align=\"left\">".$db->f("conf_nome")."</td>\n";
echo "<td align=\"right\">€".$db->f("conf_costo")."</td>\n";
echo "<td align=\"right\"><a href=\"carrello.php?id=".$db->f("conf_id")."\">acquista</font></a></td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
// carrello
class Cart {
var $items;
var $tot;
var $total;
var $peso;
var $italia;
// add product(s) to the cart
function addqta($id, $qta) {
if($qta > 0)
$this->items[$id] += $qta;
}
function add($id) {
$this->addqta($id,1);
}
// remove $qty product(s) from the cart
function set($id, $qta) {
$this->items[$id] = $qta;
}
function remove($id) {
unset($this->items[$id]);
}
function svuota() {
$this->items=array();
}
function getqta($id) {
return $this->items[$id];
}
function gettotal() {
return $this->total;
}
function getitems() {
return $this->items;
}
function vuoto() {
if (count($this->items)>0) return FALSE;
else return TRUE;
}
}
class MyCart extends Cart {
function display($mod) {
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">\n";
echo "<tr align=\"center\" bgcolor=\"#FFCC66\" class=\"textbold\">";
if ($this->vuoto()) {
echo "<td align=\"center\"> Il carrello è vuoto</td>";
}
else {
$totale = 0; $pes = 0;
$ids = ""; // holds all the product ids in the cart
foreach($this->items as $id => $qta)
$ids .= ",$id";
$ids = substr($ids, 1);
$db = new DB;
$sql = "SELECT * FROM ecom_confezioni WHERE conf_id IN (" . $ids . ")";
$db->query($sql);
echo "<td width=\"65%\">Prodotto</td><td width=\"12%\">Prezzo</td><td width=\"12%\">Quantità</td>
<td width=\"13%\" align=\"center\">Totale</td></tr>";
while ($db->next_record()) {
echo "<tr class=\"text\" bgcolor=\"#FFFF99\">\n";
echo "<td align=\"left\">".prod_desc($db->f("prod_id"))."
".$db->f("conf_nome")."</td>\n";
$prezzo=$db->f("conf_costo"); $pesuni=$db->f("conf_peso");
echo "<td align=\"center\">€".eur($prezzo)."</td>\n";
$qta=$this->items[$db->f("conf_id")];
if ($mod)
echo "<td align=\"center\">
<input name=\"qta".$db- size="20">f("conf_id")."\" type=\"text\" id=\"textfield\" value="".$qta."\" size=\"5\" maxlength=\"4\" class=\"textbox\"></td>\n";
else $message.= "<td align=\"center\">".$qta."</td>\n";
$stot=$prezzo*$qta;$totale+=$stot; $pes+=$pesuni*$qta;
$message.= "<td align=\"right\">".eur($stot)."</td>\n";
$message.= "</tr>\n";
}
$this->tot=$totale;$this->peso=$pes;
echo "<tr>";
if ($mod) {
echo "<td colspan=\"2\"></td>";
echo "<td colspan=\"2\" align=\"right\" bgcolor=\"#FFFF99\">
Totale:";
if ($totale!="") echo eur($totale); else echo eur(0);
echo "</p></td>";
}
else {
echo "<td class=\"text\"></td>";
echo "<td class=\"text\" colspan=\"2\" align=\"right\" bgcolor=\"#FFFF99\">Subtotale:
Spese di spedizione:
I.V.A.:
Totale</td>";
echo "<td class=\"text\" align=\"right\" bgcolor=\"#FFFF99\">";
if ($totale!="") echo eur($totale); else echo eur(0);echo "
";
$spese=$this->spe($this->italia);$totale+=$spese;
if ($spese!="") echo eur($spese); else echo eur(0);echo "
";
$iva=$totale*0.2;
if ($iva!="") echo eur($iva); else echo eur(0);echo "
";
$totale += $iva;
if ($totale!="") echo eur($totale); else echo eur(0);echo "";
echo "</td>";
$this->total=$totale;
}
} // else
echo "</tr></table>\n";
return; // $ids;
} // display()
function spe($ita) {
$p=$this->peso;
if ($ita) {
if ($p < 1) $spese = 0.00;
else if ($p <= 10) $spese = 5.16;
else if ($p > 10 and $p <= 20) $spese = 6.90;
else if ($p > 20 and $p <= 50) $spese = 11.62;
else if ($p > 50 and $p <= 100) $spese = 17.22;
else if ($p > 100 and $p <= 200) $spese = 30.99;
else if ($p > 200 and $p <= 300) $spese = 43.38;
else if ($p > 300 and $p <= 500) $spese = 74.37;
}
else {
if ($p <= 10) $spese = 17.22;
else if ($p > 10 and $p <= 20) $spese = 34.44;
else if ($p > 20 and $p <= 50) $spese = 68.88;
}
return $spese;
} //spe
function mailca($mod) {
$message.= "";
$message.= "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">\n";
$message.= "<tr align=\"center\" bgcolor=\"#FFCC66\" class=\"textbold\">";
if ($this->vuoto()) {
$message.= "<td align=\"center\"> Il carrello è vuoto</td>";
}
else {
$totale = 0; $pes = 0;
$ids = ""; // holds all the product ids in the cart
foreach($this->items as $id => $qta)
$ids .= ",$id";
$ids = substr($ids, 1);
$db = new DB;
$sql = "SELECT * FROM ecom_confezioni WHERE conf_id IN (" . $ids . ")";
$db->query($sql);
$message.= "<td width=\"65%\">Prodotto</td><td width=\"12%\">Prezzo</td><td width=\"12%\">Quantità</td>
<td width=\"13%\" align=\"center\">Totale</td></tr>";
while ($db->next_record()) {
$message.= "<tr class=\"text\" bgcolor=\"#FFFF99\">\n";
$message.= "<td align=\"left\">".prod_desc($db->f("prod_id"))."
".$db->f("conf_nome")."</td>\n";
$prezzo=$db->f("conf_costo"); $pesuni=$db->f("conf_peso");
$message.= "<td align=\"center\">€".eur($prezzo)."</td>\n";
$qta=$this->items[$db->f("conf_id")];
if ($mod)
$message.= "<td align=\"center\">
<input name=\"qta".$db- size="20">f("conf_id")."\" type=\"text\" id=\"textfield\" value="".$qta."\" size=\"5\" maxlength=\"4\" class=\"textbox\"></td>\n";
else $message.= "<td align=\"center\">".$qta."</td>\n";
$stot=$prezzo*$qta;$totale+=$stot; $pes+=$pesuni*$qta;
$message.= "<td align=\"right\">".eur($stot)."</td>\n";
$message.= "</tr>\n";
}
$this->tot=$totale;$this->peso=$pes;
$message.= "<tr>";
if ($mod) {
$message.= "<td colspan=\"2\"></td>";
$message.= "<td colspan=\"2\" align=\"right\" bgcolor=\"#FFFF99\">
Totale:";
if ($totale!="") $message.= eur($totale); else $message.= eur(0);
$message.= "</p></td>";
}
else {
$message.= "<td class=\"text\"></td>";
$message.= "<td class=\"text\" colspan=\"2\" align=\"right\" bgcolor=\"#FFFF99\">Subtotale:
Spese di spedizione:
I.V.A.:
Totale</td>";
$message.= "<td class=\"text\" align=\"right\" bgcolor=\"#FFFF99\">";
if ($totale!="") $message.= eur($totale); else $message.= eur(0);$message.= "
";
$spese=$this->spe($this->italia);$totale+=$spese;
if ($spese!="") $message.= eur($spese); else $message.= eur(0);$message.= "
";
$iva=$totale*0.2;
if ($iva!="") $message.= eur($iva); else $message.= eur(0);$message.= "
";
$totale += $iva;
if ($totale!="") $message.= eur($totale); else $message.= eur(0);$message.= "";
$message.= "</td>";
$this->total=$totale;
}
} // else
$message.= "</tr></table>\n";
return $message; // $ids;
} // mailca()
} // MyCart
?>