public static function getGuess($userid, $count) { self::$db = Database::getDB(); $foods = self::getCartByUserId($userid); $guess = array(); $catagories = array(); $all = json_decode(FoodDB::getAll()); foreach ($foods as $food) { $i = true; foreach ($catagories as $catagory) { if ($food->Food_Catagory == $catagory) { $i = false; break; } } if ($i == true) { $catagories[] = $food->Food_Catagory; } $pieces = explode(" ", $food->Food_Name); foreach ($pieces as $piece) { $pattern = "/" . $piece . "/i"; foreach ($all as $a) { if (preg_match($pattern, $a->Food_Name)) { $guess[] = $a->Food_id; } } } } foreach ($catagories as $catagory) { $fs = json_decode(FoodDB::getFoodsByCatagory($catagory)); foreach ($fs as $item) { $guess[] = $item->Food_id; } } $results = array_unique($guess); $r = array(); foreach ($results as $key => $n) { $r[] = $n; } $number = 0; $final = []; foreach ($foods as $food) { if (($key = array_search($food->Food_id, $r)) !== false) { unset($r[$key]); } } $r2 = array(); foreach ($r as $key => $n) { $r2[] = $n; } $r = $r2; if (count($r) <= $count) { $final = $r; } else { while ($number < $count) { $random = rand(0, count($r) - 1); $final[] = $r[$random]; unset($r[$random]); $r1 = array(); foreach ($r as $key => $n) { $r1[] = $n; } $r = $r1; $number++; } } $finalfoods = []; foreach ($final as $item) { $food = FoodDB::getFoodById($item); $finalfoods[] = $food; } return $finalfoods; }
include "bottomload.php"; } else { if ($action == "update") { ShoppingcartDB::updateSizeById($_GET["id"], $_GET["size"]); } else { if ($action == "updatecinema") { ShoppingcartDB::updateCinemaById($_GET["id"], $_GET["cinema"]); } else { if ($action == "updateq") { ShoppingcartDB::updateQuantityById($_GET["id"], $_GET["quantity"]); echo $_GET["id"] . " " . $_GET["quantity"]; } else { if ($page == "cart_list") { $cart = ShoppingcartDB::getCartByUserId(AuthModel::getUser('id')); $cinemas = FoodDB::getFoodCinema(); $guess = ShoppingcartDB::getGuess(AuthModel::getUser('id'), 6); include "food-shopping-cart.php"; } else { if ($page == "order_management") { include "Order_Management.php"; } } } } } } } } } } }
FoodDB::setHistory($_GET["id"]); $cartnumber = ShoppingcartDB::getCount(AuthModel::getUser('id')); include "food_product.php"; } else { if (isset($_POST["action"])) { if ($_POST["action"] == "add") { $count = ShoppingcartDB::insertItemById($_POST['foodId'], AuthModel::getUser('id'), $_POST['quantity'], $_POST['size'], $_POST['cinema']); } else { if ($_POST["action"] == "insertcomment") { $count = FoodDB::insertCommentById($_POST["orderitemid"], $_POST["foodid"], $_POST["comment"], $_POST["mark"], $_POST["satisfaction"], $_POST["file"], AuthModel::getUser('id')); } } } else { if (isset($_GET["foodid"])) { $food = FoodDB::getFoodById($_GET["foodid"]); $cartnumber = ShoppingcartDB::getCount(AuthModel::getUser('id')); include "CommentForm.php"; } else { if (isset($_POST["submit"])) { //path of the file in temp directory $file_temp = $_FILES['upfile']['tmp_name']; //original path and file name of the uploaded file $file_name = $_FILES['upfile']['name']; //size of the uploaded file in bytes $file_size = $_FILES['upfile']['size']; //type of the file(if browser provides) $file_type = $_FILES['upfile']['type']; //error number $file_error = $_FILES['upfile']['error']; echo $file_temp . "<br />"; echo $file_name . "<br />";
$orderdb->updateOrder($_GET['total'], 1, $_GET['phone'], $_GET['id']); foreach ($_GET['foodid'] as $key => $id) { $food = FoodDB::getFoodById($id); $stock = $food->getInstock() - $_GET['itemquantity'][$key]; $sale = $food->getSalesVolume() + 1; FoodDB::updateFoodById($id, $stock, $sale); } } else { if ($page == "ajax") { echo $_SESSION["food"]; } else { if ($page == "paying") { echo json_encode($_SESSION["food1"]); } } } } } } } } } if (isset($_POST["check"])) { $total = $_POST["total"]; $orderid = $orderdb->insertOrder(AuthModel::getUser('id')); foreach ($_POST["info"] as $item) { $food = ShoppingcartDB::getItemById($item[0]); $orderdb->insertOrderItem($orderid, $item[1], $item[2], $item[3], $item[4], $food); } $orderdb->updateOrder($total, 0, "", $orderid); }