Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

Historique | Voir | Annoter | Télécharger (11,2 ko)

1
<?php
2
/*
3
 * @version $Id: cartridge.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

    
37
if (!defined('GLPI_ROOT')){
38
        die("Sorry. You can't access directly to this file");
39
        }
40

    
41

    
42
//!  CartridgeType Class
43
/** CartridgeType Class
44
  This class is used to manage the various types of cartridges.
45
  \see Cartridge
46
  \author Julien Dombre
47
 */
48
class CartridgeType extends CommonDBTM {
49

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

    
58
        function cleanDBonPurge($ID) {
59
                global $DB;
60
                // Delete cartridges
61
                $query = "DELETE FROM glpi_cartridges WHERE (FK_glpi_cartridges_type = '$ID')";
62
                $DB->query($query);
63
                // Delete all cartridge assoc
64
                $query2 = "DELETE FROM glpi_cartridges_assoc WHERE (FK_glpi_cartridges_type = '$ID')";
65
                $result2 = $DB->query($query2);
66

    
67
                $query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='".CARTRIDGE_TYPE."')";
68
                $result = $DB->query($query);
69

    
70
        }
71

    
72
        function post_getEmpty () {
73
                global $CFG_GLPI;
74
                $this->fields["alarm"]=$CFG_GLPI["cartridges_alarm"];
75
        }
76

    
77
        function defineOnglets($withtemplate){
78
                global $LANG;
79

    
80
                $ong[1]=$LANG["title"][26];
81
                if (haveRight("contract_infocom","r"))
82
                        $ong[4]=$LANG["Menu"][26];
83
                if (haveRight("document","r"))
84
                        $ong[5]=$LANG["Menu"][27];
85
                if (haveRight("link","r"))
86
                        $ong[7]=$LANG["title"][34];
87
                if (haveRight("notes","r"))
88
                        $ong[10]=$LANG["title"][37];
89

    
90
                return $ong;
91
        }
92

    
93
        ///// SPECIFIC FUNCTIONS
94

    
95
        /**
96
         * Count cartridge of the cartridge type
97
         *
98
         *@return number of cartridges
99
         *
100
         **/
101
        function countCartridges() {
102
                global $DB;
103
                $query = "SELECT * FROM glpi_cartridges WHERE (FK_glpi_cartridges_type = '".$this->fields["ID"]."')";
104
                if ($result = $DB->query($query)) {
105
                        $number = $DB->numrows($result);
106
                        return $number;
107
                } else {
108
                        return false;
109
                }
110
        }
111

    
112
        /**
113
         * Add a compatible printer type for a cartridge type
114
         *
115
         * Add the compatible printer $type type for the cartridge type $tID
116
         *
117
         *@param $tID integer: cartridge type identifier
118
         *@param $type integer: printer type identifier
119
         *@return nothing ()
120
         *
121
         **/
122
        function addCompatibleType($tID,$type){
123
                global $DB;
124
                if ($tID>0&&$type>0){
125

    
126
                        $query="INSERT INTO glpi_cartridges_assoc (FK_glpi_cartridges_type,FK_glpi_dropdown_model_printers ) VALUES ('$tID','$type');";
127
                        $result = $DB->query($query);
128
                }
129
        }
130

    
131
        /**
132
         * delete a compatible printer associated to a cartridge
133
         *
134
         * Delete a compatible printer associated to a cartridge with assoc identifier $ID
135
         *
136
         *@param $ID integer: glpi_cartridge_assoc identifier.
137
         *
138
         *@return nothing ()
139
         *
140
         **/
141
        function deleteCompatibleType($ID){
142

    
143
                global $DB;
144
                $query="DELETE FROM glpi_cartridges_assoc WHERE ID= '$ID';";
145
                $result = $DB->query($query);
146
        }
147

    
148

    
149

    
150
        /**
151
         * Print the cartridge type form
152
         *
153
         *
154
         * Print general cartridge type form
155
         *
156
         *@param $target filename : where to go when done.
157
         *@param $ID Integer : Id of the cartridge type
158
         *@param $withtemplate='' boolean : template or basic item
159
         *
160
         *
161
         *@return Nothing (display)
162
         *
163
         **/
164
        function showForm ($target,$ID,$withtemplate='') {
165
                // Show CartridgeType or blank form
166

    
167
                global $CFG_GLPI,$LANG;
168

    
169
                if (!haveRight("cartridge","r")) return false;
170

    
171

    
172
                $ct_spotted = false;
173
                $use_cache=true;
174
                if (empty($ID)) {
175
                        $use_cache=false;
176
                        if($this->getEmpty()) $ct_spotted = true;
177
                } else {
178
                        if($this->getFromDB($ID)&&haveAccessToEntity($this->fields["FK_entities"])) $ct_spotted = true;
179
                }                
180

    
181
                if ($ct_spotted){
182
                        $this->showOnglets($ID, $withtemplate,$_SESSION['glpi_onglet']);
183
                        echo "<form method='post' action=\"$target\"><div class='center'>\n";
184
                        if (empty($ID)){
185
                                echo "<input type='hidden' name='FK_entities' value='".$_SESSION["glpiactive_entity"]."'>";
186
                        }
187

    
188
                        if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) {
189
                                echo "<table class='tab_cadre_fixe'>\n";
190
                                echo "<tr><th colspan='3'>\n";
191
                                if (!$ID) {
192
                                        echo $LANG["cartridges"][6];
193
                                } else { 
194
                                        echo $LANG["common"][2]." $ID";
195
                                }
196

    
197
                                if (isMultiEntitiesMode()){
198
                                        echo "&nbsp;(".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")";
199
                                }                        
200
        
201
                                echo "</th></tr>\n";
202
        
203
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][16].":                </td>\n";
204
                                echo "<td colspan='2'>";
205
                                autocompletionTextField("name","glpi_cartridges_type","name",$this->fields["name"],25,$this->fields["FK_entities"]);
206
                                echo "</td></tr>\n";
207
        
208
                                echo "<tr class='tab_bg_1'><td>".$LANG["consumables"][2].":                </td>\n";
209
                                echo "<td colspan='2'>";
210
                                autocompletionTextField("ref","glpi_cartridges_type","ref",$this->fields["ref"],25,$this->fields["FK_entities"]);        
211
                                echo "</td></tr>\n";
212
        
213
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][17].":         </td><td colspan='2'>\n";
214
                                dropdownValue("glpi_dropdown_cartridge_type","type",$this->fields["type"]);
215
                                echo "</td></tr>\n";
216
        
217
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][5].":         </td><td colspan='2'>\n";
218
                                dropdownValue("glpi_dropdown_manufacturer","FK_glpi_enterprise",$this->fields["FK_glpi_enterprise"]);
219
                                echo "</td></tr>\n";
220
        
221
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][10].":         </td><td colspan='2'>\n";
222
                                dropdownUsersID("tech_num", $this->fields["tech_num"],"interface",1,$this->fields["FK_entities"]);
223
                                echo "</td></tr>\n";
224
        
225
                                echo "<tr class='tab_bg_1'><td>".$LANG["consumables"][36].":         </td><td colspan='2'>\n";
226
                                dropdownValue("glpi_dropdown_locations","location",$this->fields["location"],1,$this->fields["FK_entities"]);
227
                                echo "</td></tr>\n";
228
        
229
                                echo "<tr class='tab_bg_1'><td>".$LANG["consumables"][38].":</td><td colspan='2'>";
230
                                dropdownInteger('alarm',$this->fields["alarm"],-1,100);
231
                                echo "</td></tr>\n";
232
        
233
        
234
                                echo "<tr class='tab_bg_1'><td valign='top'>\n";
235
                                echo $LANG["common"][25].":        </td>";
236
                                echo "<td align='center' colspan='2'><textarea cols='35' rows='4' name='comments' >".$this->fields["comments"]."</textarea>";
237
                                echo "</td></tr>\n";
238
                                if ($use_cache){
239
                                        $CFG_GLPI["cache"]->end();
240
                                }
241
                        }
242

    
243
                        if (haveRight("cartridge","w"))
244
                                if (!$ID) {
245

    
246
                                        echo "<tr>\n";
247
                                        echo "<td class='tab_bg_2' valign='top' colspan='3'>\n";
248
                                        echo "<div class='center'><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></div>";
249
                                        echo "</td>";
250
                                        echo "</tr>\n";
251
                                } else {
252

    
253
                                        echo "<tr>\n";
254
                                        echo "<td class='tab_bg_2'></td>";
255
                                        echo "<td class='tab_bg_2' valign='top'>";
256
                                        echo "<input type='hidden' name='ID' value=\"$ID\">\n";
257
                                        echo "<div class='center'><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></div>";
258
                                        echo "</td>";
259
                                        echo "<td class='tab_bg_2' valign='top'>\n";
260
                                        echo "<div class='center'>";
261
                                        if (!$this->fields["deleted"])
262
                                                echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>";
263
                                        else {
264
                                                echo "<input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>";
265

    
266
                                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'>\n";
267
                                        }
268
                                        echo "</div>";
269
                                        echo "</td>";
270
                                        echo "</tr>\n";
271
                                }
272

    
273
                        echo "</table></div></form>";
274

    
275
                }
276
                else {
277
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
278
                        return false;
279
                }
280
                return true;
281
        }
282

    
283

    
284

    
285
}
286

    
287
//!  Cartridge Class
288
/**
289
  This class is used to manage the cartridges.
290
  \see CartridgeType
291
  \author Julien Dombre
292
 */
293
class Cartridge extends CommonDBTM {
294

    
295
        /**
296
         * Constructor
297
         **/
298
        function Cartridge () {
299
                $this->table="glpi_cartridges";
300
                $this->type=CARTRIDGE_ITEM_TYPE;
301
        }
302

    
303

    
304
        function cleanDBonPurge($ID) {
305
                global $DB;
306
                $query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='".CARTRIDGE_ITEM_TYPE."')";
307
                $result = $DB->query($query);
308
        }
309

    
310
        function prepareInputForAdd($input) {
311
                return array("FK_glpi_cartridges_type"=>$input["tID"],
312
                                "date_in"=>date("Y-m-d"));
313
        }
314

    
315
        function post_addItem($newID,$input) {
316
                // Add infocoms if exists for the licence
317
                $ic=new Infocom();
318

    
319
                if ($ic->getFromDBforDevice(CARTRIDGE_TYPE,$this->fields["FK_glpi_cartridges_type"])){
320
                        unset($ic->fields["ID"]);
321
                        $ic->fields["FK_device"]=$newID;
322
                        $ic->fields["device_type"]=CARTRIDGE_ITEM_TYPE;
323
                        $ic->addToDB();
324
                }
325
        }
326

    
327
        function restore($input,$history=1) {
328

    
329
                global $DB;
330
                $query = "UPDATE glpi_cartridges SET date_out = NULL, date_use = NULL , FK_glpi_printers = 0 WHERE ID='".$input["ID"]."'";
331
                if ($result = $DB->query($query)) {
332
                        return true;
333
                } else {
334
                        return false;
335
                }
336
        }
337

    
338
        // SPECIFIC FUNCTIONS
339
        /**
340
         * Update count pages value of a cartridge
341
         *
342
         *@param $ID ID of the cartridge
343
         *@param $pages  count pages value
344
         *
345
         **/
346
        function updatePages($ID,$pages){
347
                global $DB;
348
                $query="UPDATE glpi_cartridges SET pages='$pages' WHERE ID='$ID'";
349
                $DB->query($query);
350
        }
351

    
352
        /**
353
         * Link a cartridge to a printer.
354
         *
355
         * Link the first unused cartridge of type $Tid to the printer $pID
356
         *
357
         *@param $tID : cartridge type identifier
358
         *@param $pID : printer identifier
359
         *
360
         *@return nothing
361
         *
362
         **/
363
        function install($pID,$tID) {
364
                global $DB,$LANG;
365

    
366
                // Get first unused cartridge
367
                $query = "SELECT ID FROM glpi_cartridges WHERE FK_glpi_cartridges_type = '$tID' AND date_use IS NULL";
368
                $result = $DB->query($query);
369
                if ($DB->numrows($result)>0){
370
                        // Mise a jour cartouche en prenant garde aux insertion multiples        
371
                        $query = "UPDATE glpi_cartridges SET date_use = '".date("Y-m-d")."', FK_glpi_printers = '$pID' WHERE ID='".$DB->result($result,0,0)."' AND date_use IS NULL";
372
                        if ($result = $DB->query($query)) {
373
                                return true;
374
                        } else {
375
                                return false;
376
                        }
377
                } else {
378
                        addMessageAfterRedirect($LANG["cartridges"][34]);
379
                        return false;                
380
                }
381
        }
382

    
383
        /**
384
         * UnLink a cartridge linked to a printer
385
         *
386
         * UnLink the cartridge identified by $ID
387
         *
388
         *@param $ID : cartridge identifier
389
         *
390
         *@return boolean
391
         *
392
         **/
393
        function uninstall($ID) {
394

    
395
                global $DB;
396
                $query = "UPDATE glpi_cartridges SET date_out = '".date("Y-m-d")."' WHERE ID='$ID'";
397
                if ($result = $DB->query($query)) {
398
                        return true;
399
                } else {
400
                        return false;
401
                }
402
        }
403

    
404

    
405
}
406

    
407
?>
Redmine Appliance - Powered by TurnKey Linux