-
Notifications
You must be signed in to change notification settings - Fork 1
/
index2.8-loanercheckout.php
231 lines (173 loc) · 6.97 KB
/
index2.8-loanercheckout.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
<?php
#Version 1
#Used external database to track check in and out
#Version 2
#Used EAs within the JSS to track check in and out. Smart group, API call for the full group and then API call for every machine
#Version 2.5
#Used EAs within the JSS. Advanced Computer Search with certain Display fields
#Version 2.8
#Now with more global definitions, clearing up a lot of junk and fixed what Chris broke
#Requirements
#----------------------------------------------------------------------------------------
#Advanaced Computer Search to find all Loaner computer
#Fields need to be shown in the Search - Name, DateCheckedIn, DateCheckedOut, LoanerAvailability, Username, Department, Serial Number, JSS ID
#Extension Attributes Needed to be added into the JSS - DateCheckedIn, DateCheckedOut, LoanerAvailability
#EA - DateReturned and DateOut set as Data Type date
#EA - Availability set as Input Type Pop Up Menu, choices Yes and No
#global settings
$jss = 'https://jamfproserver:8443';
$emailDomain = 'emailDomain.org';
$username = 'username';
$password = 'password';
$availabilityID = 'xx';
$returnedID = 'xx';
$outID = 'xx';
$advancedComputerSearch = 'xx';
$jssAPI = $jss."/JSSResource/";
function PUTintoCasper($JSSResource, $Avail) {
#PUT info into the JSS using API
$userpass = $GLOBALS['username'].":".$GLOBALS['password'];
$remote_url = $GLOBALS['jssAPI'] . $JSSResource;
$xml = "";
if ($Avail == "Yes"){
#checking out a laptop
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><computer><location><username></username><real_name></real_name><email_address></email_address><department></department></location><extension_attributes><extension_attribute><id>".$GLOBALS['availabilityID']."</id><value>".$Avail."</value></extension_attribute><extension_attribute><id>".$GLOBALS['returnedID']."</id><value>".$_POST['DateReturned']."</value></extension_attribute></extension_attributes></computer>";
} elseif ($Avail == "No"){
#checking in a laptop
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><computer><location><username>".$_POST['User']."</username></location><extension_attributes><extension_attribute><id>".$GLOBALS['availabilityID']."</id><type>String</type><value>".$Avail."</value></extension_attribute><extension_attribute><id>".$GLOBALS['outID']."</id><type>Date</type><value>".$_POST['DateOut']."</value></extension_attribute></extension_attributes></computer>";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $remote_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Accept: text/xml', 'Content-Length: ' . strlen($xml),'X-HTTP-Method-Override: PUT'));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $GLOBALS['username'].":".$GLOBALS['password']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_STDERR, $GLOBALS['outID']);
$response = curl_exec($ch);
curl_close($ch);
fclose($GLOBALS['outID']);
}
function ReadJSS($JSSResource) {
#GET info from JSS using the API
$remote_url = $GLOBALS['jssAPI'] . $JSSResource;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $remote_url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_USERPWD, $GLOBALS['username'].":".$GLOBALS['password']);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
If ($_POST){
#If there's a POST available
if ($_POST["avail"] == "checkout"){
PUTintoCasper("computers/serialnumber/".$_POST['laptop'], "No");
}
if ($_POST["avail"] == "checkin"){
PUTintoCasper("computers/serialnumber/".$_POST['laptop'], "Yes");
}
}
?>
<HTML>
<HEAD>
<style type="text/css">
<!--
body {
background-image: url("YellowLinedPaper.jpg");
background-color: #fcf5ad;
background-size: 100% 30%;
}
.TheBody {
margin-left: 15%;
margin-right: 12%;
}
table {
width: 100%;
}
table, tr, td {
border-collapse: collapse;
text-align: center;
}
a:link {
text-decoration: none;
color: black;
}
a:visited {
text-decoration: none;
color: black;
}
a:hover {
text-decoration: underline;
color: gray;
}
a:active {
text-decoration: underline;
}
</style>
<script>
function DoubleCheck(LaptopConfirm){
var r = confirm("Confirm update to " + LaptopConfirm);
if (r == true) {
document.getElementById('laptopsform').submit();
return true;
} else {
x = "You pressed Cancel!";
document.getElementById('laptopsform').reset();
return false;
}
}
</script>
<TITLE>Loaner Checkout</TITLE>
</HEAD>
<BODY>
<div class="TheBody">
<BR>
<table>
<tr style="font-size: 15pt; text-decoration: underline;">
<td>Laptop</td>
<td>User</td>
<td>Date Out</td>
<td>Date Returned</td>
<td></td>
</tr>
<?php
#Advanced Saved Computer Search ID needed here
#Fields need to be shown in the Search - Name, DateCheckedIn, DateCheckedOut, LoanerAvailability, Username, Department, Serial Number, JSS ID
$Read_result=ReadJSS("computerreports/id/".$advancedComputerSearch);
$TodayDate = date('Y/m/d');
$jss_array = json_decode($Read_result, true);
$device_array = $jss_array['computer_reports'];
foreach($device_array as $device){
echo "<form action=\"\" method=\"Post\" name=\"laptopsform\" id=\"laptopsform\" onSubmit=\"return DoubleCheck('".$device['Computer_Name']."');\">";
echo "<tr style=\"font-size: 12pt;\">";
echo "<input type=\"hidden\" name=\"laptop\" value=\"".$device['Serial_Number']."\">";
echo "<td><a href=\"".$jss."/computers.html?id=".$device['JSS_Computer_ID']."\" target=\"_blank\">".$device['Computer_Name']."</a></td>";
if($device['LoanerAvailability'] == "No"){
echo "<td><a href=\"mailto:".$device['Username']."@".$emailDomain."\" target=\"_blank\">".$device['Username']."</a></td>";
echo "<td>".$device['DateCheckedOut']."</td>";
echo "<td><input type=\"date\" name=\"DateReturned\" value=\"".$TodayDate."\"></td>";
echo "<input type=\"hidden\" name=\"avail\" value=\"checkin\">";
echo "<td><input type=\"submit\" value=\"Submit\" id=\"submit\" name=\"submit\"></td>";
echo "</form>";
} else if ($device['LoanerAvailability'] == "Yes"){
echo "<td><input type=\"text\" name=\"User\"></td>";
echo "<td><input type=\"date\" name=\"DateOut\" value=\"".$TodayDate."\"></td>";
echo "<td>".$device['DateCheckedIn']."</td>";
echo "<input type=\"hidden\" name=\"avail\" value=\"checkout\">";
echo "<td><input type=\"submit\" value=\"Submit\" id=\"submit\" name=\"submit\"></td>";
echo "</form>";
}
}
?>
</div>
</BODY>
</HTML>