-
Notifications
You must be signed in to change notification settings - Fork 0
/
faculty_info.php
244 lines (215 loc) · 6.95 KB
/
faculty_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
<?php
// *************************************************************
// file: faculty_info.php
// created by: Alex Gordon, Elliott Staude
// date: 04-6-2014
// purpose: This page shows info about an individual faculty member and allows easy access to the computers 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']==USER_PERMISSION || $_SESSION['access']==ADMIN_PERMISSION || $_SESSION['access']==FACULTY_PERMISSION) {
?>
<div class="row">
<div class="large-10 large-centered columns">
<h1>Faculty Information</h1>
<ul class="breadcrumbs">
<li><a href="home.php">Home</a></li>
<li><a href="faculty.php">Faculty</a></li>
<li class="current"><a href="#">Faculty Info</a></li>
</ul>
<?php
$itemID = $_GET['id'];
// submit form
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;
$start_assignment = $dateTime;
$OnCampusDepartment = $_POST['OnCampusDepartment'];
$computer = $_POST['computerChoice'];
$full_time = 0;
$primary_computer = 0;
$replace_with_recycled = 0;
if ($_POST['full_time'] = "yes")
{
$full_time = 1;
}
if ($_POST['primary_computer'] = "yes")
{
$primary_computer = 1;
}
if ($_POST['replace_with_recycled'] = "yes")
{
$replace_with_recycled = 1;
}
$assignment_type = $_POST['assignment_type'];
//SQL query to insert variables above into table
$hardware_assignmentSQL = "INSERT INTO dbo.hardware_assignments ([computer],[last_updated_by],[last_updated_at],[created_at],[user_id],[department],[replace_with_recycled],[full_time],[primary_computer],[assignment_type])VALUES($computer,'$last_updated_by','$last_updated_at',$itemID,'$OnCampusDepartment',$replace_with_recycled,$full_time,$primary_computer,'$assignment_type')";
$result = sqlsrv_query($conn, $sql);
//if the query cant be executed
if(!$result)
{
echo print_r( sqlsrv_errors(), true);
exit;
}
echo "<div class=\"large-8 large-centered columns\">";
echo "<h3 class=\"large-centered\">Data successfully added</h3>";
echo "<a class=\"button\" href=\"faculty.php\">OK</a>";
echo "</div>";
// close the connection
sqlsrv_close( $conn);
}
else {
include 'open_db.php';
// Queries for a faculty member's info, their hardware assignments, and relevant computers information
$facultyQuery = "SELECT *
FROM FacandStaff
WHERE FacandStaff.ID = $itemID;";
$hardware_assignmentQuery = "SELECT hardware_assignments.id as hardware_assignment_id,
hardware_assignments.last_updated_by as hardware_assignment_updater,
hardware_assignments.last_updated_at as hardware_assignment_updated,
hardware_assignments.created_at as hardware_assignment_created,
hardware_assignments.start_assignment as start_assignment,
hardware_assignments.end_assignment as end_assignment,
hardware_assignments.id as hardware_assignment_computer_id,
hardware_assignments.assignment_type as assignment_type,
computers.computer_id as computer_id,
computers.control as control,
computers.last_updated_by as computers_updater,
computers.last_updated_at as computers_updated,
computers.created_at as computers_created,
computers.model as model,
computers.hard_drive as hard_drive,
computers.computer_type as computer_type
FROM hardware_assignments
LEFT JOIN computers
ON hardware_assignments.computer = computers.computer_id
WHERE hardware_assignments.user_id = $itemID;";
$populationQuery = "SELECT computer_id, control, model
FROM computers
ORDER BY control;";
$facultyResult = sqlsrv_query($conn, $facultyQuery);
$hardware_assignmentResult = sqlsrv_query($conn, $hardware_assignmentQuery);
$populationResult = sqlsrv_query($conn, $populationQuery);
if(!$facultyResult)
{
echo print_r( sqlsrv_errors(), true);
exit;
}
$item = sqlsrv_fetch_array($facultyResult, SQLSRV_FETCH_ASSOC);
?>
<form data-abide type="submit" name="submit" enctype='multipart/form-data' <?php echo "action=\"faculty_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>Last name<strong/></label>
<label name="LastName"><?php echo $item['LastName']; ?></label>
</div>
<div class="large-3 columns">
<label><strong>Department<strong/></label>
<label name="OnCampusDepartment"><?php echo $item['OnCampusDepartment']; ?></label>
</div>
<div class="large-1 columns">
<label><strong>DPT.<strong/></label>
<label name="Dept"><?php echo $item['Dept']; ?></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>Computers assigned</legend>
<table>
<thead>
<th>Control number</th>
<th>Model</th>
<th>Type of unit</th>
<th>Assignment type</th>
<th>Assignment start time</th>
<th>Assignment end time</th>
</thead>
<?php
//get the info on each of the individual's computers here
while($row = sqlsrv_fetch_array($hardware_assignmentResult))
{
$comptype = "Laptop";
if ($row['computer_type'] == "2")
{
$comptype = "Desktop";
}
if ($row['computer_type'] == "3")
{
$comptype = "Tablet";
}
$asgntype = "Dedicated unit";
if ($row['assignment_type'] == "2")
{
$comptype = "Special";
}
if ($row['assignment_type'] == "3")
{
$comptype = "Lab";
}
if ($row['assignment_type'] == "4")
{
$comptype = "Kiosk";
}
if ($row['assignment_type'] == "5")
{
$comptype = "Printer";
}
$endasgn = "N/A";
if ($row['end_assignment'] != NULL)
{
$endasgn = $row['end_assignment']->format('Y-m-d H:i:s');
}
$startasgn = "N/A";
if ($row['end_assignment'] != NULL)
{
$startasgn = $row['start_assignment']->format('Y-m-d H:i:s');
}
echo "<tr><td>" . "<a href=\"/info.php?id=" . $row['control'] . "\">" . $row['control'] . "</a>" . "</td><td>" . $row['model'] . "</td><td>" . $comptype . "</td><td>" . $asgntype . "</td><td>" . $startasgn . "</td><td>" . $endasgn . "</td></tr>";
}
?>
</table>
</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')
?>