ryxeo-glpi-git / inc / ajax.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (7,44 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: ajax.function.php 7763 2009-01-06 18:44:50Z moyo $
|
4 |
-------------------------------------------------------------------------
|
5 |
GLPI - Gestionnaire Libre de Parc Informatique
|
6 |
Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
7 |
|
8 |
http://indepnet.net/ http://glpi-project.org
|
9 |
-------------------------------------------------------------------------
|
10 |
|
11 |
LICENSE
|
12 |
|
13 |
This file is part of GLPI.
|
14 |
|
15 |
GLPI is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
17 |
the Free Software Foundation; either version 2 of the License, or
|
18 |
(at your option) any later version.
|
19 |
|
20 |
GLPI is distributed in the hope that it will be useful,
|
21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
GNU General Public License for more details.
|
24 |
|
25 |
You should have received a copy of the GNU General Public License
|
26 |
along with GLPI; if not, write to the Free Software
|
27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
28 |
--------------------------------------------------------------------------
|
29 |
*/
|
30 |
|
31 |
/**
|
32 |
* Complete Dropdown system using ajax to get datas
|
33 |
*
|
34 |
* @param $use_ajax Use ajax search system (if not display a standard dropdown)
|
35 |
* @param $relativeurl Relative URL to the root directory of GLPI
|
36 |
* @param $params Parameters to send to ajax URL
|
37 |
* @param $default Default datas t print in case of $use_ajax
|
38 |
* @param $rand Random parameter used
|
39 |
**/
|
40 |
function ajaxDropdown($use_ajax,$relativeurl,$params=array(),$default=" ",$rand=0){ |
41 |
global $CFG_GLPI,$DB,$LANG,$LINK_ID_TABLE; |
42 |
|
43 |
if ($rand==0){ |
44 |
$rand=mt_rand();
|
45 |
} |
46 |
ajaxDisplaySearchTextForDropdown($rand);
|
47 |
ajaxUpdateItemOnInputTextEvent("search_$rand","results_$rand",$CFG_GLPI["root_doc"].$relativeurl,$params); |
48 |
if (!$use_ajax){ |
49 |
echo "<script type='text/javascript' >\n"; |
50 |
echo "\$('search_$rand').hide();"; |
51 |
echo "</script>\n"; |
52 |
} |
53 |
echo "<span id='results_$rand'>\n"; |
54 |
if (!$use_ajax){ |
55 |
// Save post datas if exists
|
56 |
$oldpost=array(); |
57 |
if (isset($_POST)&&count($_POST)){ |
58 |
$oldpost=$_POST; |
59 |
} |
60 |
$_POST=$params; |
61 |
$_POST["searchText"]=$CFG_GLPI["ajax_wildcard"]; |
62 |
include (GLPI_ROOT.$relativeurl); |
63 |
// Restore $_POST datas
|
64 |
if (count($oldpost)){ |
65 |
$_POST=$oldpost; |
66 |
} |
67 |
} else {
|
68 |
echo $default; |
69 |
} |
70 |
echo "</span>\n"; |
71 |
} |
72 |
|
73 |
/**
|
74 |
* Input text used as search system in ajax system
|
75 |
*
|
76 |
* @param $id ID of the ajax item
|
77 |
* @param $size size of the input text field
|
78 |
**/
|
79 |
function ajaxDisplaySearchTextForDropdown($id,$size=4){ |
80 |
global $CFG_GLPI; |
81 |
echo "<input type='text' ondblclick=\"window.document.getElementById('search_$id').value='".$CFG_GLPI["ajax_wildcard"]."';\" id='search_$id' name='____data_$id' size='$size'>\n"; |
82 |
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* Javascript code for update an item when a Input text item changed
|
87 |
*
|
88 |
* @param $toobserve id of the Input text to observe
|
89 |
* @param $toupdate id of the item to update
|
90 |
* @param $url Url to get datas to update the item
|
91 |
* @param $parameters Parameters to send to ajax URL
|
92 |
* @param $spinner is a spinner displayed when loading ?
|
93 |
**/
|
94 |
function ajaxUpdateItemOnInputTextEvent($toobserve,$toupdate,$url,$parameters=array(),$spinner=true){ |
95 |
ajaxUpdateItemOnEvent($toobserve,$toupdate,$url,$parameters,array("dblclick","keyup"),$spinner); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Javascript code for update an item when a select item changed
|
100 |
*
|
101 |
* @param $toobserve id of the select to observe
|
102 |
* @param $toupdate id of the item to update
|
103 |
* @param $url Url to get datas to update the item
|
104 |
* @param $parameters Parameters to send to ajax URL
|
105 |
* @param $spinner is a spinner displayed when loading ?
|
106 |
**/
|
107 |
function ajaxUpdateItemOnSelectEvent($toobserve,$toupdate,$url,$parameters=array(),$spinner=true){ |
108 |
ajaxUpdateItemOnEvent($toobserve,$toupdate,$url,$parameters,array("change"),$spinner); |
109 |
} |
110 |
|
111 |
|
112 |
/**
|
113 |
* Javascript code for update an item when another item changed
|
114 |
*
|
115 |
* @param $toobserve id of the select to observe
|
116 |
* @param $toupdate id of the item to update
|
117 |
* @param $url Url to get datas to update the item
|
118 |
* @param $parameters Parameters to send to ajax URL
|
119 |
* @param $events array of the observed events
|
120 |
* @param $spinner is a spinner displayed when loading ?
|
121 |
**/
|
122 |
function ajaxUpdateItemOnEvent($toobserve,$toupdate,$url,$parameters=array(),$events=array("change"),$spinner=true){ |
123 |
global $CFG_GLPI; |
124 |
echo "<script type='text/javascript' >\n"; |
125 |
ajaxUpdateItemOnEventJsCode($toobserve,$toupdate,$url,$parameters,$events,$spinner); |
126 |
echo "</script>\n"; |
127 |
if ($spinner){ |
128 |
echo "<span id='spinner_$toupdate' style=' position:absolute; filter:alpha(opacity=70); -moz-opacity:0.7; opacity: 0.7; display:none;'><img src=\"".$CFG_GLPI["root_doc"]."/pics/wait.png\" title='Processing....' alt='Processing....' ></span>\n"; |
129 |
} |
130 |
|
131 |
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Javascript code for update an item when another item changed (Javascript code only)
|
136 |
*
|
137 |
* @param $toobserve id of the select to observe
|
138 |
* @param $toupdate id of the item to update
|
139 |
* @param $url Url to get datas to update the item
|
140 |
* @param $parameters Parameters to send to ajax URL
|
141 |
* @param $events array of the observed events
|
142 |
* @param $spinner is a spinner displayed when loading ?
|
143 |
**/
|
144 |
function ajaxUpdateItemOnEventJsCode($toobserve,$toupdate,$url,$parameters=array(),$events=array("change"),$spinner=true){ |
145 |
global $CFG_GLPI; |
146 |
|
147 |
echo " new Form.Element.Observer('$toobserve', 1, \n"; |
148 |
echo " function(element, value) {\n"; |
149 |
ajaxUpdateItemJsCode($toupdate,$url,$parameters,$spinner,$toobserve); |
150 |
echo "});\n"; |
151 |
} |
152 |
|
153 |
|
154 |
/**
|
155 |
* Javascript code for update an item
|
156 |
*
|
157 |
* @param $toupdate id of the item to update
|
158 |
* @param $url Url to get datas to update the item
|
159 |
* @param $parameters Parameters to send to ajax URL
|
160 |
* @param $spinner is a spinner displayed when loading ?
|
161 |
* @param $toobserve id of another item used to get value in case of __VALUE__ used
|
162 |
**/
|
163 |
function ajaxUpdateItem($toupdate,$url,$parameters=array(),$spinner=true,$toobserve=""){ |
164 |
global $CFG_GLPI; |
165 |
echo "<script type='text/javascript' >\n"; |
166 |
ajaxUpdateItemJsCode($toupdate,$url,$parameters,$spinner,$toobserve); |
167 |
echo "</script>\n"; |
168 |
if ($spinner){ |
169 |
echo "<div id='spinner_$toupdate' style=' position:absolute; filter:alpha(opacity=70); -moz-opacity:0.7; opacity: 0.7; display:none;'><img src=\"".$CFG_GLPI["root_doc"]."/pics/wait.png\" title='Processing....' alt='Processing....' /></div>\n"; |
170 |
} |
171 |
} |
172 |
|
173 |
|
174 |
|
175 |
/**
|
176 |
* Javascript code for update an item (Javascript code only)
|
177 |
*
|
178 |
* @param $toupdate id of the item to update
|
179 |
* @param $url Url to get datas to update the item
|
180 |
* @param $parameters Parameters to send to ajax URL
|
181 |
* @param $spinner is a spinner displayed when loading ?
|
182 |
* @param $toobserve id of another item used to get value in case of __VALUE__ used
|
183 |
**/
|
184 |
function ajaxUpdateItemJsCode($toupdate,$url,$parameters=array(),$spinner=true,$toobserve=""){ |
185 |
global $CFG_GLPI; |
186 |
|
187 |
echo "new Ajax.Updater('$toupdate', '$url', {asynchronous:true, evalScripts:true, method:'post' "; |
188 |
if ($spinner){ |
189 |
echo " ,onComplete:function(request)\n"; |
190 |
echo " {Element.hide('spinner_$toupdate');}\n"; |
191 |
echo " ,onLoading:function(request)\n"; |
192 |
echo " {Element.show('spinner_$toupdate');}\n"; |
193 |
} |
194 |
if (count($parameters)){ |
195 |
echo ",parameters:'"; |
196 |
$first=true; |
197 |
foreach ($parameters as $key => $val){ |
198 |
if ($first){ |
199 |
$first=false; |
200 |
} else {
|
201 |
echo "&"; |
202 |
} |
203 |
|
204 |
echo $key."="; |
205 |
if ($val==="__VALUE__"){ |
206 |
echo "'+\$F('$toobserve')+'"; |
207 |
} else {
|
208 |
if (is_array($val)){ |
209 |
echo serialize($val); |
210 |
} else {
|
211 |
echo $val; |
212 |
} |
213 |
} |
214 |
|
215 |
} |
216 |
echo "'\n"; |
217 |
} |
218 |
echo "});\n"; |
219 |
|
220 |
|
221 |
} |
222 |
|
223 |
?>
|