-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.php
More file actions
262 lines (252 loc) · 9.31 KB
/
scripts.php
File metadata and controls
262 lines (252 loc) · 9.31 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
//Variables
//$dbhost = "localhost";
//$dbuser = "root";
//$dbpass = "root";
function makeConnection($dbhost, $dbuser, $dbpass, $dbname){
return $con = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
}
//Gets run on Login to populate session with user data.
function populateSession($connection){
$query = "SELECT * FROM login_information WHERE user_name='" . $_SESSION['user_name'] . "'";
//echo $query;
$result = mysqli_query($connection, $query);
/*
$list = mysql_fetch_array($result);
$size_of_list = sizeof($list);
*/
//This one Works
while($row = $result->fetch_assoc())
{
//Username is already stored on login.
$_SESSION['user_email'] = $row['user_email'];
$_SESSION['isAdmin'] = $row['isAdmin'];
$_SESSION['isEmployee'] = $row['isEmployee'];
}
}
function uploadAboutPicture($ftu){
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES[$ftu]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["aboutPicSubmit"])) {
$check = getimagesize($_FILES[$ftu]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
//Check file size
if ($_FILES[$ftu]["size"] > 5000000) {
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.";
} else { // if everything is ok, try to upload file
if (move_uploaded_file($_FILES[$ftu]["tmp_name"], "images/aboutuspic.png")) {
echo "The file ". basename( $_FILES[$ftu]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
}
function uploadSlidePicture($ftu){
$target_dir = "images/slideshow/";
$target_file = $target_dir . basename($_FILES[$ftu]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES[$ftu]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
//Check file size
if ($_FILES[$ftu]["size"] > 5000000) {
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.";
} else { // if everything is ok, try to upload file
if (move_uploaded_file($_FILES[$ftu]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES[$ftu]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
function uploadProdPic($ftu) {
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES[$ftu]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES[$ftu]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
//Check file size
if ($_FILES[$ftu]["size"] > 5000000) {
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.";
} else { // if everything is ok, try to upload file
if (move_uploaded_file($_FILES[$ftu]["tmp_name"], $target_file)) {
// echo "The file ". basename( $_FILES[$ftu]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
function changeTextFile($filename, $formName) {
$file = 'adminTools/'. $filename;
// check if form has been submitted
if (isset($_POST[$formName]))
{
// save the text contents
file_put_contents($file, $_POST[$formName]);
}
// read the textfile
$text = file_get_contents($file);
return $text;
}
function addProductForm() {
echo '<form action="" method="POST" enctype="multipart/form-data">
Item Name:<br>
<textarea name="itemName" ></textarea>
<br>
Price:<br>
<textarea name="price" ></textarea>
<br>
Description:<br>
<textarea name="desc" rows=7 cols=40 ></textarea>
<br>
Calories:<br>
<textarea name="cal" ></textarea>
<br>
Protein:<br>
<textarea name="prot" ></textarea>
<br>
Choles:<br>
<textarea name="chol" ></textarea>
<br>
Sodium:<br>
<textarea name="sodi" ></textarea>
<br>
Carbohydrates:<br>
<textarea name="carb" ></textarea>
<br>
Sugar:<br>
<textarea name="sugar" ></textarea>
<br>
Picture:<br>
<input type="file" name="picLink" id="picLink">
<input type="submit" value="Add Product" name="prodSubmit">
</form>';
}
function editProductForm($prod) {
echo '<form action="" method="POST" enctype="multipart/form-data">
<br>Item Name:<br>
<textarea name="itemName" >'.$prod["itemName"].'</textarea>
<br>
Price:<br>
<textarea name="price" >'.$prod["price"].'</textarea>
<br>
Description:<br>
<textarea name="desc" rows=7 cols=40 >'.$prod["description"].'</textarea>
<br>
Calories:<br>
<textarea name="cal" >'.$prod["calories"].'</textarea>
<br>
Protein:<br>
<textarea name="prot" >'.$prod["protein"].'</textarea>
<br>
Choles:<br>
<textarea name="chol" >'.$prod["choles"].'</textarea>
<br>
Sodium:<br>
<textarea name="sodi" >'.$prod["sodi"].'</textarea>
<br>
Carbohydrates:<br>
<textarea name="carb" >'.$prod["carbo"].'</textarea>
<br>
Sugar:<br>
<textarea name="sugar" >'.$prod["sugars"].'</textarea>
<br>
Current Picture:<br>
<img src=images/'.$prod["picLink"].' /><br />
New Picture:<br>
<input type="file" name="picLink" id="picLink"><br><br>
<input type="submit" value="Edit Product" name="changeSubmit">
</form>';
}
function editProduct( $itm, $prc, $dsc, $cl, $prt, $chl, $sdi, $crb, $sgr, $pclnk=null ) {
$itemName = mysqli_real_escape_string($con, $_REQUEST[$itm]);
$price = mysqli_real_escape_string($con, $_REQUEST[$prc]);
$desc = mysqli_real_escape_string($con, $_REQUEST[$dsc]);
$cal = mysqli_real_escape_string($con, $_REQUEST[$cl]);
$prot = mysqli_real_escape_string($con, $_REQUEST[$prt]);
$chol = mysqli_real_escape_string($con, $_REQUEST[$chl]);
$sodi = mysqli_real_escape_string($con, $_REQUEST[$sdi]);
$carb = mysqli_real_escape_string($con, $_REQUEST[$crb]);
$sugar = mysqli_real_escape_string($con, $_REQUEST[$sgr]);
if($pcLnk != null) {
$pic = mysqli_real_escape_string($con, basename($_FILES[$pcLnk]["name"]));
$sql = $db->prepare(
"UPDATE items
SET itemName='$itemName', price='$price', description='$desc', calories='$cal', protein='$prot', choles='$chol',
sodi='$sodi', picLink='$pcLnk', carbo='$carb', sugars='$sugar'" );
if ($sql->execute()){
echo '<br>Product added successfully. Please refresh page to see changes.';
} else {
echo 'error';
}
}
else {
$sql = $db->prepare(
"UPDATE items
SET itemName='$itemName', price='$price', description='$desc', calories='$cal', protein='$prot', choles='$chol',
sodi='$sodi', carbo='$carb', sugars='$sugar'" );
if ($sql->execute()){
echo '<br>Product added successfully. Please refresh page to see changes.';
} else {
echo 'error';
}
}
}
?>