2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * URL/hidden inputs generating.
10 * Generates text with hidden inputs.
12 * @param string $db optional database name
13 * (can also be an array of parameters)
14 * @param string $table optional table name
15 * @param int $indent indenting level
16 * @param string $skip do not generate a hidden field for this parameter
17 * (can be an array of strings)
19 * @see PMA_generate_common_url()
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
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;
46 $params['table'] = $table;
50 if (! empty($GLOBALS['server'])
51 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
53 $params['server'] = $GLOBALS['server'];
55 if (empty($_COOKIE['pma_lang']) && ! empty($GLOBALS['lang'])) {
56 $params['lang'] = $GLOBALS['lang'];
58 if (empty($_COOKIE['pma_collation_connection'])
59 && ! empty($GLOBALS['collation_connection'])
61 $params['collation_connection'] = $GLOBALS['collation_connection'];
64 $params['token'] = $_SESSION[' PMA_token '];
66 if (! is_array($skip)) {
67 if (isset($params[$skip])) {
68 unset($params[$skip]);
71 foreach ($skip as $skipping) {
72 if (isset($params[$skipping])) {
73 unset($params[$skipping]);
78 return PMA_getHiddenFields($params);
82 * create hidden form fields from array with name => value
96 * echo PMA_getHiddenFields($values);
99 * <input type="hidden" name="aaa" Value="aaa" />
100 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
101 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
102 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
103 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
106 * @param array $values hidden values
107 * @param string $pre prefix
109 * @return string form fields of type hidden
111 function PMA_getHiddenFields($values, $pre = '')
115 foreach ($values as $name => $value) {
117 $name = $pre. '[' . $name . ']';
120 if (is_array($value)) {
121 $fields .= PMA_getHiddenFields($value, $name);
123 // do not generate an ending "\n" because
124 // PMA_generate_common_hidden_inputs() is sometimes called
125 // from a JS document.write()
126 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
127 . '" value="' . htmlspecialchars($value) . '" />';
135 * Generates text with URL parameters.
138 * // OLD derepecated style
140 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
141 * // produces with cookies enabled:
142 * // script.php?db=mysql&table=rights
143 * // with cookies disabled:
144 * // script.php?server=1&lang=en&db=mysql&table=rights
147 * $params['myparam'] = 'myvalue';
148 * $params['db'] = 'mysql';
149 * $params['table'] = 'rights';
150 * // note the missing ?
151 * echo 'script.php' . PMA_generate_common_url($params);
152 * // produces with cookies enabled:
153 * // script.php?myparam=myvalue&db=mysql&table=rights
154 * // with cookies disabled:
155 * // script.php?server=1&lang=en&myparam=myvalue&db=mysql&table=rights
157 * // note the missing ?
158 * echo 'script.php' . PMA_generate_common_url();
159 * // produces with cookies enabled:
161 * // with cookies disabled:
162 * // script.php?server=1&lang=en
165 * @param mixed assoc. array with url params or optional string with database name
166 * if first param is an array there is also an ? prefixed to the url
168 * @param string - if first param is array: 'html' to use htmlspecialchars()
169 * on the resulting URL (for a normal URL displayed in HTML)
170 * or something else to avoid using htmlspecialchars() (for
171 * a URL sent via a header); if not set,'html' is assumed
172 * - if first param is not array: optional table name
174 * @param string - if first param is array: optional character to
176 * - if first param is not array: optional character to use
177 * instead of '&' for dividing URL parameters
179 * @return string string with URL parameters
182 function PMA_generate_common_url()
184 $args = func_get_args();
186 if (isset($args[0]) && is_array($args[0])) {
190 if (isset($args[1])) {
196 if (isset($args[2])) {
197 $questionmark = $args[2];
204 if (PMA_isValid($args[0])) {
205 $params['db'] = $args[0];
208 if (PMA_isValid($args[1])) {
209 $params['table'] = $args[1];
212 if (isset($args[2]) && $args[2] !== '&') {
221 $separator = PMA_get_arg_separator();
223 if (isset($GLOBALS['server'])
224 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
225 // avoid overwriting when creating navi panel links to servers
226 && ! isset($params['server'])
228 $params['server'] = $GLOBALS['server'];
231 if (empty($_COOKIE['pma_lang']) && ! empty($GLOBALS['lang'])) {
232 $params['lang'] = $GLOBALS['lang'];
234 if (empty($_COOKIE['pma_collation_connection'])
235 && ! empty($GLOBALS['collation_connection'])
237 $params['collation_connection'] = $GLOBALS['collation_connection'];
240 if (isset($_SESSION[' PMA_token '])) {
241 $params['token'] = $_SESSION[' PMA_token '];
244 if (empty($params)) {
248 $query = $questionmark . http_build_query($params, null, $separator);
250 if ($encode === 'html') {
251 $query = htmlspecialchars($query);
258 * Returns url separator
260 * extracted from arg_separator.input as set in php.ini
261 * we do not use arg_separator.output to avoid problems with & and &
263 * @param string $encode whether to encode separator or not,
264 * currently 'none' or 'html'
266 * @return string character used for separating url parts usally ; or &
269 function PMA_get_arg_separator($encode = 'none')
271 static $separator = null;
273 if (null === $separator) {
274 // use seperators defined by php, but prefer ';'
275 // as recommended by W3C
276 $php_arg_separator_input = ini_get('arg_separator.input');
277 if (strpos($php_arg_separator_input, ';') !== false) {
279 } elseif (strlen($php_arg_separator_input) > 0) {
280 $separator = $php_arg_separator_input{0};
288 return htmlentities($separator);