Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Elswerky
Last active June 11, 2017 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahmed-Elswerky/a8d081464a0c6645143926f6399cb234 to your computer and use it in GitHub Desktop.
Save Ahmed-Elswerky/a8d081464a0c6645143926f6399cb234 to your computer and use it in GitHub Desktop.
This gist is Shantah (http://shantah.me.pn) (shopping site I'm building)
<?php
ob_start();
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
include 'mysqli.php';
if(isset($_COOKIE['user_id']))
$uid = $_COOKIE['user_id'];
switch($_REQUEST['t'])
{
case "sign-in":sign_in();break;
case "sign-up":sign_up();break;
case "logout":logout();break;
case "products-filling":product_filling();break;
case "reset-password":reset_password($_REQUEST['e']);break;
case "market-location":market_location($_REQUEST['g']);break;
case "markets-build":markets_build();break;
case "hello":hello();break;
case "bill-add":bill_add($_REQUEST['pro']);break;
case "bill-remove":bill_remove($_REQUEST['pro']);break;
case "bill-edit":bill_edit($_REQUEST['pro'],$_REQUEST['q']);break;
case "bill-trunc":bill_trunc();break;
case "checkout-b":checkout_b();break;
case "cart-f":cart_f($_REQUEST['ma']);break;
case "marekts-f":markets_f($_REQUEST['bid'],$_REQUEST['mid']);break;
case "req-f":req_f($_REQUEST['bid'],$_REQUEST['mid']);break;
case "bag-done":bag_done($_REQUEST['bid']);break;
case "meals-add":meals_add();break;
case "meals-b-f":meals_b_f();break;
case "meals-pick":meals_pick();break;
case "market-type-f":market_type_fill();break;
case "market-update":market_update($_REQUEST['id']);break;
default:ob_end_clean();header("Location: ./");break;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function sign_in(){
echo "sign_in";
$email = filter_input(INPUT_POST,'user_email');
$password = $_POST['password'];
$result = $GLOBALS['conn']->query("SELECT name,id,password,major FROM users WHERE email='$email'");
$row = $result->fetch_assoc();
if($row){
if(password_verify($password,$row['password']))
{
echo "<br>password is good <br>";
$_SESSION['user_id'] = $row['id'];
$_SESSION['user_name'] = $row['name'];
$_SESSION['user_email'] = $email;
$_SESSION['major'] = $row['major'];
$result1 = $GLOBALS['conn']->query("SELECT id FROM markets WHERE user_id='$_SESSION[user_id]'");
$row = $result1->fetch_assoc();
$_SESSION['market_id'] = $row['id'];
setcookie("user_id",$_SESSION['user_id'],time()+(60*24*60*60));
setcookie("user_name",$_SESSION['user_name'],time()+(60*24*60*60));
setcookie("user_email",$_SESSION['user_email'],time()+(60*24*60*60));
setcookie("major",$_SESSION['major'],time()+(60*24*60*60));
$_SESSION['sign_error'] = "";
header("Location: ./");
}
else {echo $_SESSION['sign_error'] = "Password Wrong";header("Location: ./sign.php");}
}
else {$_SESSION['sign_error'] = "Email is wrong or doesn't exist";header("Location: ./sign.php");}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function sign_up(){
echo "sign_up";
$name = filter_input(INPUT_POST,'user_name');
$email = filter_input(INPUT_POST,'user_email');
$major = filter_input(INPUT_POST,'major');
$password = password_hash($_POST['password'],PASSWORD_BCRYPT);
$result1 = $GLOBALS['conn']->query("SELECT email FROM users WHERE email='$email'");
$row1=$result1->fetch_assoc();
if(!$row1){
$insert = $GLOBALS['conn']->query("INSERT INTO users (name,email,major,password) VALUES ('$name','$email','$major','$password')");
$result = $GLOBALS['conn']->query("SELECT name,id,password,major FROM users WHERE email='$email'");
$row = $result->fetch_assoc();
if($row)
{
echo "<br> Everything is good <br>";
$_SESSION['user_id'] = $row['id'];
$_SESSION['user_name'] = $name;
$_SESSION['user_email'] = $email;
$_SESSION['major'] = $major;
setcookie("user_id",$_SESSION['user_id'],time()+(60*24*60*60));
setcookie("user_name",$_SESSION['user_name'],time()+(60*24*60*60));
setcookie("user_email",$_SESSION['user_email'],time()+(60*24*60*60));
setcookie("major",$_SESSION['major'],time()+(60*24*60*60));
echo "<br>result ok<br>";
$_SESSION['sign_error'] = "";
header("Location: ./");
}
else die("something happened!").$GLOBALS['conn']->error();
}
else {
echo "<br>result not ok<br>";$_SESSION['sign_error'] = "Email is Already there!";header("Location: ./sign.php");}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function product_filling(){
$name = filter_input(INPUT_POST,"name");
$price = filter_input(INPUT_POST,"price");
$type = filter_input(INPUT_POST,"type");
$market_id = filter_input(INPUT_POST,"market_id");
$GLOBALS['conn']->query("INSERT INTO products (name,price,type,market_id) VALUES ('$name','$price','$type','$market_id')");
header("Location: ./products.php?id=".$_SESSION['market_id']);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function logout(){
session_destroy();
setcookie("user_name","");
setcookie("user_email","");
setcookie("user_id","");
ob_clean();
header("Location: ./");
}
///////////////////////////////////////////////////////////////////////////////////////////////////
function reset_password($e){
echo "$e";
$result = $GLOBALS['conn']->query("SELECT password FROM users WHERE email='$e'");
$row = $result->fetch_assoc();
if($row){
$headers = 'From: <daha.amd11212@gmail.com>' . "\r\n";
mail('$e', 'Reset your passowrd', "If you didn't demand to reset your password, just ignore this<br>".$_SERVER['HTTP_HOST']."/funcs.php?t=password-reset&p=".$row['password'],$headers);
echo "done";
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function market_type_fill(){
$res = $GLOBALS['conn']->query("SELECT DISTINCT type FROM markets");
if($res){
$row = $res->fetch_assoc();
echo "
<option>what you selling</option>
<option value='".$row['type']."'>".$row['type']."</option>
";
while($row = $res->fetch_assoc()){
echo "<option value='".$row['type']."'>".$row['type']."</option>";
}
echo "<option value='others'>others</option>";
}
else echo "what!!";
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
*/
function markets_build(){
$conn = $GLOBALS['conn'];
$res_id = $conn->query("SELECT max(id) FROM markets");
if($res_id)
$row_id = $res_id->fetch_assoc();
$mid = $row_id['max(id)'];
///////////////////////////////////////////////////////////////////
if(isset($_FILES['market_image'])){
echo "<br>upload is set<br>";
$target_dir = "./uploads/";
$ex = explode(".",$_FILES['market_image']['name']);
$_FILES['market_image']['name'] = $mid.".".end($ex);
echo $_FILES['market_image']['name'];
$target_file = $target_dir . basename($_FILES["market_image"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["market_image"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["market_image"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["market_image"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["market_image"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
echo "<br>process successfully done";
}
else die( "where file!");
////////////////////////////////////////////
$name = filter_input(INPUT_POST,"name");
if(!empty($_POST['others']))
$type = filter_input(INPUT_POST,"others");
else $type = filter_input(INPUT_POST,"type");
$telephone = filter_input(INPUT_POST,"telephone");
if(!empty($_POST['telephone2']))
$telephone .= ",".filter_input(INPUT_POST,"telephone2");
$governorate = filter_input(INPUT_POST,"governorate");
if(($conn->query("SELECT name FROM markets WHERE name='$name'")) === true)
{ $_SESSION['market_build_error'] = "the market is already there!";echo "not good";}
else {
$conn->query("INSERT INTO markets (name,type,telephones,governorate,user_id) VALUES ('$name','$type','$telephone','$governorate','$_SESSION[user_id]')");
$result = $conn->query("SELECT id FROM markets WHERE name='$name'");
$row = $result->fetch_assoc();
$_SESSION['market_id'] = $row['id'];
$_SESSION['market_name'] = $name;
setcookie("market_id",$_SESSION['market_id'],time()+(60*24*60*60));
setcookie("market_name",$_SESSION['market_name'],time()+(60*24*60*60));
echo "good";
}
header("Location: ./");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
function market_location($a){
$result = $GLOBALS['conn']->query("SELECT id,name,type,governorate,telephones FROM markets WHERE governorate='$a'");
$row = $result->fetch_assoc();
if($row){
echo "
<div class='market'>
<a href='./products.php?id=$row[id]'><img class='m_i' src='./uploads/$row[id].jpg'></a>
<a class='m_n' href='./products.php?id=$row[id]'>$row[name]</a>
<p class='m_t'>sells $row[type]</p>
<a class='m_t' href='tel:$row[telephones]'>$row[telephones]</a>
<a class='m_l' >$row[governorate]</a>
</div>
";
while($row = $result->fetch_assoc()){
echo "
<div class='market'>
<a href='./products.php?id=$row[id]'><img class='m_i' src='./uploads/$row[id].jpg'></a>
<a class='m_n' href='./products.php?id=$row[id]'>$row[name]</a>
<p class='m_t'>sells $row[type]</p>
<a class='m_t' href='tel:$row[telephones]'>$row[telephones]</a>
<a class='m_l' >$row[governorate]</a>
</div>
";
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function hello(){
echo "hello";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* function bill(){
$i=0;
$res = $GLOBALS['conn']->query("SELECT max(id) FROM bags");
if($res){
$row = $res->fetch_assoc();
$id = $row['max(id)'] + 1;
}
else $id = 1;
while(!is_null($_POST['product'][$i])){
$product = $_POST['product'][$i];
$quantity = $_POST['quantity'][$i];
$GLOBALS['conn']->query("INSERT INTO bags (id,user_id,product_id,market_id,quantity,date) VALUES ('$id','$_SESSION[user_id]','$product','$_POST[market_id]','$quantity',current_date())");
$i++;
}
header("Location: /bill.php");
}*/
//////////////////////////////////////////////////////////////////////////////////////////
function bill_add($pro){
$result = $GLOBALS['conn']->query("SELECT price FROM products WHERE id='$pro'");
if($result)
$row = $result->fetch_assoc();
$price = $row['price'];
//echo "okay ".$price." user_id: ".$id." ";
$GLOBALS['conn']->query("INSERT INTO cache (user_id,product_id,market_id,quantity,price,date) VALUES ('$GLOBALS[uid]','$pro',(SELECT market_id FROM products WHERE id='$pro'),'1','$price',current_date())");
$res = $GLOBALS['conn']->query("SELECT COUNT(num) FROM cache WHERE user_id='$GLOBALS[uid]'");
if($res)
$row = $res->fetch_assoc();
echo $row['COUNT(num)'];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function bill_edit($pro,$q){
$result = $GLOBALS['conn']->query("SELECT price FROM products WHERE id='$pro'");
if($result)
$row = $result->fetch_assoc();
$price = (($row['price'])*$q);
$GLOBALS['conn']->query("UPDATE cache SET quantity='$q',price='$price' WHERE product_id='$pro' AND user_id='$GLOBALS[uid]'");
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function bill_remove($pro){
$GLOBALS['conn']->query("DELETE FROM cache WHERE product_id='$pro' AND user_id='$GLOBALS[uid]'");
$res = $GLOBALS['conn']->query("SELECT COUNT(num) FROM cache WHERE user_id='$GLOBALS[uid]'");
if($res)
$row = $res->fetch_assoc();
echo $row['COUNT(num)'];
}
///////////////////////////////////////////////////////////////////////////////////////////
function bill_trunc(){
$GLOBALS['conn']->query("DELETE FROM cache WHERE user_id='$GLOBALS[uid]'");
$res = $GLOBALS['conn']->query("SELECT COUNT(num) FROM cache WHERE user_id='$GLOBALS[uid]'");
if($res)
$row = $res->fetch_assoc();
echo $row['COUNT(num)'];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function cart_f($ma){
if($ma == 'consumer'){
$res = $GLOBALS['conn']->query("SELECT product_id,price,quantity FROM cache WHERE user_id='$GLOBALS[uid]' ");
if($res){
$ro = $res->fetch_assoc();
$result_p = $GLOBALS['conn']->query("SELECT name,market_id FROM products WHERE id='$ro[product_id]'");
if($result_p) {
$row_p = $result_p->fetch_assoc();
$result1 = $GLOBALS['conn']->query("SELECT name FROM markets WHERE id='$row_p[market_id]'");
$row1 = $result1->fetch_assoc();
if(count($ro) >1) {
echo "
<tr>
<td>Product</td>
<td>Quantity</td>
<td>price</td>
<td>market</td>
</tr>
<tr>
<td>$row_p[name]</td>
<td>$ro[quantity]</td>
<td>$ro[price]</td>
<td>$row1[name]</td>
</tr> ";
while ($ro = $res->fetch_assoc()) {
$result_p = $GLOBALS['conn']->query("SELECT name,market_id FROM products WHERE id='$ro[product_id]'");
if ($result_p) {
$row_p = $result_p->fetch_assoc();
$result1 = $GLOBALS['conn']->query("SELECT name FROM markets WHERE id='$row_p[market_id]'");
$row1 = $result1->fetch_assoc();
echo "
<tr>
<td>$row_p[name]</td>
<td>$ro[quantity]</td>
<td>$ro[price]</td>
<td>$row1[name]</td>
</tr>";
}
}
}
else echo " ";
}
}
}
else if($ma == 'market_admin'){
$res_o = $GLOBALS['conn']->query("SELECT market_id,bag_id FROM ");
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function markets_f($bid,$mid){
$res = $GLOBALS['conn']->query("SELECT product_id,price,quantity FROM bags WHERE user_id='$GLOBALS[uid]' AND id='$bid' AND market_id='$mid' ");
if($res){
$ro = $res->fetch_assoc();
$result_p = $GLOBALS['conn']->query("SELECT name,market_id FROM products WHERE id='$ro[product_id]'");
if($result_p) {
$row_p = $result_p->fetch_assoc();
$result1 = $GLOBALS['conn']->query("SELECT name FROM markets WHERE id='$row_p[market_id]'");
$row1 = $result1->fetch_assoc();
if(count($ro) >1) {
echo "
<tr>
<td>Product</td>
<td>Quantity</td>
<td>price</td>
<td>market</td>
</tr>
<tr>
<td>$row_p[name]</td>
<td>$ro[quantity]</td>
<td>$ro[price]</td>
<td>$row1[name]</td>
</tr> ";
while ($ro = $res->fetch_assoc()) {
$result_p = $GLOBALS['conn']->query("SELECT name,market_id FROM products WHERE id='$ro[product_id]'");
if ($result_p) {
$row_p = $result_p->fetch_assoc();
$result1 = $GLOBALS['conn']->query("SELECT name FROM markets WHERE id='$row_p[market_id]'");
$row1 = $result1->fetch_assoc();
echo "
<tr>
<td>$row_p[name]</td>
<td>$ro[quantity]</td>
<td>$ro[price]</td>
<td>$row1[name]</td>
</tr>";
}
}
}
else echo " ";
}
else $GLOBALS['conn']->error;
}
else $GLOBALS['conn']->error;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function req_f($bid,$mid){
$res = $GLOBALS['conn']->query("SELECT product_id,price,quantity FROM bags WHERE id='$bid' AND market_id='$mid' ");
if($res){
$ro = $res->fetch_assoc();
$result_p = $GLOBALS['conn']->query("SELECT name,market_id FROM products WHERE id='$ro[product_id]'");
if($result_p) {
$row_p = $result_p->fetch_assoc();
$result1 = $GLOBALS['conn']->query("SELECT name FROM markets WHERE id='$row_p[market_id]'");
$row1 = $result1->fetch_assoc();
if(count($ro) >1) {
echo "
<tr>
<td>Product</td>
<td>Quantity</td>
</tr>
<tr>
<td>$row_p[name]</td>
<td>$ro[quantity]</td>
</tr> ";
while ($ro = $res->fetch_assoc()) {
$result_p = $GLOBALS['conn']->query("SELECT name,market_id FROM products WHERE id='$ro[product_id]'");
if ($result_p) {
$row_p = $result_p->fetch_assoc();
$result1 = $GLOBALS['conn']->query("SELECT name FROM markets WHERE id='$row_p[market_id]'");
$row1 = $result1->fetch_assoc();
echo "
<tr>
<td>$row_p[name]</td>
<td>$ro[quantity]</td>
</tr>";
}
}
}
else echo " ";
}
else $GLOBALS['conn']->error;
}
else $GLOBALS['conn']->error;
}
///////////////////////////////////////////////
function checkout_b(){
$res_c = $GLOBALS['conn']->query("SELECT product_id,market_id,price,quantity,date FROM cache WHERE user_id='$GLOBALS[uid]'");
if($res_c){
$row_c = $res_c->fetch_assoc();
$res_mid = $GLOBALS['conn']->query("SELECT max(id) FROM bags");
echo "1";
if($res_mid){
$row_mid = $res_mid->fetch_assoc();
$mid = $row_mid['max(id)'];
$mid++;}
else $mid = 1;
$product = $row_c['product_id'];
$market = $row_c['market_id'];
$quantity = $row_c['quantity'];
$price = $row_c['price'];
$date = $row_c['date'];
$GLOBALS['conn']->query("INSERT INTO bags (id,user_id,product_id,market_id,quantity,price,date) VALUES ('$mid','$GLOBALS[uid]','$product','$market','$quantity','$price','$date')");
while($row_c = $res_c->fetch_assoc()){
$product = $row_c['product_id'];
$market = $row_c['market_id'];
$quantity = $row_c['quantity'];
$price = $row_c['price'];
$date = $row_c['date'];
$GLOBALS['conn']->query("INSERT INTO bags (id,user_id,product_id,market_id,quantity,price,date) VALUES ('$mid','$GLOBALS[uid]','$product','$market','$quantity','$price','$date')");
}
$GLOBALS['conn']->query("TRUNCATE TABLE cache");
$res_b = $GLOBALS['conn']->query("SELECT DISTINCT market_id FROM bags WHERE id='$mid'");
if($res_b){
$row_b = $res_b->fetch_assoc();
if($row_b){
$market = $row_b['market_id'];
$GLOBALS['conn']->query("INSERT INTO operations (market_id,bag_id,state) VALUES ('$market','$mid','not yet')");
echo $GLOBALS['conn']->error;
while($row_b = $res_b->fetch_assoc()){
$market = $row_b['market_id'];
$GLOBALS['conn']->query("INSERT INTO operations (market_id,bag_id,state) VALUES ('$market','$mid','not yet')");
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
function bag_done($bid){
$res_op = $GLOBALS['conn']->query("UPDATE operations SET state='Done' WHERE bag_id='$bid'");
if($res_op)
echo "Done";
else echo "touib";
}
//////////////////////////////////////////////////////////////////////////////////
function meals_add(){
$name = htmlspecialchars($_REQUEST['n']);
$color = htmlspecialchars($_REQUEST['c']);
$GLOBALS['conn']->query("INSERT INTO meals (name,user_id,color) VALUES ('$name','$GLOBALS[uid]','$color')");
}
////////////////////////////////////
function meals_b_f(){
$res = $GLOBALS['conn']->query("SELECT name,color FROM meals WHERE user_id='$GLOBALS[uid]' ORDER BY id ");
if($res){
$row = $res->fetch_assoc();
echo "<div class='meal' style='background:#" . $row['color'] . ";'>" . $row['name'] . "</div>";
while($row = $res->fetch_assoc()){
echo "<div class='meal' style='background:#" . $row['color'] . ";'>" . $row['name'] . "</div>";
}
}
}
////////////////
function meals_pick(){
$res = $GLOBALS['conn']->query("SELECT DISTINCT name,color FROM meals WHERE user_id != '$GLOBALS[uid]' ORDER BY RAND()");
if($res){
$row = $res->fetch_assoc();
$name = $row['name'];
$color = $row['color'];
echo "<div class='mmeal' style='background:#" . $color . ";'>" . $name . "</div><div class='mplus' style='background:#" . $color . ";' title='Add to my list' onclick='meals_adds(\"".$name."\",\"".$color."\")'>+</div><br>";
while($row = $res->fetch_assoc()){
$name = $row['name'];
$color = $row['color'];
echo "<div class='mmeal' style='background:#" . $color . ";'>" . $name . "</div><div class='mplus' style='background:#" . $color . ";' title='Add to my list' onclick='meals_adds(\"".$name."\",\"".$color."\")'>+</div><br>";
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////
function market_update($id){
if(isset($_FILES['market_image'])){
echo "<br>upload is set<br>";
$target_dir = "./uploads/";
$ex = explode(".",$_FILES['market_image']['name']);
$_FILES['market_image']['name'] = $id.".jpg";
echo $_FILES['market_image']['name'];
$target_file = $target_dir . basename($_FILES["market_image"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["market_image"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
unlink($target_file);
echo "Sorry, file already exists.";
$target_dir = "./uploads/";
$ex = explode(".",$_FILES['market_image']['name']);
$_FILES['market_image']['name'] = $id.".jpg";
echo $_FILES['market_image']['name'];
$target_file = $target_dir . basename($_FILES["market_image"]["name"]);
$uploadOk = 1;
}
// Check file size
if ($_FILES["market_image"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["market_image"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["market_image"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
echo "<br>process successfully done";
header("Location: ./");
}
else die( "where file!");
}
ob_end_flush();
*{padding:0;margin:0;transition:0.3s;}
html{height:100%;background:linear-gradient(rgba(0,0,0,0.3),rgba(0,0,0,0.3)),url('backi.jpg') fixed;background-position:center;background-size:cover;}
a{color:rgba(255, 255, 255, 0.74);}
a:hover{color:rgb(255, 255, 255) !important;border-color:white}
input[type="submit"]{ padding: 2px;
border-radius: 2px;
border: transparent;
background: white;
font-weight: bold;
font-family: monospace;
display: block;
border: transparent !important;
margin: 11px;
transition:0.3s;}
input[type="submit"]:hover{background:#111;color:white;cursor:pointer;}
form{text-align:center;text-align:-webkit-center}
table{width:100%}
table *{
padding:7px;
}
table input[type='text'],table input[type='number']{
padding: 2px;
width: 30px;
border-radius: 2px;
border: transparent;
box-shadow: 0 0 1px 1px #272727;
}
#navbar{top:0;background:#336088;position:fixed;display:block;width:100%;}
#navbar_before{content:"";display:block;width:100%;}
#navbar #logo{display:inline-block;}
#navbar #logo img{width:103px;padding:3px 0 0 10px;display:inline-block;}
#meals{
position:fixed;
top:110px;
right:0px;
}
.meal{
margin: 0.2em;
padding: 2px;
color: white;
font-family: monospace;
font-size: 17px;
font-weight: bolder;
box-shadow: 0 0 0.5px 0.5px rgba(43, 43, 43, 0.44);
border-radius: 2px;
text-shadow: 2px 1px 3px black;
}
#meals_l{
background:white;
border-top-left-radius:2px;
border-bottom-left-radius:2px;
display:inline-block;
}
#meals_l i{
padding:4px;
border-right: 5px solid #4d4de6;
}
#meals_l i:hover{
cursor:pointer;
border-right: 5px solid #111;
}
#meals_r{
padding:5px;
background:white;
display:inline-block;
float:right;
box-shadow:0 2px 2px 1px;
}
#meals_r fieldset{
padding:3px;
text-align:center;
text-align:-webkit-center;
}
#meals_r fieldset legend{
font-family:arial;
font-size:15px;
font-weight:bolder;
}
#meals_r fieldset #meals_b{
padding:3px;
overflow-y: scroll;
max-height: 340px;
}
#meals_r #meals_button{
padding:2px;
}
#meals_in{
position: fixed;
width: 70%;
background: rgba(43, 43, 43, 0.65);
height: 50%;
color: white;
padding: 15%;
text-align:center;
text-align:-webkit-center;
}
#meals_in p{
margin:2%;
font-weight:bold;
}
#meals_in #mleft{
display:inline-block;
float:left;
max-height: 350px;
overflow-y: scroll;
padding: 5px;
background:rgba(255, 255, 255, 0.89);
border-radius:5px;
}
#meals_in .mmeal{
display:inline-block;
padding:2px;
}
#meals_in .mplus{
display:inline-block;
padding:3px;
color:white;
border-radius:2px;
margin:3%;
}
#meals_in .mplus:hover{
cursor:pointer;
box-shadow: 0 0 2px 1px #3a3a3a;
}
#meals_buttons input{
border-radius:3px;
padding:3px;
margin:2px;
display:inline-block;
border:2px solid transparent;
color:white;
font-family:monospace;
font-weight:bolder;
}
#meals_buttons input:hover{
cursor:pointer;
background:#272727 !important;
}
#meals_buttons input[value="Add"]{
background:#4747da;
}
#meals_buttons input[value="Random"]{
background:#c54848;
}
#meals_buttons input[value="Reset"]{
background:#585858;
}
#navbar #user{float:right;margin-right:15%;padding:15px;}
#navbar #user a{
color:rgba(255, 255, 255, 0.74);
font-family: monospace;
font-size: 20px;
text-decoration: none;
font-weight: bold;
}
#navbar #sign_a{
float: right;
margin: 0.5% 15%;
border: 2px solid rgba(255, 255, 255, 0.7);
color: rgba(255, 255, 255, 0.87);
vertical-align: middle;
padding: 7px;
font-weight: bold;
text-decoration:none;
border-radius:1px
}
#navbar #bill_d{
float: right;
margin: 0.7%;
background: white;
padding: 5px 5px 5px 20px;
font-family: monospace;
position:relative;
}
#navbar #bill_d div{
display:inline-block;
}
#navbar #bill_d:hover{
cursor:pointer;
}
#navbar #bill_n:before{
content:"\f07a";
position:absolute;
left:2px;
vertical-align:middle;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
/*--adjust as necessary--*/
color: #000;
font-size: 18px;
padding-right: 0.5em;
}
#navbar #bill_d #checkout{
display: block;
text-align: -webkit-center;
background: #ff5a5a;
font-family: monospace;
padding: 5px;
text-align: center;
margin: 7px;
font-size: 20px;
font-weight: bold;
color: white;
}
#navbar #bill_d #checkout:hover{
background:black;
}
#navbar #bill_d button{
background: #ce5357;
border: 2px solid transparent;
border-radius: 2px;
font-weight: bold;
color: white;
padding:1px;
}
#navbar #bill_d button:hover {
cursor:pointer;
background:black;
}
#navbar #bill_d #bill_n{
display: inline-block;
padding: 0 4px;
font-weight: bold;
font-size: 15px;
}
#bill_f_d {
position: absolute;
padding: 15px;
right: 15px;
top: 30px;
}
#bill_padding{ background: white;
padding:15px;
}
#bill_f_d:before {
content: "";
position: absolute;
top: -4px;
right: 23px;
border: 8px solid transparent;
border-bottom: 12px solid white;
}
#location{
margin: 15%;
padding: 15px;
background: rgba(255, 255, 255, 0.65);
text-align: center;
text-align: -webkit-center;
color: #353535;
font-family: monospace;
font-weight: bold;
font-size: 20px;
}
#loc_sel{
padding: 15px;
background: rgba(171, 171, 171, 0.42);
}
#location select{
margin:10px;
border: 1px solid transparent;
padding: 5px;
border-radius: 2px;
box-shadow: 0 0 1px 1px grey;
}
#marketing{margin:10% 15%;background: rgba(255, 255, 255, 0.65);padding:15px}
#marketing form{
background: rgba(148, 146, 146, 0.64);
padding-bottom:5px;
margin-bottom:2%;
}
#marketing form p{
padding:5px;
font-size: 23px;
color: white;
text-shadow: 1px 0 3px black;
font-family: sans-serif;
font-weight: lighter;
background: #969696;
}
#marketing input,select{
padding:5px;
border:2px solid transparent;
border-radius:2px;
font-family:arial;
box-shadow: 0 0 2px 0px;
margin:1%
}
#marketing input:focus,select:focus{
box-shadow: 0 0 13px 1px #383838 !important;
outline:none;
}
.market{
font-size: 20px;
margin: 1%;
background: rgba(40, 85, 123, 0.27);
padding:5px;
display:table;}
.market *{display:inline-block;padding:5px;margin:2px; background: rgba(45, 51, 84, 0.55);font-family:arial;font-weight:bold;border-radius:2px
}
#info{
padding: 5%;
margin: 1%;
background: rgba(255, 255, 255, 0.67);
text-align: center;
text-align: -webkit-center;
border-radius: 2px;
}
#info .inf{
padding:9px;
}
#intro p{
font-size: 30px;
font-weight: bold;
color: white;
text-shadow: 3px 2px 2px black;
font-family: monospace;
}
#info ul{
list-style-type: none;
padding:7px;
}
#intro{
background: rgba(56, 56, 56, 0.57);
border-radius: 2px;
}
#how{
color: #2b2b2b;
font-weight: bold;
border-radius: 2px;
background: rgba(255, 255, 255, 0.71);
}
#how h3{
font-family: monospace;
font-size: 26px;
}
#how li{
padding:5px;
margin:4px;
padding: 5px;
margin: 4px;
font-family: monospace;
font-size: 20px;
}
#how_customer,#how_admin{
border: 1px solid black;
margin:15px;
display:inline-block;
width:45%;
}
#how_customer h3{
color: rgb(59, 243, 117);
font-weight: bolder;
text-shadow: 2px 1px 0px rgba(62, 62, 62, 0.77);
}
#how_admin h3{
color: rgb(65, 157, 255);
font-weight: bolder;
text-shadow: 2px 1px 0px rgba(62, 62, 62, 0.77);
}
#footer{ width: 100%;
background: #333333;
padding: 15px 0 15px 0;
position: absolute;
left:0;
}
#footer a{padding:15px}
#footer #copy{color:white;font-weight:bolder;font-family: monospace; text-align: center;text-align: -webkit-center;}
@media screen and (max-width:1000px) {
#navbar #user {
float: right;
margin-right: 1%;
padding: 13px;
}
#logo img{width:80px !important;}
#meals_b{max-height:250px !important;}
form input {
margin: 6px;
display: flex;
}
.market {
font-size: 17px;
margin: 5%;
background: rgba(81, 150, 210, 0.63);
}
.market {
font-size: 17px;
}
#location {
margin: 5% 1%;
}
#how_customer, #how_admin {
width: auto;
}
#sign_in_d button, #sign_up_d button {
width: auto;
}
}
window.onload = setTimeout(function(){
if(document.getElementById("sign_up")!=undefined)
document.getElementById("sign_up").style.background = "rgb(32, 78, 117)";
if(document.getElementById("bill_d") != undefined)
cart_f("consumer");
if(document.getElementById("markets_loc") != undefined)
document.getElementById("markets_loc").focus();
},500);
function meals_right(){
if(document.getElementById("meals") != undefined){
var m_r = document.getElementById("meals_r").scrollWidth;
document.getElementById("meals").style.right = "-" + m_r + "px";
}
}
function meals_r(){
var meals = document.getElementById("meals");
if(meals.style.right != "0px")
meals.style.right = "0px";
else meals_right();
}
function meal_random(){
var meal = document.querySelectorAll(".meal");
var ml = meal.length;
var r;
r = Math.floor(Math.random()*ml+1);
if(r <= ml)
meal[r].style.background = 'black';
}
function meals_add(inn){
var colorr = ["#de4848","#27b559","#274cb5","#27a1b5","#5e27b5","#a93157","#65a931","#a93131"],i=0,r;
r = Math.floor(Math.random()*8+1)
var x = colorr[r];
x = x.replace('#','');
document.getElementById("meal_color").value = x;
if(inn == 'f'){
document.getElementById("meals_in").style.display = 'block';
meals_pick();
}
if(inn == 'p'){
var n = document.getElementById("meal_name").value,c = document.getElementById("meal_color").value;
xml = new XMLHttpRequest;
xml.onreadystatechange = function(){
if(this.status == 200 && this.readyState == 4){
document.getElementById("meals_b").innerHTML += "<div class='meal' style='background:#" + c + ";'>" + n + "</div>";
document.getElementById("meal_name").value = "";
}
}
xml.open("post","funcs.php?t=meals-add&n=" + n + "&c=" + c,true);
xml.send();
}
console.log("m_a")
}
function meals_b_f(){
var xml = new XMLHttpRequest;
xml.onreadystatechange = function(){
if(this.status == 200 && this.readyState == 4){
if(this.responseText.length > 46){
console.log(this.responseText.length);
document.getElementById("meals_b").innerHTML = this.responseText;}
meals_right();
}
}
xml.open("post","funcs.php?t=meals-b-f",true);
xml.send();
}
var pickn = 0;
function meals_pick(){
if(pickn<1){
var xml = new XMLHttpRequest;
xml.onreadystatechange = function(){
if(this.status == 200 && this.readyState == 4){
document.getElementById("mleft").innerHTML = this.responseText;
pickn++;
}
}
xml.open("post","funcs.php?t=meals-pick",true);
xml.send();
}
}
function meals_adds(n,c){
xml = new XMLHttpRequest;
xml.onreadystatechange = function(){
if(this.status == 200 && this.readyState == 4){
document.getElementById("meals_b").innerHTML += "<div class='meal' style='background:#" + c + ";'>" + n + "</div>";
document.getElementById("meal_name").value = "";
}
}
xml.open("post","funcs.php?t=meals-add&n=" + n + "&c=" + c,true);
xml.send();
}
var onmouse;
function meals_onmouse(j){
if(j == "over")
onmouse = true;
if(j == "leave")
onmouse = false;
}
function meals_in_click(){
if(!onmouse)
document.getElementById("meals_in").style.display = 'none';
}
function select_change(e){
for(var i=0;i<15;i++){
if(document.getElementsByTagName("location")[i])
{document.getElementsByTagName("location")[i].style.display = "none";
console.log(i);}
else break;
console.log("what!");
}
if(document.getElementById(e.value + "_loc")!=undefined)
document.getElementById(e.value + "_loc").style.display = "inline-block";
}
function sign_toggle(e){
var inn = document.getElementById('sign_in_form');
var up = document.getElementById('sign_up_form');
inn.style.display = "none";
up.style.display = "none";
var id = e.getAttribute("id");
document.getElementById(id + "_form").style.display = "block";
if(id == "sign_up")
document.getElementById("sign_in").style.background = "rgba(0,0,0,0.5)";
else if(id == "sign_in")
document.getElementById("sign_up").style.background = "rgba(0,0,0,0.5)";
e.style.background = "rgb(32, 78, 117)";
}
function select_market(e){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200){
document.getElementById("location1").innerHTML = this.responseText;
}
}
console.log(e.value);
xml.open("POST","./funcs.php?t=market-location&g=" + e.value,true);
xml.send();
}
//function market_type(e){
// if(e.value == "others")
// document.getElementById("others").style.display = "inline-block";
//else {document.getElementById("others").style.display = "none";document.getElementById("others").value = "";}
//}
function market_type_f(){
var xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200 && this.readyState == 4){
document.getElementById("market_type").innerHTML = this.responseText;
}
}
xml.open("POST","funcs.php?t=market-type-f",true);
xml.send();
}
//for products checking
function checkbox(e){
var uid = document.getElementById("uid").value;
if(e.getAttribute("data-type") == 'product'){
var id = e.getAttribute("data-id");
if(e.checked){
document.getElementById("q" + id).disabled = false;
document.getElementById('q' + id).value = '1';
//document.getElementById('quantity').value = '1';
//document.getElementById('product').value = e.value;
console.log("product " + e.value);
//document.getElementById('bill_s').click();
//document.getElementById('bill_f').submit();
//document.getElementById('bill_f').prevetDefault();
xml_bill_add(e.value);
}
else {
document.getElementById('q' + id).value = '';
document.getElementById('q' + id).disabled = true;
//document.getElementById('quantity').value = '';
// document.getElementById('product').value = e.value;
//document.getElementById('q' + id).value = '';
xml_bill_remove(e.value);
}
}
else if(e.getAttribute("data-type") == 'quantity'){
var pro = e.getAttribute('data-product');
xml_bill_edit(pro,e.value);
}
}
function xml_bill_add(pro){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200){
document.getElementById('bill_n').innerHTML = this.responseText;
cart_f('consumer');
}
}
xml.open('post','funcs.php?t=bill-add&pro=' + pro,true);
xml.send();
}
function xml_bill_edit(pro,value){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200){
//document.getElementById('bill_n').innerHTML = this.responseText;
cart_f('consumer');
}
}
xml.open('post','funcs.php?t=bill-edit&pro=' + pro + '&q=' + value,true);
xml.send();
}
function xml_bill_remove(pro){
console.log("remove" + pro);
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200){
document.getElementById('bill_n').innerHTML = this.responseText;
cart_f('consumer');
}
}
xml.open('post','funcs.php?t=bill-remove&pro=' + pro,true);
xml.send();
}
function xml_bill_trunc(){
for(var i=0;i<10000,document.getElementsByClassName('check')[i] != undefined;i++){
document.getElementsByClassName('check')[i].checked = false;
var id = document.getElementsByClassName('check')[i].getAttribute('data-id'),
value = document.getElementsByClassName('check')[i].value;
document.getElementById('q' + id).value = '';
document.getElementById('q' + id).disabled = true;
//document.getElementById('quantity').value = '';
//document.getElementById('product').value = value;
document.getElementById('q' + id).value = '';
}
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200){
document.getElementById('bill_n').innerHTML = this.responseText;
cart_f('consumer');
}
}
xml.open('post','funcs.php?t=bill-trunc',true);
xml.send();
}
//////////////////////////////////////////////////////
function xml_checkout_b(){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200){
xml_bill_trunc();
window.location = 'user.php';
}
}
xml.open('post','funcs.php?t=checkout-b',true);
xml.send();
}
/////////////////////////////////////////////////////////////////////////////////////////////
function bill_f(){
var doc = document.getElementById("bill_f_d");
if(doc.style.display == 'none') {
doc.style.display = 'block';
}
else {doc.style.display = 'none';}
}
///////////////////////////////////////////////////////////////////////
function cart_f(maj){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200) {
document.getElementById("cart").innerHTML = this.responseText;
var str = this.responseText;
if (str.length > 1) {
console.log("length: " + str.length)
document.getElementById("checkout").style.display = 'block';
}
else
document.getElementById("checkout").style.display = 'none';
}
}
xml.open('post','funcs.php?t=cart-f&ma=' + maj,true);
xml.send();
}
////////////////////////////////////////////////////////////////////////
function markets_f(bid,mid){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200) {
document.getElementById("table_"+ bid + "_" + mid).innerHTML = this.responseText;
}
}
xml.open('post','funcs.php?t=marekts-f&bid=' + bid + "&mid=" + mid,true);
xml.send();
}
///////////////////////////////////////////////////
function req_f(bid,mid){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200) {
document.getElementById("table_"+ bid + "_" + mid).innerHTML = this.responseText;
}
}
xml.open('post','funcs.php?t=req-f&bid=' + bid + "&mid=" + mid,true);
xml.send();
}
<?php
ob_start();
include 'mysqli.php';
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(!isset($_SESSION['market_build_error']))
$_SESSION['market_build_error'] = "";
$_SESSION['sign_error'] = "";
if(isset($_COOKIE['user_name']))
{
$_SESSION['user_name'] = $_COOKIE['user_name'];
$_SESSION['user_email'] = $_COOKIE['user_email'];
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['major'] = $_COOKIE['major'];
}
//else header("Location: ./sign.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Shantah | Main page</title>
<?php
include 'navbar.php';
if(!empty($_SESSION['user_name']))
{
if($_SESSION['major']=="consumer"){
echo '
<section id="location">
<div id="loc_sel">
<div id="p">Select your location:</div>
<select name="governorate" onchange="select_market(this);setTimeout(function(){height11();},800);" class="location" id="markets_loc" placeholder="Select your Governorate/state" required>
';
$result = $GLOBALS['conn']->query("SELECT DISTINCT governorate FROM markets ");
if($result)
$row = $result->fetch_assoc();ini_set('display_errors', 1);
if($row){
echo "
<option value=''>Select your governorate/city</option>
<option value='$row[governorate]'>$row[governorate]</option>
";
while($row = $result->fetch_assoc()){
echo "
<option value='$row[governorate]'>$row[governorate]</option>
";
}
}
echo '</select></div>
<div id="location1"></div></section>';
}
else if($_SESSION['major']=="market_admin"){
echo "<div id='marketing'>$_SESSION[market_build_error]
<form action='funcs.php?t=markets-build' method='post' enctype='multipart/form-data'>
<p>New shop info.</p>
<input type='file' name='market_image'>
<input type='text' name='name' placeholder='Market name' required>
<select id='market_type' name='type' onchange='if(this.value == \"others\")
document.getElementById(\"others\").style.display = \"inline-block\";
else {document.getElementById(\"others\").style.display = \"none\";document.getElementById(\"others\").value = \"\";}' required>
<script>market_type_f();</script>
</select>
<input type='text' style='display:none' id='others' placeholder='Type of things you sell' name='others'>
<input type='text' name='telephone' placeholder='Telephone number' required>
<input type='text' name='telephone2' placeholder='optional: Telephone 2 '>
<select name='governorate' placeholder='market governorate/city' required>
<option value='6th of October'>6th of October</option>
<option value='Al Sharqia'>Al Sharqia</option>
<option value='Alexandria'>Alexandria</option>
<option value='Aswan'>Aswan</option>
<option value='Asyut'>Asyut</option>
<option value='Beheira'>Beheira</option>
<option value='Beni Suef'>Beni Suef</option>
<option value='Cairo'>Cairo</option>
<option value='Dakahlia'>Dakahlia</option>
<option value='Damietta'>Damietta</option>
<option value='Faiyum'>Faiyum</option>
<option value='Gharbia'>Gharbia</option>
<option value='Giza'>Giza</option>
<option value='Helwan'>Helwan</option>
<option value='Ismailia'>Ismailia</option>
<option value='Kafr el-Sheikh'>Kafr el-Sheikh</option>
<option value='Luxor'>Luxor</option>
<option value='Matrouh'>Matrouh</option>
<option value='Minya'>Minya</option>
<option value='Monufia'>Monufia</option>
<option value='New Valley'>New Valley</option>
<option value='North Sinai'>North Sinai</option>
<option value='Port Said'>Port Said</option>
<option value='Qalyubia'>Qalyubia</option>
<option value='Qena'>Qena</option>
<option value='Red Sea'>Red Sea</option>
<option value='Sohag'>Sohag</option>
<option value='South Sinai'>South Sinai</option>
<option value='Suez'>Suez</option>
</select>
<input type='submit' value='Add' name='submit' title='Add new market'>
</form>
";
$result1 = $GLOBALS['conn']->query("SELECT id,name,type,governorate,telephones FROM markets WHERE user_id='$_SESSION[user_id]'");
$row = $result1->fetch_assoc();
if($row){
echo "
<div class='market'>
<a href='./products.php?id=$row[id]'>$row[name]</a>
<p>sells $row[type]</p>
<a href='./funcs.php?t=governorate&name=$row[governorate]'>$row[governorate]</a>
<a href='tel:$row[telephones]'>$row[telephones]</a>
</div>
";
while($row = $result1->fetch_assoc()){
echo "
<div class='market'>
<a href='./products.php?id=$row[id]'>$row[name]</a>
<p>sells $row[type]</p>
<a href='./funcs.php?t=governorate&name=$row[governorate]'>$row[governorate]</a>
<a href='tel:$row[telephones]'>$row[telephones]</a>
</div>
";
}
}
echo "</div>";
}
}
else {
echo "
<div id='info'>
<div id='intro' class='inf'>
<p>Welcome to our site,<br><small style='font-size: 21px;'>This site is for making shopping easy for you.</small></p>
</div>
<div id='how' class='inf'>
<div id='how_customer' class='inf'>
<h3>How to use the site as a customer:</h3>
<ul>
<li>•Sign up as a Customer</li>
<li>•Select your current city</li>
<li>•Select the market you like</li>
<li>•Select products you need</li>
<li>•Click Done</li>
</ul>
</div>
<div id='how_admin' class='inf'>
<h3>How to use the site as a Market admin:</h3>
<ul>
<li>•Sign up as a market admin</li>
<li>•Enter Your market's info</li>
<li>•Enter The products you have in the market</li>
<li>*Update the prices and products daily</li>
</ul>
</div>
</div>
";
}
include 'footer.php';
?>
<script type="text/javascript" src="index.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</body>
</html>
<?php
ob_end_flush();
?>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<meta name='keywords' content='food, shopping, food shopping, buy food, register, sell'>
<meta name='description' content='This site is to make shopping easy for both customer and market owners, you can register your market and your products and let people buy in an easy way, and you can register as customer and enjoy the simble way of shopping'>
<link rel="stylesheet" href="./index.css">
<link rel='stylesheet' type='text/css' href='./user.css'>
<link rel='icon' href='logo1.png'>
<link rel="stylesheet" href="css/font-awesome.css"
<link rel="stylesheet" href="css/font-awesome.min.css">
<style>
<?php
if($_SESSION['major'] == 'market_admin')
echo ".consumer{display:none;}";
?>
</style>
</head>
<body>
<script src="./index.js"></script>
<div id="navbar">
<div id="logo"><a href="http://localhost/shantah"><img src="./logo.png"></a></div>
<?php
echo "<script>setTimeout(function(){meals_b_f();},300);</script>";
if(!empty($_SESSION['user_name'])){
echo " <div id='meals'>
<div id='meals_l'><i class='fa fa-cutlery' title='Your meals' onclick='meals_r()'></i></div>
<div id='meals_r'>
<fieldset>
<legend>Your meals</legend>
<div id='meals_b'></div>
<div id='meals_buttons'>
<input type='button' value='Add' title='Add a meal to the list' onclick='meals_add(\"f\")'>
<input type='button' value='Random' title='Pick a random meal from the list' onclick='meal_random()'>
<input type='button' value='Reset' title='Return all selected to default' onclick='meals_b_f()'>
</div>
</fieldset>
</div>
</div>";
if($_SESSION['major'] == 'consumer'){
$res_count = $GLOBALS['conn']->query("SELECT COUNT(num) FROM cache WHERE user_id='$_SESSION[user_id]' ");
$ro_count = $res_count->fetch_assoc();
echo "
<div id='bill_d' onclick='bill_f()' onmouseover=\"document.getElementById('bill_f_d').style.display = 'block'\" onmouseleave=\"document.getElementById('bill_f_d').style.display = 'none'\">
<div>
<div id='bill_n' >".$ro_count['COUNT(num)']."</div>
<div><button onclick='xml_bill_trunc()' title='Remove all produucts from cart'>X</button></div>
<div id='bill_f_d' style='display:none' onmouseleave=\"document.getElementById('bill_f_d').style.display = 'none'\">
<div id='bill_padding'><fieldset style='padding:2px;'>
<legend style='text-align: center;font-weight: bold;font-size: 20px;'>Your cart</legend>
<table id='cart'></table>
<div id='checkout' style='display: none;' onclick='xml_checkout_b()' title='Finish buying and add the selected products to market's list>Checkout</div>
</fieldset>
</div>
</div>
</div>
</div>
";
}
if($_SESSION['major'] == 'market_admin'){
if(isset($_REQUEST['id'])){
$res_count = $GLOBALS['conn']->query("SELECT COUNT(id) FROM operations WHERE market_id='$_REQUEST[id]' AND state='not yet'");
$ro_count = $res_count->fetch_assoc();
echo "
<script>document.getElementsByTagName('style')[0].innerHTML += \"#bill_n:before{content:'\\\\f0f3' !important; }\"</script>
<div id='bill_d' title='Bags are not done yet' >
<div>
<div id='bill_n' >".$ro_count['COUNT(id)']."</div>
</div>
</div>
";
}
}
echo"<div id='user'>
<a target='_blank' href='./user.php'>$_SESSION[user_name]</a>
<a href='./funcs.php?t=logout'><small style='font-size: 13px;'>&nbsp;&nbsp;&nbsp;Logout</small></a>
</div>
";
}
else echo "<a id='sign_a' href='sign.php'>Sign up or Sign in</a>";
?>
</div>
<div id='meals_in' style='display:none;' onclick='meals_in_click()'>
<div id='meals_in_d' onmouseover='meals_onmouse("over")' onmouseleave='meals_onmouse("leave")'>
<div id='mleft'></div>
<p>Meal info.</p>
<form method='post' action='funcs.php?t=meals-add' onsubmit='meals_add("p");return false;'>
<input type="text" id='meal_name' name='name' required>
<input type="hidden" id='meal_color' name='color' required>
<input type="submit" name='submit'>
</form>
</div>
</div>
<div id="navbar_before"></div>
<script>var height = document.getElementById('navbar').scrollHeight;
document.getElementById('navbar_before').style.height = height + 'px';</script>
*{
padding:0;
margin:0;
}
html{background:url("./back.jpg") fixed;background-size:cover;}
#container{
margin: 7%;
background: #423c98;
font-family: arial;
color: white;
padding: 1%;
}
#container form{
padding:5px;
margin:4px;
}
#container #m_h{display:table;margin:2% auto 2%;padding:10px;background:white;color:black;}
#container #m_h:hover{color:white;background:black;}
#market_name{
margin-top:5%;
text-align:center;
color: white;
font-weight: bolder;
font-size: x-large;
font-family: arial;}
form input[type="text"],form input[type="number"]{
padding: 4px;
border: 1px solid transparent;
border-radius: 2px;
box-shadow: 0 0 4px 1px #2f2f2f;
transition:0.3s;
margin:3px
}
input[type="text"]:focus,form input[type="number"]{
box-shadow: 0 0 7px 3px #2f2f2f;
outline:none;
}
@media screen and (max-width:1000px){
#container{margin:1%;}
#products_fill{text-align:center; text-align:-webkit-center;}
#products_fill input[type="text"]{margin:7px;padding:7px}
table *{padding:2px}
}
<?php
include 'mysqli.php';
if(isset($_COOKIE['user_name'])){
$_SESSION['user_name'] = $_COOKIE['user_name'];
$_SESSION['user_email'] = $_COOKIE['user_email'];
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['major'] = $_COOKIE['major'];
}
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_REQUEST['id']))
{ $m = "WHERE market_id='$_REQUEST[id]'"; $id = $_REQUEST['id'];}
else header("Location: ./");
$result = $conn->query("SELECT * FROM products $m");
if($result)
$row = $result->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<title>Akly | Products filling</title>
<link rel="stylesheet" type="text/css" href="./products.css">
<?php
include 'navbar.php';
$result1 = $GLOBALS['conn']->query("SELECT name FROM markets WHERE id='$id'");
$row1 = $result1->fetch_assoc();
echo "<div id='container'><div id='market_name'>".$row1['name']." </div>";if($_SESSION['major'] == 'market_admin') echo"<a id='m_h' href='./user.php?id=".$_REQUEST['id']."'>Demands</a>";
if($_SESSION["major"] == "market_admin"){
echo '
<form id="products_fill" action="funcs.php?t=products-filling" method="post">
<input type="text" name="name" placeholder="Product name" required>
<input type="text" name="price" placeholder="Product price" required>
<input type="text" name="type" placeholder="Product type" required>
<input type="hidden" value="'.$id.'" name="market_id" required>
<input type="submit" name="submit">
</form>';
}
if($row)
{$i=1;
echo "<input type='hidden' value='$_SESSION[user_id]' id='uid'>
<table>
<tr>
<th class='consumer'> </th>
<th>num.</th>
<th>Name</th>
<th>Price</th>
<th>Type</th>
<th>Market ID</th>
</tr>
<tr>
<td class='consumer'><input type='checkbox' class='check' data-id='$i' onchange='checkbox(this)' data-type='product' value='$row[id]' name='product[]'/></td>
<th>$i</th>
<td>$row[name]</td>
<td>$row[price]* <input type='number' class='consumer' id='q".$i."' onchange='checkbox(this)' disabled='true' data-product='$row[id]' data-type='quantity' value='' name='quantity[]' min='1'/></td>
<td>$row[type]</td>
<td>$row[market_id]</td>
</tr>
";
while($row = $result->fetch_assoc()){
if($row){ $i++; echo "
<tr>
<td class='consumer'><input type='checkbox' class='check' data-id='$i' onchange='checkbox(this)' data-type='product' value='$row[id]' name='product[]'/>
</td>
<th>$i</th>
<td>$row[name]</td>
<td>$row[price]* <input type='number' class='consumer' id='q$i' onchange='checkbox(this)' disabled='true' data-product='$row[id]' data-type='quantity' value='' name='quantity[]' min='1'/></td>
<td>$row[type]</td>
<td>$row[market_id]</td>
</tr>
";}
}
echo "</table>";
echo "<script>console.log($_SESSION[user_id] + ' ' + $id);</script>";
}
echo "</div>";
include 'footer.php';
echo "
<script>
if(document.getElementsByTagName(\"tr\")[1] != undefined){
console.log(\"ok\");
for(i=0;i<10000,document.getElementsByTagName(\"tr\")[i] != undefined;i++){
console.log(\"ok two\");
if(i%2 != 0)
{
document.getElementsByTagName(\"tr\")[i].style.background = \"rgb(122, 117, 191)\";
}
}
}";
$result_c = $GLOBALS['conn']->query("SELECT product_id,quantity FROM cache WHERE user_id='$_SESSION[user_id]' AND market_id='$_REQUEST[id]'");
if($result_c)
{
$row_c = $result_c->fetch_assoc();
if($row_c){
$c_i=0;
$cache_p[$c_i] = $row_c['product_id'];
$cache_q[$c_i] = $row_c['quantity'];
while($row_c = $result_c->fetch_assoc()){
$c_i++;
$cache_p[$c_i] = $row_c['product_id'];
$cache_q[$c_i] = $row_c['quantity'];
}
//echo 'index : '.$c_i.';';
}
$i_i = 0;
echo "\n var q;";
while(!empty($cache_q[$i_i])){
echo "
if(document.querySelector(\"input[value='".$cache_p[$i_i]."']\") != undefined){
var onchange = document.querySelector(\"input[value='".$cache_p[$i_i]."']\").onchange;
document.querySelector(\"input[value='".$cache_p[$i_i]."']\").onchange = 'return false;';
document.querySelector(\"input[value='".$cache_p[$i_i]."']\").click();
q = document.querySelector(\"input[value='".$cache_p[$i_i]."']\").getAttribute(\"data-id\");
document.getElementById(\"q\" + q).value = ".$cache_q[$i_i].";
document.getElementById(\"q\" + q).disabled = false;
document.querySelector(\"input[value='".$cache_p[$i_i]."']\").onchange = onchange;
}
";
$i_i++;
}
}
echo "
</script>
";
?>
<script src="./index.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</body>
</html>
#body{
margin:15%;
padding:15px;
background: #3d9655;
}
#sign_up_d .input:focus,#sign_in_d .input:focus{border-bottom:2px solid blue;}
#sign_up_d,#sign_in_d{
display:inline-block;
padding:15px;
text-align:center;
text-align: -webkit-center;
width:95%;
}
#sign_up_d input,#sign_in_d input{
border: 3px solid transparent;
border-bottom-color: #313131;
padding: 5px;
border-radius: 2px;
}
#sign_in_d button,#sign_up_d button{
background: rgba(0,0,0,0.5);
width: 10%;
margin: 10px;
padding:7px;
display:block;
border:transparent;
color:white;
font-weight:bold;
cursor:pointer;
}
#sign_in_d button:focus,#sign_up_d button:focus{outline:none;}
#sign_up_d select[name="major"]::before{
content:"";
display:block;
}
<?php
ob_start();
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_COOKIE['user_name']))
{
$_SESSION['user_name'] = $_COOKIE['user_name'];
$_SESSION['user_email'] = $_COOKIE['user_email'];
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['major'] = $_COOKIE['major'];
header("Location: ./");
}
if(!isset($_SESSION['sign_error']))
$_SESSION['sign_error'] = "";
?>
<!DOCTYPE html>
<html>
<head>
<title>Shantah | Registeration</title>
<link rel="stylesheet" type="text/css" href="./sign.css">
<?php include 'navbar.php'; ?>
<div id="body">
<?php echo $_SESSION['sign_error']; ?>
<div id="sign_up_d">
<button id="sign_up" onclick="sign_toggle(this)">Sign up</button>
<form method="post" action="funcs.php?t=sign-up" id="sign_up_form" >
<input class="input" type="text" name="user_name" placeholder="Full Name" required="required">
<input class="input" type="email" name="user_email" placeholder="E-mail Here" required="required">
<!-- <input type="hidden" name="typ" value="sign_up"> -->
<!-- <input type="text" name="location" placeholder="Enter your adress" required="true"> -->
<select name="major" onchange="select_change(this)" onkeyup="select_change(this)" placeholder="Select your major" required="required">
<option value="">Select your</option>
<option value="consumer">Customer</option>
<option value="market_admin">Market admin</option>
</select>
<!--------------------------------------------customer-------------------------------------------------- -->
<!-- <select name="governorate" onchange="select_change(this)" style="display:none;" class="location" id="consumer_loc" placeholder="Select your Governorate/state" required="true">
<option value="">Select your</option>
<option value="giza"</option>
<option value="cairo"</option>
<option value="fayoum"</option>
<option value="byherah"</option>
<option value="Damietta"</option>
</select>
<select name="city" onchange="select_change(this)" style="display:none;" class="location" id="damietta_loc" placeholder="Select your Governorate/state/city" required="true">
<option value="">Select your city</option>
<option value="6_october1">6</option>
<option value="fayoum1"</option>
<option value="byherah1"</option>
<option value="Damietta1"</option>
</select>->
<!-- ------------------------------------------------------------------------------------------ -->
<!-- --------------------------------------------------market owner--------------------------------------------------
<select name="governorate" onchange="select_change(this)" style="display:none;" class="location" id="market_owner_loc" placeholder="Select your Governorate/state" required="true">
<option value="6th of October">6th of October</option>
<option value="Al Sharqia">Al Sharqia</option>
<option value="Alexandria">Alexandria</option>
<option value="Aswan">Aswan</option>
<option value="Asyut">Asyut</option>
<option value="Beheira">Beheira</option>
<option value="Beni Suef">Beni Suef</option>
<option value="Cairo">Cairo</option>
<option value="Dakahlia">Dakahlia</option>
<option value="Damietta">Damietta</option>
<option value="Faiyum">Faiyum</option>
<option value="Gharbia">Gharbia</option>
<option value="Giza">Giza</option>
<option value="Helwan">Helwan</option>
<option value="Ismailia">Ismailia</option>
<option value="Kafr el-Sheikh">Kafr el-Sheikh</option>
<option value="Luxor">Luxor</option>
<option value="Matrouh">Matrouh</option>
<option value="Minya">Minya</option>
<option value="Monufia">Monufia</option>
<option value="New Valley">New Valley</option>
<option value="North Sinai">North Sinai</option>
<option value="Port Said">Port Said</option>
<option value="Qalyubia">Qalyubia</option>
<option value="Qena">Qena</option>
<option value="Red Sea">Red Sea</option>
<option value="Sohag">Sohag</option>
<option value="South Sinai">South Sinai</option>
<option value="Suez">Suez</option>
</select>
<select name="city" onchange="select_change(this)" style="display:none;" class="location" id="damietta_loc" placeholder="Select your Governorate/state/city" required="true">
<option value="">Select your city/quesm</option>
<option value="6_october1">6 October</option>
<option value="fayoum1">Fayoum</option>
<option value="byherah1">Byhera</option>
<option value="Damietta1">Damietta</option>
</select> -->
<!-- ------------------------------------------------------------------------------------------ -->
<input class="input" type="password" name="password" placeholder="Password Here" required="required">
<input type="submit" name="submit">
</form>
</div>
<div id="sign_in_d">
<button id="sign_in" onclick="sign_toggle(this)">Sign in</button>
<form action="funcs.php?t=sign-in" style="display:none;" id="sign_in_form" method="post">
<input class="input" type="email" name="user_email" placeholder="E-mail Here" required="required">
<!-- <input type="hidden" name="typ" value="sign_in" required="true"> -->
<input class="input" type="password" name="password" placeholder="Password Here" required="required">
<input type="submit" name="">
</form>
</div>
<!-- <a href="./funs.php?t=reset_password&e=$_SESSION ['user_email']" >reset password </a> -->
<a href="#" onclick="reset_password()" >reset password </a>
</div>
<?php include 'footer.php'; ?>
<script type="text/javascript" src="./index.js"></script>
</body>
</html>
<?php
ob_end_flush();
?>
#bags *{font-family:arial;}
#bags{margin:15%;background:white;border:5px solid black;padding:15px;}
.bag{margin:3%;border:4px solid #5454ea;}
.bag_label{margin:0;ext-align;center;text-align:-webkit-center;padding:10px;background:#5454ea;color:white;}
.market_bag{border:3px solid #d43737;border-radius:2px; margin:2%;}
.market_label{margin:0 0 10px 0;padding:5px; background:#d43737;color:white;}
.market_label:hover{cursor:pointer;}
#m_bags{
margin:3%;
padding:5px;
}
.m_bag:hover{
cursor:pointer;
}
.m_bag{
display:inline-block;
padding:10px;
border-radius:2px;
color:black;
background:white;
margin:1%;
font-weight:bold;
font-family: monospace;
}
.m_market_body{
display:none;
position: fixed;
width: 100%;
height: 100%;
background: rgba(37, 37, 37, 0.72);
padding: 15%;
top: 0;
left: 0;
color:white;
font-weight:bold;
font-size:25px;
}
.bag_state{
text-align:center;
text-align:-webkit-center;
color:#2b2b2b;
background:white;
padding:2px;
margin:10% 0 0 0;
border-radius:2px;
border:2px solid black;
}
.Done{background:white; font-weight:bolder;color:#4bca4b;}
.market_bag .bag_state{margin:1%;}
window.onload = function(){
var bag = document.getElementsByClassName("m_bag");
var colorr = ["#de4848","#27b559","#274cb5","#27a1b5","#5e27b5","#a93157","#65a931","#a93131"],i=0,r;
while(bag[i]!=undefined){
r = Math.floor(Math.random()*8+1)
if(colorr[r] != null)
{bag[i].style.background = colorr[r] + "";
bag[i].style.color = "#fff";}
i++;
}
}
function m_bag(bid){
var mb = document.getElementById("market_body_" + bid);
if(mb.style.display == "block")
mb.style.display = "none";
else mb.style.display = "block";
console.log("okay!!");
}
function bag_done(bid){
xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200){
document.getElementById("bag_state_" + bid).innerHTML = this.responseText;
console.log(this.responseText);
}
}
xml.open("post","funcs.php?t=bag-done&bid=" + bid,true);
xml.send();
}
<?php
include 'mysqli.php';
if (session_status() == PHP_SESSION_NONE){
session_start();
}
if(!isset($_SESSION['market_build_error'])){
$_SESSION['market_build_error'] = "";
$_SESSION['sign_error'] = "";
if(isset($_COOKIE['user_name'])){
$_SESSION['user_name'] = $_COOKIE['user_name'];
$_SESSION['user_email'] = $_COOKIE['user_email'];
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['major'] = $_COOKIE['major'];
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Akly | User page</title>
<?php
include 'navbar.php';
if($_SESSION['user_name']){
if($_SESSION['major'] == 'consumer'){
$res_id = $GLOBALS['conn']->query("SELECT distinct id FROM bags WHERE user_id='$_SESSION[user_id]' ORDER BY id DESC");
if($res_id){
$row_id = $res_id->fetch_assoc();
if($row_id){
$bid = $row_id['id'];
echo "
<div id='bags'>
<div class='bag'>
<div class='bag_label' data-label='$bid'>Bag $bid</div>
<div id='bag_body_$bid' class='bag_body'>
";
$res_markets = $GLOBALS['conn']->query("SELECT DISTINCT market_id FROM bags WHERE user_id='$_SESSION[user_id]' AND id='$bid'");
if($res_markets){
$row_markets = $res_markets->fetch_assoc();
$mid = $row_markets['market_id'];
$res_oppp = $GLOBALS['conn']->query("SELECT state FROM operations WHERE bag_id='$bid' AND market_id='$mid'");
if($res_oppp){
$row_oppp = $res_oppp->fetch_assoc();
echo "
<div class='market_bag'>
<div class='market_label' data-label='".$bid."_".$mid."' onclick='markets_f(".$bid.",".$mid.")'>market $mid from $bid</div>
<div id='market_body_".$bid."_".$mid."' class='market_body'>
<table id='table_".$bid."_".$mid."'></table>
<script>setTimeout(function(){markets_f(".$bid.",".$mid.");},300);</script>
<div class='bag_state ".$row_oppp['state']."'>".$row_oppp['state']."</div>
</div>
</div>
";}
}
while($row_markets = $res_markets->fetch_assoc()){
$mid = $row_markets['market_id'];
$res_oppp = $GLOBALS['conn']->query("SELECT state FROM operations WHERE bag_id='$bid' AND market_id='$mid'");
if($res_oppp){
$row_oppp = $res_oppp->fetch_assoc();
echo "
<div class='market_bag'>
<div class='market_label' data-label='".$bid."_".$mid."' onclick='markets_f(".$bid.",".$mid.")'>market $mid from $bid</div>
<div id='market_body_".$bid."_".$mid."' class='market_body'>
<table id='table_".$bid."_".$mid."'></table>
<div class='bag_state ".$row_oppp['state']."'>".$row_oppp['state']."</div>
</div>
</div>
";}
}
echo "</div></div>";
}
while($row_id=$res_id->fetch_assoc()){
$bid = $row_id['id'];
echo "
<div class='bag'>
<div class='bag_label' data-label='$bid'>Bag $bid</div>
<div id='bag_body_$bid' class='bag_body'>
";
$res_markets = $GLOBALS['conn']->query("SELECT DISTINCT market_id FROM bags WHERE user_id='$_SESSION[user_id]' AND id='$bid'");
if($res_markets){
$row_markets = $res_markets->fetch_assoc();
$mid = $row_markets['market_id'];
$res_oppp = $GLOBALS['conn']->query("SELECT state FROM operations WHERE bag_id='$bid' AND market_id='$mid'");
if($res_oppp){
$row_oppp = $res_oppp->fetch_assoc();
echo "
<div class='market_bag'>
<div class='market_label' data-label='".$bid."_".$mid."' onclick='markets_f(".$bid.",".$mid.")'>market $mid from $bid</div>
<div id='market_body_".$bid."_".$mid."' class='market_body'>
<table id='table_".$bid."_".$mid."'></table>
<div class='bag_state ".$row_oppp['state']."'>".$row_oppp['state']."</div>
</div>
</div>
";}
}
while($row_markets = $res_markets->fetch_assoc()){
$mid = $row_markets['market_id'];
$res_oppp = $GLOBALS['conn']->query("SELECT state FROM operations WHERE bag_id='$bid' AND market_id='$mid'");
if($res_oppp){
$row_oppp = $res_oppp->fetch_assoc();
echo "
<div class='market_bag'>
<div class='market_label' data-label='".$bid."_".$mid."' onclick='markets_f(".$bid.",".$mid.")'>market $mid from $bid</div>
<div id='market_body_".$bid."_".$mid."' class='market_body'>
<table id='table_".$bid."_".$mid."'></table>
<div class='bag_state ".$row_oppp['state']."'>".$row_oppp['state']."</div>
</div>
</div>
";}
}
echo "</div></div>";
}
}
}
else if($_SESSION['major'] == 'market_admin'){
if(!isset($_REQUEST['id']))
header("Location: ./");
$res_id = $GLOBALS['conn']->query("SELECT distinct id FROM bags WHERE market_id='$_REQUEST[id]' ORDER BY id DESC");
if($res_id){
$mid = $_REQUEST['id'];
$row_id = $res_id->fetch_assoc();
if($row_id){
$bid = $row_id['id'];
echo "
<div id='m_bags'>
<div class='m_bag' onclick=\"m_bag('".$bid."')\">
<div class='m_bag_label' data-label='$bid'>Bag $bid</div>
<div id='bag_body_$bid' class='m_bag_body'>
";
$res_markets = $GLOBALS['conn']->query("SELECT DISTINCT user_id FROM bags WHERE market_id='$_REQUEST[id]' AND id='$bid'");
$res_opp = $GLOBALS['conn']->query("SELECT state FROM operations WHERE market_id='$_REQUEST[id]' AND bag_id='$bid'");
$row_opp = $res_opp->fetch_assoc();
if($res_markets && $res_opp){
$row_markets = $res_markets->fetch_assoc();
$uid = $row_markets['user_id'];
$res_u = $GLOBALS['conn']->query("SELECT name FROM users WHERE id='$uid'");
$row_u = $res_u->fetch_assoc();
echo "
<div class='m_user_bag'>
<div class='m_user_label' data-label='".$bid."_".$mid."'>User: ".$row_u['name']."</div>
<div class='bag_state ".$row_opp['state']."' id='bag_state_".$bid."'>".$row_opp['state']."</div>
<div id='market_body_".$bid."' class='m_market_body'>
<h2>Bag $bid</h2>
<table id='table_".$bid."_".$mid."'></table>
<script>setTimeout(function(){req_f(".$bid.",".$mid.");},300);</script>
<button onclick='bag_done(".$bid.")'>Done</button>
</div>
</div>
";
}
while($row_markets = $res_markets->fetch_assoc()){
$res_u = $GLOBALS['conn']->query("SELECT name FROM users WHERE id='$uid'");
$row_u = $res_u->fetch_assoc();
echo "
<div class='m_user_bag'>
<div class='m_user_label' data-label='".$bid."_".$mid."'>User: ".$row_u['name']."</div>
<div class='bag_state ".$row_opp['state']."' id='bag_state_".$bid."'>".$row_opp['state']."</div>
<div id='market_body_".$bid."' class='m_market_body'>
<h2>Bag $bid</h2>
<table id='table_".$bid."_".$mid."'></table>
<script>setTimeout(function(){req_f(".$bid.",".$mid.");},300);</script>
<button onclick='bag_done(".$bid.")'>Done</button>
</div>
</div>
";
}
echo "</div></div>";
}
while($row_id=$res_id->fetch_assoc()){
$bid = $row_id['id'];
echo "
<div class='m_bag' onclick=\"m_bag('".$bid."')\">
<div class='m_bag_label' data-label='$bid'>Bag $bid</div>
<div id='bag_body_$bid' class='m_bag_body'>
";
$res_markets = $GLOBALS['conn']->query("SELECT DISTINCT user_id FROM bags WHERE market_id='$_REQUEST[id]' AND id='$bid'");
$res_opp = $GLOBALS['conn']->query("SELECT state FROM operations WHERE market_id='$_REQUEST[id]' AND bag_id='$bid'");
$row_opp = $res_opp->fetch_assoc();
if($res_markets && $res_opp){
$row_markets = $res_markets->fetch_assoc();
$uid = $row_markets['user_id'];
$res_u = $GLOBALS['conn']->query("SELECT name FROM users WHERE id='$uid'");
$row_u = $res_u->fetch_assoc();
echo "
<div class='m_user_bag'>
<div class='m_user_label' data-label='".$bid."_".$mid."'>User: ".$row_u['name']."</div>
<div class='bag_state ".$row_opp['state']."' id='bag_state_".$bid."'>".$row_opp['state']."</div>
<div id='market_body_".$bid."' class='m_market_body'>
<h2>Bag $bid</h2>
<table id='table_".$bid."_".$mid."'></table>
<script>setTimeout(function(){req_f(".$bid.",".$mid.");},300);</script>
<button onclick='bag_done(".$bid.")'>Done</button>
</div>
</div>
";
}
while($row_markets = $res_markets->fetch_assoc()){
$res_u = $GLOBALS['conn']->query("SELECT name FROM users WHERE id='$uid'");
$row_u = $res_u->fetch_assoc();
echo "
<div class='m_user_bag'>
<div class='m_user_label' data-label='".$bid."_".$mid."'>User: ".$row_u['name']."</div>
<div class='bag_state ".$row_opp['state']."' id='bag_state_".$bid."'>".$row_opp['state']."</div>
<div id='market_body_".$bid."' class='m_market_body'>
<h2>Bag $bid</h2>
<table id='table_".$bid."_".$mid."'></table>
<script>setTimeout(function(){req_f(".$bid.",".$mid.");},300);</script>
<button onclick='bag_done(".$bid.")'>Done</button>
</div>
</div>
";
}
echo "</div></div>";
}
}
}
}
include 'footer.php';
?>
<script src='./user.js'></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment