-
Notifications
You must be signed in to change notification settings - Fork 0
/
faculty.php
336 lines (267 loc) · 9.05 KB
/
faculty.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
326
327
328
329
330
331
332
333
334
335
336
<?php
// *************************************************************
// file: Faculty.php
// created by: Alex Gordon, Elliott Staude
// date: 04-6-2014
// purpose: A page used for displaying the data of and relevant to all faculty and staff members currently in Gordon College’s Active Directory.
//
// *************************************************************
// include nav bar and other default page items
include('header.php');
include('getPage.php');
include ('paginate.php');
include('open_db.php');
// check the session to see if the person is authenticated
if(!isset($_SESSION['user'])) {
header('Location: login.php');
}
// queries
// Set up ordering
// Find the requested content ordering
// When the sorting is the same kind as before, then "reverse" the ordering from previous
$sortMarker;
$orderingWatch;
if (isset($_GET['sorting']))
{
$sortMarker = $_GET['sorting'];
switch ($sortMarker)
{
case "FirstName":
$orderingWatch = "case when FirstName is null then 1 else 0 end, FirstName";
break;
case "FlipFirstName":
$orderingWatch = "FirstName DESC";
break;
case "LastName":
$orderingWatch = "case when LastName is null then 1 else 0 end, LastName";
break;
case "FlipLastName":
$orderingWatch = "LastName DESC";
break;
case "ID":
$orderingWatch = "case when ID is null then 1 else 0 end, ID";
break;
case "FlipID":
$orderingWatch = "ID DESC";
case "Facstaff":
$orderingWatch = "case when type is null then 1 else 0 end, type";
break;
case "FlipFacstaff":
$orderingWatch = "type DESC";
break;
case "Dept":
$orderingWatch = "case when OnCampusDepartment is null then 1 else 0 end, OnCampusDepartment";
break;
case "FlipDept":
$orderingWatch = "OnCampusDepartment DESC";
break;
case "Email":
$orderingWatch = "case when Email is null then 1 else 0 end, Email";
break;
case "FlipEmail":
$orderingWatch = "Email DESC";
break;
}
}
else
{
$sortMarker = "LastName";
$orderingWatch = "case when LastName is null then 1 else 0 end, LastName";
}
// sql query
if (isset($_POST['searchTerms'])) {
$strippedQuery = strip_tags($_POST['searchTerms']);
$query = "SELECT ID, FirstName, LastName, Email, OnCampusDepartment, type
FROM dbo.FacandStaff
where ID LIKE '" . $strippedQuery . "'
OR FirstName LIKE '" . $strippedQuery . "'
OR LastName LIKE '" . $strippedQuery . "'
OR Email LIKE '" . $strippedQuery . "'
OR OnCampusDepartment LIKE '" . $strippedQuery . "'
OR type LIKE '" . $strippedQuery . "'
ORDER BY " . $orderingWatch . ";";
?>
<div class="row">
<div class="large-10 large-centered columns">
<h1>Searching for <?php echo $strippedQuery; ?></h1>
<?php
} else {
$query = "SELECT ID, FirstName, LastName, Email, OnCampusDepartment, type
FROM dbo.FacandStaff
ORDER BY " . $orderingWatch . ";";
?>
<div class="row">
<div class="large-10 large-centered columns">
<h1>Facstaff</h1>
<?php
}
// $countQuery = "SELECT ID FROM dbo.FacandStaff";
$count = sqlsrv_query($conn, $query, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if ( !$count )
die( print_r( sqlsrv_errors(), true));
$num_rows = sqlsrv_num_rows( $count );
$result = sqlsrv_query($conn, $query, array(), array( "Scrollable" => 'static' ));
if ( !$result ) {
die( print_r( sqlsrv_errors(), true));
}
$thereIsData = sqlsrv_has_rows( $result );
// data for pagination
$num_rows = sqlsrv_num_rows( $count );
$rowsPerPage = 25;
$numOfPages = ceil($num_rows/$rowsPerPage);
if (isset($_GET['page'])) {
$page = $_GET['page'];
if ($page == 0) {
$pageNum = 1;
} else {
$pageNum = (($page / $rowsPerPage) + 1);
}
} else {
$pageNum = 1;
}
if (isset($_GET['page'])) {
$pCurrent = $_GET['page'];
} else {
$pCurrent = 0;
}
$aLeft = 'faculty.php?sorting=' . $sortMarker . '&page=';
$aRight = '';
$sMultiplier = 25;
$sArrows = TRUE;
// get page, this parses the page info
$page = getPage($result, $pageNum, $rowsPerPage);
if($_SESSION['access']=="3" OR $_SESSION['access']=="2" OR $_SESSION['access']=="1" ) {
?>
<ul class="breadcrumbs">
<li><a href="home.php">Home</a></li>
<li class="current"><a href="#">Facstaff</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="large-10 large-centered columns">
<?php
if ($thereIsData) {
?>
<table cellspacing="0">
<thead>
<tr>
<form method="post" action="">
<th width="75"><?php if ($sortMarker == "FirstName"){echo "<a href='faculty.php?sorting=FlipFirstName'>";} else {echo "<a href='faculty.php?sorting=FirstName'>";} ?>First Name</a></th>
<th width="75"><?php if ($sortMarker == "LastName"){echo "<a href='faculty.php?sorting=FlipLastName'>";} else {echo "<a href='faculty.php?sorting=LastName'>";} ?>Last Name</a></th>
<th width="50"><?php if ($sortMarker == "Facstaff"){echo "<a href='faculty.php?sorting=FlipFacstaff'>";} else {echo "<a href='faculty.php?sorting=Facstaff'>";} ?>Faculty/Staff</a></th>
<th width="200"><?php if ($sortMarker == "Dept"){echo "<a href='faculty.php?sorting=FlipDept'>";} else {echo "<a href='faculty.php?sorting=Dept'>";} ?>Department</a></th>
<th width="200"><?php if ($sortMarker == "Email"){echo "<a href='faculty.php?sorting=FlipEmail'>";} else {echo "<a href='faculty.php?sorting=Email'>";} ?>Email</a></th>
</form>
</tr>
</thead>
<a href=""></a>
<?php
foreach($page as $row)
{
echo "<tr><td><a href=\"/faculty_info.php?&id=" . $row[0] . "\">" . $row[1] . "</a></td><td><a href=\"/faculty_info.php?&id=" . $row[0] . "\">" . $row[2] . "</a></td><td>" . $row[5] . "</td><td>" . $row[4] . "</td><td>" . $row[3] . "</td></tr>";
}
//$row['index'] the index here is a field name
?>
</table>
</div>
</div>
<div class="row">
<div class="large-12 large-centered columns">
<?php
echo PHPagination($pCurrent, $num_rows, $aLeft, $aRight, $sMultiplier, $sArrows);
} else {
if (isset($_POST['searchTerms'])) {
$strippedQuery = strip_tags($_POST['searchTerms']);
$newQuery = "SELECT *
FROM computers
where control LIKE '" . $strippedQuery . "'
OR model LIKE '" . $strippedQuery . "'
OR manufacturer LIKE '" . $strippedQuery . "' ;";
$resultTwo = sqlsrv_query($conn, $newQuery);
$thereIsNewData = sqlsrv_has_rows( $resultTwo );
if ($thereIsNewData ) {
?>
</div>
</div>
<div class="row" align="center">
<div class="large-10 large-centered columns">
<h1>There's no search results here, but it looks like there is some in Equipment!</h1>
<form data-abide type="submit" id="searchTerms" enctype='multipart/form-data' action="/home.php" method="POST">
<?php
echo "<input type='hidden' name=\"searchTerms\" value='". $strippedQuery ."'>";
?>
<input id="searchTerms" type="submit" class="button" formmethod="POST" value="Go home"></input>
</form>
<?php
} elseif (!$thereIsNewData ) {
?>
</div>
</div>
<div class="row">
<div class="large-9 large-centered columns">
<h1>There's no search results.</h1>
<?php
} else {
?>
</div>
</div>
<div class="row">
<div class="large-9 large-centered columns">
<h1>There's no data.</h1>
<?php
}
} else {
?>
</div>
</div>
<div class="row">
<div class="large-9 large-centered columns">
<h1>There's nothing here.</h1>
<?php
}
}
sqlsrv_close( $conn );
?>
</div>
<!--
Hey... wanna see something cool?
&&&&&&&&&&&&&&&&&&&&&&&&&
& &
& * &
& * ** &
& * ** * &
& * *** ** &
& ** &
& *** ***** &
& * ***** ** &
& *** *** * &
& ()) ___ ** &
& fsshpop === * &
& /***\ * &
& /**~~*\ &
& (*~~****) &
& |~~*~~~~| &
& * |~~~~~*~|* &
& ** |~~~~~~~|* &
& (~~~~~~~) &
& |~~~~~| &
& |~~~~~| &
& ** (~~~~~~~) &
& |~~~~~~~| &
& **(._._._.) &
& * **** ** &
& ******* ***** *** &
& **** **** ** * * &
& ******** * * ** &
&&&&&&&&&&&&&&&&&&&&&&&&&
...oops.
-2014
For the love of all that is good and holy, kids, do not let Alex Gordon near your soda.
You will not have soda for long otherwise.
-->
</div>
<?php
}
include('footer.php')
?>