ryxeo-glpi-git / inc / contract.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (10,9 ko)
1 | b67d8923 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: contract.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 | /// Contract class
|
||
42 | class Contract extends CommonDBTM { |
||
43 | |||
44 | /**
|
||
45 | * Constructor
|
||
46 | **/
|
||
47 | function Contract () { |
||
48 | $this->table="glpi_contracts"; |
||
49 | $this->type=CONTRACT_TYPE; |
||
50 | $this->entity_assign=true; |
||
51 | $this->may_be_recursive=true; |
||
52 | } |
||
53 | |||
54 | function post_getEmpty () { |
||
55 | global $CFG_GLPI; |
||
56 | $this->fields["alert"]=$CFG_GLPI["contract_alerts"]; |
||
57 | } |
||
58 | |||
59 | function cleanDBonPurge($ID) { |
||
60 | |||
61 | global $DB; |
||
62 | |||
63 | $query2 = "DELETE FROM glpi_contract_enterprise WHERE (FK_contract = '$ID')"; |
||
64 | $DB->query($query2); |
||
65 | |||
66 | $query3 = "DELETE FROM glpi_contract_device WHERE (FK_contract = '$ID')"; |
||
67 | $DB->query($query3); |
||
68 | } |
||
69 | |||
70 | function defineOnglets($withtemplate){ |
||
71 | global $LANG; |
||
72 | $ong[1]=$LANG["title"][26]; |
||
73 | if (haveRight("document","r")) |
||
74 | $ong[5]=$LANG["Menu"][27]; |
||
75 | if (haveRight("link","r")) |
||
76 | $ong[7]=$LANG["title"][34]; |
||
77 | if (haveRight("notes","r")) |
||
78 | $ong[10]=$LANG["title"][37]; |
||
79 | return $ong; |
||
80 | } |
||
81 | |||
82 | function prepareInputForUpdate($input) { |
||
83 | // Backup initial values
|
||
84 | if (isset($input['begin_date'])){ |
||
85 | $input['_begin_date']=$this->fields['begin_date']; |
||
86 | } |
||
87 | if (isset($input['duration'])){ |
||
88 | $input['_duration']=$this->fields['duration']; |
||
89 | } |
||
90 | if (isset($input['notice'])){ |
||
91 | $input['_notice']=$this->fields['notice']; |
||
92 | } |
||
93 | return $input; |
||
94 | } |
||
95 | |||
96 | |||
97 | function post_updateItem($input,$updates,$history=1) { |
||
98 | // Clean end alert if begin_date is after old one
|
||
99 | // Or if duration is greater than old one
|
||
100 | if ((in_array('begin_date',$updates) |
||
101 | && ($input['_begin_date'] < $this->fields['begin_date'] )) |
||
102 | || ( in_array('duration',$updates) |
||
103 | && ($input['_duration'] < $this->fields['duration'] )) |
||
104 | ){ |
||
105 | $alert=new Alert(); |
||
106 | $alert->clear($this->type,$this->fields['ID'],ALERT_END); |
||
107 | } |
||
108 | |||
109 | // Clean notice alert if begin_date is after old one
|
||
110 | // Or if duration is greater than old one
|
||
111 | // Or if notice is lesser than old one
|
||
112 | if ((in_array('begin_date',$updates) |
||
113 | && ($input['_begin_date'] < $this->fields['begin_date'] )) |
||
114 | || ( in_array('duration',$updates) |
||
115 | && ($input['_duration'] < $this->fields['duration'] )) |
||
116 | || ( in_array('notice',$updates) |
||
117 | && ($input['_notice'] > $this->fields['notice'] )) |
||
118 | ){ |
||
119 | $alert=new Alert(); |
||
120 | $alert->clear($this->type,$this->fields['ID'],ALERT_NOTICE); |
||
121 | } |
||
122 | |||
123 | } |
||
124 | |||
125 | /**
|
||
126 | * Print the contract form
|
||
127 | *
|
||
128 | *@param $target filename : where to go when done.
|
||
129 | *@param $ID Integer : Id of the item to print
|
||
130 | *@param $withtemplate integer template or basic item
|
||
131 | *
|
||
132 | *@return boolean item found
|
||
133 | **/
|
||
134 | function showForm ($target,$ID,$withtemplate='') { |
||
135 | // Show Contract or blank form
|
||
136 | |||
137 | global $CFG_GLPI,$LANG; |
||
138 | |||
139 | // if (!haveRight("contract_infocom","r")) return false;
|
||
140 | |||
141 | $spotted=false; |
||
142 | $use_cache=true; |
||
143 | |||
144 | |||
145 | if ($ID>0) { |
||
146 | if($this->can($ID,'r')) { |
||
147 | $spotted = true; |
||
148 | } |
||
149 | } else {
|
||
150 | $use_cache=false; |
||
151 | if ($this->can(-1,'w')){ |
||
152 | $spotted = true; |
||
153 | } |
||
154 | } |
||
155 | |||
156 | if ($spotted){ |
||
157 | $can_edit=$this->can($ID,'w'); |
||
158 | |||
159 | $this->showOnglets($ID, $withtemplate,$_SESSION['glpi_onglet']); |
||
160 | |||
161 | if ($can_edit) { |
||
162 | echo "<form name='form' method='post' action=\"$target\"><div class='center'>"; |
||
163 | if (empty($ID)||$ID<0){ |
||
164 | echo "<input type='hidden' name='FK_entities' value='".$_SESSION["glpiactive_entity"]."'>"; |
||
165 | } |
||
166 | } |
||
167 | |||
168 | echo "<table class='tab_cadre_fixe'>"; |
||
169 | echo "<tr><th colspan='2'>"; |
||
170 | if ($ID<0) { |
||
171 | echo $LANG["financial"][36]; |
||
172 | } else {
|
||
173 | echo $LANG["common"][2]." $ID"; |
||
174 | } |
||
175 | if (isMultiEntitiesMode()){
|
||
176 | echo " (".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")"; |
||
177 | } |
||
178 | |||
179 | echo "</th>"; |
||
180 | |||
181 | echo "<th colspan='2'>"; |
||
182 | if (isMultiEntitiesMode()){
|
||
183 | echo $LANG["entity"][9].": "; |
||
184 | |||
185 | if ($this->can($ID,'recursive')) { |
||
186 | dropdownYesNo("recursive",$this->fields["recursive"]); |
||
187 | } else {
|
||
188 | echo getYesNo($this->fields["recursive"]); |
||
189 | } |
||
190 | } else {
|
||
191 | echo " "; |
||
192 | } |
||
193 | echo "</th>"; |
||
194 | |||
195 | echo "</tr>"; |
||
196 | |||
197 | if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) { |
||
198 | |||
199 | echo "<tr class='tab_bg_1'><td>".$LANG["common"][16].": </td><td>"; |
||
200 | autocompletionTextField("name","glpi_contracts","name",$this->fields["name"],25,$this->fields["FK_entities"]); |
||
201 | echo "</td>"; |
||
202 | |||
203 | echo "<td>".$LANG["financial"][6].": </td><td >"; |
||
204 | dropdownValue("glpi_dropdown_contract_type","contract_type",$this->fields["contract_type"]); |
||
205 | echo "</td></tr>"; |
||
206 | |||
207 | |||
208 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][4].": </td>"; |
||
209 | echo "<td><input type='text' name='num' value=\"".$this->fields["num"]."\" size='25'></td>"; |
||
210 | |||
211 | echo "<td colspan='2'></td></tr>"; |
||
212 | |||
213 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][5].": </td><td>"; |
||
214 | echo "<input type='text' name='cost' value=\"".formatNumber($this->fields["cost"],true)."\" size='16'>"; |
||
215 | echo "</td>"; |
||
216 | |||
217 | echo "<td>".$LANG["search"][8].": </td>"; |
||
218 | echo "<td>"; |
||
219 | showCalendarForm("form","begin_date",$this->fields["begin_date"]); |
||
220 | echo "</td></tr>"; |
||
221 | |||
222 | |||
223 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][8].": </td><td>"; |
||
224 | dropdownInteger("duration",$this->fields["duration"],0,120); |
||
225 | echo " ".$LANG["financial"][57]; |
||
226 | if ($this->fields["begin_date"]!=''&&$this->fields["begin_date"]!="0000-00-00"){ |
||
227 | echo " -> ".getWarrantyExpir($this->fields["begin_date"],$this->fields["duration"]); |
||
228 | } |
||
229 | echo "</td>"; |
||
230 | |||
231 | echo "<td>".$LANG["financial"][13].": </td><td>"; |
||
232 | autocompletionTextField("compta_num","glpi_contracts","compta_num",$this->fields["compta_num"],25,$this->fields["FK_entities"]); |
||
233 | |||
234 | echo "</td></tr>"; |
||
235 | |||
236 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][69].": </td><td>"; |
||
237 | dropdownContractPeriodicity("periodicity",$this->fields["periodicity"]); |
||
238 | echo "</td>"; |
||
239 | |||
240 | |||
241 | echo "<td>".$LANG["financial"][10].": </td><td>"; |
||
242 | dropdownInteger("notice",$this->fields["notice"],0,120); |
||
243 | echo " ".$LANG["financial"][57]; |
||
244 | if ($this->fields["begin_date"]!=''&&$this->fields["begin_date"]!="0000-00-00" && $this->fields["notice"]>0){ |
||
245 | echo " -> ".getWarrantyExpir($this->fields["begin_date"],$this->fields["duration"],$this->fields["notice"]); |
||
246 | } |
||
247 | echo "</td></tr>"; |
||
248 | |||
249 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][107].": </td><td>"; |
||
250 | dropdownContractRenewal("renewal",$this->fields["renewal"]); |
||
251 | echo "</td>"; |
||
252 | |||
253 | |||
254 | echo "<td>".$LANG["financial"][11].": </td>"; |
||
255 | echo "<td>"; |
||
256 | dropdownContractPeriodicity("facturation",$this->fields["facturation"]); |
||
257 | echo "</td></tr>"; |
||
258 | |||
259 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][83].": </td><td>"; |
||
260 | dropdownInteger("device_countmax",$this->fields["device_countmax"],0,200); |
||
261 | echo "</td>"; |
||
262 | |||
263 | |||
264 | echo "<td>".$LANG["common"][41]."</td>"; |
||
265 | echo "<td>"; |
||
266 | dropdownContractAlerting("alert",$this->fields["alert"]); |
||
267 | echo "</td></tr>"; |
||
268 | |||
269 | |||
270 | |||
271 | echo "<tr class='tab_bg_1'><td valign='top'>"; |
||
272 | echo $LANG["common"][25].": </td>"; |
||
273 | echo "<td align='center' colspan='3'><textarea cols='50' rows='4' name='comments' >".$this->fields["comments"]."</textarea>"; |
||
274 | echo "</td></tr>"; |
||
275 | |||
276 | echo "<tr class='tab_bg_2'><td>".$LANG["financial"][59].": </td>"; |
||
277 | echo "<td colspan='3'> </td>"; |
||
278 | echo "</tr>"; |
||
279 | |||
280 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][60].": </td><td colspan='3'>"; |
||
281 | echo $LANG["buttons"][33].":"; |
||
282 | dropdownHours("week_begin_hour",$this->fields["week_begin_hour"]); |
||
283 | echo $LANG["buttons"][32].":"; |
||
284 | dropdownHours("week_end_hour",$this->fields["week_end_hour"]); |
||
285 | echo "</td></tr>"; |
||
286 | |||
287 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][61].": </td><td colspan='3'>"; |
||
288 | dropdownYesNo("saturday",$this->fields["saturday"]); |
||
289 | echo $LANG["buttons"][33].":"; |
||
290 | dropdownHours("saturday_begin_hour",$this->fields["saturday_begin_hour"]); |
||
291 | echo $LANG["buttons"][32].":"; |
||
292 | dropdownHours("saturday_end_hour",$this->fields["saturday_end_hour"]); |
||
293 | echo "</td></tr>"; |
||
294 | |||
295 | echo "<tr class='tab_bg_1'><td>".$LANG["financial"][62].": </td><td colspan='3'>"; |
||
296 | dropdownYesNo("monday",$this->fields["monday"]); |
||
297 | echo $LANG["buttons"][33].":"; |
||
298 | dropdownHours("monday_begin_hour",$this->fields["monday_begin_hour"]); |
||
299 | echo $LANG["buttons"][32].":"; |
||
300 | dropdownHours("monday_end_hour",$this->fields["monday_end_hour"]); |
||
301 | echo "</td></tr>"; |
||
302 | if ($use_cache){ |
||
303 | $CFG_GLPI["cache"]->end(); |
||
304 | } |
||
305 | } |
||
306 | |||
307 | if ($can_edit) { |
||
308 | echo "<tr>"; |
||
309 | |||
310 | if ($ID>0) { |
||
311 | |||
312 | echo "<td class='tab_bg_2' valign='top' colspan='2'>"; |
||
313 | echo "<input type='hidden' name='ID' value=\"$ID\">\n"; |
||
314 | echo "<div class='center'><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></div>"; |
||
315 | echo "</td>\n\n"; |
||
316 | |||
317 | echo "<td class='tab_bg_2' valign='top' colspan='2'>\n"; |
||
318 | if (!$this->fields["deleted"]) |
||
319 | echo "<div class='center'><input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'></div>"; |
||
320 | else {
|
||
321 | echo "<div class='center'><input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>"; |
||
322 | |||
323 | echo " <input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'></div>"; |
||
324 | } |
||
325 | |||
326 | echo "</td>"; |
||
327 | echo "</tr>"; |
||
328 | |||
329 | } else {
|
||
330 | |||
331 | echo "<td class='tab_bg_2' valign='top' colspan='4'>"; |
||
332 | echo "<div class='center'><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></div>"; |
||
333 | echo "</td>"; |
||
334 | echo "</tr>"; |
||
335 | } |
||
336 | echo "</table></div></form>"; |
||
337 | |||
338 | } else { // can't edit |
||
339 | echo "</table></div>"; |
||
340 | } |
||
341 | |||
342 | } else { // con_spotted |
||
343 | echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>"; |
||
344 | return false; |
||
345 | |||
346 | } |
||
347 | |||
348 | return true; |
||
349 | } |
||
350 | |||
351 | } |
||
352 | |||
353 | ?> |