ryxeo-glpi-git / htdocs / inc / ocsng.class.php @ 1c14bcc4
Historique | Voir | Annoter | Télécharger (27,3 ko)
1 | 1c14bcc4 | Eric Seigne | <?php
|
---|---|---|---|
2 | |||
3 | |||
4 | /*
|
||
5 | * @version $Id: ocsng.class.php 7763 2009-01-06 18:44:50Z moyo $
|
||
6 | -------------------------------------------------------------------------
|
||
7 | GLPI - Gestionnaire Libre de Parc Informatique
|
||
8 | Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
||
9 | |||
10 | http://indepnet.net/ http://glpi-project.org
|
||
11 | -------------------------------------------------------------------------
|
||
12 | |||
13 | LICENSE
|
||
14 | |||
15 | This file is part of GLPI.
|
||
16 | |||
17 | GLPI is free software; you can redistribute it and/or modify
|
||
18 | it under the terms of the GNU General Public License as published by
|
||
19 | the Free Software Foundation; either version 2 of the License, or
|
||
20 | (at your option) any later version.
|
||
21 | |||
22 | GLPI is distributed in the hope that it will be useful,
|
||
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
25 | GNU General Public License for more details.
|
||
26 | |||
27 | You should have received a copy of the GNU General Public License
|
||
28 | along with GLPI; if not, write to the Free Software
|
||
29 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
30 | --------------------------------------------------------------------------
|
||
31 | */
|
||
32 | |||
33 | if (!defined('GLPI_ROOT')) { |
||
34 | die("Sorry. You can't access directly to this file"); |
||
35 | } |
||
36 | |||
37 | /// DB class to connect to a OCS server
|
||
38 | class DBocs extends DBmysql { |
||
39 | |||
40 | ///Store the id of the ocs server
|
||
41 | var $ocs_server_id = -1; |
||
42 | |||
43 | /**
|
||
44 | * Constructor
|
||
45 | * @param $ID ID of the ocs server ID
|
||
46 | **/
|
||
47 | function DBocs($ID) { |
||
48 | global $CFG_GLPI; |
||
49 | $this->ocs_server_id = $ID; |
||
50 | |||
51 | if ($CFG_GLPI["ocs_mode"]) { |
||
52 | $data = getOcsConf($ID); |
||
53 | $this->dbhost = $data["ocs_db_host"]; |
||
54 | $this->dbuser = $data["ocs_db_user"]; |
||
55 | $this->dbpassword = rawurldecode($data["ocs_db_passwd"]); |
||
56 | $this->dbdefault = $data["ocs_db_name"]; |
||
57 | $this->dbenc="latin1"; |
||
58 | $this->DBmysql(); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /**
|
||
63 | * Get current ocs server ID
|
||
64 | * @return ID of the ocs server ID
|
||
65 | **/
|
||
66 | function getServerID() |
||
67 | { |
||
68 | return $this->ocs_server_id; |
||
69 | } |
||
70 | |||
71 | |||
72 | } |
||
73 | |||
74 | /// OCS config class
|
||
75 | class Ocsng extends CommonDBTM { |
||
76 | |||
77 | /**
|
||
78 | * Constructor
|
||
79 | **/
|
||
80 | function Ocsng() { |
||
81 | global $CFG_GLPI; |
||
82 | |||
83 | $this->table = "glpi_ocs_config"; |
||
84 | $this->type = OCSNG_TYPE; |
||
85 | } |
||
86 | |||
87 | /**
|
||
88 | * Print ocs config form
|
||
89 | *
|
||
90 | *@param $target form target
|
||
91 | *@param $ID Integer : Id of the ocs config
|
||
92 | *@param $withtemplate template or basic computer
|
||
93 | *@param $templateid Integer : Id of the template used
|
||
94 | *@todo clean template process
|
||
95 | *@return Nothing (display)
|
||
96 | *
|
||
97 | **/
|
||
98 | function ocsFormConfig($target, $ID,$withtemplate='',$templateid='') { |
||
99 | global $DB, $LANG, $CFG_GLPI; |
||
100 | |||
101 | if (!haveRight("ocsng", "w")) |
||
102 | return false; |
||
103 | |||
104 | $action =""; |
||
105 | if (!isset($withtemplate) || $withtemplate == "") |
||
106 | $action = "edit_server"; |
||
107 | elseif (isset($withtemplate) && $withtemplate ==1) |
||
108 | { |
||
109 | if ($ID == -1 && $templateid == '') |
||
110 | $action = "add_template"; |
||
111 | else
|
||
112 | $action = "update_template"; |
||
113 | } |
||
114 | elseif (isset($withtemplate) && $withtemplate ==2) |
||
115 | { |
||
116 | if ($templateid== '') |
||
117 | $action = "edit_server"; |
||
118 | elseif ($ID == -1) |
||
119 | $action = "add_server_with_template"; |
||
120 | else
|
||
121 | $action = "update_server_with_template"; |
||
122 | } |
||
123 | |||
124 | //Get datas
|
||
125 | switch($action) |
||
126 | { |
||
127 | case "update_server_with_template" : |
||
128 | |||
129 | //Get the template configuration
|
||
130 | $template_config = getOcsConf($templateid); |
||
131 | |||
132 | //Unset all the variable which are not in the template
|
||
133 | unset($template_config["ID"]); |
||
134 | unset($template_config["name"]); |
||
135 | unset($template_config["ocs_db_user"]); |
||
136 | unset($template_config["ocs_db_password"]); |
||
137 | unset($template_config["ocs_db_name"]); |
||
138 | unset($template_config["ocs_db_host"]); |
||
139 | unset($template_config["checksum"]); |
||
140 | |||
141 | //Add all the template's informations to the server's object'
|
||
142 | foreach ($template_config as $key => $value) |
||
143 | if ($value != "") $this->fields[$key] = $value; |
||
144 | break;
|
||
145 | case "edit_server" : |
||
146 | if (empty($ID)) |
||
147 | $this->getEmpty($ID); |
||
148 | else
|
||
149 | $this->getFromDB($ID); |
||
150 | break;
|
||
151 | case "add_template" : |
||
152 | $this->getEmpty($ID); |
||
153 | break;
|
||
154 | case "update_template" : |
||
155 | case "add_server_with_template" : |
||
156 | $this->getFromDB($templateid); |
||
157 | break;
|
||
158 | } |
||
159 | |||
160 | $datestring = $LANG["computers"][14].": "; |
||
161 | $date = convDateTime($_SESSION["glpi_currenttime"]); |
||
162 | |||
163 | echo "<form name='formconfig' action=\"$target\" method=\"post\">"; |
||
164 | echo "<input type='hidden' name='ID' value='" . $ID . "'>"; |
||
165 | |||
166 | echo "<div class='center'><table class='tab_cadre'>"; |
||
167 | |||
168 | //This is a new template, name must me supplied
|
||
169 | if($action == "add_template" || $action == "update_template") { |
||
170 | echo "<input type=\"hidden\" name=\"is_template\" value=\"1\">"; |
||
171 | echo "<input type=\"hidden\" name=\"withtemplate\" value=\"1\">"; |
||
172 | echo "<input type=\"hidden\" name=\"ID\" value=\"".$templateid."\">"; |
||
173 | } |
||
174 | if ($action == "add_template") |
||
175 | echo "<input type=\"hidden\" name=\"name\" value=\"\">"; |
||
176 | if ($action == "update_server_with_template") |
||
177 | echo "<input type=\"hidden\" name=\"tplname\" value=\"".$this->fields["tplname"]."\">"; |
||
178 | |||
179 | |||
180 | //If template, display a textfield to modify name
|
||
181 | if($action == "add_template" || $action == "update_template") { |
||
182 | echo "<tr><th align='center' colspan=2>"; |
||
183 | |||
184 | echo $LANG["common"][6]." : "; |
||
185 | autocompletionTextField("tplname","glpi_ocs_config","tplname",$this->fields["tplname"],20); |
||
186 | echo "</th></tr>"; |
||
187 | |||
188 | //Adding a new machine, just display the name, not editable
|
||
189 | } |
||
190 | elseif($action == "edit_server" || $action == "update_server_with_template") { |
||
191 | echo "<tr><th align='center'>"; |
||
192 | |||
193 | echo $LANG["ocsng"][28].": ".$this->fields["tplname"]; |
||
194 | echo "<input type='hidden' name='tplname' value='".$this->fields["tplname"]."'>"; |
||
195 | |||
196 | echo "</th>"; |
||
197 | |||
198 | echo "<th align='center'>".$datestring.$date."</th>"; |
||
199 | echo "</tr>"; |
||
200 | } |
||
201 | |||
202 | |||
203 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][59] . " </td><td> <input type=\"text\" size='30' name=\"ocs_url\" value=\"" . $this->fields["ocs_url"] . "\"></td></tr>"; |
||
204 | |||
205 | echo "<tr><th colspan='2'>" . $LANG["ocsconfig"][5] . "</th></tr>"; |
||
206 | |||
207 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][17] . " </td><td> <input type=\"text\" size='30' name=\"tag_limit\" value=\"" . $this->fields["tag_limit"] . "\"></td></tr>"; |
||
208 | |||
209 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][16] . " </td><td>"; |
||
210 | dropdownValue("glpi_dropdown_state", "default_state", $this->fields["default_state"]); |
||
211 | echo "</td></tr>"; |
||
212 | |||
213 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][48] . " </td><td>"; |
||
214 | //getListState($ID);
|
||
215 | dropdownArrayValues("deconnection_behavior",
|
||
216 | array(''=>$LANG["buttons"][49], "trash"=>$LANG["ocsconfig"][49], "delete"=>$LANG["ocsconfig"][50]), |
||
217 | $this->fields["deconnection_behavior"]); |
||
218 | echo "</td></tr>"; |
||
219 | |||
220 | $import_array = array("0"=>$LANG["ocsconfig"][11],"1"=>$LANG["ocsconfig"][10],"2"=>$LANG["ocsconfig"][12]); |
||
221 | $import_array2= array("0"=>$LANG["ocsconfig"][11],"1"=>$LANG["ocsconfig"][10],"2"=>$LANG["ocsconfig"][12],"3"=>$LANG["ocsconfig"][19]); |
||
222 | $periph = $this->fields["import_periph"]; |
||
223 | $monitor = $this->fields["import_monitor"]; |
||
224 | $printer = $this->fields["import_printer"]; |
||
225 | $software = $this->fields["import_software"]; |
||
226 | $license = $this->fields["import_software_licensetype"]; |
||
227 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["Menu"][16] . " </td><td>"; |
||
228 | dropdownArrayValues("import_periph",$import_array,$periph); |
||
229 | echo "</td></tr>"; |
||
230 | |||
231 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["Menu"][3] . " </td><td>"; |
||
232 | dropdownArrayValues("import_monitor",$import_array2,$monitor); |
||
233 | echo "</td></tr>"; |
||
234 | |||
235 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["Menu"][2] . " </td><td>"; |
||
236 | dropdownArrayValues("import_printer",$import_array,$printer); |
||
237 | echo "</td></tr>"; |
||
238 | |||
239 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["Menu"][4] . " </td><td>"; |
||
240 | $import_array = array("0"=>$LANG["ocsconfig"][11],"1"=>$LANG["ocsconfig"][12]); |
||
241 | dropdownArrayValues("import_software",$import_array,$software); |
||
242 | echo "</td></tr>"; |
||
243 | |||
244 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][44] . " </td><td>"; |
||
245 | $import_array=array("global"=>$LANG["ocsconfig"][45],"free"=>$LANG["ocsconfig"][46]); |
||
246 | dropdownArrayValues("import_software_licensetype",$import_array,$license); |
||
247 | echo "</td></tr>"; |
||
248 | |||
249 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][47] . " </td><td>"; |
||
250 | dropdownYesNo("import_software_buy", $this->fields["import_software_buy"]); |
||
251 | echo "</td></tr>"; |
||
252 | |||
253 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][38] . " </td><td>"; |
||
254 | dropdownYesNo("use_soft_dict", $this->fields["use_soft_dict"]); |
||
255 | echo "</td></tr>"; |
||
256 | |||
257 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][41] . " </td><td>"; |
||
258 | dropdownYesNo("import_registry", $this->fields["import_registry"]); |
||
259 | echo "</td></tr>"; |
||
260 | |||
261 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][40] . " </td><td>"; |
||
262 | dropdownInteger('cron_sync_number', $this->fields["cron_sync_number"], 0, 100); |
||
263 | echo "</td></tr>"; |
||
264 | |||
265 | echo "</table></div>"; |
||
266 | |||
267 | echo "<div class='center'>" . $LANG["ocsconfig"][15] . "</div>"; |
||
268 | echo "<div class='center'>" . $LANG["ocsconfig"][14] . "</div>"; |
||
269 | echo "<div class='center'>" . $LANG["ocsconfig"][13] . "</div>"; |
||
270 | |||
271 | echo "<br>"; |
||
272 | |||
273 | echo "<div class='center'><table class='tab_cadre'>"; |
||
274 | echo "<tr><th>" . $LANG["ocsconfig"][27] ." ".$LANG["Menu"][0]. "</th><th>" . $LANG["title"][30] . "</th><th>" . $LANG["ocsconfig"][43] . "</th></tr>"; |
||
275 | echo "<tr><td class='tab_bg_2' valign='top'><table width='100%' cellpadding='1' cellspacing='0' border='0'>"; |
||
276 | |||
277 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][16] . " </td><td>"; |
||
278 | dropdownYesNo("import_general_name", $this->fields["import_general_name"]); |
||
279 | echo "</td></tr>"; |
||
280 | |||
281 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["computers"][9] . " </td><td>"; |
||
282 | dropdownYesNo("import_general_os", $this->fields["import_general_os"]); |
||
283 | echo "</td></tr>"; |
||
284 | |||
285 | echo "<tr class='tab_bg_2'><td colspan='2'>"; |
||
286 | echo "</td></tr>"; |
||
287 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["computers"][10] . " </td><td>"; |
||
288 | dropdownYesNo("import_os_serial", $this->fields["import_os_serial"]); |
||
289 | echo "</td></tr>"; |
||
290 | |||
291 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][19] . " </td><td>"; |
||
292 | dropdownYesNo("import_general_serial", $this->fields["import_general_serial"]); |
||
293 | echo "</td></tr>"; |
||
294 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][22] . " </td><td>"; |
||
295 | dropdownYesNo("import_general_model", $this->fields["import_general_model"]); |
||
296 | echo "</td></tr>"; |
||
297 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][5] . " </td><td>"; |
||
298 | dropdownYesNo("import_general_enterprise", $this->fields["import_general_enterprise"]); |
||
299 | echo "</td></tr>"; |
||
300 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][17] . " </td><td>"; |
||
301 | dropdownYesNo("import_general_type", $this->fields["import_general_type"]); |
||
302 | echo "</td></tr>"; |
||
303 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][89] . " </td><td>"; |
||
304 | dropdownYesNo("import_general_domain", $this->fields["import_general_domain"]); |
||
305 | echo "</td></tr>"; |
||
306 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][18] . " </td><td>"; |
||
307 | dropdownYesNo("import_general_contact", $this->fields["import_general_contact"]); |
||
308 | echo "</td></tr>"; |
||
309 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][25] . " </td><td>"; |
||
310 | dropdownYesNo("import_general_comments", $this->fields["import_general_comments"]); |
||
311 | echo "</td></tr>"; |
||
312 | |||
313 | echo "<tr class='tab_bg_2'><td colspan='2'>"; |
||
314 | echo "</td></tr>"; |
||
315 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["networking"][14] . " </td><td>"; |
||
316 | dropdownYesNo("import_ip", $this->fields["import_ip"]); |
||
317 | echo "</td></tr>"; |
||
318 | |||
319 | echo "</table></td>"; |
||
320 | |||
321 | echo "<td class='tab_bg_2' valign='top'><table width='100%' cellpadding='1' cellspacing='0' border='0'>"; |
||
322 | |||
323 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["devices"][4] . " </td><td>"; |
||
324 | dropdownYesNo("import_device_processor", $this->fields["import_device_processor"]); |
||
325 | echo "</td></tr>"; |
||
326 | |||
327 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["devices"][6] . " </td><td>"; |
||
328 | dropdownYesNo("import_device_memory", $this->fields["import_device_memory"]); |
||
329 | echo "</td></tr>"; |
||
330 | |||
331 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["devices"][1] . " </td><td>"; |
||
332 | dropdownYesNo("import_device_hdd", $this->fields["import_device_hdd"]); |
||
333 | echo "</td></tr>"; |
||
334 | |||
335 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["devices"][3] . " </td><td>"; |
||
336 | dropdownYesNo("import_device_iface", $this->fields["import_device_iface"]); |
||
337 | echo "</td></tr>"; |
||
338 | |||
339 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["devices"][2] . " </td><td>"; |
||
340 | dropdownYesNo("import_device_gfxcard", $this->fields["import_device_gfxcard"]); |
||
341 | echo "</td></tr>"; |
||
342 | |||
343 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["devices"][7] . " </td><td>"; |
||
344 | dropdownYesNo("import_device_sound", $this->fields["import_device_sound"]); |
||
345 | echo "</td></tr>"; |
||
346 | |||
347 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["devices"][19] . " </td><td>"; |
||
348 | dropdownYesNo("import_device_drives", $this->fields["import_device_drives"]); |
||
349 | echo "</td></tr>"; |
||
350 | |||
351 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][36] . " </td><td>"; |
||
352 | dropdownYesNo("import_device_modems", $this->fields["import_device_modems"]); |
||
353 | echo "</td></tr>"; |
||
354 | |||
355 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][37] . " </td><td>"; |
||
356 | dropdownYesNo("import_device_ports", $this->fields["import_device_ports"]); |
||
357 | echo "</td></tr>"; |
||
358 | |||
359 | echo "</table></td><td class='tab_bg_2' valign='top'><table width='100%' cellpadding='1' cellspacing='0' border='0'>"; |
||
360 | |||
361 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][20] . " </td><td>"; |
||
362 | echo "<select name='import_otherserial'>"; echo "<option value=''>" . $LANG["ocsconfig"][11] . "</option>"; |
||
363 | $listColumnOCS = getColumnListFromAccountInfoTable($ID,"otherserial"); |
||
364 | echo $listColumnOCS; |
||
365 | echo "</select>"; |
||
366 | echo "</td></tr>"; |
||
367 | |||
368 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][15] . " </td><td>"; |
||
369 | echo "<select name='import_location'>"; echo "<option value=''>" . $LANG["ocsconfig"][11] . "</option>"; |
||
370 | $listColumnOCS = getColumnListFromAccountInfoTable($ID,"location"); |
||
371 | echo $listColumnOCS; |
||
372 | echo "</select>"; |
||
373 | echo "</td></tr>"; |
||
374 | |||
375 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][35] . " </td><td>"; |
||
376 | echo "<select name='import_group'>"; echo "<option value=''>" . $LANG["ocsconfig"][11] . "</option>"; |
||
377 | $listColumnOCS = getColumnListFromAccountInfoTable($ID,"FK_groups"); |
||
378 | echo $listColumnOCS; |
||
379 | echo "</select>"; |
||
380 | echo "</td></tr>"; |
||
381 | |||
382 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][21] . " </td><td>"; |
||
383 | echo "<select name='import_contact_num'>"; echo "<option value=''>" . $LANG["ocsconfig"][11] . "</option>"; |
||
384 | $listColumnOCS = getColumnListFromAccountInfoTable($ID,"contact_num"); |
||
385 | echo $listColumnOCS; |
||
386 | echo "</select>"; |
||
387 | echo "</td></tr>"; |
||
388 | |||
389 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][88] . " </td><td>"; |
||
390 | echo "<select name='import_network'>"; echo "<option value=''>" . $LANG["ocsconfig"][11] . "</option>"; |
||
391 | $listColumnOCS = getColumnListFromAccountInfoTable($ID,"network"); |
||
392 | echo $listColumnOCS; |
||
393 | echo "</select>"; |
||
394 | echo "</td></tr>"; |
||
395 | |||
396 | echo "</table></td>"; |
||
397 | echo "</tr>"; |
||
398 | |||
399 | echo "<tr><th>" . $LANG["ocsconfig"][27] ." ".$LANG["Menu"][3]. "</th><th>" . $LANG["ocsconfig"][27] ." ".$LANG["Menu"][4] . "</th><th> </th></tr>"; |
||
400 | |||
401 | echo "<tr><td class='tab_bg_2' valign='top'><table width='100%' cellpadding='1' cellspacing='0' border='0'>"; |
||
402 | echo "<tr class='tab_bg_2'><td align='center'>" . $LANG["common"][25] . " </td><td>"; |
||
403 | dropdownYesNo("import_monitor_comments", $this->fields["import_monitor_comments"]); |
||
404 | echo "</td></tr>"; |
||
405 | echo "</table></td>"; |
||
406 | |||
407 | echo "<td class='tab_bg_2' valign='top'><table width='100%' cellpadding='1' cellspacing='0' border='0'>"; |
||
408 | echo "<tr class='tab_bg_2'><td align='center'>" . $LANG["common"][25] . " </td><td>"; |
||
409 | dropdownYesNo("import_software_comments", $this->fields["import_software_comments"]); |
||
410 | echo "</td></tr>"; |
||
411 | echo "</table></td>"; |
||
412 | echo "<td class='tab_bg_2' valign='top'></td></tr>"; |
||
413 | |||
414 | echo "</table></div>"; |
||
415 | |||
416 | echo "<br><div class='center'><table class='tab_cadre'>"; |
||
417 | echo "<tr><th colspan='4'>" . $LANG["ocsconfig"][52] . "</th></tr>"; |
||
418 | echo "<tr class='tab_bg_2'><td>" . $LANG["ocsconfig"][53] . " </td><td>"; |
||
419 | dropdownYesNo("glpi_link_enabled", $this->fields["glpi_link_enabled"]); |
||
420 | echo "</td><td colspan='2'></td></tr>"; |
||
421 | |||
422 | echo "<tr><th colspan='4'>" . $LANG["ocsconfig"][54] . "</th></tr>"; |
||
423 | echo "<tr class='tab_bg_2'><td>" . $LANG["networking"][14] . " </td><td>"; |
||
424 | dropdownYesNo("link_ip", $this->fields["link_ip"]); |
||
425 | echo "</td>"; |
||
426 | echo "<td>" . $LANG["device_iface"][2] . " </td><td>"; |
||
427 | dropdownYesNo("link_mac_address", $this->fields["link_mac_address"]); |
||
428 | echo "</td></tr>"; |
||
429 | echo "<tr class='tab_bg_2'><td>" . $LANG["rulesengine"][25] . " </td><td>"; |
||
430 | $link_array=array("0"=>$LANG["choice"][0],"1"=>$LANG["choice"][1]." : ".$LANG["ocsconfig"][57],"2"=>$LANG["choice"][1]." : ".$LANG["ocsconfig"][56]); |
||
431 | dropdownArrayValues("link_name", $link_array,$this->fields["link_name"]); |
||
432 | echo "</td>"; |
||
433 | echo "<td>" . $LANG["common"][19] . " </td><td>"; |
||
434 | dropdownYesNo("link_serial", $this->fields["link_serial"]); |
||
435 | echo "</td></tr>"; |
||
436 | echo "<tr class='tab_bg_2'><td>" . $LANG["ocsconfig"][55] . " </td><td>"; |
||
437 | dropdownValue("glpi_dropdown_state", "link_if_status", $this->fields["link_if_status"]); |
||
438 | echo "</td><td colspan='2'></tr>"; |
||
439 | echo "</table><br>".$LANG["ocsconfig"][58]."</div>"; |
||
440 | |||
441 | |||
442 | switch($action) |
||
443 | { |
||
444 | case "update_server_with_template" : |
||
445 | echo "<p class=\"submit\"><input type=\"submit\" name=\"update_server_with_template\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" ></p>"; |
||
446 | break;
|
||
447 | case "edit_server" : |
||
448 | echo "<p class=\"submit\"><input type=\"submit\" name=\"update_server\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" ></p>"; |
||
449 | break;
|
||
450 | case "add_template" : |
||
451 | echo "<p class=\"submit\"><input type=\"submit\" name=\"add_template\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" ></p>"; |
||
452 | break;
|
||
453 | case "update_template" : |
||
454 | echo "<p class=\"submit\"><input type=\"submit\" name=\"update_template\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" ></p>"; |
||
455 | break;
|
||
456 | } |
||
457 | |||
458 | echo "</form>"; |
||
459 | } |
||
460 | |||
461 | /**
|
||
462 | * Print simple ocs config form (database part)
|
||
463 | *
|
||
464 | *@param $target form target
|
||
465 | *@param $ID Integer : Id of the ocs config
|
||
466 | *@param $withtemplate template or basic computer
|
||
467 | *@param $templateid Integer : Id of the template used
|
||
468 | *@todo clean template process
|
||
469 | *@return Nothing (display)
|
||
470 | *
|
||
471 | **/
|
||
472 | function showForm($target, $ID,$withtemplate='',$templateid='') { |
||
473 | |||
474 | global $DB, $DBocs, $LANG, $CFG_GLPI; |
||
475 | |||
476 | if (!haveRight("ocsng", "w")) |
||
477 | return false; |
||
478 | |||
479 | //If no ID provided, or if the server is created using an existing template
|
||
480 | if (empty ($ID) || $ID == -1 ) { |
||
481 | //Create a server using a template
|
||
482 | if ($templateid != '' && $templateid != -1) |
||
483 | $this->getFromDB($templateid); |
||
484 | else
|
||
485 | //Installing without a template
|
||
486 | $this->getEmpty();
|
||
487 | } else {
|
||
488 | $this->getFromDB($ID); |
||
489 | } |
||
490 | |||
491 | echo "<br><form name='formdbconfig' action=\"$target\" method=\"post\">"; |
||
492 | if (!empty ($ID) && $withtemplate!=2) |
||
493 | echo "<input type='hidden' name='ID' value='" . $ID. "'>"; |
||
494 | //Creation or modification of a machine, using a template
|
||
495 | elseif ($withtemplate == 2) |
||
496 | { |
||
497 | echo "<input type='hidden' name='withtemplate' value=2>"; |
||
498 | echo "<input type='hidden' name='templateid' value='" . $templateid. "'>"; |
||
499 | } |
||
500 | echo "<div class='center'><table class='tab_cadre'>"; |
||
501 | echo "<tr><th colspan='2'>" . $LANG["ocsconfig"][0] . "</th></tr>"; |
||
502 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][16] . " </td><td> <input type=\"text\" name=\"name\" value=\"" . $this->fields["name"] . "\"></td></tr>"; |
||
503 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][2] . " </td><td> <input type=\"text\" name=\"ocs_db_host\" value=\"" . $this->fields["ocs_db_host"] . "\"></td></tr>"; |
||
504 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][4] . " </td><td> <input type=\"text\" name=\"ocs_db_name\" value=\"" . $this->fields["ocs_db_name"] . "\"></td></tr>"; |
||
505 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][1] . " </td><td> <input type=\"text\" name=\"ocs_db_user\" value=\"" . $this->fields["ocs_db_user"] . "\"></td></tr>"; |
||
506 | echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ocsconfig"][3] . " </td><td> <input type=\"password\" name=\"ocs_db_passwd\" value=\"\"></td></tr>"; |
||
507 | echo "</table></div>"; |
||
508 | |||
509 | echo "<br><div class='center'><table border='0'>"; |
||
510 | |||
511 | if ($ID == -1 || $withtemplate == 2) |
||
512 | echo "<tr class='tab_bg_2'><td align='center' colspan=2><input type=\"submit\" name=\"add_server\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" ></td></tr>"; |
||
513 | else
|
||
514 | { |
||
515 | echo "<tr class='tab_bg_2'><td class='center'><input type=\"submit\" name=\"update_server\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" ></td>"; |
||
516 | echo "<td class='center'><input type=\"submit\" name=\"delete\" class=\"submit\" value=\"" . $LANG["buttons"][6] . "\" ></td></tr>"; |
||
517 | |||
518 | } |
||
519 | echo "</table></div>"; |
||
520 | echo "</form>"; |
||
521 | |||
522 | |||
523 | echo "<div class='center'>"; |
||
524 | |||
525 | if ($ID != -1) { |
||
526 | if (!checkOCSconnection($ID)){ |
||
527 | echo $LANG["ocsng"][21]; |
||
528 | } |
||
529 | else if (!ocsCheckConfig(1)) { |
||
530 | echo $LANG["ocsng"][20]; |
||
531 | } |
||
532 | else if (!ocsCheckConfig(2)) { |
||
533 | echo $LANG["ocsng"][42]; |
||
534 | } |
||
535 | else if (!ocsCheckConfig(4)) { |
||
536 | echo $LANG["ocsng"][43]; |
||
537 | } |
||
538 | else if (!ocsCheckConfig(8)) { |
||
539 | echo $LANG["ocsng"][44]; |
||
540 | } |
||
541 | else {
|
||
542 | echo $LANG["ocsng"][18] . "<br>"; |
||
543 | echo $LANG["ocsng"][19]; |
||
544 | |||
545 | if ($withtemplate == 2) |
||
546 | $this->ocsFormConfig($target,$ID,$withtemplate,$templateid); |
||
547 | else
|
||
548 | $this->ocsFormConfig($target, $ID,$withtemplate); |
||
549 | } |
||
550 | |||
551 | } |
||
552 | echo "</div>"; |
||
553 | } |
||
554 | |||
555 | function prepareInputForUpdate($input){ |
||
556 | |||
557 | if (isset($input["ocs_db_passwd"])&&!empty($input["ocs_db_passwd"])){ |
||
558 | $input["ocs_db_passwd"]=rawurlencode(stripslashes($input["ocs_db_passwd"])); |
||
559 | } else {
|
||
560 | unset($input["ocs_db_passwd"]); |
||
561 | } |
||
562 | |||
563 | if (isset($input["import_ip"])){ |
||
564 | $input["checksum"]=0; |
||
565 | |||
566 | if ($input["import_ip"]) $input["checksum"]|= pow(2,NETWORKS_FL); |
||
567 | if ($input["import_device_ports"]) $input["checksum"]|= pow(2,PORTS_FL); |
||
568 | if ($input["import_device_modems"]) $input["checksum"]|= pow(2,MODEMS_FL); |
||
569 | if ($input["import_device_drives"]) $input["checksum"]|= pow(2,STORAGES_FL); |
||
570 | if ($input["import_device_sound"]) $input["checksum"]|= pow(2,SOUNDS_FL); |
||
571 | if ($input["import_device_gfxcard"]) $input["checksum"]|= pow(2,VIDEOS_FL); |
||
572 | if ($input["import_device_iface"]) $input["checksum"]|= pow(2,NETWORKS_FL); |
||
573 | if ($input["import_device_hdd"]) $input["checksum"]|= pow(2,STORAGES_FL); |
||
574 | if ($input["import_device_memory"]) $input["checksum"]|= pow(2,MEMORIES_FL); |
||
575 | if ( $input["import_device_processor"] |
||
576 | ||$input["import_general_contact"] |
||
577 | ||$input["import_general_comments"] |
||
578 | ||$input["import_general_domain"] |
||
579 | ||$input["import_general_os"] |
||
580 | ||$input["import_general_name"]) $input["checksum"]|= pow(2,HARDWARE_FL); |
||
581 | if ( $input["import_general_enterprise"] |
||
582 | ||$input["import_general_type"] |
||
583 | ||$input["import_general_model"] |
||
584 | ||$input["import_general_serial"]) $input["checksum"]|= pow(2,BIOS_FL); |
||
585 | if ($input["import_printer"]) $input["checksum"]|= pow(2,PRINTERS_FL); |
||
586 | if ($input["import_software"]) $input["checksum"]|= pow(2,SOFTWARES_FL); |
||
587 | if ($input["import_monitor"]) $input["checksum"]|= pow(2,MONITORS_FL); |
||
588 | if ($input["import_periph"]) $input["checksum"]|= pow(2,INPUTS_FL); |
||
589 | if ($input["import_registry"]) $input["checksum"]|= pow(2,REGISTRY_FL); |
||
590 | } |
||
591 | |||
592 | return $input; |
||
593 | } |
||
594 | |||
595 | function prepareInputForAdd($input){ |
||
596 | |||
597 | if (isset($input["ocs_db_passwd"])&&!empty($input["ocs_db_passwd"])){ |
||
598 | $input["ocs_db_passwd"]=rawurlencode(stripslashes($input["ocs_db_passwd"])); |
||
599 | } else {
|
||
600 | unset($input["ocs_db_passwd"]); |
||
601 | } |
||
602 | |||
603 | if (isset($input["import_ip"])){ # are inputs defined |
||
604 | $input["checksum"]=0; |
||
605 | |||
606 | if ($input["import_ip"]) $input["checksum"]|= pow(2,NETWORKS_FL); |
||
607 | if ($input["import_device_ports"]) $input["checksum"]|= pow(2,PORTS_FL); |
||
608 | if ($input["import_device_modems"]) $input["checksum"]|= pow(2,MODEMS_FL); |
||
609 | if ($input["import_device_drives"]) $input["checksum"]|= pow(2,STORAGES_FL); |
||
610 | if ($input["import_device_sound"]) $input["checksum"]|= pow(2,SOUNDS_FL); |
||
611 | if ($input["import_device_gfxcard"]) $input["checksum"]|= pow(2,VIDEOS_FL); |
||
612 | if ($input["import_device_iface"]) $input["checksum"]|= pow(2,NETWORKS_FL); |
||
613 | if ($input["import_device_hdd"]) $input["checksum"]|= pow(2,STORAGES_FL); |
||
614 | if ($input["import_device_memory"]) $input["checksum"]|= pow(2,MEMORIES_FL); |
||
615 | if ( $input["import_device_processor"] |
||
616 | ||$input["import_general_contact"] |
||
617 | ||$input["import_general_comments"] |
||
618 | ||$input["import_general_domain"] |
||
619 | ||$input["import_general_os"] |
||
620 | ||$input["import_general_name"]) $input["checksum"]|= pow(2,HARDWARE_FL); |
||
621 | if ( $input["import_general_enterprise"] |
||
622 | ||$input["import_general_type"] |
||
623 | ||$input["import_general_model"] |
||
624 | ||$input["import_general_serial"]) $input["checksum"]|= pow(2,BIOS_FL); |
||
625 | if ($input["import_printer"]) $input["checksum"]|= pow(2,PRINTERS_FL); |
||
626 | if ($input["import_software"]) $input["checksum"]|= pow(2,SOFTWARES_FL); |
||
627 | if ($input["import_monitor"]) $input["checksum"]|= pow(2,MONITORS_FL); |
||
628 | if ($input["import_periph"]) $input["checksum"]|= pow(2,INPUTS_FL); |
||
629 | if ($input["import_registry"]) $input["checksum"]|= pow(2,REGISTRY_FL); |
||
630 | } |
||
631 | |||
632 | return $input; |
||
633 | } |
||
634 | |||
635 | function cleanDBonPurge($ID) { |
||
636 | global $DB; |
||
637 | |||
638 | $query = "DELETE FROM glpi_ocs_link WHERE (ocs_server_id = '$ID')"; |
||
639 | $result = $DB->query($query); |
||
640 | } |
||
641 | |||
642 | |||
643 | /**
|
||
644 | * Update Admin Info retrieve config
|
||
645 | *
|
||
646 | *@param $tab data array
|
||
647 | **/
|
||
648 | function updateAdminInfo($tab){ |
||
649 | $adm = new AdminInfo(); |
||
650 | $adm->cleanDBonPurge($tab["ID"]); |
||
651 | if (isset ($tab["import_location"])){ |
||
652 | if($tab["import_location"]!=""){ |
||
653 | $adm = new AdminInfo(); |
||
654 | $adm->fields["ocs_server_id"] = $tab["ID"]; |
||
655 | $adm->fields["glpi_column"] = "location"; |
||
656 | $adm->fields["ocs_column"] = $tab["import_location"]; |
||
657 | $isNewAdm = $adm->addToDB(); |
||
658 | } |
||
659 | } |
||
660 | if (isset ($tab["import_otherserial"])){ |
||
661 | if($tab["import_otherserial"]!=""){ |
||
662 | $adm = new AdminInfo(); |
||
663 | $adm->fields["ocs_server_id"] = $tab["ID"]; |
||
664 | $adm->fields["glpi_column"] = "otherserial"; |
||
665 | $adm->fields["ocs_column"] = $tab["import_otherserial"]; |
||
666 | $isNewAdm = $adm->addToDB(); |
||
667 | } |
||
668 | } |
||
669 | if (isset ($tab["import_group"])){ |
||
670 | if($tab["import_group"]!=""){ |
||
671 | $adm = new AdminInfo(); |
||
672 | $adm->fields["ocs_server_id"] = $tab["ID"]; |
||
673 | $adm->fields["glpi_column"] = "FK_groups"; |
||
674 | $adm->fields["ocs_column"] = $tab["import_group"]; |
||
675 | $isNewAdm = $adm->addToDB(); |
||
676 | } |
||
677 | } |
||
678 | if (isset ($tab["import_network"])){ |
||
679 | if($tab["import_network"]!=""){ |
||
680 | $adm = new AdminInfo(); |
||
681 | $adm->fields["ocs_server_id"] = $tab["ID"]; |
||
682 | $adm->fields["glpi_column"] = "network"; |
||
683 | $adm->fields["ocs_column"] = $tab["import_network"]; |
||
684 | $isNewAdm = $adm->addToDB(); |
||
685 | } |
||
686 | } |
||
687 | if (isset ($tab["import_contact_num"])){ |
||
688 | if($tab["import_contact_num"]!=""){ |
||
689 | $adm = new AdminInfo(); |
||
690 | $adm->fields["ocs_server_id"] = $tab["ID"]; |
||
691 | $adm->fields["glpi_column"] = "contact_num"; |
||
692 | $adm->fields["ocs_column"] = $tab["import_contact_num"]; |
||
693 | $isNewAdm = $adm->addToDB(); |
||
694 | } |
||
695 | } |
||
696 | } |
||
697 | } |
||
698 | |||
699 | |||
700 | ?> |