forked from Xinyi-Lai/CS411_Geniuses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_request.php
executable file
·218 lines (190 loc) · 10.1 KB
/
post_request.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
<?php
session_start();
include_once "db_functions.php";
$msg = "";
$product_name_err = $tag_err = "";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$buyer_id = $_SESSION['curr_user'];
$product_name = ppc($_POST["product_name"]);
$tag = ppc($_POST["tag"]);
$description = ppc($_POST["description"]);
$intended_price = (double)ppc($_POST["intendedPrice"]);
if (empty($product_name)){
$product_name_err = "* Product name is required.";
}
if (empty($tag)){
$tag_err = "* Tag is required.";
}
if ($product_name_err || $tag_err){
$msg = "* Please check your input again";
}else {
$filename = "";
if (file_exists($_FILES['image']['tmp_name'])){
$upload_dir="images/".$buyer_id."/";
if(!is_dir($upload_dir)) {
mkdir($upload_dir);
}
/* Get the postfix of the image */
$postfix = substr($_FILES['image']['name'],strrpos($_FILES['image']['name'],'.'));
/* Set the file name */
$filename = $upload_dir.date("YmdHis").$postfix;
/* Store the image to the server */
if(!move_uploaded_file($_FILES['image']['tmp_name'], $filename)){
echo 'Store fail';
die;
}
}
/* Get the database */
$conn = connectDB();
/* Set the decode */
$sql = "INSERT INTO Requests(BuyerID, ProductName, Tag, Description, Image, IntendedPrice)
VALUES ('$buyer_id', '$product_name', '$tag', '$description', '$filename', $intended_price)";
$success = $conn->query($sql);
if ($success){
header("location:myrequests.php");
exit;
}else{
echo 'Insert fail'.$conn->error;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>BEACON - Post_Request</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,400i,700,700i,600,600i">
<link rel="stylesheet" href="assets/css/baguetteBox.min.css">
<link rel="stylesheet" href="assets/css/smoothproducts.css">
</head>
<body>
<nav class="navbar navbar-dark navbar-expand-lg bg-primary clean-navbar" style="height: 60px; padding-top: 30px;">
<div class="container"><button data-toggle="collapse" class="navbar-toggler" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="navbar-toggler-icon"></span></button><a class="navbar-brand text-white logo" href="index.php"><p style="font-size: larger;">BEACON</p></a>
<div class="collapse navbar-collapse"
id="navcol-1">
<ul class="nav navbar-nav ml-auto"></ul>
</div>
</div>
</nav>
<main class="page post-page">
<section class="clean-block clean-form dark">
<div class="container">
<div class="block-heading">
<h2 class="text-info">Post Your Request</h2>
</div>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<!-- productName input -->
<div class="form-group">
<label for="focusedInput">Product Name</label><span class="warning"> <?php echo $product_name_err;?></span>
<input class="form-control item" type="text" name="product_name" placeholder="product name" value="<?php echo $product_name; ?>"/>
</div>
<!-- tag input -->
<div class="form-group">
<label for="focusedInput">Tag</label><span class="warning"> <?php echo $tag_err;?></span>
<select class="form-control" id="tag" name="tag" value="<?php echo $tag; ?>">
<optgroup label="tag">
<option value="accessories" <?php echo $tag=="accessories" ? 'selected':'' ?> >accessories</option>
<option value="clothing" <?php echo $tag=="clothing" ? 'selected':'' ?> >clothing</option>
<option value="daily necessity" <?php echo $tag=="daily necessity" ? 'selected':'' ?> >daily necessity</option>
<option value="electronics"<?php echo $tag=="electronics" ? 'selected':'' ?> >electronics</option>
<option value="food" <?php echo $tag=="food" ? 'selected':'' ?> >food</option>
<option value="furniture" <?php echo $tag=="furniture" ? 'selected':'' ?> >furniture</option>
<option value="jewelry" <?php echo $tag=="jewelry" ? 'selected':'' ?> >jewelry</option>
<option value="makeup/personal care" <?php echo $tag=="makeup/personal care" ? 'selected':'' ?> >makeup/personal care</option>
<option value="otherbooks" <?php echo $tag=="otherbooks" ? 'selected':'' ?> >otherbooks</option>
<option value="other" <?php echo $tag=="other" ? 'selected':'' ?> >other</option>
<option value="sports" <?php echo $tag=="sports" ? 'selected':'' ?> >sports</option>
<option value="sublease" <?php echo $tag=="sublease" ? 'selected':'' ?> >sublease</option>
<option value="stationery" <?php echo $tag=="stationery" ? 'selected':'' ?> >stationery</option>
<option value="test prep" <?php echo $tag=="test prep" ? 'selected':'' ?> >test prep</option>
<option value="textbook" <?php echo $tag=="textbook" ? 'selected':'' ?> >textbook</option>
<option value="tools" <?php echo $tag=="tools" ? 'selected':'' ?> >tools</option>
<option value="toys/games" <?php echo $tag=="toys/games" ? 'selected':'' ?> >toys/games</option>
</optgroup>
</select>
</div>
<!-- description confirm -->
<div class="form-group">
<label for="focusedInput">Description</label> <span class="warning">
<input class="form-control item" type="text" name="description" placeholder="description" value="<?php echo $description; ?>"/>
</div>
<!-- intendedPrice input -->
<div class="form-group">
<label for="focusedInput">Intended Price</label>
<input class="form-control item" type="text" name="intendedPrice" placeholder="intended price" value="<?php echo $intended_price; ?>"/>
</div>
<!-- Image upload -->
<div class="form-group">
<label for="focusedInput">Image</label><br/>
<input type="file" name="image"/><br/>
</div>
<div class="form-group">
<fieldset>
<legend></legend>
</fieldset>
</div>
<button class="btn btn-primary btn-block" type="submit" name="submit">Post</button>
</form>
</div>
</section>
</main>
<footer class="page-footer dark">
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="single-widget">
<h5>ABOUT US</h5>
<ul>
<span class="white-font">CS411 2020 Summer Course Project</br></span>
<span class="white-font">Team Geniuses</br></span>
<span class="white-font">Xinyi Lai: [email protected]</br></span>
<span class="white-font">Jiaqi Lou: [email protected]</br></span>
<span class="white-font">Hanyin Shao: [email protected]</br></span>
<span class="white-font"> Kerui Zhu: [email protected]</span>
</ul>
</div>
</div>
<div class="col-sm-3">
<div class="single-widget">
<h5>INFORMATION</h5>
<ul>
<span class="white-font"><a href="#">Frequently Asked Question</a></br></span>
<span class="white-font"><a href="#">Terms and Condition</a></br></span>
<span class="white-font"><a href="#">Privacy Policy</a></br></span>
<span class="white-font"><a href="#">Customer Service</a></br></span>
<span class="white-font"><a href="#">Delivery Information</a></br></span>
<span class="white-font"><a href="#">Manufacturers</a></br></span>
</ul>
</div>
</div>
<div class="col-sm-3">
<div class="single-widget">
<h5>CUSTOMER CARE</h5>
<ul>
<span class="white-font"><a href="#">Contact Us</a></br></span>
<span class="white-font"><a href="#">Sitemap</a></br></span>
<span class="white-font"><a href="#">Live Chat 24x7</a></br></span>
</ul>
</div>
</div>
<div class="col-sm-3">
<div class="single-widget-1">
<h5>OUR SERVICES</h5>
<ul>
<span class="white-font"><a href="#">Secure Shopping</a></br></span>
</ul>
</div>
</div>
</div>
</div>
</footer>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/baguetteBox.min.js"></script>
<script src="assets/js/smoothproducts.min.js"></script>
<script src="assets/js/theme.js"></script>
</body>
</html>