File: computer.function.php

package info (click to toggle)
glpi 0.68.2-1etch0.2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,476 kB
  • ctags: 9,739
  • sloc: php: 69,695; sql: 3,514; sh: 175; makefile: 61
file content (247 lines) | stat: -rw-r--r-- 6,929 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/*
 * @version $Id: computer.function.php 3881 2006-09-14 11:10:45Z moyo $
 -------------------------------------------------------------------------
 GLPI - Gestionnaire Libre de Parc Informatique
 Copyright (C) 2003-2006 by the INDEPNET Development Team.

 http://indepnet.net/   http://glpi-project.org
 -------------------------------------------------------------------------

 LICENSE

 This file is part of GLPI.

 GLPI is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 GLPI is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with GLPI; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 --------------------------------------------------------------------------
 */

// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------


// FUNCTIONS Computers


/**
 * Test if a field is a dropdown
 *
 * Return true if the field $field is a dropdown 
 * or false if not.
 *
 *@param $field string field name
 *
 *
 *@return bool
 *
 **/
function IsDropdown($field) {
	$dropdown = array("netpoint","os","model");
	if(in_array($field,$dropdown)) {
		return true;
	}
	else  {
		return false;
	}
}
/**
 * Test if a field is a device
 *
 * Return true if the field $field is a device 
 * or false if not.
 *
 *@param $field string device name
 *
 *
 *@return bool
 *
 **/
function IsDevice($field) {
	global $cfg_glpi;
	if(in_array($field,$cfg_glpi["devices_tables"])) {
		return true;
	}
	else  {
		return false;
	}
}


/**
 * Print the form for devices linked to a computer or a template
 *
 *
 * Print the form for devices linked to a computer or a template 
 *
 *@param $target filename : where to go when done.
 *@param $ID Integer : Id of the computer or the template to print
 *@param $withtemplate='' boolean : template or basic computer
 *
 *
 *@return Nothing (display)
 *
 **/
function showDeviceComputerForm($target,$ID,$withtemplate='') {
	global $lang;

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

	$comp = new Computer;
	if(empty($ID) && $withtemplate == 1) {
		$comp->getEmpty();
	} else {
		$comp->getfromDBwithDevices($ID);
	}

	if (!empty($ID)){
		//print devices.
		echo "<div align='center'>";
		echo "<form name='form_device_action' action=\"$target\" method=\"post\" >";
		echo "<input type='hidden' name='ID' value='$ID'>";	
		echo "<input type='hidden' name='device_action' value='$ID'>";			
		echo "<table class='tab_cadre_fixe' >";
		echo "<tr><th colspan='65'>".$lang["devices"][10]."</th></tr>";
		foreach($comp->devices as $key => $val) {
			$device = new Device($val["devType"]);
			$device->getFromDB($val["devID"]);
			printDeviceComputer($device,$val["quantity"],$val["specificity"],$comp->fields["ID"],$val["compDevID"],$withtemplate);

		}
		if ($canedit&&!(!empty($withtemplate) && $withtemplate == 2))
			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>";
		echo "</table>";

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


}

/**
 * Print the computers or template local connections form. 
 *
 * Print the form for computers or templates connections to printers, screens or peripherals
 *
 *@param $target 
 *@param $ID integer: Computer or template ID
 *@param $withtemplate=''  boolean : Template or basic item.
 *
 *@return Nothing (call to classes members)
 *
 **/
function showConnections($target,$ID,$withtemplate='') {

	global $db,$cfg_glpi, $lang,$INFOFORM_PAGES;


	$state=new StateItem();
	$ci=new CommonItem;

	$items=array(PRINTER_TYPE=>$lang["computers"][39],MONITOR_TYPE=>$lang["computers"][40],PERIPHERAL_TYPE=>$lang["computers"][46],PHONE_TYPE=>$lang["computers"][55]);


	foreach ($items as $type => $title){
		if (!haveTypeRight($type,"r")) unset($items[$type]);

	}
	if (count($items)){
		echo "&nbsp;<div align='center'><table class='tab_cadre_fixe'>";

		echo "<tr><th colspan='".count($items)."'>".$lang["connect"][0].":</th></tr>";

		echo "<tr>";
		foreach ($items as $type => $title)
			echo "<th>".$title.":</th>";
		echo "</tr>";

		echo "<tr class='tab_bg_1'>";

		foreach ($items as $type=>$title){
			$canedit=haveTypeRight($type,"w");

			echo "<td align='center'>";
			$query = "SELECT * from glpi_connect_wire WHERE end2='$ID' AND type='".$type."'";
			if ($result=$db->query($query)) {
				$resultnum = $db->numrows($result);
				if ($resultnum>0) {
					echo "<table width='100%'>";
					for ($i=0; $i < $resultnum; $i++) {
						$tID = $db->result($result, $i, "end1");
						$connID = $db->result($result, $i, "ID");
						$ci->getFromDB($type,$tID);

						echo "<tr ".($ci->obj->fields["deleted"]=='Y'?"class='tab_bg_2_2'":"").">";
						echo "<td align='center'><b>";
						echo $ci->getLink();
						echo "</b>";
						if ($state->getfromDB($type,$tID))
							echo " - ".getDropdownName("glpi_dropdown_state",$state->fields['state']);

						echo "</td>";
						if($canedit&&(empty($withtemplate) || $withtemplate != 2)) {
							echo "<td align='center'><a 	href=\"".$cfg_glpi["root_doc"]."/front/computer.form.php?cID=$ID&amp;ID=$connID&amp;disconnect=1amp;withtemplate=".$withtemplate."\"><b>";
							echo $lang["buttons"][10];
							echo "</b></a></td>";
						}
						echo "</tr>";
					}
					echo "</table>";
				} else {
					switch ($type){
						case PRINTER_TYPE:
							echo $lang["computers"][38];
							break;
						case MONITOR_TYPE:
							echo $lang["computers"][37];
							break;
						case PERIPHERAL_TYPE:
							echo $lang["computers"][47];
							break;
						case PHONE_TYPE:
							echo $lang["computers"][54];
							break;
					}
					echo "<br>";
				}
				if ($canedit)
					if(empty($withtemplate) || $withtemplate != 2) {
						echo "<form method='post' action=\"$target\">";
						echo "<input type='hidden' name='connect' value='connect'>";
						echo "<input type='hidden' name='cID' value='$ID'>";
						echo "<input type='hidden' name='device_type' value='".$type."'>";
						dropdownConnect($type,COMPUTER_TYPE,"item",$withtemplate);
						echo "<input type='submit' value=\"".$lang["buttons"][9]."\" class='submit'>";
						echo "</form>";
					}
			}
			echo "</td>";
		}

		echo "</tr>";
		echo "</table></div><br>";
	}

}




?>