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
187 * @param string - if first param is array: 'html' to use htmlspecialchars()
188 * on the resulting URL (for a normal URL displayed in HTML)
189 * or something else to avoid using htmlspecialchars() (for
190 * a URL sent via a header); if not set,'html' is assumed
191 * - if first param is not array: optional table name
193 * @param string - if first param is array: optional character to
195 * - if first param is not array: optional character to use
196 * instead of '&' for dividing URL parameters
197 * @return string string with URL parameters
201 function PMA_generate_common_url()
203 $args = func_get_args();
205 if (isset($args[0]) && is_array($args[0])) {
209 if (isset($args[1])) {
215 if (isset($args[2])) {
216 $questionmark = $args[2];
223 if (PMA_isValid($args[0])) {
224 $params['db'] = $args[0];
227 if (PMA_isValid($args[1])) {
228 $params['table'] = $args[1];
231 if (isset($args[2]) && $args[2] !== '&') {
240 $separator = PMA_get_arg_separator();
242 if (isset($GLOBALS['server'])
243 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
244 // avoid overwriting when creating navi panel links to servers
245 && ! isset($params['server'])) {
246 $params['server'] = $GLOBALS['server'];
249 if (empty($_COOKIE['pma_lang'])
250 && ! empty($GLOBALS['lang'])) {
251 $params['lang'] = $GLOBALS['lang'];
253 if (empty($_COOKIE['pma_charset'])
254 && ! empty($GLOBALS['convcharset'])) {
255 $params['convcharset'] = $GLOBALS['convcharset'];
257 if (empty($_COOKIE['pma_collation_connection'])
258 && ! empty($GLOBALS['collation_connection'])) {
259 $params['collation_connection'] = $GLOBALS['collation_connection'];
262 if (isset($_SESSION[' PMA_token '])) {
263 $params['token'] = $_SESSION[' PMA_token '];
266 if (empty($params)) {
270 $query = $questionmark . http_build_query($params, null, $separator);
272 if ($encode === 'html') {
273 $query = htmlspecialchars($query);
280 * Returns url separator
282 * extracted from arg_separator.input as set in php.ini
283 * we do not use arg_separator.output to avoid problems with & and &
288 * @param string whether to encode separator or not, currently 'none' or 'html'
289 * @return string character used for separating url parts usally ; or &
293 function PMA_get_arg_separator($encode = 'none')
295 static $separator = null;
297 if (null === $separator) {
298 // use seperators defined by php, but prefer ';'
299 // as recommended by W3C
300 $php_arg_separator_input = ini_get('arg_separator.input');
301 if (strpos($php_arg_separator_input, ';') !== false) {
303 } elseif (strlen($php_arg_separator_input) > 0) {
304 $separator = $php_arg_separator_input{0};
312 return htmlentities($separator);