This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
/
inventorycomputercomputer.class.php
375 lines (320 loc) · 11.9 KB
/
inventorycomputercomputer.class.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<?php
/**
* FusionInventory
*
* Copyright (C) 2010-2016 by the FusionInventory Development Team.
*
* http://www.fusioninventory.org/
* https://github.com/fusioninventory/fusioninventory-for-glpi
* http://forge.fusioninventory.org/
*
* ------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of FusionInventory project.
*
* FusionInventory is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FusionInventory is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with FusionInventory. If not, see <http://www.gnu.org/licenses/>.
*
* ------------------------------------------------------------------------
*
* This file is used to manage the extended information of a computer.
*
* ------------------------------------------------------------------------
*
* @package FusionInventory
* @author David Durieux
* @copyright Copyright (c) 2010-2016 FusionInventory team
* @license AGPL License 3.0 or (at your option) any later version
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* @link http://www.fusioninventory.org/
* @link https://github.com/fusioninventory/fusioninventory-for-glpi
*
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
/**
* Manage the extended information of a computer.
*/
class PluginFusioninventoryInventoryComputerComputer extends CommonDBTM {
/**
* The right name for this class
*
* @var string
*/
static $rightname = 'computer';
/**
* Get name of this type by language of the user connected
*
* @param integer $nb number of elements
* @return string name of this type
*/
static function getTypeName($nb = 0) {
return "";
}
/**
* Display information about computer (bios, last contact...)
*
* @global array $CFG_GLPI
* @param object $item
* @return true
*/
static function showAgentInfo($item) {
global $CFG_GLPI;
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
$a_computerextend = current($pfInventoryComputerComputer->find(
"`computers_id`='".$item->getID()."'",
"", 1));
if (empty($a_computerextend)) {
return;
}
echo '<table class="tab_glpi" width="100%">';
$pfAgent = new PluginFusioninventoryAgent();
$pfAgent->showInfoForComputer($item);
if ($a_computerextend['bios_date'] != '') {
echo '<tr class="tab_bg_1">';
echo '<td>'.__('BIOS date', 'fusioninventory').'</td>';
echo '<td>'.Html::convDate($a_computerextend['bios_date']).'</td>';
echo '</tr>';
}
if ($a_computerextend['bios_version'] != '') {
echo '<tr class="tab_bg_1">';
echo '<td>'.__('BIOS version', 'fusioninventory').'</td>';
echo '<td>'.$a_computerextend['bios_version'].'</td>';
echo '</tr>';
}
if ($a_computerextend['bios_manufacturers_id'] > 0) {
echo '<tr class="tab_bg_1">';
echo '<td>'.__('Manufacturer').' :</td>';
echo '<td>';
echo Dropdown::getDropdownName("glpi_manufacturers",
$a_computerextend['bios_manufacturers_id']);
echo '</td>';
echo '</tr>';
}
if ($a_computerextend['operatingsystem_installationdate'] != '') {
echo '<tr class="tab_bg_1">';
echo "<td>".__('Operating system')." - ".__('Installation')." (".
strtolower(__('Date')).")</td>";
echo '<td>'.Html::convDate($a_computerextend['operatingsystem_installationdate']).'</td>';
echo '</tr>';
}
if ($a_computerextend['winowner'] != '') {
echo '<tr class="tab_bg_1">';
echo '<td>'.__('Owner', 'fusioninventory').'</td>';
echo '<td>'.$a_computerextend['winowner'].'</td>';
echo '</tr>';
}
if ($a_computerextend['wincompany'] != '') {
echo '<tr class="tab_bg_1">';
echo '<td>'.__('Company', 'fusioninventory').'</td>';
echo '<td>'.$a_computerextend['wincompany'].'</td>';
echo '</tr>';
}
return true;
}
/**
* Get automatic inventory info for a computer
* @since 9.1+1.2
* @param computers_id the computer ID to look for
* @return inventory computer infos or an empty array
*/
function hasAutomaticInventory($computers_id) {
$a_computerextend = current($this->find("`computers_id`='$computers_id'",
"", 1));
if (empty($a_computerextend)) {
return [];
} else {
return $a_computerextend;
}
}
/**
* Display information about computer that is linked to an agent but
* has no inventory
*
* @since 9.2
* @param object $item
* @return true
*/
static function showFormForAgentWithNoInventory($item) {
$id = $item->getID();
$pfComputer = new self();
if ($item->isNewItem()
|| !empty($pfComputer->hasAutomaticInventory($id))) {
return true;
} else {
$pfAgent = new PluginFusioninventoryAgent();
if ($pfAgent->getAgentWithComputerid($id)) {
echo '<tr>';
echo '<td colspan=\'4\'></td>';
echo '</tr>';
echo '<tr>';
echo '<th colspan="4">'.__('FusionInventory', 'fusioninventory').'</th>';
echo '</tr>';
$pfAgent->showInfoForComputer($item, 4);
}
return true;
}
}
/**
* Display information about a computer operating system
* has no inventory
*
* @since 9.2
* @param object $item
* @return true
*/
static function showFormOS($item) {
$pfComputer = new self();
$a_computerextend = current(
$pfComputer->find("`computers_id`='".$item->fields['items_id']."'", "", 1)
);
if (empty($a_computerextend)) {
return;
}
echo '<tr class="tab_bg_1">';
echo "<th colspan='4'></th>";
echo "</tr>";
echo '<tr class="tab_bg_1">';
echo '<td>'.__('Company', 'fusioninventory').'</td>';
echo '<td>'.$a_computerextend['wincompany'].'</td>';
echo '<td>'.__('Owner', 'fusioninventory').'</td>';
echo '<td>'.$a_computerextend['winowner'].'</td>';
echo '</tr>';
echo '<tr class="tab_bg_1">';
echo "<td>".__('Comments')."</td>";
echo '<td>'.$a_computerextend['oscomment'].'</td>';
echo "<td>".__("Installation date")."</td>";
echo '<td>'.Html::convDate($a_computerextend['operatingsystem_installationdate']).'</td>';
echo "<tr class='tab_bg_1'>";
echo "<td>".__('HostID', 'fusioninventory')."</td>";
echo "<td>";
echo $a_computerextend['hostid'];
echo "</td><colspan='2'></td>";
echo "</tr>";
return true;
}
/**
* Display information about computer (bios, last contact...)
*
* @global array $CFG_GLPI
* @param object $item
* @return true
*/
static function showComputerInfo($item) {
global $CFG_GLPI;
// Manage locks pictures
PluginFusioninventoryLock::showLockIcon('Computer');
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($item->getID());
if (empty($a_computerextend)) {
return true;
}
echo '<table class="tab_glpi" width="100%">';
echo '<tr>';
echo '<th colspan="4">'.__('FusionInventory', 'fusioninventory').'</th>';
echo '</tr>';
echo '<tr class="tab_bg_1">';
echo '<td>';
echo __('Last inventory', 'fusioninventory');
echo '</td>';
echo '<td>';
echo Html::convDateTime($a_computerextend['last_fusioninventory_update']);
echo '</td>';
if ($a_computerextend['remote_addr'] != '') {
echo '<td>'.__('Public contact address', 'fusioninventory').'</td>';
echo '<td>'.$a_computerextend['remote_addr'].'</td>';
}
echo "<td colspan='2'></td>";
echo '</tr>';
$pfAgent = new PluginFusioninventoryAgent();
$pfAgent->showInfoForComputer($item, 4);
// Display automatic entity transfer
if (Session::isMultiEntitiesMode()) {
echo '<tr class="tab_bg_1">';
echo '<td>'.__('Automatic entity transfer', 'fusioninventory').'</td>';
echo '<td>';
$pfEntity = new PluginFusioninventoryEntity();
if ($pfEntity->getValue('transfers_id_auto', $item->fields['entities_id']) == 0) {
echo __('No, locked (by entity configuration)', 'fusioninventory');
} else {
if ($a_computerextend['is_entitylocked'] == 1) {
echo __('No, locked manually', 'fusioninventory');
echo " [ <a href='".$CFG_GLPI['root_doc']."/plugins/fusioninventory/front/computerentitylock.form.php?id=".
$a_computerextend['id']."&lock=0'>".__('Unlock it', 'fusioninventory')."</a> ]";
} else {
echo __('Yes');
echo " [ <a href='".$CFG_GLPI['root_doc']."/plugins/fusioninventory/front/computerentitylock.form.php?id=".
$a_computerextend['id']."&lock=1'>".__('Lock it', 'fusioninventory')."</a> ]";
}
}
echo '</td>';
echo '</tr>';
}
$pfRemoteManagement = new PluginFusioninventoryComputerRemoteManagement();
$pfRemoteManagement->showInformation($item->getID());
echo '</table>';
return true;
}
static function showDownloadInventoryFile($computers_id) {
global $CFG_GLPI;
$folder = substr($computers_id, 0, -1);
if (empty($folder)) {
$folder = '0';
}
if (file_exists(PLUGIN_FUSIONINVENTORY_XML_DIR."computer/".$folder."/".$computers_id)) {
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'>";
echo "<th>";
echo "<a href='".$CFG_GLPI['root_doc'].
"/plugins/fusioninventory/front/send_inventory.php".
"?itemtype=PluginFusioninventoryInventoryComputerComputer".
"&function=sendXML&items_id=computer/".$folder."/".$computers_id.
"&filename=Computer-".$computers_id.".xml'".
"target='_blank'>";
$message = __('Download inventory file', 'fusioninventory');
echo "<img src=\"".$CFG_GLPI["root_doc"].
"/pics/icones/csv-dist.png\" alt='$message' title='$message'>";
echo " $message</a>";
echo "</th></tr></table>";
}
}
/**
* Delete extended information of computer
*
* @param integer $computers_id
*/
static function cleanComputer($computers_id) {
$pfComputer = new self();
$pfComputer->deleteByCriteria(['computers_id' => $computers_id], true, false);
}
/**
* Get entity lock. If true, computer can't be transfered to another entity
* by agent inventory (so in automatic)
*
* @param integer $computers_id
* @return boolean
*/
function getLock($computers_id) {
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
$a_computerextend = current($pfInventoryComputerComputer->find(
"`computers_id`='".$computers_id."'",
"", 1));
if (empty($a_computerextend)) {
return false;
}
return $a_computerextend['is_entitylocked'];
}
}