-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
executable file
·277 lines (251 loc) · 8.12 KB
/
search.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
<?php
// *************************************************************
// file:
// created by: Alex Gordon, Elliott Staude
// date: 04-6-2014
// purpose: A general-use search page for finding data in a given section of the GQUIP database by table.
//
// *************************************************************
// include nav bar and other default page items
include('header.php');
// check the session to see if the person is authenticated
if(!isset($_SESSION['user'])) {
header('Location: login.php');
}
// Manager or User
if($_SESSION['access']==ADMIN_PERMISSION || $_SESSION['access']==USER_PERMISSION) {
include('open_db.php');
?>
<div class="large-10 large-centered columns">
<h1>Search GQUIP</h1>
<?php
$realTerms;
echo "<p>Searching terms:";
if (!isset($_POST['searchTerms']) OR $_POST['searchTerms'] == "")
{
echo "<br />No search terms set";
}
else
{
echo "<ul>";
$realTerms = str_replace(",", " ", $_POST['searchTerms']);
$realTerms = str_replace(" ", " ", $realTerms);
$realTerms = explode(" ", $realTerms);
foreach ( $realTerms as $thisTerm )
{
$thisTerm = trim($thisTerm);
echo "<li>", $thisTerm, "</li>";
}
echo '</ul>';
echo '</p>';
$query;
$result;
//Check if the tables to search are set
echo "<p>Searching tables:";
if (!isset($_POST['searchTables']))
{
echo "<br />No search tables set</p>";
}
else
{
echo "<ul>";
foreach ( $_POST['searchTables'] as $table )
{
echo "<li>", $tableReadableArray[$table], "</li>";
$query[$table] = "SELECT *
FROM " . $table . " WHERE ";
$numberCols = count($columnArray[$table]);
$numberTerms = count($realTerms);
//Ask all of the columns if they have a row containing this value
if ($numberCols > 1)
{
for($colIndex = 0; $colIndex < ($numberCols - 1); $colIndex++)
{
for($realIndex = 0; $realIndex < ($numberTerms); $realIndex++)
{
$query[$table] .= $columnArray[$table][$colIndex] . " LIKE '%" . $realTerms[$realIndex] . "%' OR ";
}
}
}
if ($numberTerms > 1)
{
for($realIndex = 0; $realIndex < ($numberTerms - 1); $realIndex++)
{
$query[$table] .= $columnArray[$table][$numberCols-1] . " LIKE '%" . $realTerms[$realIndex] . "%' OR ";
}
}
$query[$table] .= $columnArray[$table][$numberCols-1] . " LIKE '%" . $realTerms[$numberTerms-1] . "%';";
}
echo '</ul>';
echo '</p>';
include 'open_db.php';
//Go through each table's query, get the relevant data, display it
echo "Results:\n\n";
foreach ( $_POST['searchTables'] as $table )
{
$searchResultsArray['tables'][] = $table;
$result[$table] = sqlsrv_query($conn, $query[$table]);
sqlsrvErrorLinguist($result[$table], "Problem with searching for results on table " . $table);
$IDName;
$pageName;
$requiresQuery = 0;
switch ($table)
{
case "computers":
$IDName = "control";
$pageName = "info.php?id=";
$linkText = "Computer information";
break;
case "hardware_assignments": //***
$IDName = "computer";
$pageName = "info.php?id=";
$requiresQuery = 1;
$linkText = "Computer information";
break;
case "changes": //***
$IDName = "computer_id";
$pageName = "info.php?id=";
$requiresQuery = 1;
$linkText = "Computer information";
break;
case "FacandStaff":
$IDName = "ID";
$pageName = "faculty_info.php?&id=";
$linkText = "Faculty/Staff member information";
break;
case "gordonstudents":
$IDName = "id";
$pageName = "student_info.php?&id=";
$linkText = "Student information";
break;
case "software":
$IDName = "index_id";
$pageName = "edit_software.php?edit=";
$linkText = "Software edit page";
break;
case "licenses":
$IDName = "id";
$pageName = "student_info.php?&id=";
$linkText = "Student with license";
break;
case "comments": //***
$IDName = "computer_id";
$pageName = "info.php?id=";
$requiresQuery = 1;
$linkText = "Computer information";
break;
}
//Ensure there are some results before starting to show tables
if (count($result[$table]) > 0)
{
//Output this table's data
echo "<h3>" . $tableReadableArray[$table] . "</h3>";
echo "<div class=\"large-12 large-centered columns\">\n";
echo "<div class=\"row\">\n";
echo "<table><thead><tr>\n";
echo "<th>Link to page</th>";
foreach ($columnReadableArray[$table] as $col)
{
$searchResultsArray[$table]['header'][] = $col;
echo "<th>" . $col . "</th>";
}
echo "</thead></tr>\n";
while($row[$table] = sqlsrv_fetch_array($result[$table], SQLSRV_FETCH_ASSOC))
{
echo "<tr>";
$linkValue = $pageName;
if ($requiresQuery)
{
$linkedComputer = "SELECT control FROM computers WHERE computer_id = " . $row[$table][$IDName] . ";";
$linkedResult = sqlsrv_query($conn, $linkedComputer);
sqlsrvErrorLinguist($linkedResult, "There was an unusual value detected in the rows returned");
$rowItem = sqlsrv_fetch_array($linkedResult);
$linkValue .= $rowItem['control'];
}
else
{
$linkValue .= $row[$table][$IDName];
}
echo "<td><a class='button tiny' href='" . $linkValue . "'>" . $linkText . "</a></td>";
foreach ( $columnArray[$table] as $tableRowValue )
{
$searchResultsArray[$table]['body'][$tableRowValue][] = $row[$table][$tableRowValue];
if (!($row[$table][$tableRowValue] instanceof DateTime))
{
if () {
echo "<td>" . $row[$table][$tableRowValue] . "</td>";
} else {
echo "<td>" . $row[$table][$tableRowValue] . "</td>";
}
}
else
{
echo "<td>" . $row[$table][$tableRowValue]->format('Y-m-d H:i:s') . "</td>";
}
}
echo "</tr>";
}
echo "</table>";
echo "</div>";
echo "</div>";
echo "<hr />\n\n";
}
}
}
}
?>
<form data-abide type="submit" name="submit" enctype='multipart/form-data' action="search.php" method="POST">
<fieldset>
<legend>Areas searched</legend>
<div class="large-12 columns">
<div class="row">
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='FacandStaff'><span class="label radius">Faculty</span>
</div>
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='computers'><span class="label radius">Computers</span>
</div>
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='changes'><span class="label radius">Computer change records</span>
</div>
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='hardware_assignments'><span class="label radius">Hardware assignments</span>
</div>
</div>
<div class="row">
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='gordonstudents'><span class="label radius">Students</span>
</div>
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='software'><span class="label radius">Software records</span>
</div>
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='licenses'><span class="label radius">Licenses to students</span>
</div>
<div class="large-3 columns">
<input type='checkbox' name='searchTables[]' value='comments'><span class="label radius">Comments</span>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Terms</legend>
<input type="text" name="searchTerms">
</fieldset>
<input type="submit" name="submit" value="Search" class="button" formmethod="post">
<input type="submit" name="pdfsubmit" value="PDF of Results" class="button" formmethod="post">
</form>
<?php
?>
</div>
<?php
}
// Faculty
if($_SESSION['access']==FACULTY_PERMISSION) {
// Faculty should not have access to this page.
header('Location: home.php');
}
sqlsrv_close($conn);
//footer
include('footer.php');
?>