3 // vim: expandtab sw=4 ts=4 sts=4:
7 * URL/hidden inputs generating.
12 * Generates text with hidden inputs.
14 * @see PMA_generate_common_url()
15 * @param string optional database name
16 * @param string optional table name
17 * @param int indenting level
19 * @return string string with input fields
21 * @global string the current language
22 * @global string the current conversion charset
23 * @global string the current connection collation
24 * @global string the current server
25 * @global array the configuration array
26 * @global boolean whether recoding is allowed or not
32 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
36 $_indent = empty($table) ?
$indent : $table;
37 $_skip = empty($indent) ?
$skip : $indent;
42 if (isset($db) && strlen($db)) {
45 if (isset($table) && strlen($table)) {
46 $params['table'] = $table;
50 if (! empty($GLOBALS['server'])
51 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
52 $params['server'] = $GLOBALS['server'];
54 if (empty($_COOKIE['pma_lang'])
55 && ! empty($GLOBALS['lang'])) {
56 $params['lang'] = $GLOBALS['lang'];
58 if (empty($_COOKIE['pma_charset'])
59 && ! empty($GLOBALS['convcharset'])) {
60 $params['convcharset'] = $GLOBALS['convcharset'];
62 if (empty($_COOKIE['pma_collation_connection'])
63 && ! empty($GLOBALS['collation_connection'])) {
64 $params['collation_connection'] = $GLOBALS['collation_connection'];
67 $params['token'] = $_SESSION[' PMA_token '];
69 if (! is_array($skip)) {
70 if (isset($params[$skip])) {
71 unset($params[$skip]);
74 foreach ($skip as $skipping) {
75 if (isset($params[$skipping])) {
76 unset($params[$skipping]);
81 $spaces = str_repeat(' ', $indent);
84 foreach ($params as $key => $val) {
85 $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />' . "\n";
92 * Generates text with URL parameters.
96 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
97 * // produces with cookies enabled:
98 * // script.php?db=mysql&table=rights
99 * // with cookies disabled:
100 * // script.php?server=1&lang=en-utf-8&db=mysql&table=rights
102 * $params['myparam'] = 'myvalue';
103 * $params['db'] = 'mysql';
104 * $params['table'] = 'rights';
105 * // note the missing ?
106 * echo 'script.php' . PMA_generate_common_url($params);
107 * // produces with cookies enabled:
108 * // script.php?myparam=myvalue&db=mysql&table=rights
109 * // with cookies disabled:
110 * // script.php?server=1&lang=en-utf-8&myparam=myvalue&db=mysql&table=rights
112 * // note the missing ?
113 * echo 'script.php' . PMA_generate_common_url();
114 * // produces with cookies enabled:
116 * // with cookies disabled:
117 * // script.php?server=1&lang=en-utf-8
120 * @param mixed assoc. array with url params or optional string with database name
121 * if first param is an array there is also an ? prefixed to the url
122 * @param string optional table name only if first param is array
123 * @param string character to use instead of '&' for deviding
124 * multiple URL parameters from each other
126 * @return string string with URL parameters
128 * @global string the current language
129 * @global string the current conversion charset
130 * @global string the current connection collation
131 * @global string the current server
132 * @global array the configuration array
133 * @global boolean whether recoding is allowed or not
139 function PMA_generate_common_url ($db = '', $table = '', $delim = '&')
143 $delim = empty($table) ?
$delim : $table;
147 if (isset($db) && strlen($db)) {
150 if (isset($table) && strlen($table)) {
151 $params['table'] = $table;
156 // use seperators defined by php, but prefer ';'
157 // as recommended by W3C
158 $separator = PMA_get_arg_separator();
160 // check wether to htmlentity the separator or not
161 if ($delim === '&') {
162 $delim = htmlentities($separator);
167 if (isset($GLOBALS['server'])
168 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
169 $params['server'] = $GLOBALS['server'];
172 if (empty($_COOKIE['pma_lang'])
173 && ! empty($GLOBALS['lang'])) {
174 $params['lang'] = $GLOBALS['lang'];
176 if (empty($_COOKIE['pma_charset'])
177 && ! empty($GLOBALS['convcharset'])) {
178 $params['convcharset'] = $GLOBALS['convcharset'];
180 if (empty($_COOKIE['pma_collation_connection'])
181 && ! empty($GLOBALS['collation_connection'])) {
182 $params['collation_connection'] = $GLOBALS['collation_connection'];
185 $params['token'] = $_SESSION[' PMA_token '];
187 $param_strings = array();
188 foreach ($params as $key => $val) {
189 /* We ignore arrays as we don't use them! */
190 if (!is_array($val)) {
191 $param_strings[] = urlencode($key) . '=' . urlencode($val);
195 if (empty($param_strings)) {
199 return $questionmark . implode($delim, $param_strings);
203 * Returns url separator
205 * @return string character used for separating url parts
211 function PMA_get_arg_separator() {
212 // use seperators defined by php, but prefer ';'
213 // as recommended by W3C
214 $php_arg_separator_input = ini_get('arg_separator.input');
215 if (strpos($php_arg_separator_input, ';') !== false) {
217 } elseif (strlen($php_arg_separator_input) > 0) {
218 return $php_arg_separator_input{0};