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 * (can also be an array of parameters)
15 * @param string optional table name
16 * @param int indenting level
17 * @param string do not generate a hidden field for this parameter
18 * (can be an array of strings)
20 * @return string string with input fields
22 * @global string the current language
23 * @global string the current conversion charset
24 * @global string the current connection collation
25 * @global string the current server
26 * @global array the configuration array
27 * @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']) {
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_collation_connection'])
59 && ! empty($GLOBALS['collation_connection'])) {
60 $params['collation_connection'] = $GLOBALS['collation_connection'];
63 $params['token'] = $_SESSION[' PMA_token '];
65 if (! is_array($skip)) {
66 if (isset($params[$skip])) {
67 unset($params[$skip]);
70 foreach ($skip as $skipping) {
71 if (isset($params[$skipping])) {
72 unset($params[$skipping]);
77 return PMA_getHiddenFields($params);
81 * create hidden form fields from array with name => value
95 * echo PMA_getHiddenFields($values);
98 * <input type="hidden" name="aaa" Value="aaa" />
99 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
100 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
101 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
102 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
105 * @param array $values
107 * @return string form fields of type hidden
109 function PMA_getHiddenFields($values, $pre = '')
113 foreach ($values as $name => $value) {
115 $name = $pre. '[' . $name . ']';
118 if (is_array($value)) {
119 $fields .= PMA_getHiddenFields($value, $name);
121 // do not generate an ending "\n" because
122 // PMA_generate_common_hidden_inputs() is sometimes called
123 // from a JS document.write()
124 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
125 . '" value="' . htmlspecialchars($value) . '" />';
133 * Generates text with URL parameters.
136 * // OLD derepecated style
138 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
139 * // produces with cookies enabled:
140 * // script.php?db=mysql&table=rights
141 * // with cookies disabled:
142 * // script.php?server=1&lang=en&db=mysql&table=rights
145 * $params['myparam'] = 'myvalue';
146 * $params['db'] = 'mysql';
147 * $params['table'] = 'rights';
148 * // note the missing ?
149 * echo 'script.php' . PMA_generate_common_url($params);
150 * // produces with cookies enabled:
151 * // script.php?myparam=myvalue&db=mysql&table=rights
152 * // with cookies disabled:
153 * // script.php?server=1&lang=en&myparam=myvalue&db=mysql&table=rights
155 * // note the missing ?
156 * echo 'script.php' . PMA_generate_common_url();
157 * // produces with cookies enabled:
159 * // with cookies disabled:
160 * // script.php?server=1&lang=en
163 * @param mixed assoc. array with url params or optional string with database name
164 * if first param is an array there is also an ? prefixed to the url
166 * @param string - if first param is array: 'html' to use htmlspecialchars()
167 * on the resulting URL (for a normal URL displayed in HTML)
168 * or something else to avoid using htmlspecialchars() (for
169 * a URL sent via a header); if not set,'html' is assumed
170 * - if first param is not array: optional table name
172 * @param string - if first param is array: optional character to
174 * - if first param is not array: optional character to use
175 * instead of '&' for dividing URL parameters
176 * @return string string with URL parameters
179 function PMA_generate_common_url()
181 $args = func_get_args();
183 if (isset($args[0]) && is_array($args[0])) {
187 if (isset($args[1])) {
193 if (isset($args[2])) {
194 $questionmark = $args[2];
201 if (PMA_isValid($args[0])) {
202 $params['db'] = $args[0];
205 if (PMA_isValid($args[1])) {
206 $params['table'] = $args[1];
209 if (isset($args[2]) && $args[2] !== '&') {
218 $separator = PMA_get_arg_separator();
220 if (isset($GLOBALS['server'])
221 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
222 // avoid overwriting when creating navi panel links to servers
223 && ! isset($params['server'])) {
224 $params['server'] = $GLOBALS['server'];
227 if (empty($_COOKIE['pma_lang'])
228 && ! empty($GLOBALS['lang'])) {
229 $params['lang'] = $GLOBALS['lang'];
231 if (empty($_COOKIE['pma_collation_connection'])
232 && ! empty($GLOBALS['collation_connection'])) {
233 $params['collation_connection'] = $GLOBALS['collation_connection'];
236 if (isset($_SESSION[' PMA_token '])) {
237 $params['token'] = $_SESSION[' PMA_token '];
240 if (empty($params)) {
244 $query = $questionmark . http_build_query($params, null, $separator);
246 if ($encode === 'html') {
247 $query = htmlspecialchars($query);
254 * Returns url separator
256 * extracted from arg_separator.input as set in php.ini
257 * we do not use arg_separator.output to avoid problems with & and &
259 * @param string whether to encode separator or not, currently 'none' or 'html'
260 * @return string character used for separating url parts usally ; or &
263 function PMA_get_arg_separator($encode = 'none')
265 static $separator = null;
267 if (null === $separator) {
268 // use seperators defined by php, but prefer ';'
269 // as recommended by W3C
270 $php_arg_separator_input = ini_get('arg_separator.input');
271 if (strpos($php_arg_separator_input, ';') !== false) {
273 } elseif (strlen($php_arg_separator_input) > 0) {
274 $separator = $php_arg_separator_input{0};
282 return htmlentities($separator);