-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudents.php
executable file
·175 lines (154 loc) · 5.35 KB
/
students.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
<?php
// *************************************************************
// file: students.php
// created by: Alex Gordon, Elliott Staude
// date: 04-6-2014
// purpose: A page used for displaying the data of and relevant to all students 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');
}
// query 1, for total number of items from DB
$countQuery = "SELECT ID FROM dbo.gordonstudents";
$count = sqlsrv_query($conn, $countQuery, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if ( !$count )
die( print_r( sqlsrv_errors(), true));
$num_rows = sqlsrv_num_rows( $count );
// 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";
break;
case "Class":
$orderingWatch = "case when Class is null then 1 else 0 end, Class";
break;
case "FlipClass":
$orderingWatch = "Class 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";
}
// query 2, for all items we need
$query = "SELECT ID, FirstName, LastName, Email, Class
FROM dbo.gordonstudents
ORDER BY " . $orderingWatch . ";";
$result = sqlsrv_query($conn, $query, array(), array( "Scrollable" => 'static' ));
if ( !$result )
die( print_r( sqlsrv_errors(), true));
//
// data for pagination
// This is the syntax we pass to the paginator.php to give us our numbers
// the left page link
$aLeft = 'students.php?sorting=' . $sortMarker . '&page=';
// the right page link. If blank, then left will be used.
$aRight = '';
// do we want to show the fancy arrows?
$sArrows = TRUE;
// the number of items in the database
$num_rows = sqlsrv_num_rows( $count );
// rows of items per page
$rowsPerPage = 25;
// number of pages equals number of items divided by how many we show per page
$numOfPages = ceil($num_rows/$rowsPerPage);
// some quick math to find out what page we're on
if (isset($_GET['page'])) {
$page = $_GET['page'];
if ($page == 0) {
$pageNum = 1;
} else {
$pageNum = (($page / $rowsPerPage) + 1);
}
} else {
$pageNum = 1;
}
// This finds out our current starting place (or item)
if (isset($_GET['page'])) {
$pCurrent = $_GET['page'];
} else {
$pCurrent = 0;
}
// gets the correct SQL Data. This makes a call to the getPage.php function
$page = getPage($result, $pageNum, $rowsPerPage);
// If faculty or user
if($_SESSION['access']=="3" OR $_SESSION['access']=="1" ) {
?>
<div class="row">
<div class="large-10 large-centered columns">
<h1>Students</h1>
<ul class="breadcrumbs">
<li><a href="home.php">Home</a></li>
<li class="current"><a href="#">Students</a></li>
</ul>
<table cellspacing="0">
<thead>
<tr>
<th width="150"><?php if ($sortMarker == "FirstName"){echo "<a href='students.php?sorting=FlipFirstName'>";} else {echo "<a href='students.php?sorting=FirstName'>";} ?>First Name</a></th>
<th width="150"><?php if ($sortMarker == "LastName"){echo "<a href='students.php?sorting=FlipLastName'>";} else {echo "<a href='students.php?sorting=LastName'>";} ?>Last Name</a></th>
<th width="100"><?php if ($sortMarker == "Class"){echo "<a href='students.php?sorting=FlipClass'>";} else {echo "<a href='students.php?sorting=Class'>";} ?>Class</a></th>
<th width="300"><?php if ($sortMarker == "Email"){echo "<a href='students.php?sorting=FlipEmail'>";} else {echo "<a href='students.php?sorting=Email'>";} ?>Email</a></th>
</tr>
</thead>
<a href=""></a>
<?php
foreach($page as $row)
{
echo "<tr><td><a href=\"/student_info.php?&id=" . $row[0] . "\">" . $row[1] . "</a></td><td><a href=\"/student_info.php?&id=" . $row[0] . "\">" . $row[2] . "</a></td><td>" . $row[4] . "</td><td>" . $row[3] . "</td></tr>";
}
?>
</table>
</div>
</div>
<div class="row">
<div class="large-12 large-centered columns">
<?php
// Spit out the pagination info. This makes a call to the paginate.php function.
echo PHPagination($pCurrent, $num_rows, $aLeft, $aRight, $rowsPerPage, $sArrows);
// close the database connection
sqlsrv_close( $conn );
}
?>
</div>
</div>
<?php
include('footer.php')
?>