-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_item.php
349 lines (325 loc) · 13.2 KB
/
new_item.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
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
// *************************************************************
// file: new_item.php
// created by: Alex Gordon, Elliott Staude
// date: 04-6-2014
// purpose: The page used to add equipment item content to GQUIP’s database.
//
// *************************************************************
// 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 ) {
if (isset($_POST['submit'])){
//connect to the database
$serverName = "sql05train1.gordon.edu";
$connectionInfo = array(
'Database' => 'CTSEquipment');
$conn = sqlsrv_connect($serverName, $connectionInfo);
//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
// post data
$controlNumber = $_POST['controlNumber'];
$manufacturer = $_POST['manufacturer'];
$model = $_POST['model'];
$serialNumber = $_POST['serialNumber'];
$usageStatus = "circulation";
$ram = $_POST['ram'];
$hdSize = $_POST['hdSize'];
$partNumber = $_POST['partNumber'];
$equipmentType;
if (isset($_POST['equipmentType'])) {
$equipmentType = $_POST['equipmentType'];
} else {
$equipmentType = 0;
}
$warrantyLength = $_POST['warrantyLength'];
$accountNumber = $_POST['accountNumber'];
$purchaseDate = $_POST['purchaseDate'];
$warrantyStart = $purchaseDate;
$purchasePrice = $_POST['purchasePrice'];
$replacementYear = $_POST['replacementYear'];
$department = $_POST['department'];
$assignmentType = $_POST['assignmentType'];
// if primary computer is set
if (isset($_POST['primaryComputer'])) {
$primary_computer = $_POST['primaryComputer'];
} else {
$primary_computer = 0;
}
// if fulltime is set
if (isset($_POST['fullTime'])) {
$full_time = $_POST['fullTime'];
} else {
$full_time = 0;
}
$notes = $_POST['notes'];
// Get the faculty/staff member getting assigned
$selectFacultyStaffID = $_POST['userName'];
if (isset($_SESSION['user'])) {
$lastUpdatedBy = $_SESSION['user'];
}
$timezone = new DateTimeZone("UTC");
$lastUpdatedAt = new DateTime("now", $timezone);
$lastUpdatedAtString = $lastUpdatedAt->format('Y-m-d H:i:s');
$createdAt = new DateTime("now", $timezone);
$createdAtString = $createdAt->format('Y-m-d H:i:s');
$startAssignment = new DateTime("now", $timezone);
$startAssignmentString = $startAssignment->format('Y-m-d H:i:s');
//SQL query to insert variables above into table
$insertComputer = " INSERT INTO dbo.computers ([last_updated_by], [last_updated_at], [created_at], [control], [serial_num], [model], [manufacturer], [purchase_date], [purchase_price], [purchase_acct], [usage_status], [memory], [hard_drive], [warranty_length], [warranty_start], [replacement_year], [computer_type], [part_number])VALUES( '$lastUpdatedBy', '$lastUpdatedAtString', '$createdAtString', '$controlNumber', '$serialNumber', '$model', '$manufacturer', '$purchaseDate', '$purchasePrice', '$accountNumber', '$usageStatus', '$ram', '$hdSize', '$warrantyLength', '$purchaseDate', '$replacementYear', '$equipmentType', '$partNumber')";
$computer = sqlsrv_query($conn, $insertComputer);
if(!$computer)
{
echo print_r( sqlsrv_errors(), true);
exit;
}
$selectNewInsert = "Select computer_id from dbo.computers where control = " . $controlNumber . " ";
$computer_id_result = sqlsrv_query($conn, $selectNewInsert);
while( $row = sqlsrv_fetch_array( $computer_id_result, SQLSRV_FETCH_ASSOC) ) {
$computer_id = $row['computer_id'];
}
if ($department != "unassigned" || $selectFacultyStaffID != "unassigned")
{
$insertAssignment;
if ($selectFacultyStaffID == "unassigned")
{
$insertAssignment = " INSERT INTO dbo.hardware_assignments ( [computer], [last_updated_by], [last_updated_at], [created_at], [department_id], [full_time], [primary_computer], [start_assignment], [assignment_type], [nextneed_note])VALUES('$computer_id', '$lastUpdatedBy', '$lastUpdatedAtString', '$createdAtString', '$department', '$full_time', '$primary_computer', '$startAssignmentString', '$assignmentType', '$notes')";
}
else
{
$insertAssignment = " INSERT INTO dbo.hardware_assignments ( [computer], [last_updated_by], [last_updated_at], [created_at], [user_id], [department_id], [full_time], [primary_computer], [start_assignment], [assignment_type], [nextneed_note])VALUES('$computer_id', '$lastUpdatedBy', '$lastUpdatedAtString', '$createdAtString', $selectFacultyStaffID, '$department', '$full_time', '$primary_computer', '$startAssignmentString', '$assignmentType', '$notes')";
}
$assignment = sqlsrv_query($conn, $insertAssignment);
sqlsrvErrorLinguist($assignment, "SQL problem with adding this assignment");
$changeContent = "";
$changeContent .= "*** ASSIGNMENT ADDED *** \n";
$changeContent .= "*** ASSIGNMENT ADDED *** \n";
$changeContent .= "*** ASSIGNMENT ADDED *** \n";
$changeContent .= "*** ASSIGNMENT ADDED *** \n";
$changeContent .= "*** ASSIGNMENT ADDED *** \n";
$changeQuery = "INSERT INTO
changes
([body],[last_updated_by],[creator],[last_updated_at],[created_at],[computer_id])VALUES('$changeContent','$lastUpdatedBy','$lastUpdatedBy','$createdAtString','$createdAtString','$computer_id');";
$changeResult = sqlsrv_query($conn, $changeQuery);
sqlsrvErrorLinguist($changeResult, "SQL problem output 108");
}
sqlsrv_close( $conn);
?>
<div class="row">
<div class="large-10 large-centered columnslarge-centered columns">
<h1>Successfully Created Item.</h1>
<a class="button" href=" <?php echo "info.php?id=". $controlNumber ."" ?> ">Click here to view the item</a>
</div>
</div>
<?php
} else {
?>
<div class="row">
<div class="large-12 large-centered columns">
<h1>New Equipment Item</h1>
<ul class="breadcrumbs">
<li><a href="home.php">Home</a></li>
<li class="current"><a href="#">Create New Item</a></li>
</ul>
<form data-abide type="submit" name="submit" enctype='multipart/form-data' action="new_item.php" method="POST">
<fieldset>
<legend>Equipment Info</legend>
<div class="row">
<div class="large-4 columns">
<label>Control Number</label>
<input type="text" name="controlNumber" placeholder="01234" maxlength="10" required>
<small class="error">A valid Control Number is required.</small>
</div>
<div class="large-4 columns">
<label>Manufacturer</label>
<input type="text" name="manufacturer" placeholder="Lenovo" maxlength="20" required>
</div>
<div class="large-4 columns">
<label>Model</label>
<input type="text" name="model" placeholder="T440" maxlength="10" required>
</div>
</div>
<div class="row">
<div class="large-4 columns">
<label>Serial Number</label>
<input type="text" name="serialNumber" placeholder="S012345ABC" maxlength="20" required>
</div>
<div class="large-4 columns">
<div class="row collapse">
<label>Memory Amount </label>
<div class="small-9 columns">
<input type="number" name="ram" placeholder="6" max='2000000000' required>
</div>
<div class="small-3 columns">
<span class="postfix">GB's</span >
</div>
</div>
</div>
<div class="large-4 columns">
<div class="row collapse">
<label>Hard Drive Size</label>
<div class="small-9 columns">
<input type="number" name="hdSize" placeholder="500" max='2000000000' required>
</div>
<div class="small-3 columns">
<span class="postfix">GB's</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="large-4 columns">
<label>Part Number</label>
<input type="text" placeholder="4325-335" name="partNumber" maxlength="20" required>
</div>
<div class="large-4 columns">
<label>Equipment Type</label>
<select class="medium" name="equipmentType" required data-invalid>
<option <?php echo "value=" . LAPTOP_EQUIPMENT_TYPE . ">"; ?>Laptop</option>
<option <?php echo "value=" . DESKTOP_EQUIPMENT_TYPE . ">"; ?>Desktop</option>
<option <?php echo "value=" . TABLET_EQUIPMENT_TYPE . ">"; ?>Tablet</option>
</select>
</div>
<div class="large-4 columns">
<label>Warranty Length</label>
<select class="medium" name="warrantyLength" required data-invalid>
<option <?php echo "value=" . ONE_YEAR_WARRANTY_LENGTH . ">"; ?>1 Year</option>
<option <?php echo "value=" . TWO_YEAR_WARRANTY_LENGTH . ">"; ?>2 Years</option>
<option <?php echo "value=" . THREE_YEAR_WARRANTY_LENGTH . ">"; ?>3 Years</option>
<option <?php echo "value=" . FOUR_YEAR_WARRANTY_LENGTH . ">"; ?>4 Years</option>
<option <?php echo "value=" . EXPIRED_WARRANTY_LENGTH . ">"; ?>Expired</option>
</select>
</div>
</div>
</fieldset>
<fieldset>
<legend>Purchasing Info</legend>
<div class="row">
<div class="large-3 columns">
<label>Purchasing Account Number</label>
<input type="text" name="accountNumber" placeholder="000000-123456" maxlength="20" required>
</div>
<div class="large-3 columns">
<label>Purchasing Date</label>
<input type="date" name="purchaseDate" placeholder="date" required>
</div>
<div class="large-3 columns">
<div class="row collapse">
<label>Purchasing Price</label>
<div class="small-3 columns">
<span class="prefix">$</span>
</div>
<div class="small-9 columns">
<input type="number" name="purchasePrice" placeholder="1480" max='2000000000' required>
</div>
</div>
</div>
<div class="large-3 columns">
<label>Replacement Year</label>
<input type="text" name="replacementYear" maxlength="10" required>
</div>
</div>
</fieldset>
<fieldset>
<legend>Computer Assignment Info</legend>
<div class="row">
<?php
include('open_db.php');
$populationQuery = "SELECT DISTINCT OnCampusDepartment
FROM FacStaff
WHERE OnCampusDepartment IS NOT NULL;";
$facultyQuery = "SELECT FirstName, LastName, ID
FROM FacStaff ORDER by LastName ASC;";
//The sqlsrv_query function allows PHP to make a query against the database
//and returns the resulting data
$facultyResult = sqlsrv_query($conn, $facultyQuery);
$populationResult = sqlsrv_query($conn, $populationQuery);
//This array gets all the possible departments that a search could target if
//it were valid
$securityArray[0] = "unassigned";
?>
<div class="large-4 columns">
<label>User Name</label>
<select class="medium" name="userName" required data-invalid>
<option value="unassigned">Unassigned</option>
<?php
while($row = sqlsrv_fetch_array($facultyResult))
{
echo "<option value=\" " . $row["ID"] . " \">" . $row["LastName"] . ", " . $row["FirstName"] . "</option>\n";
// Use an array to get all legal values for the department search
// $securityArray[] = $row["OnCampusDepartment"];
}
?>
</select>
</div>
<div class="large-4 columns">
<label>Department (if not assigned to a person)</label>
<select class="medium" name="department" required data-invalid>
<option value="unassigned" selected>Unassigned</option>
<?php
while($row = sqlsrv_fetch_array($populationResult))
{
echo "<option value=\"" . $row["OnCampusDepartment"] . "\">" . $row["OnCampusDepartment"] . "</option>\n";
// Use an array to get all legal values for the department search
$securityArray[] = $row["OnCampusDepartment"];
}
?>
</select>
</div>
<div class="large-4 columns">
<label>Assignment Type</label>
<select class="medium" name="assignmentType" required>
<option <?php echo "value='" . DEDICATED_COMPUTER_ASSIGNMENT_TYPE . "'"; ?>>Dedicated Computer</option>
<option <?php echo "value='" . SPECIAL_ASSIGNMENT_TYPE . "'"; ?>>Special</option>
<option <?php echo "value='" . LAB_ASSIGNMENT_TYPE . "'"; ?>>Lab</option>
<option <?php echo "value='" . KIOSK_ASSIGNMENT_TYPE . "'"; ?>>Kiosk</option>
<option <?php echo "value='" . PRINTER_ASSIGNMENT_TYPE . "'"; ?>>Printer</option>
</select>
</div>
</div>
<div class="row">
<div class="large-2 columns">
<label>Check if Primary Computer</label>
<input type="checkbox" name="primaryComputer" value="1">
</div>
<div class="large-2 columns">
<label>Check if Full Time Assignment</label>
<input type="checkbox" name="fullTime" value="1" data-invalid>
</div>
<div class="large-8 columns">
<label>Notes</label>
<textarea name="notes"></textarea>
</div>
</div>
</fieldset>
<div class="large-12 columns">
<div class="row" align="center">
<input type="submit" name="submit" value="Create New Item" class="button expand" formmethod="post">
</div>
</div>
</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')
?>