/
volunteerEventPage.php
284 lines (265 loc) · 11.1 KB
/
volunteerEventPage.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
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
include('session.php');
if (!isset($_SESSION['login_auth'])){
header("location: Guest.php");
}
switch($_SESSION['login_auth']){
case "S":
header("location: Student.php"); // Redirecting To Student Page
break;
}
?>
<?php
$event = $_POST['event'];
$connection = mysqli_connect("localhost", "root", "091904", "holmenHighSchool");
$eventObject = mysqli_query($connection, "select * from events WHERE eventId = $event ");
$row = $eventObject->fetch_object();
$eventTitle = $row->title;
$minVolunteers = $row->minVolunteers;
$maxVolunteers = $row->maxVolunteers;
$minStudents = $row->minStudents;
$maxStudents = $row->maxStudents;
$description = $row->description;
$startDateTime = $row->startDateTime;
$endDateTime = $row->endDateTime;
$SYear = $startDateTime{0}.$startDateTime{1}.$startDateTime{2}.$startDateTime{3};
$SMonth = $startDateTime{5}.$startDateTime{6};
$SDay = $startDateTime{8}.$startDateTime{9};
$SHour = $startDateTime{11}.$startDateTime{12};
$SMin = $startDateTime{14}.$startDateTime{15};
$EYear = $endDateTime{0}.$endDateTime{1}.$endDateTime{2}.$endDateTime{3};
$EMonth = $endDateTime{5}.$endDateTime{6};
$EDay = $endDateTime{8}.$endDateTime{9};
$EHour = $endDateTime{11}.$endDateTime{12};
$EMin = $endDateTime{14}.$endDateTime{15};
mysqli_close($connection);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Event Creator</title>
<!-- Styles -->
<link rel="stylesheet" type="text/css" href="normalize.css/normalize.css" />
<link rel="stylesheet" type="text/css" href="theme.css" />
<link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css?family=Cuprum&subset=latin' />
<link rel="stylesheet" type="text/css" href="forms/view.css" media="all">
<link rel="stylesheet" type="text/css" href="jquery.confirm/jquery.confirm.css" />
<style type="text/css">
.auto-style1 {
margin-top: 0;
}
</style>
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="forms/view.js"></script>
<script type="text/javascript" src="forms/calendar.js"></script>
<script src="jquery.confirm/jquery.confirm.js"></script>
</head>
<body>
<div id="title">
<a href="Volunteer.php">
<h2 id="titleName">
<img id="titleIcon" src="img/bot2.jpg" alt="icon"> Holmen High School Robotics Club
</h2>
</a>
<input id="log" class="button" type="button" onClick="location.href='logout.php'" value="Log out">
<input id="changePassword" class="button" type="button" onClick="location.href='changePassword.php'" value="Change password">
</div>
<div id="main_body">
<div id="form_container">
<h2> <a style="width: 637px">Create a new Event</a></h2>
<form id="form_1059751" class="appnitro" method="post" action="">
<div class="form_description">
Fill in event details to create an event.
</div>
<ul style="width: 103%; height: 927px" >
<li id="Title" style="left: 0px; top: -3px; width: 45%; height: 65px" >
<label class="description" for="Title">Title </label>
<div>
<input id="Title" name="Title" class="element text medium" type="text" maxlength="255" value="<?=$eventTitle?>" required/>
</div>
</li>
<li id="Location" style="left: 342px; top: -73px; width: 41%; height: 65px" >
<label class="description" for="description">Location </label>
<div>
<input id="description" name="Location" class="element text medium" type="text" maxlength="255" value="" required/>
</div>
</li>
<li id="StartDate" style="left: 4px; top: -48px; width: 44%" >
<label class="description" for="StartDate">Start Date </label>
<span>
<input id="SMonth" name="SMonth" class="element text" size="3" maxlength="2" value="<?=$SMonth?>" type="text" required/> /
<label for="SMonth">MM</label>
</span>
<span>
<input id="SDay" name="SDay" class="element text" size="3" maxlength="2" value="<?=$SDay?>" type="text" required/> /
<label for="SDay">DD</label>
</span>
<span>
<input id="SYear" name="SYear" class="element text" size="5" maxlength="4" value="<?=$SYear?>" type="text" required/>
<label for="SYear">YYYY</label>
</span>
</li>
<li id="EndDate" class="auto-style1" style="left: 343px; top: -107px; width: 42%" >
<label class="description" for="EndDate">End Date </label>
<span>
<input id="EMonth" name="EMonth" class="element text" size="3" maxlength="2" value="<?=$EMonth?>" type="text" required/> /
<label for="EMonth">MM</label>
</span>
<span>
<input id="EDay" name="EDay" class="element text" size="3" maxlength="2" value="<?=$EDay?>" type="text" required/> /
<label for="EDay">DD</label>
</span>
<span>
<input id="EYear" name="EYear" class="element text" size="5" maxlength="4" value="<?=$EYear?>" type="text" required/>
<label for="EYear">YYYY</label>
</span>
</li>
<li id="StartTime" style="left: 4px; top: -107px; width: 42%" >
<label class="description" for="StartTime">Start Time </label>
<span>
<input id="SHour" name="SHour" class="element text " size="3" type="text" maxlength="2" value="<?=$SHour?>" required/> :
<label>HH</label>
</span>
<span>
<input id="SMin" name="SMin" class="element text " size="3" type="text" maxlength="2" value="<?=$SMin?>" required/>
<label>MM</label>
</span>
</li>
<li id="li_6" style="left: 343px; top: -174px; width: 42%" >
<label class="description" for="EndTime">End Time </label>
<span>
<input id="EHour" name="EHour" class="element text " size="3" type="text" maxlength="2" value="<?=$EHour?>" required/> :
<label>HH</label>
</span>
<span>
<input id="EMin" name="EMin" class="element text " size="3" type="text" maxlength="2" value="<?=$EMin?>" required/>
<label>MM</label>
</span>
</li>
<li id="MinVol" style="left: 4px; top: -116px; width: 37%" >
<label class="description" for="MinVol">Min Number of Volunteers </label>
<div>
<input id="MinVol" name="MinVol" class="element text small" type="text" maxlength="255" value="<?=$minVolunteers?>" style="width: 11%" required/>
</div>
</li>
<li id="MaxVol" style="left: 343px; top: -170px; width: 37%" >
<label class="description" for="MaxVol">Max Number of Volunteers </label>
<div>
<input id="MaxVol" name="MaxVol" class="element text small" type="text" maxlength="255" value="<?=$maxVolunteers?>" style="width: 11%" required/>
</div>
</li>
<li id="MinStud" style="left: 4px; top: -154px; width: 36%" >
<label class="description" for="MinStud">Min Number of Students </label>
<div>
<input id="MinStud" name="MinStud" class="element text small" type="text" maxlength="255" value="<?=$minStudents?>" style="width: 11%" required/>
</div>
</li>
<li id="MaxStud" style="left: 343px; top: -210px; width: 36%" >
<label class="description" for="MaxStud">Max Number of Students </label>
<div>
<input id="MaxStud" name="MaxStud" class="element text small" type="text" maxlength="255" value="<?=$maxStudents?>" style="width: 11%" required/>
</div>
</li>
<li id="Desc" style="left: 4px; top: -112px; width: 95%" >
<label class="description" for="Desc">Description </label>
<div>
<textarea id="Desc" name="Desc" placeholder="" class="element textarea medium"><?=$description?></textarea>
</div>
</li>
<li class="buttons" style="left: 4px; top: -100px">
<input type="hidden" name="form_id" value="1059751" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Change" />
</li>
</ul>
</form>
</div>
<img id="bottom" src="forms/bottom.png" alt="">
</div>
</body>
</html>
<?php
// Logic to handle submission of form
if (isset($_POST['submit'])) {
// Get username of person creating event
$user = $_SESSION['login_user'];
// Set date variables and put into ISO 8601
$maxVol = $_POST['MaxVol'];
$minVol = $_POST['MinVol'];
$minStud = $_POST['MinStud'];
$maxStud = $_POST['MaxStud'];
$today = date("Y-m-d H:i:s");
$startDateTime = $_POST['SYear']. "-" .$_POST['SMonth']. "-" .$_POST['SDay']. " " .$_POST['SHour']. ":" .$_POST['SMin']. ":00";
$endDateTime = $_POST['EYear']. "-" .$_POST['EMonth']. "-" .$_POST['EDay']. " " .$_POST['EHour']. ":" .$_POST['EMin']. ":00";
if(!checkDateTime($startDateTime)){
echo "<div>Start Date is not a valid date.</div>";
}else if(!checkDateTime($endDateTime)){
echo "<div>End Date is not a valid date.</div>";
}else if(!ctype_digit( $maxVol )){
echo "<div>Max Volunteer number is not a integer.</div>";
}else if(!ctype_digit( $minVol )){
echo "<div>Min Volunteer number is not a integer.</div>";
}else if(!ctype_digit( $minStud )){
echo "<div>Min Student number is not a integer.</div>";
}else if(!ctype_digit( $maxStud )){
echo "<div>Max Student number is not a integer.</div>";
}else if($today > $startDateTime ){
echo "<div>Start Date is not onward.</div>";
}else if($endDateTime < $startDateTime ){
echo "<div>End Date is before Start Date.</div>";
}
else{
$title = mysqli_real_escape_string($connection, $_POST['Title']);
$location = mysqli_real_escape_string($connection, $_POST['Location']);
$description = mysqli_real_escape_string($connection, $_POST['Desc']);
// Create connection
$connection = mysqli_connect("localhost", "root", "091904", "holmenHighSchool");
// Check connection
if (mysqli_connect_errno($connection)) {
echo "<div>";
echo "Failed to connect to MySQL: " . mysqli_connect_error();
echo "</div>";
}
$userObject = mysqli_query($connection, "select * from users WHERE username = '$user' ");
$row = $userObject->fetch_object();
$userid = $row->id;
// Insert event into database
$newQuery = "UPDATE events SET title='$title', description='$description', startDateTime='$startDateTime',
endDateTime='$endDateTime', minVolunteers=$minVol, maxVolunteers=$maxVol, minStudents=$minStud, maxStudents=$maxStud where eventId=$event";
if(mysqli_query($connection, $newQuery)){
echo ("<script>$.confirm({
'title' : '',
'message' : '<div align=\"center\">Successfully added new event</div>',
'buttons' : {
'OK' : {
'class' : 'blue',
}
},
});</script>");
}
else {
echo ("<script>$.confirm({
'title' : '',
'message' : '<div align=\"center\">Failed to add event to the database</div>',
'buttons' : {
'OK' : {
'class' : 'blue',
}
},
});</script>");
}
mysqli_close($connection); // Closing Connection
}
}
function checkDateTime($data) {
if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
return true;
} else {
return false;
}
}
?>