ryxeo-glpi-git / inc / commonitem.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (13 ko)
1 | b67d8923 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: commonitem.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 | |||
41 | /**
|
||
42 | * Common Item of GLPI : Global simple interface to items - abstraction usage
|
||
43 | */
|
||
44 | class CommonItem{ |
||
45 | //! Object Type depending of the device_type
|
||
46 | var $obj = NULL; |
||
47 | //! Device Type ID of the object
|
||
48 | var $device_type=0; |
||
49 | //! Device ID of the object
|
||
50 | var $id_device=0; |
||
51 | |||
52 | |||
53 | /**
|
||
54 | * Get an Object / General Function
|
||
55 | *
|
||
56 | * Create a new Object depending of $device_type and Get the item with the ID $id_device
|
||
57 | *
|
||
58 | * @param $device_type Device Type ID of the object
|
||
59 | * @param $id_device Device ID of the object
|
||
60 | *
|
||
61 | * @return boolean : object founded and loaded
|
||
62 | */
|
||
63 | function getFromDB ($device_type,$id_device) { |
||
64 | |||
65 | $this->id_device=$id_device; |
||
66 | $this->setType($device_type,1); |
||
67 | |||
68 | if ($this->obj!=NULL){ |
||
69 | // Do not load devices
|
||
70 | return $this->obj->getFromDB($id_device); |
||
71 | } |
||
72 | else return false; |
||
73 | |||
74 | } |
||
75 | |||
76 | /**
|
||
77 | * Set the device type
|
||
78 | *
|
||
79 | * @param $device_type Device Type ID of the object
|
||
80 | * @param $init_object Create an instance of the object ?
|
||
81 | *
|
||
82 | */
|
||
83 | function setType ($device_type,$init_object=false){ |
||
84 | global $PLUGIN_HOOKS; |
||
85 | |||
86 | $this->device_type=$device_type; |
||
87 | // Make new database object and fill variables
|
||
88 | if ($init_object){ |
||
89 | switch ($device_type){ |
||
90 | case COMPUTER_TYPE : |
||
91 | $this->obj=new Computer; |
||
92 | break;
|
||
93 | case NETWORKING_TYPE : |
||
94 | $this->obj=new Netdevice; |
||
95 | break;
|
||
96 | case PRINTER_TYPE : |
||
97 | $this->obj=new Printer; |
||
98 | break;
|
||
99 | case MONITOR_TYPE : |
||
100 | $this->obj= new Monitor; |
||
101 | break;
|
||
102 | case PERIPHERAL_TYPE : |
||
103 | $this->obj= new Peripheral; |
||
104 | break;
|
||
105 | case SOFTWARE_TYPE : |
||
106 | $this->obj= new Software; |
||
107 | break;
|
||
108 | case CONTACT_TYPE : |
||
109 | $this->obj= new Contact; |
||
110 | break;
|
||
111 | case ENTERPRISE_TYPE : |
||
112 | $this->obj= new Enterprise; |
||
113 | break;
|
||
114 | case CONTRACT_TYPE : |
||
115 | $this->obj= new Contract; |
||
116 | break;
|
||
117 | case CARTRIDGE_TYPE : |
||
118 | $this->obj= new CartridgeType; |
||
119 | break;
|
||
120 | case TYPEDOC_TYPE : |
||
121 | $this->obj= new TypeDoc; |
||
122 | break;
|
||
123 | case DOCUMENT_TYPE : |
||
124 | $this->obj= new Document; |
||
125 | break;
|
||
126 | case KNOWBASE_TYPE : |
||
127 | $this->obj= new kbitem; |
||
128 | break;
|
||
129 | case USER_TYPE : |
||
130 | $this->obj= new User; |
||
131 | break;
|
||
132 | case TRACKING_TYPE : |
||
133 | $this->obj= new Job; |
||
134 | break;
|
||
135 | case CONSUMABLE_TYPE : |
||
136 | $this->obj= new ConsumableType; |
||
137 | break;
|
||
138 | case CARTRIDGE_ITEM_TYPE : |
||
139 | $this->obj= new Cartridge; |
||
140 | break;
|
||
141 | case CONSUMABLE_ITEM_TYPE : |
||
142 | $this->obj= new Consumable; |
||
143 | break;
|
||
144 | case LICENSE_TYPE : |
||
145 | $this->obj= new License; |
||
146 | break;
|
||
147 | case LINK_TYPE : |
||
148 | $this->obj= new Link; |
||
149 | break;
|
||
150 | case PHONE_TYPE : |
||
151 | $this->obj= new Phone; |
||
152 | break;
|
||
153 | case REMINDER_TYPE : |
||
154 | $this->obj= new Reminder; |
||
155 | break;
|
||
156 | case GROUP_TYPE : |
||
157 | $this->obj= new Group; |
||
158 | break;
|
||
159 | case ENTITY_TYPE : |
||
160 | $this->obj= new Entity; |
||
161 | break;
|
||
162 | case AUTH_MAIL_TYPE: |
||
163 | $this->obj = new AuthMail; |
||
164 | break;
|
||
165 | case AUTH_LDAP_TYPE: |
||
166 | $this->obj = new AuthLDAP; |
||
167 | break;
|
||
168 | case OCSNG_TYPE: |
||
169 | $this->obj = new Ocsng; |
||
170 | break;
|
||
171 | case REGISTRY_TYPE: |
||
172 | $this->obj = new Registry; |
||
173 | break;
|
||
174 | case PROFILE_TYPE: |
||
175 | $this->obj = new Profile; |
||
176 | break;
|
||
177 | case MAILGATE_TYPE: |
||
178 | $this->obj = new Mailgate; |
||
179 | break;
|
||
180 | case INFOCOM_TYPE: |
||
181 | $this->obj = new InfoCom; |
||
182 | break;
|
||
183 | case TRANSFER_TYPE: |
||
184 | $this->obj = new Transfer; |
||
185 | break;
|
||
186 | case BOOKMARK_TYPE: |
||
187 | $this->obj = new Bookmark; |
||
188 | break;
|
||
189 | default :
|
||
190 | // Plugin case
|
||
191 | if ($device_type>1000){ |
||
192 | if (isset($PLUGIN_HOOKS['plugin_classes'][$device_type])){ |
||
193 | $class=$PLUGIN_HOOKS['plugin_classes'][$device_type]; |
||
194 | if (class_exists($class)){ |
||
195 | $this->obj = new $class(); |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | break;
|
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | |||
204 | /**
|
||
205 | * Get The Type Name of the Object
|
||
206 | *
|
||
207 | * @return String: name of the object type in the current language
|
||
208 | */
|
||
209 | function getType (){ |
||
210 | global $LANG,$PLUGIN_HOOKS; |
||
211 | |||
212 | switch ($this->device_type){ |
||
213 | case GENERAL_TYPE : |
||
214 | return $LANG["help"][30]; |
||
215 | break;
|
||
216 | case COMPUTER_TYPE : |
||
217 | return $LANG["computers"][44]; |
||
218 | break;
|
||
219 | case NETWORKING_TYPE : |
||
220 | return $LANG["networking"][12]; |
||
221 | break;
|
||
222 | case PRINTER_TYPE : |
||
223 | return $LANG["help"][27]; |
||
224 | break;
|
||
225 | case MONITOR_TYPE : |
||
226 | return $LANG["help"][28]; |
||
227 | break;
|
||
228 | case PERIPHERAL_TYPE : |
||
229 | return $LANG["help"][29]; |
||
230 | break;
|
||
231 | case SOFTWARE_TYPE : |
||
232 | return $LANG["help"][31]; |
||
233 | break;
|
||
234 | case CONTACT_TYPE : |
||
235 | return $LANG["common"][18]; |
||
236 | break;
|
||
237 | case ENTERPRISE_TYPE : |
||
238 | return $LANG["financial"][26]; |
||
239 | break;
|
||
240 | case CONTRACT_TYPE : |
||
241 | return $LANG["financial"][1]; |
||
242 | break;
|
||
243 | case CARTRIDGE_TYPE : |
||
244 | return $LANG["cartridges"][12]; |
||
245 | break;
|
||
246 | case TYPEDOC_TYPE : |
||
247 | return $LANG["document"][7]; |
||
248 | break;
|
||
249 | case DOCUMENT_TYPE : |
||
250 | return $LANG["Menu"][27]; |
||
251 | break;
|
||
252 | case KNOWBASE_TYPE : |
||
253 | return $LANG["title"][5]; |
||
254 | break;
|
||
255 | case USER_TYPE : |
||
256 | return $LANG["common"][34]; |
||
257 | break;
|
||
258 | case TRACKING_TYPE : |
||
259 | return $LANG["job"][38]; |
||
260 | break;
|
||
261 | case CONSUMABLE_TYPE : |
||
262 | return $LANG["consumables"][12]; |
||
263 | break;
|
||
264 | case CARTRIDGE_ITEM_TYPE : |
||
265 | return $LANG["cartridges"][0]; |
||
266 | break;
|
||
267 | case CONSUMABLE_ITEM_TYPE : |
||
268 | return $LANG["consumables"][0]; |
||
269 | break;
|
||
270 | case LICENSE_TYPE : |
||
271 | return $LANG["software"][11]; |
||
272 | break;
|
||
273 | case LINK_TYPE : |
||
274 | return $LANG["setup"][87]; |
||
275 | break;
|
||
276 | case PHONE_TYPE : |
||
277 | return $LANG["help"][35]; |
||
278 | break;
|
||
279 | case REMINDER_TYPE : |
||
280 | return $LANG["title"][37]; |
||
281 | break;
|
||
282 | case GROUP_TYPE : |
||
283 | return $LANG["common"][35]; |
||
284 | break;
|
||
285 | case ENTITY_TYPE : |
||
286 | return $LANG["Menu"][37]; |
||
287 | break;
|
||
288 | case AUTH_MAIL_TYPE: |
||
289 | return $LANG["login"][3]; |
||
290 | break;
|
||
291 | case AUTH_LDAP_TYPE: |
||
292 | return $LANG["login"][2]; |
||
293 | break;
|
||
294 | case OCSNG_TYPE: |
||
295 | return $LANG["ocsng"][29]; |
||
296 | break;
|
||
297 | case REGISTRY_TYPE: |
||
298 | return $LANG["title"][43]; |
||
299 | break;
|
||
300 | case PROFILE_TYPE: |
||
301 | return $LANG["Menu"][35]; |
||
302 | break;
|
||
303 | case MAILGATE_TYPE: |
||
304 | return $LANG["Menu"][39]; |
||
305 | break;
|
||
306 | case INFOCOM_TYPE: |
||
307 | return $LANG["financial"][3]; |
||
308 | break;
|
||
309 | default :
|
||
310 | // Plugin case
|
||
311 | if ($this->device_type>1000){ |
||
312 | // Use plugin name if set
|
||
313 | if (isset($PLUGIN_HOOKS['plugin_typenames'][$this->device_type]) |
||
314 | && !empty($PLUGIN_HOOKS['plugin_typenames'][$this->device_type])){ |
||
315 | return $PLUGIN_HOOKS['plugin_typenames'][$this->device_type]; |
||
316 | } else { // Else use pluginname |
||
317 | if (isset($PLUGIN_HOOKS['plugin_types'][$this->device_type])){ |
||
318 | $function="plugin_version_".$PLUGIN_HOOKS['plugin_types'][$this->device_type]; |
||
319 | if (function_exists($function)){ |
||
320 | $data=$function(); |
||
321 | if (isset($data['name'])){ |
||
322 | return $data['name']; |
||
323 | } |
||
324 | } |
||
325 | } |
||
326 | } |
||
327 | } |
||
328 | break;
|
||
329 | } |
||
330 | return ""; |
||
331 | } |
||
332 | |||
333 | /**
|
||
334 | * Get the value of a field
|
||
335 | * @param $field field name
|
||
336 | * @return value of the field / false if not exists
|
||
337 | */
|
||
338 | function getField($field){ |
||
339 | if ($this->obj==NULL) return false; |
||
340 | if ($this->device_type==0) { |
||
341 | return false; |
||
342 | } else {
|
||
343 | if (isset($this->obj->fields[$field])) { |
||
344 | return $this->obj->fields[$field]; |
||
345 | } else {
|
||
346 | return false; |
||
347 | } |
||
348 | } |
||
349 | } |
||
350 | /**
|
||
351 | * Get The Name of the Object
|
||
352 | * @param $with_comments add comments to name
|
||
353 | * @return String: name of the object in the current language
|
||
354 | */
|
||
355 | function getName($with_comments=0){ |
||
356 | global $LANG; |
||
357 | |||
358 | |||
359 | if ($this->device_type==0) { |
||
360 | return ""; |
||
361 | } |
||
362 | |||
363 | $toadd=""; |
||
364 | if ($with_comments) $toadd=" ".$this->getComments(); |
||
365 | |||
366 | if ($this->device_type==KNOWBASE_TYPE&&$this->obj!=NULL&&isset($this->obj->fields["question"])&&$this->obj->fields["question"]!="") |
||
367 | return $this->obj->fields["question"]; |
||
368 | else if ($this->device_type==LICENSE_TYPE&&$this->obj!=NULL&&isset($this->obj->fields["serial"])&&$this->obj->fields["serial"]!="") |
||
369 | return $this->obj->fields["serial"]; |
||
370 | else if (($this->device_type==CARTRIDGE_TYPE||$this->device_type==CONSUMABLE_TYPE)&&$this->obj!=NULL&&$this->obj->fields["name"]!=""){ |
||
371 | $name=$this->obj->fields["name"]; |
||
372 | if (isset($this->obj->fields["ref"])&&!empty($this->obj->fields["ref"])) |
||
373 | $name.=" - ".$this->obj->fields["ref"]; |
||
374 | return $name.$toadd; |
||
375 | } |
||
376 | else if ($this->obj!=NULL&&isset($this->obj->fields["name"])&&$this->obj->fields["name"]!="") |
||
377 | return $this->obj->fields["name"].$toadd; |
||
378 | else
|
||
379 | return "N/A"; |
||
380 | } |
||
381 | /**
|
||
382 | * Get The Name of the Object with the ID if the config is set
|
||
383 | * @param $with_comments add comments to name
|
||
384 | * @return String: name of the object in the current language
|
||
385 | */
|
||
386 | function getNameID($with_comments=0){ |
||
387 | global $CFG_GLPI; |
||
388 | $toadd=""; |
||
389 | if ($with_comments) $toadd=" ".$this->getComments(); |
||
390 | if ($CFG_GLPI["view_ID"]){ |
||
391 | if ($this->device_type==0) |
||
392 | return $this->getName().$toadd; |
||
393 | else return $this->getName()." (".$this->id_device.")".$toadd; |
||
394 | } else return $this->getName().$toadd; |
||
395 | } |
||
396 | /**
|
||
397 | * Get The link to the Object
|
||
398 | * @param $with_comments Display comments
|
||
399 | * @return String: link to the object type in the current language
|
||
400 | */
|
||
401 | function getLink($with_comments=0){ |
||
402 | |||
403 | global $CFG_GLPI,$INFOFORM_PAGES; |
||
404 | $ID=""; |
||
405 | switch ($this->device_type){ |
||
406 | case GENERAL_TYPE : |
||
407 | case LICENSE_TYPE : |
||
408 | case CARTRIDGE_ITEM_TYPE : |
||
409 | case CONSUMABLE_ITEM_TYPE : |
||
410 | return $this->getName($with_comments); |
||
411 | break;
|
||
412 | default :
|
||
413 | return "<a href=\"".$CFG_GLPI["root_doc"]."/".$INFOFORM_PAGES[$this->device_type]."?ID=".$this->id_device."\">".$this->getNameID($with_comments)."</a>"; |
||
414 | break;
|
||
415 | } |
||
416 | |||
417 | |||
418 | } |
||
419 | /**
|
||
420 | * Get comments of the Object
|
||
421 | *
|
||
422 | * @return String: comments of the object in the current language
|
||
423 | */
|
||
424 | function getComments(){ |
||
425 | global $LANG,$CFG_GLPI; |
||
426 | $comment=""; |
||
427 | |||
428 | if (!($comment = $CFG_GLPI["cache"]->get("comments_".$this->id_device."_".$_SESSION["glpilanguage"],"GLPI_".$this->device_type))) { |
||
429 | if ($tmp=$this->getField('serial')){ |
||
430 | $comment.="<strong>".$LANG["common"][19].": "."</strong>".$tmp."<br>"; |
||
431 | } |
||
432 | |||
433 | if ($tmp=$this->getField('otherserial')){ |
||
434 | $comment.="<strong>".$LANG["common"][20].": "."</strong>".$tmp."<br>"; |
||
435 | } |
||
436 | if ($tmp=$this->getField('location')){ |
||
437 | $tmp=getDropdownName("glpi_dropdown_locations",$tmp); |
||
438 | if (!empty($tmp)&&$tmp!=' '){ |
||
439 | $comment.="<strong>".$LANG["common"][15].": "."</strong>".$tmp."<br>"; |
||
440 | } |
||
441 | } |
||
442 | if ($tmp=$this->getField('FK_users')){ |
||
443 | $tmp=getUserName($tmp); |
||
444 | if (!empty($tmp)&&$tmp!=' '){ |
||
445 | $comment.="<strong>".$LANG["common"][34].": "."</strong>".$tmp."<br>"; |
||
446 | } |
||
447 | } |
||
448 | if ($tmp=$this->getField('FK_groups')){ |
||
449 | $tmp=getDropdownName("glpi_groups",$tmp); |
||
450 | if (!empty($tmp)&&$tmp!=' '){ |
||
451 | $comment.="<strong>".$LANG["common"][35].": "."</strong>".$tmp."<br>"; |
||
452 | } |
||
453 | } |
||
454 | if ($tmp=$this->getField('tech_num')){ |
||
455 | $tmp=getUserName($tmp); |
||
456 | if (!empty($tmp)&&$tmp!=' '){ |
||
457 | $comment.="<strong>".$LANG["common"][10].": "."</strong>".$tmp."<br>"; |
||
458 | } |
||
459 | } |
||
460 | if ($tmp=$this->getField('contact')){ |
||
461 | $comment.="<strong>".$LANG["common"][18].": "."</strong>".$tmp."<br>"; |
||
462 | } |
||
463 | if ($tmp=$this->getField('contact_num')){ |
||
464 | $comment.="<strong>".$LANG["common"][21].": "."</strong>".$tmp."<br>"; |
||
465 | } |
||
466 | $CFG_GLPI["cache"]->save($comment,"comments_".$this->id_device."_".$_SESSION["glpilanguage"],"GLPI_".$this->device_type); |
||
467 | } |
||
468 | |||
469 | if (!empty($comment)){ |
||
470 | $rand=mt_rand();
|
||
471 | $comments_display=" onmouseout=\"cleanhide('comments_commonitem$rand')\" onmouseover=\"cleandisplay('comments_commonitem$rand')\" "; |
||
472 | $comments_display2="<span class='over_link' id='comments_commonitem$rand'>".nl2br($comment)."</span>"; |
||
473 | |||
474 | $comment="<img alt='' src='".$CFG_GLPI["root_doc"]."/pics/aide.png' $comments_display> "; |
||
475 | $comment.=$comments_display2; |
||
476 | } |
||
477 | |||
478 | |||
479 | return $comment; |
||
480 | } |
||
481 | } |
||
482 | |||
483 | |||
484 | |||
485 | |||
486 | ?> |