ryxeo-glpi-git / htdocs / inc / setup.function.php @ 1c14bcc4
Historique | Voir | Annoter | Télécharger (43,7 ko)
1 |
<?php
|
---|---|
2 |
|
3 |
|
4 |
/*
|
5 |
* @version $Id: setup.function.php 7881 2009-01-23 17:56:15Z 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 |
// ----------------------------------------------------------------------
|
34 |
// Original Author of file:
|
35 |
// Purpose of file:
|
36 |
// ----------------------------------------------------------------------
|
37 |
|
38 |
if (!defined('GLPI_ROOT')) { |
39 |
die("Sorry. You can't access directly to this file"); |
40 |
} |
41 |
|
42 |
// FUNCTIONS Setup
|
43 |
|
44 |
|
45 |
function showDropdownList($target, $tablename,$FK_entities='',$location=-1){ |
46 |
global $DB,$CFG_GLPI,$LANG; |
47 |
|
48 |
if (!haveRight("dropdown", "w")&&!haveRight("entity_dropdown", "w")) |
49 |
return false; |
50 |
|
51 |
$field="name"; |
52 |
if (in_array($tablename, $CFG_GLPI["dropdowntree_tables"])) { |
53 |
$field="completename"; |
54 |
} |
55 |
|
56 |
$where=""; |
57 |
$entity_restrict = -1; |
58 |
|
59 |
if (!empty($FK_entities) && $FK_entities>=0){ |
60 |
$entity_restrict = $FK_entities; |
61 |
} else {
|
62 |
$entity_restrict = $_SESSION["glpiactive_entity"]; |
63 |
} |
64 |
|
65 |
if ($tablename=="glpi_dropdown_netpoint") { |
66 |
if ($location > 0) { |
67 |
$where = " WHERE location='$location'"; |
68 |
} else if ($location < 0) { |
69 |
$where = getEntitiesRestrictRequest(" WHERE ",$tablename,'',$entity_restrict); |
70 |
} else {
|
71 |
$where = " WHERE location=0 " . getEntitiesRestrictRequest(" AND ",$tablename,'',$entity_restrict); |
72 |
} |
73 |
} else if (in_array($tablename, $CFG_GLPI["specif_entities_tables"])) { |
74 |
$where=getEntitiesRestrictRequest(" WHERE ",$tablename,'',$entity_restrict); |
75 |
} |
76 |
|
77 |
echo "<div class='center'>"; |
78 |
$query="SELECT * FROM `$tablename` $where ORDER BY $field"; |
79 |
if ($result=$DB->query($query)){ |
80 |
if ($DB->numrows($result)>0){ |
81 |
echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"$target\"><table class='tab_cadre_fixe'>"; |
82 |
|
83 |
$sel=""; |
84 |
if (isset($_GET["select"])&&$_GET["select"]=="all") { |
85 |
$sel="checked"; |
86 |
} |
87 |
$i=0; |
88 |
while ($data=$DB->fetch_assoc($result)){ |
89 |
$class=" class='tab_bg_2' "; |
90 |
if ($i%2){ |
91 |
$class=" class='tab_bg_1' "; |
92 |
} |
93 |
echo "<tr $class><td width='10'><input type='checkbox' name='item[".$data["ID"]."]' value='1' $sel></td><td>".$data[$field]."</td></tr>"; |
94 |
$i++;
|
95 |
} |
96 |
echo "</table>"; |
97 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
98 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
99 |
echo "<input type='hidden' name='value2' value='$location'>"; |
100 |
|
101 |
echo "<div>"; |
102 |
echo "<table width='950'>"; |
103 |
$parameters="which=$tablename&mass_deletion=1&FK_entities=$FK_entities"; |
104 |
echo "<tr><td><img src=\"".$CFG_GLPI["root_doc"]."/pics/arrow-left.png\" alt=''></td><td><a onclick= \"if ( markAllRows('massiveaction_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?$parameters&select=all'>".$LANG["buttons"][18]."</a></td>"; |
105 |
|
106 |
echo "<td>/</td><td ><a onclick=\"if ( unMarkAllRows('massiveaction_form') ) return false;\" href='".$_SERVER['PHP_SELF']."?$parameters&select=none'>".$LANG["buttons"][19]."</a>"; |
107 |
echo "</td><td class='left' width='80%'>"; |
108 |
echo "<input type='submit' class='submit' name='mass_delete' value='".$LANG["buttons"][6]."'>"; |
109 |
echo " <strong>".$LANG["setup"][1]."</strong>"; |
110 |
echo "</td></table></div>"; |
111 |
echo "</form>"; |
112 |
} else {
|
113 |
echo "<strong>".$LANG["search"][15]."</strong>"; |
114 |
} |
115 |
|
116 |
} |
117 |
echo "</div>"; |
118 |
|
119 |
} |
120 |
|
121 |
function showFormTreeDown($target, $tablename, $human, $ID, $value2 = '', $where = '', $tomove = '', $type = '',$FK_entities='') { |
122 |
|
123 |
global $CFG_GLPI, $LANG; |
124 |
|
125 |
if (!haveRight("dropdown", "w")&&!haveRight("entity_dropdown", "w")) |
126 |
return false; |
127 |
|
128 |
|
129 |
$entity_restrict = -1; |
130 |
$numberof = 0; |
131 |
if (in_array($tablename, $CFG_GLPI["specif_entities_tables"])) { |
132 |
if (!empty($FK_entities)&&$FK_entities>=0){ |
133 |
$entity_restrict = $FK_entities; |
134 |
} else {
|
135 |
$entity_restrict = $_SESSION["glpiactive_entity"]; |
136 |
} |
137 |
|
138 |
$numberof = countElementsInTableForEntity($tablename, $entity_restrict); |
139 |
} else {
|
140 |
$numberof = countElementsInTable($tablename); |
141 |
} |
142 |
|
143 |
|
144 |
echo "<div class='center'> \n"; |
145 |
|
146 |
echo "<form method='post' action=\"$target\">"; |
147 |
|
148 |
|
149 |
|
150 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>\n"; |
151 |
echo "<tr><th colspan='3'>$human:</th></tr>"; |
152 |
if ($numberof > 0) { |
153 |
echo "<tr><td align='center' valign='middle' class='tab_bg_1'>"; |
154 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
155 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
156 |
|
157 |
$value = getTreeLeafValueName($tablename, $ID, 1); |
158 |
|
159 |
dropdownValue($tablename, "ID", $ID, 0, $entity_restrict); |
160 |
// on ajoute un input text pour entrer la valeur modifier
|
161 |
echo "  <input type='image' class='calendrier' src=\"" . $CFG_GLPI["root_doc"] . "/pics/puce.gif\" alt='' title='' name='fillright' value='fillright'> "; |
162 |
|
163 |
autocompletionTextField('value',$tablename,'name',$value["name"],20,$entity_restrict,'maxlength=\'100\''); |
164 |
echo '<br>'; |
165 |
echo "<textarea rows='2' cols='50' name='comments' title='" . $LANG["common"][25] . "' >" . $value["comments"] . "</textarea>"; |
166 |
|
167 |
echo "</td><td align='center' class='tab_bg_2' width='99'>"; |
168 |
echo "<input type='hidden' name='tablename' value='$tablename'>"; |
169 |
// on ajoute un bouton modifier
|
170 |
echo "<input type='submit' name='update' value='" . $LANG["buttons"][14] . "' class='submit'>"; |
171 |
echo "</td><td align='center' class='tab_bg_2' width='99'>"; |
172 |
//
|
173 |
echo "<input type='submit' name='delete' value=\"" . $LANG["buttons"][6] . "\" class='submit'>"; |
174 |
echo "</td></tr></table></form>"; |
175 |
|
176 |
echo "<form method='post' action=\"$target\">"; |
177 |
|
178 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
179 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>\n"; |
180 |
|
181 |
echo "<tr><td align='center' class='tab_bg_1'>"; |
182 |
|
183 |
dropdownValue($tablename, "value_to_move", $tomove, 0, $entity_restrict); |
184 |
echo " " . $LANG["setup"][75] . " : "; |
185 |
|
186 |
dropdownValue($tablename, "value_where", $where, 0, $entity_restrict); |
187 |
echo "</td><td align='center' colspan='2' class='tab_bg_2' width='202'>"; |
188 |
echo "<input type='hidden' name='tablename' value='$tablename' >"; |
189 |
echo "<input type='submit' name='move' value=\"" . $LANG["buttons"][20] . "\" class='submit'>"; |
190 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
191 |
|
192 |
echo "</td></tr>"; |
193 |
|
194 |
} |
195 |
echo "</table></form>"; |
196 |
|
197 |
echo "<form action=\"$target\" method='post'>"; |
198 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
199 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
200 |
|
201 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>\n"; |
202 |
echo "<tr><td align='center' class='tab_bg_1'>"; |
203 |
autocompletionTextField('value',$tablename,'name','',15,$entity_restrict,'maxlength=\'100\''); |
204 |
echo " "; |
205 |
|
206 |
if ($numberof > 0) { |
207 |
echo "<select name='type'>"; |
208 |
echo "<option value='under' " . ($type == 'under' ? " selected " : "") . ">" . $LANG["setup"][75] . "</option>"; |
209 |
echo "<option value='same' " . ($type == 'same' ? " selected " : "") . ">" . $LANG["setup"][76] . "</option>"; |
210 |
echo "</select> "; |
211 |
dropdownValue($tablename, "value2", (strlen($value2) ? $value2 : 0), 0, $entity_restrict); |
212 |
} else
|
213 |
echo "<input type='hidden' name='type' value='first'>"; |
214 |
|
215 |
echo "<br><textarea rows='2' cols='50' name='comments' title='" . $LANG["common"][25] . "' ></textarea>"; |
216 |
|
217 |
echo "</td><td align='center' colspan='2' class='tab_bg_2' width='202'>"; |
218 |
echo "<input type='hidden' name='tablename' value='$tablename' >"; |
219 |
|
220 |
echo "<input type='submit' name='add' value=\"" . $LANG["buttons"][8] . "\" class='submit'>"; |
221 |
echo "</td></tr>"; |
222 |
|
223 |
echo "</table></form>"; |
224 |
|
225 |
if (ereg('setup.dropdowns.php',$target) && $numberof>0){ |
226 |
echo "<a href='$target?which=$tablename&mass_deletion=1&FK_entities=$FK_entities'>".$LANG["title"][42]."</a>"; |
227 |
} |
228 |
|
229 |
|
230 |
echo "</div>"; |
231 |
} |
232 |
|
233 |
function showFormNetpoint($target, $human, $ID, $FK_entities='',$location=0) { |
234 |
|
235 |
global $DB, $CFG_GLPI, $LANG; |
236 |
|
237 |
$tablename="glpi_dropdown_netpoint"; |
238 |
|
239 |
if (!haveRight("entity_dropdown", "w")) |
240 |
return false; |
241 |
|
242 |
$entity_restrict = -1; |
243 |
$numberof=0; |
244 |
if (!empty($FK_entities)&&$FK_entities>=0){ |
245 |
$entity_restrict = $FK_entities; |
246 |
} else {
|
247 |
$entity_restrict = $_SESSION["glpiactive_entity"]; |
248 |
} |
249 |
if ($location>0) { |
250 |
$numberof = countElementsInTable($tablename, "location=$location "); |
251 |
} else if ($location<0){ |
252 |
$numberof = countElementsInTable($tablename, getEntitiesRestrictRequest(" ",$tablename,'',$entity_restrict)); |
253 |
} else {
|
254 |
$numberof = countElementsInTable($tablename, "location=0 ".getEntitiesRestrictRequest(" AND ",$tablename,'',$entity_restrict)); |
255 |
} |
256 |
|
257 |
echo "<div class='center'> "; |
258 |
echo "<form method='post' action=\"$target\">"; |
259 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>"; |
260 |
echo "<tr><th colspan='3'>$human:</th></tr>"; |
261 |
if ($numberof > 0) { |
262 |
echo "<tr><td class='tab_bg_1' align='center' valign='top'>"; |
263 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
264 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
265 |
echo "<input type='hidden' name='value2' value='$location'>"; |
266 |
|
267 |
dropdownNetpoint("ID", $ID, $location, 0, $entity_restrict); |
268 |
|
269 |
// on ajoute un input text pour entrer la valeur modifier
|
270 |
echo " <input type='image' class='calendrier' src=\"" . $CFG_GLPI["root_doc"] . "/pics/puce.gif\" alt='' title='' name='fillright' value='fillright'> "; |
271 |
|
272 |
|
273 |
$query = "select * from glpi_dropdown_netpoint where ID = '" . $ID . "'"; |
274 |
$result = $DB->query($query); |
275 |
$value = $loc = $comments = ""; |
276 |
$entity = 0; |
277 |
if ($DB->numrows($result) == 1) { |
278 |
$value = $DB->result($result, 0, "name"); |
279 |
$loc = $DB->result($result, 0, "location"); |
280 |
$comments = $DB->result($result, 0, "comments"); |
281 |
} |
282 |
echo "<br>"; |
283 |
echo $LANG["common"][15] . ": "; |
284 |
dropdownValue("glpi_dropdown_locations", "value2", $location, 0, $entity_restrict); |
285 |
|
286 |
echo $LANG["networking"][52] . ": "; |
287 |
autocompletionTextField('value',$tablename,'name',$value,10,$entity_restrict,'maxlength=\'100\''); |
288 |
echo "<br>"; |
289 |
echo "<textarea rows='2' cols='50' name='comments' title='" . $LANG["common"][25] . "' >" . $comments . "</textarea>"; |
290 |
|
291 |
//
|
292 |
echo "</td><td align='center' class='tab_bg_2' width='99'>"; |
293 |
echo "<input type='hidden' name='tablename' value='$tablename'>"; |
294 |
|
295 |
// on ajoute un bouton modifier
|
296 |
echo "<input type='submit' name='update' value='" . $LANG["buttons"][14] . "' class='submit'>"; |
297 |
echo "</td><td align='center' class='tab_bg_2' width='99'>"; |
298 |
//
|
299 |
echo "<input type='submit' name='delete' value=\"" . $LANG["buttons"][6] . "\" class='submit'>"; |
300 |
echo "</td></tr>"; |
301 |
|
302 |
} |
303 |
echo "</table></form>"; |
304 |
echo "<form action=\"$target\" method='post'>"; |
305 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
306 |
echo "<input type='hidden' name='tablename' value='$tablename' >"; |
307 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
308 |
echo "<input type='hidden' name='value2' value='$location'>"; |
309 |
|
310 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>"; |
311 |
echo "<tr><td align='center' class='tab_bg_1'>"; |
312 |
|
313 |
echo $LANG["networking"][52] . ": "; |
314 |
autocompletionTextField('value',$tablename,'name','',10,$entity_restrict,'maxlength=\'100\''); |
315 |
echo "<br>"; |
316 |
echo "<textarea rows='2' cols='50' name='comments' title='" . $LANG["common"][25] . "'></textarea>"; |
317 |
|
318 |
echo "</td><td align='center' colspan='2' class='tab_bg_2' width='202'>"; |
319 |
|
320 |
echo "<input type='submit' name='add' value=\"" . $LANG["buttons"][8] . "\" class='submit'>"; |
321 |
echo "</td></tr>"; |
322 |
|
323 |
// Multiple Add for Netpoint
|
324 |
echo "</table></form>"; |
325 |
|
326 |
echo "<form action=\"$target\" method='post'>"; |
327 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
328 |
echo "<input type='hidden' name='value2' value='$location'>"; |
329 |
echo "<input type='hidden' name='tablename' value='$tablename' >"; |
330 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
331 |
|
332 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>"; |
333 |
echo "<tr><td align='center' class='tab_bg_1'>"; |
334 |
|
335 |
echo $LANG["networking"][52] . ": "; |
336 |
echo "<input type='text' maxlength='100' size='5' name='before'>"; |
337 |
dropdownInteger('from', 0, 0, 400); |
338 |
echo "-->"; |
339 |
dropdownInteger('to', 0, 0, 400); |
340 |
|
341 |
echo "<input type='text' maxlength='100' size='5' name='after'><br>"; |
342 |
echo "<textarea rows='2' cols='50' name='comments' title='" . $LANG["common"][25] . "'></textarea>"; |
343 |
echo "</td><td align='center' colspan='2' class='tab_bg_2' width='202'>"; |
344 |
|
345 |
echo "<input type='submit' name='several_add' value=\"" . $LANG["buttons"][8] . "\" class='submit'>"; |
346 |
echo "</td></tr>"; |
347 |
|
348 |
echo "</table></form>"; |
349 |
|
350 |
if (ereg('setup.dropdowns.php',$target) && $numberof>0){ |
351 |
echo "<a href='$target?which=$tablename&mass_deletion=1&FK_entities=$FK_entities&value2=$location'>".$LANG["title"][42]."</a>"; |
352 |
} |
353 |
|
354 |
echo "</div>"; |
355 |
} |
356 |
|
357 |
function showFormDropDown($target, $tablename, $human, $ID, $FK_entities='') { |
358 |
|
359 |
global $DB, $CFG_GLPI, $LANG; |
360 |
|
361 |
if (!haveRight("dropdown", "w")&&!haveRight("entity_dropdown", "w")) |
362 |
return false; |
363 |
|
364 |
$entity_restrict = -1; |
365 |
$numberof=0; |
366 |
if (in_array($tablename, $CFG_GLPI["specif_entities_tables"])) { |
367 |
if (!empty($FK_entities)&&$FK_entities>=0){ |
368 |
$entity_restrict = $FK_entities; |
369 |
} else {
|
370 |
$entity_restrict = $_SESSION["glpiactive_entity"]; |
371 |
} |
372 |
$numberof = countElementsInTableForEntity($tablename, $entity_restrict); |
373 |
} else {
|
374 |
$numberof = countElementsInTable($tablename); |
375 |
} |
376 |
|
377 |
|
378 |
|
379 |
echo "<div class='center'> "; |
380 |
echo "<form method='post' action=\"$target\">"; |
381 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>"; |
382 |
echo "<tr><th colspan='3'>$human:</th></tr>"; |
383 |
if ($numberof > 0) { |
384 |
echo "<tr><td class='tab_bg_1' align='center' valign='top'>"; |
385 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
386 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
387 |
|
388 |
if (!empty ($ID)) { |
389 |
$value = getDropdownName($tablename, $ID, 1); |
390 |
} else {
|
391 |
$value = array ( |
392 |
"name" => "", |
393 |
"comments" => "" |
394 |
); |
395 |
} |
396 |
dropdownValue($tablename, "ID", $ID, 0, $entity_restrict); |
397 |
|
398 |
// on ajoute un input text pour entrer la valeur modifier
|
399 |
echo " <input type='image' class='calendrier' src=\"" . $CFG_GLPI["root_doc"] . "/pics/puce.gif\" alt='' title='' name='fillright' value='fillright'> "; |
400 |
|
401 |
|
402 |
autocompletionTextField('value',$tablename,'name',$value["name"],20,$entity_restrict,'maxlength=\'100\''); |
403 |
echo "<br>"; |
404 |
echo "<textarea rows='2' cols='50' name='comments' title='" . $LANG["common"][25] . "' >" . $value["comments"] . "</textarea>"; |
405 |
|
406 |
//
|
407 |
echo "</td><td align='center' class='tab_bg_2' width='99'>"; |
408 |
echo "<input type='hidden' name='tablename' value='$tablename'>"; |
409 |
|
410 |
// on ajoute un bouton modifier
|
411 |
echo "<input type='submit' name='update' value='" . $LANG["buttons"][14] . "' class='submit'>"; |
412 |
echo "</td><td align='center' class='tab_bg_2' width='99'>"; |
413 |
//
|
414 |
echo "<input type='submit' name='delete' value=\"" . $LANG["buttons"][6] . "\" class='submit'>"; |
415 |
echo "</td></tr>"; |
416 |
|
417 |
} |
418 |
echo "</table></form>"; |
419 |
echo "<form action=\"$target\" method='post'>"; |
420 |
echo "<input type='hidden' name='which' value='$tablename'>"; |
421 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
422 |
|
423 |
echo "<table class='tab_cadre_fixe' cellpadding='1'>"; |
424 |
echo "<tr><td align='center' class='tab_bg_1'>"; |
425 |
autocompletionTextField('value',$tablename,'name','',20,$entity_restrict,'maxlength=\'100\''); |
426 |
echo "<br>"; |
427 |
echo "<textarea rows='2' cols='50' name='comments' title='" . $LANG["common"][25] . "'></textarea>"; |
428 |
|
429 |
echo "</td><td align='center' colspan='2' class='tab_bg_2' width='202'>"; |
430 |
echo "<input type='hidden' name='tablename' value='$tablename' >"; |
431 |
echo "<input type='hidden' name='FK_entities' value='$entity_restrict'>"; |
432 |
|
433 |
echo "<input type='submit' name='add' value=\"" . $LANG["buttons"][8] . "\" class='submit'>"; |
434 |
echo "</td></tr>"; |
435 |
|
436 |
echo "</table></form>"; |
437 |
|
438 |
if (ereg('setup.dropdowns.php',$target) && $numberof>0){ |
439 |
echo "<a href='$target?which=$tablename&mass_deletion=1&FK_entities=$FK_entities'>".$LANG["title"][42]."</a>"; |
440 |
} |
441 |
|
442 |
echo "</div>"; |
443 |
} |
444 |
|
445 |
function moveTreeUnder($table, $to_move, $where) { |
446 |
global $DB; |
447 |
if ($where != $to_move) { |
448 |
// Is the $where location under the to move ???
|
449 |
$impossible_move = false; |
450 |
|
451 |
$current_ID = $where; |
452 |
while ($current_ID != 0 && $impossible_move == false) { |
453 |
|
454 |
$query = "SELECT * FROM `$table` WHERE ID='$current_ID'"; |
455 |
$result = $DB->query($query); |
456 |
$current_ID = $DB->result($result, 0, "parentID"); |
457 |
if ($current_ID == $to_move){ |
458 |
$impossible_move = true; |
459 |
} |
460 |
} |
461 |
if (!$impossible_move) { |
462 |
// Move Location
|
463 |
$query = "UPDATE `$table` SET parentID='$where' where ID='$to_move'"; |
464 |
$result = $DB->query($query); |
465 |
regenerateTreeCompleteNameUnderID($table, $to_move); |
466 |
} |
467 |
} |
468 |
} |
469 |
|
470 |
function updateDropdown($input) { |
471 |
global $DB, $CFG_GLPI; |
472 |
|
473 |
// Clean datas
|
474 |
$input["value"]=trim($input["value"]); |
475 |
if (empty($input["value"])) return false; |
476 |
|
477 |
if ($input["tablename"] == "glpi_dropdown_netpoint") { |
478 |
$query = "update " . $input["tablename"] . " SET name = '" . $input["value"] . "', location = '" . $input["value2"] . "', comments='" . $input["comments"] . "' where ID = '" . $input["ID"] . "'"; |
479 |
|
480 |
} else {
|
481 |
$query = "update " . $input["tablename"] . " SET name = '" . $input["value"] . "', comments='" . $input["comments"] . "' where ID = '" . $input["ID"] . "'"; |
482 |
} |
483 |
|
484 |
if ($result = $DB->query($query)) { |
485 |
if (in_array($input["tablename"], $CFG_GLPI["dropdowntree_tables"])) { |
486 |
regenerateTreeCompleteNameUnderID($input["tablename"], $input["ID"]); |
487 |
if ($input["tablename"]=="glpi_entities"&&isset($_SESSION["glpiID"])){ |
488 |
$activeprof=$_SESSION['glpiactiveprofile']['ID']; |
489 |
initEntityProfiles($_SESSION["glpiID"]); |
490 |
changeProfile($activeprof);
|
491 |
} |
492 |
} |
493 |
cleanRelationCache($input["tablename"]); |
494 |
return true; |
495 |
} else {
|
496 |
return false; |
497 |
} |
498 |
} |
499 |
|
500 |
function getDropdownID($input){ |
501 |
global $DB, $CFG_GLPI; |
502 |
// Clean datas
|
503 |
$input["value"]=trim($input["value"]); |
504 |
if (!empty ($input["value"])) { |
505 |
$add_entity_field_twin = ""; |
506 |
if (in_array($input["tablename"], $CFG_GLPI["specif_entities_tables"])) { |
507 |
$add_entity_field_twin = " FK_entities = '" . $input["FK_entities"] . "' AND "; |
508 |
} |
509 |
$query=""; |
510 |
$query_twin=""; |
511 |
if ($input["tablename"] == "glpi_dropdown_netpoint") { |
512 |
$query_twin="SELECT ID FROM `" . $input["tablename"] . "` WHERE $add_entity_field_twin name= '".$input["value"]."' AND location = '".$input["value2"]."'"; |
513 |
} else {
|
514 |
if (in_array($input["tablename"], $CFG_GLPI["dropdowntree_tables"])) { |
515 |
|
516 |
$query_twin="SELECT ID FROM `" . $input["tablename"] . "` WHERE $add_entity_field_twin name= '".$input["value"]."' AND parentID='0'"; |
517 |
|
518 |
if ($input['type'] != "first" && $input["value2"] != 0) { |
519 |
$level_up=-1; |
520 |
$query = "SELECT * FROM `" . $input["tablename"] . "` where ID='" . $input["value2"] . "'"; |
521 |
|
522 |
$result = $DB->query($query); |
523 |
|
524 |
if ($DB->numrows($result) > 0) { |
525 |
|
526 |
$data = $DB->fetch_array($result); |
527 |
$level_up = $data["parentID"]; |
528 |
if ($input["type"] == "under") { |
529 |
$level_up = $data["ID"]; |
530 |
} |
531 |
} |
532 |
$query_twin="SELECT ID FROM `" . $input["tablename"] . "` WHERE $add_entity_field_twin name= '".$input["value"]."' AND parentID='$level_up'"; |
533 |
} |
534 |
} else {
|
535 |
$query_twin="SELECT ID FROM `" . $input["tablename"] . "` WHERE $add_entity_field_twin name= '".$input["value"]."' "; |
536 |
} |
537 |
} |
538 |
|
539 |
// Check twin :
|
540 |
if ($result_twin = $DB->query($query_twin) ) { |
541 |
if ($DB->numrows($result_twin) > 0){ |
542 |
return $DB->result($result_twin,0,"ID"); |
543 |
} |
544 |
} |
545 |
return -1; |
546 |
} |
547 |
} |
548 |
|
549 |
|
550 |
/**
|
551 |
* Import a value in a dropdown table.
|
552 |
*
|
553 |
* This import a new dropdown if it doesn't exist.
|
554 |
*
|
555 |
*@param $dpdTable string : Name of the glpi dropdown table.
|
556 |
*@param $value string : Value of the new dropdown.
|
557 |
*@param $FK_entities int : entity in case of specific dropdown
|
558 |
*@param $external_params
|
559 |
*@param $comments
|
560 |
*@param $add if true, add it if not found. if false, just check if exists
|
561 |
*
|
562 |
*@return integer : dropdown id.
|
563 |
*
|
564 |
**/
|
565 |
function externalImportDropdown($dpdTable, $value, $FK_entities = -1,$external_params=array(),$comments="",$add=true) { |
566 |
global $DB, $CFG_GLPI; |
567 |
|
568 |
$value=trim($value); |
569 |
if (strlen($value)==0){ |
570 |
return 0; |
571 |
} |
572 |
|
573 |
$input["tablename"] = $dpdTable; |
574 |
$input["value"] = $value; |
575 |
$input['type'] = "first"; |
576 |
$input["comments"] = $comments; |
577 |
$input["FK_entities"] = $FK_entities; |
578 |
|
579 |
|
580 |
$process = false; |
581 |
|
582 |
$input_values=array("name"=>$value); |
583 |
|
584 |
$rulecollection = getRuleCollectionClassByTableName($dpdTable); |
585 |
|
586 |
switch ($dpdTable) |
587 |
{ |
588 |
case "glpi_dropdown_manufacturer": |
589 |
case "glpi_dropdown_os": |
590 |
case "glpi_dropdown_os_sp": |
591 |
case "glpi_dropdown_os_version": |
592 |
case "glpi_type_computers": |
593 |
case "glpi_type_monitors": |
594 |
case "glpi_type_printers": |
595 |
case "glpi_type_peripherals": |
596 |
case "glpi_type_phones": |
597 |
case "glpi_type_networking": |
598 |
$process = true; |
599 |
break;
|
600 |
case "glpi_dropdown_model": |
601 |
case "glpi_dropdown_model_monitors": |
602 |
case "glpi_dropdown_model_printers": |
603 |
case "glpi_dropdown_model_peripherals": |
604 |
case "glpi_dropdown_model_phones": |
605 |
case "glpi_dropdown_model_networking": |
606 |
|
607 |
$process = true; |
608 |
$input_values["manufacturer"] = $external_params["manufacturer"]; |
609 |
break;
|
610 |
default:
|
611 |
break;
|
612 |
} |
613 |
|
614 |
if ($process){ |
615 |
|
616 |
$res_rule = $rulecollection->processAllRules($input_values, array (), array()); |
617 |
if (isset($res_rule["name"])){ |
618 |
$input["value"] = $res_rule["name"]; |
619 |
} |
620 |
} |
621 |
|
622 |
return ($add ? addDropdown($input) : getDropdownID($input)); |
623 |
} |
624 |
|
625 |
|
626 |
function addDropdown($input) { |
627 |
global $DB, $CFG_GLPI; |
628 |
// Clean datas
|
629 |
$input["value"]=trim($input["value"]); |
630 |
|
631 |
// Check twin :
|
632 |
if ($ID = getDropdownID($input) ) { |
633 |
if ($ID>0){ |
634 |
return $ID; |
635 |
} |
636 |
} |
637 |
|
638 |
if (!empty ($input["value"])) { |
639 |
$add_entity_field = ""; |
640 |
$add_entity_value = ""; |
641 |
if (in_array($input["tablename"], $CFG_GLPI["specif_entities_tables"])) { |
642 |
$add_entity_field = "FK_entities,"; |
643 |
$add_entity_value = "'" . $input["FK_entities"] . "',"; |
644 |
} |
645 |
$query=""; |
646 |
if ($input["tablename"] == "glpi_dropdown_netpoint") { |
647 |
$query = "INSERT INTO `" . $input["tablename"] . "` (" . $add_entity_field . "name,location,comments) VALUES (" . $add_entity_value . "'" . $input["value"] . "', '" . $input["value2"] . "', '" . $input["comments"] . "')"; |
648 |
} else {
|
649 |
if (in_array($input["tablename"], $CFG_GLPI["dropdowntree_tables"])) { |
650 |
|
651 |
$query = "INSERT INTO `" . $input["tablename"] . "` (" . $add_entity_field . "name,parentID,completename,comments) VALUES (" . $add_entity_value . "'" . $input["value"] . "', '0','','" . $input["comments"] . "')"; |
652 |
|
653 |
if ($input['type'] != "first" && $input["value2"] != 0) { |
654 |
$level_up=-1; |
655 |
$query = "SELECT * FROM `" . $input["tablename"] . "` where ID='" . $input["value2"] . "'"; |
656 |
|
657 |
$result = $DB->query($query); |
658 |
|
659 |
if ($DB->numrows($result) > 0) { |
660 |
|
661 |
$data = $DB->fetch_array($result); |
662 |
$level_up = $data["parentID"]; |
663 |
if ($input["type"] == "under") { |
664 |
$level_up = $data["ID"]; |
665 |
} |
666 |
} |
667 |
$query = "INSERT INTO `" . $input["tablename"] . "` (" . $add_entity_field . "name,parentID,completename,comments) VALUES (" . $add_entity_value . "'" . $input["value"] . "', '$level_up','','" . $input["comments"] . "')"; |
668 |
} |
669 |
} else {
|
670 |
$query = "INSERT INTO `" . $input["tablename"] . "` (" . $add_entity_field . "name,comments) VALUES (" . $add_entity_value . "'" . $input["value"] . "','" . $input["comments"] . "')"; |
671 |
} |
672 |
} |
673 |
|
674 |
if ($result = $DB->query($query)) { |
675 |
$ID = $DB->insert_id(); |
676 |
if (in_array($input["tablename"], $CFG_GLPI["dropdowntree_tables"])) { |
677 |
regenerateTreeCompleteNameUnderID($input["tablename"], $ID); |
678 |
} |
679 |
if ($input["tablename"]=="glpi_entities"&&isset($_SESSION["glpiID"])){ |
680 |
$activeprof=$_SESSION['glpiactiveprofile']['ID']; |
681 |
initEntityProfiles($_SESSION["glpiID"]); |
682 |
changeProfile($activeprof);
|
683 |
} |
684 |
|
685 |
cleanRelationCache($input["tablename"]); |
686 |
return $ID; |
687 |
} else {
|
688 |
return false; |
689 |
} |
690 |
} |
691 |
} |
692 |
|
693 |
function deleteDropdown($input) { |
694 |
|
695 |
global $DB; |
696 |
$send = array (); |
697 |
$send["tablename"] = $input["tablename"]; |
698 |
$send["oldID"] = $input["ID"]; |
699 |
$send["newID"] = 0; |
700 |
replaceDropDropDown($send);
|
701 |
cleanRelationCache($input["tablename"]); |
702 |
} |
703 |
|
704 |
/** Replace a dropdown item (oldID) by another one (newID) in a dropdown table (tablename) and update all linked fields
|
705 |
* @param $input array : paramaters : need tablename / oldID / newID
|
706 |
*/
|
707 |
function replaceDropDropDown($input) { |
708 |
global $DB,$CFG_GLPI; |
709 |
|
710 |
if (!isset($input["tablename"])||!isset($input["oldID"])||!isset($input["newID"])||$input["oldID"]==$input["newID"]){ |
711 |
return false; |
712 |
} |
713 |
|
714 |
$name = getDropdownNameFromTable($input["tablename"]); |
715 |
if (empty($name)){ |
716 |
return false; |
717 |
} |
718 |
$RELATION = getDbRelations();
|
719 |
// Man
|
720 |
|
721 |
if (isset ($RELATION[$input["tablename"]])) |
722 |
foreach ($RELATION[$input["tablename"]] as $table => $field){ |
723 |
if ($table[0]!='_'){ |
724 |
if (!is_array($field)){ |
725 |
// Manage OCS lock for items - no need for array case
|
726 |
if ($table=="glpi_computers"&&$CFG_GLPI['ocs_mode']){ |
727 |
$query="SELECT ID FROM `glpi_computers` WHERE ocs_import='1' AND `$field` = '" . $input["oldID"] . "'"; |
728 |
$result=$DB->query($query); |
729 |
if ($DB->numrows($result)){ |
730 |
if (!function_exists('mergeOcsArray')){ |
731 |
include_once (GLPI_ROOT . "/inc/ocsng.function.php"); |
732 |
} |
733 |
while ($data=$DB->fetch_array($result)){ |
734 |
mergeOcsArray($data['ID'],array($field),"computer_update"); |
735 |
} |
736 |
} |
737 |
} |
738 |
|
739 |
|
740 |
$query = "UPDATE `$table` SET `$field` = '" . $input["newID"] . "' WHERE `$field` = '" . $input["oldID"] . "'"; |
741 |
$DB->query($query); |
742 |
} else {
|
743 |
foreach ($field as $f){ |
744 |
$query = "UPDATE `$table` SET `$f` = '" . $input["newID"] . "' WHERE `$f` = '" . $input["oldID"] . "'"; |
745 |
$DB->query($query); |
746 |
} |
747 |
} |
748 |
} |
749 |
} |
750 |
|
751 |
$query = "DELETE FROM `".$input["tablename"]."` WHERE `ID` = '" . $input["oldID"] . "'"; |
752 |
$DB->query($query); |
753 |
|
754 |
// Need to be done on entity class
|
755 |
if ($input["tablename"]=="glpi_entities"){ |
756 |
$query = "DELETE FROM `glpi_entities_data` WHERE `FK_entities` = '" . $input["oldID"] . "'"; |
757 |
$DB->query($query); |
758 |
|
759 |
if (isset($_SESSION["glpiID"])){ |
760 |
$activeprof=$_SESSION['glpiactiveprofile']['ID']; |
761 |
initEntityProfiles($_SESSION["glpiID"]); |
762 |
changeProfile($activeprof);
|
763 |
} |
764 |
} |
765 |
cleanRelationCache($input["tablename"]); |
766 |
} |
767 |
|
768 |
function showDeleteConfirmForm($target, $table, $ID,$FK_entities) { |
769 |
global $DB, $LANG,$CFG_GLPI; |
770 |
|
771 |
if (in_array($table, $CFG_GLPI["specif_entities_tables"])) { |
772 |
if (!haveRight("entity_dropdown","w")) |
773 |
return false; |
774 |
} else {
|
775 |
if (!haveRight("dropdown", "w")) |
776 |
return false; |
777 |
} |
778 |
|
779 |
if (in_array($table,$CFG_GLPI["dropdowntree_tables"])) { |
780 |
|
781 |
$query = "SELECT COUNT(*) AS cpt FROM `$table` WHERE `parentID` = '" . $ID . "'"; |
782 |
$result = $DB->query($query); |
783 |
if ($DB->result($result, 0, "cpt") > 0) { |
784 |
echo "<div class='center'><p class='red'>" . $LANG["setup"][74] . "</p></div>"; |
785 |
return;
|
786 |
} |
787 |
|
788 |
if ($table == "glpi_dropdown_kbcategories") { |
789 |
$query = "SELECT COUNT(*) AS cpt FROM `glpi_kbitems` WHERE `categoryID` = '" . $ID . "'"; |
790 |
$result = $DB->query($query); |
791 |
if ($DB->result($result, 0, "cpt") > 0) { |
792 |
echo "<div class='center'><p class='red'>" . $LANG["setup"][74] . "</p></div>"; |
793 |
return;
|
794 |
} |
795 |
} |
796 |
} |
797 |
|
798 |
|
799 |
|
800 |
echo "<div class='center'>"; |
801 |
echo "<p class='red'>" . $LANG["setup"][63] . "</p>"; |
802 |
|
803 |
if ($table!="glpi_entities"){ |
804 |
echo "<p>" . $LANG["setup"][64] . "</p>"; |
805 |
echo "<form action=\"" . $target . "\" method=\"post\">"; |
806 |
echo "<input type=\"hidden\" name=\"tablename\" value=\"" . $table . "\" />"; |
807 |
echo "<input type=\"hidden\" name=\"ID\" value=\"" . $ID . "\" />"; |
808 |
echo "<input type=\"hidden\" name=\"which\" value=\"" . $table . "\" />"; |
809 |
echo "<input type=\"hidden\" name=\"forcedelete\" value=\"1\" />"; |
810 |
echo "<input type=\"hidden\" name=\"FK_entities\" value=\"$FK_entities\" />"; |
811 |
|
812 |
echo "<table class='tab_cadre'><tr><td>"; |
813 |
echo "<input class='button' type=\"submit\" name=\"delete\" value=\"" . $LANG["buttons"][2] . "\" /></td>"; |
814 |
|
815 |
echo "<td><input class='button' type=\"submit\" name=\"annuler\" value=\"" . $LANG["buttons"][34] . "\" /></td></tr></table>"; |
816 |
echo "</form>"; |
817 |
} |
818 |
echo "<p>" . $LANG["setup"][65] . "</p>"; |
819 |
echo "<form action=\" " . $target . "\" method=\"post\">"; |
820 |
echo "<input type=\"hidden\" name=\"which\" value=\"" . $table . "\" />"; |
821 |
echo "<table class='tab_cadre'><tr><td>"; |
822 |
dropdownNoValue($table, "newID", $ID,$FK_entities); |
823 |
echo "<input type=\"hidden\" name=\"tablename\" value=\"" . $table . "\" />"; |
824 |
echo "<input type=\"hidden\" name=\"oldID\" value=\"" . $ID . "\" />"; |
825 |
echo "<input type=\"hidden\" name=\"FK_entities\" value=\"$FK_entities\" />"; |
826 |
echo "</td><td><input class='button' type=\"submit\" name=\"replace\" value=\"" . $LANG["buttons"][39] . "\" /></td><td>"; |
827 |
echo "<input class='button' type=\"submit\" name=\"annuler\" value=\"" . $LANG["buttons"][34] . "\" /></td></tr></table>"; |
828 |
echo "</form>"; |
829 |
|
830 |
echo "</div>"; |
831 |
} |
832 |
|
833 |
function getDropdownNameFromTable($table) { |
834 |
$name=""; |
835 |
if (ereg("glpi_type_", $table)) { |
836 |
$name = ereg_replace("glpi_type_", "", $table); |
837 |
} else {
|
838 |
if ($table == "glpi_dropdown_locations") |
839 |
$name = "location"; |
840 |
else {
|
841 |
$name = ereg_replace("glpi_dropdown_", "", $table); |
842 |
} |
843 |
} |
844 |
return $name; |
845 |
} |
846 |
|
847 |
function getDropdownNameFromTableForStats($table) { |
848 |
|
849 |
if (ereg("glpi_type_", $table)) { |
850 |
$name = "type"; |
851 |
} else {
|
852 |
if ($table == "glpi_dropdown_locations") |
853 |
$name = "location"; |
854 |
else {
|
855 |
$name = ereg_replace("glpi_dropdown_", "", $table); |
856 |
} |
857 |
} |
858 |
return $name; |
859 |
} |
860 |
|
861 |
/** Check if the dropdown $ID is used into item tables
|
862 |
* @param $table string : table name
|
863 |
* @param $ID integer : value ID
|
864 |
* @return boolean : is the value used ?
|
865 |
*/
|
866 |
function dropdownUsed($table, $ID) { |
867 |
|
868 |
global $DB; |
869 |
$name = getDropdownNameFromTable($table); |
870 |
|
871 |
$RELATION = getDbRelations();
|
872 |
if (isset ($RELATION[$table])){ |
873 |
foreach ($RELATION[$table] as $tablename => $field) { |
874 |
if ($tablename[0]!='_'){ |
875 |
if (!is_array($field)){ |
876 |
$query = "SELECT COUNT(*) AS cpt FROM `$tablename` WHERE `$field` = '" . $ID . "'"; |
877 |
$result = $DB->query($query); |
878 |
if ($DB->result($result, 0, "cpt") > 0){ |
879 |
return true; |
880 |
} |
881 |
} else {
|
882 |
foreach ($field as $f){ |
883 |
$query = "SELECT COUNT(*) AS cpt FROM `$tablename` WHERE `$f` = '" . $ID . "'"; |
884 |
$result = $DB->query($query); |
885 |
if ($DB->result($result, 0, "cpt") > 0){ |
886 |
return true; |
887 |
} |
888 |
} |
889 |
} |
890 |
} |
891 |
} |
892 |
} |
893 |
|
894 |
return false; |
895 |
|
896 |
} |
897 |
|
898 |
function listTemplates($type, $target, $add = 0) { |
899 |
|
900 |
global $DB, $CFG_GLPI, $LANG; |
901 |
|
902 |
//Check is user have minimum right r
|
903 |
if (!haveTypeRight($type, "r") && !haveTypeRight($type, "w")) |
904 |
return false; |
905 |
|
906 |
switch ($type) { |
907 |
case COMPUTER_TYPE : |
908 |
$title = $LANG["Menu"][0]; |
909 |
$query = "SELECT * FROM glpi_computers WHERE is_template = '1' AND FK_entities='" . $_SESSION["glpiactive_entity"] . "' ORDER by tplname"; |
910 |
break;
|
911 |
case NETWORKING_TYPE : |
912 |
$title = $LANG["Menu"][1]; |
913 |
$query = "SELECT * FROM glpi_networking WHERE is_template = '1' AND FK_entities='" . $_SESSION["glpiactive_entity"] . "' ORDER by tplname"; |
914 |
break;
|
915 |
case MONITOR_TYPE : |
916 |
$title = $LANG["Menu"][3]; |
917 |
$query = "SELECT * FROM glpi_monitors WHERE is_template = '1' AND FK_entities='" . $_SESSION["glpiactive_entity"] . "' ORDER by tplname"; |
918 |
break;
|
919 |
case PRINTER_TYPE : |
920 |
$title = $LANG["Menu"][2]; |
921 |
$query = "SELECT * FROM glpi_printers WHERE is_template = '1' AND FK_entities='" . $_SESSION["glpiactive_entity"] . "' ORDER by tplname"; |
922 |
break;
|
923 |
case PERIPHERAL_TYPE : |
924 |
$title = $LANG["Menu"][16]; |
925 |
$query = "SELECT * FROM glpi_peripherals WHERE is_template = '1' AND FK_entities='" . $_SESSION["glpiactive_entity"] . "' ORDER by tplname"; |
926 |
break;
|
927 |
case SOFTWARE_TYPE : |
928 |
$title = $LANG["Menu"][4]; |
929 |
$query = "SELECT * FROM glpi_software WHERE is_template = '1' AND FK_entities='" . $_SESSION["glpiactive_entity"] . "' ORDER by tplname"; |
930 |
break;
|
931 |
case PHONE_TYPE : |
932 |
$title = $LANG["Menu"][34]; |
933 |
$query = "SELECT * FROM glpi_phones WHERE is_template = '1' AND FK_entities='" . $_SESSION["glpiactive_entity"] . "' ORDER by tplname"; |
934 |
break;
|
935 |
case OCSNG_TYPE : |
936 |
$title = $LANG["Menu"][33]; |
937 |
$query = "SELECT * FROM glpi_ocs_config WHERE is_template = '1' ORDER by tplname"; |
938 |
break;
|
939 |
|
940 |
} |
941 |
if ($result = $DB->query($query)) { |
942 |
|
943 |
echo "<div class='center'><table class='tab_cadre' width='50%'>"; |
944 |
if ($add) { |
945 |
echo "<tr><th>" . $LANG["common"][7] . " - $title:</th></tr>"; |
946 |
} else {
|
947 |
echo "<tr><th colspan='2'>" . $LANG["common"][14] . " - $title:</th></tr>"; |
948 |
} |
949 |
|
950 |
if ($add) { |
951 |
|
952 |
echo "<tr>"; |
953 |
echo "<td align='center' class='tab_bg_1'>"; |
954 |
echo "<a href=\"$target?ID=-1&withtemplate=2\"> " . $LANG["common"][31] . " </a></td>"; |
955 |
echo "</tr>"; |
956 |
} |
957 |
|
958 |
while ($data = $DB->fetch_array($result)) { |
959 |
|
960 |
$templname = $data["tplname"]; |
961 |
if ($CFG_GLPI["view_ID"]||empty($data["tplname"])){ |
962 |
$templname.= "(".$data["ID"].")"; |
963 |
} |
964 |
echo "<tr>"; |
965 |
echo "<td align='center' class='tab_bg_1'>"; |
966 |
|
967 |
if (haveTypeRight($type, "w") && !$add) { |
968 |
echo "<a href=\"$target?ID=" . $data["ID"] . "&withtemplate=1\"> $templname </a></td>"; |
969 |
|
970 |
echo "<td align='center' class='tab_bg_2'>"; |
971 |
echo "<strong><a href=\"$target?ID=" . $data["ID"] . "&purge=purge&withtemplate=1\">" . $LANG["buttons"][6] . "</a></strong>"; |
972 |
echo "</td>"; |
973 |
} else {
|
974 |
echo "<a href=\"$target?ID=" . $data["ID"] . "&withtemplate=2\"> $templname </a></td>"; |
975 |
} |
976 |
|
977 |
echo "</tr>"; |
978 |
|
979 |
} |
980 |
|
981 |
if (haveTypeRight($type, "w") &&!$add) { |
982 |
echo "<tr>"; |
983 |
echo "<td colspan='2' align='center' class='tab_bg_2'>"; |
984 |
echo "<strong><a href=\"$target?withtemplate=1\">" . $LANG["common"][9] . "</a></strong>"; |
985 |
echo "</td>"; |
986 |
echo "</tr>"; |
987 |
} |
988 |
|
989 |
echo "</table></div>"; |
990 |
} |
991 |
|
992 |
} |
993 |
|
994 |
function showFormExtAuthList($target) { |
995 |
|
996 |
global $DB, $LANG, $CFG_GLPI; |
997 |
|
998 |
if (!haveRight("config", "w")) |
999 |
return false; |
1000 |
echo "<div class='center'>"; |
1001 |
echo "<form name=cas action=\"$target\" method=\"post\">"; |
1002 |
echo "<input type='hidden' name='ID' value='" . $CFG_GLPI["ID"] . "'>"; |
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
echo "<div id='barre_onglets'><ul id='onglet'>"; |
1008 |
|
1009 |
$onglets=array( |
1010 |
1 => $LANG["login"][2], |
1011 |
2 => $LANG["login"][3], |
1012 |
3 => $LANG["common"][67] |
1013 |
); |
1014 |
|
1015 |
foreach($onglets as $key => $val){ |
1016 |
echo "<li "; |
1017 |
if ($_SESSION['glpi_authconfig'] == $key) { |
1018 |
echo "class='actif'"; |
1019 |
} |
1020 |
echo "><a href='$target?onglet=$key'>$val</a></li>"; |
1021 |
} |
1022 |
echo "</ul></div>"; |
1023 |
|
1024 |
|
1025 |
switch ($_SESSION['glpi_authconfig']){ |
1026 |
case 2 : |
1027 |
if (canUseImapPop()) {
|
1028 |
echo "<table class='tab_cadre_fixe' cellpadding='5'>"; |
1029 |
echo "<tr><th colspan='2'>"; |
1030 |
echo "<strong>" . $LANG["login"][3] . "</strong>"; |
1031 |
|
1032 |
echo "</th></tr>"; |
1033 |
echo "<tr class='tab_bg_1'><td class='center'>" . $LANG["common"][16] . "</td><td class='center'>" . $LANG["common"][52] . "</td></tr>"; |
1034 |
$sql = "SELECT * from glpi_auth_mail"; |
1035 |
$result = $DB->query($sql); |
1036 |
if ($DB->numrows($result)) { |
1037 |
|
1038 |
|
1039 |
while ($mail_method = $DB->fetch_array($result)){ |
1040 |
echo "<tr class='tab_bg_2'><td class='center'><a href='$target?next=extauth_mail&ID=" . $mail_method["ID"] . "' >" . $mail_method["name"] . "</a>" . |
1041 |
"</td><td class='center'>" . $mail_method["imap_host"] . "</td></tr>"; |
1042 |
} |
1043 |
} |
1044 |
echo "</table>"; |
1045 |
} else {
|
1046 |
echo "<input type=\"hidden\" name=\"IMAP_Test\" value=\"1\" >"; |
1047 |
|
1048 |
echo "<table class='tab_cadre_fixe'>"; |
1049 |
echo "<tr><th colspan='2'>" . $LANG["setup"][162] . "</th></tr>"; |
1050 |
echo "<tr class='tab_bg_2'><td class='center'><p class='red'>" . $LANG["setup"][165] . "</p><p>" . $LANG["setup"][166] . "</p></td></tr></table>"; |
1051 |
} |
1052 |
break;
|
1053 |
case 1 : |
1054 |
if (canUseLdap()) {
|
1055 |
|
1056 |
echo "<table class='tab_cadre_fixe' cellpadding='5'>"; |
1057 |
echo "<tr><th colspan='2'>"; |
1058 |
echo "<strong>" . $LANG["login"][2] . "</strong>"; |
1059 |
echo "</th></tr>"; |
1060 |
echo "<tr class='tab_bg_1'><td class='center'>" . $LANG["common"][16] . "</td><td class='center'>" . $LANG["common"][52] . "</td></tr>"; |
1061 |
|
1062 |
$sql = "SELECT * from glpi_auth_ldap"; |
1063 |
$result = $DB->query($sql); |
1064 |
if ($DB->numrows($result)) { |
1065 |
while ($ldap_method = $DB->fetch_array($result)){ |
1066 |
echo "<tr class='tab_bg_2'><td class='center'><a href='$target?next=extauth_ldap&ID=" . $ldap_method["ID"] . "' >" . $ldap_method["name"] . "</a>" . |
1067 |
"</td><td class='center'>" . $LANG["ldap"][21]." : ".$ldap_method["ldap_host"].":".$ldap_method["ldap_port"]; |
1068 |
$replicates=getAllReplicatesNamesForAMaster($ldap_method["ID"]); |
1069 |
if (!empty($replicates)){ |
1070 |
echo "<br>".$LANG["ldap"][22]." : ".$replicates. "</td>"; |
1071 |
} |
1072 |
echo '</tr>'; |
1073 |
} |
1074 |
} |
1075 |
echo "</table>"; |
1076 |
} else {
|
1077 |
echo "<input type=\"hidden\" name=\"LDAP_Test\" value=\"1\" >"; |
1078 |
echo "<table class='tab_cadre_fixe'>"; |
1079 |
echo "<tr><th colspan='2'>" . $LANG["setup"][152] . "</th></tr>"; |
1080 |
echo "<tr class='tab_bg_2'><td class='center'><p class='red'>" . $LANG["setup"][157] . "</p><p>" . $LANG["setup"][158] . "</p></td></tr></table>"; |
1081 |
} |
1082 |
break;
|
1083 |
|
1084 |
case 3 : |
1085 |
echo "<table class='tab_cadre_fixe' cellpadding='5'>"; |
1086 |
|
1087 |
// CAS config
|
1088 |
echo "<tr><th colspan='2'>" . $LANG["setup"][177]; |
1089 |
if (!empty($CFG_GLPI["cas_host"])){ |
1090 |
echo " - ".$LANG["setup"][192]; |
1091 |
} |
1092 |
echo "</th></tr>"; |
1093 |
|
1094 |
if (function_exists('curl_init') && (version_compare(PHP_VERSION, '5', '>=') || (function_exists("domxml_open_mem") && function_exists("utf8_decode")))) { |
1095 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][174] . "</td><td><input type=\"text\" name=\"cas_host\" value=\"" . $CFG_GLPI["cas_host"] . "\"></td></tr>"; |
1096 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][175] . "</td><td><input type=\"text\" name=\"cas_port\" value=\"" . $CFG_GLPI["cas_port"] . "\"></td></tr>"; |
1097 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][176] . "</td><td><input type=\"text\" name=\"cas_uri\" value=\"" . $CFG_GLPI["cas_uri"] . "\" ></td></tr>"; |
1098 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][182] . "</td><td><input type=\"text\" name=\"cas_logout\" value=\"" . $CFG_GLPI["cas_logout"] . "\" ></td></tr>"; |
1099 |
} else {
|
1100 |
echo "<tr class='tab_bg_2'><td class='center' colspan='2'><p class='red'>" . $LANG["setup"][178] . "</p><p>" . $LANG["setup"][179] . "</p></td></tr>"; |
1101 |
} |
1102 |
// X509 config
|
1103 |
echo "<tr><th colspan='2'>" . $LANG["setup"][190]; |
1104 |
if (!empty($CFG_GLPI["x509_email_field"])){ |
1105 |
echo " - ".$LANG["setup"][192]; |
1106 |
} |
1107 |
echo "</th></tr>"; |
1108 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][191] . "</td><td><input type=\"text\" name=\"x509_email_field\" value=\"" . $CFG_GLPI["x509_email_field"] . "\"></td></tr>"; |
1109 |
|
1110 |
// X509 config
|
1111 |
echo "<tr><th colspan='2'>" . $LANG["common"][67]; |
1112 |
if (!empty($CFG_GLPI["existing_auth_server_field"])){ |
1113 |
echo " - ".$LANG["setup"][192]; |
1114 |
} |
1115 |
echo "</th></tr>"; |
1116 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][193] . "</td><td>"; |
1117 |
echo "<select name='existing_auth_server_field'>"; |
1118 |
echo "<option value=''> </option>"; |
1119 |
echo "<option value='HTTP_AUTH_USER' " . ($CFG_GLPI["existing_auth_server_field"]=="HTTP_AUTH_USER" ? " selected " : "") . ">HTTP_AUTH_USER</option>"; |
1120 |
echo "<option value='REMOTE_USER' " . ($CFG_GLPI["existing_auth_server_field"]=="REMOTE_USER" ? " selected " : "") . ">REMOTE_USER</option>"; |
1121 |
echo "<option value='PHP_AUTH_USER' " . ($CFG_GLPI["existing_auth_server_field"]=="PHP_AUTH_USER" ? " selected " : "") . ">PHP_AUTH_USER</option>"; |
1122 |
echo "<option value='USERNAME' " . ($CFG_GLPI["existing_auth_server_field"]=="USERNAME" ? " selected " : "") . ">USERNAME</option>"; |
1123 |
echo "<option value='REDIRECT_REMOTE_USER' " . ($CFG_GLPI["existing_auth_server_field"]=="REDIRECT_REMOTE_USER" ? " selected " : "") . ">REDIRECT_REMOTE_USER</option>"; |
1124 |
echo "</select>"; |
1125 |
|
1126 |
echo "</td></tr>"; |
1127 |
|
1128 |
echo "<tr><th colspan='2'>" . $LANG["setup"][194]."</th></tr>"; |
1129 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["ldap"][4] . "</td><td>"; |
1130 |
dropdownValue("glpi_auth_ldap","extra_ldap_server",$CFG_GLPI["extra_ldap_server"]); |
1131 |
echo "</td></tr>"; |
1132 |
|
1133 |
echo "<tr class='tab_bg_1'><td align='center' colspan='2'><input type=\"submit\" name=\"update\" class=\"submit\" value=\"" . $LANG["buttons"][7] . "\" ></td></tr>"; |
1134 |
|
1135 |
echo "</table>"; |
1136 |
break;
|
1137 |
} |
1138 |
|
1139 |
|
1140 |
echo "</form>"; |
1141 |
echo "</div>"; |
1142 |
} |
1143 |
|
1144 |
|
1145 |
function showMailServerConfig($value) { |
1146 |
global $LANG; |
1147 |
|
1148 |
if (!haveRight("config", "w")) |
1149 |
return false; |
1150 |
|
1151 |
if (ereg(":", $value)) { |
1152 |
$addr = ereg_replace("{", "", preg_replace("/:.*/", "", $value)); |
1153 |
$port = preg_replace("/.*:/", "", preg_replace("/\/.*/", "", $value)); |
1154 |
} else {
|
1155 |
if (ereg("/", $value)) |
1156 |
$addr = ereg_replace("{", "", preg_replace("/\/.*/", "", $value)); |
1157 |
else
|
1158 |
$addr = ereg_replace("{", "", preg_replace("/}.*/", "", $value)); |
1159 |
$port = ""; |
1160 |
} |
1161 |
$mailbox = preg_replace("/.*}/", "", $value); |
1162 |
|
1163 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["common"][52] . "</td><td><input size='30' type=\"text\" name=\"mail_server\" value=\"" . $addr . "\" ></td></tr>"; |
1164 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][168] . "</td><td>"; |
1165 |
echo "<select name='server_type'>"; |
1166 |
echo "<option value=''> </option>"; |
1167 |
echo "<option value='/imap' " . (ereg("/imap", $value) ? " selected " : "") . ">IMAP</option>"; |
1168 |
echo "<option value='/pop' " . (ereg("/pop", $value) ? " selected " : "") . ">POP</option>"; |
1169 |
echo "</select>"; |
1170 |
echo "<select name='server_ssl'>"; |
1171 |
echo "<option value=''> </option>"; |
1172 |
echo "<option value='/ssl' " . (ereg("/ssl", $value) ? " selected " : "") . ">SSL</option>"; |
1173 |
echo "</select>"; |
1174 |
|
1175 |
echo "<select name='server_tls'>"; |
1176 |
echo "<option value=''> </option>"; |
1177 |
echo "<option value='/tls' " . (ereg("/tls", $value) ? " selected " : "") . ">TLS</option>"; |
1178 |
echo "<option value='/notls' " . (ereg("/notls", $value) ? " selected " : "") . ">NO-TLS</option>"; |
1179 |
echo "</select>"; |
1180 |
|
1181 |
echo "<select name='server_cert'>"; |
1182 |
echo "<option value=''> </option>"; |
1183 |
echo "<option value='/novalidate-cert' " . (ereg("/novalidate-cert", $value) ? " selected " : "") . ">NO-VALIDATE-CERT</option>"; |
1184 |
echo "<option value='/validate-cert' " . (ereg("/validate-cert", $value) ? " selected " : "") . ">VALIDATE-CERT</option>"; |
1185 |
echo "</select>"; |
1186 |
|
1187 |
echo "<input type=hidden name=imap_string value='".$value."'>"; |
1188 |
echo "</td></tr>"; |
1189 |
|
1190 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][169] . "</td><td><input size='30' type=\"text\" name=\"server_mailbox\" value=\"" . $mailbox . "\" ></td></tr>"; |
1191 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][171] . "</td><td><input size='10' type=\"text\" name=\"server_port\" value=\"" . $port . "\" ></td></tr>"; |
1192 |
if (empty ($value)) |
1193 |
$value = " "; |
1194 |
echo "<tr class='tab_bg_2'><td class='center'>" . $LANG["setup"][170] . "</td><td><strong>$value</strong></td></tr>"; |
1195 |
|
1196 |
} |
1197 |
function constructMailServerConfig($input) { |
1198 |
|
1199 |
$out = ""; |
1200 |
if (isset ($input['mail_server']) && !empty ($input['mail_server'])) |
1201 |
$out .= "{" . $input['mail_server']; |
1202 |
else
|
1203 |
return $out; |
1204 |
if (isset ($input['server_port']) && !empty ($input['server_port'])) |
1205 |
$out .= ":" . $input['server_port']; |
1206 |
if (isset ($input['server_type'])) |
1207 |
$out .= $input['server_type']; |
1208 |
if (isset ($input['server_ssl'])) |
1209 |
$out .= $input['server_ssl']; |
1210 |
if (isset ($input['server_cert'])&& ( !empty($input['server_ssl']) || !empty($input['server_tls']))) |
1211 |
$out .= $input['server_cert']; |
1212 |
if (isset ($input['server_tls'])) |
1213 |
$out .= $input['server_tls']; |
1214 |
|
1215 |
$out .= "}"; |
1216 |
if (isset ($input['server_mailbox'])) |
1217 |
$out .= $input['server_mailbox']; |
1218 |
|
1219 |
return $out; |
1220 |
|
1221 |
} |
1222 |
|
1223 |
?>
|