Convert Excel column name correctly
[phpmyadmin/arisferyanto.git] / libraries / url_generating.lib.php
blob659c63e2a3fd573ece0d6f19994d16f3c4db4fb1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * URL/hidden inputs generating.
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
11 * Generates text with hidden inputs.
13 * @see PMA_generate_common_url()
14 * @uses PMA_getHiddenFields
15 * @param string optional database name
16 * (can also be an array of parameters)
17 * @param string optional table name
18 * @param int indenting level
19 * @param string do not generate a hidden field for this parameter
20 * (can be an array of strings)
22 * @return string string with input fields
24 * @global string the current language
25 * @global string the current conversion charset
26 * @global string the current connection collation
27 * @global string the current server
28 * @global array the configuration array
29 * @global boolean whether recoding is allowed or not
31 * @access public
33 * @author nijel
35 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
37 if (is_array($db)) {
38 $params =& $db;
39 $_indent = empty($table) ? $indent : $table;
40 $_skip = empty($indent) ? $skip : $indent;
41 $indent =& $_indent;
42 $skip =& $_skip;
43 } else {
44 $params = array();
45 if (strlen($db)) {
46 $params['db'] = $db;
48 if (strlen($table)) {
49 $params['table'] = $table;
53 if (! empty($GLOBALS['server'])
54 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
55 $params['server'] = $GLOBALS['server'];
57 if (empty($_COOKIE['pma_lang'])
58 && ! empty($GLOBALS['lang'])) {
59 $params['lang'] = $GLOBALS['lang'];
61 if (empty($_COOKIE['pma_charset'])
62 && ! empty($GLOBALS['convcharset'])) {
63 $params['convcharset'] = $GLOBALS['convcharset'];
65 if (empty($_COOKIE['pma_collation_connection'])
66 && ! empty($GLOBALS['collation_connection'])) {
67 $params['collation_connection'] = $GLOBALS['collation_connection'];
70 $params['token'] = $_SESSION[' PMA_token '];
72 if (! is_array($skip)) {
73 if (isset($params[$skip])) {
74 unset($params[$skip]);
76 } else {
77 foreach ($skip as $skipping) {
78 if (isset($params[$skipping])) {
79 unset($params[$skipping]);
84 return PMA_getHiddenFields($params);
87 /**
88 * create hidden form fields from array with name => value
90 * <code>
91 * $values = array(
92 * 'aaa' => aaa,
93 * 'bbb' => array(
94 * 'bbb_0',
95 * 'bbb_1',
96 * ),
97 * 'ccc' => array(
98 * 'a' => 'ccc_a',
99 * 'b' => 'ccc_b',
100 * ),
101 * );
102 * echo PMA_getHiddenFields($values);
104 * // produces:
105 * <input type="hidden" name="aaa" Value="aaa" />
106 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
107 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
108 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
109 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
110 * </code>
112 * @param array $values
113 * @param string $pre
114 * @return string form fields of type hidden
116 function PMA_getHiddenFields($values, $pre = '')
118 $fields = '';
120 foreach ($values as $name => $value) {
121 if (! empty($pre)) {
122 $name = $pre. '[' . $name . ']';
125 if (is_array($value)) {
126 $fields .= PMA_getHiddenFields($value, $name);
127 } else {
128 // do not generate an ending "\n" because
129 // PMA_generate_common_hidden_inputs() is sometimes called
130 // from a JS document.write()
131 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
132 . '" value="' . htmlspecialchars($value) . '" />';
136 return $fields;
140 * Generates text with URL parameters.
142 * <code>
143 * // OLD derepecated style
144 * // note the ?
145 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
146 * // produces with cookies enabled:
147 * // script.php?db=mysql&amp;table=rights
148 * // with cookies disabled:
149 * // script.php?server=1&amp;lang=en-utf-8&amp;db=mysql&amp;table=rights
151 * // NEW style
152 * $params['myparam'] = 'myvalue';
153 * $params['db'] = 'mysql';
154 * $params['table'] = 'rights';
155 * // note the missing ?
156 * echo 'script.php' . PMA_generate_common_url($params);
157 * // produces with cookies enabled:
158 * // script.php?myparam=myvalue&amp;db=mysql&amp;table=rights
159 * // with cookies disabled:
160 * // script.php?server=1&amp;lang=en-utf-8&amp;myparam=myvalue&amp;db=mysql&amp;table=rights
162 * // note the missing ?
163 * echo 'script.php' . PMA_generate_common_url();
164 * // produces with cookies enabled:
165 * // script.php
166 * // with cookies disabled:
167 * // script.php?server=1&amp;lang=en-utf-8
168 * </code>
170 * @uses $GLOBALS['server']
171 * @uses $GLOBALS['cfg']['ServerDefault']
172 * @uses $_COOKIE['pma_lang']
173 * @uses $GLOBALS['lang']
174 * @uses $_COOKIE['pma_charset']
175 * @uses $GLOBALS['convcharset']
176 * @uses $_COOKIE['pma_collation_connection']
177 * @uses $GLOBALS['collation_connection']
178 * @uses $_SESSION[' PMA_token ']
179 * @uses PMA_get_arg_separator()
180 * @uses is_array()
181 * @uses strlen()
182 * @uses htmlentities()
183 * @uses urlencode()
184 * @uses implode()
185 * @param mixed assoc. array with url params or optional string with database name
186 * if first param is an array there is also an ? prefixed to the url
188 * @param string - if first param is array: 'html' to use htmlspecialchars()
189 * on the resulting URL (for a normal URL displayed in HTML)
190 * or something else to avoid using htmlspecialchars() (for
191 * a URL sent via a header); if not set,'html' is assumed
192 * - if first param is not array: optional table name
194 * @param string - if first param is array: optional character to
195 * use instead of '?'
196 * - if first param is not array: optional character to use
197 * instead of '&amp;' for dividing URL parameters
198 * @return string string with URL parameters
199 * @access public
200 * @author nijel
202 function PMA_generate_common_url()
204 $args = func_get_args();
206 if (isset($args[0]) && is_array($args[0])) {
207 // new style
208 $params = $args[0];
210 if (isset($args[1])) {
211 $encode = $args[1];
212 } else {
213 $encode = 'html';
216 if (isset($args[2])) {
217 $questionmark = $args[2];
218 } else {
219 $questionmark = '?';
221 } else {
222 // old style
224 if (PMA_isValid($args[0])) {
225 $params['db'] = $args[0];
228 if (PMA_isValid($args[1])) {
229 $params['table'] = $args[1];
232 if (isset($args[2]) && $args[2] !== '&amp;') {
233 $encode = 'text';
234 } else {
235 $encode = 'html';
238 $questionmark = '';
241 $separator = PMA_get_arg_separator();
243 if (isset($GLOBALS['server'])
244 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
245 // avoid overwriting when creating navi panel links to servers
246 && ! isset($params['server'])) {
247 $params['server'] = $GLOBALS['server'];
250 if (empty($_COOKIE['pma_lang'])
251 && ! empty($GLOBALS['lang'])) {
252 $params['lang'] = $GLOBALS['lang'];
254 if (empty($_COOKIE['pma_charset'])
255 && ! empty($GLOBALS['convcharset'])) {
256 $params['convcharset'] = $GLOBALS['convcharset'];
258 if (empty($_COOKIE['pma_collation_connection'])
259 && ! empty($GLOBALS['collation_connection'])) {
260 $params['collation_connection'] = $GLOBALS['collation_connection'];
263 if (isset($_SESSION[' PMA_token '])) {
264 $params['token'] = $_SESSION[' PMA_token '];
267 if (empty($params)) {
268 return '';
271 $query = $questionmark . http_build_query($params, null, $separator);
273 if ($encode === 'html') {
274 $query = htmlspecialchars($query);
277 return $query;
281 * Returns url separator
283 * extracted from arg_separator.input as set in php.ini
284 * we do not use arg_separator.output to avoid problems with &amp; and &
286 * @uses ini_get()
287 * @uses strpos()
288 * @uses strlen()
289 * @param string whether to encode separator or not, currently 'none' or 'html'
290 * @return string character used for separating url parts usally ; or &
291 * @access public
292 * @author nijel
294 function PMA_get_arg_separator($encode = 'none')
296 static $separator = null;
298 if (null === $separator) {
299 // use seperators defined by php, but prefer ';'
300 // as recommended by W3C
301 $php_arg_separator_input = ini_get('arg_separator.input');
302 if (strpos($php_arg_separator_input, ';') !== false) {
303 $separator = ';';
304 } elseif (strlen($php_arg_separator_input) > 0) {
305 $separator = $php_arg_separator_input{0};
306 } else {
307 $separator = '&';
311 switch ($encode) {
312 case 'html':
313 return htmlentities($separator);
314 break;
315 case 'text' :
316 case 'none' :
317 default :
318 return $separator;