PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php class basket { var $items; var $empty; var $cartid; var $voucher_id_set; function basket() { global $cartid; global $vat_rate; global $voucher_id_set; global $outmail; global $conn; global $_COOKIE; global $_POST; $voucher_id_set = 0; $number = 0; if (isset($_COOKIE["cart_id"])) { $cartid = ClearString(substr($_COOKIE["cart_id"], 0, 10)); $testcartid = $cartid; settype($testcartid, "integer"); if ($testcartid > 0) { $strsql = "SELECT * from g_tempbasket where basket_id = '" . clearstring(substr($cartid, 0, 10)) . "'"; $result = safedb_query($strsql); $number = mysqli_num_rows($result); } else { $number = 0; } } else { // force cart creation $number = 0; } if ($number == 0) { $todaydate = date("Y-m-d h:i:s"); $strsql = "INSERT INTO g_tempbasket (basket_id,date) "; $strsql .= "VALUES (NULL,'$todaydate')"; safedb_query($strsql); $newcartid = mysqli_insert_id($conn); if ($outmail == 1) { setcookie("cart_id", $newcartid, time() + (24 * 3600), "", ".website.co.uk", 1); setcookie("voucher_id", "", 0, "", ".website.co.uk", 1); } else { setcookie("cart_id", $newcartid, time() + (24 * 3600)); setcookie("voucher_id", "", 0); } $cartid = $newcartid; } $strsql = "SELECT t.product_id, p.descript, p.cost, t.qty "; $strsql .= "FROM g_tempbasket AS tb, g_product AS p, g_tempitems AS t "; $strsql .= "WHERE tb.basket_id = t.basket_id "; $strsql .= "AND t.product_id = p.product_id "; $strsql .= "AND tb.basket_id = " . $cartid; $result = safedb_query($strsql); $number = mysqli_num_rows($result); mysqli_free_result($result); //$this->items=$result; if ($number != 0) { $this->empty = false; } else { $this->empty = true; } } //function function additem($id, $name, $addcount) { global $cartid; // Get product info to add $strsql = "SELECT descript, cost, no_vat FROM g_product "; $strsql .= "WHERE product_id = '" . $id . "'"; $prodaddresult = safedb_query($strsql); $prodaddrow = mysqli_fetch_assoc($prodaddresult); $prodname = $prodaddrow["descript"]; $prodcost = $prodaddrow["cost"]; $prodnovat = $prodaddrow["no_vat"]; $strsql = "SELECT qty FROM g_tempitems "; $strsql .= "WHERE basket_id = " . $cartid; $strsql .= " AND product_id = '" . $id . "'"; $result = safedb_query($strsql); $number = mysqli_num_rows($result); $strsqls = "SELECT prod_code FROM g_ship_options "; $strsqls .= "WHERE prod_code = '" . $id . "'"; $sresult = safedb_query($strsqls); $snumber = mysqli_num_rows($sresult); if ($number == 0) { if ($id == "" || $addcount < 1) { // Basic anti-bot validation header("Location: index.php"); exit; } if ($snumber != 0) { // Item is shipping - mark in basket $strsql = "INSERT INTO g_tempitems "; $strsql .= "(basket_id, product_id, qty, shipping, descript, cost, no_vat) "; $strsql .= "VALUES (".$cartid.", '".$id."', ".$addcount.", 1, '".$prodname."', '".$prodcost."', '".$prodnovat."')"; } else { // Non-shipping item $strsql = "INSERT INTO g_tempitems "; $strsql .= "(basket_id, product_id, qty, shipping, descript, cost, no_vat) "; $strsql .= "VALUES (".$cartid.", '".$id."', ".$addcount.", 0, '".$prodname."', '".$prodcost."', '".$prodnovat."')"; } } else { if ($id == "") { // Basic anti-bot validation header("Location: index.php"); exit; } $currow = mysqli_fetch_assoc($result); $current = $currow["qty"]; $new = $current + $addcount; if ($new <= 0) { $new = 1; } $strsql = "UPDATE g_tempitems "; $strsql .= "SET qty = ".$new.", "; $strsql .= "descript = '".$prodname."', "; $strsql .= "cost = ".$prodcost.", "; $strsql .= "no_vat = ".$prodnovat." "; $strsql .= "WHERE basket_id = ".$cartid." "; $strsql .= "AND product_id = '".$id."'"; } mysqli_free_result($result); safedb_query($strsql); $this->empty = false; }
Show:  
Copy Clear