-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
72 lines (70 loc) · 2.59 KB
/
update.php
File metadata and controls
72 lines (70 loc) · 2.59 KB
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
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
//tickets
$tid = $request->tid;
$newcomment = $request->newcomment;
//devices
$deviceid=$request->did;
$dserial=$request->serial;
$dstatus=$request->status;
//students
$studentid=$request->studentid;
$sfname=$request->fname;
$slname=$request->lname;
$susername=$request->username;
$sgrade=$request->grade;
$shomeroom=$request->homeroom;
$sipadnum=$request->ipadnum;
if($sipadnum===''|| empty($sipadnum)){
$sipadnum= "NULL";
}
//update device status from ticket
$updeviceid=$request->updid;
$updstatus=$request->upstatus;
//close ticket
$close=$request->close;
$tid=$request->tid;
include 'pdo.php';
//add new comment to ticket
if(isset($newcomment) && $newcomment!= ''){
$comsql ="INSERT INTO `ip2`.`comments_maintenance` (`ticket_id`, `comment`, `date`) VALUES ('".$tid."', '".$newcomment."', CURRENT_TIMESTAMP);";
$stmtcom = $pdo->prepare ($comsql);
$stmtcom->execute();
echo $comsql;
}
//update device
if(isset($deviceid) && $deviceid!=''){
$upddevice ="INSERT INTO `iPads` (`iPad #`, `Serial Number`, `Status`) VALUES ('".$deviceid."', '".$dserial."', '".$dstatus."') ON DUPLICATE KEY UPDATE `iPad #`=VALUES(`iPad #`), `Serial Number`=VALUES(`Serial Number`), `Status`=VALUES(`Status`)";
$stmup = $pdo->prepare ($upddevice);
$stmup->execute();
echo $upddevice;
}
//update student
if(isset($studentid) && $studentid!=''){
$updstudent ="INSERT INTO `students14_15` (`Student ID`, `First Name`, `Last Name`, `Username`, `Grade`,`Homeroom`, `iPad #`) VALUES ('".$studentid."', '".$sfname."', '".$slname."', '".$susername."', '".$sgrade."', '".$shomeroom."', ".$sipadnum.") ON DUPLICATE KEY UPDATE `Student ID`=VALUES(`Student ID`), `First Name`=VALUES(`First Name`), `Last Name`=VALUES(`Last Name`), `Username`=VALUES(`Username`), `Grade`=VALUES(`Grade`), `Homeroom`=VALUES(`Homeroom`), `iPad #`=VALUES(`iPad #`)";
$stmup = $pdo->prepare ($updstudent);
$stmup->execute();
echo $updstudent;
}
//update device status
if(isset($updeviceid) && $updeviceid!='' && isset($updstatus) && $updstatus!=''){
$statsql ="UPDATE `iPads` SET `Status` = ".$updstatus." WHERE `iPad #` = ".$updeviceid;
$statstmt =$pdo->prepare ($statsql);
$statstmt->execute();
echo $statsql;
}
//close ticket
if (isset($tid) && isset($close)){
if ($close) {
$openclose = 0;
}else{
$openclose = 1;
}
$closesql="UPDATE `maintenance` SET `open` = ".$openclose." WHERE `ticket_id` = ".$tid;
$closestmt=$pdo->prepare ($closesql);
$closestmt->execute();
echo $closesql;
}