ryxeo-glpi-git / inc / phone.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (14,5 ko)
1 | b67d8923 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: phone.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 Phone extends CommonDBTM { |
||
44 | |||
45 | /**
|
||
46 | * Constructor
|
||
47 | **/
|
||
48 | function Phone () { |
||
49 | $this->table="glpi_phones"; |
||
50 | $this->type=PHONE_TYPE; |
||
51 | $this->dohistory=true; |
||
52 | } |
||
53 | |||
54 | function defineOnglets($withtemplate){ |
||
55 | global $LANG,$CFG_GLPI; |
||
56 | $ong=array(); |
||
57 | |||
58 | $ong[1]=$LANG["title"][26]; |
||
59 | if (haveRight("contract_infocom","r")){ |
||
60 | $ong[4]=$LANG["Menu"][26]; |
||
61 | } |
||
62 | if (haveRight("document","r")){ |
||
63 | $ong[5]=$LANG["Menu"][27]; |
||
64 | } |
||
65 | |||
66 | if(empty($withtemplate)){ |
||
67 | if (haveRight("show_all_ticket","1")){ |
||
68 | $ong[6]=$LANG["title"][28]; |
||
69 | } |
||
70 | if (haveRight("link","r")){ |
||
71 | $ong[7]=$LANG["title"][34]; |
||
72 | } |
||
73 | if (haveRight("notes","r")){ |
||
74 | $ong[10]=$LANG["title"][37]; |
||
75 | } |
||
76 | if (haveRight("reservation_central","r")){ |
||
77 | $ong[11]=$LANG["Menu"][17]; |
||
78 | } |
||
79 | |||
80 | $ong[12]=$LANG["title"][38]; |
||
81 | } |
||
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(PHONE_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='".PHONE_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='".PHONE_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"],PHONE_TYPE,$newID); |
||
138 | } |
||
139 | |||
140 | // ADD Documents
|
||
141 | $query="SELECT FK_doc from glpi_doc_device WHERE FK_device='".$input["_oldID"]."' AND device_type='".PHONE_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"],PHONE_TYPE,$newID); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | } |
||
151 | |||
152 | |||
153 | |||
154 | function cleanDBonPurge($ID) { |
||
155 | |||
156 | global $DB,$CFG_GLPI; |
||
157 | |||
158 | |||
159 | $job =new Job(); |
||
160 | $query = "SELECT * FROM glpi_tracking WHERE (computer = '$ID' AND device_type='".PHONE_TYPE."')"; |
||
161 | $result = $DB->query($query); |
||
162 | |||
163 | if ($DB->numrows($result)) |
||
164 | while ($data=$DB->fetch_array($result)) { |
||
165 | if ($CFG_GLPI["keep_tracking_on_delete"]==1){ |
||
166 | $query = "UPDATE glpi_tracking SET computer = '0', device_type='0' WHERE ID='".$data["ID"]."';"; |
||
167 | $DB->query($query); |
||
168 | } else $job->delete(array("ID"=>$data["ID"])); |
||
169 | } |
||
170 | |||
171 | $query="select * from glpi_reservation_item where (device_type='".PHONE_TYPE."' and id_device='$ID')"; |
||
172 | if ($result = $DB->query($query)) { |
||
173 | if ($DB->numrows($result)>0){ |
||
174 | $rr=new ReservationItem(); |
||
175 | $rr->delete(array("ID"=>$DB->result($result,0,"ID"))); |
||
176 | } |
||
177 | } |
||
178 | |||
179 | $query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='".PHONE_TYPE."')"; |
||
180 | $result = $DB->query($query); |
||
181 | |||
182 | |||
183 | $query="SELECT * FROM glpi_connect_wire WHERE (type='".PHONE_TYPE."' AND end1='$ID')"; |
||
184 | if ($result = $DB->query($query)) { |
||
185 | if ($DB->numrows($result)>0) { |
||
186 | while ($data = $DB->fetch_array($result)){ |
||
187 | // Disconnect without auto actions
|
||
188 | Disconnect($data["ID"],1,false); |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | |||
193 | $query = "DELETE FROM glpi_contract_device WHERE (FK_device = '$ID' AND device_type='".PHONE_TYPE."')"; |
||
194 | $result = $DB->query($query); |
||
195 | } |
||
196 | |||
197 | /**
|
||
198 | * Print the phone form
|
||
199 | *
|
||
200 | *@param $target filename : where to go when done.
|
||
201 | *@param $ID Integer : Id of the item to print
|
||
202 | *@param $withtemplate integer template or basic item
|
||
203 | *
|
||
204 | *@return boolean item found
|
||
205 | **/
|
||
206 | function showForm ($target,$ID,$withtemplate='') { |
||
207 | |||
208 | global $CFG_GLPI, $LANG; |
||
209 | |||
210 | if (!haveRight("phone","r")) return false; |
||
211 | |||
212 | |||
213 | |||
214 | $mon_spotted = false; |
||
215 | $use_cache=true; |
||
216 | if((empty($ID) && $withtemplate == 1)||$ID==-1) { |
||
217 | $use_cache=false; |
||
218 | if($this->getEmpty()) $mon_spotted = true; |
||
219 | } else {
|
||
220 | if($this->getFromDB($ID)&&haveAccessToEntity($this->fields["FK_entities"])) $mon_spotted = true; |
||
221 | } |
||
222 | |||
223 | if($mon_spotted) { |
||
224 | $this->showOnglets($ID, $withtemplate,$_SESSION['glpi_onglet']); |
||
225 | |||
226 | if(!empty($withtemplate) && $withtemplate == 2) { |
||
227 | $use_cache=false; |
||
228 | $template = "newcomp"; |
||
229 | $datestring = $LANG["computers"][14].": "; |
||
230 | $date = convDateTime($_SESSION["glpi_currenttime"]); |
||
231 | } elseif(!empty($withtemplate) && $withtemplate == 1) { |
||
232 | $use_cache=false; |
||
233 | $template = "newtemplate"; |
||
234 | $datestring = $LANG["computers"][14].": "; |
||
235 | $date = convDateTime($_SESSION["glpi_currenttime"]); |
||
236 | } else {
|
||
237 | $datestring = $LANG["common"][26].": "; |
||
238 | $date = convDateTime($this->fields["date_mod"]); |
||
239 | $template = false; |
||
240 | } |
||
241 | |||
242 | |||
243 | echo "<div class='center'>"; |
||
244 | echo "<form method='post' name=form action=\"$target\">"; |
||
245 | if(strcmp($template,"newtemplate") === 0) { |
||
246 | echo "<input type=\"hidden\" name=\"is_template\" value=\"1\" />"; |
||
247 | } |
||
248 | |||
249 | echo "<input type='hidden' name='FK_entities' value='".$this->fields["FK_entities"]."'>"; |
||
250 | |||
251 | echo "<table width='950' class='tab_cadre' cellpadding='2'>"; |
||
252 | |||
253 | echo "<tr><th align='center' >"; |
||
254 | |||
255 | |||
256 | |||
257 | if(!$template) { |
||
258 | echo $LANG["common"][2]." ".$this->fields["ID"]; |
||
259 | }elseif (strcmp($template,"newcomp") === 0) { |
||
260 | echo $LANG["phones"][30].": ".$this->fields["tplname"]; |
||
261 | echo "<input type='hidden' name='tplname' value='".$this->fields["tplname"]."'>"; |
||
262 | }elseif (strcmp($template,"newtemplate") === 0) { |
||
263 | echo $LANG["common"][6]." : "; |
||
264 | autocompletionTextField("tplname","glpi_phones","tplname",$this->fields["tplname"],20,$this->fields["FK_entities"]); |
||
265 | } |
||
266 | if (isMultiEntitiesMode()){
|
||
267 | echo " (".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")"; |
||
268 | } |
||
269 | |||
270 | echo "</th><th align='center'>".$datestring.$date; |
||
271 | if (!$template&&!empty($this->fields['tplname'])) |
||
272 | echo " (".$LANG["common"][13].": ".$this->fields['tplname'].")"; |
||
273 | echo "</th></tr>"; |
||
274 | |||
275 | if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) { |
||
276 | echo "<tr><td class='tab_bg_1' valign='top'>"; |
||
277 | |||
278 | echo "<table cellpadding='1' cellspacing='0' border='0'>\n"; |
||
279 | |||
280 | echo "<tr><td>".$LANG["common"][16].($template?"*":"").": </td>"; |
||
281 | echo "<td>"; |
||
282 | $objectName = autoName($this->fields["name"], "name", ($template === "newcomp"), PHONE_TYPE,$this->fields["FK_entities"]); |
||
283 | autocompletionTextField("name","glpi_phones","name",$objectName,20,$this->fields["FK_entities"]); |
||
284 | echo "</td></tr>"; |
||
285 | |||
286 | echo "<tr><td>".$LANG["common"][15].": </td><td>"; |
||
287 | dropdownValue("glpi_dropdown_locations", "location", $this->fields["location"],1,$this->fields["FK_entities"]); |
||
288 | echo "</td></tr>"; |
||
289 | |||
290 | echo "<tr class='tab_bg_1'><td>".$LANG["common"][10].": </td><td colspan='2'>"; |
||
291 | dropdownUsersID("tech_num", $this->fields["tech_num"],"interface",1,$this->fields["FK_entities"]); |
||
292 | echo "</td></tr>"; |
||
293 | |||
294 | echo "<tr><td>".$LANG["common"][21].": </td><td>"; |
||
295 | autocompletionTextField("contact_num","glpi_phones","contact_num",$this->fields["contact_num"],20,$this->fields["FK_entities"]); |
||
296 | echo "</td></tr>"; |
||
297 | |||
298 | echo "<tr><td>".$LANG["common"][18].": </td><td>"; |
||
299 | autocompletionTextField("contact","glpi_phones","contact",$this->fields["contact"],20,$this->fields["FK_entities"]); |
||
300 | echo "</td></tr>"; |
||
301 | |||
302 | echo "<tr><td>".$LANG["common"][34].": </td><td>"; |
||
303 | dropdownAllUsers("FK_users", $this->fields["FK_users"],1,$this->fields["FK_entities"]); |
||
304 | echo "</td></tr>"; |
||
305 | |||
306 | echo "<tr><td>".$LANG["common"][35].": </td><td>"; |
||
307 | dropdownValue("glpi_groups", "FK_groups", $this->fields["FK_groups"],1,$this->fields["FK_entities"]); |
||
308 | echo "</td></tr>"; |
||
309 | |||
310 | |||
311 | |||
312 | echo "<tr><td>".$LANG["common"][17].": </td><td>"; |
||
313 | dropdownValue("glpi_type_phones", "type", $this->fields["type"]); |
||
314 | echo "</td></tr>"; |
||
315 | |||
316 | echo "<tr><td>".$LANG["common"][22].": </td><td>"; |
||
317 | dropdownValue("glpi_dropdown_model_phones", "model", $this->fields["model"]); |
||
318 | echo "</td></tr>"; |
||
319 | |||
320 | echo "</table>"; |
||
321 | |||
322 | echo "</td>\n"; |
||
323 | echo "<td class='tab_bg_1' valign='top'>"; |
||
324 | |||
325 | echo "<table cellpadding='1' cellspacing='0' border='0'>"; |
||
326 | |||
327 | echo "<tr><td>".$LANG["peripherals"][33].":</td><td>"; |
||
328 | globalManagementDropdown($target,$withtemplate,$this->fields["ID"],$this->fields["is_global"],$CFG_GLPI["phones_management_restrict"]); |
||
329 | echo "</td></tr>"; |
||
330 | |||
331 | echo "<tr><td>".$LANG["phones"][36].":</td><td>"; |
||
332 | dropdownValue("glpi_dropdown_phone_power", "power", $this->fields["power"]); |
||
333 | echo "</td></tr>"; |
||
334 | |||
335 | |||
336 | echo "<tr class='tab_bg_1'><td>".$LANG["common"][5].": </td><td colspan='2'>"; |
||
337 | dropdownValue("glpi_dropdown_manufacturer","FK_glpi_enterprise",$this->fields["FK_glpi_enterprise"]); |
||
338 | echo "</td></tr>"; |
||
339 | |||
340 | echo "<tr><td>".$LANG["phones"][18].":</td><td>"; |
||
341 | autocompletionTextField("brand","glpi_phones","brand",$this->fields["brand"],20,$this->fields["FK_entities"]); |
||
342 | echo "</td></tr>"; |
||
343 | |||
344 | |||
345 | echo "<tr><td>".$LANG["common"][19].": </td><td>"; |
||
346 | autocompletionTextField("serial","glpi_phones","serial",$this->fields["serial"],20,$this->fields["FK_entities"]); |
||
347 | echo "</td></tr>"; |
||
348 | |||
349 | echo "<tr><td>".$LANG["common"][20].($template?"*":"").":</td><td>"; |
||
350 | $objectName = autoName($this->fields["otherserial"], "otherserial", ($template === "newcomp"), PHONE_TYPE,$this->fields["FK_entities"]); |
||
351 | autocompletionTextField("otherserial","glpi_phones","otherserial",$objectName,20,$this->fields["FK_entities"]); |
||
352 | echo "</td></tr>"; |
||
353 | |||
354 | |||
355 | echo "<tr><td>".$LANG["phones"][35].": </td><td>"; |
||
356 | autocompletionTextField("firmware","glpi_phones","firmware",$this->fields["firmware"],20,$this->fields["FK_entities"]); |
||
357 | echo "</td></tr>"; |
||
358 | |||
359 | |||
360 | echo "<tr><td>".$LANG["state"][0].":</td><td>"; |
||
361 | dropdownValue("glpi_dropdown_state", "state",$this->fields["state"]); |
||
362 | echo "</td></tr>"; |
||
363 | |||
364 | echo "<tr><td>".$LANG["phones"][40].": </td><td>"; |
||
365 | autocompletionTextField("number_line","glpi_phones","number_line",$this->fields["number_line"],20,$this->fields["FK_entities"]); |
||
366 | echo "</td></tr>"; |
||
367 | |||
368 | |||
369 | echo "<tr><td>".$LANG["monitors"][18].": </td><td>"; |
||
370 | |||
371 | // micro?
|
||
372 | echo "<table border='0' cellpadding='2' cellspacing='0'><tr>"; |
||
373 | echo "<td>".$LANG["phones"][38]."</td>"; |
||
374 | echo "<td>"; |
||
375 | dropdownYesNo("flags_casque",$this->fields["flags_casque"]); |
||
376 | echo "</td>"; |
||
377 | |||
378 | echo "</tr>"; |
||
379 | |||
380 | // hp?
|
||
381 | echo "<tr>"; |
||
382 | echo "<td>".$LANG["phones"][39]."</td>"; |
||
383 | echo "<td>"; |
||
384 | dropdownYesNo("flags_hp",$this->fields["flags_hp"]); |
||
385 | echo "</td>"; |
||
386 | |||
387 | echo "</tr></table>"; |
||
388 | echo "</td></tr>"; |
||
389 | echo "</table>"; |
||
390 | echo "</td>\n"; |
||
391 | echo "</tr>"; |
||
392 | echo "<tr>"; |
||
393 | echo "<td class='tab_bg_1' valign='top' colspan='2'>"; |
||
394 | |||
395 | echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td valign='top'>"; |
||
396 | echo $LANG["common"][25].": </td>"; |
||
397 | echo "<td class='center'><textarea cols='35' rows='4' name='comments' >".$this->fields["comments"]."</textarea>"; |
||
398 | echo "</td></tr></table>"; |
||
399 | |||
400 | echo "</td>"; |
||
401 | echo "</tr>"; |
||
402 | if ($use_cache){ |
||
403 | $CFG_GLPI["cache"]->end(); |
||
404 | } |
||
405 | } |
||
406 | |||
407 | |||
408 | if (haveRight("phone","w")){ |
||
409 | echo "<tr>"; |
||
410 | |||
411 | if ($template) { |
||
412 | |||
413 | if (empty($ID)||$withtemplate==2){ |
||
414 | echo "<td class='tab_bg_2' align='center' colspan='2'>\n"; |
||
415 | echo "<input type='hidden' name='ID' value=$ID>"; |
||
416 | echo "<input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'>"; |
||
417 | echo "</td>\n"; |
||
418 | } else {
|
||
419 | echo "<td class='tab_bg_2' align='center' colspan='2'>\n"; |
||
420 | echo "<input type='hidden' name='ID' value=$ID>"; |
||
421 | echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>"; |
||
422 | echo "</td>\n"; |
||
423 | } |
||
424 | } else {
|
||
425 | |||
426 | echo "<td class='tab_bg_2' valign='top' align='center'>"; |
||
427 | echo "<input type='hidden' name='ID' value=\"$ID\">\n"; |
||
428 | echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>"; |
||
429 | echo "</td>"; |
||
430 | echo "<td class='tab_bg_2' valign='top'>\n"; |
||
431 | echo "<div class='center'>"; |
||
432 | if (!$this->fields["deleted"]) |
||
433 | echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>"; |
||
434 | else {
|
||
435 | echo "<input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>"; |
||
436 | echo " <input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'>"; |
||
437 | } |
||
438 | echo "</div>"; |
||
439 | echo "</td>"; |
||
440 | } |
||
441 | echo "</tr>"; |
||
442 | } |
||
443 | echo "</table></form></div>"; |
||
444 | |||
445 | return true; |
||
446 | } |
||
447 | else {
|
||
448 | echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>"; |
||
449 | return false; |
||
450 | } |
||
451 | |||
452 | } |
||
453 | |||
454 | |||
455 | |||
456 | } |
||
457 | |||
458 | ?> |