-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaisie.php
More file actions
236 lines (210 loc) · 10.1 KB
/
saisie.php
File metadata and controls
236 lines (210 loc) · 10.1 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
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
<?php
require "config/config.php";
require "inc/utils.php";
require "inc/vendor/autoload.php";
// Instanciate the API client
$client = new Glpi\Api\Rest\Client(URL_GLPI.'/apirest.php/', new GuzzleHttp\Client());
// Authenticate
try {
$client->setAppToken(GLPI_APPTOKEN);
$client->initSessionByCredentials(GLPI_USER, GLPI_PASS);
} catch (Exception $e) {
echo $e->getMessage();
die();
}
$itemHandler = new \Glpi\Api\Rest\ItemHandler($client);
//récupération du matériel
$response = $itemHandler->getItem(ucfirst($_GET["type"]), $_GET["id"]);
$item = json_decode($response['body']);
//récupération de la liste des users
$response = $itemHandler->getAllItems("user");
$users = json_decode($response['body']);
//Récupération des lieux
$response = $itemHandler->getAllItems("location");
$lieux = json_decode($response['body']);
//récupération de la liste des statuts
$response = $itemHandler->getAllItems("State");
$statuts = json_decode($response['body']);
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GLPI - Inventaire physique</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/font-awesome/css/all.min.css" rel="stylesheet">
<link href="assets/select2-4.0.13/dist/css/select2.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="card" style="margin-top:30px;margin-left:auto;margin-right:auto;">
<div class="card-body">
<div class="text-center">
<img src="assets/pics/logo_glpi.png" height="30%" width="30%">
</div>
<h4 class="card-title text-info text-center"><?php echo $item->name; ?> <a href="<?php echo $_GET["url"]; ?>" target="new" style="text-decoration:none;" class="text-info"><i class="fa fa-link"></i></a></h4>
<div class="mb-3">
<label for="serial" class="form-label">N° de série :</label>
<input type="text" class="form-control" id="serial" value="<?php echo $item->serial; ?>" disabled>
</div>
<div class="mb-3">
<label for="user" class="form-label">Utilisateur attribué :</label>
<select class="form-select selectpicker" id="user">
<?php
foreach ($users as $user)
{
if($user->firstname<>"")
{
echo "<option value='".$user->id."'";
if($item->users_id==$user->id)
{
echo " selected";
}
echo ">".$user->realname." ".$user->firstname."</option>";
}
}
?>
</select>
</div>
<div class="mb-3">
<label for="lieu" class="form-label">Lieu :</label>
<select class="form-select selectpicker" id="lieu">
<?php
foreach ($lieux as $lieu)
{
echo "<option value='".$lieu->id."'";
if($item->locations_id==$lieu->id)
{
echo " selected";
}
echo ">".$lieu->name."</option>";
}
?>
</select>
</div>
<div class="mb-3">
<label for="statut" class="form-label">Statut
-- :</label>
<select class="form-select selectpicker" id="statut">
<?php
foreach ($statuts as $statut)
{
$affiche=0;
switch($_GET["type"])
{
case "computer":
if($statut->is_visible_computer==1)
{
$affiche=1;
}
break;
case "monitor":
if($statut->is_visible_monitor==1)
{
$affiche=1;
}
break;
case "networkequipment":
if($statut->is_visible_networkequipment==1)
{
$affiche=1;
}
break;
case "peripheral":
if($statut->is_visible_peripheral==1)
{
$affiche=1;
}
break;
case "phone":
if($statut->is_visible_phone==1)
{
$affiche=1;
}
break;
case "printer":
if($statut->is_visible_printer==1)
{
$affiche=1;
}
break;
case "networkequipment":
if($statut->is_visible_networkequipment==1)
{
$affiche=1;
}
break;
}
if($affiche==1)
{
echo "<option value='".$statut->id."'";
if($item->states_id==$statut->id)
{
echo " selected";
}
echo ">".$statut->completename."</option>";
}
}
?>
</select>
</div>
<br>
<div class="d-grid gap-2">
<button type="button" class="btn btn-primary" onclick="valider()">Valider</button>
</div>
</div>
</div>
</div>
<script src="assets/js/jquery-3.6.0.min.js"></script>
<script src="assets/select2-4.0.13/dist/js/select2.full.min.js"></script>
<script>
$('#user').select2({
sorter: function(data) {
return data.sort(function (a, b) {
if (a.text > b.text) {
return 1;
}
if (a.text < b.text) {
return -1;
}
return 0;
})
}
});
$('#lieu').select2();
$('#statut').select2({
sorter: function(data) {
return data.sort(function (a, b) {
if (a.text > b.text) {
return 1;
}
if (a.text < b.text) {
return -1;
}
return 0;
})
}
});
function valider() {
$.ajax({
url: "ajax/maj_item.php",
type: "POST",
data: {
id: <?php echo $_GET["id"]; ?>,
users_id: $("#user").val(),
locations_id: $("#lieu").val(),
type:"<?php echo $_GET["type"]; ?>",
states_id: $("#statut").val(),
},
success: function(response) {
var result = $.trim(response);
//alert(result);
document.location.href="index.php";
}
});
//$response = $itemHandler->updateItems("location");
}
</script>
</body>
</html>