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 * @param string optional database name
14 * @param string optional table name
15 * @param int indenting level
17 * @return string string with input fields
19 * @global string the current language
20 * @global string the current conversion charset
21 * @global string the current connection collation
22 * @global string the current server
23 * @global array the configuration array
24 * @global boolean whether recoding is allowed or not
30 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
34 $_indent = empty($table) ?
$indent : $table;
35 $_skip = empty($indent) ?
$skip : $indent;
44 $params['table'] = $table;
48 if (! empty($GLOBALS['server'])
49 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
50 $params['server'] = $GLOBALS['server'];
52 if (empty($_COOKIE['pma_lang'])
53 && ! empty($GLOBALS['lang'])) {
54 $params['lang'] = $GLOBALS['lang'];
56 if (empty($_COOKIE['pma_charset'])
57 && ! empty($GLOBALS['convcharset'])) {
58 $params['convcharset'] = $GLOBALS['convcharset'];
60 if (empty($_COOKIE['pma_collation_connection'])
61 && ! empty($GLOBALS['collation_connection'])) {
62 $params['collation_connection'] = $GLOBALS['collation_connection'];
65 $params['token'] = $_SESSION[' PMA_token '];
67 if (! is_array($skip)) {
68 if (isset($params[$skip])) {
69 unset($params[$skip]);
72 foreach ($skip as $skipping) {
73 if (isset($params[$skipping])) {
74 unset($params[$skipping]);
79 $spaces = str_repeat(' ', $indent);
82 foreach ($params as $key => $val) {
83 $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />' . "\n";
90 * Generates text with URL parameters.
94 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
95 * // produces with cookies enabled:
96 * // script.php?db=mysql&table=rights
97 * // with cookies disabled:
98 * // script.php?server=1&lang=en-utf-8&db=mysql&table=rights
100 * $params['myparam'] = 'myvalue';
101 * $params['db'] = 'mysql';
102 * $params['table'] = 'rights';
103 * // note the missing ?
104 * echo 'script.php' . PMA_generate_common_url($params);
105 * // produces with cookies enabled:
106 * // script.php?myparam=myvalue&db=mysql&table=rights
107 * // with cookies disabled:
108 * // script.php?server=1&lang=en-utf-8&myparam=myvalue&db=mysql&table=rights
110 * // note the missing ?
111 * echo 'script.php' . PMA_generate_common_url();
112 * // produces with cookies enabled:
114 * // with cookies disabled:
115 * // script.php?server=1&lang=en-utf-8
118 * @param mixed assoc. array with url params or optional string with database name
119 * if first param is an array there is also an ? prefixed to the url
120 * @param string optional table name only if first param is array
121 * @param string character to use instead of '&' for deviding
122 * multiple URL parameters from each other
124 * @return string string with URL parameters
126 * @global string the current language
127 * @global string the current conversion charset
128 * @global string the current connection collation
129 * @global string the current server
130 * @global array the configuration array
131 * @global boolean whether recoding is allowed or not
137 function PMA_generate_common_url ($db = '', $table = '', $delim = '&')
141 $delim = empty($table) ?
$delim : $table;
148 if (strlen($table)) {
149 $params['table'] = $table;
154 // use seperators defined by php, but prefer ';'
155 // as recommended by W3C
156 $separator = PMA_get_arg_separator();
158 // check wether to htmlentity the separator or not
159 if ($delim === '&') {
160 $delim = htmlentities($separator);
165 if (isset($GLOBALS['server'])
166 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
167 $params['server'] = $GLOBALS['server'];
170 if (empty($_COOKIE['pma_lang'])
171 && ! empty($GLOBALS['lang'])) {
172 $params['lang'] = $GLOBALS['lang'];
174 if (empty($_COOKIE['pma_charset'])
175 && ! empty($GLOBALS['convcharset'])) {
176 $params['convcharset'] = $GLOBALS['convcharset'];
178 if (empty($_COOKIE['pma_collation_connection'])
179 && ! empty($GLOBALS['collation_connection'])) {
180 $params['collation_connection'] = $GLOBALS['collation_connection'];
183 $params['token'] = $_SESSION[' PMA_token '];
185 $param_strings = array();
186 foreach ($params as $key => $val) {
187 /* We ignore arrays as we don't use them! */
188 if (!is_array($val)) {
189 $param_strings[] = urlencode($key) . '=' . urlencode($val);
193 if (empty($param_strings)) {
197 return $questionmark . implode($delim, $param_strings);
201 * Returns url separator
203 * @return string character used for separating url parts
209 function PMA_get_arg_separator() {
210 // use seperators defined by php, but prefer ';'
211 // as recommended by W3C
212 $php_arg_separator_input = ini_get('arg_separator.input');
213 if (strpos($php_arg_separator_input, ';') !== false) {
215 } elseif (strlen($php_arg_separator_input) > 0) {
216 return $php_arg_separator_input{0};