ryxeo-glpi-git / inc / device.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (24,5 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: device.function.php 7763 2009-01-06 18:44:50Z moyo $
|
4 |
-------------------------------------------------------------------------
|
5 |
GLPI - Gestionnaire Libre de Parc Informatique
|
6 |
Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
7 |
|
8 |
http://indepnet.net/ http://glpi-project.org
|
9 |
-------------------------------------------------------------------------
|
10 |
|
11 |
LICENSE
|
12 |
|
13 |
This file is part of GLPI.
|
14 |
|
15 |
GLPI is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
17 |
the Free Software Foundation; either version 2 of the License, or
|
18 |
(at your option) any later version.
|
19 |
|
20 |
GLPI is distributed in the hope that it will be useful,
|
21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
GNU General Public License for more details.
|
24 |
|
25 |
You should have received a copy of the GNU General Public License
|
26 |
along with GLPI; if not, write to the Free Software
|
27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
28 |
--------------------------------------------------------------------------
|
29 |
*/
|
30 |
|
31 |
if (!defined('GLPI_ROOT')){ |
32 |
die("Sorry. You can't access directly to this file"); |
33 |
} |
34 |
|
35 |
/** Get device table based on device type
|
36 |
*@param $dev_type device type
|
37 |
*@return table name string
|
38 |
*/
|
39 |
function getDeviceTable($dev_type){ |
40 |
switch ($dev_type){ |
41 |
case MOBOARD_DEVICE : |
42 |
return "glpi_device_moboard"; |
43 |
break;
|
44 |
case PROCESSOR_DEVICE : |
45 |
return "glpi_device_processor"; |
46 |
break;
|
47 |
case RAM_DEVICE : |
48 |
return "glpi_device_ram"; |
49 |
break;
|
50 |
case HDD_DEVICE : |
51 |
return "glpi_device_hdd"; |
52 |
break;
|
53 |
case NETWORK_DEVICE : |
54 |
return "glpi_device_iface"; |
55 |
break;
|
56 |
case DRIVE_DEVICE : |
57 |
return "glpi_device_drive"; |
58 |
break;
|
59 |
case CONTROL_DEVICE : |
60 |
return "glpi_device_control"; |
61 |
break;
|
62 |
case GFX_DEVICE : |
63 |
return "glpi_device_gfxcard"; |
64 |
break;
|
65 |
case SND_DEVICE : |
66 |
return "glpi_device_sndcard"; |
67 |
break;
|
68 |
case PCI_DEVICE : |
69 |
return "glpi_device_pci"; |
70 |
break;
|
71 |
case CASE_DEVICE : |
72 |
return "glpi_device_case"; |
73 |
break;
|
74 |
case POWER_DEVICE : |
75 |
return "glpi_device_power"; |
76 |
break;
|
77 |
|
78 |
} |
79 |
|
80 |
} |
81 |
|
82 |
/** Get device specifity label based on device type
|
83 |
*@param $dev_type device type
|
84 |
*@return specifity label string
|
85 |
*/
|
86 |
function getDeviceSpecifityLabel($dev_type){ |
87 |
global $LANG; |
88 |
switch ($dev_type){ |
89 |
case MOBOARD_DEVICE : |
90 |
return ""; |
91 |
break;
|
92 |
case PROCESSOR_DEVICE : |
93 |
return $LANG["device_ram"][1]; |
94 |
break;
|
95 |
case RAM_DEVICE : |
96 |
return $LANG["device_ram"][2]; |
97 |
break;
|
98 |
case HDD_DEVICE : |
99 |
return $LANG["device_hdd"][4]; |
100 |
break;
|
101 |
case NETWORK_DEVICE : |
102 |
return $LANG["device_iface"][2]; |
103 |
break;
|
104 |
case DRIVE_DEVICE : |
105 |
return ""; |
106 |
break;
|
107 |
case CONTROL_DEVICE : |
108 |
return ""; |
109 |
break;
|
110 |
case GFX_DEVICE : |
111 |
//return "";
|
112 |
return $LANG["device_gfxcard"][0]; |
113 |
break;
|
114 |
case SND_DEVICE : |
115 |
return ""; |
116 |
break;
|
117 |
case PCI_DEVICE : |
118 |
return ""; |
119 |
break;
|
120 |
case CASE_DEVICE : |
121 |
return ""; |
122 |
break;
|
123 |
case POWER_DEVICE : |
124 |
return ""; |
125 |
break;
|
126 |
|
127 |
} |
128 |
} |
129 |
|
130 |
|
131 |
/**
|
132 |
* Get device type name based on device type
|
133 |
*
|
134 |
* @param $device_num device type
|
135 |
* @return if $device_num == -1 return array of names else return device name
|
136 |
**/
|
137 |
function getDictDeviceLabel($device_num=-1) { |
138 |
|
139 |
global $LANG; |
140 |
$dp=array(); |
141 |
$dp[MOBOARD_DEVICE]=$LANG["devices"][5]; |
142 |
$dp[PROCESSOR_DEVICE]=$LANG["devices"][4]; |
143 |
$dp[NETWORK_DEVICE]=$LANG["devices"][3]; |
144 |
$dp[RAM_DEVICE]=$LANG["devices"][6]; |
145 |
$dp[HDD_DEVICE]=$LANG["devices"][1]; |
146 |
$dp[DRIVE_DEVICE]=$LANG["devices"][19]; |
147 |
$dp[CONTROL_DEVICE]=$LANG["devices"][20]; |
148 |
$dp[GFX_DEVICE]=$LANG["devices"][2]; |
149 |
$dp[SND_DEVICE]=$LANG["devices"][7]; |
150 |
$dp[PCI_DEVICE]=$LANG["devices"][21]; |
151 |
$dp[CASE_DEVICE]=$LANG["devices"][22]; |
152 |
$dp[POWER_DEVICE]=$LANG["devices"][23]; |
153 |
if ($device_num==-1) |
154 |
return $dp; |
155 |
else return $dp[$device_num]; |
156 |
} |
157 |
|
158 |
/** print form/tab for a device linked to a computer
|
159 |
*@param $device device object
|
160 |
*@param $quantity quantity of device
|
161 |
*@param $specif specificity value
|
162 |
*@param $compID computer ID
|
163 |
*@param $compDevID computer device ID
|
164 |
*@param $withtemplate template or basic computer
|
165 |
*/
|
166 |
function printDeviceComputer($device,$quantity,$specif,$compID,$compDevID,$withtemplate='') { |
167 |
global $LANG,$CFG_GLPI; |
168 |
|
169 |
if (!haveRight("computer","r")) return false; |
170 |
$canedit=haveRight("computer","w"); |
171 |
|
172 |
//print the good form switch the wanted device type.
|
173 |
$entry=array(); |
174 |
$type=""; |
175 |
$name=""; |
176 |
$specificity_label = getDeviceSpecifityLabel($device->devtype); |
177 |
switch($device->devtype) { |
178 |
case HDD_DEVICE : |
179 |
$type=$LANG["devices"][1]; |
180 |
$name=$device->fields["designation"]; |
181 |
if (!empty($device->fields["rpm"])) $entry[$LANG["device_hdd"][0]]=$device->fields["rpm"]; |
182 |
if ($device->fields["interface"]) $entry[$LANG["common"][65]]=getDropdownName("glpi_dropdown_interface",$device->fields["interface"]); |
183 |
if (!empty($device->fields["cache"])) $entry[$LANG["device_hdd"][1]]=$device->fields["cache"]; |
184 |
|
185 |
$specificity_size = 10; |
186 |
break;
|
187 |
case GFX_DEVICE : |
188 |
$type=$LANG["devices"][2]; |
189 |
$name=$device->fields["designation"]; |
190 |
// if (!empty($device->fields["ram"])) $entry[$LANG["device_gfxcard"][0]]=$device->fields["ram"];
|
191 |
// if (!empty($device->fields["interface"])) $entry[$LANG["common"][65]]=getDropdownName("glpi_dropdown_interface",$device->fields["interface"]);
|
192 |
|
193 |
$entry[$LANG["common"][65]]=$device->fields["interface"]; |
194 |
$specificity_size = 10; |
195 |
break;
|
196 |
case NETWORK_DEVICE : |
197 |
$type=$LANG["devices"][3]; |
198 |
$name=$device->fields["designation"]; |
199 |
if (!empty($device->fields["bandwidth"])) $entry[$LANG["device_iface"][0]]=$device->fields["bandwidth"]; |
200 |
|
201 |
$specificity_size = 18; |
202 |
break;
|
203 |
case MOBOARD_DEVICE : |
204 |
$type=$LANG["devices"][5]; |
205 |
$name=$device->fields["designation"]; |
206 |
if (!empty($device->fields["chipset"])) $entry[$LANG["device_moboard"][0]]=$device->fields["chipset"]; |
207 |
|
208 |
$specificity_size = 10; |
209 |
break;
|
210 |
case PROCESSOR_DEVICE : |
211 |
$type=$LANG["devices"][4]; |
212 |
$name=$device->fields["designation"]; |
213 |
if (!empty($device->fields["frequence"])) $entry[$LANG["device_ram"][1]]=$device->fields["frequence"]; |
214 |
|
215 |
$specificity_size = 10; |
216 |
break;
|
217 |
case RAM_DEVICE : |
218 |
$type=$LANG["devices"][6]; |
219 |
$name=$device->fields["designation"]; |
220 |
if (!empty($device->fields["type"])) $entry[$LANG["common"][17]]=getDropdownName("glpi_dropdown_ram_type",$device->fields["type"]); |
221 |
if (!empty($device->fields["frequence"])) $entry[$LANG["device_ram"][1]]=$device->fields["frequence"]; |
222 |
|
223 |
$specificity_size = 10; |
224 |
break;
|
225 |
case SND_DEVICE : |
226 |
|
227 |
$type=$LANG["devices"][7]; |
228 |
$name=$device->fields["designation"]; |
229 |
if (!empty($device->fields["type"])) $entry[$LANG["common"][17]]=$device->fields["type"]; |
230 |
|
231 |
$specificity_size = 10; |
232 |
break;
|
233 |
case DRIVE_DEVICE : |
234 |
$type=$LANG["devices"][19]; |
235 |
$name=$device->fields["designation"]; |
236 |
if ($device->fields["is_writer"]) $entry[$LANG["device_drive"][0]]=getYesNo($device->fields["is_writer"]); |
237 |
if (!empty($device->fields["speed"])) $entry[$LANG["device_drive"][1]]=$device->fields["speed"]; |
238 |
if (!empty($device->fields["frequence"])) $entry[$LANG["common"][65]]=$device->fields["frequence"]; |
239 |
break;
|
240 |
case CONTROL_DEVICE : |
241 |
$type=$LANG["devices"][20]; |
242 |
$name=$device->fields["designation"]; |
243 |
if ($device->fields["raid"]) $entry[$LANG["device_control"][0]]=getYesNo($device->fields["raid"]); |
244 |
if ($device->fields["interface"]) $entry[$LANG["common"][65]]=getDropdownName("glpi_dropdown_interface",$device->fields["interface"]); |
245 |
|
246 |
break;
|
247 |
case PCI_DEVICE : |
248 |
$type=$LANG["devices"][21]; |
249 |
$name=$device->fields["designation"]; |
250 |
|
251 |
break;
|
252 |
case POWER_DEVICE : |
253 |
$type=$LANG["devices"][23]; |
254 |
$name=$device->fields["designation"]; |
255 |
if (!empty($device->fields["power"])) $entry[$LANG["device_power"][0]]=$device->fields["power"]; |
256 |
if ($device->fields["atx"]) $entry[$LANG["device_power"][1]]=getYesNo($device->fields["atx"]); |
257 |
|
258 |
break;
|
259 |
case CASE_DEVICE : |
260 |
$type=$LANG["devices"][22]; |
261 |
$name=$device->fields["designation"]; |
262 |
if (!empty($device->fields["type"])) { |
263 |
$entry[$LANG["device_case"][0]]=getDropdownName("glpi_dropdown_case_type",$device->fields["type"]); |
264 |
} |
265 |
|
266 |
break;
|
267 |
} |
268 |
|
269 |
echo "<tr class='tab_bg_2'>"; |
270 |
echo "<td class='center'>"; |
271 |
echo "<select name='quantity_$compDevID'>"; |
272 |
for ($i=0;$i<100;$i++) |
273 |
echo "<option value='$i' ".($quantity==$i?"selected":"").">".$i."x</option>"; |
274 |
echo "</select>"; |
275 |
echo "</td>"; |
276 |
|
277 |
if (haveRight("device","w")) { |
278 |
echo "<td class='center'><a href='".$CFG_GLPI["root_doc"]."/front/device.php?device_type=".$device->devtype."'>$type</a></td>"; |
279 |
echo "<td class='center'><a href='".$CFG_GLPI["root_doc"]."/front/device.form.php?ID=".$device->fields['ID']."&device_type=".$device->devtype."'> $name ".($CFG_GLPI["view_ID"]?" (".$device->fields['ID'].")":"")."</a></td>"; |
280 |
} else {
|
281 |
echo "<td class='center'>$type</td>"; |
282 |
echo "<td class='center'> $name ".($CFG_GLPI["view_ID"]?" (".$device->fields['ID'].")":"")."</td>"; |
283 |
} |
284 |
|
285 |
if (count($entry)>0){ |
286 |
$more=0; |
287 |
if(!empty($specificity_label)) $more=1; |
288 |
$colspan=60/(count($entry)+$more); |
289 |
foreach ($entry as $key => $val){ |
290 |
echo "<td colspan='$colspan'>$key: $val</td>"; |
291 |
|
292 |
} |
293 |
|
294 |
} else if(empty($specificity_label)) echo "<td colspan='60'> </td>"; |
295 |
else $colspan=60; |
296 |
|
297 |
|
298 |
if(!empty($specificity_label)) { |
299 |
|
300 |
//Mise a jour des sp�ificit�s
|
301 |
if(!empty($withtemplate) && $withtemplate == 2) { |
302 |
if(empty($specif)) $specif = " "; |
303 |
echo "<td colspan='$colspan'>".$specificity_label.": $specif</td><td> </td>"; |
304 |
} |
305 |
else {
|
306 |
|
307 |
echo "<td align='right' colspan='$colspan'>".$specificity_label.": <input type='text' name='devicevalue_$compDevID' value=\"".$specif."\" size='$specificity_size' ></td>"; |
308 |
|
309 |
} |
310 |
|
311 |
} |
312 |
echo "</tr>"; |
313 |
} |
314 |
|
315 |
|
316 |
|
317 |
/** Update an internal device specificity
|
318 |
* @param $newValue new specifity value
|
319 |
* @param $compDevID computer device ID
|
320 |
* @param $strict update based on ID
|
321 |
* @param $checkcoherence check coherence of new value before updating : do not update if it is not coherent
|
322 |
*/
|
323 |
function update_device_specif($newValue,$compDevID,$strict=false,$checkcoherence=false) { |
324 |
|
325 |
// Check old value for history
|
326 |
global $DB; |
327 |
|
328 |
|
329 |
$query ="SELECT * FROM glpi_computer_device WHERE ID = '".$compDevID."'"; |
330 |
|
331 |
if ($result = $DB->query($query)) { |
332 |
if ($DB->numrows($result)){ |
333 |
$data = addslashes_deep($DB->fetch_array($result)); |
334 |
cleanAllItemCache("device_".$data["FK_computers"],"GLPI_".COMPUTER_TYPE); |
335 |
|
336 |
if ($checkcoherence){ |
337 |
switch ($data["device_type"]){ |
338 |
case PROCESSOR_DEVICE : |
339 |
//Prevent division by O error if newValue is null or doesn't contains any value
|
340 |
if ($newValue == null || $newValue=='') |
341 |
return false; |
342 |
|
343 |
//Calculate pourcent change of frequency
|
344 |
$pourcent = ( $newValue / ($data["specificity"] / 100) ) - 100; |
345 |
|
346 |
//If new processor speed value is superior to the old one, and if the change is at least 5% change
|
347 |
if ($data["specificity"] < $newValue && $pourcent > 4) |
348 |
$condition = true; |
349 |
else
|
350 |
$condition = false; |
351 |
break;
|
352 |
case GFX_DEVICE : |
353 |
//If memory has changed and his new value is not 0
|
354 |
if ($data["specificity"] != $newValue && $newValue > 0) |
355 |
$condition = true; |
356 |
else
|
357 |
$condition = false; |
358 |
break;
|
359 |
default :
|
360 |
if ($data["specificity"] != $newValue) |
361 |
$condition = true; |
362 |
else
|
363 |
$condition = false; |
364 |
break;
|
365 |
} |
366 |
} |
367 |
else
|
368 |
{ |
369 |
if ($data["specificity"] != $newValue) |
370 |
$condition = true; |
371 |
else
|
372 |
$condition = false; |
373 |
} |
374 |
|
375 |
// Is it a real change ?
|
376 |
if( $condition){ |
377 |
|
378 |
// Update specificity
|
379 |
$WHERE=" WHERE FK_device = '".$data["FK_device"]."' AND FK_computers = '".$data["FK_computers"]."' AND device_type = '".$data["device_type"]."' AND specificity='".$data["specificity"]."'"; |
380 |
if ($strict) $WHERE=" WHERE ID='$compDevID'"; |
381 |
|
382 |
$query2 = "UPDATE glpi_computer_device SET specificity = '".$newValue."' $WHERE"; |
383 |
if($DB->query($query2)){ |
384 |
|
385 |
$changes[0]='0'; |
386 |
$changes[1]=addslashes($data["specificity"]); |
387 |
$changes[2]=$newValue; |
388 |
// history log
|
389 |
historyLog ($data["FK_computers"],COMPUTER_TYPE,$changes,$data["device_type"],HISTORY_UPDATE_DEVICE); |
390 |
return true; |
391 |
}else{
|
392 |
return false; |
393 |
} |
394 |
} |
395 |
} |
396 |
} |
397 |
|
398 |
} |
399 |
|
400 |
/** Update an internal device quantity
|
401 |
* @param $newNumber new quantity value
|
402 |
* @param $compDevID computer device ID
|
403 |
*/
|
404 |
function update_device_quantity($newNumber,$compDevID){ |
405 |
// Check old value for history
|
406 |
global $DB; |
407 |
$query ="SELECT * FROM glpi_computer_device WHERE ID = '".$compDevID."'"; |
408 |
if ($result = $DB->query($query)) { |
409 |
$data = addslashes_deep($DB->fetch_array($result)); |
410 |
|
411 |
$query2 = "SELECT ID FROM glpi_computer_device WHERE FK_device = '".$data["FK_device"]."' AND FK_computers = '".$data["FK_computers"]."' AND device_type = '".$data["device_type"]."' AND specificity='".$data["specificity"]."'"; |
412 |
if ($result2 = $DB->query($query2)) { |
413 |
|
414 |
// Delete devices
|
415 |
$number=$DB->numrows($result2); |
416 |
if ($number>$newNumber){ |
417 |
for ($i=$newNumber;$i<$number;$i++){ |
418 |
$data2 = $DB->fetch_array($result2); |
419 |
unlink_device_computer($data2["ID"],1); |
420 |
} |
421 |
// Add devices
|
422 |
} else if ($number<$newNumber){ |
423 |
for ($i=$number;$i<$newNumber;$i++){ |
424 |
compdevice_add($data["FK_computers"],$data["device_type"],$data["FK_device"],$data["specificity"],1); |
425 |
} |
426 |
} |
427 |
} |
428 |
} |
429 |
} |
430 |
|
431 |
/**
|
432 |
* Unlink a device, linked to a computer.
|
433 |
*
|
434 |
* Unlink a device and a computer witch link ID is $compDevID (on table glpi_computer_device)
|
435 |
*
|
436 |
* @param $compDevID ID of the computer-device link (table glpi_computer_device)
|
437 |
* @param $dohistory log history updates ?
|
438 |
* @returns boolean
|
439 |
**/
|
440 |
function unlink_device_computer($compDevID,$dohistory=1){ |
441 |
|
442 |
// get old value and id for history
|
443 |
global $DB; |
444 |
$query ="SELECT * FROM glpi_computer_device WHERE ID = '".$compDevID."'"; |
445 |
if ($result = $DB->query($query)) { |
446 |
$data = $DB->fetch_array($result); |
447 |
} |
448 |
|
449 |
cleanAllItemCache("device_".$data["FK_computers"],"GLPI_".COMPUTER_TYPE); |
450 |
|
451 |
$query2 = "DELETE FROM glpi_computer_device where ID = '".$compDevID."'"; |
452 |
if($DB->query($query2)){ |
453 |
|
454 |
if ($dohistory){ |
455 |
$device = new Device($data["device_type"]); |
456 |
if ($device->getFromDB($data["FK_device"])){ |
457 |
$changes[0]='0'; |
458 |
$changes[1]=addslashes($device->fields["designation"]); |
459 |
$changes[2]=""; |
460 |
// history log
|
461 |
historyLog ($data["FK_computers"],COMPUTER_TYPE,$changes,$data["device_type"],HISTORY_DELETE_DEVICE); |
462 |
} |
463 |
} |
464 |
|
465 |
return true; |
466 |
}else{ return false;} |
467 |
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* Link the device to the computer
|
472 |
*
|
473 |
* @param $cID Computer ID
|
474 |
* @param $device_type device type
|
475 |
* @param $dID device ID
|
476 |
* @param $specificity specificity value
|
477 |
* @param $dohistory do history log
|
478 |
* @returns new computer device ID
|
479 |
**/
|
480 |
function compdevice_add($cID,$device_type,$dID,$specificity='',$dohistory=1) { |
481 |
$device = new Device($device_type); |
482 |
$device->getFromDB($dID); |
483 |
if (empty($specificity)) $specificity=$device->fields['specif_default']; |
484 |
$newID=$device->computer_link($cID,$device_type,$specificity); |
485 |
cleanAllItemCache("device_".$cID,"GLPI_".COMPUTER_TYPE); |
486 |
if ($dohistory){ |
487 |
$changes[0]='0'; |
488 |
$changes[1]=""; |
489 |
$changes[2]=addslashes($device->fields["designation"]); |
490 |
// history log
|
491 |
historyLog ($cID,COMPUTER_TYPE,$changes,$device_type,HISTORY_ADD_DEVICE); |
492 |
} |
493 |
return $newID; |
494 |
} |
495 |
|
496 |
/**
|
497 |
* Show Device list of a defined type
|
498 |
*
|
499 |
* @param $device_type device type
|
500 |
* @param $target wher to go on action
|
501 |
**/
|
502 |
function showDevicesList($device_type,$target) { |
503 |
|
504 |
// Lists Device from a device_type
|
505 |
|
506 |
global $DB,$CFG_GLPI, $LANG; |
507 |
|
508 |
|
509 |
$query = "select device.ID, device.designation, glpi_dropdown_manufacturer.name as manufacturer FROM ".getDeviceTable($device_type)." as device "; |
510 |
$query.= " LEFT JOIN glpi_dropdown_manufacturer ON (glpi_dropdown_manufacturer.ID = device.FK_glpi_enterprise ) "; |
511 |
$query .= " ORDER by device.designation ASC"; |
512 |
|
513 |
// Get it from database
|
514 |
if ($result = $DB->query($query)) { |
515 |
$numrows = $DB->numrows($result); |
516 |
$numrows_limit = $numrows; |
517 |
$result_limit = $result; |
518 |
if ($numrows_limit>0) { |
519 |
// Produce headline
|
520 |
echo "<div class='center'><table class='tab_cadre'><tr>"; |
521 |
|
522 |
// designation
|
523 |
echo "<th>"; |
524 |
echo $LANG["common"][16]."</th>"; |
525 |
|
526 |
// Manufacturer
|
527 |
echo "<th>"; |
528 |
echo $LANG["common"][5]."</th>"; |
529 |
|
530 |
echo "</tr>"; |
531 |
|
532 |
while ($data=$DB->fetch_array($result)) { |
533 |
$ID = $data["ID"]; |
534 |
echo "<tr class='tab_bg_2'>"; |
535 |
echo "<td><strong>"; |
536 |
echo "<a href=\"".$CFG_GLPI["root_doc"]."/front/device.form.php?ID=$ID&device_type=$device_type\">"; |
537 |
echo $data["designation"]; |
538 |
if ($CFG_GLPI["view_ID"]) echo " (".$data["ID"].")"; |
539 |
echo "</a></strong></td>"; |
540 |
echo "<td>". $data["manufacturer"]."</td>"; |
541 |
echo "</tr>"; |
542 |
} |
543 |
|
544 |
// Close Table
|
545 |
echo "</table></div>"; |
546 |
} else {
|
547 |
echo "<div class='center'><strong>".$LANG["devices"][18]."</strong></div>"; |
548 |
} |
549 |
} |
550 |
} |
551 |
|
552 |
/**
|
553 |
* title for Devices
|
554 |
*
|
555 |
* @param $device_type device type
|
556 |
**/
|
557 |
function titleDevices($device_type){ |
558 |
global $LANG,$CFG_GLPI; |
559 |
|
560 |
displayTitle($CFG_GLPI["root_doc"]."/pics/periph.png",$LANG["devices"][12],"",array("device.form.php?device_type=$device_type"=>$LANG["devices"][12])); |
561 |
|
562 |
} |
563 |
|
564 |
|
565 |
/**
|
566 |
* Show Device Form
|
567 |
*
|
568 |
* @param $device_type device type
|
569 |
* @param $ID device ID
|
570 |
* @param $target where to go on action
|
571 |
**/
|
572 |
function showDevicesForm ($target,$ID,$device_type) { |
573 |
|
574 |
global $CFG_GLPI,$LANG,$REFERER; |
575 |
|
576 |
$device = new Device($device_type); |
577 |
|
578 |
$device_spotted = false; |
579 |
|
580 |
if(empty($ID)) { |
581 |
if($device->getEmpty()) $device_spotted = true; |
582 |
} else {
|
583 |
if($device->getFromDB($ID)) $device_spotted = true; |
584 |
} |
585 |
|
586 |
if ($device_spotted){ |
587 |
|
588 |
$table=getDeviceTable($device_type); |
589 |
|
590 |
echo "<div class='center'>"; |
591 |
echo "<a href='$REFERER'>".$LANG["buttons"][13]."</a>"; |
592 |
|
593 |
$device->showOnglets($ID, "",$_SESSION['glpi_onglet'],"","designation","&device_type=$device_type&referer=$REFERER"); |
594 |
echo "<form method='post' name='form' action=\"$target\">"; |
595 |
echo "<input type='hidden' name='referer' value='$REFERER'>"; |
596 |
echo "<table class='tab_cadre_fixe' cellpadding='2'>"; |
597 |
echo "<tr><th align='center' colspan='1'>"; |
598 |
echo getDictDeviceLabel($device_type)."</th><th align='center' colspan='1'> ID : ".$ID; |
599 |
echo "<tr><td class='tab_bg_1' colspan='1'>"; |
600 |
// table commune
|
601 |
echo "<table cellpadding='1' cellspacing='0' border='0'>\n"; |
602 |
echo "<tr><td>".$LANG["common"][16].": </td>"; |
603 |
echo "<td>"; |
604 |
autocompletionTextField("designation",$table,"designation",$device->fields["designation"],50); |
605 |
|
606 |
echo "</td></tr>"; |
607 |
echo "<tr class='tab_bg_1'><td>".$LANG["common"][5].": </td><td colspan='2'>"; |
608 |
dropdownValue("glpi_dropdown_manufacturer","FK_glpi_enterprise",$device->fields["FK_glpi_enterprise"]); |
609 |
echo "</td></tr>"; |
610 |
if (getDeviceSpecifityLabel($device_type)!=""){ |
611 |
echo "<tr><td>".getDeviceSpecifityLabel($device_type)." ".$LANG["devices"][24]."</td>"; |
612 |
echo "<td><input type='text' name='specif_default' value=\"".$device->fields["specif_default"]."\" size='20'></td>"; |
613 |
echo "</tr>"; |
614 |
} |
615 |
echo "</table>"; |
616 |
// fin table Commune
|
617 |
echo "</td>\n"; |
618 |
echo "<td class='tab_bg_1' valign='top'>"; |
619 |
|
620 |
// table particuliere
|
621 |
echo "<table cellpadding='1' cellspacing='0' border='0'>"; |
622 |
switch($table) { |
623 |
case "glpi_device_moboard" : |
624 |
echo "<tr><td>".$LANG["device_moboard"][0].":</td>"; |
625 |
echo "<td>"; |
626 |
autocompletionTextField("chipset",$table,"chipset",$device->fields["chipset"],20); |
627 |
|
628 |
echo "</td></tr>"; |
629 |
break;
|
630 |
case "glpi_device_processor" : |
631 |
echo "<tr><td>".$LANG["device_ram"][1].":</td><td>"; |
632 |
autocompletionTextField("frequence",$table,"frequence",$device->fields["frequence"],20); |
633 |
echo "</td></tr>"; |
634 |
break;
|
635 |
case "glpi_device_ram" : |
636 |
echo "<tr><td>".$LANG["common"][17].":</td>"; |
637 |
echo "<td>"; |
638 |
dropdownValue("glpi_dropdown_ram_type","type",$device->fields["type"]); |
639 |
echo "</td>"; |
640 |
echo "</tr>"; |
641 |
echo "<tr><td>".$LANG["device_ram"][1].":</td><td>"; |
642 |
autocompletionTextField("frequence",$table,"frequence",$device->fields["frequence"],20); |
643 |
echo "</td></tr>"; |
644 |
break;
|
645 |
case "glpi_device_hdd" : |
646 |
echo "<tr><td>".$LANG["device_hdd"][0].":</td><td>"; |
647 |
autocompletionTextField("rpm",$table,"rpm",$device->fields["rpm"],20); |
648 |
|
649 |
echo "</td></tr>"; |
650 |
echo "<tr><td>".$LANG["device_hdd"][1].":</td><td>"; |
651 |
autocompletionTextField("cache",$table,"cache",$device->fields["cache"],20); |
652 |
echo "</td></tr>"; |
653 |
|
654 |
|
655 |
echo "<tr><td>".$LANG["common"][65].":</td>"; |
656 |
echo "<td>"; |
657 |
dropdownValue("glpi_dropdown_interface","interface",$device->fields["interface"]); |
658 |
echo "</td>"; |
659 |
|
660 |
echo "</tr>"; |
661 |
break;
|
662 |
case "glpi_device_iface" : |
663 |
echo "<tr><td>".$LANG["device_iface"][0].":</td><td>"; |
664 |
autocompletionTextField("bandwidth",$table,"bandwidth",$device->fields["bandwidth"],20); |
665 |
echo "</td></tr>"; |
666 |
break;
|
667 |
case "glpi_device_drive" : |
668 |
echo "</tr>"; |
669 |
echo "<tr><td>".$LANG["device_drive"][0].":</td>"; |
670 |
echo "<td>"; |
671 |
dropdownYesNo("is_writer",$device->fields["is_writer"]); |
672 |
echo "</td>"; |
673 |
echo "</tr>"; |
674 |
echo "<tr><td>".$LANG["common"][65].":</td>"; |
675 |
echo "<td>"; |
676 |
|
677 |
dropdownValue("glpi_dropdown_interface","interface",$device->fields["interface"]); |
678 |
|
679 |
echo "</td>"; |
680 |
echo "</tr>"; |
681 |
echo "<tr><td>".$LANG["device_drive"][1].":</td><td>"; |
682 |
autocompletionTextField("speed",$table,"speed",$device->fields["speed"],20); |
683 |
echo "</td></tr>"; |
684 |
|
685 |
|
686 |
break;
|
687 |
case "glpi_device_control" : |
688 |
echo "</tr>"; |
689 |
echo "<tr><td>".$LANG["device_control"][0].":</td>"; |
690 |
echo "<td>"; |
691 |
dropdownYesNo("raid",$device->fields["raid"]); |
692 |
echo "</td>"; |
693 |
echo "</tr>"; |
694 |
echo "<tr><td>".$LANG["common"][65].":</td>"; |
695 |
echo "<td>"; |
696 |
dropdownValue("glpi_dropdown_interface","interface",$device->fields["interface"]); |
697 |
echo "</td>"; |
698 |
echo "</tr>"; |
699 |
|
700 |
break;
|
701 |
case "glpi_device_gfxcard" : |
702 |
echo "<tr><td>".$LANG["device_gfxcard"][0].":</td><td>"; |
703 |
autocompletionTextField("specif_default",$table,"specif_default",$device->fields["specif_default"],20); |
704 |
echo "</td></tr>"; |
705 |
echo "<tr><td>".$LANG["common"][65].":</td>"; |
706 |
echo "<td><select name='interface'>"; |
707 |
echo "<option value='' ".($device->fields["interface"]==""?"selected":"")."> </option>"; |
708 |
echo "<option value='AGP' ".($device->fields["interface"]=="AGP"?"selected":"").">AGP</option>"; |
709 |
echo "<option value='PCI' ".($device->fields["interface"]=="PCI"?"selected":"").">PCI</option>"; |
710 |
echo "<option value='PCIe' ".($device->fields["interface"]=="PCIe"?"selected":"").">PCIe</option>"; |
711 |
echo "<option value='PCI-X' ".($device->fields["interface"]=="PCI-X"?"selected":"").">PCI-X</option>"; |
712 |
echo "<option value='Other' ".($device->fields["interface"]=="Other"?"selected":"").">Other</option>"; |
713 |
echo "</select>"; |
714 |
echo "</td>"; |
715 |
echo "</tr>"; |
716 |
break;
|
717 |
case "glpi_device_sndcard" : |
718 |
echo "<tr><td>".$LANG["common"][17].":</td><td>"; |
719 |
autocompletionTextField("type",$table,"type",$device->fields["type"],20); |
720 |
echo "</td></tr>"; |
721 |
break;
|
722 |
case "glpi_device_pci" : |
723 |
break;
|
724 |
case "glpi_device_case" : |
725 |
echo "<tr><td>".$LANG["device_case"][0].":</td>"; |
726 |
echo "<td>"; |
727 |
dropdownValue("glpi_dropdown_case_type","type",$device->fields["type"]); |
728 |
echo "</td>"; |
729 |
echo "</tr>"; |
730 |
|
731 |
break;
|
732 |
case "glpi_device_power" : |
733 |
echo "<tr><td>".$LANG["device_power"][0].":</td><td>"; |
734 |
autocompletionTextField("power",$table,"power",$device->fields["power"],20); |
735 |
echo "</td></tr>"; |
736 |
echo "<tr><td>".$LANG["device_power"][1].":</td>"; |
737 |
echo "<td>"; |
738 |
dropdownYesNo("atx",$device->fields["atx"]); |
739 |
echo "</td>"; |
740 |
echo "</tr>"; |
741 |
|
742 |
break;
|
743 |
|
744 |
} |
745 |
echo "</table>"; |
746 |
echo "</td>\n"; |
747 |
echo "</tr>"; |
748 |
|
749 |
echo "<tr>"; |
750 |
echo "<td class='tab_bg_1' valign='top' colspan='2'>"; |
751 |
|
752 |
// table commentaires
|
753 |
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td valign='top'>"; |
754 |
echo $LANG["common"][25].": </td>"; |
755 |
echo "<td class='center'><textarea cols='35' rows='4' name='comment' >".$device->fields["comment"]."</textarea>"; |
756 |
echo "</td></tr></table>"; |
757 |
|
758 |
echo "</td>"; |
759 |
echo "</tr>"; |
760 |
echo "<tr>"; |
761 |
if(!empty($ID)) { |
762 |
echo "<td class='tab_bg_2' valign='top' align='center'>"; |
763 |
echo "<input type='hidden' name='ID' value=\"$ID\">\n"; |
764 |
echo "<input type='hidden' name='device_type' value=\"$device_type\">\n"; |
765 |
echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>"; |
766 |
echo "</td>"; |
767 |
echo "<td class='tab_bg_2' valign='top' align='center'>\n"; |
768 |
echo "<div class='center'>"; |
769 |
echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>"; |
770 |
echo "</div>"; |
771 |
echo "</td>"; |
772 |
echo "</tr>"; |
773 |
} |
774 |
else {
|
775 |
echo "<td class='tab_bg_2' valign='top' align='center' colspan='2'>"; |
776 |
echo "<input type='hidden' name='device_type' value=\"$device_type\">\n"; |
777 |
echo "<input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'>"; |
778 |
echo "</td>"; |
779 |
} |
780 |
echo "</table></form></div>"; |
781 |
} else {
|
782 |
echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>"; |
783 |
return false; |
784 |
} |
785 |
} |
786 |
|
787 |
?>
|