Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

manager with the functionality to create cart cookie storing the Create a moltiu

ID: 3749941 • Letter: M

Question

manager with the functionality to create cart cookie storing the Create a moltiuser cart cart of nultiple users by userid. Here is an example of the format that you can use shopping for the cart cookiei CART COOKIE PORMAT ce2euser id2ticemligtyl pricel-item2:qty2uprice2e rtueridilitemliqtyliprice1-item2iqty2ipri parse string for to get multiple user carts parse string for to isolate userid and the user's parse string for - to get user's multiple cart items parse string for to get the item name,qty and price complete cart FUNCTIONALITY It creates an empty cookie cart it it does not already exiat. If the value with the text box is populated it will override the contents of the cart cookie with those provided Create Cart Cookie Get Cart Cookie Shows the complete contents of the cookie cart Removes the cart cookie along with its contents. There should be no cart cookie atter this operation. Del Cart Cookie Adds to the cart cookie a the new userid along with the contents provided. If the userid already exits, it wil1 override it. Create User Cart Get User Cart Del User Cart Add Cart Item By Userid Displays the cart of the userid provided. Removes the userid and its contents from the cart cookie It adds the item,qty and price of the new item into the shopping cart of the userid. If item exists it will override it. Get Cart Item by Userid And Item Displays the quantity and price of the given item name Name with its corresponding userid. The cost is also evaluated change Item Quantity By Userid It changes the quantity of the shopping cart item corresponding to the userid. corresponding to the userid. from the shopping cart corresponding to the given userid. corresponding to the userid. And Item Name Change Item Price By Userid And It changes the price of the shopping cart item Item Name Delete Cart Item By Userid and It removes the item(along with its quantity and price) Item Name. Compute User's Shopping Cart Cost It computes the total cost of the shopping cart By Providing Userid MULTIUSER CART MANAGER

Explanation / Answer

1.cart2jump.php -> for perations

<?php include('server.php');

// if the user is not logged in , they cant access this page

if (empty($_SESSION['username']))

{

header('location: login.php');

}

?>

<?php

include('server.php');

$userid = $_SESSION['username'];

$db = mysqli_connect('localhost','root','','main');

if(isset($_GET['do']))

{

$action = $_GET['do'];

switch($action)

{

case"add":

$usid = mysqli_real_escape_string($db, $_GET['userid']);

$ordid = mysqli_real_escape_string($db, $_GET['uid']);

$type = mysqli_real_escape_string($db, $_GET['type']);

$name = mysqli_real_escape_string($db, $_GET['name']);

$price = mysqli_real_escape_string($db, $_GET['price']);

$image = mysqli_real_escape_string($db, $_GET['image']);

$city = mysqli_real_escape_string($db, $_GET['city']);

$hname = mysqli_real_escape_string($db, $_GET['hname']);

$qty = 1;

$db = mysqli_connect('localhost','root','','main');

$result = mysqli_query($db, "SELECT * FROM foodcart");  

$count = 0;

if ($count==0)

{

$sql = "INSERT INTO foodcart (uid,ordid,type,qty,price,name,image,city,hname) VALUES ('$userid','$ordid','$type','$qty','$price','$name','$image','$city','$hname')";

mysqli_query($db, $sql);

header('location: foodcart.php');

}  

break;

case"remove":

$ordid = mysqli_real_escape_string($db, $_GET['ordid']);

$type = mysqli_real_escape_string($db, $_GET['type']);

$name = mysqli_real_escape_string($db, $_GET['name']);

$price = mysqli_real_escape_string($db, $_GET['price']);

$image = mysqli_real_escape_string($db, $_GET['image']);

$city = mysqli_real_escape_string($db, $_GET['city']);

$sql_item_delete = "DELETE FROM foodcart WHERE ordid='$ordid' AND uid = '$userid' AND name = '$name'AND price = '$price'";

$result = mysqli_query($db,$sql_item_delete)or die(mysqli_error($db).'-'. $sql_item_delete);

if($result){

header('location: foodcart.php');

}else{

$msg = "Cannot delete item";

header('location: foodcart.php');

}  

break;

case"removepurchase":

// Code of deleting a spesific items details from order

$ordid = mysqli_real_escape_string($db, $_GET['ordid']);

$type = mysqli_real_escape_string($db, $_GET['type']);

$name = mysqli_real_escape_string($db, $_GET['name']);

$price = mysqli_real_escape_string($db, $_GET['price']);

$image = mysqli_real_escape_string($db, $_GET['image']);

$city = mysqli_real_escape_string($db, $_GET['city']);

$sql_item_delete = "DELETE FROM foodcart WHERE ordid='$ordid' AND uid = '$userid'";

$result = mysqli_query($db,$sql_item_delete)or die(mysqli_error($db).'-'. $sql_item_delete);

if($result){

header('location: purchase.php');

}else{

$msg = "Cannot delete item";

header('location: purchase.php');

}  

break;

}

}

?>

2.foodcart.php -> cart where all ur cookies will apper

<?php include('server.php');
if (empty($_SESSION['username'])) {
header('location: login.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>
Foodpila.com
</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">

<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/fontAwesome.css">
<link rel="stylesheet" href="css/hero-slider.css">
<link rel="stylesheet" href="css/owl-carousel.css">
<link rel="stylesheet" href="css/templatemo-style.css">

<link href="https://fonts.googleapis.com/css?family=Spectral:200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">

<script src="js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
<style type="text/css">
.img_container{
width: 175px;
height: 175px;
}
</style>

</head>

<body>

<div class="header">
<div class="container">
<nav class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<button type="button" id="nav-toggle" class="navbar-toggle" data-toggle="collapse" data-target="#main-nav">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!--/.navbar-header-->
<div id="main-nav" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li><a href="pastorders.php">My Past Orders</a></li>
<li><a href="myorders.php">My Recent Orders</h4></a></li>
  
  
<li><a href="profile.php"><span class="glyphicon glyphicon-user"></span> Your Account</a></li>
<li><a href="foodcart.php"><span class="glyphicon glyphicon-shopping-cart"></span> Your Cart</a></li>
  
<?php if (isset($_SESSION['success'])): ?>
<?php unset($_SESSION['success']);?>
<?php endif ?>
<?php if (isset($_SESSION["username"])): ?>
<li><a href="index.php?logout='1'">Logout</a></li>
<?php endif ?>
</ul>

</div>
<!--/.navbar-collapse-->
</nav>
<!--/.navbar-->
</div>
<!--/.container-->
</div>
<!--/.header-->


<section class="banner">
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h4>Here you can find delecious foods</h4>
<h2>Foodpila</h2>
<p>Just at one click on your favorite dish, with in 2 hours , you will be enjoying that. Growing to be a grate comercial web hub for online food delivery</p>
<form action='search3.php' class="navbar-form navbar-center" role="search" method='GET'>
<center>
<div class="form-group input-group">
<input type="text" size="90" name="search" class="form-control" placeholder="search food...">
<span class="input-group-btn">
<button type="submit" name="submit" class="btn btn-success">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</center>
</form>


<form action='index.php' class="navbar-form navbar-center" method='POST'>
<center>
<?php include('errors.php'); ?>
<?php include('citylist.php'); ?>
</center>
</form>
<?php
echo "<center><h4>Please, select your city. You are now in $pty </h4> </center><br>";
?>
</div>
</div>
  
</div>
</section>

<section class="featured-food">
<div class="container">

<?php

include('server.php');
$suc = $_SESSION['username'];
@$search = $_SESSION['username'];
  
if(strlen($search)<=1)
echo "Search term too short";
else{
$db = mysqli_connect('localhost','root','','main');
$search_exploded = explode (" ", $search);
$x = "";
$construct = "";  

foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="uid LIKE '%$search_each%'";
else
$construct .="AND uid LIKE '%$search_each%'";
}
  
$constructs ="SELECT * FROM foodcart WHERE $construct";
$run = mysqli_query($db, $constructs);
  
$foundnum = mysqli_num_rows($run);
  
if ($foundnum==0)
{
echo "<div class='heading'>";
echo "<h2><em>Sorry, there are no items in your cart...<br> Add one to have in your cart ..</em></h2>";
echo "</div>";
echo "</div>";
}

else
{
echo "<div class='heading'>";
echo "<h2><em>$foundnum number of items are there in your cart .</em></h2>";
echo "</div>";
echo "</div>";

echo "<a href="purchase.php"><h3>";
echo "<span class='btn btn-danger btn-lg btn-block' >Proceed ";
echo "<span class='glyphicon glyphicon-fast-forward'></span></span>";
echo "</a>";


$per_page = 16;
$start = isset($_GET['start']) ? $_GET['start']: '';
$max_pages = ceil($foundnum / $per_page);
if(!$start)
$start=0;
$getquery = mysqli_query($db , "SELECT * FROM foodcart WHERE $construct LIMIT $start, $per_page");
  
echo "<div class='row'>";

while($runrows = mysqli_fetch_assoc($getquery))
{
$id = $runrows ['id'];
$uid = $runrows ['uid'];
$ordid = $runrows ['ordid'];
$type = $runrows ['type'];
$name = $runrows ['name'];
$price = $runrows ['price'];
$city = $runrows ['city'];
$qty = $runrows ['qty'];
$image = $runrows ['image'];
$hname = $runrows ['hname'];

echo "<div class='col-sm-3'>";
echo "<div class='food-item'>";

echo "<img src="products/$image" class='img_container' alt='image' > ";
echo "<div class='price'>";
echo "Rs. $price ";
echo "</div>";

echo "<div class='text-content'>";
echo "<p> $name , $city , $hname , Quantity = $qty </p>";
echo "</div>";

echo "<a href="cart2jump.php?do=remove&amp;ordid=$ordid&amp;type=$type&amp;name=$name&amp;price=$price&amp;city=$city&amp;image=$image">";
echo "<span class='btn btn-warning'>Remove ";
echo "<span class='glyphicon glyphicon-trash'></span></span>";
echo "</a>";

echo "<a href="editqty.php?do=edt&amp;ordid=$ordid&amp;id=$id&amp;type=$type&amp;name=$name&amp;price=$price&amp;city=$city&amp;image=$image">";
echo "<span class='btn btn-success'>Edit Quantity ";
echo "<span class='glyphicon glyphicon-edit'></span></span>";
echo "</a>";


echo "</div>";
echo "</div>";

}

echo "</div>";
echo "</div>";
echo "<a href="purchase.php"><h3>";
echo "<span class='btn btn-danger btn-lg btn-block' >Proceed ";
echo "<span class='glyphicon glyphicon-fast-forward'></span></span>";
echo "</a>";
echo "</section>";

//Pagination Starts
echo "<center>";
  
$prev = $start - $per_page;
$next = $start + $per_page;
$adjacents = 3;
$last = $max_pages - 1;
  
if($max_pages > 1)
{
//previous button
if (!($start<=0))
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$prev">Prev</a> ";   
  
//pages
if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
$i = 0;
for ($counter = 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i"><b>$counter</b></a> ";
}
else {
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i">$counter</a> ";
}  
$i = $i + $per_page;
}
}
elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if(($start/$per_page) < 1 + ($adjacents * 2))   
{
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($i == $start){
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i"><b>$counter</b></a> ";
}
else {
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i">$counter</a> ";
}
$i = $i + $per_page;
}
  
}
//in middle; hide some front and some back
elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2))
{
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=0">1</a> ";
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$per_page">2</a> .... ";

$i = $start;
for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++)
{
if ($i == $start){
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i"><b>$counter</b></a> ";
}
else {
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i">$counter</a> ";
}
$i = $i + $per_page;   
}
  
}
//close to end; only hide early pages
else
{
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=0">1</a> ";
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$per_page">2</a> .... ";

$i = $start;   
for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i"><b>$counter</b></a> ";
}
else {
echo " <a href="foodcart.php?search=$search&amp;submit=Search+source+code&amp;start=$i">$counter</a> ";
}
$i = $i + $per_page;   
}
}
}</body></html>

3.editqty.php

<?php include('server.php');

// if the user is not logged in , they cant access this page

if (empty($_SESSION['username']))

{

header('location: login.php');

}

?>

<?php

if(isset($_POST['upload']))

{

$db = mysqli_connect('localhost','root','','main');

$qty = mysqli_real_escape_string($db, $_POST['qty']);

if(isset($_GET['do']))

{

$action = $_GET['do'];

switch($action)

{

case"change":

$id = mysqli_real_escape_string($db, $_GET['id']);

$sql = "UPDATE foodcart SET qty = '$qty' WHERE id = '$id'";

$res = mysqli_query($db, $sql) or die("coulde not make change".mysqli_error($db));

header('location: foodcart.php');

}

}

}

?>


<?php
$db = mysqli_connect('localhost','root','','main');
$userid = $_SESSION['username'];

if(isset($_GET['do']))
{
$action = $_GET['do'];
switch($action)
{
case"edt":
$id = mysqli_real_escape_string($db, $_GET['id']);
$ordid = mysqli_real_escape_string($db, $_GET['ordid']);
$type = mysqli_real_escape_string($db, $_GET['type']);
$name = mysqli_real_escape_string($db, $_GET['name']);
$price = mysqli_real_escape_string($db, $_GET['price']);
$image = mysqli_real_escape_string($db, $_GET['image']);
$city = mysqli_real_escape_string($db, $_GET['city']);
$getquery = mysqli_query($db, "SELECT * FROM foodcart WHERE id='$id'");

echo "<div class='row'>";

while($runrows = mysqli_fetch_assoc($getquery))
{
$id = $runrows ['id'];
$qty = $runrows ['qty'];
$uid = $runrows ['uid'];
$type = $runrows ['type'];
$name = $runrows ['name'];
$price = $runrows ['price'];
$city = $runrows ['city'];
$image = $runrows ['image'];

echo "<div class='col-sm-6'>";
echo "<div class='food-item'>";

echo "<img src="products/$image" class='img_container' alt='image' > ";
echo "<div class='price'>";
echo "Rs. $price ";
echo "</div>";

echo "<div class='text-content'>";
echo "<p> present quantity = $qty .</p>";
echo "</div>";

echo "<form action='editqty.php?do=change&id=$id' method='POST'>";
echo "<center>";
echo "<div class='input-group'>";
echo "<input type='number' name='qty' min='0.5' step='0.5' placeholder='enter new qty'>";
echo "<button type='submit' name='upload' class='btn btn-success'>change quantity</button>";
echo "</div>";
echo "</center>";
echo "</form>";

echo "</div>";
echo "</div>";

}

echo "</div>";

echo "</div>";
echo "</section>";   

}
}
?>