Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

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

1
<?php
2
/*
3
 * @version $Id: printer.class.php 7875 2009-01-23 15:16:47Z 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
// CLASSES Printers
41

    
42

    
43
class Printer  extends CommonDBTM {
44

    
45
        /**
46
         * Constructor
47
        **/
48
        function Printer () {
49
                $this->table="glpi_printers";
50
                $this->type=PRINTER_TYPE;
51
                $this->dohistory=true;
52
        }        
53

    
54
        function defineOnglets($withtemplate){
55
                global $LANG,$CFG_GLPI;
56

    
57
                if (haveRight("cartridge","r"))        {
58
                        $ong[1]=$LANG["title"][26];
59
                }
60
                if (haveRight("networking","r")||haveRight("computer","r")){
61
                        $ong[3]=$LANG["title"][27];
62
                }
63
                if (haveRight("contract_infocom","r")){
64
                        $ong[4]=$LANG["Menu"][26];
65
                }
66
                if (haveRight("document","r")){
67
                        $ong[5]=$LANG["Menu"][27];
68
                }
69

    
70
                if(empty($withtemplate)){
71
                        if (haveRight("show_all_ticket","1")){
72
                                $ong[6]=$LANG["title"][28];
73
                        }
74
                        if (haveRight("link","r")){
75
                                $ong[7]=$LANG["title"][34];
76
                        }
77
                        if (haveRight("notes","r")){
78
                                $ong[10]=$LANG["title"][37];
79
                        }
80
                        if (haveRight("reservation_central","r")){
81
                                $ong[11]=$LANG["Menu"][17];
82
                        }
83
                                
84
                        $ong[12]=$LANG["title"][38];
85

    
86
                }        
87
                return $ong;
88
        }
89

    
90
        function prepareInputForAdd($input) {
91

    
92
                if (isset($input["ID"])&&$input["ID"]>0){
93
                        $input["_oldID"]=$input["ID"];
94
                }
95
                unset($input['ID']);
96
                unset($input['withtemplate']);
97

    
98
                return $input;
99
        }
100

    
101
        function post_addItem($newID,$input) {
102
                global $DB;
103

    
104
                // Manage add from template
105
                if (isset($input["_oldID"])){
106
                        // ADD Infocoms
107
                        $ic= new Infocom();
108
                        if ($ic->getFromDBforDevice(PRINTER_TYPE,$input["_oldID"])){
109
                                $ic->fields["FK_device"]=$newID;
110
                                unset ($ic->fields["ID"]);
111
                                if (isset($ic->fields["num_immo"])) {
112
                                        $ic->fields["num_immo"] = autoName($ic->fields["num_immo"], "num_immo", 1, INFOCOM_TYPE,$input['FK_entities']);
113
                                }
114
        
115
                                $ic->addToDB();
116
                        }
117
        
118
                        // ADD Ports
119
                        $query="SELECT ID from glpi_networking_ports WHERE on_device='".$input["_oldID"]."' AND device_type='".PRINTER_TYPE."';";
120
                        $result=$DB->query($query);
121
                        if ($DB->numrows($result)>0){
122
        
123
                                while ($data=$DB->fetch_array($result)){
124
                                        $np= new Netport();
125
                                        $np->getFromDB($data["ID"]);
126
                                        unset($np->fields["ID"]);
127
                                        unset($np->fields["ifaddr"]);
128
                                        unset($np->fields["ifmac"]);
129
                                        unset($np->fields["netpoint"]);
130
                                        $np->fields["on_device"]=$newID;
131
                                        $np->addToDB();
132
                                }
133
                        }
134
        
135
                        // ADD Contract                                
136
                        $query="SELECT FK_contract from glpi_contract_device WHERE FK_device='".$input["_oldID"]."' AND device_type='".PRINTER_TYPE."';";
137
                        $result=$DB->query($query);
138
                        if ($DB->numrows($result)>0){
139
        
140
                                while ($data=$DB->fetch_array($result))
141
                                        addDeviceContract($data["FK_contract"],PRINTER_TYPE,$newID);
142
                        }
143
        
144
                        // ADD Documents                        
145
                        $query="SELECT FK_doc from glpi_doc_device WHERE FK_device='".$input["_oldID"]."' AND device_type='".PRINTER_TYPE."';";
146
                        $result=$DB->query($query);
147
                        if ($DB->numrows($result)>0){
148
        
149
                                while ($data=$DB->fetch_array($result))
150
                                        addDeviceDocument($data["FK_doc"],PRINTER_TYPE,$newID);
151
                        }
152
                }
153

    
154
        }
155

    
156

    
157
        function cleanDBonPurge($ID) {
158
                global $DB,$CFG_GLPI;
159

    
160

    
161
                $job =new Job();
162
                $query = "SELECT * FROM glpi_tracking WHERE (computer = '$ID'  AND device_type='".PRINTER_TYPE."')";
163
                $result = $DB->query($query);
164

    
165
                if ($DB->numrows($result))
166
                        while ($data=$DB->fetch_array($result)) {
167
                                if ($CFG_GLPI["keep_tracking_on_delete"]==1){
168
                                        $query = "UPDATE glpi_tracking SET computer = '0', device_type='0' WHERE ID='".$data["ID"]."';";
169
                                        $DB->query($query);
170
                                } else $job->delete(array("ID"=>$data["ID"]));
171
                        }
172

    
173

    
174
                $query = "SELECT ID FROM glpi_networking_ports WHERE (on_device = '$ID' AND device_type = '".PRINTER_TYPE."')";
175
                $result = $DB->query($query);
176
                while ($data = $DB->fetch_array($result)){
177
                        $q = "DELETE FROM glpi_networking_wire WHERE (end1 = '".$data["ID"]."' OR end2 = '".$data["ID"]."')";
178
                        $result2 = $DB->query($q);                                        
179
                }
180

    
181
                $query2 = "DELETE FROM glpi_networking_ports WHERE (on_device = '$ID' AND device_type = '".PRINTER_TYPE."')";
182
                $result2 = $DB->query($query2);
183

    
184
                $query="SELECT * FROM glpi_connect_wire WHERE (type='".PRINTER_TYPE."' AND end1='$ID')";
185
                if ($result = $DB->query($query)) {
186
                        if ($DB->numrows($result)>0) {
187
                                while ($data = $DB->fetch_array($result)){
188
                                        // Disconnect without auto actions
189
                                        Disconnect($data["ID"],1,false);
190
                                }
191
                        }
192
                }
193

    
194

    
195
                $query="select * from glpi_reservation_item where (device_type='".PRINTER_TYPE."' and id_device='$ID')";
196
                if ($result = $DB->query($query)) {
197
                        if ($DB->numrows($result)>0){
198
                                $rr=new ReservationItem();
199
                                $rr->delete(array("ID"=>$DB->result($result,0,"ID")));
200
                        }
201
                }
202

    
203
                $query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='".PRINTER_TYPE."')";
204
                $result = $DB->query($query);
205

    
206
                $query = "DELETE FROM glpi_contract_device WHERE (FK_device = '$ID' AND device_type='".PRINTER_TYPE."')";
207
                $result = $DB->query($query);
208

    
209
                $query = "UPDATE glpi_cartridges  SET FK_glpi_printers = NULL WHERE (FK_glpi_printers='$ID')";
210
                $result = $DB->query($query);
211

    
212
        }
213

    
214
        /**
215
         * Print the printer form
216
         *
217
         *@param $target string: where to go when done.
218
         *@param $ID integer: Id of the item to print
219
         *@param $withtemplate integer: template or basic item
220
         *
221
          *@return boolean item found
222
         **/
223
        function showForm ($target,$ID,$withtemplate='') {
224

    
225
                global $CFG_GLPI, $LANG;
226
                if (!haveRight("printer","r")) return false;
227

    
228
                $printer_spotted = false;
229
                $use_cache=true;
230
                if((empty($ID) && $withtemplate == 1)||$ID==-1) {
231
                        $use_cache=false;
232
                        if($this->getEmpty()) $printer_spotted = true;
233
                } else {
234
                        if($this->getFromDB($ID)&&haveAccessToEntity($this->fields["FK_entities"])) $printer_spotted = true;
235
                }
236

    
237
                if($printer_spotted) {
238

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

    
241
                        if(!empty($withtemplate) && $withtemplate == 2) {
242
                                $use_cache=false;
243
                                $template = "newcomp";
244
                                $datestring = $LANG["computers"][14].": ";
245
                                $date = convDateTime($_SESSION["glpi_currenttime"]);
246
                        } elseif(!empty($withtemplate) && $withtemplate == 1) { 
247
                                $use_cache=false;
248
                                $template = "newtemplate";
249
                                $datestring = $LANG["computers"][14].": ";
250
                                $date = convDateTime($_SESSION["glpi_currenttime"]);
251
                        } else {
252
                                $datestring = $LANG["common"][26].": ";
253
                                $date = convDateTime($this->fields["date_mod"]);
254
                                $template = false;
255
                        }
256

    
257

    
258
                        echo "<div align='center' ><form method='post' name='form' action=\"$target\">\n";
259
                        if(strcmp($template,"newtemplate") === 0) {
260
                                echo "<input type=\"hidden\" name=\"is_template\" value=\"1\" />\n";
261
                        }
262
                        
263
                        echo "<input type='hidden' name='FK_entities' value='".$this->fields["FK_entities"]."'>";
264

    
265
                        echo "<table class='tab_cadre_fixe' cellpadding='2'>\n";
266

    
267
                        echo "<tr><th align='center' >\n";
268
                        if(!$template) {
269
                                echo $LANG["common"][2]." ".$this->fields["ID"];
270
                        }elseif (strcmp($template,"newcomp") === 0) {
271
                                echo $LANG["printers"][28].": ".$this->fields["tplname"];
272
                                echo "<input type='hidden' name='tplname' value='".$this->fields["tplname"]."'>";
273
                        }elseif (strcmp($template,"newtemplate") === 0) {
274
                                echo $LANG["common"][6]."&nbsp;: ";
275
                                autocompletionTextField("tplname","glpi_printers","tplname",$this->fields["tplname"],20,$this->fields["FK_entities"]);
276
                        }
277
                        if (isMultiEntitiesMode()){
278
                                echo "&nbsp;(".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")";
279
                        }
280

    
281
                        echo "</th><th  align='center'>".$datestring.$date;
282
                        if (!$template&&!empty($this->fields['tplname']))
283
                                echo "&nbsp;&nbsp;&nbsp;(".$LANG["common"][13].": ".$this->fields['tplname'].")";
284
                        echo "</th></tr>\n";
285

    
286
                        if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) {
287
                                echo "<tr><td class='tab_bg_1' valign='top'>\n";
288
        
289
                                // table identification
290
                                echo "<table cellpadding='1' cellspacing='0' border='0'>\n";
291
                                echo "<tr><td>".$LANG["common"][16].($template?"*":"").":        </td>\n";
292
                                echo "<td>";
293
                                $objectName = autoName($this->fields["name"], "name", ($template === "newcomp"), PRINTER_TYPE,$this->fields["FK_entities"]);
294
                                autocompletionTextField("name","glpi_printers","name",$objectName,20,$this->fields["FK_entities"]);
295
                                echo "</td></tr>\n";
296
        
297
                                echo "<tr><td>".$LANG["common"][15].":         </td><td>\n";
298
                                dropdownValue("glpi_dropdown_locations", "location", $this->fields["location"],1,$this->fields["FK_entities"]);
299
                                echo "</td></tr>\n";
300
        
301
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][5].":         </td><td colspan='2'>\n";
302
                                dropdownValue("glpi_dropdown_manufacturer","FK_glpi_enterprise",$this->fields["FK_glpi_enterprise"]);
303
                                echo "</td></tr>\n";
304
        
305
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][10].":         </td><td colspan='2'>\n";
306
                                dropdownUsersID("tech_num", $this->fields["tech_num"],"interface",1,$this->fields["FK_entities"]);
307
                                echo "</td></tr>\n";
308
        
309
                                echo "<tr><td>".$LANG["common"][18].":        </td><td>\n";
310
                                autocompletionTextField("contact","glpi_printers","contact",$this->fields["contact"],20,$this->fields["FK_entities"]);
311
                                echo "</td></tr>\n";
312

    
313
                                echo "<tr><td>".$LANG["common"][21].":        </td><td>\n";
314
                                autocompletionTextField("contact_num","glpi_printers","contact_num",$this->fields["contact_num"],20,$this->fields["FK_entities"]);
315
                                echo "</td></tr>\n";
316
        
317
        
318
                                echo "<tr><td>".$LANG["common"][34].":         </td><td>";
319
                                dropdownAllUsers("FK_users", $this->fields["FK_users"],1,$this->fields["FK_entities"]);
320
                                echo "</td></tr>";
321
        
322
                                echo "<tr><td>".$LANG["common"][35].":         </td><td>";
323
                                dropdownValue("glpi_groups", "FK_groups", $this->fields["FK_groups"],1,$this->fields["FK_entities"]);
324
                                echo "</td></tr>";
325
        
326
        
327
                                
328
        
329
                                echo "<tr><td>".$LANG["setup"][88].":         </td><td>\n";
330
                                dropdownValue("glpi_dropdown_network", "network", $this->fields["network"]);
331
                                echo "</td></tr>\n";
332
        
333
                                echo "<tr><td>".$LANG["setup"][89].":         </td><td>\n";
334
                                dropdownValue("glpi_dropdown_domain", "domain", $this->fields["domain"]);
335
                                echo "</td></tr>\n";
336
        
337
        
338
                                echo "</table>"; // fin table indentification
339
        
340
                                echo "</td>\n";        
341
                                echo "<td class='tab_bg_1' valign='top'>\n";
342
        
343
                                // table type,serial..
344
                                echo "<table cellpadding='1' cellspacing='0' border='0'>\n";
345
        
346
                                echo "<tr><td>".$LANG["state"][0].":</td><td>\n";
347
                                dropdownValue("glpi_dropdown_state", "state",$this->fields["state"]);
348
                                echo "</td></tr>\n";
349
        
350
                                echo "<tr><td>".$LANG["common"][17].":         </td><td>\n";
351
                                dropdownValue("glpi_type_printers", "type", $this->fields["type"]);
352
                                echo "</td></tr>\n";
353
        
354
                                echo "<tr><td>".$LANG["common"][22].":         </td><td>";
355
                                dropdownValue("glpi_dropdown_model_printers", "model", $this->fields["model"]);
356
                                echo "</td></tr>";
357
        
358
                                echo "<tr><td>".$LANG["common"][19].":        </td><td>\n";
359
                                autocompletionTextField("serial","glpi_printers","serial",$this->fields["serial"],20,$this->fields["FK_entities"]);        
360
                                echo "</td></tr>\n";
361
        
362
                                echo "<tr><td>".$LANG["common"][20].($template?"*":"").":</td><td>\n";
363
                                $objectName = autoName($this->fields["otherserial"], "otherserial", ($template === "newcomp"), PRINTER_TYPE,$this->fields["FK_entities"]);
364
                                autocompletionTextField("otherserial","glpi_printers","otherserial",$objectName,20,$this->fields["FK_entities"]);
365
                                echo "</td></tr>\n";
366
        
367
                                echo "<tr><td>".$LANG["printers"][18].": </td><td>\n";
368
        
369
                                // serial interface?
370
                                echo "<table border='0' cellpadding='2' cellspacing='0'><tr>\n";
371
                                echo "<td>".$LANG["printers"][14]."</td>\n";
372
                                echo "<td>";
373
                                dropdownYesNo("flags_serial",$this->fields["flags_serial"]);
374
                                echo "</td>";
375
                                echo "</tr></table>\n";
376
        
377
                                // parallel interface?
378
                                echo "<table border='0' cellpadding='2' cellspacing='0'><tr>\n";
379
                                echo "<td>".$LANG["printers"][15]."</td>\n";
380
                                echo "<td>";
381
                                dropdownYesNo("flags_par",$this->fields["flags_par"]);
382
                                echo "</td>";
383
        
384
                                echo "</tr></table>\n";
385
        
386
                                // USB ?
387
                                echo "<table border='0' cellpadding='2' cellspacing='0'><tr>\n";
388
                                echo "<td>".$LANG["printers"][27]."</td>\n";
389
                                echo "<td>";
390
                                dropdownYesNo("flags_usb",$this->fields["flags_usb"]);
391
                                echo "</td>";
392
        
393
                                echo "</tr></table>\n";
394
        
395
                                // Ram ?
396
                                echo "<tr><td>".$LANG["devices"][6].":</td><td>\n";
397
                                autocompletionTextField("ramSize","glpi_printers","ramSize",$this->fields["ramSize"],20,$this->fields["FK_entities"]);
398
                                echo "</td></tr>\n";
399
                                // Initial count pages ?
400
                                echo "<tr><td>".$LANG["printers"][30].":</td><td>\n";
401
                                autocompletionTextField("initial_pages","glpi_printers","initial_pages",$this->fields["initial_pages"],20,$this->fields["FK_entities"]);                
402
                                echo "</td></tr>\n";
403
        
404
        
405
                                echo "<tr><td>".$LANG["peripherals"][33].":</td><td>";
406
                                globalManagementDropdown($target,$withtemplate,$this->fields["ID"],$this->fields["is_global"],$CFG_GLPI["printers_management_restrict"]);
407
                                echo "</td></tr>";
408
        
409
                                echo "</table>\n";
410
                                echo "</td>\n";        
411
                                echo "</tr>\n";
412
        
413
                                echo "<tr>\n";
414
                                echo "<td class='tab_bg_1' valign='top' colspan='2'>\n";
415
        
416
                                // table commentaires
417
                                echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td valign='top'>\n";
418
                                echo $LANG["common"][25].":        </td>\n";
419
                                echo "<td class='center'><textarea cols='35' rows='4' name='comments' >".$this->fields["comments"]."</textarea>\n";
420
                                echo "</td></tr></table>\n";
421
        
422
                                echo "</td>\n";
423
                                echo "</tr>\n";
424
                                if ($use_cache){
425
                                        $CFG_GLPI["cache"]->end();
426
                                }
427
                        }
428

    
429

    
430

    
431
                        if (haveRight("printer","w")){
432
                                echo "<tr>\n";
433

    
434
                                if ($template) {
435

    
436
                                        if (empty($ID)||$withtemplate==2){
437
                                                echo "<td class='tab_bg_2' align='center' colspan='2'>\n";
438
                                                echo "<input type='hidden' name='ID' value=$ID>";
439
                                                echo "<input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'>";
440
                                                echo "</td>\n";
441
                                        } else {
442
                                                echo "<td class='tab_bg_2' align='center' colspan='2'>\n";
443
                                                echo "<input type='hidden' name='ID' value=$ID>";
444
                                                echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>";
445
                                                echo "</td>\n";
446
                                        }
447

    
448
                                } else {
449

    
450
                                        echo "<td class='tab_bg_2' valign='top' align='center'>";
451
                                        echo "<input type='hidden' name='ID' value=\"$ID\">\n";
452
                                        echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>";
453
                                        echo "</td>\n\n";
454
                                        echo "<td class='tab_bg_2' valign='top' align='center'>\n";
455
                                        echo "<div class='center'>";
456
                                        if (!$this->fields["deleted"])
457
                                                echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>";
458
                                        else {
459
                                                echo "<input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>";
460

    
461
                                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'>";
462
                                        }
463
                                        echo "</div>";
464
                                        echo "</td>";
465

    
466
                                }
467
                                echo "</tr>";
468
                        }
469
                        echo "</table></form></div>";
470

    
471
                        return true;        
472
                }
473
                else {
474
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
475
                        return false;
476
                }
477

    
478
        }
479

    
480

    
481

    
482

    
483
}
484

    
485
?>
Redmine Appliance - Powered by TurnKey Linux