bug 633422
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php3
blob507b995675a42d7fe39801a79e6c862f4ddf7e2d
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Set of functions used to display the records returned by a sql query
7 */
11 if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
12 define('PMA_DISPLAY_TBL_LIB_INCLUDED', 1);
14 /**
15 * Defines the display mode to use for the results of a sql query
17 * It uses a synthetic string that contains all the required informations.
18 * In this string:
19 * - the first two characters stand for the action to do while
20 * clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
21 * edit link...);
22 * - the next two characters stand for the action to do while
23 * clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
24 * no delete link...);
25 * - the next characters are boolean values (1/0) and respectively stand
26 * for sorting links, navigation bar, "insert a new row" link, the
27 * bookmark feature, the expand/collapse text/blob fields button and
28 * the "display printable view" option.
29 * Of course '0'/'1' means the feature won't/will be enabled.
31 * @param string the synthetic value for display_mode (see ยง1 a few
32 * lines above for explanations)
33 * @param integer the total number of rows returned by the sql query
34 * without any programmatically appended "LIMIT" clause
35 * (just a copy of $unlim_num_rows if it exists, else
36 * computed inside this function)
38 * @return array an array with explicit indexes for all the display
39 * elements
41 * @global string the database name
42 * @global string the table name
43 * @global integer the total number of rows returned by the sql query
44 * without any programmatically appended "LIMIT" clause
45 * @global array the properties of the fields returned by the query
46 * @global string the url to return to in case of error in a sql
47 * statement
49 * @access private
51 * @see PMA_displayTable()
53 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
55 global $db, $table;
56 global $unlim_num_rows, $fields_meta;
57 global $err_url;
59 // 1. Initializes the $do_display array
60 $do_display = array();
61 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
62 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
63 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
64 $do_display['nav_bar'] = (string) $the_disp_mode[5];
65 $do_display['ins_row'] = (string) $the_disp_mode[6];
66 $do_display['bkm_form'] = (string) $the_disp_mode[7];
67 $do_display['text_btn'] = (string) $the_disp_mode[8];
68 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
70 // 2. Display mode is not "false for all elements" -> updates the
71 // display mode
72 if ($the_disp_mode != 'nnnn000000') {
73 // 2.0 Print view -> set all elements to FALSE!
74 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
75 $do_display['edit_lnk'] = 'nn'; // no edit link
76 $do_display['del_lnk'] = 'nn'; // no delete link
77 $do_display['sort_lnk'] = (string) '0';
78 $do_display['nav_bar'] = (string) '0';
79 $do_display['ins_row'] = (string) '0';
80 $do_display['bkm_form'] = (string) '0';
81 $do_display['text_btn'] = (string) '0';
82 $do_display['pview_lnk'] = (string) '0';
84 // 2.1 Statement is a "SELECT COUNT", a
85 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
86 // contains a "PROC ANALYSE" part
87 else if ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
88 $do_display['edit_lnk'] = 'nn'; // no edit link
89 $do_display['del_lnk'] = 'nn'; // no delete link
90 $do_display['sort_lnk'] = (string) '0';
91 $do_display['nav_bar'] = (string) '0';
92 $do_display['ins_row'] = (string) '0';
93 $do_display['bkm_form'] = (string) '1';
94 $do_display['text_btn'] = (string) '0';
95 $do_display['pview_lnk'] = (string) '1';
97 // 2.2 Statement is a "SHOW..."
98 else if ($GLOBALS['is_show']) {
99 // 2.2.1 TODO : defines edit/delete links depending on show statement
100 $tmp = eregi('^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS)', $GLOBALS['sql_query'], $which);
101 if (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
102 $do_display['edit_lnk'] = 'nn'; // no edit link
103 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
105 else {
106 // Default case -> no links
107 $do_display['edit_lnk'] = 'nn'; // no edit link
108 $do_display['del_lnk'] = 'nn'; // no delete link
110 // 2.2.2 Other settings
111 $do_display['sort_lnk'] = (string) '0';
112 $do_display['nav_bar'] = (string) '0';
113 $do_display['ins_row'] = (string) '0';
114 $do_display['bkm_form'] = (string) '1';
115 $do_display['text_btn'] = (string) '0';
116 $do_display['pview_lnk'] = (string) '1';
118 // 2.3 Other statements (ie "SELECT" ones) -> updates
119 // $do_display['edit_lnk'], $do_display['del_lnk'] and
120 // $do_display['text_btn'] (keeps other default values)
121 else {
122 $prev_table = $fields_meta[0]->table;
123 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
124 $is_link = ($do_display['edit_lnk'] != 'nn'
125 || $do_display['del_lnk'] != 'nn'
126 || $do_display['sort_lnk'] != '0'
127 || $do_display['ins_row'] != '0');
128 // 2.3.1 Displays text cut/expand button?
129 if ($do_display['text_btn'] == '0' && eregi('BLOB', $fields_meta[$i]->type)) {
130 $do_display['text_btn'] = (string) '1';
131 if (!$is_link) {
132 break;
134 } // end if (2.3.1)
135 // 2.3.2 Displays edit/delete/sort/insert links?
136 if ($is_link
137 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
138 $do_display['edit_lnk'] = 'nn'; // don't display links
139 $do_display['del_lnk'] = 'nn';
140 // TODO: May be problematic with same fields names in
141 // two joined table.
142 // $do_display['sort_lnk'] = (string) '0';
143 $do_display['ins_row'] = (string) '0';
144 if ($do_display['text_btn'] == '1') {
145 break;
147 } // end if (2.3.2)
148 // 2.3.3 Always display print view link
149 $do_display['pview_lnk'] = (string) '1';
150 $prev_table = $fields_meta[$i]->table;
151 } // end for
152 } // end if..elseif...else (2.1 -> 2.3)
153 } // end if (2)
155 // 3. Gets the total number of rows if it is unknown
156 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
157 $the_total = $unlim_num_rows;
159 else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
160 && (!empty($db) && !empty($table))) {
161 $local_query = 'SELECT COUNT(*) AS total FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
162 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
163 $the_total = PMA_mysql_result($result, 0, 'total');
164 mysql_free_result($result);
167 // 4. If navigation bar or sorting fields names urls should be
168 // displayed but there is only one row, change these settings to
169 // false
170 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
171 if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
172 $do_display['nav_bar'] = (string) '0';
173 $do_display['sort_lnk'] = (string) '0';
175 } // end if (3)
177 // 5. Updates the synthetic var
178 $the_disp_mode = join('', $do_display);
180 return $do_display;
181 } // end of the 'PMA_setDisplayMode()' function
185 * Displays a navigation bar to browse among the results of a sql query
187 * @param integer the offset for the "next" page
188 * @param integer the offset for the "previous" page
189 * @param string the url-encoded query
191 * @global string the current language
192 * @global string the currect charset for MySQL
193 * @global integer the server to use (refers to the number in the
194 * configuration file)
195 * @global string the database name
196 * @global string the table name
197 * @global string the url to go back in case of errors
198 * @global integer the total number of rows returned by the sql query
199 * @global integer the total number of rows returned by the sql query
200 * without any programmatically appended "LIMIT" clause
201 * @global integer the current position in results
202 * @global mixed the maximum number of rows per page ('all' = no limit)
203 * @global string the display mode (horizontal/vertical)
204 * @global integer the number of row to display between two table headers
205 * @global boolean whether to limit the number of displayed characters of
206 * text type fields or not
208 * @access private
210 * @see PMA_displayTable()
212 function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
214 global $lang, $convcharset, $server, $db, $table;
215 global $goto;
216 global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
217 global $disp_direction, $repeat_cells;
218 global $dontlimitchars;
221 <!-- Navigation bar -->
222 <table border="0">
223 <tr>
224 <?php
225 // Move to the beginning or to the previous page
226 if ($pos > 0 && $session_max_rows != 'all') {
227 // loic1: patch #474210 from Gosha Sakovich - part 1
228 if ($GLOBALS['cfg']['NavigationBarIconic']) {
229 $caption1 = '&lt;&lt;';
230 $caption2 = '&nbsp;&lt;&nbsp;';
231 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
232 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
233 } else {
234 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
235 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
236 $title1 = '';
237 $title2 = '';
238 } // end if... else...
240 <td>
241 <form action="sql.php3" method="post">
242 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
243 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
244 <input type="hidden" name="server" value="<?php echo $server; ?>" />
245 <input type="hidden" name="db" value="<?php echo $db; ?>" />
246 <input type="hidden" name="table" value="<?php echo $table; ?>" />
247 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
248 <input type="hidden" name="pos" value="0" />
249 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
250 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
251 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
252 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
253 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
254 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
255 </form>
256 </td>
257 <td>
258 <form action="sql.php3" method="post">
259 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
260 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
261 <input type="hidden" name="server" value="<?php echo $server; ?>" />
262 <input type="hidden" name="db" value="<?php echo $db; ?>" />
263 <input type="hidden" name="table" value="<?php echo $table; ?>" />
264 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
265 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
266 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
267 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
268 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
269 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
270 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
271 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
272 </form>
273 </td>
274 <?php
275 } // end move back
276 echo "\n";
278 <td>
279 &nbsp;&nbsp;&nbsp;
280 </td>
281 <td align="center">
282 <form action="sql.php3" method="post"
283 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', 1) && checkFormElementInRange(this, 'pos', 0, <?php echo $unlim_num_rows - 1; ?>))">
284 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
285 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
286 <input type="hidden" name="server" value="<?php echo $server; ?>" />
287 <input type="hidden" name="db" value="<?php echo $db; ?>" />
288 <input type="hidden" name="table" value="<?php echo $table; ?>" />
289 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
290 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
291 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
292 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?>&nbsp;:" />
293 <input type="text" name="session_max_rows" size="3" value="<?php echo (($session_max_rows != 'all') ? $session_max_rows : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
294 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
295 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
296 <br />
297 <?php
298 // Display mode (horizontal/vertical and repeat headers)
299 $param1 = ' <select name="disp_direction">' . "\n"
300 . ' <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
301 . ' <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
302 . ' </select>' . "\n"
303 . ' ';
304 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
305 . ' ';
306 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
308 </form>
309 </td>
310 <td>
311 &nbsp;&nbsp;&nbsp;
312 </td>
313 <?php
314 // Move to the next page or to the last one
315 if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
316 && $session_max_rows != 'all') {
317 // loic1: patch #474210 from Gosha Sakovich - part 2
318 if ($GLOBALS['cfg']['NavigationBarIconic']) {
319 $caption3 = '&nbsp;&gt;&nbsp;';
320 $caption4 = '&gt;&gt;';
321 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
322 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
323 } else {
324 $caption3 = '&gt; ' . $GLOBALS['strNext'];
325 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
326 $title3 = '';
327 $title4 = '';
328 } // end if... else...
329 echo "\n";
331 <td>
332 <form action="sql.php3" method="post">
333 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
334 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
335 <input type="hidden" name="server" value="<?php echo $server; ?>" />
336 <input type="hidden" name="db" value="<?php echo $db; ?>" />
337 <input type="hidden" name="table" value="<?php echo $table; ?>" />
338 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
339 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
340 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
341 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
342 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
343 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
344 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
345 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
346 </form>
347 </td>
348 <td>
349 <form action="sql.php3" method="post"
350 onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
351 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
352 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
353 <input type="hidden" name="server" value="<?php echo $server; ?>" />
354 <input type="hidden" name="db" value="<?php echo $db; ?>" />
355 <input type="hidden" name="table" value="<?php echo $table; ?>" />
356 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
357 <input type="hidden" name="pos" value="<?php echo $unlim_num_rows - $session_max_rows; ?>" />
358 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
359 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
360 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
361 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
362 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
363 <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> />
364 </form>
365 </td>
366 <?php
367 } // end move toward
369 // Show all the records if allowed
370 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
371 echo "\n";
373 <td>
374 &nbsp;&nbsp;&nbsp;
375 </td>
376 <td>
377 <form action="sql.php3" method="post">
378 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
379 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
380 <input type="hidden" name="server" value="<?php echo $server; ?>" />
381 <input type="hidden" name="db" value="<?php echo $db; ?>" />
382 <input type="hidden" name="table" value="<?php echo $table; ?>" />
383 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
384 <input type="hidden" name="pos" value="0" />
385 <input type="hidden" name="session_max_rows" value="all" />
386 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
387 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
388 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
389 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
390 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
391 </form>
392 </td>
393 <?php
394 } // end show all
395 echo "\n";
397 </tr>
398 </table>
400 <?php
401 } // end of the 'PMA_displayTableNavigation()' function
405 * Displays the headers of the results table
407 * @param array which elements to display
408 * @param array the list of fields properties
409 * @param integer the total number of fields returned by the sql query
411 * @return boolean always true
413 * @global string the current language
414 * @global string the current charset for MySQL
415 * @global integer the server to use (refers to the number in the
416 * configuration file)
417 * @global string the database name
418 * @global string the table name
419 * @global string the sql query
420 * @global string the url to go back in case of errors
421 * @global integer the total number of rows returned by the sql query
422 * @global integer the current position in results
423 * @global integer the maximum number of rows per page
424 * @global array informations used with vertical display mode
425 * @global string the display mode (horizontal/vertical)
426 * @global integer the number of row to display between two table headers
427 * @global boolean whether to limit the number of displayed characters of
428 * text type fields or not
430 * @access private
432 * @see PMA_displayTable()
434 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0)
436 global $lang, $convcharset, $server, $db, $table;
437 global $goto;
438 global $sql_query, $num_rows, $pos, $session_max_rows;
439 global $vertical_display, $disp_direction, $repeat_cells;
440 global $dontlimitchars;
442 if ($disp_direction == 'horizontal') {
444 <!-- Results table headers -->
445 <tr>
446 <?php
447 echo "\n";
450 $vertical_display['emptypre'] = 0;
451 $vertical_display['emptyafter'] = 0;
452 $vertical_display['textbtn'] = '';
454 // 1. Displays the full/partial text button (part 1)...
455 if ($disp_direction == 'horizontal') {
456 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
457 ? ' colspan="2"'
458 : '';
459 } else {
460 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
461 ? ' rowspan="2"'
462 : '';
464 $text_url = 'sql.php3'
465 . '?lang=' . $lang
466 . '&amp;convcharset=' . $convcharset
467 . '&amp;server=' . $server
468 . '&amp;db=' . urlencode($db)
469 . '&amp;table=' . urlencode($table)
470 . '&amp;sql_query=' . urlencode($sql_query)
471 . '&amp;pos=' . $pos
472 . '&amp;session_max_rows=' . $session_max_rows
473 . '&amp;pos=' . $pos
474 . '&amp;disp_direction=' . $disp_direction
475 . '&amp;repeat_cells=' . $repeat_cells
476 . '&amp;goto=' . $goto
477 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
479 // ... before the result table
480 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
481 && $is_display['text_btn'] == '1') {
482 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
483 if ($disp_direction == 'horizontal') {
485 <td colspan="<?php echo $fields_cnt; ?>" align="center">
486 <a href="<?php echo $text_url; ?>">
487 <img src="./images/<?php echo (($dontlimitchars) ? 'partialtext' : 'fulltext'); ?>.png" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
488 </td>
489 </tr>
491 <tr>
492 <?php
493 } // end horizontal mode
494 else {
495 echo "\n";
497 <tr>
498 <td colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
499 <a href="<?php echo $text_url; ?>">
500 <img src="./images/<?php echo (($dontlimitchars) ? 'partialtext' : 'fulltext'); ?>.png" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
501 </td>
502 </tr>
503 <?php
504 } // end vertical mode
507 // ... at the left column of the result table header if possible
508 // and required
509 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
510 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
511 if ($disp_direction == 'horizontal') {
512 echo "\n";
514 <td<?php echo $colspan; ?> align="center">
515 <a href="<?php echo $text_url; ?>">
516 <img src="./images/<?php echo (($dontlimitchars) ? 'partialtext' : 'fulltext'); ?>.png" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
517 </td>
518 <?php
519 } // end horizontal mode
520 else {
521 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
522 . ' <a href="' . $text_url . '">' . "\n"
523 . ' <img src="./images/' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png" border="0" width="50" height="20" alt="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" /></a>' . "\n"
524 . ' </td>' . "\n";
525 } // end vertical mode
528 // ... else if no button, displays empty(ies) col(s) if required
529 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
530 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
531 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
532 if ($disp_direction == 'horizontal') {
533 echo "\n";
535 <td<?php echo $colspan; ?>></td>
536 <?php
537 echo "\n";
538 } // end horizontal mode
539 else {
540 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
541 } // end vertical mode
544 // 2. Displays the fields' name
545 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
546 // statement (see 2.1.3)
547 if ($is_display['sort_lnk'] == '1') {
548 $is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
549 } else {
550 $is_join = FALSE;
552 for ($i = 0; $i < $fields_cnt; $i++) {
554 // 2.1 Results can be sorted
555 if ($is_display['sort_lnk'] == '1') {
556 // Defines the url used to append/modify a sorting order
557 // 2.1.1 Checks if an hard coded 'order by' clause exists
558 if (eregi('(.*)([[:space:]]ORDER[[:space:]]*BY[[:space:]](.*))', $sql_query, $regs1)) {
559 if (eregi('((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)', $regs1[2], $regs2)) {
560 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
561 $sql_order = trim($regs2[1]);
563 else if (eregi('((.*))[[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) {
564 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]);
565 $sql_order = trim($regs3[1]) . ' ASC';
566 } else {
567 $unsorted_sql_query = trim($regs1[1]);
568 $sql_order = trim($regs1[2]) . ' ASC';
570 } else {
571 $unsorted_sql_query = $sql_query;
573 // 2.1.2 Checks if the current column is used to sort the
574 // results
575 if (empty($sql_order)) {
576 $is_in_sort = FALSE;
577 } else {
578 //$is_in_sort = eregi('[[:space:]](`?)' . str_replace('\\', '\\\\', $fields_meta[$i]->name) . '(`?)[ ,$]', $sql_order);
579 $pattern = str_replace('\\', '\\\\', $fields_meta[$i]->name);
580 $pattern = str_replace('(','\(', $pattern);
581 $pattern = str_replace(')','\)', $pattern);
582 //$is_in_sort = eregi('[[:space:]](`?)' . $pattern . '(`?)[ ,$]', $sql_order);
583 // field name may be preceded by a space, or any number
584 // of characters followed by a dot (tablename.fieldname)
585 $is_in_sort = eregi('([[:space:]]|(.*\.))(`?)' . $pattern . '(`?)[ ,$]', $sql_order);
587 // 2.1.3 Checks if the table name is required (it's the case
588 // for a query with a "JOIN" statement and if the column
589 // isn't aliased)
590 if ($is_join
591 && !eregi('([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name, $select_stt[1], $parts)) {
592 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
593 } else {
594 $sort_tbl = '';
596 // 2.1.4 Check the field name for backquotes.
597 // If it contains some, it's probably a function column
598 // like 'COUNT(`field`)'
599 if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
600 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
601 } else {
602 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
604 // 2.1.5 Do define the sorting url
605 if (!$is_in_sort) {
606 // loic1: patch #455484 ("Smart" order)
607 $cfg['Order'] = strtoupper($GLOBALS['cfg']['Order']);
608 if ($cfg['Order'] == 'SMART') {
609 $cfg['Order'] = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
611 $sort_order .= $cfg['Order'];
612 $order_img = '';
614 else if (eregi('[[:space:]]ASC$', $sql_order)) {
615 $sort_order .= ' DESC';
616 $order_img = '&nbsp;<img src="./images/asc_order.gif" border="0" width="7" height="7" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" />';
618 else if (eregi('[[:space:]]DESC$', $sql_order)) {
619 $sort_order .= ' ASC';
620 $order_img = '&nbsp;<img src="./images/desc_order.gif" border="0" width="7" height="7" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" />';
622 if (eregi('(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))', $unsorted_sql_query, $regs3)) {
623 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
624 } else {
625 $sorted_sql_query = $unsorted_sql_query . $sort_order;
627 $url_query = 'lang=' . $lang
628 . '&amp;convcharset=' . $convcharset
629 . '&amp;server=' . $server
630 . '&amp;db=' . urlencode($db)
631 . '&amp;table=' . urlencode($table)
632 . '&amp;pos=' . $pos
633 . '&amp;session_max_rows=' . $session_max_rows
634 . '&amp;disp_direction=' . $disp_direction
635 . '&amp;repeat_cells=' . $repeat_cells
636 . '&amp;dontlimitchars=' . $dontlimitchars
637 . '&amp;sql_query=' . urlencode($sorted_sql_query);
639 // 2.1.5 Displays the sorting url
640 if ($disp_direction == 'horizontal') {
641 echo "\n";
643 <th>
644 <a href="sql.php3?<?php echo $url_query; ?>">
645 <?php echo htmlspecialchars($fields_meta[$i]->name); ?></a><?php echo $order_img . "\n"; ?>
646 </th>
647 <?php
649 $vertical_display['desc'][] = ' <th>' . "\n"
650 . ' <a href="sql.php3?' . $url_query . '">' . "\n"
651 . ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
652 . ' </th>' . "\n";
653 } // end if (2.1)
655 // 2.2 Results can't be sorted
656 else {
657 if ($disp_direction == 'horizontal') {
658 echo "\n";
660 <th>
661 <?php echo htmlspecialchars($fields_meta[$i]->name) . "\n"; ?>
662 </th>
663 <?php
665 $vertical_display['desc'][] = ' <th>' . "\n"
666 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
667 . ' </th>';
668 } // end else (2.2)
669 } // end for
671 // 3. Displays the full/partial text button (part 2) at the right
672 // column of the result table header if possible and required...
673 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
674 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
675 && $is_display['text_btn'] == '1') {
676 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
677 if ($disp_direction == 'horizontal') {
678 echo "\n";
680 <td<?php echo $colspan; ?> align="center">
681 <a href="<?php echo $text_url; ?>">
682 <img src="./images/<?php echo (($dontlimitchars) ? 'partialtext' : 'fulltext'); ?>.png" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
683 </td>
684 <?php
685 } // end horizontal mode
686 else {
687 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
688 . ' <a href="' . $text_url . '">' . "\n"
689 . ' <img src="./images/' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png" border="0" width="50" height="20" alt="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" /></a>' . "\n"
690 . ' </td>' . "\n";
691 } // end vertical mode
694 // ... else if no button, displays empty cols if required
695 // (unless coming from Browse mode print view)
696 else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
697 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
698 && (!$GLOBALS['is_header_sent'])) {
699 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
700 if ($disp_direction == 'horizontal') {
701 echo "\n";
703 <td<?php echo $colspan; ?>></td>
704 <?php
705 } // end horizontal mode
706 else {
707 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
708 } // end vertical mode
711 if ($disp_direction == 'horizontal') {
712 echo "\n";
714 </tr>
715 <?php
717 echo "\n";
719 return TRUE;
720 } // end of the 'PMA_displayTableHeaders()' function
724 * Displays a link, or a button if the link's URL is too large, to
725 * accommodate some browsers' limitations
727 * @param string the URL
728 * @param string the link message
729 * @param string js confirmation
731 * @return string the results to be echoed or saved in an array
733 function PMA_linkOrButton($url, $message, $js_conf)
735 if (strlen($url) <= 2047) {
736 $onclick_url = (empty($js_conf) ? '' : ' onclick="return confirmLink(this, \'' . $js_conf . '\')"');
737 $link_or_button = ' <a href="' . $url . '"' . $onclick_url . '>' . "\n"
738 . ' ' . $message . '</a>' . "\n";
740 else {
741 $edit_url_parts = parse_url($url);
742 $query_parts = explode('&', $edit_url_parts['query']);
743 $link_or_button = ' <form action="'
744 . $edit_url_parts['path']
745 . '" method="post">' . "\n";
746 reset ($query_parts);
747 while (list(, $query_pair) = each($query_parts)) {
748 list($eachvar, $eachval) = explode('=', $query_pair);
749 $link_or_button .= ' <input type="hidden" name="' . str_replace('amp;', '', $eachvar) . '" value="' . htmlspecialchars(urldecode($eachval)) . '" />' . "\n";
750 } // end while
751 $link_or_button .= ' <input type="submit" value="'
752 . htmlspecialchars($message) . '" />' . "\n" . '</form>' . "\n";
753 } // end if... else...
755 return $link_or_button;
756 } // end of the 'PMA_linkOrButton()' function
760 * Displays the body of the results table
762 * @param integer the link id associated to the query which results have
763 * to be displayed
764 * @param array which elements to display
765 * @param array the list of relations
766 * @param array the analyzed query
768 * @return boolean always true
770 * @global string the current language
771 * @global string the current charset for MySQL
772 * @global integer the server to use (refers to the number in the
773 * configuration file)
774 * @global string the database name
775 * @global string the table name
776 * @global string the sql query
777 * @global string the url to go back in case of errors
778 * @global integer the current position in results
779 * @global integer the maximum number of rows per page
780 * @global array the list of fields properties
781 * @global integer the total number of fields returned by the sql query
782 * @global array informations used with vertical display mode
783 * @global string the display mode (horizontal/vertical)
784 * @global integer the number of row to display between two table headers
785 * @global boolean whether to limit the number of displayed characters of
786 * text type fields or not
788 * @access private
790 * @see PMA_displayTable()
792 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
794 global $lang, $convcharset, $server, $db, $table;
795 global $goto;
796 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
797 global $vertical_display, $disp_direction, $repeat_cells;
798 global $dontlimitchars;
800 if (!is_array($map)) {
801 $map = array();
804 <!-- Results table body -->
805 <?php
806 echo "\n";
808 $row_no = 0;
809 $vertical_display['edit'] = array();
810 $vertical_display['delete'] = array();
811 $vertical_display['data'] = array();
813 // Correction uva 19991216 in the while below
814 // Previous code assumed that all tables have keys, specifically that
815 // the phpMyAdmin GUI should support row delete/edit only for such
816 // tables.
817 // Although always using keys is arguably the prescribed way of
818 // defining a relational table, it is not required. This will in
819 // particular be violated by the novice.
820 // We want to encourage phpMyAdmin usage by such novices. So the code
821 // below has been changed to conditionally work as before when the
822 // table being displayed has one or more keys; but to display
823 // delete/edit options correctly for tables without keys.
825 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
826 // to get the NULL values
828 while ($row = PMA_mysql_fetch_array($dt_result)) {
830 // lem9: "vertical display" mode stuff
831 if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && $disp_direction == 'horizontal') {
832 echo '<tr>' . "\n";
834 for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
835 echo ' <td>&nbsp;</td>' . "\n";
838 reset($vertical_display['desc']);
839 while (list($key, $val) = each($vertical_display['desc'])) {
840 echo $val;
843 for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
844 echo ' <td>&nbsp;</td>' . "\n";
847 echo '</tr>' . "\n";
848 } // end if
850 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
851 $bgcolor = '#ffffff';
852 } else {
853 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
856 if ($disp_direction == 'horizontal') {
857 // loic1: pointer code part
858 $on_mouse = '';
859 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
860 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
861 $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
862 . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
864 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
865 $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
867 } // end if
869 <tr<?php echo $on_mouse; ?>>
870 <?php
871 echo "\n";
874 // 1. Prepares the row (gets primary keys to use)
875 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
876 $primary_key = '';
877 $unique_key = '';
878 $uva_nonprimary_condition = '';
880 // 1.1 Results from a "SELECT" statement -> builds the
881 // "primary" key to use in links
882 if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
883 for ($i = 0; $i < $fields_cnt; ++$i) {
884 $meta = $fields_meta[$i];
886 // to fix the bug where float fields (primary or not)
887 // can't be matched because of the imprecision of
888 // floating comparison, use CONCAT
889 // (also, the syntax "CONCAT(field) IS NULL"
890 // that we need on the next "if" will work)
892 if ($meta->type == 'real') {
893 $condition = ' CONCAT(' . PMA_backquote($meta->name) . ') ';
894 } else {
895 $condition = ' ' . PMA_backquote($meta->name) . ' ';
896 } // end if... else...
898 // loic1: To fix bug #474943 under php4, the row
899 // pointer will depend on whether the "is_null"
900 // php4 function is available or not
901 $pointer = (function_exists('is_null') ? $i : $meta->name);
902 if (!isset($row[$meta->name])
903 || (function_exists('is_null') && is_null($row[$pointer]))) {
904 $condition .= 'IS NULL AND';
905 } else {
906 $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer]) . '\' AND';
908 if ($meta->primary_key > 0) {
909 $primary_key .= $condition;
910 } else if ($meta->unique_key > 0) {
911 $unique_key .= $condition;
913 $uva_nonprimary_condition .= $condition;
914 } // end for
916 // Correction uva 19991216: prefer primary or unique keys
917 // for condition, but use conjunction of all values if no
918 // primary key
919 if ($primary_key) {
920 $uva_condition = $primary_key;
921 } else if ($unique_key) {
922 $uva_condition = $unique_key;
923 } else {
924 $uva_condition = $uva_nonprimary_condition;
926 $uva_condition = urlencode(ereg_replace('[[:space:]]?AND$', '', $uva_condition));
927 } // end if (1.1)
929 // 1.2 Defines the urls for the modify/delete link(s)
930 $url_query = 'lang=' . $lang
931 . '&amp;convcharset=' . $convcharset
932 . '&amp;server=' . $server
933 . '&amp;db=' . urlencode($db)
934 . '&amp;table=' . urlencode($table)
935 . '&amp;pos=' . $pos
936 . '&amp;session_max_rows=' . $session_max_rows
937 . '&amp;disp_direction=' . $disp_direction
938 . '&amp;repeat_cells=' . $repeat_cells
939 . '&amp;dontlimitchars=' . $dontlimitchars;
941 // 1.2.1 Modify link(s)
942 if ($is_display['edit_lnk'] == 'ur') { // update row case
943 // $lnk_goto = 'sql.php3'
944 // . '?' . str_replace('&amp;', '&', $url_query)
945 // . '&sql_query=' . urlencode($sql_query)
946 // . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
947 // to reduce the length of the URL, because of some browsers limitations:
948 $lnk_goto = 'sql.php3';
950 $edit_url = 'tbl_change.php3'
951 . '?' . $url_query
952 . '&amp;primary_key=' . $uva_condition
953 . '&amp;sql_query=' . urlencode($sql_query)
954 . '&amp;goto=' . urlencode($lnk_goto);
955 $edit_str = $GLOBALS['strEdit'];
956 } // end if (1.2.1)
958 // 1.2.2 Delete/Kill link(s)
959 if ($is_display['del_lnk'] == 'dr') { // delete row case
960 $lnk_goto = 'sql.php3'
961 . '?' . str_replace('&amp;', '&', $url_query)
962 . '&sql_query=' . urlencode($sql_query)
963 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
964 . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
965 $del_url = 'sql.php3'
966 . '?' . $url_query
967 . '&amp;sql_query=' . urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . ((PMA_MYSQL_INT_VERSION >= 32207) ? urlencode(' LIMIT 1') : '')
968 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
969 . '&amp;goto=' . urlencode($lnk_goto);
970 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
971 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
972 . ((PMA_MYSQL_INT_VERSION >= 32207) ? ' LIMIT 1' : '');
973 $del_str = $GLOBALS['strDelete'];
974 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
975 $lnk_goto = 'sql.php3'
976 . '?' . str_replace('&amp;', '&', $url_query)
977 . '&sql_query=' . urlencode($sql_query)
978 . '&goto=main.php3';
979 $del_url = 'sql.php3'
980 . '?lang=' . $lang
981 . '&amp;convcharset=' . $convcharset
982 . '&amp;server=' . $server
983 . '&amp;db=mysql'
984 . '&amp;sql_query=' . urlencode('KILL ' . $row['Id'])
985 . '&amp;goto=' . urlencode($lnk_goto);
986 $js_conf = 'KILL ' . $row['Id'];
987 $del_str = $GLOBALS['strKill'];
988 } // end if (1.2.2)
990 // 1.3 Displays the links at left if required
991 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
992 && ($disp_direction == 'horizontal')) {
993 if (!empty($edit_url)) {
994 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
995 echo PMA_linkOrButton($edit_url, $edit_str, '');
996 echo ' </td>' . "\n";
998 if (!empty($del_url)) {
999 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
1000 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1001 echo ' </td>' . "\n";
1003 } // end if (1.3)
1004 echo (($disp_direction == 'horizontal') ? "\n" : '');
1005 } // end if (1)
1007 // 2. Displays the rows' values
1008 for ($i = 0; $i < $fields_cnt; ++$i) {
1009 $meta = $fields_meta[$i];
1010 // loic1: To fix bug #474943 under php4, the row pointer will
1011 // depend on whether the "is_null" php4 function is
1012 // available or not
1013 $pointer = (function_exists('is_null') ? $i : $meta->name);
1015 // n u m e r i c
1016 if ($meta->numeric == 1) {
1018 // lem9: if two fields have the same name (this is possible
1019 // with self-join queries, for example), using $meta->name
1020 // will show both fields NULL even if only one is NULL,
1021 // so use the $pointer
1022 // (works only if function_exists('is_null')
1023 // PS: why not always work with the number ($i), since
1024 // the default second parameter of
1025 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1026 // associative and numeric indices?
1028 //if (!isset($row[$meta->name])
1029 if (!isset($row[$pointer])
1030 || (function_exists('is_null') && is_null($row[$pointer]))) {
1031 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1032 } else if ($row[$pointer] != '') {
1033 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '">';
1035 if (isset($map[$meta->name])) {
1036 // Field to display from the foreign table?
1037 if (!empty($map[$meta->name][2])) {
1038 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1039 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1040 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1041 . ' = ' . $row[$pointer];
1042 $dispresult = PMA_mysql_query($dispsql);
1043 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1044 $dispval = PMA_mysql_result($dispresult, 0);
1046 else {
1047 $dispval = $GLOBALS['strLinkNotFound'];
1050 else {
1051 $dispval = '';
1052 } // end if... else...
1053 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1055 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1056 . 'lang=' . $lang . '&amp;server=' . $server
1057 . '&amp;convcharset=' . $convcharset
1058 . '&amp;db=' . urlencode($db) . '&amp;table=' . urlencode($map[$meta->name][0])
1059 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1060 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>'
1061 . $row[$pointer] . '</a>';
1062 } else {
1063 $vertical_display['data'][$row_no][$i] .= $row[$pointer];
1065 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1066 } else {
1067 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1070 // b l o b
1072 } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && eregi('BLOB', $meta->type)) {
1073 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1074 // TEXT fields type, however TEXT fields must be displayed
1075 // even if $cfg['ShowBlob'] is false -> get the true type
1076 // of the fields.
1077 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1078 if (eregi('BINARY', $field_flags)) {
1079 $vertical_display['data'][$row_no][$i] = ' <td align="center" valign="top" bgcolor="' . $bgcolor . '">[BLOB]</td>' . "\n";
1080 } else {
1081 //if (!isset($row[$meta->name])
1082 if (!isset($row[$pointer])
1083 || (function_exists('is_null') && is_null($row[$pointer]))) {
1084 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1085 } else if ($row[$pointer] != '') {
1086 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1087 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1089 // loic1: displays all space characters, 4 space
1090 // characters for tabulations and <cr>/<lf>
1091 $row[$pointer] = htmlspecialchars($row[$pointer]);
1092 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1093 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1094 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
1095 } else {
1096 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1099 } else {
1100 //if (!isset($row[$meta->name])
1101 if (!isset($row[$pointer])
1102 || (function_exists('is_null') && is_null($row[$pointer]))) {
1103 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1104 } else if ($row[$pointer] != '') {
1105 // loic1: support blanks in the key
1106 $relation_id = $row[$pointer];
1108 // loic1: Cut text/blob fields even if $cfg['ShowBlob'] is true
1109 if (eregi('BLOB', $meta->type)) {
1110 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1111 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1114 // loic1: displays special characters from binaries
1115 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1116 if (eregi('BINARY', $field_flags)) {
1117 $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]);
1118 $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]);
1119 $row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]);
1120 $row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]);
1121 $row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]);
1122 $row[$pointer] = htmlspecialchars($row[$pointer]);
1124 // loic1: displays all space characters, 4 space
1125 // characters for tabulations and <cr>/<lf>
1126 else {
1127 $row[$pointer] = htmlspecialchars($row[$pointer]);
1128 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1129 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1131 // loic1: do not wrap if date field type
1132 $nowrap = (eregi('DATE|TIME', $meta->type) ? ' nowrap="nowrap"' : '');
1133 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"' . $nowrap . '>';
1135 reset($analyzed_sql[0]['select_expr']);
1136 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1137 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1138 if (!empty($alias)) {
1139 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1140 if ($alias == $meta->name) {
1141 $meta->name = $true_column;
1145 if (isset($map[$meta->name])) {
1146 // Field to display from the foreign table?
1147 if (!empty($map[$meta->name][2])) {
1148 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1149 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1150 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1151 . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
1152 $dispresult = @PMA_mysql_query($dispsql);
1153 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1154 $dispval = PMA_mysql_result($dispresult, 0);
1156 else {
1157 $dispval = $GLOBALS['strLinkNotFound'];
1160 else {
1161 $dispval = '';
1163 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1165 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1166 . 'lang=' . $lang . '&amp;convcharset=' . $convcharset
1167 . '&amp;server=' . $server
1168 . '&amp;db=' . urlencode($db) . '&amp;table=' . urlencode($map[$meta->name][0])
1169 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1170 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1171 . $row[$pointer] . '</a>';
1172 } else {
1173 $vertical_display['data'][$row_no][$i] .= $row[$pointer];
1175 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1176 } else {
1177 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1181 // lem9: output stored cell
1182 if ($disp_direction == 'horizontal') {
1183 echo $vertical_display['data'][$row_no][$i];
1186 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1187 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1188 } else {
1189 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1191 } // end for (2)
1193 // 3. Displays the modify/delete links on the right if required
1194 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1195 && ($disp_direction == 'horizontal')) {
1196 if (!empty($edit_url)) {
1197 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
1198 echo PMA_linkOrButton($edit_url, $edit_str, '');
1199 echo ' </td>' . "\n";
1201 if (!empty($del_url)) {
1202 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
1203 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1204 echo ' </td>' . "\n";
1206 } // end if (3)
1208 if ($disp_direction == 'horizontal') {
1209 echo "\n";
1211 </tr>
1212 <?php
1213 } // end if
1215 // 4. Gather links of del_urls and edit_urls in an array for later
1216 // output
1217 if (!isset($vertical_display['edit'][$row_no])) {
1218 $vertical_display['edit'][$row_no] = '';
1219 $vertical_display['delete'][$row_no] = '';
1222 if (isset($edit_url)) {
1223 $vertical_display['edit'][$row_no] .= ' <td bgcolor="' . $bgcolor . '">' . "\n"
1224 . PMA_linkOrButton($edit_url, $edit_str, '')
1225 . ' </td>' . "\n";
1228 if (isset($del_url)) {
1229 $vertical_display['delete'][$row_no] .= ' <td bgcolor="' . $bgcolor . '">' . "\n"
1230 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''))
1231 . ' </td>' . "\n";
1234 echo (($disp_direction == 'horizontal') ? "\n" : '');
1235 $row_no++;
1236 } // end while
1238 return TRUE;
1239 } // end of the 'PMA_displayTableBody()' function
1243 * Do display the result table with the vertical direction mode.
1244 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1246 * @return boolean always true
1248 * @global array the information to display
1249 * @global integer the number of row to display between two table headers
1251 * @access private
1253 * @see PMA_displayTable()
1255 function PMA_displayVerticalTable()
1257 global $vertical_display, $repeat_cells;
1259 reset($vertical_display);
1261 // Displays "edit" link at top if required
1262 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit'])) {
1263 echo '<tr>' . "\n";
1264 echo $vertical_display['textbtn'];
1265 reset($vertical_display['edit']);
1266 $foo_counter = 0;
1267 while (list($key, $val) = each($vertical_display['edit'])) {
1268 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1269 echo ' <td>&nbsp;</td>' . "\n";
1272 echo $val;
1273 $foo_counter++;
1274 } // end while
1275 echo '</tr>' . "\n";
1276 } // end if
1278 // Displays "delete" link at top if required
1279 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete'])) {
1280 echo '<tr>' . "\n";
1281 if (!is_array($vertical_display['edit'])) {
1282 echo $vertical_display['textbtn'];
1284 reset($vertical_display['delete']);
1285 $foo_counter = 0;
1286 while (list($key, $val) = each($vertical_display['delete'])) {
1287 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1288 echo '<td>&nbsp;</td>' . "\n";
1291 echo $val;
1292 $foo_counter++;
1293 } // end while
1294 echo '</tr>' . "\n";
1295 } // end if
1297 // Displays data
1298 reset($vertical_display['desc']);
1299 while (list($key, $val) = each($vertical_display['desc'])) {
1300 echo '<tr>' . "\n";
1301 echo $val;
1303 $foo_counter = 0;
1304 while (list($subkey, $subval) = each($vertical_display['rowdata'][$key])) {
1305 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1306 echo $val;
1309 echo $subval;
1310 $foo_counter++;
1311 } // end while
1313 echo '</tr>' . "\n";
1314 } // end while
1316 // Displays "edit" link at bottom if required
1317 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit'])) {
1318 echo '<tr>' . "\n";
1319 echo $vertical_display['textbtn'];
1320 reset($vertical_display['edit']);
1321 $foo_counter = 0;
1322 while (list($key, $val) = each($vertical_display['edit'])) {
1323 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1324 echo '<td>&nbsp;</td>' . "\n";
1327 echo $val;
1328 $foo_counter++;
1329 } // end while
1330 echo '</tr>' . "\n";
1331 } // end if
1333 // Displays "delete" link at bottom if required
1334 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete'])) {
1335 echo '<tr>' . "\n";
1336 if (!is_array($vertical_display['edit'])) {
1337 echo $vertical_display['textbtn'];
1339 reset($vertical_display['delete']);
1340 $foo_counter = 0;
1341 while (list($key, $val) = each($vertical_display['delete'])) {
1342 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1343 echo '<td>&nbsp;</td>' . "\n";
1346 echo $val;
1347 $foo_counter++;
1348 } // end while
1349 echo '</tr>' . "\n";
1352 return TRUE;
1353 } // end of the 'PMA_displayVerticalTable' function
1357 * Displays a table of results returned by a sql query.
1358 * This function is called by the "sql.php3" script.
1360 * @param integer the link id associated to the query which results have
1361 * to be displayed
1362 * @param array the display mode
1363 * @param array the analyzed query
1365 * @global string the current language
1366 * @global integer the server to use (refers to the number in the
1367 * configuration file)
1368 * @global array the current server config
1369 * @global string the database name
1370 * @global string the table name
1371 * @global string the url to go back in case of errors
1372 * @global string the current sql query
1373 * @global integer the total number of rows returned by the sql query
1374 * @global integer the total number of rows returned by the sql query
1375 * without any programmatically appended "LIMIT" clause
1376 * @global integer the current postion of the first record to be
1377 * displayed
1378 * @global array the list of fields properties
1379 * @global integer the total number of fields returned by the sql query
1380 * @global array informations used with vertical display mode
1381 * @global string the display mode (horizontal/vertical)
1382 * @global integer the number of row to display between two table headers
1383 * @global boolean whether to limit the number of displayed characters of
1384 * text type fields or not
1385 * @global array the relation settings
1387 * @access private
1389 * @see PMA_showMessage(), PMA_setDisplayMode(),
1390 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1391 * PMA_displayTableBody()
1393 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1395 global $lang, $server, $cfg, $db, $table;
1396 global $goto;
1397 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1398 global $vertical_display, $disp_direction, $repeat_cells;
1399 global $dontlimitchars;
1400 global $cfgRelation;
1402 // 1. ----- Prepares the work -----
1404 // 1.1 Gets the informations about which functionnalities should be
1405 // displayed
1406 $total = '';
1407 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1408 if ($total == '') {
1409 unset($total);
1412 // 1.2 Defines offsets for the next and previous pages
1413 if ($is_display['nav_bar'] == '1') {
1414 if (!isset($pos)) {
1415 $pos = 0;
1417 if ($GLOBALS['session_max_rows'] == 'all') {
1418 $pos_next = 0;
1419 $pos_prev = 0;
1420 } else {
1421 $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
1422 $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
1423 if ($pos_prev < 0) {
1424 $pos_prev = 0;
1427 } // end if
1429 // 1.3 Urlencodes the query to use in input form fields ($sql_query
1430 // will be stripslashed in 'sql.php3' if the 'magic_quotes_gpc'
1431 // directive is set to 'on')
1432 if (get_magic_quotes_gpc()) {
1433 $encoded_sql_query = urlencode(addslashes($sql_query));
1434 } else {
1435 $encoded_sql_query = urlencode($sql_query);
1438 // 2. ----- Displays the top of the page -----
1440 // 2.1 Displays a messages with position informations
1441 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1442 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1443 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1444 } else {
1445 $selectstring = '';
1447 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1448 ? $total - 1
1449 : $pos_next - 1;
1450 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ')');
1451 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1452 PMA_showMessage($GLOBALS['strSQLQuery']);
1455 // 2.3 Displays the navigation bars
1456 if (!isset($table) || strlen(trim($table)) == 0) {
1457 $table = $fields_meta[0]->table;
1459 if ($is_display['nav_bar'] == '1') {
1460 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1461 echo "\n";
1462 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1463 echo "\n" . '<br /><br />' . "\n";
1466 // 2b ----- Get field references from Database -----
1467 // (see the 'relation' config variable)
1468 // loic1, 2002-03-02: extended to php3
1470 // init map
1471 $map = array();
1473 if ($cfgRelation['relwork']) {
1474 // find tables
1475 //$pattern = '`?[[:space:]]+(((ON|on)[[:space:]]+[^,]+)?,|((NATURAL|natural)[[:space:]]+)?(INNER|inner|LEFT|left|RIGHT|right)([[:space:]]+(OUTER|outer))?[[:space:]]+(JOIN|join))[[:space:]]*`?';
1476 //$target = eregi_replace('^.*[[:space:]]+FROM[[:space:]]+`?|`?[[:space:]]*(ON[[:space:]]+[^,]+)?(WHERE[[:space:]]+.*)?$', '', $sql_query);
1477 //$target = eregi_replace('`?[[:space:]]ORDER BY[[:space:]](.*)','',$target);
1478 //$tabs = '(\'' . join('\',\'', split($pattern, $target)) . '\')';
1479 $target=array();
1480 reset($analyzed_sql[0]['table_ref']);
1481 while (list ($table_ref_position, $table_ref) = each ($analyzed_sql[0]['table_ref'])) {
1482 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1484 $tabs = '(\'' . join('\',\'', $target) . '\')';
1486 $local_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
1487 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
1488 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
1489 . ' AND master_table IN ' . $tabs;
1490 $result = @PMA_query_as_cu($local_query, FALSE);
1491 if ($result) {
1492 while ($rel = PMA_mysql_fetch_row($result)) {
1493 // check for display field?
1494 if ($cfgRelation['displaywork']) {
1495 $display_field = PMA_getDisplayField($db, $rel[2]);
1496 } // end if
1497 $map[$rel[0]] = array($rel[2], $rel[3], $display_field);
1498 } // end while
1499 } // end if
1500 } // end 2b
1502 // 3. ----- Displays the results table -----
1503 echo '<!-- Results table -->' . "\n"
1504 . '<table ';
1505 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1506 echo 'border="1" cellpadding="2" cellspacing="0"';
1507 } else {
1508 echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="5"';
1510 echo '>' . "\n";
1511 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt);
1512 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1513 // lem9: vertical output case
1514 if ($disp_direction == 'vertical') {
1515 PMA_displayVerticalTable();
1516 } // end if
1517 unset($vertical_display);
1519 </table>
1520 <?php
1522 echo "\n";
1524 // 4. ----- Displays the navigation bar at the bottom if required -----
1526 if ($is_display['nav_bar'] == '1') {
1527 echo '<br />' . "\n";
1528 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1529 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1530 echo "\n" . '<br /><br />' . "\n";
1532 } // end of the 'PMA_displayTable()' function
1534 } // $__PMA_DISPLAY_TBL_LIB__