ryxeo-glpi-git / inc / peripheral.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (13,6 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: peripheral.class.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 |
// ----------------------------------------------------------------------
|
32 |
// Original Author of file:
|
33 |
// Purpose of file:
|
34 |
// ----------------------------------------------------------------------
|
35 |
|
36 |
if (!defined('GLPI_ROOT')){ |
37 |
die("Sorry. You can't access directly to this file"); |
38 |
} |
39 |
|
40 |
// CLASSES peripherals
|
41 |
|
42 |
|
43 |
class Peripheral extends CommonDBTM { |
44 |
|
45 |
/**
|
46 |
* Constructor
|
47 |
**/
|
48 |
function Peripheral () { |
49 |
$this->table="glpi_peripherals"; |
50 |
$this->type=PERIPHERAL_TYPE; |
51 |
$this->dohistory=true; |
52 |
} |
53 |
|
54 |
function defineOnglets($withtemplate){ |
55 |
global $LANG; |
56 |
$ong=array(); |
57 |
if (haveRight("computer","r")){ |
58 |
$ong[1]=$LANG["title"][26]; |
59 |
} |
60 |
if (haveRight("contract_infocom","r")){ |
61 |
$ong[4]=$LANG["Menu"][26]; |
62 |
} |
63 |
if (haveRight("document","r")){ |
64 |
$ong[5]=$LANG["Menu"][27]; |
65 |
} |
66 |
|
67 |
if(empty($withtemplate)){ |
68 |
if (haveRight("show_all_ticket","1")){ |
69 |
$ong[6]=$LANG["title"][28]; |
70 |
} |
71 |
if (haveRight("link","r")){ |
72 |
$ong[7]=$LANG["title"][34]; |
73 |
} |
74 |
if (haveRight("notes","r")){ |
75 |
$ong[10]=$LANG["title"][37]; |
76 |
} |
77 |
if (haveRight("reservation_central","r")){ |
78 |
$ong[11]=$LANG["Menu"][17]; |
79 |
} |
80 |
|
81 |
$ong[12]=$LANG["title"][38]; |
82 |
} |
83 |
return $ong; |
84 |
} |
85 |
|
86 |
function prepareInputForAdd($input) { |
87 |
|
88 |
if (isset($input["ID"])&&$input["ID"]>0){ |
89 |
$input["_oldID"]=$input["ID"]; |
90 |
} |
91 |
unset($input['ID']); |
92 |
unset($input['withtemplate']); |
93 |
|
94 |
return $input; |
95 |
} |
96 |
|
97 |
function post_addItem($newID,$input) { |
98 |
global $DB; |
99 |
|
100 |
// Manage add from template
|
101 |
if (isset($input["_oldID"])){ |
102 |
// ADD Infocoms
|
103 |
$ic= new Infocom(); |
104 |
if ($ic->getFromDBforDevice(PERIPHERAL_TYPE,$input["_oldID"])){ |
105 |
$ic->fields["FK_device"]=$newID; |
106 |
unset ($ic->fields["ID"]); |
107 |
if (isset($ic->fields["num_immo"])) { |
108 |
$ic->fields["num_immo"] = autoName($ic->fields["num_immo"], "num_immo", 1, INFOCOM_TYPE,$input['FK_entities']); |
109 |
} |
110 |
|
111 |
$ic->addToDB();
|
112 |
} |
113 |
|
114 |
// ADD Ports
|
115 |
$query="SELECT ID from glpi_networking_ports WHERE on_device='".$input["_oldID"]."' AND device_type='".PERIPHERAL_TYPE."';"; |
116 |
$result=$DB->query($query); |
117 |
if ($DB->numrows($result)>0){ |
118 |
|
119 |
while ($data=$DB->fetch_array($result)){ |
120 |
$np= new Netport(); |
121 |
$np->getFromDB($data["ID"]); |
122 |
unset($np->fields["ID"]); |
123 |
unset($np->fields["ifaddr"]); |
124 |
unset($np->fields["ifmac"]); |
125 |
unset($np->fields["netpoint"]); |
126 |
$np->fields["on_device"]=$newID; |
127 |
$np->addToDB();
|
128 |
} |
129 |
} |
130 |
|
131 |
// ADD Contract
|
132 |
$query="SELECT FK_contract from glpi_contract_device WHERE FK_device='".$input["_oldID"]."' AND device_type='".PERIPHERAL_TYPE."';"; |
133 |
$result=$DB->query($query); |
134 |
if ($DB->numrows($result)>0){ |
135 |
|
136 |
while ($data=$DB->fetch_array($result)) |
137 |
addDeviceContract($data["FK_contract"],PERIPHERAL_TYPE,$newID); |
138 |
} |
139 |
|
140 |
// ADD Documents
|
141 |
$query="SELECT FK_doc from glpi_doc_device WHERE FK_device='".$input["_oldID"]."' AND device_type='".PERIPHERAL_TYPE."';"; |
142 |
$result=$DB->query($query); |
143 |
if ($DB->numrows($result)>0){ |
144 |
|
145 |
while ($data=$DB->fetch_array($result)) |
146 |
addDeviceDocument($data["FK_doc"],PERIPHERAL_TYPE,$newID); |
147 |
} |
148 |
} |
149 |
|
150 |
} |
151 |
|
152 |
function cleanDBonPurge($ID) { |
153 |
global $DB,$CFG_GLPI; |
154 |
|
155 |
$job =new Job(); |
156 |
$query = "SELECT * FROM glpi_tracking WHERE (computer = '$ID' AND device_type='".PERIPHERAL_TYPE."')"; |
157 |
$result = $DB->query($query); |
158 |
|
159 |
if ($DB->numrows($result)) |
160 |
while ($data=$DB->fetch_array($result)) { |
161 |
if ($CFG_GLPI["keep_tracking_on_delete"]==1){ |
162 |
$query = "UPDATE glpi_tracking SET computer = '0', device_type='0' WHERE ID='".$data["ID"]."';"; |
163 |
$DB->query($query); |
164 |
} else $job->delete(array("ID"=>$data["ID"])); |
165 |
} |
166 |
|
167 |
$query="select * from glpi_reservation_item where (device_type='".PERIPHERAL_TYPE."' and id_device='$ID')"; |
168 |
if ($result = $DB->query($query)) { |
169 |
if ($DB->numrows($result)>0){ |
170 |
$rr=new ReservationItem(); |
171 |
$rr->delete(array("ID"=>$DB->result($result,0,"ID"))); |
172 |
} |
173 |
} |
174 |
|
175 |
$query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='".PERIPHERAL_TYPE."')"; |
176 |
$result = $DB->query($query); |
177 |
|
178 |
$query="SELECT * FROM glpi_connect_wire WHERE (type='".PERIPHERAL_TYPE."' AND end1='$ID')"; |
179 |
if ($result = $DB->query($query)) { |
180 |
if ($DB->numrows($result)>0) { |
181 |
while ($data = $DB->fetch_array($result)){ |
182 |
// Disconnect without auto actions
|
183 |
Disconnect($data["ID"],1,false); |
184 |
} |
185 |
} |
186 |
} |
187 |
|
188 |
$query = "DELETE FROM glpi_contract_device WHERE (FK_device = '$ID' AND device_type='".PERIPHERAL_TYPE."')"; |
189 |
$result = $DB->query($query); |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Print the peripheral form
|
194 |
*
|
195 |
*@param $target filename : where to go when done.
|
196 |
*@param $ID Integer : Id of the item to print
|
197 |
*@param $withtemplate integer template or basic item
|
198 |
*
|
199 |
*@return boolean item found
|
200 |
**/
|
201 |
function showForm ($target,$ID,$withtemplate='') { |
202 |
|
203 |
global $CFG_GLPI, $LANG; |
204 |
|
205 |
if (!haveRight("peripheral","r")) return false; |
206 |
|
207 |
|
208 |
|
209 |
$mon_spotted = false; |
210 |
$use_cache=true; |
211 |
if((empty($ID) && $withtemplate == 1)||$ID==-1) { |
212 |
$use_cache=false; |
213 |
if($this->getEmpty()) $mon_spotted = true; |
214 |
} else {
|
215 |
if($this->getFromDB($ID)&&haveAccessToEntity($this->fields["FK_entities"])) $mon_spotted = true; |
216 |
} |
217 |
|
218 |
if($mon_spotted) { |
219 |
$this->showOnglets($ID, $withtemplate,$_SESSION['glpi_onglet']); |
220 |
if(!empty($withtemplate) && $withtemplate == 2) { |
221 |
$use_cache=false; |
222 |
$template = "newcomp"; |
223 |
$datestring = $LANG["computers"][14].": "; |
224 |
$date = convDateTime($_SESSION["glpi_currenttime"]); |
225 |
} elseif(!empty($withtemplate) && $withtemplate == 1) { |
226 |
$use_cache=false; |
227 |
$template = "newtemplate"; |
228 |
$datestring = $LANG["computers"][14].": "; |
229 |
$date = convDateTime($_SESSION["glpi_currenttime"]); |
230 |
} else {
|
231 |
$datestring = $LANG["common"][26].": "; |
232 |
$date = convDateTime($this->fields["date_mod"]); |
233 |
$template = false; |
234 |
} |
235 |
|
236 |
|
237 |
echo "<div class='center'>"; |
238 |
echo "<form method='post' name=form action=\"$target\">"; |
239 |
if(strcmp($template,"newtemplate") === 0) { |
240 |
echo "<input type=\"hidden\" name=\"is_template\" value=\"1\" />"; |
241 |
} |
242 |
|
243 |
echo "<input type='hidden' name='FK_entities' value='".$this->fields["FK_entities"]."'>"; |
244 |
|
245 |
echo "<table class='tab_cadre_fixe' cellpadding='2'>"; |
246 |
|
247 |
echo "<tr><th align='center' >"; |
248 |
|
249 |
|
250 |
|
251 |
if(!$template) { |
252 |
echo $LANG["common"][2]." ".$this->fields["ID"]; |
253 |
}elseif (strcmp($template,"newcomp") === 0) { |
254 |
echo $LANG["peripherals"][30].": ".$this->fields["tplname"]; |
255 |
echo "<input type='hidden' name='tplname' value='".$this->fields["tplname"]."'>"; |
256 |
}elseif (strcmp($template,"newtemplate") === 0) { |
257 |
echo $LANG["common"][6]." : "; |
258 |
autocompletionTextField("tplname","glpi_peripherals","tplname",$this->fields["tplname"],20,$this->fields["FK_entities"]); |
259 |
} |
260 |
if (isMultiEntitiesMode()){
|
261 |
echo " (".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")"; |
262 |
} |
263 |
|
264 |
echo "</th><th align='center'>".$datestring.$date; |
265 |
if (!$template&&!empty($this->fields['tplname'])) |
266 |
echo " (".$LANG["common"][13].": ".$this->fields['tplname'].")"; |
267 |
echo "</th></tr>"; |
268 |
|
269 |
if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) { |
270 |
echo "<tr><td class='tab_bg_1' valign='top'>"; |
271 |
|
272 |
echo "<table cellpadding='1' cellspacing='0' border='0'>\n"; |
273 |
|
274 |
echo "<tr><td>".$LANG["common"][16].($template?"*":"").": </td>"; |
275 |
echo "<td>"; |
276 |
$objectName = autoName($this->fields["name"], "name", ($template === "newcomp"), PERIPHERAL_TYPE,$this->fields["FK_entities"]); |
277 |
autocompletionTextField("name","glpi_peripherals","name",$objectName,20,$this->fields["FK_entities"]); |
278 |
echo "</td></tr>"; |
279 |
|
280 |
echo "<tr><td>".$LANG["common"][15].": </td><td>"; |
281 |
dropdownValue("glpi_dropdown_locations", "location", $this->fields["location"],1,$this->fields["FK_entities"]); |
282 |
echo "</td></tr>"; |
283 |
|
284 |
echo "<tr class='tab_bg_1'><td>".$LANG["common"][10].": </td><td colspan='2'>"; |
285 |
dropdownUsersID("tech_num", $this->fields["tech_num"],"interface",1,$this->fields["FK_entities"]); |
286 |
echo "</td></tr>"; |
287 |
|
288 |
echo "<tr><td>".$LANG["common"][21].": </td><td>"; |
289 |
autocompletionTextField("contact_num","glpi_peripherals","contact_num",$this->fields["contact_num"],20,$this->fields["FK_entities"]); |
290 |
echo "</td></tr>"; |
291 |
|
292 |
echo "<tr><td>".$LANG["common"][18].": </td><td>"; |
293 |
autocompletionTextField("contact","glpi_peripherals","contact",$this->fields["contact"],20,$this->fields["FK_entities"]); |
294 |
echo "</td></tr>"; |
295 |
|
296 |
echo "<tr><td>".$LANG["common"][34].": </td><td>"; |
297 |
dropdownAllUsers("FK_users", $this->fields["FK_users"],1,$this->fields["FK_entities"]); |
298 |
echo "</td></tr>"; |
299 |
|
300 |
echo "<tr><td>".$LANG["common"][35].": </td><td>"; |
301 |
dropdownValue("glpi_groups", "FK_groups", $this->fields["FK_groups"],1,$this->fields["FK_entities"]); |
302 |
echo "</td></tr>"; |
303 |
|
304 |
|
305 |
|
306 |
echo "</table>"; |
307 |
|
308 |
echo "</td>\n"; |
309 |
echo "<td class='tab_bg_1' valign='top'>"; |
310 |
|
311 |
echo "<table cellpadding='1' cellspacing='0' border='0'>"; |
312 |
|
313 |
echo "<tr><td>".$LANG["peripherals"][33].":</td><td>"; |
314 |
globalManagementDropdown($target,$withtemplate,$this->fields["ID"],$this->fields["is_global"],$CFG_GLPI["peripherals_management_restrict"]); |
315 |
echo "</td></tr>"; |
316 |
|
317 |
echo "<tr><td>".$LANG["common"][17].": </td><td>"; |
318 |
dropdownValue("glpi_type_peripherals", "type", $this->fields["type"]); |
319 |
echo "</td></tr>"; |
320 |
|
321 |
echo "<tr><td>".$LANG["common"][22].": </td><td>"; |
322 |
dropdownValue("glpi_dropdown_model_peripherals", "model", $this->fields["model"]); |
323 |
echo "</td></tr>"; |
324 |
|
325 |
echo "<tr class='tab_bg_1'><td>".$LANG["common"][5].": </td><td colspan='2'>"; |
326 |
dropdownValue("glpi_dropdown_manufacturer","FK_glpi_enterprise",$this->fields["FK_glpi_enterprise"]); |
327 |
echo "</td></tr>"; |
328 |
|
329 |
echo "<tr><td>".$LANG["peripherals"][18].":</td><td>"; |
330 |
autocompletionTextField("brand","glpi_peripherals","brand",$this->fields["brand"],20,$this->fields["FK_entities"]); |
331 |
echo "</td></tr>"; |
332 |
|
333 |
|
334 |
echo "<tr><td>".$LANG["common"][19].": </td><td>"; |
335 |
autocompletionTextField("serial","glpi_peripherals","serial",$this->fields["serial"],20,$this->fields["FK_entities"]); |
336 |
echo "</td></tr>"; |
337 |
|
338 |
echo "<tr><td>".$LANG["common"][20].($template?"*":"").":</td><td>"; |
339 |
$objectName = autoName($this->fields["otherserial"], "otherserial", ($template === "newcomp"), PERIPHERAL_TYPE,$this->fields["FK_entities"]); |
340 |
autocompletionTextField("otherserial","glpi_peripherals","otherserial",$objectName,20,$this->fields["FK_entities"]); |
341 |
|
342 |
echo "</td></tr>"; |
343 |
|
344 |
|
345 |
echo "<tr><td>".$LANG["state"][0].":</td><td>"; |
346 |
dropdownValue("glpi_dropdown_state", "state",$this->fields["state"]); |
347 |
echo "</td></tr>"; |
348 |
|
349 |
|
350 |
|
351 |
echo "</table>"; |
352 |
echo "</td>\n"; |
353 |
echo "</tr>"; |
354 |
echo "<tr>"; |
355 |
echo "<td class='tab_bg_1' valign='top' colspan='2'>"; |
356 |
|
357 |
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td valign='top'>"; |
358 |
echo $LANG["common"][25].": </td>"; |
359 |
echo "<td class='center'><textarea cols='35' rows='4' name='comments' >".$this->fields["comments"]."</textarea>"; |
360 |
echo "</td></tr></table>"; |
361 |
|
362 |
echo "</td>"; |
363 |
echo "</tr>"; |
364 |
if ($use_cache){ |
365 |
$CFG_GLPI["cache"]->end(); |
366 |
} |
367 |
} |
368 |
|
369 |
if (haveRight("peripheral","w")){ |
370 |
echo "<tr>"; |
371 |
|
372 |
if ($template) { |
373 |
|
374 |
if (empty($ID)||$withtemplate==2){ |
375 |
echo "<td class='tab_bg_2' align='center' colspan='2'>\n"; |
376 |
echo "<input type='hidden' name='ID' value=$ID>"; |
377 |
echo "<input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'>"; |
378 |
echo "</td>\n"; |
379 |
} else {
|
380 |
echo "<td class='tab_bg_2' align='center' colspan='2'>\n"; |
381 |
echo "<input type='hidden' name='ID' value=$ID>"; |
382 |
echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>"; |
383 |
echo "</td>\n"; |
384 |
} |
385 |
|
386 |
|
387 |
} else {
|
388 |
|
389 |
echo "<td class='tab_bg_2' valign='top' align='center'>"; |
390 |
echo "<input type='hidden' name='ID' value=\"$ID\">\n"; |
391 |
echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>"; |
392 |
echo "</td>"; |
393 |
echo "<td class='tab_bg_2' valign='top'>\n"; |
394 |
echo "<div class='center'>"; |
395 |
if (!$this->fields["deleted"]) |
396 |
echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>"; |
397 |
else {
|
398 |
echo "<input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>"; |
399 |
echo " <input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'>"; |
400 |
} |
401 |
echo "</div>"; |
402 |
echo "</td>"; |
403 |
} |
404 |
echo "</tr>"; |
405 |
} |
406 |
echo "</table></form></div>"; |
407 |
|
408 |
return true; |
409 |
} |
410 |
else {
|
411 |
echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>"; |
412 |
return false; |
413 |
} |
414 |
|
415 |
} |
416 |
|
417 |
|
418 |
|
419 |
} |
420 |
|
421 |
?>
|