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
33 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
37 $_indent = empty($table) ?
$indent : $table;
38 $_skip = empty($indent) ?
$skip : $indent;
47 $params['table'] = $table;
51 if (! empty($GLOBALS['server'])
52 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
53 $params['server'] = $GLOBALS['server'];
55 if (empty($_COOKIE['pma_lang'])
56 && ! empty($GLOBALS['lang'])) {
57 $params['lang'] = $GLOBALS['lang'];
59 if (empty($_COOKIE['pma_collation_connection'])
60 && ! 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
108 * @return string form fields of type hidden
110 function PMA_getHiddenFields($values, $pre = '')
114 foreach ($values as $name => $value) {
116 $name = $pre. '[' . $name . ']';
119 if (is_array($value)) {
120 $fields .= PMA_getHiddenFields($value, $name);
122 // do not generate an ending "\n" because
123 // PMA_generate_common_hidden_inputs() is sometimes called
124 // from a JS document.write()
125 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
126 . '" value="' . htmlspecialchars($value) . '" />';
134 * Generates text with URL parameters.
137 * // OLD derepecated style
139 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
140 * // produces with cookies enabled:
141 * // script.php?db=mysql&table=rights
142 * // with cookies disabled:
143 * // script.php?server=1&lang=en&db=mysql&table=rights
146 * $params['myparam'] = 'myvalue';
147 * $params['db'] = 'mysql';
148 * $params['table'] = 'rights';
149 * // note the missing ?
150 * echo 'script.php' . PMA_generate_common_url($params);
151 * // produces with cookies enabled:
152 * // script.php?myparam=myvalue&db=mysql&table=rights
153 * // with cookies disabled:
154 * // script.php?server=1&lang=en&myparam=myvalue&db=mysql&table=rights
156 * // note the missing ?
157 * echo 'script.php' . PMA_generate_common_url();
158 * // produces with cookies enabled:
160 * // with cookies disabled:
161 * // script.php?server=1&lang=en
164 * @uses $GLOBALS['server']
165 * @uses $GLOBALS['cfg']['ServerDefault']
166 * @uses $_COOKIE['pma_lang']
167 * @uses $GLOBALS['lang']
168 * @uses $_COOKIE['pma_collation_connection']
169 * @uses $GLOBALS['collation_connection']
170 * @uses $_SESSION[' PMA_token ']
171 * @uses PMA_get_arg_separator()
174 * @uses htmlentities()
177 * @param mixed assoc. array with url params or optional string with database name
178 * if first param is an array there is also an ? prefixed to the url
180 * @param string - if first param is array: 'html' to use htmlspecialchars()
181 * on the resulting URL (for a normal URL displayed in HTML)
182 * or something else to avoid using htmlspecialchars() (for
183 * a URL sent via a header); if not set,'html' is assumed
184 * - if first param is not array: optional table name
186 * @param string - if first param is array: optional character to
188 * - if first param is not array: optional character to use
189 * instead of '&' for dividing URL parameters
190 * @return string string with URL parameters
193 function PMA_generate_common_url()
195 $args = func_get_args();
197 if (isset($args[0]) && is_array($args[0])) {
201 if (isset($args[1])) {
207 if (isset($args[2])) {
208 $questionmark = $args[2];
215 if (PMA_isValid($args[0])) {
216 $params['db'] = $args[0];
219 if (PMA_isValid($args[1])) {
220 $params['table'] = $args[1];
223 if (isset($args[2]) && $args[2] !== '&') {
232 $separator = PMA_get_arg_separator();
234 if (isset($GLOBALS['server'])
235 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
236 // avoid overwriting when creating navi panel links to servers
237 && ! isset($params['server'])) {
238 $params['server'] = $GLOBALS['server'];
241 if (empty($_COOKIE['pma_lang'])
242 && ! empty($GLOBALS['lang'])) {
243 $params['lang'] = $GLOBALS['lang'];
245 if (empty($_COOKIE['pma_collation_connection'])
246 && ! empty($GLOBALS['collation_connection'])) {
247 $params['collation_connection'] = $GLOBALS['collation_connection'];
250 if (isset($_SESSION[' PMA_token '])) {
251 $params['token'] = $_SESSION[' PMA_token '];
254 if (empty($params)) {
258 $query = $questionmark . http_build_query($params, null, $separator);
260 if ($encode === 'html') {
261 $query = htmlspecialchars($query);
268 * Returns url separator
270 * extracted from arg_separator.input as set in php.ini
271 * we do not use arg_separator.output to avoid problems with & and &
276 * @param string whether to encode separator or not, currently 'none' or 'html'
277 * @return string character used for separating url parts usally ; or &
280 function PMA_get_arg_separator($encode = 'none')
282 static $separator = null;
284 if (null === $separator) {
285 // use seperators defined by php, but prefer ';'
286 // as recommended by W3C
287 $php_arg_separator_input = ini_get('arg_separator.input');
288 if (strpos($php_arg_separator_input, ';') !== false) {
290 } elseif (strlen($php_arg_separator_input) > 0) {
291 $separator = $php_arg_separator_input{0};
299 return htmlentities($separator);