2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * URL/hidden inputs generating.
8 if (! defined('PHPMYADMIN')) {
13 * Generates text with hidden inputs.
15 * @param string $db optional database name
16 * (can also be an array of parameters)
17 * @param string $table optional table name
18 * @param int $indent indenting level
19 * @param string $skip do not generate a hidden field for this parameter
20 * (can be an array of strings)
22 * @see PMA_generate_common_url()
24 * @return string string with input fields
26 * @global string the current language
27 * @global string the current conversion charset
28 * @global string the current connection collation
29 * @global string the current server
30 * @global array the configuration array
31 * @global boolean whether recoding is allowed or not
35 function PMA_generate_common_hidden_inputs($db = '', $table = '',
36 $indent = 0, $skip = array()
40 $_indent = empty($table) ?
$indent : $table;
41 $_skip = empty($indent) ?
$skip : $indent;
50 $params['table'] = $table;
54 if (! empty($GLOBALS['server'])
55 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
57 $params['server'] = $GLOBALS['server'];
59 if (empty($_COOKIE['pma_lang']) && ! empty($GLOBALS['lang'])) {
60 $params['lang'] = $GLOBALS['lang'];
62 if (empty($_COOKIE['pma_collation_connection'])
63 && ! empty($GLOBALS['collation_connection'])
65 $params['collation_connection'] = $GLOBALS['collation_connection'];
68 $params['token'] = $_SESSION[' PMA_token '];
70 if (! is_array($skip)) {
71 if (isset($params[$skip])) {
72 unset($params[$skip]);
75 foreach ($skip as $skipping) {
76 if (isset($params[$skipping])) {
77 unset($params[$skipping]);
82 return PMA_getHiddenFields($params);
86 * create hidden form fields from array with name => value
100 * echo PMA_getHiddenFields($values);
103 * <input type="hidden" name="aaa" Value="aaa" />
104 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
105 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
106 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
107 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
110 * @param array $values hidden values
111 * @param string $pre prefix
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 (deprecated) 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&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&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
169 * @param mixed assoc. array with url params or optional string with database name
170 * if first param is an array there is also an ? prefixed to the url
172 * @param string - if first param is array: 'html' to use htmlspecialchars()
173 * on the resulting URL (for a normal URL displayed in HTML)
174 * or something else to avoid using htmlspecialchars() (for
175 * a URL sent via a header); if not set,'html' is assumed
176 * - if first param is not array: optional table name
178 * @param string - if first param is array: optional character to
180 * - if first param is not array: optional character to use
181 * instead of '&' for dividing URL parameters
183 * @return string string with URL parameters
186 function PMA_generate_common_url()
188 $args = func_get_args();
190 if (isset($args[0]) && is_array($args[0])) {
194 if (isset($args[1])) {
200 if (isset($args[2])) {
201 $questionmark = $args[2];
208 if (PMA_isValid($args[0])) {
209 $params['db'] = $args[0];
212 if (PMA_isValid($args[1])) {
213 $params['table'] = $args[1];
216 if (isset($args[2]) && $args[2] !== '&') {
225 $separator = PMA_get_arg_separator();
227 // avoid overwriting when creating navi panel links to servers
228 if (isset($GLOBALS['server'])
229 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
230 && ! isset($params['server'])
232 $params['server'] = $GLOBALS['server'];
235 if (empty($_COOKIE['pma_lang']) && ! empty($GLOBALS['lang'])) {
236 $params['lang'] = $GLOBALS['lang'];
238 if (empty($_COOKIE['pma_collation_connection'])
239 && ! empty($GLOBALS['collation_connection'])
241 $params['collation_connection'] = $GLOBALS['collation_connection'];
244 if (isset($_SESSION[' PMA_token '])) {
245 $params['token'] = $_SESSION[' PMA_token '];
248 if (empty($params)) {
252 $query = $questionmark . http_build_query($params, null, $separator);
254 if ($encode === 'html') {
255 $query = htmlspecialchars($query);
262 * Returns url separator
264 * extracted from arg_separator.input as set in php.ini
265 * we do not use arg_separator.output to avoid problems with & and &
267 * @param string $encode whether to encode separator or not,
268 * currently 'none' or 'html'
270 * @return string character used for separating url parts usally ; or &
273 function PMA_get_arg_separator($encode = 'none')
275 static $separator = null;
277 if (null === $separator) {
278 // use separators defined by php, but prefer ';'
279 // as recommended by W3C
280 // (see http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2)
281 $php_arg_separator_input = ini_get('arg_separator.input');
282 if (strpos($php_arg_separator_input, ';') !== false) {
284 } elseif (strlen($php_arg_separator_input) > 0) {
285 $separator = $php_arg_separator_input{0};
293 return htmlentities($separator);