Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

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

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

    
42

    
43
class Monitor extends CommonDBTM {
44

    
45

    
46
        /**
47
         * Constructor
48
        **/
49
        function Monitor () {
50
                $this->table="glpi_monitors";
51
                $this->type=MONITOR_TYPE;
52
                $this->dohistory=true;
53
        }        
54

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

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

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

    
85
                }        
86
                return $ong;
87
        }        
88

    
89
        function prepareInputForAdd($input) {
90

    
91
                if (isset($input["ID"])&&$input["ID"]>0){
92
                        $input["_oldID"]=$input["ID"];
93
                }
94

    
95
                if (isset($input["size"]) && $input["size"] == '')
96
                        unset($input["size"]);
97
                        
98
                unset($input['ID']);
99
                unset($input['withtemplate']);
100

    
101
                return $input;
102
        }
103

    
104

    
105
        function post_addItem($newID,$input) {
106
                global $DB;
107

    
108
                // Manage add from template
109
                if (isset($input["_oldID"])){
110
                        // ADD Infocoms
111
                        $ic= new Infocom();
112
                        if ($ic->getFromDBforDevice(MONITOR_TYPE,$input["_oldID"])){
113
                                $ic->fields["FK_device"]=$newID;
114
                                unset ($ic->fields["ID"]);
115
                                if (isset($ic->fields["num_immo"])) {
116
                                        $ic->fields["num_immo"] = autoName($ic->fields["num_immo"], "num_immo", 1, INFOCOM_TYPE, $input['FK_entities']);
117
                                }
118
        
119
                                $ic->addToDB();
120
                        }
121
        
122
                        // ADD Contract                                
123
                        $query="SELECT FK_contract from glpi_contract_device WHERE FK_device='".$input["_oldID"]."' AND device_type='".MONITOR_TYPE."';";
124
                        $result=$DB->query($query);
125
                        if ($DB->numrows($result)>0){
126
        
127
                                while ($data=$DB->fetch_array($result))
128
                                        addDeviceContract($data["FK_contract"],MONITOR_TYPE,$newID);
129
                        }
130
        
131
                        // ADD Documents                        
132
                        $query="SELECT FK_doc from glpi_doc_device WHERE FK_device='".$input["_oldID"]."' AND device_type='".MONITOR_TYPE."';";
133
                        $result=$DB->query($query);
134
                        if ($DB->numrows($result)>0){
135
        
136
                                while ($data=$DB->fetch_array($result))
137
                                        addDeviceDocument($data["FK_doc"],MONITOR_TYPE,$newID);
138
                        }
139
                }
140

    
141
        }
142

    
143
        function cleanDBonPurge($ID) {
144

    
145
                global $DB,$CFG_GLPI;
146

    
147
                $job =new Job();
148
                $query = "SELECT * FROM glpi_tracking WHERE (computer = '$ID'  AND device_type='".MONITOR_TYPE."')";
149
                $result = $DB->query($query);
150

    
151
                if ($DB->numrows($result))
152
                        while ($data=$DB->fetch_array($result)) {
153
                                if ($CFG_GLPI["keep_tracking_on_delete"]==1){
154
                                        $query = "UPDATE glpi_tracking SET computer = '0', device_type='0' WHERE ID='".$data["ID"]."';";
155
                                        $DB->query($query);
156
                                } else $job->delete(array("ID"=>$data["ID"]));
157
                        }
158

    
159
                $query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='".MONITOR_TYPE."')";
160
                $DB->query($query);
161

    
162
                $query="SELECT * FROM glpi_reservation_item WHERE (device_type='".MONITOR_TYPE."' and id_device='$ID')";
163
                if ($result = $DB->query($query)) {
164
                        if ($DB->numrows($result)>0) {
165
                                $rr=new ReservationItem();
166
                                $rr->delete(array("ID"=>$DB->result($result,0,"ID")));
167
                        }
168
                }
169

    
170
                $query="SELECT * FROM glpi_connect_wire WHERE (type='".MONITOR_TYPE."' AND end1='$ID')";
171
                if ($result = $DB->query($query)) {
172
                        if ($DB->numrows($result)>0) {
173
                                while ($data = $DB->fetch_array($result)){
174
                                        // Disconnect without auto actions
175
                                        Disconnect($data["ID"],1,false);
176
                                }
177
                        }
178
                }
179

    
180

    
181
                $query = "DELETE FROM glpi_contract_device WHERE (FK_device = '$ID' AND device_type='".MONITOR_TYPE."')";
182
                $DB->query($query);
183
        }
184

    
185
        /**
186
         * Print the monitor form
187
         *
188
         *@param $target filename : where to go when done.
189
         *@param $ID Integer : Id of the item to print
190
         *@param $withtemplate integer template or basic item
191
         *
192
         *@return boolean item found
193
         **/
194
        function showForm ($target,$ID,$withtemplate='') {
195

    
196
                global $CFG_GLPI, $LANG;
197

    
198
                if (!haveRight("monitor","r")) return false;
199

    
200

    
201
                $mon_spotted = false;
202
                $use_cache=true;
203
                if((empty($ID) && $withtemplate == 1)||$ID==-1) {
204
                        $use_cache=false;
205
                        if($this->getEmpty()) $mon_spotted = true;
206

    
207
                } else {
208
                        if($this->getFromDB($ID)&&haveAccessToEntity($this->fields["FK_entities"])) $mon_spotted = true;
209
                }
210

    
211
                if($mon_spotted) {
212
                        $this->showOnglets($ID, $withtemplate,$_SESSION['glpi_onglet']);
213
        
214
                        if(!empty($withtemplate) && $withtemplate == 2) {
215
                                $use_cache=false;
216
                                $template = "newcomp";
217
                                $datestring = $LANG["computers"][14].": ";
218
                                $date = convDateTime($_SESSION["glpi_currenttime"]);
219
                        } elseif(!empty($withtemplate) && $withtemplate == 1) { 
220
                                $use_cache=false;
221
                                $template = "newtemplate";
222
                                $datestring = $LANG["computers"][14].": ";
223
                                $date = convDateTime($_SESSION["glpi_currenttime"]);
224
                        } else {
225
                                $datestring = $LANG["common"][26]." : ";
226
                                $date = convDateTime($this->fields["date_mod"]);
227
                                $template = false;
228
                        }
229

    
230
                        echo "<div class='center'><form method='post' name=form action=\"$target\">";
231
                        if(strcmp($template,"newtemplate") === 0) {
232
                                echo "<input type=\"hidden\" name=\"is_template\" value=\"1\" />";
233
                        }
234

    
235
                        echo "<input type='hidden' name='FK_entities' value='".$this->fields["FK_entities"]."'>";
236

    
237
                        echo "<table  class='tab_cadre_fixe' cellpadding='2'>";
238

    
239
                        echo "<tr><th align='center' >";
240
                        if(!$template) {
241
                                echo $LANG["common"][2]." ".$this->fields["ID"];
242
                        }elseif (strcmp($template,"newcomp") === 0) {
243
                                echo $LANG["monitors"][30].": ".$this->fields["tplname"];
244
                                echo "<input type='hidden' name='tplname' value='".$this->fields["tplname"]."'>";
245
                        }elseif (strcmp($template,"newtemplate") === 0) {
246
                                echo $LANG["common"][6]."&nbsp;: ";
247
                                autocompletionTextField("tplname","glpi_monitors","tplname",$this->fields["tplname"],20,$this->fields["FK_entities"]);        
248
                        }
249
                        if (isMultiEntitiesMode()){
250
                                echo "&nbsp;(".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")";
251
                        }
252

    
253
                        echo "</th><th  align='center'>".$datestring.$date;
254
                        if (!$template&&!empty($this->fields['tplname']))
255
                                echo "&nbsp;&nbsp;&nbsp;(".$LANG["common"][13].": ".$this->fields['tplname'].")";
256
                        echo "</th></tr>";
257

    
258
                        if (!$use_cache||!($CFG_GLPI["cache"]->start($ID."_".$_SESSION["glpilanguage"],"GLPI_".$this->type))) {
259
                                echo "<tr><td class='tab_bg_1' valign='top'>";
260
        
261
                                echo "<table cellpadding='1' cellspacing='0' border='0'>\n";
262
        
263
                                echo "<tr><td>".$LANG["common"][16].($template?"*":"").":        </td>";
264
                                echo "<td>";
265
                                $objectName = autoName($this->fields["name"], "name", ($template === "newcomp"), MONITOR_TYPE,$this->fields["FK_entities"]);
266
                                autocompletionTextField("name","glpi_monitors","name",$objectName,20,$this->fields["FK_entities"]);
267
        
268
                                echo "</td></tr>";
269
        
270
                                echo "<tr><td>".$LANG["common"][15].":         </td><td>";
271
                                dropdownValue("glpi_dropdown_locations", "location", $this->fields["location"],1,$this->fields["FK_entities"]);
272
                                echo "</td></tr>";
273
        
274
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][10].":         </td><td colspan='2'>";
275
                                dropdownUsersID("tech_num", $this->fields["tech_num"],"interface",1,$this->fields["FK_entities"]);
276
                                echo "</td></tr>";
277
        
278
                                echo "<tr class='tab_bg_1'><td>".$LANG["common"][5].":         </td><td colspan='2'>";
279
                                dropdownValue("glpi_dropdown_manufacturer","FK_glpi_enterprise",$this->fields["FK_glpi_enterprise"]);
280
                                echo "</td></tr>";
281
        
282
                                echo "<tr><td>".$LANG["common"][21].":        </td>";
283
                                echo "<td>";
284
                                autocompletionTextField("contact_num","glpi_monitors","contact_num",$this->fields["contact_num"],20,$this->fields["FK_entities"]);        
285
                                echo "</td></tr>";
286
        
287
                                echo "<tr><td>".$LANG["common"][18].":        </td><td>";
288
                                autocompletionTextField("contact","glpi_monitors","contact",$this->fields["contact"],20,$this->fields["FK_entities"]);        
289
                                echo "</td></tr>";
290
        
291
                                echo "<tr><td>".$LANG["common"][34].":         </td><td>";
292
                                dropdownAllUsers("FK_users", $this->fields["FK_users"],1,$this->fields["FK_entities"]);
293
                                echo "</td></tr>";
294
        
295
                                echo "<tr><td>".$LANG["common"][35].":         </td><td>";
296
                                dropdownValue("glpi_groups", "FK_groups", $this->fields["FK_groups"],1,$this->fields["FK_entities"]);
297
                                echo "</td></tr>";
298
        
299
                                echo "<tr><td>".$LANG["state"][0].":</td><td>";
300
                                dropdownValue("glpi_dropdown_state", "state",$this->fields["state"]);
301
                                echo "</td></tr>";
302
                                
303
                                echo "</table>";
304
        
305
                                echo "</td>\n";        
306
                                echo "<td class='tab_bg_1' valign='top'>";
307
        
308
                                echo "<table cellpadding='1' cellspacing='0' border='0'";
309
        
310
                                echo "<tr><td>".$LANG["peripherals"][33].":</td><td>";
311
                                globalManagementDropdown($target,$withtemplate,$this->fields["ID"],$this->fields["is_global"],$CFG_GLPI["monitors_management_restrict"]);
312
                                echo "</td></tr>";
313
                                        
314
                                echo "<tr><td>".$LANG["common"][17].":         </td><td>";
315
                                dropdownValue("glpi_type_monitors", "type", $this->fields["type"]);
316
                                echo "</td></tr>";
317
        
318
                                echo "<tr><td>".$LANG["common"][22].":         </td><td>";
319
                                dropdownValue("glpi_dropdown_model_monitors", "model", $this->fields["model"]);
320
                                echo "</td></tr>";
321
        
322
                                echo "<tr><td>".$LANG["common"][19].":        </td><td>";
323
                                autocompletionTextField("serial","glpi_monitors","serial",$this->fields["serial"],20,$this->fields["FK_entities"]);
324
                                echo "</td></tr>";
325
        
326
                                echo "<tr><td>".$LANG["common"][20].($template?"*":"").":</td><td>";
327
                                $objectName = autoName($this->fields["otherserial"], "otherserial", ($template === "newcomp"), MONITOR_TYPE,$this->fields["FK_entities"]);
328
                                autocompletionTextField("otherserial","glpi_monitors","otherserial",$objectName,20,$this->fields["FK_entities"]);
329
        
330
                                echo "</td></tr>";
331
        
332
                                echo "<tr><td>".$LANG["monitors"][21].":</td>";
333
                                echo "<td>";
334
                                autocompletionTextField("size","glpi_monitors","size",$this->fields["size"],2,$this->fields["FK_entities"]);        
335
                                echo "\"</td></tr>";
336
        
337
                                echo "<tr><td>".$LANG["monitors"][18].": </td><td>";
338
        
339
                                // micro?
340
                                echo "<table border='0' cellpadding='2' cellspacing='0'><tr>";
341
                                echo "<td>".$LANG["monitors"][14]."</td>";
342
                                echo "<td>";
343
                                dropdownYesNo("flags_micro",$this->fields["flags_micro"]);
344
                                echo "</td>";
345
        
346
                                // speakers?
347
                                echo "<td>".$LANG["monitors"][15]."</td>";
348
                                echo "<td>";
349
                                dropdownYesNo("flags_speaker",$this->fields["flags_speaker"]);
350
                                echo "</td>";
351
                                echo "</tr><tr>";
352
        
353
                                // sub-d?
354
                                echo "<td>".$LANG["monitors"][19]."</td>";
355
                                echo "<td>";
356
                                dropdownYesNo("flags_subd",$this->fields["flags_subd"]);
357
                                echo "</td>";
358
        
359
                                // bnc?
360
                                echo "<td>".$LANG["monitors"][20]."</td>";
361
                                echo "<td>";
362
                                dropdownYesNo("flags_bnc",$this->fields["flags_bnc"]);
363
                                echo "</td>";
364
        
365
                                echo "</tr><tr>";
366
        
367
                                // dvi?
368
                                echo "<td>".$LANG["monitors"][32]."</td>";
369
                                echo "<td>";
370
                                dropdownYesNo("flags_dvi",$this->fields["flags_dvi"]);
371
                                echo "</td>";
372
        
373
                                // pivot ?
374
                                echo "<td>".$LANG["monitors"][33]."</td>";
375
                                echo "<td>";
376
                                dropdownYesNo("flags_pivot",$this->fields["flags_pivot"]);
377
                                echo "</td>";
378

    
379
                                echo "</tr></table>";
380
        
381
                                echo "</td></tr>";
382
        
383
                                echo "</table>";
384
                                echo "</td>\n";        
385
                                echo "</tr>";
386
                                echo "<tr>";
387
                                echo "<td class='tab_bg_1' valign='top' colspan='2'>";
388
        
389
                                echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><td valign='top'>";
390
                                echo $LANG["common"][25].":        </td>";
391
                                echo "<td class='center'><textarea cols='75' rows='4' name='comments' >".$this->fields["comments"]."</textarea>";
392
                                echo "</td></tr></table>";
393
        
394
                                echo "</td>";
395
                                echo "</tr>";
396
                                if ($use_cache){
397
                                        $CFG_GLPI["cache"]->end();
398
                                }
399
                        }
400

    
401
                        if (haveRight("monitor","w")){
402

    
403
                                echo "<tr>";
404

    
405
                                if ($template) {
406

    
407
                                        if (empty($ID)||$withtemplate==2){
408
                                                echo "<td class='tab_bg_2' align='center' colspan='2'>\n";
409
                                                echo "<input type='hidden' name='ID' value=$ID>";
410
                                                echo "<input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'>";
411
                                                echo "</td>\n";
412
                                        } else {
413
                                                echo "<td class='tab_bg_2' align='center' colspan='2'>\n";
414
                                                echo "<input type='hidden' name='ID' value=$ID>";
415
                                                echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>";
416
                                                echo "</td>\n";
417
                                        }
418
                                } else {
419

    
420
                                        echo "<td class='tab_bg_2' valign='top' align='center'>";
421
                                        echo "<input type='hidden' name='ID' value=\"$ID\">\n";
422
                                        echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>";
423
                                        echo "</td>\n\n";
424
                                        echo "<td class='tab_bg_2' valign='top'>\n";
425
                                        echo "<div class='center'>";
426
                                        if (!$this->fields["deleted"])
427
                                                echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>";
428
                                        else {
429
                                                echo "<input type='submit' name='restore' value=\"".$LANG["buttons"][21]."\" class='submit'>";
430

    
431
                                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='purge' value=\"".$LANG["buttons"][22]."\" class='submit'>";
432
                                        }
433
                                        echo "</div>";
434
                                        echo "</td>";
435
                                }
436
                                echo "</tr>";
437
                        }
438

    
439
                        echo "</table></form></div>";
440

    
441
                        return true;
442
                }
443
                else {
444
                        echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>";
445
                        return false;
446
                }
447

    
448

    
449

    
450
        }
451

    
452
}
453

    
454
?>
Redmine Appliance - Powered by TurnKey Linux