-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_info.php
executable file
·269 lines (228 loc) · 7.74 KB
/
student_info.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
<?php
// *************************************************************
// file: student_info.php
// created by: Alex Gordon, Elliott Staude
// date: 04-6-2014
// purpose: This page shows info about an individual student and allows easy access to the software assigned to them and contact information.
//
// *************************************************************
// 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 OR $_SESSION['access']==USER_PERMISSION) {
?>
<div class="row">
<div class="large-10 large-centered columns">
<h1>Student Information</h1>
<ul class="breadcrumbs">
<li><a href="home.php">Home</a></li>
<li><a href="students.php">Students</a></li>
<li class="current"><a href="#">Student Info</a></li>
</ul>
<?php
$itemID = $_GET['id'];
$licenseKinds[] = NULL;
if (isset($_POST['submit'])){
//connect to the database
include 'open_db.php';
//display error if database cannot be accessed
if (!$conn )
{
echo('<div data-alert class="alert-box warning">
Sorry! Database is unavailable.
<a href="#" class="close">×</a>
</div>');
echo( print_r( sqlsrv_errors(), true));
}
//assign form input to variables
include 'dateTime.php';
$last_updated_by = $_SESSION['user'];
$last_updated_at = $dateTime;
$created_at = $dateTime;
$date_sold = $dateTime;
$seller = $_POST['seller'];
$software_id = $_POST['licenseChoice'];
$softwareTypeResult = "0";
$possessedSoftwareTypeQuery = "SELECT DISTINCT software_type
FROM software
RIGHT JOIN licenses
ON software.index_id = licenses.software_id
WHERE licenses.id = $itemID;";
$findSubmittedSoftwareQuery = "SELECT DISTINCT software_type
FROM software
WHERE software.index_id = $software_id;";
$findSubmittedSoftwareResult = sqlsrv_query($conn, $findSubmittedSoftwareQuery);
$softwareStats = sqlsrv_fetch_array($findSubmittedSoftwareResult, SQLSRV_FETCH_ASSOC);
$softwareTypeResult = sqlsrv_query($conn, $possessedSoftwareTypeQuery);
while($thisHereItem = sqlsrv_fetch_array($softwareTypeResult, SQLSRV_FETCH_ASSOC))
{
$licenseKinds[] = $thisHereItem['software_type'];
}
if (array_search($softwareStats['software_type'], $licenseKinds) === false)
{
//SQL query to insert variables above into table
$sql = "INSERT INTO dbo.licenses ([last_updated_by],[last_updated_at],[created_at],[date_sold],[seller],[software_id],[id])VALUES('$last_updated_by','$last_updated_at','$created_at','$date_sold','$seller','$software_id','$itemID')";
$result = sqlsrv_query($conn, $sql);
//if the query cant be executed
if(!$result)
{
echo print_r( sqlsrv_errors(), true);
exit;
}
echo "<div class=\"row\">";
echo "<div class=\"large-10 large-centered columns\">";
echo "<h3 class=\"large-centered\">Data successfully added</h3>";
echo "<a class=\"button expand\" href=\"student_info.php?&id=" . $itemID . " \">OK</a>";
echo "</div>";
echo "</div>";
}
else
{
echo "<div class=\"large-8 large-centered columns\">";
echo "<h3 class=\"large-centered\">Sorry - that type of license is already possessed by the student</h3>";
echo "<a class=\"button\" href=\"students.php\">OK</a>";
echo "</div>";
}
// close the connection
sqlsrv_close( $conn);
}
else {
include 'open_db.php';
// Queries for a student's info, their purchased licenses, and relevant software information
$studentQuery = "SELECT *
FROM gordonstudents
WHERE gordonstudents.id = $itemID;";
$licenseQuery = "SELECT licenses.index_id as license_id,
licenses.last_updated_by as license_updater,
licenses.last_updated_at as license_updated,
licenses.created_at as license_created,
licenses.date_sold as date_sold,
licenses.id as id,
licenses.seller as seller,
licenses.software_id as software_id,
software.index_id as index_id,
software.last_updated_by as software_updater,
software.last_updated_at as software_updated,
software.created_at as software_created,
software.name as name,
software.software_type as software_type
FROM licenses
LEFT JOIN software
ON licenses.software_id = software.index_id
WHERE licenses.id = $itemID;";
$populationQuery = "SELECT *
FROM software;";
$studentResult = sqlsrv_query($conn, $studentQuery);
$licenseResult = sqlsrv_query($conn, $licenseQuery);
$populationResult = sqlsrv_query($conn, $populationQuery);
if(!$studentResult)
{
echo print_r( sqlsrv_errors(), true);
exit;
}
$item = sqlsrv_fetch_array($studentResult, SQLSRV_FETCH_ASSOC);
?>
<form data-abide type="submit" name="submit" enctype='multipart/form-data' <?php echo "action=\"student_info.php?id=" . $itemID . "\""; ?> method="POST">
<fieldset>
<legend>Personal Data</legend>
<div class="row">
<div class="large-2 columns">
<label><strong>First Name</strong></label>
<label name="FirstName"><?php echo $item['FirstName']; ?></label>
</div>
<div class="large-2 columns">
<label><strong>Middle name</strong></label>
<label name="MiddleName"><?php echo $item['MiddleName']; ?></label>
</div>
<div class="large-2 columns">
<label><strong>Last name</strong></label>
<label name="LastName"><?php echo $item['LastName']; ?></label>
</div>
<div class="large-1 columns">
<label><strong>Class</strong></label>
<label name="Class"><?php echo $item['Class']; ?></label>
</div>
<div class="large-2 columns">
<label><strong>Grad Student</strong></label>
<label name="grad_student"><?php echo $item['grad_student']; ?></label>
</div>
<div class="large-3 columns">
<label><strong>Email</strong></label>
<label name="Email"><?php echo $item['Email']; ?></label>
</div>
</div>
</fieldset>
<fieldset>
<legend>Software Licenses</legend>
<?php
while($licenseItem = sqlsrv_fetch_array($licenseResult, SQLSRV_FETCH_ASSOC))
{
?>
<div class="row">
<div class="large-3 columns">
<label><strong>Software Name</strong></label>
<label name="software_name"><?php echo $licenseItem['name']; ?></label>
</div>
<div class="large-3 columns">
<label><strong>Software Type</strong></label>
<label name="software_type"><?php echo $licenseItem['software_type']; ?></label>
</div>
<div class="large-2 columns">
<label><strong>Seller</strong></label>
<label name="edited_seller"><?php echo $licenseItem['seller']; ?></label>
</div>
<div class="large-2 columns">
<label><strong>Time Sold</strong></label>
<label name="date_sold"><?php echo $licenseItem['date_sold']->format('Y-m-d H:i:s'); ?></label>
</div>
<?php
echo "<a href=\"edit_license.php?edit=" . $licenseItem['license_id'] . "\" class=\"button\">Edit</a>";
?>
</div>
<?php
}
?>
</fieldset>
<fieldset>
<legend>Add a license</legend>
<div class="row">
<div class="large-4 columns">
<label>Software licensed</label>
<select name="licenseChoice" id="licenseChoice">
<?php
while($row = sqlsrv_fetch_array($populationResult))
{
echo "<option value=\"" . $row["index_id"] . "\">" . $row['name'] . "</option>\n";
// Use an array to get all legal values for the software search
$securityArray[] = $row["index_id"];
}
?>
</select>
</div>
<div class="large-4 columns">
<label>Seller to student</label>
<input type="text" name="seller" placeholder="John Smith" required>
</div>
<div class="large-4 columns">
<input type="submit" name="submit" value="Add Item" class="button expand" formmethod="post">
</div>
</div>
</fieldset>
</form>
</div>
</div>
<?php
}
}
// Faculty
if($_SESSION['access']==FACULTY_PERMISSION) {
// Faculty should not have access to this page.
header('Location: home.php');
}
//footer
include('footer.php')
?>