ryxeo-glpi-git / inc / dropdown.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (73,8 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: dropdown.function.php 7882 2009-01-23 18:24:05Z moyo $
|
4 |
-------------------------------------------------------------------------
|
5 |
GLPI - Gestionnaire Libre de Parc Informatique
|
6 |
Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
7 |
|
8 |
http://indepnet.net/ http://glpi-project.org
|
9 |
-------------------------------------------------------------------------
|
10 |
|
11 |
LICENSE
|
12 |
|
13 |
This file is part of GLPI.
|
14 |
|
15 |
GLPI is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
17 |
the Free Software Foundation; either version 2 of the License, or
|
18 |
(at your option) any later version.
|
19 |
|
20 |
GLPI is distributed in the hope that it will be useful,
|
21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
GNU General Public License for more details.
|
24 |
|
25 |
You should have received a copy of the GNU General Public License
|
26 |
along with GLPI; if not, write to the Free Software
|
27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
28 |
--------------------------------------------------------------------------
|
29 |
*/
|
30 |
|
31 |
// ----------------------------------------------------------------------
|
32 |
// Original Author of file:
|
33 |
// Purpose of file:
|
34 |
// ----------------------------------------------------------------------
|
35 |
|
36 |
if (!defined('GLPI_ROOT')){ |
37 |
die("Sorry. You can't access directly to this file"); |
38 |
} |
39 |
|
40 |
// Functions Dropdown
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
/**
|
46 |
* Print out an HTML "<select>" for a dropdown
|
47 |
*
|
48 |
* @param $table the dropdown table from witch we want values on the select
|
49 |
* @param $myname the name of the HTML select
|
50 |
* @param $display_comments display the comments near the dropdown
|
51 |
* @param $entity_restrict Restrict to a defined entity
|
52 |
* @param $used Already used items : not to display in dropdown
|
53 |
* @return nothing (display the select box)
|
54 |
**/
|
55 |
function dropdown($table,$myname,$display_comments=1,$entity_restrict=-1,$used=array()) { |
56 |
|
57 |
return dropdownValue($table,$myname,'',$display_comments,$entity_restrict,"",$used); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Print out an HTML "<select>" for a dropdown with preselected value
|
62 |
*
|
63 |
*
|
64 |
* @param $table the dropdown table from witch we want values on the select
|
65 |
* @param $myname the name of the HTML select
|
66 |
* @param $value the preselected value we want
|
67 |
* @param $display_comments display the comments near the dropdown
|
68 |
* @param $entity_restrict Restrict to a defined entity
|
69 |
* @param $update_item Update a specific item on select change on dropdown (need value_fieldname, to_update, url (see ajaxUpdateItemOnSelectEvent for informations) and may have moreparams)
|
70 |
* @param $used Already used items : not to display in dropdown
|
71 |
* @return nothing (display the select box)
|
72 |
*
|
73 |
*/
|
74 |
function dropdownValue($table,$myname,$value='',$display_comments=1,$entity_restrict=-1,$update_item="",$used=array()) { |
75 |
|
76 |
global $DB,$CFG_GLPI,$LANG; |
77 |
|
78 |
$rand=mt_rand();
|
79 |
|
80 |
$name="------"; |
81 |
$comments=""; |
82 |
$limit_length=$CFG_GLPI["dropdown_limit"]; |
83 |
|
84 |
|
85 |
if (strlen($value)==0) $value=-1; |
86 |
|
87 |
if ($value>0 |
88 |
|| ($table=="glpi_entities"&&$value>=0)){ |
89 |
$tmpname=getDropdownName($table,$value,1); |
90 |
if ($tmpname["name"]!=" "){ |
91 |
$name=$tmpname["name"]; |
92 |
$comments=$tmpname["comments"]; |
93 |
$limit_length=max(strlen($name),$CFG_GLPI["dropdown_limit"]); |
94 |
} |
95 |
} |
96 |
|
97 |
$use_ajax=false; |
98 |
if ($CFG_GLPI["use_ajax"]){ |
99 |
$nb=0; |
100 |
if ($table=='glpi_entities' || in_array($table,$CFG_GLPI["specif_entities_tables"])){ |
101 |
if (!($entity_restrict<0)){ |
102 |
$nb=countElementsInTableForEntity($table,$entity_restrict); |
103 |
} else {
|
104 |
$nb=countElementsInTableForMyEntities($table); |
105 |
} |
106 |
} else {
|
107 |
$nb=countElementsInTable($table); |
108 |
} |
109 |
$nb -= count($used); |
110 |
if ($nb>$CFG_GLPI["ajax_limit_count"]){ |
111 |
$use_ajax=true; |
112 |
} |
113 |
} |
114 |
|
115 |
$params=array('searchText'=>'__VALUE__', |
116 |
'value'=>$value, |
117 |
'table'=>$table, |
118 |
'myname'=>$myname, |
119 |
'limit'=>$limit_length, |
120 |
'comments'=>$display_comments, |
121 |
'rand'=>$rand, |
122 |
'entity_restrict'=>$entity_restrict, |
123 |
'update_item'=>$update_item, |
124 |
'used'=>$used |
125 |
); |
126 |
$default="<select name='$myname' id='dropdown_".$myname.$rand."'><option value='$value'>$name</option></select>\n"; |
127 |
ajaxDropdown($use_ajax,"/ajax/dropdownValue.php",$params,$default,$rand); |
128 |
|
129 |
// Display comments
|
130 |
$which=""; |
131 |
|
132 |
$dropdown_right=false; |
133 |
|
134 |
if (ereg("glpi_dropdown_",$table)||ereg("glpi_type_",$table)){ |
135 |
if (!in_array($table,$CFG_GLPI["specif_entities_tables"])){ |
136 |
$dropdown_right=haveRight("dropdown","w"); |
137 |
} else {
|
138 |
$dropdown_right=haveRight("entity_dropdown","w"); |
139 |
} |
140 |
|
141 |
if ($dropdown_right){ |
142 |
$which=$table; |
143 |
} |
144 |
} |
145 |
|
146 |
if ($display_comments){ |
147 |
echo "<img alt='' src='".$CFG_GLPI["root_doc"]."/pics/aide.png' onmouseout=\"cleanhide('comments_$myname$rand')\" onmouseover=\"cleandisplay('comments_$myname$rand')\" "; |
148 |
if ($dropdown_right && !empty($which)) { |
149 |
if (is_array($entity_restrict) && count($entity_restrict)==1) { |
150 |
$entity_restrict=array_pop($entity_restrict); |
151 |
} |
152 |
if (!is_array($entity_restrict)) { |
153 |
echo " style='cursor:pointer;' onClick=\"var w = window.open('".$CFG_GLPI["root_doc"]."/front/popup.php?popup=dropdown&which=$which"."&rand=$rand&FK_entities=$entity_restrict' ,'glpipopup', 'height=400, width=1000, top=100, left=100, scrollbars=yes' );w.focus();\""; |
154 |
} |
155 |
} |
156 |
echo ">"; |
157 |
echo "<span class='over_link' id='comments_$myname$rand'>".nl2br($comments)."</span>"; |
158 |
} |
159 |
// Display specific Links
|
160 |
if ($table=="glpi_enterprises"){ |
161 |
echo getEnterpriseLinks($value); |
162 |
} |
163 |
|
164 |
return $rand; |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Print out an HTML "<select>" for a dropdown with preselected value
|
169 |
*
|
170 |
*
|
171 |
* @param $myname the name of the HTML select
|
172 |
* @param $value the preselected value we want
|
173 |
* @param $location default location for search
|
174 |
* @param $display_comments display the comments near the dropdown
|
175 |
* @param $entity_restrict Restrict to a defined entity
|
176 |
* @param $devtype
|
177 |
* @return nothing (display the select box)
|
178 |
*
|
179 |
*/
|
180 |
function dropdownNetpoint($myname,$value=0,$location=-1,$display_comments=1,$entity_restrict=-1,$devtype=-1) { |
181 |
|
182 |
global $DB,$CFG_GLPI,$LANG; |
183 |
|
184 |
$rand=mt_rand();
|
185 |
|
186 |
$name="------"; |
187 |
$comments=""; |
188 |
$limit_length=$CFG_GLPI["dropdown_limit"]; |
189 |
if (empty($value)) $value=0; |
190 |
if ($value>0){ |
191 |
$tmpname=getDropdownName("glpi_dropdown_netpoint",$value,1); |
192 |
if ($tmpname["name"]!=" "){ |
193 |
$name=$tmpname["name"]; |
194 |
$comments=$tmpname["comments"]; |
195 |
$limit_length=max(strlen($name),$CFG_GLPI["dropdown_limit"]); |
196 |
} |
197 |
} |
198 |
|
199 |
$use_ajax=false; |
200 |
if ($CFG_GLPI["use_ajax"]){ |
201 |
if ($location < 0 || $devtype==NETWORKING_TYPE) { |
202 |
$nb=countElementsInTableForEntity("glpi_dropdown_netpoint",$entity_restrict); |
203 |
} else if ($location > 0) { |
204 |
$nb=countElementsInTable("glpi_dropdown_netpoint", "location=$location "); |
205 |
} else {
|
206 |
$nb=countElementsInTable("glpi_dropdown_netpoint", "location=0 ".getEntitiesRestrictRequest(" AND ","glpi_dropdown_netpoint",'',$entity_restrict)); |
207 |
} |
208 |
if ($nb>$CFG_GLPI["ajax_limit_count"]){ |
209 |
$use_ajax=true; |
210 |
} |
211 |
} |
212 |
|
213 |
$params=array('searchText'=>'__VALUE__', |
214 |
'value'=>$value, |
215 |
'location'=>$location, |
216 |
'myname'=>$myname, |
217 |
'limit'=>$limit_length, |
218 |
'comments'=>$display_comments, |
219 |
'rand'=>$rand, |
220 |
'entity_restrict'=>$entity_restrict, |
221 |
'devtype'=>$devtype, |
222 |
); |
223 |
|
224 |
$default="<select name='$myname'><option value='$value'>$name</option></select>\n"; |
225 |
ajaxDropdown($use_ajax,"/ajax/dropdownNetpoint.php",$params,$default,$rand); |
226 |
|
227 |
// Display comments
|
228 |
|
229 |
if ($display_comments){ |
230 |
echo "<img alt='' src='".$CFG_GLPI["root_doc"]."/pics/aide.png' onmouseout=\"cleanhide('comments_$myname$rand')\" onmouseover=\"cleandisplay('comments_$myname$rand')\" "; |
231 |
if (haveRight("entity_dropdown","w")) { |
232 |
echo " style='cursor:pointer;' onClick=\"var w = window.open('".$CFG_GLPI["root_doc"]."/front/popup.php?popup=dropdown&which=glpi_dropdown_netpoint&value2=$location"."&rand=$rand&FK_entities=$entity_restrict' ,'glpipopup', 'height=400, width=1000, top=100, left=100, scrollbars=yes' );w.focus();\""; |
233 |
} |
234 |
echo ">"; |
235 |
echo "<span class='over_link' id='comments_$myname$rand'>".nl2br($comments)."</span>"; |
236 |
} |
237 |
|
238 |
return $rand; |
239 |
} |
240 |
|
241 |
|
242 |
|
243 |
/**
|
244 |
* Make a select box without parameters value
|
245 |
*
|
246 |
*
|
247 |
* @param $table the dropdown table from witch we want values on the select
|
248 |
* @param $myname the name of the HTML select
|
249 |
* @param $value the preselected value we want
|
250 |
* @param $entity_restrict Restrict to a defined entity
|
251 |
* @return nothing (print out an HTML select box)
|
252 |
*
|
253 |
*/
|
254 |
function dropdownNoValue($table,$myname,$value,$entity_restrict=-1) { |
255 |
// Make a select box without parameters value
|
256 |
|
257 |
global $DB,$CFG_GLPI,$LANG; |
258 |
|
259 |
$where=""; |
260 |
if (in_array($table,$CFG_GLPI["specif_entities_tables"])){ |
261 |
$where.= "WHERE `".$table."`.`FK_entities`='".$entity_restrict."'"; |
262 |
} |
263 |
|
264 |
if (in_array($table,$CFG_GLPI["deleted_tables"])){ |
265 |
if (empty($where)){ |
266 |
$where=" WHERE "; |
267 |
} else {
|
268 |
$where.=" AND "; |
269 |
} |
270 |
$where=" WHERE deleted='0'"; |
271 |
} |
272 |
if (in_array($table,$CFG_GLPI["template_tables"])){ |
273 |
if (empty($where)){ |
274 |
$where=" WHERE "; |
275 |
} else {
|
276 |
$where.=" AND "; |
277 |
} |
278 |
$where.=" is_template='0'"; |
279 |
} |
280 |
|
281 |
if (empty($where)){ |
282 |
$where=" WHERE "; |
283 |
} else {
|
284 |
$where.=" AND "; |
285 |
} |
286 |
$where.=" ID<>'$value' "; |
287 |
|
288 |
if (in_array($table,$CFG_GLPI["dropdowntree_tables"])){ |
289 |
$query = "SELECT ID, completename as name FROM `$table` $where ORDER BY completename"; |
290 |
} |
291 |
else {
|
292 |
$query = "SELECT ID, name FROM `$table` $where AND ID<>'$value' ORDER BY name"; |
293 |
} |
294 |
$result = $DB->query($query); |
295 |
|
296 |
|
297 |
echo "<select name=\"$myname\" size='1'>"; |
298 |
if ($table=="glpi_entities"){ |
299 |
echo "<option value=\"0\">".$LANG["entity"][2]."</option>"; |
300 |
} |
301 |
|
302 |
if ($DB->numrows($result) > 0) { |
303 |
while ($data=$DB->fetch_array($result)) { |
304 |
echo "<option value=\"".$data['ID']."\">".$data['name']."</option>"; |
305 |
} |
306 |
} |
307 |
echo "</select>"; |
308 |
} |
309 |
|
310 |
/**
|
311 |
* Execute the query to select box with all glpi users where select key = name
|
312 |
*
|
313 |
* Internaly used by dropdownUsersSelect and ajax/dropdownUsers.php
|
314 |
*
|
315 |
* @param $count true if execute an count(*),
|
316 |
* @param $right limit user who have specific right
|
317 |
* @param $entity_restrict Restrict to a defined entity
|
318 |
* @param $value default value
|
319 |
* @param $used array of user ID
|
320 |
* @param $search pattern
|
321 |
*
|
322 |
* @return mysql result set.
|
323 |
*
|
324 |
*/
|
325 |
function dropdownUsersSelect ($count=true, $right="all", $entity_restrict=-1, $value=0, $used=array(), $search='') { |
326 |
|
327 |
global $DB, $CFG_GLPI; |
328 |
|
329 |
if ($entity_restrict<0) { |
330 |
$entity_restrict = $_SESSION["glpiactive_entity"]; |
331 |
} |
332 |
|
333 |
$joinprofile=false; |
334 |
switch ($right){ |
335 |
case "interface" : |
336 |
$where=" glpi_profiles.interface='central' "; |
337 |
$joinprofile=true; |
338 |
$where.=getEntitiesRestrictRequest("AND","glpi_users_profiles",'',$entity_restrict,1); |
339 |
break;
|
340 |
case "ID" : |
341 |
$where=" glpi_users.ID='".$_SESSION["glpiID"]."' "; |
342 |
break;
|
343 |
case "all" : |
344 |
$where=" glpi_users.ID > '1' "; |
345 |
$where.=getEntitiesRestrictRequest("AND","glpi_users_profiles",'',$entity_restrict,1); |
346 |
break;
|
347 |
default :
|
348 |
$joinprofile=true; |
349 |
$where=" ( glpi_profiles.".$right."='1' AND glpi_profiles.interface='central' "; |
350 |
$where.=getEntitiesRestrictRequest("AND","glpi_users_profiles",'',$entity_restrict,1); |
351 |
$where.=" ) "; |
352 |
|
353 |
break;
|
354 |
} |
355 |
|
356 |
$where .= " AND glpi_users.deleted='0' AND glpi_users.active='1' "; |
357 |
|
358 |
if ($value || count($used)) { |
359 |
$where .= " AND glpi_users.ID NOT IN ("; |
360 |
if ($value) { |
361 |
$first=false; |
362 |
$where .= $value; |
363 |
} |
364 |
else {
|
365 |
$first=true; |
366 |
} |
367 |
foreach($used as $val) { |
368 |
if ($first) { |
369 |
$first = false; |
370 |
} else {
|
371 |
$where .= ","; |
372 |
} |
373 |
$where .= $val; |
374 |
} |
375 |
$where .= ")"; |
376 |
} |
377 |
|
378 |
if ($count) { |
379 |
$query = "SELECT COUNT( DISTINCT glpi_users.ID ) AS CPT FROM glpi_users "; |
380 |
} else {
|
381 |
$query = "SELECT DISTINCT glpi_users.* FROM glpi_users "; |
382 |
} |
383 |
$query.=" LEFT JOIN glpi_users_profiles ON (glpi_users.ID = glpi_users_profiles.FK_users)"; |
384 |
if ($joinprofile){ |
385 |
$query .= " LEFT JOIN glpi_profiles ON (glpi_profiles.ID= glpi_users_profiles.FK_profiles) "; |
386 |
} |
387 |
|
388 |
if ($count) { |
389 |
$query.= " WHERE $where "; |
390 |
} else {
|
391 |
if (strlen($search)>0 && $search!=$CFG_GLPI["ajax_wildcard"]){ |
392 |
$where.=" AND (glpi_users.name ".makeTextSearch($search)." OR glpi_users.realname ".makeTextSearch($search). |
393 |
" OR glpi_users.firstname ".makeTextSearch($search)." OR CONCAT(glpi_users.realname,' ',glpi_users.firstname) ".makeTextSearch($search).")"; |
394 |
} |
395 |
$query .= " WHERE $where ORDER BY glpi_users.realname,glpi_users.firstname, glpi_users.name "; |
396 |
if ($search != $CFG_GLPI["ajax_wildcard"]) { |
397 |
$query .= " LIMIT 0,".$CFG_GLPI["dropdown_max"]; |
398 |
} |
399 |
} |
400 |
|
401 |
return $DB->query($query); |
402 |
} |
403 |
|
404 |
/**
|
405 |
* Make a select box with all glpi users where select key = name
|
406 |
*
|
407 |
*
|
408 |
*
|
409 |
* @param $myname select name
|
410 |
* @param $value default value
|
411 |
* @param $right limit user who have specific right : interface -> central ; ID -> only current user ; all -> all users ; sinon specific right like show_all_ticket, create_ticket....
|
412 |
* @param $all Nobody or All display for none selected $all =0 -> Nobody $all=1 -> All $all=-1-> nothing
|
413 |
* @param $display_comments display comments near the dropdown
|
414 |
* @param $entity_restrict Restrict to a defined entity
|
415 |
* @param $helpdesk_ajax use ajax for helpdesk auto update (mail device_type)
|
416 |
* @param $used array of user ID
|
417 |
*
|
418 |
* @return nothing (print out an HTML select box)
|
419 |
*
|
420 |
*/
|
421 |
function dropdownUsers($myname,$value,$right,$all=0,$display_comments=1,$entity_restrict=-1,$helpdesk_ajax=0,$used=array()) { |
422 |
// Make a select box with all glpi users
|
423 |
|
424 |
global $DB,$CFG_GLPI,$LANG; |
425 |
|
426 |
$rand=mt_rand();
|
427 |
|
428 |
$use_ajax=false; |
429 |
if ($CFG_GLPI["use_ajax"]){ |
430 |
$res=dropdownUsersSelect (true, $right, $entity_restrict, $value, $used); |
431 |
$nb=($res ? $DB->result($res,0,"CPT") : 0); |
432 |
if ($nb > $CFG_GLPI["ajax_limit_count"]) { |
433 |
$use_ajax=true; |
434 |
} |
435 |
} |
436 |
$user=getUserName($value,2); |
437 |
$default_display=""; |
438 |
|
439 |
$default_display="<select id='dropdown_".$myname.$rand."' name='$myname'><option value='$value'>".substr($user["name"],0,$CFG_GLPI["dropdown_limit"])."</option></select>\n"; |
440 |
|
441 |
$view_users=(haveRight("user","r")); |
442 |
|
443 |
$params=array('searchText'=>'__VALUE__', |
444 |
'value'=>$value, |
445 |
'myname'=>$myname, |
446 |
'all'=>$all, |
447 |
'right'=>$right, |
448 |
'comments'=>$display_comments, |
449 |
'rand'=>$rand, |
450 |
'helpdesk_ajax'=>$helpdesk_ajax, |
451 |
'entity_restrict'=>$entity_restrict, |
452 |
'used'=>$used |
453 |
); |
454 |
if ($view_users){ |
455 |
$params['update_link']=$view_users; |
456 |
} |
457 |
|
458 |
$default=""; |
459 |
if (!empty($value)&&$value>0){ |
460 |
$default=$default_display; |
461 |
} else {
|
462 |
if ($all){ |
463 |
$default="<select name='$myname' id='dropdown_".$myname.$rand."'><option value='0'>[ ".$LANG["common"][66]." ]</option></select>\n"; |
464 |
} else {
|
465 |
$default="<select name='$myname' id='dropdown_".$myname.$rand."'><option value='0'>[ Nobody ]</option></select>\n"; |
466 |
} |
467 |
} |
468 |
|
469 |
ajaxDropdown($use_ajax,"/ajax/dropdownUsers.php",$params,$default,$rand); |
470 |
|
471 |
// Display comments
|
472 |
|
473 |
if ($display_comments) { |
474 |
if ($view_users){ |
475 |
if (empty($user["link"])){ |
476 |
$user["link"]=$CFG_GLPI['root_doc']."/front/user.php"; |
477 |
} |
478 |
echo "<a id='comments_link_$myname$rand' href='".$user["link"]."'>"; |
479 |
} |
480 |
echo "<img alt='' src='".$CFG_GLPI["root_doc"]."/pics/aide.png' onmouseout=\"cleanhide('comments_$myname$rand')\" onmouseover=\"cleandisplay('comments_$myname$rand')\">"; |
481 |
if ($view_users){ |
482 |
echo "</a>"; |
483 |
} |
484 |
echo "<span class='over_link' id='comments_$myname$rand'>".$user["comments"]."</span>"; |
485 |
} |
486 |
|
487 |
return $rand; |
488 |
} |
489 |
|
490 |
|
491 |
/**
|
492 |
* Make a select box with all glpi users
|
493 |
*
|
494 |
*
|
495 |
* @param $myname select name
|
496 |
* @param $value default value
|
497 |
* @param $display_comments display comments near the dropdown
|
498 |
* @param $entity_restrict Restrict to a defined entity
|
499 |
* @param $helpdesk_ajax use ajax for helpdesk auto update (mail device_type)
|
500 |
* @param $used array of user ID
|
501 |
*
|
502 |
* @return nothing (print out an HTML select box)
|
503 |
*
|
504 |
*/
|
505 |
function dropdownAllUsers($myname,$value=0,$display_comments=1,$entity_restrict=-1,$helpdesk_ajax=0,$used=array()) { |
506 |
return dropdownUsers($myname,$value,"all",0,$display_comments,$entity_restrict,$helpdesk_ajax,$used); |
507 |
} |
508 |
|
509 |
|
510 |
/**
|
511 |
* Make a select box with all glpi users where select key = ID
|
512 |
*
|
513 |
*
|
514 |
*
|
515 |
* @param $myname select name
|
516 |
* @param $value default value
|
517 |
* @param $right limit user who have specific right : interface -> central ; ID -> only current user ; all -> all users ; sinon specific right like show_all_ticket, create_ticket....
|
518 |
* @param $entity_restrict Restrict to a defined entity
|
519 |
* @param $display_comments display comments near the dropdown
|
520 |
* @return nothing (print out an HTML select box)
|
521 |
*/
|
522 |
function dropdownUsersID($myname,$value,$right,$display_comments=1,$entity_restrict=-1) { |
523 |
// Make a select box with all glpi users
|
524 |
|
525 |
return dropdownUsers($myname,$value,$right,0,$display_comments,$entity_restrict); |
526 |
} |
527 |
|
528 |
/**
|
529 |
* Get the value of a dropdown
|
530 |
*
|
531 |
*
|
532 |
* Returns the value of the dropdown from $table with ID $id.
|
533 |
*
|
534 |
* @param $table the dropdown table from witch we want values on the select
|
535 |
* @param $id id of the element to get
|
536 |
* @param $withcomments give array with name and comments
|
537 |
* @return string the value of the dropdown or if not exists
|
538 |
*/
|
539 |
function getDropdownName($table,$id,$withcomments=0) { |
540 |
global $DB,$CFG_GLPI,$LANG; |
541 |
|
542 |
if (in_array($table,$CFG_GLPI["dropdowntree_tables"])){ |
543 |
return getTreeValueCompleteName($table,$id,$withcomments); |
544 |
|
545 |
} else {
|
546 |
|
547 |
$name = ""; |
548 |
$comments = ""; |
549 |
if ($id){ |
550 |
$query = "SELECT * FROM `". $table ."` WHERE ID = '". $id ."'"; |
551 |
if ($result = $DB->query($query)){ |
552 |
if($DB->numrows($result) != 0) { |
553 |
$data=$DB->fetch_assoc($result); |
554 |
$name = $data["name"]; |
555 |
if (isset($data["comments"])){ |
556 |
$comments = $data["comments"]; |
557 |
} |
558 |
switch ($table){ |
559 |
case "glpi_contacts" : |
560 |
$name .= " ".$data["firstname"]; |
561 |
if (!empty($data["phone"])){ |
562 |
$comments.="<br><strong>".$LANG["help"][35].":</strong> ".$data["phone"]; |
563 |
} |
564 |
if (!empty($data["phone2"])){ |
565 |
$comments.="<br><strong>".$LANG["help"][35]." 2:</strong> ".$data["phone2"]; |
566 |
} |
567 |
if (!empty($data["mobile"])){ |
568 |
$comments.="<br><strong>".$LANG["common"][42].":</strong> ".$data["mobile"]; |
569 |
} |
570 |
if (!empty($data["fax"])){ |
571 |
$comments.="<br><strong>".$LANG["financial"][30].":</strong> ".$data["fax"]; |
572 |
} |
573 |
if (!empty($data["email"])){ |
574 |
$comments.="<br><strong>".$LANG["setup"][14].":</strong> ".$data["email"]; |
575 |
} |
576 |
break;
|
577 |
case "glpi_enterprises" : |
578 |
if (!empty($data["phone"])){ |
579 |
$comments.="<br><strong>".$LANG["help"][35].":</strong> ".$data["phone"]; |
580 |
} |
581 |
if (!empty($data["fax"])){ |
582 |
$comments.="<br><strong>".$LANG["financial"][30].":</strong> ".$data["fax"]; |
583 |
} |
584 |
if (!empty($data["email"])){ |
585 |
$comments.="<br><strong>".$LANG["setup"][14].":</strong> ".$data["email"]; |
586 |
} |
587 |
break;
|
588 |
|
589 |
case "glpi_dropdown_netpoint": |
590 |
$name .= " (".getDropdownName("glpi_dropdown_locations",$data["location"]).")"; |
591 |
break;
|
592 |
case "glpi_software": |
593 |
if ($data["platform"]!=0 && $data["helpdesk_visible"] != 0) |
594 |
$comments.="<br>".$LANG["software"][3].": ".getDropdownName("glpi_dropdown_os",$data["platform"]); |
595 |
break;
|
596 |
} |
597 |
|
598 |
} |
599 |
} |
600 |
} |
601 |
} |
602 |
if (empty($name)) $name=" "; |
603 |
if ($withcomments) return array("name"=>$name,"comments"=>$comments); |
604 |
else return $name; |
605 |
} |
606 |
|
607 |
/**
|
608 |
* Get values of a dropdown for a list of item
|
609 |
*
|
610 |
* @param $table the dropdown table from witch we want values on the select
|
611 |
* @param $ids array containing the ids to get
|
612 |
* @return array containing the value of the dropdown or if not exists
|
613 |
*/
|
614 |
function getDropdownArrayNames($table,$ids) { |
615 |
global $DB,$CFG_GLPI; |
616 |
$tabs=array(); |
617 |
|
618 |
if (count($ids)){ |
619 |
$field='name'; |
620 |
if (in_array($table,$CFG_GLPI["dropdowntree_tables"])){ |
621 |
$field='completename'; |
622 |
} |
623 |
|
624 |
$query="SELECT ID, $field FROM `$table` WHERE ID IN ("; |
625 |
$first=true; |
626 |
foreach ($ids as $val){ |
627 |
if (!$first) $query.=","; |
628 |
else $first=false; |
629 |
$query.="'".$val."'"; |
630 |
} |
631 |
$query.=")"; |
632 |
|
633 |
if ($result=$DB->query($query)){ |
634 |
while ($data=$DB->fetch_assoc($result)){ |
635 |
$tabs[$data['ID']]=$data[$field]; |
636 |
} |
637 |
} |
638 |
} |
639 |
return $tabs; |
640 |
} |
641 |
|
642 |
|
643 |
|
644 |
/**
|
645 |
* Make a select box with all glpi users in tracking table
|
646 |
*
|
647 |
*
|
648 |
*
|
649 |
* @param $myname the name of the HTML select
|
650 |
* @param $value the preselected value we want
|
651 |
* @param $field field of the glpi_tracking table to lookiup for possible users
|
652 |
* @param $display_comments display the comments near the dropdown
|
653 |
* @return nothing (print out an HTML select box)
|
654 |
*/
|
655 |
function dropdownUsersTracking($myname,$value,$field,$display_comments=1) { |
656 |
global $CFG_GLPI,$LANG,$DB; |
657 |
|
658 |
$rand=mt_rand();
|
659 |
|
660 |
$use_ajax=false; |
661 |
if ($CFG_GLPI["use_ajax"]){ |
662 |
if ($CFG_GLPI["ajax_limit_count"]==0){ |
663 |
$use_ajax=true; |
664 |
} else {
|
665 |
$query="SELECT COUNT(`".$field."`) FROM glpi_tracking ".getEntitiesRestrictRequest("WHERE","glpi_tracking"); |
666 |
$result=$DB->query($query); |
667 |
$nb=$DB->result($result,0,0); |
668 |
if ($nb>$CFG_GLPI["ajax_limit_count"]){ |
669 |
$use_ajax=true; |
670 |
} |
671 |
} |
672 |
} |
673 |
|
674 |
$default=""; |
675 |
$user=getUserName($value,2); |
676 |
$default="<select name='$myname'><option value='$value'>".substr($user["name"],0,$CFG_GLPI["dropdown_limit"])."</option></select>\n"; |
677 |
if (empty($value)||$value==0){ |
678 |
$default= "<select name='$myname'><option value='0'>[ ".$LANG["common"][66]." ]</option></select>\n"; |
679 |
} |
680 |
|
681 |
$params=array('searchText'=>'__VALUE__', |
682 |
'value'=>$value, |
683 |
'field'=>$field, |
684 |
'myname'=>$myname, |
685 |
'comments'=>$display_comments, |
686 |
'rand'=>$rand |
687 |
); |
688 |
|
689 |
ajaxDropdown($use_ajax,"/ajax/dropdownUsersTracking.php",$params,$default,$rand); |
690 |
|
691 |
// Display comments
|
692 |
|
693 |
if ($display_comments) { |
694 |
echo "<a href='".$user["link"]."'>"; |
695 |
echo "<img alt='' src='".$CFG_GLPI["root_doc"]."/pics/aide.png' onmouseout=\"cleanhide('comments_$myname$rand')\" onmouseover=\"cleandisplay('comments_$myname$rand')\">"; |
696 |
echo "</a>"; |
697 |
echo "<span class='over_link' id='comments_$myname$rand'>".$user["comments"]."</span>"; |
698 |
} |
699 |
|
700 |
return $rand; |
701 |
} |
702 |
|
703 |
/**
|
704 |
*
|
705 |
* Make a select box for icons
|
706 |
*
|
707 |
*
|
708 |
* @param $value the preselected value we want
|
709 |
* @param $myname the name of the HTML select
|
710 |
* @param $store_path path where icons are stored
|
711 |
* @return nothing (print out an HTML select box)
|
712 |
*/
|
713 |
function dropdownIcons($myname,$value,$store_path){ |
714 |
global $LANG; |
715 |
if (is_dir($store_path)){ |
716 |
if ($dh = opendir($store_path)) { |
717 |
$files=array(); |
718 |
while (($file = readdir($dh)) !== false) { |
719 |
$files[]=$file; |
720 |
} |
721 |
closedir($dh); |
722 |
sort($files); |
723 |
echo "<select name=\"$myname\">"; |
724 |
echo "<option value=''>-----</option>"; |
725 |
foreach ($files as $file){ |
726 |
if (eregi(".png$",$file)){ |
727 |
if ($file == $value) { |
728 |
echo "<option value=\"$file\" selected>".$file; |
729 |
} else {
|
730 |
echo "<option value=\"$file\">".$file; |
731 |
} |
732 |
echo "</option>"; |
733 |
} |
734 |
} |
735 |
echo "</select>"; |
736 |
} else echo "Error reading directory $store_path"; |
737 |
} else echo "Error $store_path is not a directory"; |
738 |
} |
739 |
|
740 |
|
741 |
/**
|
742 |
*
|
743 |
* Make a select box for device type
|
744 |
*
|
745 |
*
|
746 |
* @param $name name of the select box
|
747 |
* @param $value default device type
|
748 |
* @param $types types to display
|
749 |
* @return nothing (print out an HTML select box)
|
750 |
*/
|
751 |
function dropdownDeviceTypes($name,$value=0,$types=array()){ |
752 |
global $CFG_GLPI; |
753 |
|
754 |
|
755 |
$options=array(0=>'----'); |
756 |
if (count($types)){ |
757 |
$ci=new CommonItem(); |
758 |
|
759 |
foreach ($types as $type){ |
760 |
$ci->setType($type); |
761 |
$options[$type]=$ci->getType(); |
762 |
} |
763 |
asort($options); |
764 |
} |
765 |
|
766 |
dropdownArrayValues($name,$options,$value); |
767 |
|
768 |
} |
769 |
|
770 |
|
771 |
|
772 |
/**
|
773 |
*
|
774 |
*Make a select box for all items
|
775 |
*
|
776 |
*
|
777 |
* @param $myname select name
|
778 |
* @param $value default value
|
779 |
* @param $value_type default value for the device type
|
780 |
* @param $entity_restrict Restrict to a defined entity
|
781 |
* @param $types Types used
|
782 |
* @param $onlyglobal Restrict to global items
|
783 |
* @return nothing (print out an HTML select box)
|
784 |
*/
|
785 |
function dropdownAllItems($myname,$value_type=0,$value=0,$entity_restrict=-1,$types='',$onlyglobal=false) { |
786 |
global $LANG,$CFG_GLPI; |
787 |
if (!is_array($types)){ |
788 |
$types=$CFG_GLPI["state_types"]; |
789 |
} |
790 |
$rand=mt_rand();
|
791 |
$ci=new CommonItem(); |
792 |
$options=array(); |
793 |
|
794 |
foreach ($types as $type){ |
795 |
$ci->setType($type); |
796 |
$options[$type]=$ci->getType(); |
797 |
} |
798 |
asort($options); |
799 |
if (count($options)){ |
800 |
echo "<select name='type' id='item_type$rand'>\n"; |
801 |
echo "<option value='0'>-----</option>\n"; |
802 |
foreach ($options as $key => $val){ |
803 |
echo "<option value='".$key."'>".$val."</option>\n"; |
804 |
} |
805 |
echo "</select>"; |
806 |
|
807 |
$params=array('idtable'=>'__VALUE__', |
808 |
'value'=>$value, |
809 |
'myname'=>$myname, |
810 |
'entity_restrict'=>$entity_restrict, |
811 |
); |
812 |
if ($onlyglobal){ |
813 |
$params['onlyglobal']=1; |
814 |
} |
815 |
ajaxUpdateItemOnSelectEvent("item_type$rand","show_$myname$rand",$CFG_GLPI["root_doc"]."/ajax/dropdownAllItems.php",$params); |
816 |
|
817 |
echo "<br><span id='show_$myname$rand'> </span>\n"; |
818 |
|
819 |
if ($value>0){ |
820 |
echo "<script type='text/javascript' >\n"; |
821 |
echo "window.document.getElementById('item_type$rand').value='".$value_type."';"; |
822 |
echo "</script>\n"; |
823 |
|
824 |
$params["idtable"]=$value_type; |
825 |
ajaxUpdateItem("show_$myname$rand",$CFG_GLPI["root_doc"]."/ajax/dropdownAllItems.php",$params); |
826 |
|
827 |
} |
828 |
} |
829 |
return $rand; |
830 |
} |
831 |
|
832 |
|
833 |
/**
|
834 |
* Make a select box for a boolean choice (Yes/No)
|
835 |
*
|
836 |
* @param $name select name
|
837 |
* @param $value preselected value.
|
838 |
* @return nothing (print out an HTML select box)
|
839 |
*/
|
840 |
function dropdownYesNo($name,$value=0){ |
841 |
global $LANG; |
842 |
echo "<select name='$name' id='dropdownyesno_$name'>\n"; |
843 |
echo "<option value='0' ".(!$value?" selected ":"").">".$LANG["choice"][0]."</option>\n"; |
844 |
echo "<option value='1' ".($value?" selected ":"").">".$LANG["choice"][1]."</option>\n"; |
845 |
echo "</select>\n"; |
846 |
} |
847 |
|
848 |
/**
|
849 |
* Get Yes No string
|
850 |
*
|
851 |
* @param $value Yes No value
|
852 |
* @return string
|
853 |
*/
|
854 |
function getYesNo($value){ |
855 |
global $LANG; |
856 |
if ($value){ |
857 |
return $LANG["choice"][1]; |
858 |
} else {
|
859 |
return $LANG["choice"][0]; |
860 |
} |
861 |
} |
862 |
/**
|
863 |
* Make a select box for a None Read Write choice
|
864 |
*
|
865 |
*
|
866 |
*
|
867 |
* @param $name select name
|
868 |
* @param $value preselected value.
|
869 |
* @param $none display none choice ?
|
870 |
* @param $read display read choice ?
|
871 |
* @param $write display write choice ?
|
872 |
* @return nothing (print out an HTML select box)
|
873 |
*/
|
874 |
function dropdownNoneReadWrite($name,$value,$none=1,$read=1,$write=1){ |
875 |
global $LANG; |
876 |
echo "<select name='$name'>\n"; |
877 |
if ($none) |
878 |
echo "<option value='' ".(empty($value)?" selected ":"").">".$LANG["profiles"][12]."</option>\n"; |
879 |
if ($read) |
880 |
echo "<option value='r' ".($value=='r'?" selected ":"").">".$LANG["profiles"][10]."</option>\n"; |
881 |
if ($write) |
882 |
echo "<option value='w' ".($value=='w'?" selected ":"").">".$LANG["profiles"][11]."</option>\n"; |
883 |
echo "</select>\n"; |
884 |
} |
885 |
|
886 |
/**
|
887 |
* Make a select box for Tracking my devices
|
888 |
*
|
889 |
*
|
890 |
* @param $userID User ID for my device section
|
891 |
* @param $entity_restrict restrict to a specific entity
|
892 |
* @return nothing (print out an HTML select box)
|
893 |
*/
|
894 |
function dropdownMyDevices($userID=0,$entity_restrict=-1){ |
895 |
global $DB,$LANG,$CFG_GLPI,$LINK_ID_TABLE; |
896 |
|
897 |
if ($userID==0) $userID=$_SESSION["glpiID"]; |
898 |
|
899 |
$rand=mt_rand();
|
900 |
|
901 |
$already_add=array(); |
902 |
|
903 |
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]&pow(2,HELPDESK_MY_HARDWARE)){ |
904 |
$my_devices=""; |
905 |
|
906 |
$ci=new CommonItem(); |
907 |
$my_item=""; |
908 |
|
909 |
if (isset($_SESSION["helpdeskSaved"]["_my_items"])) $my_item=$_SESSION["helpdeskSaved"]["_my_items"]; |
910 |
|
911 |
// My items
|
912 |
foreach ($CFG_GLPI["linkuser_types"] as $type){ |
913 |
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,$type)){ |
914 |
$query="SELECT * FROM ".$LINK_ID_TABLE[$type]." WHERE FK_users='".$userID."' AND deleted='0' "; |
915 |
if (in_array($LINK_ID_TABLE[$type],$CFG_GLPI["template_tables"])){ |
916 |
$query.=" AND is_template='0' "; |
917 |
} |
918 |
$query.=getEntitiesRestrictRequest("AND",$LINK_ID_TABLE[$type],"",$entity_restrict); |
919 |
$query.=" ORDER BY name "; |
920 |
|
921 |
$result=$DB->query($query); |
922 |
if ($DB->numrows($result)>0){ |
923 |
$ci->setType($type); |
924 |
$type_name=$ci->getType(); |
925 |
|
926 |
while ($data=$DB->fetch_array($result)){ |
927 |
$output=$data["name"]; |
928 |
if ($type!=SOFTWARE_TYPE){ |
929 |
$output.=" - ".$data['serial']." - ".$data['otherserial']; |
930 |
} |
931 |
if (empty($output)||$CFG_GLPI["view_ID"]) $output.=" (".$data['ID'].")"; |
932 |
$my_devices.="<option title=\"$output\" value='".$type."_".$data["ID"]."' ".($my_item==$type."_".$data["ID"]?"selected":"").">"; |
933 |
$my_devices.="$type_name - ".substr($output,0,$CFG_GLPI["dropdown_limit"]); |
934 |
$my_devices.="</option>"; |
935 |
|
936 |
$already_add[$type][]=$data["ID"]; |
937 |
} |
938 |
} |
939 |
} |
940 |
} |
941 |
if (!empty($my_devices)){ |
942 |
$my_devices="<optgroup label=\"".$LANG["tracking"][1]."\">".$my_devices."</optgroup>"; |
943 |
} |
944 |
|
945 |
|
946 |
// My group items
|
947 |
if (haveRight("show_group_hardware","1")){ |
948 |
$group_where=""; |
949 |
$groups=array(); |
950 |
$query="SELECT glpi_users_groups.FK_groups, glpi_groups.name FROM glpi_users_groups LEFT JOIN glpi_groups ON (glpi_groups.ID = glpi_users_groups.FK_groups) WHERE glpi_users_groups.FK_users='".$userID."' "; |
951 |
$query.=getEntitiesRestrictRequest("AND","glpi_groups","",$entity_restrict); |
952 |
$result=$DB->query($query); |
953 |
$first=true; |
954 |
if ($DB->numrows($result)>0){ |
955 |
while ($data=$DB->fetch_array($result)){ |
956 |
if ($first) $first=false; |
957 |
else $group_where.=" OR "; |
958 |
|
959 |
$group_where.=" FK_groups = '".$data["FK_groups"]."' "; |
960 |
} |
961 |
|
962 |
$tmp_device=""; |
963 |
foreach ($CFG_GLPI["linkuser_types"] as $type){ |
964 |
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,$type)) |
965 |
{ |
966 |
$query="SELECT * FROM ".$LINK_ID_TABLE[$type]." WHERE ($group_where) AND deleted='0' "; |
967 |
$query.=getEntitiesRestrictRequest("AND",$LINK_ID_TABLE[$type],"",$entity_restrict); |
968 |
$result=$DB->query($query); |
969 |
if ($DB->numrows($result)>0){ |
970 |
$ci->setType($type); |
971 |
$type_name=$ci->getType(); |
972 |
if (!isset($already_add[$type])) $already_add[$type]=array(); |
973 |
while ($data=$DB->fetch_array($result)){ |
974 |
if (!in_array($data["ID"],$already_add[$type])){ |
975 |
$output=$data["name"]; |
976 |
if ($type!=SOFTWARE_TYPE){ |
977 |
$output.=" - ".$data['serial']." - ".$data['otherserial']; |
978 |
} |
979 |
|
980 |
if (empty($output)||$CFG_GLPI["view_ID"]) $output.=" (".$data['ID'].")"; |
981 |
$tmp_device.="<option title=\"$output\" value='".$type."_".$data["ID"]."' ".($my_item==$type."_".$data["ID"]?"selected":"").">"; |
982 |
$tmp_device.="$type_name - ".substr($output,0,$CFG_GLPI["dropdown_limit"]); |
983 |
$tmp_device.="</option>"; |
984 |
$already_add[$type][]=$data["ID"]; |
985 |
} |
986 |
} |
987 |
} |
988 |
} |
989 |
} |
990 |
if (!empty($tmp_device)){ |
991 |
$my_devices.="<optgroup label=\"".$LANG["tracking"][1]." - ".$LANG["common"][35]."\">".$tmp_device."</optgroup>"; |
992 |
} |
993 |
} |
994 |
} |
995 |
|
996 |
// Get linked items to computers
|
997 |
if (isset($already_add[COMPUTER_TYPE])&&count($already_add[COMPUTER_TYPE])){ |
998 |
$search_computer=" ("; |
999 |
$first=true; |
1000 |
foreach ($already_add[COMPUTER_TYPE] as $ID){ |
1001 |
if ($first) $first=false; |
1002 |
else $search_computer.= " OR "; |
1003 |
$search_computer.= " XXXX='$ID' "; |
1004 |
} |
1005 |
$search_computer.=" )"; |
1006 |
|
1007 |
$tmp_device=""; |
1008 |
// Direct Connection
|
1009 |
$types=array(PERIPHERAL_TYPE,MONITOR_TYPE,PRINTER_TYPE,PHONE_TYPE); |
1010 |
foreach ($types as $type){ |
1011 |
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,$type)){ |
1012 |
if (!isset($already_add[$type])) $already_add[$type]=array(); |
1013 |
$query="SELECT DISTINCT ".$LINK_ID_TABLE[$type].".* FROM glpi_connect_wire LEFT JOIN ".$LINK_ID_TABLE[$type]." ON (glpi_connect_wire.end1=".$LINK_ID_TABLE[$type].".ID) WHERE glpi_connect_wire.type='$type' AND ".ereg_replace("XXXX","glpi_connect_wire.end2",$search_computer)." AND ".$LINK_ID_TABLE[$type].".deleted='0' "; |
1014 |
if (in_array($LINK_ID_TABLE[$type],$CFG_GLPI["template_tables"])){ |
1015 |
$query.=" AND is_template='0' "; |
1016 |
} |
1017 |
$query.=getEntitiesRestrictRequest("AND",$LINK_ID_TABLE[$type],"",$entity_restrict); |
1018 |
$query.=" ORDER BY ".$LINK_ID_TABLE[$type].".name"; |
1019 |
|
1020 |
$result=$DB->query($query); |
1021 |
if ($DB->numrows($result)>0){ |
1022 |
$ci->setType($type); |
1023 |
$type_name=$ci->getType(); |
1024 |
while ($data=$DB->fetch_array($result)){ |
1025 |
if (!in_array($data["ID"],$already_add[$type])){ |
1026 |
$output=$data["name"]; |
1027 |
if ($type!=SOFTWARE_TYPE){ |
1028 |
$output.=" - ".$data['serial']." - ".$data['otherserial']; |
1029 |
} |
1030 |
if (empty($output)||$CFG_GLPI["view_ID"]) $output.=" (".$data['ID'].")"; |
1031 |
$tmp_device.="<option title=\"$output\" value='".$type."_".$data["ID"]."' ".($my_item==$type."_".$data["ID"]?"selected":"").">"; |
1032 |
$tmp_device.="$type_name - ".substr($output,0,$CFG_GLPI["dropdown_limit"]); |
1033 |
$tmp_device.="</option>"; |
1034 |
|
1035 |
$already_add[$type][]=$data["ID"]; |
1036 |
} |
1037 |
} |
1038 |
} |
1039 |
} |
1040 |
} |
1041 |
if (!empty($tmp_device)){ |
1042 |
$my_devices.="<optgroup label=\"".$LANG["reports"][36]."\">".$tmp_device."</optgroup>"; |
1043 |
} |
1044 |
|
1045 |
// Software
|
1046 |
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,SOFTWARE_TYPE)){ |
1047 |
$query = "SELECT DISTINCT glpi_licenses.version as version, glpi_software.name as name, glpi_software.ID as ID FROM glpi_inst_software, glpi_software,glpi_licenses "; |
1048 |
$query.= "WHERE glpi_inst_software.license = glpi_licenses.ID AND glpi_licenses.sID = glpi_software.ID AND ".ereg_replace("XXXX","glpi_inst_software.cID",$search_computer)." AND glpi_software.helpdesk_visible=1 "; |
1049 |
$query.=getEntitiesRestrictRequest("AND","glpi_software","",$entity_restrict); |
1050 |
$query.=" ORDER BY glpi_software.name"; |
1051 |
|
1052 |
$result=$DB->query($query); |
1053 |
if ($DB->numrows($result)>0){ |
1054 |
$tmp_device=""; |
1055 |
$ci->setType(SOFTWARE_TYPE); |
1056 |
$type_name=$ci->getType(); |
1057 |
if (!isset($already_add[SOFTWARE_TYPE])) $already_add[SOFTWARE_TYPE]=array(); |
1058 |
while ($data=$DB->fetch_array($result)){ |
1059 |
if (!in_array($data["ID"],$already_add[SOFTWARE_TYPE])){ |
1060 |
$tmp_device.="<option value='".SOFTWARE_TYPE."_".$data["ID"]."' ".($my_item==SOFTWARE_TYPE."_".$data["ID"]?"selected":"").">$type_name - ".$data["name"]." (v. ".$data["version"].")".($CFG_GLPI["view_ID"]?" (".$data["ID"].")":"")."</option>"; |
1061 |
$already_add[SOFTWARE_TYPE][]=$data["ID"]; |
1062 |
} |
1063 |
} |
1064 |
if (!empty($tmp_device)){ |
1065 |
$my_devices.="<optgroup label=\"".ucfirst($LANG["software"][17])."\">".$tmp_device."</optgroup>"; |
1066 |
} |
1067 |
} |
1068 |
} |
1069 |
} |
1070 |
echo "<div id='tracking_my_devices'>"; |
1071 |
echo $LANG["tracking"][1].": <select id='my_items' name='_my_items'><option value=''>--- ".$LANG["help"][30]." ---</option>$my_devices</select></div>"; |
1072 |
} |
1073 |
|
1074 |
} |
1075 |
/**
|
1076 |
* Make a select box for Tracking All Devices
|
1077 |
*
|
1078 |
* @param $myname select name
|
1079 |
* @param $value preselected value.
|
1080 |
* @param $admin is an admin access ?
|
1081 |
* @param $entity_restrict Restrict to a defined entity
|
1082 |
* @return nothing (print out an HTML select box)
|
1083 |
*/
|
1084 |
function dropdownTrackingAllDevices($myname,$value,$admin=0,$entity_restrict=-1){ |
1085 |
global $LANG,$CFG_GLPI,$DB,$LINK_ID_TABLE; |
1086 |
|
1087 |
$rand=mt_rand();
|
1088 |
|
1089 |
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]==0){ |
1090 |
echo "<input type='hidden' name='$myname' value='0'>"; |
1091 |
echo "<input type='hidden' name='computer' value='0'>"; |
1092 |
} else {
|
1093 |
echo "<div id='tracking_all_devices'>"; |
1094 |
|
1095 |
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]&pow(2,HELPDESK_ALL_HARDWARE)){ |
1096 |
// Display a message if view my hardware
|
1097 |
if (!$admin&&$_SESSION["glpiactiveprofile"]["helpdesk_hardware"]&pow(2,HELPDESK_MY_HARDWARE)){ |
1098 |
echo $LANG["tracking"][2].":<br>"; |
1099 |
} |
1100 |
echo "<select id='search_$myname$rand' name='$myname'>\n"; |
1101 |
echo "<option value='0' ".(($value==0)?" selected":"").">".$LANG["help"][30]."</option>\n"; |
1102 |
// Also display type if selected
|
1103 |
if ($value==COMPUTER_TYPE||$_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,COMPUTER_TYPE)) |
1104 |
echo "<option value='".COMPUTER_TYPE."' ".(($value==COMPUTER_TYPE)?" selected":"").">".$LANG["help"][25]."</option>\n"; |
1105 |
if ($value==NETWORKING_TYPE||$_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,NETWORKING_TYPE)) |
1106 |
echo "<option value='".NETWORKING_TYPE."' ".(($value==NETWORKING_TYPE)?" selected":"").">".$LANG["help"][26]."</option>\n"; |
1107 |
if ($value==PRINTER_TYPE||$_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,PRINTER_TYPE)) |
1108 |
echo "<option value='".PRINTER_TYPE."' ".(($value==PRINTER_TYPE)?" selected":"").">".$LANG["help"][27]."</option>\n"; |
1109 |
if ($value==MONITOR_TYPE||$_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,MONITOR_TYPE)) |
1110 |
echo "<option value='".MONITOR_TYPE."' ".(($value==MONITOR_TYPE)?" selected":"").">".$LANG["help"][28]."</option>\n"; |
1111 |
if ($value==PERIPHERAL_TYPE||$_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,PERIPHERAL_TYPE)) |
1112 |
echo "<option value='".PERIPHERAL_TYPE."' ".(($value==PERIPHERAL_TYPE)?" selected":"").">".$LANG["help"][29]."</option>\n"; |
1113 |
if ($value==SOFTWARE_TYPE||$_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,SOFTWARE_TYPE)) |
1114 |
echo "<option value='".SOFTWARE_TYPE."' ".(($value==SOFTWARE_TYPE)?" selected":"").">".$LANG["help"][31]."</option>\n"; |
1115 |
if ($value==PHONE_TYPE||$_SESSION["glpiactiveprofile"]["helpdesk_hardware_type"]&pow(2,PHONE_TYPE)) |
1116 |
echo "<option value='".PHONE_TYPE."' ".(($value==PHONE_TYPE)?" selected":"").">".$LANG["help"][35]."</option>\n"; |
1117 |
echo "</select>\n"; |
1118 |
|
1119 |
$params=array('type'=>'__VALUE__', |
1120 |
'entity_restrict'=>$entity_restrict, |
1121 |
'admin'=>$admin, |
1122 |
'myname'=>"computer", |
1123 |
); |
1124 |
|
1125 |
ajaxUpdateItemOnSelectEvent("search_$myname$rand","results_$myname$rand",$CFG_GLPI["root_doc"]."/ajax/dropdownTrackingDeviceType.php",$params); |
1126 |
|
1127 |
echo "<span id='results_$myname$rand'>\n"; |
1128 |
|
1129 |
if (isset($_SESSION["helpdeskSaved"]["computer"])){ |
1130 |
$ci=new CommonItem(); |
1131 |
if ($ci->getFromDB($value,$_SESSION["helpdeskSaved"]["computer"])){ |
1132 |
echo "<select name='computer'>\n"; |
1133 |
echo "<option value='".$_SESSION["helpdeskSaved"]["computer"]."'>".$ci->getName()."</option>\n"; |
1134 |
|
1135 |
echo "</select>\n"; |
1136 |
} |
1137 |
} |
1138 |
|
1139 |
echo "</span>\n"; |
1140 |
} |
1141 |
echo "</div>"; |
1142 |
} |
1143 |
return $rand; |
1144 |
} |
1145 |
|
1146 |
/**
|
1147 |
* Make a select box for connections
|
1148 |
*
|
1149 |
* @param $type type to connect
|
1150 |
* @param $fromtype from where the connection is
|
1151 |
* @param $myname select name
|
1152 |
* @param $onlyglobal display only global devices (used for templates)
|
1153 |
* @param $entity_restrict Restrict to a defined entity
|
1154 |
* @return nothing (print out an HTML select box)
|
1155 |
*/
|
1156 |
function dropdownConnect($type,$fromtype,$myname,$entity_restrict=-1,$onlyglobal=0) { |
1157 |
global $CFG_GLPI,$LINK_ID_TABLE; |
1158 |
|
1159 |
$rand=mt_rand();
|
1160 |
|
1161 |
$use_ajax=false; |
1162 |
if ($CFG_GLPI["use_ajax"]){ |
1163 |
$nb=0; |
1164 |
if ($entity_restrict>=0){ |
1165 |
$nb=countElementsInTableForEntity($LINK_ID_TABLE[$type],$entity_restrict); |
1166 |
} else {
|
1167 |
$nb=countElementsInTableForMyEntities($LINK_ID_TABLE[$type]); |
1168 |
} |
1169 |
if ($nb>$CFG_GLPI["ajax_limit_count"]){ |
1170 |
$use_ajax=true; |
1171 |
} |
1172 |
} |
1173 |
|
1174 |
$params=array('searchText'=>'__VALUE__', |
1175 |
'fromtype'=>$fromtype, |
1176 |
'idtable'=>$type, |
1177 |
'myname'=>$myname, |
1178 |
'onlyglobal'=>$onlyglobal, |
1179 |
'entity_restrict'=>$entity_restrict, |
1180 |
); |
1181 |
|
1182 |
$default="<select name='$myname'><option value='0'>------</option></select>\n"; |
1183 |
ajaxDropdown($use_ajax,"/ajax/dropdownConnect.php",$params,$default,$rand); |
1184 |
|
1185 |
return $rand; |
1186 |
} |
1187 |
|
1188 |
|
1189 |
/**
|
1190 |
* Make a select box for connected port
|
1191 |
*
|
1192 |
* @param $ID ID of the current port to connect
|
1193 |
* @param $type type of device where to search ports
|
1194 |
* @param $myname select name
|
1195 |
* @param $entity_restrict Restrict to a defined entity
|
1196 |
* @return nothing (print out an HTML select box)
|
1197 |
*/
|
1198 |
function dropdownConnectPort($ID,$type,$myname,$entity_restrict=-1) { |
1199 |
global $LANG,$CFG_GLPI; |
1200 |
|
1201 |
$rand=mt_rand();
|
1202 |
echo "<select name='type[$ID]' id='item_type$rand'>\n"; |
1203 |
echo "<option value='0'>-----</option>\n"; |
1204 |
|
1205 |
$ci =new CommonItem(); |
1206 |
|
1207 |
foreach ($CFG_GLPI["netport_types"] as $type){ |
1208 |
$ci->setType($type); |
1209 |
echo "<option value='".$type."'>".$ci->getType()."</option>\n"; |
1210 |
} |
1211 |
|
1212 |
echo "</select>\n"; |
1213 |
|
1214 |
|
1215 |
$params=array('type'=>'__VALUE__', |
1216 |
'entity_restrict'=>$entity_restrict, |
1217 |
'current'=>$ID, |
1218 |
'myname'=>$myname, |
1219 |
); |
1220 |
|
1221 |
ajaxUpdateItemOnSelectEvent("item_type$rand","show_$myname$rand",$CFG_GLPI["root_doc"]."/ajax/dropdownConnectPortDeviceType.php",$params); |
1222 |
|
1223 |
echo "<span id='show_$myname$rand'> </span>\n"; |
1224 |
|
1225 |
return $rand; |
1226 |
} |
1227 |
|
1228 |
/**
|
1229 |
* Make a select box for link document
|
1230 |
*
|
1231 |
* @param $myname name of the select box
|
1232 |
* @param $entity_restrict restrict multi entity
|
1233 |
* @param $used Already used items : not to display in dropdown
|
1234 |
* @return nothing (print out an HTML select box)
|
1235 |
*/
|
1236 |
function dropdownDocument($myname,$entity_restrict='',$used=array()) { |
1237 |
global $DB,$LANG,$CFG_GLPI; |
1238 |
|
1239 |
$rand=mt_rand();
|
1240 |
|
1241 |
$where=" WHERE glpi_docs.deleted='0' "; |
1242 |
$where.=getEntitiesRestrictRequest("AND","glpi_docs",'',$entity_restrict,true); |
1243 |
if (count($used)) { |
1244 |
$where .= " AND ID NOT IN (0"; |
1245 |
foreach ($used as $ID) |
1246 |
$where .= ",'$ID'"; |
1247 |
$where .= ")"; |
1248 |
} |
1249 |
|
1250 |
|
1251 |
$query="SELECT * FROM glpi_dropdown_rubdocs WHERE ID IN (SELECT DISTINCT rubrique FROM glpi_docs $where) ORDER BY name"; |
1252 |
//error_log($query);
|
1253 |
$result=$DB->query($query); |
1254 |
|
1255 |
echo "<select name='_rubdoc' id='rubdoc'>\n"; |
1256 |
echo "<option value='0'>------</option>\n"; |
1257 |
while ($data=$DB->fetch_assoc($result)){ |
1258 |
echo "<option value='".$data['ID']."'>".$data['name']."</option>\n"; |
1259 |
} |
1260 |
echo "</select>\n"; |
1261 |
|
1262 |
$params=array('rubdoc'=>'__VALUE__', |
1263 |
'entity_restrict'=>$entity_restrict, |
1264 |
'rand'=>$rand, |
1265 |
'myname'=>$myname, |
1266 |
'used'=>$used |
1267 |
); |
1268 |
|
1269 |
ajaxUpdateItemOnSelectEvent("rubdoc","show_$myname$rand",$CFG_GLPI["root_doc"]."/ajax/dropdownRubDocument.php",$params); |
1270 |
|
1271 |
echo "<span id='show_$myname$rand'>"; |
1272 |
$_POST["entity_restrict"]=$entity_restrict; |
1273 |
$_POST["rubdoc"]=0; |
1274 |
$_POST["myname"]=$myname; |
1275 |
$_POST["rand"]=$rand; |
1276 |
$_POST["used"]=$used; |
1277 |
include (GLPI_ROOT."/ajax/dropdownRubDocument.php"); |
1278 |
echo "</span>\n"; |
1279 |
|
1280 |
return $rand; |
1281 |
} |
1282 |
|
1283 |
|
1284 |
/**
|
1285 |
* Make a select box for software to install
|
1286 |
*
|
1287 |
*
|
1288 |
* @param $myname select name
|
1289 |
* @param $withtemplate is it a template computer ?
|
1290 |
* @param $massiveaction is it a massiveaction select ?
|
1291 |
* @param $entity_restrict Restrict to a defined entity
|
1292 |
* @return nothing (print out an HTML select box)
|
1293 |
*/
|
1294 |
function dropdownSoftwareToInstall($myname,$withtemplate,$entity_restrict,$massiveaction=0) { |
1295 |
global $CFG_GLPI; |
1296 |
|
1297 |
$rand=mt_rand();
|
1298 |
|
1299 |
$use_ajax=false; |
1300 |
|
1301 |
if ($CFG_GLPI["use_ajax"]){ |
1302 |
if(countElementsInTableForEntity("glpi_software",$entity_restrict)>$CFG_GLPI["ajax_limit_count"]){ |
1303 |
$use_ajax=true; |
1304 |
} |
1305 |
} |
1306 |
|
1307 |
$only_globalfree=0; |
1308 |
if ($massiveaction||(!empty($withtemplate)&&$withtemplate>0)){ |
1309 |
$only_globalfree=1; |
1310 |
} |
1311 |
|
1312 |
$params=array('searchText'=>'__VALUE__', |
1313 |
'only_globalfree'=>$only_globalfree, |
1314 |
'myname'=>$myname, |
1315 |
'entity_restrict'=>$entity_restrict, |
1316 |
); |
1317 |
|
1318 |
$default="<select name='$myname'><option value='0'>------</option></select>\n"; |
1319 |
ajaxDropdown($use_ajax,"/ajax/dropdownSelectSoftware.php",$params,$default,$rand); |
1320 |
|
1321 |
return $rand; |
1322 |
} |
1323 |
|
1324 |
/**
|
1325 |
* Show div with auto completion
|
1326 |
*
|
1327 |
* @param $myname text field name
|
1328 |
* @param $table table to search for autocompletion
|
1329 |
* @param $field field to serahc for autocompletion
|
1330 |
* @param $value value to fill text field
|
1331 |
* @param $size size of the text field
|
1332 |
* @param $option option of the textfield
|
1333 |
* @param $entity_restrict Restrict to a defined entity
|
1334 |
* @return nothing (print out an HTML div)
|
1335 |
*/
|
1336 |
function autocompletionTextField($myname,$table,$field,$value='',$size=20,$entity_restrict=-1,$option=''){ |
1337 |
global $CFG_GLPI; |
1338 |
|
1339 |
if ($CFG_GLPI["use_ajax"]&&$CFG_GLPI["ajax_autocompletion"]){ |
1340 |
$rand=mt_rand();
|
1341 |
echo "<input $option id='textfield_$myname$rand' type='text' name='$myname' value=\"".cleanInputText($value)."\" size='$size'>\n"; |
1342 |
echo "<div id='textfieldupdate_$myname$rand' style='display:none;border:1px solid black;background-color:white;'></div>\n"; |
1343 |
echo "<script type='text/javascript' language='javascript' charset='utf-8'>"; |
1344 |
echo "new Ajax.Autocompleter('textfield_$myname$rand','textfieldupdate_$myname$rand','".$CFG_GLPI["root_doc"]."/ajax/autocompletion.php',{parameters:'table=$table&field=$field&myname=$myname&entity_restrict=".$entity_restrict."'});"; |
1345 |
echo "</script>"; |
1346 |
} else {
|
1347 |
echo "<input $option type='text' name='$myname' value=\"".cleanInputText($value)."\" size='$size'>\n"; |
1348 |
} |
1349 |
} |
1350 |
|
1351 |
|
1352 |
/**
|
1353 |
* Make a select box form for device type
|
1354 |
*
|
1355 |
* @param $target URL to post the form
|
1356 |
* @param $cID computer ID
|
1357 |
* @param $withtemplate is it a template computer ?
|
1358 |
* @return nothing (print out an HTML select box)
|
1359 |
*/
|
1360 |
function device_selecter($target,$cID,$withtemplate='') { |
1361 |
global $LANG,$CFG_GLPI; |
1362 |
|
1363 |
if (!haveRight("computer","w")) return false; |
1364 |
|
1365 |
if(!empty($withtemplate) && $withtemplate == 2) { |
1366 |
//do nothing
|
1367 |
} else {
|
1368 |
echo "<table class='tab_cadre_fixe'>"; |
1369 |
echo "<tr class='tab_bg_1'><td colspan='2' align='right' width='30%'>"; |
1370 |
echo $LANG["devices"][0].":"; |
1371 |
echo "</td>"; |
1372 |
echo "<td colspan='63'>"; |
1373 |
echo "<form action=\"$target\" method=\"post\">"; |
1374 |
|
1375 |
$rand=mt_rand();
|
1376 |
|
1377 |
echo "<select name=\"new_device_type\" id='device$rand'>"; |
1378 |
|
1379 |
echo "<option value=\"-1\">-----</option>"; |
1380 |
$devices=getDictDeviceLabel(-1); |
1381 |
|
1382 |
foreach ($devices as $i => $name){ |
1383 |
echo "<option value=\"$i\">$name</option>"; |
1384 |
} |
1385 |
echo "</select>"; |
1386 |
|
1387 |
$params=array('idtable'=>'__VALUE__', |
1388 |
'myname'=>'new_device_id', |
1389 |
); |
1390 |
|
1391 |
ajaxUpdateItemOnSelectEvent("device$rand","showdevice$rand",$CFG_GLPI["root_doc"]."/ajax/dropdownDevice.php",$params); |
1392 |
|
1393 |
echo "<span id='showdevice$rand'> </span>\n"; |
1394 |
|
1395 |
echo "<input type=\"hidden\" name=\"withtemplate\" value=\"".$withtemplate."\" >"; |
1396 |
echo "<input type=\"hidden\" name=\"connect_device\" value=\"".true."\" >"; |
1397 |
echo "<input type=\"hidden\" name=\"cID\" value=\"".$cID."\" >"; |
1398 |
echo "<input type=\"submit\" class ='submit' value=\"".$LANG["buttons"][2]."\" >"; |
1399 |
echo "</form>"; |
1400 |
echo "</td>"; |
1401 |
echo "</tr></table>"; |
1402 |
} |
1403 |
} |
1404 |
|
1405 |
/**
|
1406 |
* Dropdown of actions for massive action
|
1407 |
*
|
1408 |
* @param $device_type item type
|
1409 |
* @param $deleted massive action for deleted items ?
|
1410 |
*/
|
1411 |
function dropdownMassiveAction($device_type,$deleted=0){ |
1412 |
global $LANG,$CFG_GLPI,$PLUGIN_HOOKS; |
1413 |
|
1414 |
$isadmin=haveTypeRight($device_type,"w"); |
1415 |
|
1416 |
echo "<select name=\"massiveaction\" id='massiveaction'>"; |
1417 |
|
1418 |
echo "<option value=\"-1\" selected>-----</option>"; |
1419 |
if (!in_array($device_type,array(MAILGATE_TYPE,OCSNG_TYPE,ENTITY_TYPE)) |
1420 |
&& ( $isadmin
|
1421 |
||(in_array($device_type,$CFG_GLPI["infocom_types"])&&haveTypeRight(INFOCOM_TYPE,"w")) |
1422 |
|| ($device_type==TRACKING_TYPE&&haveRight('update_ticket',1)) |
1423 |
) |
1424 |
){ |
1425 |
|
1426 |
echo "<option value=\"update\">".$LANG["buttons"][14]."</option>"; |
1427 |
} |
1428 |
|
1429 |
if ($deleted){ |
1430 |
if ($isadmin){ |
1431 |
echo "<option value=\"purge\">".$LANG["buttons"][22]."</option>"; |
1432 |
echo "<option value=\"restore\">".$LANG["buttons"][21]."</option>"; |
1433 |
} |
1434 |
} else {
|
1435 |
// No delete for entities and tracking of not have right
|
1436 |
if ($device_type!=ENTITY_TYPE |
1437 |
&&( ($isadmin && $device_type!=TRACKING_TYPE) |
1438 |
|| ($device_type==TRACKING_TYPE&&haveRight('delete_ticket',1)) |
1439 |
)){ |
1440 |
echo "<option value=\"delete\">".$LANG["buttons"][6]."</option>"; |
1441 |
} |
1442 |
if ($isadmin && in_array($device_type,array(PHONE_TYPE,PRINTER_TYPE,PERIPHERAL_TYPE,MONITOR_TYPE))){ |
1443 |
echo "<option value=\"connect\">".$LANG["buttons"][9]."</option>"; |
1444 |
echo "<option value=\"disconnect\">".$LANG["buttons"][10]."</option>"; |
1445 |
} |
1446 |
if (haveTypeRight(DOCUMENT_TYPE,"w") && in_array($device_type,array(CARTRIDGE_TYPE,COMPUTER_TYPE,CONSUMABLE_TYPE,CONTACT_TYPE,CONTRACT_TYPE,ENTERPRISE_TYPE, |
1447 |
MONITOR_TYPE,NETWORKING_TYPE,PERIPHERAL_TYPE,PHONE_TYPE,PRINTER_TYPE,SOFTWARE_TYPE))){ |
1448 |
echo "<option value=\"add_document\">".$LANG["document"][16]."</option>"; |
1449 |
} |
1450 |
|
1451 |
if (haveTypeRight(CONTRACT_TYPE,"w") &&in_array($device_type,$CFG_GLPI["state_types"])){ |
1452 |
echo "<option value=\"add_contract\">".$LANG["financial"][36]."</option>"; |
1453 |
} |
1454 |
if (haveRight('transfer','r') && isMultiEntitiesMode() && |
1455 |
in_array($device_type, array(CARTRIDGE_TYPE,COMPUTER_TYPE,CONSUMABLE_TYPE,CONTACT_TYPE,CONTRACT_TYPE,ENTERPRISE_TYPE, |
1456 |
MONITOR_TYPE,NETWORKING_TYPE,PERIPHERAL_TYPE,PHONE_TYPE,PRINTER_TYPE,SOFTWARE_TYPE,TRACKING_TYPE,DOCUMENT_TYPE,GROUP_TYPE)) |
1457 |
&& $isadmin
|
1458 |
){ |
1459 |
echo "<option value=\"add_transfer_list\">".$LANG["buttons"][48]."</option>"; |
1460 |
} |
1461 |
switch ($device_type){ |
1462 |
case SOFTWARE_TYPE : |
1463 |
if ($isadmin && countElementsInTable("glpi_rules_descriptions","rule_type='".RULE_SOFTWARE_CATEGORY."'") > 0){ |
1464 |
echo "<option value=\"compute_software_category\">".$LANG["rulesengine"][38]." ".$LANG["rulesengine"][40]."</option>"; |
1465 |
} |
1466 |
if (haveRight("rule_dictionnary_software","w") && countElementsInTable("glpi_rules_descriptions","rule_type='".RULE_DICTIONNARY_SOFTWARE."'") > 0){ |
1467 |
echo "<option value=\"replay_dictionnary\">".$LANG["rulesengine"][76]."</option>"; |
1468 |
} |
1469 |
|
1470 |
break;
|
1471 |
case COMPUTER_TYPE : |
1472 |
if ($isadmin){ |
1473 |
echo "<option value=\"connect_to_computer\">".$LANG["buttons"][9]."</option>"; |
1474 |
echo "<option value=\"install\">".$LANG["buttons"][4]."</option>"; |
1475 |
if ($CFG_GLPI['ocs_mode']){ |
1476 |
if (haveRight("ocsng","w") || haveRight("sync_ocsng","w")){ |
1477 |
echo "<option value=\"force_ocsng_update\">".$LANG["ocsng"][24]."</option>"; |
1478 |
} |
1479 |
echo "<option value=\"unlock_ocsng_field\">".$LANG["buttons"][38]." ".$LANG["Menu"][33]." - ".$LANG["ocsng"][16]."</option>"; |
1480 |
echo "<option value=\"unlock_ocsng_monitor\">".$LANG["buttons"][38]." ".$LANG["Menu"][33]." - ".$LANG["ocsng"][30]."</option>"; |
1481 |
echo "<option value=\"unlock_ocsng_peripheral\">".$LANG["buttons"][38]." ".$LANG["Menu"][33]." - ".$LANG["ocsng"][32]."</option>"; |
1482 |
echo "<option value=\"unlock_ocsng_printer\">".$LANG["buttons"][38]." ".$LANG["Menu"][33]." - ".$LANG["ocsng"][34]."</option>"; |
1483 |
echo "<option value=\"unlock_ocsng_software\">".$LANG["buttons"][38]." ".$LANG["Menu"][33]." - ".$LANG["ocsng"][52]."</option>"; |
1484 |
echo "<option value=\"unlock_ocsng_ip\">".$LANG["buttons"][38]." ".$LANG["Menu"][33]." - ".$LANG["ocsng"][50]."</option>"; |
1485 |
} |
1486 |
} |
1487 |
break;
|
1488 |
case ENTERPRISE_TYPE : |
1489 |
if ($isadmin){ |
1490 |
echo "<option value=\"add_contact\">".$LANG["financial"][24]."</option>"; |
1491 |
} |
1492 |
break;
|
1493 |
case CONTACT_TYPE : |
1494 |
if ($isadmin){ |
1495 |
echo "<option value=\"add_enterprise\">".$LANG["financial"][25]."</option>"; |
1496 |
} |
1497 |
break;
|
1498 |
case USER_TYPE : |
1499 |
if ($isadmin){ |
1500 |
echo "<option value=\"add_group\">".$LANG["setup"][604]."</option>"; |
1501 |
echo "<option value=\"add_userprofile\">".$LANG["setup"][607]."</option>"; |
1502 |
} |
1503 |
|
1504 |
if (haveRight("user","w")){ |
1505 |
echo "<option value=\"force_user_ldap_update\">".$LANG["ocsng"][24]."</option>"; |
1506 |
} |
1507 |
|
1508 |
break;
|
1509 |
case TRACKING_TYPE : |
1510 |
if (haveRight("comment_all_ticket","1")){ |
1511 |
echo "<option value=\"add_followup\">".$LANG["job"][29]."</option>"; |
1512 |
} |
1513 |
break;
|
1514 |
} |
1515 |
|
1516 |
// Plugin Specific actions
|
1517 |
if (isset($PLUGIN_HOOKS['use_massive_action'])){ |
1518 |
foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val){ |
1519 |
$function='plugin_'.$plugin.'_MassiveActions'; |
1520 |
if (function_exists($function)){ |
1521 |
$actions=$function($device_type); |
1522 |
if (count($actions)){ |
1523 |
foreach ($actions as $key => $val){ |
1524 |
echo "<option value=\"$key\">$val</option>"; |
1525 |
} |
1526 |
} |
1527 |
} |
1528 |
} |
1529 |
} |
1530 |
|
1531 |
|
1532 |
} |
1533 |
echo "</select>"; |
1534 |
|
1535 |
$params=array('action'=>'__VALUE__', |
1536 |
'deleted'=>$deleted, |
1537 |
'type'=>$device_type, |
1538 |
); |
1539 |
|
1540 |
ajaxUpdateItemOnSelectEvent("massiveaction","show_massiveaction",$CFG_GLPI["root_doc"]."/ajax/dropdownMassiveAction.php",$params); |
1541 |
|
1542 |
echo "<span id='show_massiveaction'> </span>\n"; |
1543 |
} |
1544 |
|
1545 |
/**
|
1546 |
* Dropdown of actions for massive action of networking ports
|
1547 |
*
|
1548 |
* @param $device_type item type
|
1549 |
*/
|
1550 |
function dropdownMassiveActionPorts($device_type){ |
1551 |
global $LANG,$CFG_GLPI; |
1552 |
|
1553 |
echo "<select name=\"massiveaction\" id='massiveaction'>"; |
1554 |
|
1555 |
echo "<option value=\"-1\" selected>-----</option>"; |
1556 |
echo "<option value=\"delete\">".$LANG["buttons"][6]."</option>"; |
1557 |
echo "<option value=\"assign_vlan\">".$LANG["networking"][55]."</option>"; |
1558 |
echo "<option value=\"unassign_vlan\">".$LANG["networking"][58]."</option>"; |
1559 |
echo "<option value=\"move\">".$LANG["buttons"][20]."</option>"; |
1560 |
echo "</select>"; |
1561 |
|
1562 |
|
1563 |
$params=array('action'=>'__VALUE__', |
1564 |
'type'=>$device_type, |
1565 |
); |
1566 |
|
1567 |
ajaxUpdateItemOnSelectEvent("massiveaction","show_massiveaction",$CFG_GLPI["root_doc"]."/ajax/dropdownMassiveActionPorts.php",$params); |
1568 |
|
1569 |
echo "<span id='show_massiveaction'> </span>\n"; |
1570 |
} |
1571 |
|
1572 |
/**
|
1573 |
* Dropdown for global item management
|
1574 |
*
|
1575 |
* @param $target target for actions
|
1576 |
* @param $withtemplate template or basic computer
|
1577 |
* @param $ID item ID
|
1578 |
* @param $value value of global state
|
1579 |
* @param $management_restrict global management restrict mode
|
1580 |
*/
|
1581 |
function globalManagementDropdown($target,$withtemplate,$ID,$value,$management_restrict=0){ |
1582 |
global $LANG,$CFG_GLPI; |
1583 |
if ($value&&empty($withtemplate)) { |
1584 |
echo $LANG["peripherals"][31]; |
1585 |
|
1586 |
echo " <a title=\"".$LANG["common"][39]."\" href=\"javascript:confirmAction('".addslashes($LANG["common"][40])."\\n".addslashes($LANG["common"][39])."','$target?unglobalize=unglobalize&ID=$ID')\">".$LANG["common"][38]."</a> "; |
1587 |
|
1588 |
echo "<img alt=\"".$LANG["common"][39]."\" title=\"".$LANG["common"][39]."\" src=\"".$CFG_GLPI["root_doc"]."/pics/aide.png\">"; |
1589 |
} else {
|
1590 |
|
1591 |
if ($management_restrict == 2){ |
1592 |
echo "<select name='is_global'>"; |
1593 |
echo "<option value='0' ".(!$value?" selected":"").">".$LANG["peripherals"][32]."</option>"; |
1594 |
echo "<option value='1' ".($value?" selected":"").">".$LANG["peripherals"][31]."</option>"; |
1595 |
echo "</select>"; |
1596 |
} else {
|
1597 |
// Templates edition
|
1598 |
if (!empty($withtemplate)){ |
1599 |
echo "<input type='hidden' name='is_global' value=\"".$management_restrict."\">"; |
1600 |
echo (!$management_restrict?$LANG["peripherals"][32]:$LANG["peripherals"][31]); |
1601 |
} else {
|
1602 |
echo (!$value?$LANG["peripherals"][32]:$LANG["peripherals"][31]); |
1603 |
} |
1604 |
} |
1605 |
|
1606 |
} |
1607 |
} |
1608 |
/**
|
1609 |
* Dropdown for alerting of contracts
|
1610 |
*
|
1611 |
* @param $myname select name
|
1612 |
* @param $value default value
|
1613 |
*/
|
1614 |
function dropdownContractAlerting($myname,$value){ |
1615 |
global $LANG; |
1616 |
echo "<select name='$myname'>"; |
1617 |
echo "<option value='0' ".($value==0?"selected":"")." >-------</option>"; |
1618 |
echo "<option value='".pow(2,ALERT_END)."' ".($value==pow(2,ALERT_END)?"selected":"")." >".$LANG["buttons"][32]."</option>"; |
1619 |
echo "<option value='".pow(2,ALERT_NOTICE)."' ".($value==pow(2,ALERT_NOTICE)?"selected":"")." >".$LANG["financial"][10]."</option>"; |
1620 |
echo "<option value='".(pow(2,ALERT_END)+pow(2,ALERT_NOTICE))."' ".($value==(pow(2,ALERT_END)+pow(2,ALERT_NOTICE))?"selected":"")." >".$LANG["buttons"][32]." + ".$LANG["financial"][10]."</option>"; |
1621 |
echo "</select>"; |
1622 |
|
1623 |
} |
1624 |
|
1625 |
|
1626 |
/**
|
1627 |
* Print a select with hours
|
1628 |
*
|
1629 |
* Print a select named $name with hours options and selected value $value
|
1630 |
*
|
1631 |
*@param $name string : HTML select name
|
1632 |
*@param $value integer : HTML select selected value
|
1633 |
*@param $limit_planning limit planning to the configuration range
|
1634 |
*
|
1635 |
*@return Nothing (display)
|
1636 |
*
|
1637 |
**/
|
1638 |
function dropdownHours($name,$value,$limit_planning=0){ |
1639 |
global $CFG_GLPI; |
1640 |
|
1641 |
$begin=0; |
1642 |
$end=24; |
1643 |
$step=$CFG_GLPI["time_step"]; |
1644 |
// Check if the $step is Ok for the $value field
|
1645 |
$split=split(":",$value); |
1646 |
// Valid value XX:YY ou XX:YY:ZZ
|
1647 |
if (count($split)==2||count($split)==3){ |
1648 |
$min=$split[1]; |
1649 |
// Problem
|
1650 |
if (($min%$step)!=0){ |
1651 |
// set minimum step
|
1652 |
$step=5; |
1653 |
} |
1654 |
} |
1655 |
|
1656 |
if ($limit_planning){ |
1657 |
$plan_begin=split(":",$CFG_GLPI["planning_begin"]); |
1658 |
$plan_end=split(":",$CFG_GLPI["planning_end"]); |
1659 |
$begin=(int) $plan_begin[0]; |
1660 |
$end=(int) $plan_end[0]; |
1661 |
} |
1662 |
echo "<select name=\"$name\">"; |
1663 |
for ($i=$begin;$i<$end;$i++){ |
1664 |
if ($i<10) |
1665 |
$tmp="0".$i; |
1666 |
else $tmp=$i; |
1667 |
|
1668 |
for ($j=0;$j<60;$j+=$step){ |
1669 |
if ($j<10) $val=$tmp.":0$j"; |
1670 |
else $val=$tmp.":$j"; |
1671 |
|
1672 |
echo "<option value='$val' ".($value==$val.":00"||$value==$val?" selected ":"").">$val</option>"; |
1673 |
} |
1674 |
} |
1675 |
// Last item
|
1676 |
$val=$end.":00"; |
1677 |
echo "<option value='$val' ".($value==$val.":00"||$value==$val?" selected ":"").">$val</option>"; |
1678 |
echo "</select>"; |
1679 |
} |
1680 |
|
1681 |
/**
|
1682 |
* Dropdown licenses for a software
|
1683 |
*
|
1684 |
* @param $myname select name
|
1685 |
* @param $sID software ID
|
1686 |
*/
|
1687 |
function dropdownLicenseOfSoftware($myname,$sID) { |
1688 |
global $DB,$LANG; |
1689 |
|
1690 |
$query="SELECT * FROM glpi_licenses |
1691 |
WHERE sID='$sID'
|
1692 |
GROUP BY version, serial, expire, oem, oem_computer, buy
|
1693 |
ORDER BY version, serial, expire, oem, oem_computer, buy";
|
1694 |
$result=$DB->query($query); |
1695 |
if ($DB->numrows($result)){ |
1696 |
echo "<select name='$myname'>"; |
1697 |
while ($data=$DB->fetch_array($result)){ |
1698 |
echo "<option value='".$data["ID"]."'>".$data["version"]." - ".$data["serial"]; |
1699 |
if ($data["expire"]!=NULL) echo " - ".$LANG["software"][25]." ".$data["expire"]; |
1700 |
else echo " - ".$LANG["software"][26]; |
1701 |
if ($data["buy"]) echo " - ".$LANG["software"][35]; |
1702 |
else echo " - ".$LANG["software"][37]; |
1703 |
if ($data["oem"]) echo " - ".$LANG["software"][28]; |
1704 |
echo "</option>"; |
1705 |
} |
1706 |
echo "</select>"; |
1707 |
} |
1708 |
|
1709 |
} |
1710 |
|
1711 |
/**
|
1712 |
* Dropdown integers
|
1713 |
*
|
1714 |
* @param $myname select name
|
1715 |
* @param $value default value
|
1716 |
* @param $min min value
|
1717 |
* @param $max max value
|
1718 |
* @param $step step used
|
1719 |
* @param $toadd values to add at the beginning
|
1720 |
*/
|
1721 |
function dropdownInteger($myname,$value,$min=0,$max=100,$step=1,$toadd=array()){ |
1722 |
|
1723 |
echo "<select name='$myname'>\n"; |
1724 |
if (count($toadd)){ |
1725 |
foreach ($toadd as $key => $val){ |
1726 |
echo "<option value='$key' ".($key==$value?" selected ":"").">$val</option>"; |
1727 |
} |
1728 |
} |
1729 |
for ($i=$min;$i<=$max;$i+=$step){ |
1730 |
echo "<option value='$i' ".($i==$value?" selected ":"").">$i</option>"; |
1731 |
} |
1732 |
echo "</select>"; |
1733 |
|
1734 |
} |
1735 |
/**
|
1736 |
* Dropdown available languages
|
1737 |
*
|
1738 |
* @param $myname select name
|
1739 |
* @param $value default value
|
1740 |
*/
|
1741 |
function dropdownLanguages($myname,$value){ |
1742 |
global $CFG_GLPI; |
1743 |
echo "<select name='$myname'>"; |
1744 |
|
1745 |
foreach ($CFG_GLPI["languages"] as $key => $val){ |
1746 |
if (isset($val[1])&&is_file(GLPI_ROOT ."/locales/".$val[1])){ |
1747 |
echo "<option value=\"".$key."\""; |
1748 |
if ($value==$key) { echo " selected"; } |
1749 |
echo ">".$val[0]." ($key)"; |
1750 |
} |
1751 |
} |
1752 |
echo "</select>"; |
1753 |
} |
1754 |
|
1755 |
/**
|
1756 |
* Display entities of the loaded profile
|
1757 |
*
|
1758 |
* @param $myname select name
|
1759 |
* @param $target target for entity change action
|
1760 |
*/
|
1761 |
function displayActiveEntities($target,$myname){ |
1762 |
global $CFG_GLPI,$LANG; |
1763 |
|
1764 |
echo "<div class='center' ><span class='b'>".$LANG["entity"][10]." ( » ".$LANG["entity"][11].")</span><br>"; |
1765 |
echo "<a style='font-size:14px;' href='".$target."?active_entity=all' title=\"".$LANG["buttons"][40]."\">_ ".ereg_replace(" "," ",$LANG["buttons"][40])." _</a></div><br>"; |
1766 |
|
1767 |
echo "<div class='left' style='width:100%'>"; |
1768 |
|
1769 |
foreach ($_SESSION['glpi_entities_tree'] as $ID => $tree){ |
1770 |
displayEntityTree($target,$myname,$tree); |
1771 |
} |
1772 |
|
1773 |
echo "</div>"; |
1774 |
/*
|
1775 |
echo "<table>";
|
1776 |
echo "<tr><td style='text-align:left;'><a href='".$target."?active_entity=all' title=\"".$LANG["buttons"][40]."\">_ ".ereg_replace(" "," ",$LANG["buttons"][40])." _</a></td></tr>";
|
1777 |
|
1778 |
foreach ($_SESSION['glpi_entities_tree'] as $ID => $tree){
|
1779 |
displayEntityTree($target,$myname,$tree);
|
1780 |
}
|
1781 |
echo "</table>";
|
1782 |
*/
|
1783 |
} |
1784 |
/**
|
1785 |
* Display entities tree
|
1786 |
*
|
1787 |
* @param $myname select name
|
1788 |
* @param $target target for entity change action
|
1789 |
* @param $tree the entity tree structure
|
1790 |
* @param $level current level displayed
|
1791 |
*/
|
1792 |
function displayEntityTree($target,$myname,$tree,$level=0){ |
1793 |
global $CFG_GLPI,$LANG; |
1794 |
|
1795 |
if (count($tree)){ |
1796 |
// Is multiple items to display ? only one expand it if have subitems
|
1797 |
foreach ($tree as $ID => $data){ |
1798 |
if (isset($data['name'])){ |
1799 |
$class=" class='tree' "; |
1800 |
$raquo=""; |
1801 |
$fsize=max(16-2*$level,12); |
1802 |
|
1803 |
//
|
1804 |
$subitems=0; |
1805 |
if (isset($data['tree'])&&count($data['tree'])){ |
1806 |
$subitems=count($data['tree']); |
1807 |
if ($subitems>1){ |
1808 |
$raquo="<a href=\"javascript:showHideDiv('entity_subitem_$ID','entity_subitem_icon_$ID','+','" . GLPI_ROOT . "/pics/collapse.gif');\">+</a>"; |
1809 |
} |
1810 |
} |
1811 |
|
1812 |
if ($level==0){ |
1813 |
$class=" class='treeroot' "; |
1814 |
$raquo=""; |
1815 |
} |
1816 |
|
1817 |
|
1818 |
echo "<div $class>".str_repeat(" ", max(1,$level)).$raquo." <a style='font-size:".$fsize."px;' title=\"".$data['name']."\" href='".$target."?active_entity=$ID'>".ereg_replace(" "," ",$data['name'])."</a>"; |
1819 |
|
1820 |
if ($subitems){ |
1821 |
echo " <a title=\"".$LANG["buttons"][40]."\" href='".$target."?active_entity=$ID&recursive=1'> » </a></div>"; |
1822 |
if ($level!=0 && $subitems>1){ |
1823 |
echo "<div id='entity_subitem_$ID' style='display: none;'>"; |
1824 |
displayEntityTree($target,$myname,$data['tree'],$level+1); |
1825 |
echo "</div>"; |
1826 |
}else {
|
1827 |
displayEntityTree($target,$myname,$data['tree'],$level+1); |
1828 |
} |
1829 |
} else {
|
1830 |
echo " </div>"; |
1831 |
} |
1832 |
} |
1833 |
} |
1834 |
} |
1835 |
|
1836 |
/* if (count($tree)){
|
1837 |
foreach ($tree as $ID => $data){
|
1838 |
if (isset($data['name'])){
|
1839 |
$class=" class='tree' ";
|
1840 |
$raquo="";
|
1841 |
if ($level==0){
|
1842 |
$class=" class='treeroot' ";
|
1843 |
$raquo="";
|
1844 |
}
|
1845 |
|
1846 |
echo "<tr><td $class>".str_repeat(" ", $level+1).$raquo." <a title=\"".$data['name']."\" href='".$target."?active_entity=$ID'>".ereg_replace(" "," ",$data['name'])."</a>";
|
1847 |
|
1848 |
if (isset($data['tree'])&&count($data['tree'])){
|
1849 |
echo " <a title=\"".$LANG["buttons"][40]."\" href='".$target."?active_entity=$ID&recursive=1'> » </a></td></tr>";
|
1850 |
displayEntityTree($target,$myname,$data['tree'],$level+1);
|
1851 |
} else echo " </td></tr>";
|
1852 |
}
|
1853 |
}
|
1854 |
}
|
1855 |
*/
|
1856 |
} |
1857 |
|
1858 |
|
1859 |
|
1860 |
/**
|
1861 |
* Dropdown of ticket status
|
1862 |
*
|
1863 |
* @param $name select name
|
1864 |
* @param $value default value
|
1865 |
*/
|
1866 |
function dropdownStatus($name,$value=0){ |
1867 |
global $LANG; |
1868 |
|
1869 |
echo "<select name='$name'>"; |
1870 |
echo "<option value='new' ".($value=="new"?" selected ":"").">".$LANG["joblist"][9]."</option>"; |
1871 |
echo "<option value='assign' ".($value=="assign"?" selected ":"").">".$LANG["joblist"][18]."</option>"; |
1872 |
echo "<option value='plan' ".($value=="plan"?" selected ":"").">".$LANG["joblist"][19]."</option>"; |
1873 |
echo "<option value='waiting' ".($value=="waiting"?" selected ":"").">".$LANG["joblist"][26]."</option>"; |
1874 |
echo "<option value='old_done' ".($value=="old_done"?" selected ":"").">".$LANG["joblist"][10]."</option>"; |
1875 |
echo "<option value='old_notdone' ".($value=="old_notdone"?" selected ":"").">".$LANG["joblist"][17]."</option>"; |
1876 |
echo "</select>"; |
1877 |
} |
1878 |
|
1879 |
/**
|
1880 |
* Get ticket status Name
|
1881 |
*
|
1882 |
* @param $value status ID
|
1883 |
*/
|
1884 |
function getStatusName($value){ |
1885 |
global $LANG; |
1886 |
|
1887 |
switch ($value){ |
1888 |
case "new" : |
1889 |
return $LANG["joblist"][9]; |
1890 |
break;
|
1891 |
case "assign" : |
1892 |
return $LANG["joblist"][18]; |
1893 |
break;
|
1894 |
case "plan" : |
1895 |
return $LANG["joblist"][19]; |
1896 |
break;
|
1897 |
case "waiting" : |
1898 |
return $LANG["joblist"][26]; |
1899 |
break;
|
1900 |
case "old_done" : |
1901 |
return $LANG["joblist"][10]; |
1902 |
break;
|
1903 |
case "old_notdone" : |
1904 |
return $LANG["joblist"][17]; |
1905 |
break;
|
1906 |
} |
1907 |
} |
1908 |
|
1909 |
/**
|
1910 |
* Dropdown of ticket priority
|
1911 |
*
|
1912 |
* @param $name select name
|
1913 |
* @param $value default value
|
1914 |
* @param $complete see also at least selection
|
1915 |
*/
|
1916 |
function dropdownPriority($name,$value=0,$complete=0){ |
1917 |
global $LANG; |
1918 |
|
1919 |
echo "<select name='$name'>"; |
1920 |
if ($complete){ |
1921 |
echo "<option value='0' ".($value==1?" selected ":"").">".$LANG["common"][66]."</option>"; |
1922 |
echo "<option value='-5' ".($value==-5?" selected ":"").">".$LANG["search"][16]." ".$LANG["help"][3]."</option>"; |
1923 |
echo "<option value='-4' ".($value==-4?" selected ":"").">".$LANG["search"][16]." ".$LANG["help"][4]."</option>"; |
1924 |
echo "<option value='-3' ".($value==-3?" selected ":"").">".$LANG["search"][16]." ".$LANG["help"][5]."</option>"; |
1925 |
echo "<option value='-2' ".($value==-2?" selected ":"").">".$LANG["search"][16]." ".$LANG["help"][6]."</option>"; |
1926 |
echo "<option value='-1' ".($value==-1?" selected ":"").">".$LANG["search"][16]." ".$LANG["help"][7]."</option>"; |
1927 |
} |
1928 |
echo "<option value='5' ".($value==5?" selected ":"").">".$LANG["help"][3]."</option>"; |
1929 |
echo "<option value='4' ".($value==4?" selected ":"").">".$LANG["help"][4]."</option>"; |
1930 |
echo "<option value='3' ".($value==3?" selected ":"").">".$LANG["help"][5]."</option>"; |
1931 |
echo "<option value='2' ".($value==2?" selected ":"").">".$LANG["help"][6]."</option>"; |
1932 |
echo "<option value='1' ".($value==1?" selected ":"").">".$LANG["help"][7]."</option>"; |
1933 |
|
1934 |
echo "</select>"; |
1935 |
} |
1936 |
|
1937 |
/**
|
1938 |
* Get ticket priority Name
|
1939 |
*
|
1940 |
* @param $value status ID
|
1941 |
*/
|
1942 |
function getPriorityName($value){ |
1943 |
global $LANG; |
1944 |
|
1945 |
switch ($value){ |
1946 |
case 5 : |
1947 |
return $LANG["help"][3]; |
1948 |
break;
|
1949 |
case 4 : |
1950 |
return $LANG["help"][4]; |
1951 |
break;
|
1952 |
case 3 : |
1953 |
return $LANG["help"][5]; |
1954 |
break;
|
1955 |
case 2 : |
1956 |
return $LANG["help"][6]; |
1957 |
break;
|
1958 |
case 1 : |
1959 |
return $LANG["help"][7]; |
1960 |
break;
|
1961 |
} |
1962 |
} |
1963 |
/**
|
1964 |
* Get ticket request type name
|
1965 |
*
|
1966 |
* @param $value status ID
|
1967 |
*/
|
1968 |
function getRequestTypeName($value){ |
1969 |
global $LANG; |
1970 |
|
1971 |
switch ($value){ |
1972 |
case 1 : |
1973 |
return $LANG["Menu"][31]; |
1974 |
break;
|
1975 |
case 2 : |
1976 |
return $LANG["setup"][14]; |
1977 |
break;
|
1978 |
case 3 : |
1979 |
return $LANG["help"][35]; |
1980 |
break;
|
1981 |
case 4 : |
1982 |
return $LANG["tracking"][34]; |
1983 |
break;
|
1984 |
case 5 : |
1985 |
return $LANG["tracking"][35]; |
1986 |
break;
|
1987 |
case 6 : |
1988 |
return $LANG["common"][62]; |
1989 |
break;
|
1990 |
default : return ""; |
1991 |
} |
1992 |
} |
1993 |
/**
|
1994 |
* Dropdown of ticket request type
|
1995 |
*
|
1996 |
* @param $name select name
|
1997 |
* @param $value default value
|
1998 |
*/
|
1999 |
function dropdownRequestType($name,$value=0){ |
2000 |
global $LANG; |
2001 |
|
2002 |
echo "<select name='$name'>"; |
2003 |
echo "<option value='0' ".($value==0?" selected ":"").">-----</option>"; |
2004 |
echo "<option value='1' ".($value==1?" selected ":"").">".$LANG["Menu"][31]."</option>"; // Helpdesk |
2005 |
echo "<option value='2' ".($value==2?" selected ":"").">".$LANG["setup"][14]."</option>"; // mail |
2006 |
echo "<option value='3' ".($value==3?" selected ":"").">".$LANG["help"][35]."</option>"; // phone |
2007 |
echo "<option value='4' ".($value==4?" selected ":"").">".$LANG["tracking"][34]."</option>"; // direct |
2008 |
echo "<option value='5' ".($value==5?" selected ":"").">".$LANG["tracking"][35]."</option>"; // writing |
2009 |
echo "<option value='6' ".($value==6?" selected ":"").">".$LANG["common"][62]."</option>"; // other |
2010 |
|
2011 |
echo "</select>"; |
2012 |
} |
2013 |
|
2014 |
/**
|
2015 |
* Dropdown of amortissement type for infocoms
|
2016 |
*
|
2017 |
* @param $name select name
|
2018 |
* @param $value default value
|
2019 |
*/
|
2020 |
function dropdownAmortType($name,$value=0){ |
2021 |
global $LANG; |
2022 |
|
2023 |
echo "<select name='$name'>"; |
2024 |
echo "<option value='0' ".($value==0?" selected ":"").">-------------</option>"; |
2025 |
echo "<option value='2' ".($value==2?" selected ":"").">".$LANG["financial"][47]."</option>"; |
2026 |
echo "<option value='1' ".($value==1?" selected ":"").">".$LANG["financial"][48]."</option>"; |
2027 |
echo "</select>"; |
2028 |
} |
2029 |
/**
|
2030 |
* Get amortissement type name for infocoms
|
2031 |
*
|
2032 |
* @param $value status ID
|
2033 |
*/
|
2034 |
function getAmortTypeName($value){ |
2035 |
global $LANG; |
2036 |
|
2037 |
switch ($value){ |
2038 |
case 2 : |
2039 |
return $LANG["financial"][47]; |
2040 |
break;
|
2041 |
case 1 : |
2042 |
return $LANG["financial"][48]; |
2043 |
break;
|
2044 |
case 0 : |
2045 |
return ""; |
2046 |
break;
|
2047 |
|
2048 |
} |
2049 |
} |
2050 |
/**
|
2051 |
* Get planninf state name
|
2052 |
*
|
2053 |
* @param $value status ID
|
2054 |
*/
|
2055 |
function getPlanningState($value) |
2056 |
{ |
2057 |
global $LANG; |
2058 |
|
2059 |
switch ($value){ |
2060 |
case 0: |
2061 |
return $LANG["planning"][16]; |
2062 |
break;
|
2063 |
case 1: |
2064 |
return $LANG["planning"][17]; |
2065 |
break;
|
2066 |
case 2: |
2067 |
return $LANG["planning"][18]; |
2068 |
break;
|
2069 |
} |
2070 |
|
2071 |
} |
2072 |
|
2073 |
/**
|
2074 |
* Dropdown of planning state
|
2075 |
*
|
2076 |
* @param $name select name
|
2077 |
* @param $value default value
|
2078 |
*/
|
2079 |
function dropdownPlanningState($name,$value='') |
2080 |
{ |
2081 |
global $LANG; |
2082 |
|
2083 |
echo "<select name='$name' id='$name'>"; |
2084 |
|
2085 |
echo "<option value='0'".($value==0?" selected ":"").">".$LANG["planning"][16]."</option>"; |
2086 |
echo "<option value='1'".($value==1?" selected ":"").">".$LANG["planning"][17]."</option>"; |
2087 |
echo "<option value='2'".($value==2?" selected ":"").">".$LANG["planning"][18]."</option>"; |
2088 |
|
2089 |
echo "</select>"; |
2090 |
|
2091 |
} |
2092 |
|
2093 |
/**
|
2094 |
* Dropdown of values in an array
|
2095 |
*
|
2096 |
* @param $name select name
|
2097 |
* @param $elements array of elements to display
|
2098 |
* @param $value default value
|
2099 |
* @param $used already used elements key (do not display)
|
2100 |
*
|
2101 |
*/
|
2102 |
function dropdownArrayValues($name,$elements,$value='',$used=array()){ |
2103 |
$rand=mt_rand();
|
2104 |
echo "<select name='$name' id='dropdown_".$name.$rand."'>"; |
2105 |
|
2106 |
foreach($elements as $key => $val){ |
2107 |
if (!isset($used[$key])) { |
2108 |
echo "<option value='".$key."'".($value==$key?" selected ":"").">".$val."</option>"; |
2109 |
} |
2110 |
} |
2111 |
|
2112 |
echo "</select>"; |
2113 |
return $rand; |
2114 |
} |
2115 |
|
2116 |
/**
|
2117 |
* Remplace an dropdown by an hidden input field
|
2118 |
* and display the value.
|
2119 |
*
|
2120 |
* @param $name select name
|
2121 |
* @param $elements array of elements to display
|
2122 |
* @param $value default value
|
2123 |
* @param $used already used elements key (do not display)
|
2124 |
*
|
2125 |
*/
|
2126 |
function dropdownArrayValuesReadonly($name,$elements,$value='',$used=array()){ |
2127 |
|
2128 |
echo "<input type='hidden' name='$name' value='$value'>"; |
2129 |
|
2130 |
if (isset($elements[$value])) { |
2131 |
echo $elements[$value]; |
2132 |
} |
2133 |
} |
2134 |
|
2135 |
/**
|
2136 |
* Dropdown of states for behaviour config
|
2137 |
*
|
2138 |
* @param $name select name
|
2139 |
* @param $lib string to add for -1 value
|
2140 |
* @param $value default value
|
2141 |
*/
|
2142 |
function dropdownStateBehaviour ($name, $lib="", $value=0){ |
2143 |
global $DB, $LANG; |
2144 |
|
2145 |
$elements=array("0"=>$LANG["setup"][195]); |
2146 |
if ($lib) { |
2147 |
$elements["-1"]=$lib; |
2148 |
} |
2149 |
|
2150 |
$queryStateList = "SELECT ID,name from glpi_dropdown_state ORDER BY name"; |
2151 |
$result = $DB->query($queryStateList); |
2152 |
if ($DB->numrows($result) > 0) { |
2153 |
while (($data = $DB->fetch_assoc($result))) { |
2154 |
$elements[$data["ID"]] = $LANG["setup"][198] . ": " . $data["name"]; |
2155 |
} |
2156 |
} |
2157 |
dropdownArrayValues($name, $elements, $value); |
2158 |
} |
2159 |
|
2160 |
/**
|
2161 |
* Dropdown for global management config
|
2162 |
*
|
2163 |
* @param $name select name
|
2164 |
* @param $value default value
|
2165 |
* @param $software is it for software ?
|
2166 |
*/
|
2167 |
function adminManagementDropdown($name,$value,$software=0){ |
2168 |
global $LANG; |
2169 |
echo "<select name=\"".$name."\">"; |
2170 |
|
2171 |
if (!$software){ |
2172 |
$yesUnit = $LANG["peripherals"][32]; |
2173 |
$yesGlobal = $LANG["peripherals"][31]; |
2174 |
} else {
|
2175 |
$yesUnit = $LANG["ocsconfig"][46]; |
2176 |
$yesGlobal = $LANG["ocsconfig"][45]; |
2177 |
} |
2178 |
|
2179 |
echo "<option value=\"2\""; |
2180 |
if ($value == 2) { |
2181 |
echo " selected"; |
2182 |
} |
2183 |
echo ">".$LANG["choice"][0]."</option>"; |
2184 |
|
2185 |
echo "<option value=\"0\""; |
2186 |
if ($value == 0) { |
2187 |
echo " selected"; |
2188 |
} |
2189 |
echo ">" . $LANG["choice"][1]." - ". $LANG["setup"][274]. " : ". $yesUnit . "</option>"; |
2190 |
|
2191 |
echo "<option value=\"1\""; |
2192 |
if ($value == 1) { |
2193 |
echo " selected"; |
2194 |
} |
2195 |
echo ">" . $LANG["choice"][1]." - ". $LANG["setup"][274]. " : ". $yesGlobal . " </option>"; |
2196 |
|
2197 |
echo "</select>"; |
2198 |
} |
2199 |
/**
|
2200 |
* Dropdown for GMT selection
|
2201 |
*
|
2202 |
* @param $name select name
|
2203 |
* @param $value default value
|
2204 |
*/
|
2205 |
function dropdownGMT($name,$value=''){ |
2206 |
global $LANG; |
2207 |
$elements = array ( -12, -11, -10, -9, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, 1, 2, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 8, 9, 9.5, 10, 11, 12, 13); |
2208 |
|
2209 |
echo "<select name='$name' id='dropdown_".$name."'>"; |
2210 |
|
2211 |
foreach($elements as $element){ |
2212 |
if ($element != 0) |
2213 |
$display_value = $LANG["gmt"][0].($element > 0?" +":" ").$element." ".$LANG["gmt"][1]; |
2214 |
else $display_value = $LANG["gmt"][0]; |
2215 |
echo "<option value='".$element."'".($element==$value?" selected ":"").">".$display_value."</option>"; |
2216 |
} |
2217 |
|
2218 |
echo "</select>"; |
2219 |
} |
2220 |
|
2221 |
/**
|
2222 |
* Dropdown rules for a defined rule_type
|
2223 |
*
|
2224 |
* @param $myname select name
|
2225 |
* @param $rule_type rule type
|
2226 |
*/
|
2227 |
function dropdownRules ($rule_type, $myname){ |
2228 |
global $DB, $CFG_GLPI, $LANG; |
2229 |
|
2230 |
$rand=mt_rand();
|
2231 |
$limit_length=$CFG_GLPI["dropdown_limit"]; |
2232 |
|
2233 |
$use_ajax=false; |
2234 |
if ($CFG_GLPI["use_ajax"]){ |
2235 |
$nb=countElementsInTable("glpi_rules_descriptions", "rule_type=".$rule_type); |
2236 |
|
2237 |
if ($nb>$CFG_GLPI["ajax_limit_count"]){ |
2238 |
$use_ajax=true; |
2239 |
} |
2240 |
} |
2241 |
$params=array('searchText'=>'__VALUE__', |
2242 |
'myname'=>$myname, |
2243 |
'limit'=>$limit_length, |
2244 |
'rand'=>$rand, |
2245 |
'type'=>$rule_type |
2246 |
); |
2247 |
$default="<select name='$myname' id='dropdown_".$myname.$rand."'><option value='0'>------</option></select>\n"; |
2248 |
ajaxDropdown($use_ajax,"/ajax/dropdownRules.php",$params,$default,$rand); |
2249 |
|
2250 |
return $rand; |
2251 |
} |
2252 |
/**
|
2253 |
* Dropdown profiles which have rights under the active one
|
2254 |
*
|
2255 |
* @param $name select name
|
2256 |
* @param $value default value
|
2257 |
*/
|
2258 |
function dropdownUnderProfiles($name,$value=''){ |
2259 |
global $DB; |
2260 |
|
2261 |
$profiles[0]="-----"; |
2262 |
|
2263 |
$prof=new Profile(); |
2264 |
|
2265 |
$query="SELECT * FROM glpi_profiles ".$prof->getUnderProfileRetrictRequest("WHERE")." ORDER BY name"; |
2266 |
|
2267 |
$res = $DB->query($query); |
2268 |
|
2269 |
//New rule -> get the next free ranking
|
2270 |
if ($DB->numrows($res)){ |
2271 |
while ($data = $DB->fetch_array($res)){ |
2272 |
$profiles[$data['ID']]=$data['name']; |
2273 |
} |
2274 |
} |
2275 |
|
2276 |
dropdownArrayValues($name,$profiles,$value); |
2277 |
} |
2278 |
|
2279 |
/**
|
2280 |
* Dropdown for infocoms alert config
|
2281 |
*
|
2282 |
* @param $name select name
|
2283 |
* @param $value default value
|
2284 |
*/
|
2285 |
function dropdownAlertInfocoms($name,$value=0){ |
2286 |
global $LANG; |
2287 |
echo "<select name=\"$name\">"; |
2288 |
echo "<option value=\"0\" ".($value==0?" selected ":"")." >-----</option>"; |
2289 |
echo "<option value=\"".pow(2,ALERT_END)."\" ".($value==pow(2,ALERT_END)?" selected ":"")." >".$LANG["financial"][80]." </option>"; |
2290 |
echo "</select>"; |
2291 |
} |
2292 |
|
2293 |
|
2294 |
/**
|
2295 |
* Private / Public switch for items which may be assign to a user and/or an entity
|
2296 |
*
|
2297 |
* @param $private default is private ?
|
2298 |
* @param $entity working entity ID
|
2299 |
* @param $recursive is the item recursive ?
|
2300 |
*/
|
2301 |
function privatePublicSwitch($private,$entity,$recursive){ |
2302 |
global $LANG,$CFG_GLPI; |
2303 |
|
2304 |
$rand=mt_rand();
|
2305 |
|
2306 |
echo "<script type='text/javascript' >\n"; |
2307 |
echo "function setPrivate$rand(){\n"; |
2308 |
|
2309 |
$params=array( |
2310 |
'private'=>1, |
2311 |
'recursive'=>$recursive, |
2312 |
'FK_entities'=>$entity, |
2313 |
'rand'=>$rand, |
2314 |
); |
2315 |
ajaxUpdateItemJsCode('private_switch'.$rand,$CFG_GLPI["root_doc"]."/ajax/private_public.php",$params,false); |
2316 |
|
2317 |
echo "};"; |
2318 |
echo "function setPublic$rand(){\n"; |
2319 |
|
2320 |
$params=array( |
2321 |
'private'=>0, |
2322 |
'recursive'=>$recursive, |
2323 |
'FK_entities'=>$entity, |
2324 |
'rand'=>$rand, |
2325 |
); |
2326 |
ajaxUpdateItemJsCode('private_switch'.$rand,$CFG_GLPI["root_doc"]."/ajax/private_public.php",$params,false); |
2327 |
|
2328 |
echo "};"; |
2329 |
echo "</script>"; |
2330 |
|
2331 |
|
2332 |
echo "<span id='private_switch$rand'>"; |
2333 |
$_POST['rand']=$rand; |
2334 |
$_POST['private']=$private; |
2335 |
$_POST['recursive']=$recursive; |
2336 |
$_POST['FK_entities']=$entity; |
2337 |
include (GLPI_ROOT."/ajax/private_public.php"); |
2338 |
echo "</span>\n"; |
2339 |
return $rand; |
2340 |
} |
2341 |
|
2342 |
|
2343 |
/**
|
2344 |
* Print a select with contract priority
|
2345 |
*
|
2346 |
* Print a select named $name with contract periodicty options and selected value $value
|
2347 |
*
|
2348 |
*@param $name string : HTML select name
|
2349 |
*@param $value integer : HTML select selected value
|
2350 |
*
|
2351 |
*@return Nothing (display)
|
2352 |
*
|
2353 |
**/
|
2354 |
function dropdownContractPeriodicity($name,$value=0){ |
2355 |
global $LANG; |
2356 |
$values=array("1","2","3","6","12","24","36"); |
2357 |
|
2358 |
echo "<select name='$name'>"; |
2359 |
echo "<option value='0' ".($value==0?" selected ":"").">-------------</option>"; |
2360 |
foreach ( $values as $val) |
2361 |
echo "<option value='$val' ".($value==$val?" selected ":"").">".$val." ".$LANG["financial"][57]."</option>"; |
2362 |
echo "</select>"; |
2363 |
} |
2364 |
|
2365 |
/**
|
2366 |
* Print a select with contract renewal
|
2367 |
*
|
2368 |
* Print a select named $name with contract renewal options and selected value $value
|
2369 |
*
|
2370 |
*@param $name string : HTML select name
|
2371 |
*@param $value integer : HTML select selected value
|
2372 |
*
|
2373 |
*@return Nothing (display)
|
2374 |
*
|
2375 |
**/
|
2376 |
function dropdownContractRenewal($name,$value=0){ |
2377 |
global $LANG; |
2378 |
|
2379 |
echo "<select name='$name'>"; |
2380 |
echo "<option value='0' ".($value==0?" selected ":"").">-------------</option>"; |
2381 |
echo "<option value='1' ".($value==1?" selected ":"").">".$LANG["financial"][105]."</option>"; |
2382 |
echo "<option value='2' ".($value==2?" selected ":"").">".$LANG["financial"][106]."</option>"; |
2383 |
echo "</select>"; |
2384 |
} |
2385 |
|
2386 |
/**
|
2387 |
* Get the renewal type name
|
2388 |
*
|
2389 |
*@param $value integer : HTML select selected value
|
2390 |
*
|
2391 |
*@return string
|
2392 |
*
|
2393 |
**/
|
2394 |
function getContractRenewalName($value){ |
2395 |
global $LANG; |
2396 |
switch ($value){ |
2397 |
case 1: return $LANG["financial"][105];break; |
2398 |
case 2: return $LANG["financial"][106];break; |
2399 |
default : return ""; |
2400 |
} |
2401 |
} |
2402 |
/**
|
2403 |
* Get renewal ID by name
|
2404 |
* @param $value the name of the renewal
|
2405 |
*
|
2406 |
* @return the ID of the renewal
|
2407 |
*/
|
2408 |
function getContractRenewalIDByName($value){ |
2409 |
global $LANG; |
2410 |
if (eregi($value,$LANG["financial"][105])){ |
2411 |
return 1; |
2412 |
} else if (eregi($value,$LANG["financial"][106])){ |
2413 |
return 2; |
2414 |
} |
2415 |
return 0; |
2416 |
} |
2417 |
|
2418 |
?>
|