/
reservation.php
161 lines (99 loc) · 4.85 KB
/
reservation.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
<?php
if(mysql_num_rows(getActiveWarningsForUser(getSessionVariable('user_id'))) < RES_WARNING_MAX_ACTIVE){
if(isset($_GET['equipid']))
$equipid = $_GET['equipid'];
$message = "";
if($pageid == "finishres"){
$userid = getSessionVariable('user_id');
$equipid = $_POST['equip_id'];
$startdate = $_POST['startdate'];
$length = $_POST['length'];
$usercomment = $_POST['usercomment'];
$start_Date = new DateTime(''.$startdate.' 00:00:00');
$start_Date->modify("+".$length." day");
//$interval = new DateInterval("P".$length."D");
//$start_Date->add($interval);
$enddate = $start_Date->format("Y-m-d");
$numrows = mysql_num_rows(getReservationsByEquipIDandDate($equipid, $startdate, $enddate));
if($numrows > 0){
$message = "<font color=\"#FF0000\"><b>Error: There already is a reservation durring your start date and end date.</b><br>Please check <a href=\"./viewsched.php?equipid=".$equipid."\" target=\"_blank\">the shedule</a>.</font><br><br>";
}
else if($numrows == 0 && ($equipid != "" && $startdate != "" && $length != "")){
$equipment = mysql_fetch_assoc(getEquipmentByID($equipid));
if($equipment['max_length'] < $length){
$message = "<font color=\"#FF0000\"><b>Error: Cannot reserve this equipment for that long.</b></font><br><br>";
}
else{
if(isDateRangeBlackedOut($startdate,$enddate)){
$message = "<font color=\"#FF0000\"><b>Error: Date Range Blacked-Out.</b></font><br><br>";
}else{
if($equipment['checkoutfrom'] != -1){
$message = "<font color=\"#FF0000\"><b>Error: You must check this out from it's assigned user.</b></font><br><br>";
}
else{
createReservation($userid, $equipid, $startdate, $length, $usercomment, "", 0);
$message = "<font color=\"#005500\"><b>Successfully created new reservation!</b></font><br><br>";
}
}
}
}
}
$equipment = mysql_fetch_assoc(getEquipmentByID($equipid));
$length = "";
for($i = 1; $i <= $equipment["max_length"]; $i++){
$length = $length . "<option value=\"".($i)."\">".($i)."</option>";
}
echo "
<center><h3>Make Reservation</h3>".$message."</center>
<script type=\"text/javascript\">
function checkDate(){
if(document.reservation.startdate.value == \"".getCurrentMySQLDate()."\"){
return confirm(\"Reservations placed on the same day as they are created cannot be guaranteed to be ready for their start date. By continuing you are acknowledging that. Would you like to continue?\");
}else{
return true;
}
}
</script>
<form name=\"reservation\" action=\"./index.php?pageid=finishres\" method=\"POST\" onsubmit=\"return checkDate();\">
<table class=\"reservation\">
<tr>
<td colspan=4 class=\"header\">Reserve the ".$equipment["name"]."<input type=\"hidden\" name=\"equip_id\" value=\"".$equipid."\"></td>
</tr>
<tr>
<td class=\"centeredcellbold\">Date (YYYY-MM-DD)</td>
<td class=\"centeredcell\"><script language=\"JavaScript\" id=\"jscal1x\">
var cal1x = new CalendarPopup(\"testdiv1\");
</script><input type=\"text\" name=\"startdate\" id=\"startdate\" onClick=\"cal1x.select(document.forms[0].startdate,'anchor1x','yyyy-MM-dd'); return false;\"><a style=\"visibility:hidden;\" name=\"anchor1x\" id=\"anchor1x\">a</a></td>
<td class=\"centeredcellbold\">Length</td>
<td class=\"centeredcell\"><select name=\"length\">".$length."</select></td>
</tr>
<!--<tr>
<td colspan=4 class=\"centeredcellbold\">Pickup Time:
<select name=\"pickup\">
<option value=\"10am-12pm (Monday/Friday)\">10am-12pm (Monday/Friday)</option>
<option value=\"9am-12pm (Tuesday)\">9am-12pm (Tuesday)</option>
<option value-\"9-10 (Wednesday/Thursday)\">9-10 (Wednesday/Thursday)</option>
<option value=\"2pm-4pm (Wednesday)\">2pm-4pm (Wednesday)</option>
<option value=\"12pm-2pm (Thursday)\">12pm-2pm (Thursday)</option>
</select>
</td>
</tr>-->
<tr>
<td colspan=1 class=\"centeredcellbold\">User Comment</th>
<td class=\"centeredcell\" colspan=3><textarea rows=5 cols=45 name=\"usercomment\"></textarea></td>
</tr>
<tr>
<td colspan=4 class=\"centeredcell\"><input type=\"submit\" value=\"Reserve\"></td>
</tr>
</table>
</form></div><DIV ID=\"testdiv1\" STYLE=\"position:absolute;visibility:hidden;background-color:white;\"></DIV>
";
}else{
echo "<center><h3><font color=\"#FF0000\">Error: You have recieved 3 or more warnings.</font></h3>To reserve equipment please contact an admin: <br><br>";
$admins = getAdmins();
while($row = mysql_fetch_assoc($admins)){
echo $row['name'] . " -- " . $row['email'] . "<br>";
}
echo "</center>";
}
?>