Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / inc / computer.function.php @ b67d8923

Historique | Voir | Annoter | Télécharger (7,89 ko)

1
<?php
2
/*
3
 * @version $Id: computer.function.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
// FUNCTIONS Computers
41

    
42

    
43
/**
44
 * Test if a field is a dropdown
45
 *
46
 * Return true if the field $field is a dropdown 
47
 * or false if not.
48
 *
49
 *@param $field string field name
50
 *
51
 *
52
 *@return bool
53
 *
54
 **/
55
function IsDropdown($field) {
56
        $dropdown = array("netpoint","os","model");
57
        if(in_array($field,$dropdown)) {
58
                return true;
59
        }
60
        else  {
61
                return false;
62
        }
63
}
64
/**
65
 * Test if a field is a device
66
 *
67
 * Return true if the field $field is a device 
68
 * or false if not.
69
 *
70
 *@param $field string device name
71
 *
72
 *
73
 *@return bool
74
 *
75
 **/
76
function IsDevice($field) {
77
        global $CFG_GLPI;
78
        if(in_array($field,$CFG_GLPI["devices_tables"])) {
79
                return true;
80
        }
81
        else  {
82
                return false;
83
        }
84
}
85

    
86

    
87
/**
88
 * Print the form for devices linked to a computer or a template
89
 *
90
 *
91
 * Print the form for devices linked to a computer or a template 
92
 *
93
 *@param $target filename : where to go when done.
94
 *@param $ID Integer : Id of the computer or the template to print
95
 *@param $withtemplate='' boolean : template or basic computer
96
 *
97
 *
98
 *@return Nothing (display)
99
 *
100
 **/
101
function showDeviceComputerForm($target,$ID,$withtemplate='') {
102
        global $LANG,$CFG_GLPI;
103

    
104
        if (!haveRight("computer","r")) return false;
105
        $canedit=haveRight("computer","w");
106

    
107
        $comp = new Computer;
108
        if(empty($ID) && $withtemplate == 1) {
109
                $comp->getEmpty();
110
        } else {
111
                $comp->getFromDBwithDevices($ID);
112
        }
113

    
114
        if (!empty($ID)){
115
                //print devices.
116
                if (!($CFG_GLPI["cache"]->start("device_".$ID."_".$_SESSION["glpilanguage"],"GLPI_".COMPUTER_TYPE))) {
117
                        echo "<div class='center'>";
118
                        echo "<form name='form_device_action' action=\"$target\" method=\"post\" >";
119
                        echo "<input type='hidden' name='ID' value='$ID'>";        
120
                        echo "<input type='hidden' name='device_action' value='$ID'>";                        
121
                        echo "<table class='tab_cadre_fixe' >";
122
                        echo "<tr><th colspan='65'>".$LANG["title"][30]."</th></tr>";
123
                        foreach($comp->devices as $key => $val) {
124
                                $device = new Device($val["devType"]);
125
                                $device->getFromDB($val["devID"]);
126
                                printDeviceComputer($device,$val["quantity"],$val["specificity"],$comp->fields["ID"],$val["compDevID"],$withtemplate);
127
        
128
                        }
129
                        $CFG_GLPI["cache"]->end();
130
                }
131
                if ($canedit&&!(!empty($withtemplate) && $withtemplate == 2)&&count($comp->devices))
132
                        echo "<tr><td colspan='65' align='center' class='tab_bg_1'><input type='submit' class='submit' name='update_device' value='".$LANG["buttons"][7]."'></td></tr>";
133
                echo "</table>";
134

    
135
                echo "</form>";
136
                //ADD a new device form.
137
                device_selecter($_SERVER['PHP_SELF'],$comp->fields["ID"],$withtemplate);
138
                echo "</div>";
139
        }        
140

    
141

    
142
}
143

    
144
/**
145
 * Print the computers or template local connections form. 
146
 *
147
 * Print the form for computers or templates connections to printers, screens or peripherals
148
 *
149
 *@param $target 
150
 *@param $ID integer: Computer or template ID
151
 *@param $withtemplate=''  boolean : Template or basic item.
152
 *
153
 *@return Nothing (call to classes members)
154
 *
155
 **/
156
function showConnections($target,$ID,$withtemplate='') {
157

    
158
        global $DB,$CFG_GLPI, $LANG,$INFOFORM_PAGES;
159

    
160

    
161
        $ci=new CommonItem;
162

    
163
        $items=array(PRINTER_TYPE=>$LANG["computers"][39],MONITOR_TYPE=>$LANG["computers"][40],PERIPHERAL_TYPE=>$LANG["computers"][46],PHONE_TYPE=>$LANG["computers"][55]);
164
        $comp=new Computer();
165
        $canedit=haveTypeRight(COMPUTER_TYPE,"w");
166

    
167
        if ($comp->getFromDB($ID)){
168

    
169
                foreach ($items as $type => $title){
170
                        if (!haveTypeRight($type,"r")) unset($items[$type]);
171
        
172
                }
173
                if (count($items)){
174
                        echo "&nbsp;<div class='center'><table class='tab_cadre_fixe'>";
175
        
176
                        echo "<tr><th colspan='".max(2,count($items))."'>".$LANG["connect"][0].":</th></tr>";
177
        
178
                        echo "<tr>";
179
                        $header_displayed=0;
180

    
181
                        foreach ($items as $type => $title){
182

    
183
                                if ($header_displayed==2){
184
                                        break;
185
                                }
186
                                echo "<th>".$title.":</th>";
187
                                $header_displayed++;
188
                        }
189
                        echo "</tr>";
190
                        echo "<tr class='tab_bg_1'>";
191
                        $items_displayed=0;
192
                        foreach ($items as $type=>$title){
193
                                if ($items_displayed==2){
194
                                        
195
                                        echo "</tr><tr>";
196
                                        $header_displayed=0;
197
                                        foreach ($items as $tmp_title){
198
                                                if ($header_displayed>=2){
199
                                                        echo "<th>".$tmp_title.":</th>";
200
                                                }
201
                                                $header_displayed++;
202
                                        }
203

    
204
                                        echo "</tr><tr class='tab_bg_1'>";
205
                                }
206
                                echo "<td class='center'>";
207
                                $query = "SELECT * FROM glpi_connect_wire WHERE end2='$ID' AND type='".$type."'";
208
                                if ($result=$DB->query($query)) {
209
                                        $resultnum = $DB->numrows($result);
210
                                        if ($resultnum>0) {
211
                                                echo "<table width='100%'>";
212
                                                for ($i=0; $i < $resultnum; $i++) {
213
                                                        $tID = $DB->result($result, $i, "end1");
214
                                                        $connID = $DB->result($result, $i, "ID");
215
                                                        $ci->getFromDB($type,$tID);
216
        
217
                                                        echo "<tr ".($ci->getField('deleted')?"class='tab_bg_2_2'":"").">";
218
                                                        echo "<td class='center'><strong>";
219
                                                        echo $ci->getLink();
220
                                                        echo "</strong>";
221
                                                        echo " - ".getDropdownName("glpi_dropdown_state",$ci->getField('state'));
222
        
223
                                                        echo "</td><td>".$ci->getField('serial');
224
                                                        echo "</td><td>".$ci->getField('otherserial');
225
                                                        echo "</td><td>";
226
                                                        if($canedit&&(empty($withtemplate) || $withtemplate != 2)) {
227
                                                                echo "<td class='center'><a         href=\"".$CFG_GLPI["root_doc"]."/front/computer.form.php?cID=$ID&amp;ID=$connID&amp;disconnect=1&amp;withtemplate=".$withtemplate."\"><strong>";
228
                                                                echo $LANG["buttons"][10];
229
                                                                echo "</strong></a></td>";
230
                                                        }
231
                                                        echo "</tr>";
232
                                                }
233
                                                echo "</table>";
234
                                        } else {
235
                                                switch ($type){
236
                                                        case PRINTER_TYPE:
237
                                                                echo $LANG["computers"][38];
238
                                                                break;
239
                                                        case MONITOR_TYPE:
240
                                                                echo $LANG["computers"][37];
241
                                                                break;
242
                                                        case PERIPHERAL_TYPE:
243
                                                                echo $LANG["computers"][47];
244
                                                                break;
245
                                                        case PHONE_TYPE:
246
                                                                echo $LANG["computers"][54];
247
                                                                break;
248
                                                }
249
                                                echo "<br>";
250
                                        }
251
                                        if ($canedit){
252
                                                if(empty($withtemplate) || $withtemplate != 2) {
253
                                                        echo "<form method='post' action=\"$target\">";
254
                                                        echo "<input type='hidden' name='connect' value='connect'>";
255
                                                        echo "<input type='hidden' name='cID' value='$ID'>";
256
                                                        echo "<input type='hidden' name='device_type' value='".$type."'>";
257
                                                        if (empty($withtemplate)){
258
                                                                echo "<input type='hidden' name='dohistory' value='1'>";
259
                                                        } else { // No history for template
260
                                                                echo "<input type='hidden' name='dohistory' value='0'>";
261
                                                        }
262
                                                        dropdownConnect($type,COMPUTER_TYPE,"item",$comp->fields["FK_entities"],$withtemplate);
263
                                                        echo "<input type='submit' value=\"".$LANG["buttons"][9]."\" class='submit'>";
264
                                                        echo "</form>";
265
                                                }
266
                                        }
267
                                }
268
                                echo "</td>";
269
                                $items_displayed++;
270
                        }
271
        
272
                        echo "</tr>";
273
                        echo "</table></div><br>";
274
                }
275
        }
276
}
277

    
278

    
279

    
280

    
281
?>
Redmine Appliance - Powered by TurnKey Linux