-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_product.php
337 lines (225 loc) · 12.6 KB
/
add_product.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php
Session_start();
if (isset($_SESSION['admin_user'])){
?>
<!DOCTYPE html>
<head>
<title>Argjentina Bike Sklep</title>
<link rel="SHORTCUT ICON" href="images/favicon.png" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="eng-GB" />
<meta http-equiv="Cache-control" content="private" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<meta name="robots" content="all" />
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
background-color: #101010;
}
.style2 {font-size: 12}
.style3 {
font-size: 10px;
font-style: italic;
}
-->
</style></head>
<body>
<!-- Banner settings -->
<center><table width="951" border="1">
<thead>
<tr>
<th height="202" colspan="2" rules="all" background="images/logo.png"></th>
</tr>
</thead>
<tfoot>
<tr>
<!-- Footer settings - Left side -->
<th height="100" colspan="2" background="images/footer.png" >
<div align="left"> <font color="white">Powered by</font> <font color="CornflowerBlue">R</font><font color="white">eday</font></a></div>
<div align="left"> <font color="white">Theme by</font> <font color="CornflowerBlue">J</font><font color="white">acek</font></a></div><br><br>
<!-- Footer settings - Right side -->
<div align="right"><a style="text-decoration:none;" href="backdoor.html"><font
color="CornflowerBlue">A</font><font color="white">dmin</font> <font color="CornflowerBlue">P</font><font color="white">anel</font></a>
</tr>
</tfoot>
<tbody>
<!-- Horizontal navigation - Left side -->
<tr>
<th height="30" colspan="1" background="images/nav_background.jpg">
<div align="left"><a style="text-decoration:none;" href="index.php"><font color="CornflowerBlue">H</font><font color="white">ome</font></a> -
<a style="text-decoration:none;" href="mailto:[email protected]"><font color="CornflowerBlue">C</font><font color="white">ontact</font></a> -
<a style="text-decoration:none;" href="Products.php"><font color="CornflowerBlue">P</font><font color="white">roducts <font color="CornflowerBlue">B</font>ikes</font></a> -
<!-- Horizontal navigation - Right side -->
<th><div align="center"><a style="text-decoration:none;" href="basket.html"><font color="CornflowerBlue">B</font><font color="white">asket</font></a> -
<a style="text-decoration:none;" href="login_register.html"><font color="CornflowerBlue">L</font><font color="white">ogin </font><font color="white">/ </font><font color="CornflowerBlue">R</font><font color="white">egister</font></a>
- <a style="text-decoration:none;" href="logout.php"><font color="CornflowerBlue">L</font><font color="white">ogout</font></a>
</div>
</th>
</tr>
<tr>
<!-- Body page -->
<td width="711" valign="top" style="background-color: #FFFFFF" >
<?php
/**
* Created by IntelliJ IDEA.
* User: reday
* Date: 19/03/2017
* Time: 16:11
*/
//Image Script -------------------------------------------------------
//Housten we have a problem
$housten = 1;
// Setting Directory
$target_dir = "images/";
//storing target descr in var
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
//adjusting filename for db stuff
$product_name_img_id = "images/" . basename(basename($_FILES["fileToUpload"]["name"]));
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1> Product Successfully Added </h1>";
echo "<a href = 'admin_cms.php'><h1>Please Click Here to go back to the CMS</h1></a>";
$housten = 1;
}
else {
echo "<h1> the upload has been incomplete, product details broken prod added </h1>";
echo "<a href = 'admin_cms.php'><h1>Please Click Here to go back to the CMS</h1></a>";
$housten = 0;
};
// --------------------------------------------------------------------
// Adding Product MongoDB ---------------------------------------------
//Housten is a variable that checks wether the upload has been successful or not. It does not execute adding something to the db if it has failed to upload image
if ($housten = 1) {
// establish connection
$mongoClient = new MongoClient();
$db = $mongoClient->Products;
$collection = $db->catalog;
//fetch data
$product_name = filter_input(INPUT_POST, 'prod_name', FILTER_SANITIZE_STRING);
$product_description = filter_input(INPUT_POST, 'prod_descr', FILTER_SANITIZE_STRING);
$product_url = $product_name_img_id;
$product_price = filter_input(INPUT_POST, 'prod_price', FILTER_SANITIZE_NUMBER_INT);
$product_stock = filter_input(INPUT_POST, 'prod_stock', FILTER_SANITIZE_NUMBER_INT);
//Constructing DB data
$prod_reg_info = [
"name" => $product_name,
"description" => $product_description,
"image_url" => $product_url,
"price" => $product_price,
"stock_count" => $product_stock,
];
//Insertion Operation
$returnVal = $collection->insert($prod_reg_info);
// Closing Connection
$mongoClient->close();
}
else {
echo "<h1> Houston we have a problem! Image upload was unsuccessful!";
echo "<a href = 'admin_cms.php'><h1>Please Click Here to go back to the CMS</h1></a>";
}
// --------------------------------------------------------------------
?>
<!-- Vertical Navigation -->
<td width="240" valign="top" background="images/nav_background.jpg">
<center>
<span style="color: CornflowerBlue"><b> ------</b></span> <span style="color: CornflowerBlue"><b>R</b></span><span style="color: white"><b>ecommended</b></span> <span style="color: CornflowerBlue"><b>B</b></span><span style="color: white"><b>ikes</b></span> <span style="color: CornflowerBlue"><b>------ </b></span><br><br>
<span style="color: white"><b>FEU - Speed Road 2017</b></span><br>
<a href="recommended_bike.html"><img src="images/bike.png" height="146" width="230"></a>
<br><br>
<span style="color: white"><b>CUBE - BMK 2017</b></span><br>
<a href="recommended_bike2.html"><img src="images/bike2.png" height="146" width="230"></a>
<br><br>
<span style="color: white"><b>BULLS - Cross 2017</b></span><br>
<a href="recommended_bike3.html"><img src="images/bike3.png" height="146" width="230"</a>
<br>
<br>
</center>
</td>
</tr>
</tbody>
</table></center>
</body>
</html>
<?php
} else {
?>
<!DOCTYPE html>
<head>
<title>Argjentina Bike Sklep</title>
<link rel="SHORTCUT ICON" href="images/favicon.png" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="eng-GB" />
<meta http-equiv="Cache-control" content="private" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<meta name="robots" content="all" />
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
background-color: #101010;
}
.style2 {font-size: 12}
.style3 {
font-size: 10px;
font-style: italic;
}
-->
</style></head>
<body>
<!-- Banner settings -->
<center><table width="951" border="1">
<thead>
<tr>
<th height="202" colspan="2" rules="all" background="images/logo.png"></th>
</tr>
</thead>
<tfoot>
<tr>
<!-- Footer settings - Left side -->
<th height="100" colspan="2" background="images/footer.png" >
<div align="left"> <font color="white">Powered by</font> <font color="CornflowerBlue">R</font><font color="white">eday</font></a></div>
<div align="left"> <font color="white">Theme by</font> <font color="CornflowerBlue">J</font><font color="white">acek</font></a></div><br><br>
<!-- Footer settings - Right side -->
<div align="right"><a style="text-decoration:none;" href="index.html"><font
color="CornflowerBlue">H</font><font color="white">ome</font> <font color="CornflowerBlue">P</font><font color="white">age</font></a>
</tr>
</tfoot>
<tbody>
<!-- Horizontal navigation - Left side -->
<tr>
<th height="30" colspan="1" background="images/nav_background.jpg">
<div align="left"><a style="text-decoration:none;" href="index.html"><font color="CornflowerBlue">H</font><font color="white">ome</font> <font color="CornflowerBlue">P</font><font color="white">age</font></a> -
<a style="text-decoration:none;" href="mailto:[email protected]"><font color="CornflowerBlue">C</font><font color="white">ontact</font></a> -
<a style="text-decoration:none;" href="road_bikes.html"><font color="CornflowerBlue">R</font><font color="white">oad <font color="CornflowerBlue">B</font>ikes</font></a> -
<a style="text-decoration:none;" href="mountain_bikes.html"><font color="CornflowerBlue">M</font><font color="white">ountain <font color="CornflowerBlue">B</font>ikes</font></a> -
<a style="text-decoration:none;" href="hybrids.html"><font color="CornflowerBlue">H</font><font color="white">ybrids</font></a></div>
<!-- Horizontal navigation - Right side -->
<th><div align="center"><a style="text-decoration:none;" href="basket.html"><font color="CornflowerBlue">B</font><font color="white">asket</font></a> -
<a style="text-decoration:none;" href="login_register.html"><font color="CornflowerBlue">L</font><font color="white">ogin </font><font color="white">/ </font><font color="CornflowerBlue">R</font><font color="white">egister</font></a>
</div>
</th>
</tr>
<tr>
<!-- Body page -->
<td width="711" valign="top" style="background-color: #FFFFFF" >
<font size="+3"><center>
<strong><i>Please log in to view</i></strong>
</center></font><br>
<!-- Vertical Navigation -->
<td width="240" valign="top" background="images/nav_background.jpg">
<center>
<span style="color: CornflowerBlue"><b> ------</b></span> <span style="color: CornflowerBlue"><b>R</b></span><span style="color: white"><b>ecommended</b></span> <span style="color: CornflowerBlue"><b>B</b></span><span style="color: white"><b>ikes</b></span> <span style="color: CornflowerBlue"><b>------ </b></span><br><br>
<br>
<br>
</center>
</td>
</tr>
</tbody>
</table></center>
</body>
</html>
<?php
}
?>