ryxeo-glpi-git / inc / infocom.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (3,74 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: infocom.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: Julien Dombre
|
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 |
class InfoCom extends CommonDBTM { |
43 |
|
44 |
|
45 |
/**
|
46 |
* Constructor
|
47 |
**/
|
48 |
function InfoCom () { |
49 |
$this->table="glpi_infocoms"; |
50 |
$this->type=INFOCOM_TYPE; |
51 |
$this->dohistory=true; |
52 |
$this->auto_message_on_action=false; |
53 |
} |
54 |
|
55 |
function post_getEmpty () { |
56 |
global $CFG_GLPI; |
57 |
$this->fields["alert"]=$CFG_GLPI["infocom_alerts"]; |
58 |
} |
59 |
|
60 |
|
61 |
/**
|
62 |
* Retrieve an item from the database for a device
|
63 |
*
|
64 |
*@param $ID ID of the device to retrieve infocom
|
65 |
*@param $device_type type of the device to retrieve infocom
|
66 |
*@return true if succeed else false
|
67 |
**/
|
68 |
function getFromDBforDevice ($device_type,$ID) { |
69 |
|
70 |
global $DB; |
71 |
$query = "SELECT * FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='$device_type')"; |
72 |
|
73 |
if ($result = $DB->query($query)) { |
74 |
if ($DB->numrows($result)==1){ |
75 |
$data = $DB->fetch_assoc($result); |
76 |
|
77 |
foreach ($data as $key => $val) { |
78 |
$this->fields[$key] = $val; |
79 |
} |
80 |
return true; |
81 |
} else return false; |
82 |
} else {
|
83 |
return false; |
84 |
} |
85 |
} |
86 |
|
87 |
function prepareInputForAdd($input) { |
88 |
global $CFG_GLPI; |
89 |
if (!$this->getFromDBforDevice($input['device_type'],$input['FK_device'])){ |
90 |
$input['alert']=$CFG_GLPI["infocom_alerts"]; |
91 |
return $input; |
92 |
} |
93 |
return false; |
94 |
} |
95 |
|
96 |
function prepareInputForUpdate($input) { |
97 |
if (isset($input["ID"])){ |
98 |
|
99 |
$this->getFromDB($input["ID"]); |
100 |
} else {
|
101 |
if (!$this->getFromDBforDevice($input["device_type"],$input["FK_device"])){ |
102 |
$input2["FK_device"]=$input["FK_device"]; |
103 |
$input2["device_type"]=$input["device_type"]; |
104 |
$this->add($input2); |
105 |
$this->getFromDBforDevice($input["device_type"],$input["FK_device"]); |
106 |
} |
107 |
$input["ID"]=$this->fields["ID"]; |
108 |
} |
109 |
|
110 |
// Backup initial values
|
111 |
if (isset($input['buy_date'])){ |
112 |
$input['_buy_date']=$this->fields['buy_date']; |
113 |
} |
114 |
if (isset($input['warranty_duration'])){ |
115 |
$input['_warranty_duration']=$this->fields['warranty_duration']; |
116 |
} |
117 |
return $input; |
118 |
} |
119 |
|
120 |
function post_updateItem($input,$updates,$history=1) { |
121 |
// Clean end alert if buy_date is after old one
|
122 |
// Or if duration is greater than old one
|
123 |
if ((in_array('buy_date',$updates) |
124 |
&& ($input['_buy_date'] < $this->fields['buy_date'] )) |
125 |
|| ( in_array('warranty_duration',$updates) |
126 |
&& ($input['_warranty_duration'] < $this->fields['warranty_duration'] )) |
127 |
){ |
128 |
$alert=new Alert(); |
129 |
$alert->clear($this->type,$this->fields['ID'],ALERT_END); |
130 |
} |
131 |
} |
132 |
|
133 |
} |
134 |
|
135 |
?>
|