2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * URL/hidden inputs generating.
11 * Generates text with hidden inputs.
13 * @see PMA_generate_common_url()
14 * @uses PMA_getHiddenFields
15 * @param string optional database name
16 * (can also be an array of parameters)
17 * @param string optional table name
18 * @param int indenting level
19 * @param string do not generate a hidden field for this parameter
20 * (can be an array of strings)
22 * @return string string with input fields
24 * @global string the current language
25 * @global string the current conversion charset
26 * @global string the current connection collation
27 * @global string the current server
28 * @global array the configuration array
29 * @global boolean whether recoding is allowed or not
35 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
39 $_indent = empty($table) ?
$indent : $table;
40 $_skip = empty($indent) ?
$skip : $indent;
49 $params['table'] = $table;
53 if (! empty($GLOBALS['server'])
54 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
55 $params['server'] = $GLOBALS['server'];
57 if (empty($_COOKIE['pma_lang'])
58 && ! empty($GLOBALS['lang'])) {
59 $params['lang'] = $GLOBALS['lang'];
61 if (empty($_COOKIE['pma_charset'])
62 && ! empty($GLOBALS['convcharset'])) {
63 $params['convcharset'] = $GLOBALS['convcharset'];
65 if (empty($_COOKIE['pma_collation_connection'])
66 && ! empty($GLOBALS['collation_connection'])) {
67 $params['collation_connection'] = $GLOBALS['collation_connection'];
70 $params['token'] = $_SESSION[' PMA_token '];
72 if (! is_array($skip)) {
73 if (isset($params[$skip])) {
74 unset($params[$skip]);
77 foreach ($skip as $skipping) {
78 if (isset($params[$skipping])) {
79 unset($params[$skipping]);
84 return PMA_getHiddenFields($params);
88 * create hidden form fields from array with name => value
102 * echo PMA_getHiddenFields($values);
105 * <input type="hidden" name="aaa" Value="aaa" />
106 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
107 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
108 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
109 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
112 * @param array $values
114 * @return string form fields of type hidden
116 function PMA_getHiddenFields($values, $pre = '')
120 foreach ($values as $name => $value) {
122 $name = $pre. '[' . $name . ']';
125 if (is_array($value)) {
126 $fields .= PMA_getHiddenFields($value, $name);
128 // do not generate an ending "\n" because
129 // PMA_generate_common_hidden_inputs() is sometimes called
130 // from a JS document.write()
131 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
132 . '" value="' . htmlspecialchars($value) . '" />';
140 * Generates text with URL parameters.
143 * // OLD derepecated style
145 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
146 * // produces with cookies enabled:
147 * // script.php?db=mysql&table=rights
148 * // with cookies disabled:
149 * // script.php?server=1&lang=en-utf-8&db=mysql&table=rights
152 * $params['myparam'] = 'myvalue';
153 * $params['db'] = 'mysql';
154 * $params['table'] = 'rights';
155 * // note the missing ?
156 * echo 'script.php' . PMA_generate_common_url($params);
157 * // produces with cookies enabled:
158 * // script.php?myparam=myvalue&db=mysql&table=rights
159 * // with cookies disabled:
160 * // script.php?server=1&lang=en-utf-8&myparam=myvalue&db=mysql&table=rights
162 * // note the missing ?
163 * echo 'script.php' . PMA_generate_common_url();
164 * // produces with cookies enabled:
166 * // with cookies disabled:
167 * // script.php?server=1&lang=en-utf-8
170 * @uses $GLOBALS['server']
171 * @uses $GLOBALS['cfg']['ServerDefault']
172 * @uses $_COOKIE['pma_lang']
173 * @uses $GLOBALS['lang']
174 * @uses $_COOKIE['pma_charset']
175 * @uses $GLOBALS['convcharset']
176 * @uses $_COOKIE['pma_collation_connection']
177 * @uses $GLOBALS['collation_connection']
178 * @uses $_SESSION[' PMA_token ']
179 * @uses PMA_get_arg_separator()
182 * @uses htmlentities()
185 * @param mixed assoc. array with url params or optional string with database name
186 * if first param is an array there is also an ? prefixed to the url
188 * @param string - if first param is array: 'html' to use htmlspecialchars()
189 * on the resulting URL (for a normal URL displayed in HTML)
190 * or something else to avoid using htmlspecialchars() (for
191 * a URL sent via a header); if not set,'html' is assumed
192 * - if first param is not array: optional table name
194 * @param string - if first param is array: optional character to
196 * - if first param is not array: optional character to use
197 * instead of '&' for dividing URL parameters
198 * @return string string with URL parameters
202 function PMA_generate_common_url()
204 $args = func_get_args();
206 if (isset($args[0]) && is_array($args[0])) {
210 if (isset($args[1])) {
216 if (isset($args[2])) {
217 $questionmark = $args[2];
224 if (PMA_isValid($args[0])) {
225 $params['db'] = $args[0];
228 if (PMA_isValid($args[1])) {
229 $params['table'] = $args[1];
232 if (isset($args[2]) && $args[2] !== '&') {
241 $separator = PMA_get_arg_separator();
243 if (isset($GLOBALS['server'])
244 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
245 // avoid overwriting when creating navi panel links to servers
246 && ! isset($params['server'])) {
247 $params['server'] = $GLOBALS['server'];
250 if (empty($_COOKIE['pma_lang'])
251 && ! empty($GLOBALS['lang'])) {
252 $params['lang'] = $GLOBALS['lang'];
254 if (empty($_COOKIE['pma_charset'])
255 && ! empty($GLOBALS['convcharset'])) {
256 $params['convcharset'] = $GLOBALS['convcharset'];
258 if (empty($_COOKIE['pma_collation_connection'])
259 && ! empty($GLOBALS['collation_connection'])) {
260 $params['collation_connection'] = $GLOBALS['collation_connection'];
263 if (isset($_SESSION[' PMA_token '])) {
264 $params['token'] = $_SESSION[' PMA_token '];
267 if (empty($params)) {
271 $query = $questionmark . http_build_query($params, null, $separator);
273 if ($encode === 'html') {
274 $query = htmlspecialchars($query);
281 * Returns url separator
283 * extracted from arg_separator.input as set in php.ini
284 * we do not use arg_separator.output to avoid problems with & and &
289 * @param string whether to encode separator or not, currently 'none' or 'html'
290 * @return string character used for separating url parts usally ; or &
294 function PMA_get_arg_separator($encode = 'none')
296 static $separator = null;
298 if (null === $separator) {
299 // use seperators defined by php, but prefer ';'
300 // as recommended by W3C
301 $php_arg_separator_input = ini_get('arg_separator.input');
302 if (strpos($php_arg_separator_input, ';') !== false) {
304 } elseif (strlen($php_arg_separator_input) > 0) {
305 $separator = $php_arg_separator_input{0};
313 return htmlentities($separator);