-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb1.php
173 lines (151 loc) · 5.52 KB
/
db1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
const DSN = "mysql:host=localhost;dbname=gigamarkt;port=3306;charset=utf8mb4";
const USER = "root";
const PASSWORD = "";
$db = new PDO(DSN, USER, PASSWORD);
function checkUserMarkt($email, $pass)
{
global $db;
$stmt = $db->prepare("select * from market_user where email=?");
$stmt->execute([$email]);
if ($stmt->rowCount()) {
$user = $stmt->fetch(PDO::FETCH_ASSOC);
$salt = "fni13uc0xrhf7332mf3";
$pass = $pass . $salt;
$pass = sha1($pass);
return $pass == $user["password"];
}
return false;
}
function checkUserCons($email, $pass)
{
global $db;
$stmt = $db->prepare("select * from consumer_user where email=?");
$stmt->execute([$email]);
if ($stmt->rowCount()) {
$user = $stmt->fetch(PDO::FETCH_ASSOC);
$salt = "fni13uc0xrhf7332mf3";
$pass = $pass . $salt;
$pass = sha1($pass);
return $pass == $user["password"];
}
return false;
}
function validSessionCons()
{
return isset($_SESSION["ConsUser"]);
}
function validSessionMarkt()
{
return isset($_SESSION["MarktUser"]);
}
function getUserMarkt($email)
{
global $db;
$stmt = $db->prepare("select * from market_user where email=?");
$stmt->execute([$email]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
function getUserCons($email)
{
global $db;
$stmt = $db->prepare("select * from consumer_user where email=?");
$stmt->execute([$email]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
function addProduct($title,$email, $stock, $norm_price, $disc_price, $exp_date, $img, $brand, $category, $sub_category){
global $db;
$stmt = $db->prepare("insert into products (title, email, stock, normal_price, discounted_price, exp_date,
img_name, brand, category, sub_category) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$title,$email, $stock, $norm_price, $disc_price, $exp_date, $img, $brand, $category, $sub_category]);
return true;
}
function getAllProducts($email){
global $db;
$stmt = $db->prepare("Select * from gigamarkt.products where email = ? and exp_date >= CURDATE()");
$stmt->execute([$email]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
function getAllProductsne($cat){
global $db;
$stmt = $db->prepare("Select * from gigamarkt.products category = ? and exp_date >= CURDATE()");
$stmt->execute([$cat]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
function getAllExpiredProducts($email){
global $db;
$stmt = $db->prepare("Select * from gigamarkt.products where email = ? and exp_date < CURDATE()");
$stmt->execute([$email]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/*
<div id="addP">
<form action="?" method="post" enctype="multipart/form-data">
<table id="main">
<tr>
<td>Title:</td>
<td><input type="text" name="title"></input></td>
</tr>
<tr>
<td>Stock Number: </td>
<td><input type="text" name="stock"></input></td>
</tr>
<tr>
<td>Normal Price: </td>
<td><input type="text" name="norm_price"></input></td>
</tr>
<tr>
<td>Discounted Price: </td>
<td><input type="text" name="disc_price"></input></td>
</tr>
<tr>
<td>Expiration Date: </td>
<td><input type="date" name="exp_date" placeholder="dd-mm-yyyy"></input></td>
</tr>
<tr>
<td>Upload the Image: </td>
<td><input type="file" name="img"></input></td>
</tr>
<tr>
<td>Brand (Optional): </td>
<td><input type="text" name="brand"></input></td>
</tr>
<tr>
<td>Category (Optional): </td>
<td>
<select class="combo" name="category" id="category">
<option value="select">Select....</option>
<option value="dairy">Dairy</option>
<option value="s_drink">Drinks</option>
<option value="bathroom">Bathroom Utensils</option>
<option value="snacks">Snacks</option>
<option value="baked">Baked Goods</option>
</td>
</tr>
<tr>
<td>Categorize More? (Optional): </td>
<td>
<select class="combo" name="sub_category" id="sub_category">
<option value="select">Select....</option>
<script>
if($("#category").val()=="dairy"){
$("sub_category").add(<option value="cheese">Cheese</option>);
// <option value="dairy">Dairy</option>
// <option value="s_drink">Drinks</option>
}
</script>
<option value="select">Select....</option>
<option value="sausage">Sausages</option>
<option value="carbonated_drink">Carbonated Drinks</option>
<option value="juice">Juice</option>
<option value="bread">Bread</option>
<option value="cake">Cakes</option>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;"><button>Add Product</button></td>
</tr>
<input type="hidden" name="add_product" value="1" />
</table>
</form>
</div>*/