forked from cjbara/domerdoors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpick.php
executable file
·200 lines (185 loc) · 7.57 KB
/
pick.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
<html>
<head>
<title>Pick</title>
<!--These two links are for bootstrap -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<!--PHP script at top so rest of html/css can get variables-->
<?php
// Connect and select database
$link = mysqli_connect("localhost", "cjbara", "database","domerdoors")
or die ("Connection failed: " .mysqli_connect_error());
//Get netID and query for name
$netID = $_REQUEST['netID'];
$pwd = $_REQUEST['password'];
$query = "select name, dorm from Resident where Resident.netID = $netID and Resident.password = $pwd;";
$result = mysqli_query($link,$query);
if(mysqli_num_rows($result) > 0){
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$name = $row['name'];
$dorm = $row['dorm'];
}
}
?>
<!---Navigation Bar at top-->
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<!--<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">-->
<ul class="nav navbar-nav">
<li><a href="browseFloor.php?netID=<?php echo "$netID"?>&password=<?php echo "$pwd"?>">Browse Rooms</a></li>
<li><a href="userPrefs.php?netID=<?php echo "$netID"?>&password=<?php echo "$pwd"?>">User Preferences</a></li>
<li class="active"><a href="pick.php?netID=<?php echo "$netID"?>&password=<?php echo "$pwd"?>">Pick <span class="sr-only">(current)</span></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="index.html">Logout</a></li>
</ul>
</div>
</div>
</nav>
<!--Split Screen-->
<div class="container">
<div class="row equal">
<!-- Insert FloorPlan -->
<div class ="col-xs-6 col-sm-4">
<h1 class="text-center">Welcome to <?php echo $dorm; ?></h1><br>
<table class="table table-bordered">
<thead>
<tr>
<th>Pick Order</th>
<th>Resident</th>
<th>netID</th>
</tr>
</thead>
<tbody>
<!--Get random generated student order-->
<?php
//query for number of residents that are not staff
$numResQuery = "select count(*) as numResidents from Pick P, Resident R where R.netID = P.netID and R.isStaff is null;";
$numResResult = mysqli_query($link,$numResQuery);
//output data for numResidents
if(mysqli_num_rows($numResResult) > 0){
while($row = mysqli_fetch_assoc($numResResult)){
$numResidents = $row['numResidents'];
}
}
//Query for name by order of picked residents
$orderQuery = "select pickNum, name, R.netID, hasPicked from Pick P, Resident R where R.netID = P.netID and isStaff is null and R.dorm = '$dorm' order by pickNum;";
//ouput data by resident number
$i = 1;
$orderResult = mysqli_query($link,$orderQuery);
if(mysqli_num_rows($orderResult) > 0){
while($row = mysqli_fetch_assoc($orderResult)){
echo "<tr class='";
if($row['hasPicked']) echo "danger";
else echo "success";
echo "'><td>";
if($row['hasPicked']) echo "<span style=\"text-decoration:line-through;\">";
echo $row['pickNum'];
if($row['hasPicked']) echo "</span>";
echo "</td>";
echo "<td>";
if($row['hasPicked']) echo "<span style=\"text-decoration:line-through;\">";
echo $row['name'];
if($row['hasPicked']) echo "</span>";
echo "</td>";
echo "<td>";
if($row['hasPicked']) echo "<span style=\"text-decoration:line-through;\">";
echo $row['netID'];
if($row['hasPicked']) echo "</span>";
echo "</td></tr>";
}
}
?>
</tbody>
</table>
</div>
<!---Available, Favorites, Recommended Table -->
<div class="col-xs-6 col-sm-4">
<table class="table table-bordered">
<thead>
<tr>
<th>Available</th>
<th>Recomended</th>
<th>Favorites</th>
</tr>
</thead>
<tbody>
<!--Query for availble rooms-->
<?php
//new query for availble rooms
$queryAvail = "select roomNum from Room where dorm = '$dorm' and isOccupied = 0 and freshmanRoom = 0 and staffRoom = 0 and lounge = 0 and studyRoom = 0 and bathroom = 0 and numResidents > 0 order by roomNum;";
$resultAvail = mysqli_query($link,$queryAvail);
//new query for favorites
$netID = $_REQUEST['netID'];
$queryFav = "select distinct F.roomNum , R.isOccupied from Favorites F, Room R where F.dorm = '$dorm' and F.dorm=R.dorm and F.netID = $netID and R.roomNum=F.roomNum order by R.roomNum;";
$resultFav = mysqli_query($link, $queryFav);
//query for recomended
$recommended = "select R.roomNum from Recommended R, Room M where R.netID=$netID and R.dorm='$dorm' and R.dorm=M.dorm and R.roomNum=M.roomNum and M.isOccupied=0 order by R.score desc, R.sqareFootage desc;";
$resultRec = mysqli_query($link, $recommended);
$count = 0;
//output data
while(mysqli_num_rows($resultAvail) > $count || mysqli_num_rows($resultFav) > $count ){
echo "<tr>";
if($row = mysqli_fetch_assoc($resultAvail)){
echo "<td>".$row['roomNum']."</td>";
}else
{
echo "<td></td>";
}
if($row3 = mysqli_fetch_assoc($resultRec)){
echo "<td>".$row3['roomNum']."</td>";
} else {
echo "<td></td>";
}
if($row2 = mysqli_fetch_assoc($resultFav))
{
echo "<td class=\"";
echo ($row2['isOccupied'])? "danger": "success";
echo "\">";
if($row2['isOccupied']) echo "<span style=\"text-decoration:line-through;\">";
echo $row2['roomNum'];
if($row2['isOccupied']) echo "</span>";
echo "</td>";
}else
{
echo"<td></td>";
}
$count= $count +1;
echo"</tr>";
}
?>
<!--Crazy Query for Recomendation-->
<!--Favorites-->
</tbody>
</table>
</div>
<!--Pick chart-->
<div class="col-xs-6 col-sm-2">
<!--Enter Room, Roommates, and PICK!-->
<form action="updatePick.php" method="post">
<div class="form-group">
<input class="form-control" type="hidden" name="netID" value=<?php echo $_REQUEST['netID'] ?>>
<input class="form-control" type="hidden" name="password" value=<?php echo $_REQUEST['password'] ?>>
<label for="RoomNum">Room Number</label>
<input type="text" class="form-control" name="RoomNum">
<label> Roomate netIDs:</label>
<input type="text" class="form-control" name="mate1"><br>
<input type="text" class="form-control" name="mate2"><br>
<input type="text" class="form-control" name="mate3"><br>
<input type="text" class="form-control" name="mate4"><br>
<input type="text" class="form-control" name="mate5"><br>
<!--INSERT ROOMATE OPTION-->
</div>
<button type="submit" class="btn btn-default">PICK!</button>
</form>
</div>
</div>
</div>
</body>
<?php
mysqli_close($link);
?>