Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / inc / consumable.class.php @ b67d8923

Historique | Voir | Annoter | Télécharger (8,54 ko)

1
<?php
2
/*
3
 * @version $Id: consumable.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
//!  ConsumableType Class
43
/**
44
  This class is used to manage the various types of consumables.
45
  \see Consumable
46
  \author Julien Dombre
47
 */
48
class ConsumableType extends CommonDBTM {
49

    
50
        /**
51
         * Constructor
52
         **/
53
        function ConsumableType () {
54
                $this->table="glpi_consumables_type";
55
                $this->type=CONSUMABLE_TYPE;
56
        }
57

    
58
        function cleanDBonPurge($ID) {
59
                global $DB;
60
                // Delete cartridconsumablesges
61
                $query = "DELETE FROM glpi_consumables WHERE (FK_glpi_consumables_type = '$ID')";
62
                $DB->query($query);
63
        }
64

    
65
        function post_getEmpty () {
66
                global $CFG_GLPI;
67
                $this->fields["alarm"]=$CFG_GLPI["cartridges_alarm"];
68
        }
69

    
70
        function defineOnglets($withtemplate){
71
                global $LANG;
72
                $ong[1]=$LANG["title"][26];
73
                if (haveRight("contract_infocom","r"))        
74
                        $ong[4]=$LANG["Menu"][26];
75
                if (haveRight("document","r"))        
76
                        $ong[5]=$LANG["Menu"][27];
77
                if (haveRight("link","r"))        
78
                        $ong[7]=$LANG["title"][34];
79
                if (haveRight("notes","r"))
80
                        $ong[10]=$LANG["title"][37];
81
                return $ong;
82
        }
83

    
84
        /**
85
         * Print the consumable type form
86
         *
87
         *
88
         * Print g��al consumable type form
89
         *
90
         *@param $target filename : where to go when done.
91
         *@param $ID Integer : Id of the consumable type
92
         *@param $withtemplate='' boolean : template or basic item
93
         *
94
         *
95
         *@return Nothing (display)
96
         *
97
         **/
98
        function showForm ($target,$ID,$withtemplate='') {
99
                // Show ConsumableType or blank form
100

    
101
                global $CFG_GLPI,$LANG;
102

    
103
                if (!haveRight("consumable","r")) return false;
104

    
105

    
106
                $ct_spotted=false;
107
                $use_cache=true;
108
                if (!$ID) {
109
                        $use_cache=false;
110
                        if($this->getEmpty()) $ct_spotted = true;
111
                } else {
112
                        if($this->getFromDB($ID)&&haveAccessToEntity($this->fields["FK_entities"])) $ct_spotted = true;
113
                }
114

    
115
                if ($ct_spotted){
116

    
117
                        $this->showOnglets($ID, $withtemplate,$_SESSION['glpi_onglet']);
118

    
119
                        echo "<form method='post' action=\"$target\"><div class='center'>\n";
120
                        if (empty($ID)){
121
                                echo "<input type='hidden' name='FK_entities' value='".$_SESSION["glpiactive_entity"]."'>";
122
                        }
123

    
124
                        if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) {
125

    
126
                                echo "<table class='tab_cadre_fixe'>\n";
127
                                echo "<tr><th colspan='3'>\n";
128
                                if (!$ID) {
129
                                        echo $LANG["consumables"][6];
130
                                } else {
131
                                        echo $LANG["common"][2]." $ID";
132
                                }                
133
                                if (isMultiEntitiesMode()){
134
                                        echo "&nbsp;(".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")";
135
                                }
136

    
137
                                echo "</th></tr>\n";
138
        
139
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][16].":                </td>\n";
140
                                echo "<td colspan='2'>";
141
                                autocompletionTextField("name","glpi_consumables_type","name",$this->fields["name"],25,$this->fields["FK_entities"]);        
142
                                echo "</td></tr>\n";
143
        
144
                                echo "<tr class='tab_bg_1'><td>".$LANG["consumables"][2].":                </td>\n";
145
                                echo "<td colspan='2'>";
146
                                autocompletionTextField("ref","glpi_consumables_type","ref",$this->fields["ref"],25,$this->fields["FK_entities"]);        
147
                                echo "</td></tr>\n";
148
        
149
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][17].":         </td><td colspan='2'>\n";
150
                                dropdownValue("glpi_dropdown_consumable_type","type",$this->fields["type"]);
151
                                echo "</td></tr>\n";
152
        
153
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][5].":         </td><td colspan='2'>\n";
154
                                dropdownValue("glpi_dropdown_manufacturer","FK_glpi_enterprise",$this->fields["FK_glpi_enterprise"]);
155
                                echo "</td></tr>\n";
156
        
157
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][10].":         </td><td colspan='2'>\n";
158
                                dropdownUsersID("tech_num", $this->fields["tech_num"],"interface",1,$this->fields["FK_entities"]);
159
                                echo "</td></tr>\n";
160
        
161
                                echo "<tr class='tab_bg_1'><td>".$LANG["consumables"][36].":         </td><td colspan='2'>\n";
162
                                dropdownValue("glpi_dropdown_locations","location",$this->fields["location"],1,$this->fields["FK_entities"]);
163
                                echo "</td></tr>\n";
164
        
165
                                echo "<tr class='tab_bg_1'><td>".$LANG["consumables"][38].":</td><td colspan='2'>";
166
                                dropdownInteger('alarm',$this->fields["alarm"],-1,100);
167
                                echo "</td></tr>\n";
168
        
169
        
170
                                echo "<tr class='tab_bg_1'><td valign='top'>\n";
171
                                echo $LANG["common"][25].":        </td>";
172
                                echo "<td align='center' colspan='2'><textarea cols='35' rows='4' name='comments' >".$this->fields["comments"]."</textarea>";
173
                                echo "</td></tr>\n";
174
                                if ($use_cache){
175
                                        $CFG_GLPI["cache"]->end();
176
                                }
177
                        }
178

    
179
                        if (haveRight("consumable","w"))
180
                                if (!$ID) {
181

    
182
                                        echo "<tr>\n";
183
                                        echo "<td class='tab_bg_2' valign='top' colspan='3'>\n";
184
                                        echo "<div class='center'><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></div>";
185
                                        echo "</td>";
186
                                        echo "</tr>\n";
187

    
188

    
189
                                } else {
190

    
191
                                        echo "<tr>\n";
192
                                        echo "<td class='tab_bg_2'></td>";
193
                                        echo "<td class='tab_bg_2' valign='top'>";
194
                                        echo "<input type='hidden' name='ID' value=\"$ID\">\n";
195
                                        echo "<div class='center'><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></div>";
196
                                        echo "</td>";
197
                                        echo "<td class='tab_bg_2' valign='top'>\n";
198
                                        echo "<div class='center'>";
199
                                        if (!$this->fields["deleted"])
200
                                                echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>";
201
                                        else {
202
                                                echo "<input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>";
203

    
204
                                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'>\n";
205
                                        }
206
                                        echo "</div>";
207
                                        echo "</td>";
208
                                        echo "</tr>\n";
209

    
210

    
211
                                }
212
                        echo "</table></div></form>";
213

    
214
                } else {
215

    
216
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
217
                        return false;
218
                }
219
                return true;
220
        }
221

    
222
}
223

    
224
//!  Consumable Class
225
/**
226
  This class is used to manage the consumables.
227
  \see ConsumableType
228
  \author Julien Dombre
229
 */
230
class Consumable extends CommonDBTM {
231

    
232
        /**
233
         * Constructor
234
         **/
235
        function Consumable () {
236
                $this->table="glpi_consumables";
237
                $this->type=CONSUMABLE_ITEM_TYPE;
238
        }
239

    
240

    
241
        function cleanDBonPurge($ID) {
242
                global $DB;
243
                $query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='".CONSUMABLE_ITEM_TYPE."')";
244
                $result = $DB->query($query);
245
        }
246

    
247
        function prepareInputForAdd($input) {
248
                return array("FK_glpi_consumables_type"=>$input["tID"],
249
                                "date_in"=>date("Y-m-d"));
250
        }
251

    
252
        function post_addItem($newID,$input) {
253
                // Add infocoms if exists for the licence
254
                $ic=new Infocom();
255

    
256
                if ($ic->getFromDBforDevice(CONSUMABLE_TYPE,$this->fields["FK_glpi_consumables_type"])){
257
                        unset($ic->fields["ID"]);
258
                        $ic->fields["FK_device"]=$newID;
259
                        $ic->fields["device_type"]=CONSUMABLE_ITEM_TYPE;
260
                        $ic->addToDB();
261
                }
262
        }
263

    
264
        function restore($input,$history=1){
265
                global $DB;
266
                $query = "UPDATE glpi_consumables SET date_out = NULL WHERE ID='".$input["ID"]."'";
267

    
268
                if ($result = $DB->query($query)) {
269
                        return true;
270
                } else {
271
                        return false;
272
                }
273
        }
274

    
275
        /**
276
         * UnLink a consumable linked to a printer
277
         *
278
         * UnLink the consumable identified by $ID
279
         *
280
         *@param $ID : consumable identifier
281
         *@param $id_user : ID of the user giving the consumable
282
         *
283
         *@return boolean
284
         *
285
         **/
286
        function out($ID,$id_user=0) {
287

    
288
                global $DB;
289
                $query = "UPDATE glpi_consumables SET date_out = '".date("Y-m-d")."', id_user='$id_user' WHERE ID='$ID'";
290

    
291
                if ($result = $DB->query($query)) {
292
                        return true;
293
                } else {
294
                        return false;
295
                }
296
        }
297

    
298

    
299
}
300

    
301
?>
Redmine Appliance - Powered by TurnKey Linux