2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * URL/hidden inputs generating.
10 * Generates text with hidden inputs.
12 * @see PMA_generate_common_url()
13 * @uses PMA_getHiddenFields
14 * @param string optional database name
15 * (can also be an array of parameters)
16 * @param string optional table name
17 * @param int indenting level
18 * @param string do not generate a hidden field for this parameter
19 * (can be an array of strings)
21 * @return string string with input fields
23 * @global string the current language
24 * @global string the current conversion charset
25 * @global string the current connection collation
26 * @global string the current server
27 * @global array the configuration array
28 * @global boolean whether recoding is allowed or not
34 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
38 $_indent = empty($table) ?
$indent : $table;
39 $_skip = empty($indent) ?
$skip : $indent;
48 $params['table'] = $table;
52 if (! empty($GLOBALS['server'])
53 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
54 $params['server'] = $GLOBALS['server'];
56 if (empty($_COOKIE['pma_lang'])
57 && ! empty($GLOBALS['lang'])) {
58 $params['lang'] = $GLOBALS['lang'];
60 if (empty($_COOKIE['pma_charset'])
61 && ! empty($GLOBALS['convcharset'])) {
62 $params['convcharset'] = $GLOBALS['convcharset'];
64 if (empty($_COOKIE['pma_collation_connection'])
65 && ! empty($GLOBALS['collation_connection'])) {
66 $params['collation_connection'] = $GLOBALS['collation_connection'];
69 $params['token'] = $_SESSION[' PMA_token '];
71 if (! is_array($skip)) {
72 if (isset($params[$skip])) {
73 unset($params[$skip]);
76 foreach ($skip as $skipping) {
77 if (isset($params[$skipping])) {
78 unset($params[$skipping]);
83 return PMA_getHiddenFields($params);
87 * create hidden form fields from array with name => value
101 * echo PMA_getHiddenFields($values);
104 * <input type="hidden" name="aaa" Value="aaa" />
105 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
106 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
107 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
108 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
111 * @param array $values
113 * @return string form fields of type hidden
115 function PMA_getHiddenFields($values, $pre = '')
119 foreach ($values as $name => $value) {
121 $name = $pre. '[' . $name . ']';
124 if (is_array($value)) {
125 $fields .= PMA_getHiddenFields($value, $name);
127 // do not generate an ending "\n" because
128 // PMA_generate_common_hidden_inputs() is sometimes called
129 // from a JS document.write()
130 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
131 . '" value="' . htmlspecialchars($value) . '" />';
139 * Generates text with URL parameters.
142 * // OLD derepecated style
144 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
145 * // produces with cookies enabled:
146 * // script.php?db=mysql&table=rights
147 * // with cookies disabled:
148 * // script.php?server=1&lang=en-utf-8&db=mysql&table=rights
151 * $params['myparam'] = 'myvalue';
152 * $params['db'] = 'mysql';
153 * $params['table'] = 'rights';
154 * // note the missing ?
155 * echo 'script.php' . PMA_generate_common_url($params);
156 * // produces with cookies enabled:
157 * // script.php?myparam=myvalue&db=mysql&table=rights
158 * // with cookies disabled:
159 * // script.php?server=1&lang=en-utf-8&myparam=myvalue&db=mysql&table=rights
161 * // note the missing ?
162 * echo 'script.php' . PMA_generate_common_url();
163 * // produces with cookies enabled:
165 * // with cookies disabled:
166 * // script.php?server=1&lang=en-utf-8
169 * @uses $GLOBALS['server']
170 * @uses $GLOBALS['cfg']['ServerDefault']
171 * @uses $_COOKIE['pma_lang']
172 * @uses $GLOBALS['lang']
173 * @uses $_COOKIE['pma_charset']
174 * @uses $GLOBALS['convcharset']
175 * @uses $_COOKIE['pma_collation_connection']
176 * @uses $GLOBALS['collation_connection']
177 * @uses $_SESSION[' PMA_token ']
178 * @uses PMA_get_arg_separator()
181 * @uses htmlentities()
184 * @param mixed assoc. array with url params or optional string with database name
185 * if first param is an array there is also an ? prefixed to the url
186 * @param string optional table name only if first param is array
187 * @param string character to use instead of '&' for deviding
188 * multiple URL parameters from each other
189 * @return string string with URL parameters
193 function PMA_generate_common_url()
195 $args = func_get_args();
197 if (isset($args[0]) && is_array($args[0])) {
201 if (isset($args[1])) {
207 if (isset($args[2])) {
208 $questionmark = $args[2];
215 if (PMA_isValid($args[0])) {
216 $params['db'] = $args[0];
219 if (PMA_isValid($args[1])) {
220 $params['table'] = $args[1];
223 if (isset($args[2]) && $args[2] !== '&') {
232 $separator = PMA_get_arg_separator();
234 if (isset($GLOBALS['server'])
235 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
236 $params['server'] = $GLOBALS['server'];
239 if (empty($_COOKIE['pma_lang'])
240 && ! empty($GLOBALS['lang'])) {
241 $params['lang'] = $GLOBALS['lang'];
243 if (empty($_COOKIE['pma_charset'])
244 && ! empty($GLOBALS['convcharset'])) {
245 $params['convcharset'] = $GLOBALS['convcharset'];
247 if (empty($_COOKIE['pma_collation_connection'])
248 && ! empty($GLOBALS['collation_connection'])) {
249 $params['collation_connection'] = $GLOBALS['collation_connection'];
252 if (isset($_SESSION[' PMA_token '])) {
253 $params['token'] = $_SESSION[' PMA_token '];
256 if (empty($params)) {
260 $query = $questionmark . http_build_query($params, null, $separator);
262 if ($encode === 'html') {
263 $query = htmlspecialchars($query);
270 * Returns url separator
272 * extracted from arg_separator.input as set in php.ini
273 * we do not use arg_separator.output to avoid problems with & and &
278 * @param string whether to encode separator or not, currently 'none' or 'html'
279 * @return string character used for separating url parts usally ; or &
283 function PMA_get_arg_separator($encode = 'none')
285 static $separator = null;
287 if (null === $separator) {
288 // use seperators defined by php, but prefer ';'
289 // as recommended by W3C
290 $php_arg_separator_input = ini_get('arg_separator.input');
291 if (strpos($php_arg_separator_input, ';') !== false) {
293 } elseif (strlen($php_arg_separator_input) > 0) {
294 $separator = $php_arg_separator_input{0};
302 return htmlentities($separator);