undefined messages in Designer
[phpmyadmin/last10db.git] / libraries / url_generating.lib.php
blob069e4b439b9d755b130a0db7f0afec8357627173
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * URL/hidden inputs generating.
6 * @package phpMyAdmin
7 */
9 /**
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
30 * @access public
33 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
35 if (is_array($db)) {
36 $params =& $db;
37 $_indent = empty($table) ? $indent : $table;
38 $_skip = empty($indent) ? $skip : $indent;
39 $indent =& $_indent;
40 $skip =& $_skip;
41 } else {
42 $params = array();
43 if (strlen($db)) {
44 $params['db'] = $db;
46 if (strlen($table)) {
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]);
70 } else {
71 foreach ($skip as $skipping) {
72 if (isset($params[$skipping])) {
73 unset($params[$skipping]);
78 return PMA_getHiddenFields($params);
81 /**
82 * create hidden form fields from array with name => value
84 * <code>
85 * $values = array(
86 * 'aaa' => aaa,
87 * 'bbb' => array(
88 * 'bbb_0',
89 * 'bbb_1',
90 * ),
91 * 'ccc' => array(
92 * 'a' => 'ccc_a',
93 * 'b' => 'ccc_b',
94 * ),
95 * );
96 * echo PMA_getHiddenFields($values);
98 * // produces:
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" />
104 * </code>
106 * @param array $values
107 * @param string $pre
108 * @return string form fields of type hidden
110 function PMA_getHiddenFields($values, $pre = '')
112 $fields = '';
114 foreach ($values as $name => $value) {
115 if (! empty($pre)) {
116 $name = $pre. '[' . $name . ']';
119 if (is_array($value)) {
120 $fields .= PMA_getHiddenFields($value, $name);
121 } else {
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) . '" />';
130 return $fields;
134 * Generates text with URL parameters.
136 * <code>
137 * // OLD derepecated style
138 * // note the ?
139 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
140 * // produces with cookies enabled:
141 * // script.php?db=mysql&amp;table=rights
142 * // with cookies disabled:
143 * // script.php?server=1&amp;lang=en&amp;db=mysql&amp;table=rights
145 * // NEW style
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&amp;db=mysql&amp;table=rights
153 * // with cookies disabled:
154 * // script.php?server=1&amp;lang=en&amp;myparam=myvalue&amp;db=mysql&amp;table=rights
156 * // note the missing ?
157 * echo 'script.php' . PMA_generate_common_url();
158 * // produces with cookies enabled:
159 * // script.php
160 * // with cookies disabled:
161 * // script.php?server=1&amp;lang=en
162 * </code>
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()
172 * @uses is_array()
173 * @uses strlen()
174 * @uses htmlentities()
175 * @uses urlencode()
176 * @uses implode()
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
187 * use instead of '?'
188 * - if first param is not array: optional character to use
189 * instead of '&amp;' for dividing URL parameters
190 * @return string string with URL parameters
191 * @access public
193 function PMA_generate_common_url()
195 $args = func_get_args();
197 if (isset($args[0]) && is_array($args[0])) {
198 // new style
199 $params = $args[0];
201 if (isset($args[1])) {
202 $encode = $args[1];
203 } else {
204 $encode = 'html';
207 if (isset($args[2])) {
208 $questionmark = $args[2];
209 } else {
210 $questionmark = '?';
212 } else {
213 // old style
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] !== '&amp;') {
224 $encode = 'text';
225 } else {
226 $encode = 'html';
229 $questionmark = '';
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)) {
255 return '';
258 $query = $questionmark . http_build_query($params, null, $separator);
260 if ($encode === 'html') {
261 $query = htmlspecialchars($query);
264 return $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 &amp; and &
273 * @uses ini_get()
274 * @uses strpos()
275 * @uses strlen()
276 * @param string whether to encode separator or not, currently 'none' or 'html'
277 * @return string character used for separating url parts usally ; or &
278 * @access public
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) {
289 $separator = ';';
290 } elseif (strlen($php_arg_separator_input) > 0) {
291 $separator = $php_arg_separator_input{0};
292 } else {
293 $separator = '&';
297 switch ($encode) {
298 case 'html':
299 return htmlentities($separator);
300 break;
301 case 'text' :
302 case 'none' :
303 default :
304 return $separator;