Fixed variable usage.
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php3
blob2deb8a0f3dfd82d2f9df446fb10e511f44e24fa5
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 */
9 if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
10 define('PMA_DISPLAY_TBL_LIB_INCLUDED', 1);
12 /**
13 * Defines the display mode to use for the results of a sql query
15 * It uses a synthetic string that contains all the required informations.
16 * In this string:
17 * - the first two characters stand for the action to do while
18 * clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
19 * edit link...);
20 * - the next two characters stand for the action to do while
21 * clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
22 * no delete link...);
23 * - the next characters are boolean values (1/0) and respectively stand
24 * for sorting links, navigation bar, "insert a new row" link, the
25 * bookmark feature, the expand/collapse text/blob fields button and
26 * the "display printable view" option.
27 * Of course '0'/'1' means the feature won't/will be enabled.
29 * @param string the synthetic value for display_mode (see ยง1 a few
30 * lines above for explanations)
31 * @param integer the total number of rows returned by the sql query
32 * without any programmatically appended "LIMIT" clause
33 * (just a copy of $unlim_num_rows if it exists, else
34 * computed inside this function)
36 * @return array an array with explicit indexes for all the display
37 * elements
39 * @global string the database name
40 * @global string the table name
41 * @global integer the total number of rows returned by the sql query
42 * without any programmatically appended "LIMIT" clause
43 * @global array the properties of the fields returned by the query
44 * @global string the url to return to in case of error in a sql
45 * statement
47 * @access private
49 * @see PMA_displayTable()
51 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
53 global $db, $table;
54 global $unlim_num_rows, $fields_meta;
55 global $err_url;
57 // 1. Initializes the $do_display array
58 $do_display = array();
59 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
60 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
61 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
62 $do_display['nav_bar'] = (string) $the_disp_mode[5];
63 $do_display['ins_row'] = (string) $the_disp_mode[6];
64 $do_display['bkm_form'] = (string) $the_disp_mode[7];
65 $do_display['text_btn'] = (string) $the_disp_mode[8];
66 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
68 // 2. Display mode is not "false for all elements" -> updates the
69 // display mode
70 if ($the_disp_mode != 'nnnn000000') {
71 // 2.0 Print view -> set all elements to FALSE!
72 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
73 $do_display['edit_lnk'] = 'nn'; // no edit link
74 $do_display['del_lnk'] = 'nn'; // no delete link
75 $do_display['sort_lnk'] = (string) '0';
76 $do_display['nav_bar'] = (string) '0';
77 $do_display['ins_row'] = (string) '0';
78 $do_display['bkm_form'] = (string) '0';
79 $do_display['text_btn'] = (string) '0';
80 $do_display['pview_lnk'] = (string) '0';
82 // 2.1 Statement is a "SELECT COUNT", a
83 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
84 // contains a "PROC ANALYSE" part
85 else if ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
86 $do_display['edit_lnk'] = 'nn'; // no edit link
87 $do_display['del_lnk'] = 'nn'; // no delete link
88 $do_display['sort_lnk'] = (string) '0';
89 $do_display['nav_bar'] = (string) '0';
90 $do_display['ins_row'] = (string) '0';
91 $do_display['bkm_form'] = (string) '1';
92 $do_display['text_btn'] = (string) '0';
93 $do_display['pview_lnk'] = (string) '1';
95 // 2.2 Statement is a "SHOW..."
96 else if ($GLOBALS['is_show']) {
97 // 2.2.1 TODO : defines edit/delete links depending on show statement
98 $tmp = eregi('^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS)', $GLOBALS['sql_query'], $which);
99 if (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
100 $do_display['edit_lnk'] = 'nn'; // no edit link
101 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
103 else {
104 // Default case -> no links
105 $do_display['edit_lnk'] = 'nn'; // no edit link
106 $do_display['del_lnk'] = 'nn'; // no delete link
108 // 2.2.2 Other settings
109 $do_display['sort_lnk'] = (string) '0';
110 $do_display['nav_bar'] = (string) '0';
111 $do_display['ins_row'] = (string) '0';
112 $do_display['bkm_form'] = (string) '1';
113 $do_display['text_btn'] = (string) '0';
114 $do_display['pview_lnk'] = (string) '1';
116 // 2.3 Other statements (ie "SELECT" ones) -> updates
117 // $do_display['edit_lnk'], $do_display['del_lnk'] and
118 // $do_display['text_btn'] (keeps other default values)
119 else {
120 $prev_table = $fields_meta[0]->table;
121 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
122 $is_link = ($do_display['edit_lnk'] != 'nn'
123 || $do_display['del_lnk'] != 'nn'
124 || $do_display['sort_lnk'] != '0'
125 || $do_display['ins_row'] != '0');
126 // 2.3.1 Displays text cut/expand button?
127 if ($do_display['text_btn'] == '0' && eregi('BLOB', $fields_meta[$i]->type)) {
128 $do_display['text_btn'] = (string) '1';
129 if (!$is_link) {
130 break;
132 } // end if (2.3.1)
133 // 2.3.2 Displays edit/delete/sort/insert links?
134 if ($is_link
135 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
136 $do_display['edit_lnk'] = 'nn'; // don't display links
137 $do_display['del_lnk'] = 'nn';
138 // TODO: May be problematic with same fields names in
139 // two joined table.
140 // $do_display['sort_lnk'] = (string) '0';
141 $do_display['ins_row'] = (string) '0';
142 if ($do_display['text_btn'] == '1') {
143 break;
145 } // end if (2.3.2)
146 // 2.3.3 Always display print view link
147 $do_display['pview_lnk'] = (string) '1';
148 $prev_table = $fields_meta[$i]->table;
149 } // end for
150 } // end if..elseif...else (2.1 -> 2.3)
151 } // end if (2)
153 // 3. Gets the total number of rows if it is unknown
154 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
155 $the_total = $unlim_num_rows;
157 else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
158 && (!empty($db) && !empty($table))) {
159 $local_query = 'SELECT COUNT(*) AS total FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
160 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
161 $the_total = PMA_mysql_result($result, 0, 'total');
162 mysql_free_result($result);
165 // 4. If navigation bar or sorting fields names urls should be
166 // displayed but there is only one row, change these settings to
167 // false
168 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
170 if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
171 // garvin: force display of navbar for vertical/horizontal display-choice.
172 // $do_display['nav_bar'] = (string) '0';
173 $do_display['sort_lnk'] = (string) '0';
176 } // end if (3)
178 // 5. Updates the synthetic var
179 $the_disp_mode = join('', $do_display);
181 return $do_display;
182 } // end of the 'PMA_setDisplayMode()' function
186 * Displays a navigation bar to browse among the results of a sql query
188 * @param integer the offset for the "next" page
189 * @param integer the offset for the "previous" page
190 * @param string the url-encoded query
192 * @global string the current language
193 * @global string the currect charset for MySQL
194 * @global integer the server to use (refers to the number in the
195 * configuration file)
196 * @global string the database name
197 * @global string the table name
198 * @global string the url to go back in case of errors
199 * @global integer the total number of rows returned by the sql query
200 * @global integer the total number of rows returned by the sql query
201 * without any programmatically appended "LIMIT" clause
202 * @global integer the current position in results
203 * @global mixed the maximum number of rows per page ('all' = no limit)
204 * @global string the display mode (horizontal/vertical/horizontalflipped)
205 * @global integer the number of row to display between two table headers
206 * @global boolean whether to limit the number of displayed characters of
207 * text type fields or not
209 * @access private
211 * @see PMA_displayTable()
213 function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
215 global $lang, $convcharset, $server, $db, $table;
216 global $goto;
217 global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
218 global $disp_direction, $repeat_cells;
219 global $dontlimitchars;
222 <!-- Navigation bar -->
223 <table border="0">
224 <tr>
225 <?php
226 // Move to the beginning or to the previous page
227 if ($pos > 0 && $session_max_rows != 'all') {
228 // loic1: patch #474210 from Gosha Sakovich - part 1
229 if ($GLOBALS['cfg']['NavigationBarIconic']) {
230 $caption1 = '&lt;&lt;';
231 $caption2 = '&nbsp;&lt;&nbsp;';
232 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
233 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
234 } else {
235 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
236 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
237 $title1 = '';
238 $title2 = '';
239 } // end if... else...
241 <td>
242 <form action="sql.php3" method="post">
243 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
244 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
245 <input type="hidden" name="pos" value="0" />
246 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
247 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
248 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
249 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
250 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
251 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
252 </form>
253 </td>
254 <td>
255 <form action="sql.php3" method="post">
256 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
257 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
258 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
259 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
260 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
261 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
262 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
263 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
264 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
265 </form>
266 </td>
267 <?php
268 } // end move back
269 echo "\n";
271 <td>
272 &nbsp;&nbsp;&nbsp;
273 </td>
274 <td align="center">
275 <form action="sql.php3" method="post"
276 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', 1) && checkFormElementInRange(this, 'pos', 0, <?php echo $unlim_num_rows - 1; ?>))">
277 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
278 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
279 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
280 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
281 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?>&nbsp;:" />
282 <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()" />
283 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
284 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
285 <br />
286 <?php
287 // Display mode (horizontal/vertical and repeat headers)
288 $param1 = ' <select name="disp_direction">' . "\n"
289 . ' <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
290 . ' <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
291 . ' <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
292 . ' </select>' . "\n"
293 . ' ';
294 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
295 . ' ';
296 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
298 </form>
299 </td>
300 <td>
301 &nbsp;&nbsp;&nbsp;
302 </td>
303 <?php
304 // Move to the next page or to the last one
305 if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
306 && $session_max_rows != 'all') {
307 // loic1: patch #474210 from Gosha Sakovich - part 2
308 if ($GLOBALS['cfg']['NavigationBarIconic']) {
309 $caption3 = '&nbsp;&gt;&nbsp;';
310 $caption4 = '&gt;&gt;';
311 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
312 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
313 } else {
314 $caption3 = '&gt; ' . $GLOBALS['strNext'];
315 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
316 $title3 = '';
317 $title4 = '';
318 } // end if... else...
319 echo "\n";
321 <td>
322 <form action="sql.php3" method="post">
323 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
324 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
325 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
326 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
327 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
328 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
329 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
330 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
331 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
332 </form>
333 </td>
334 <td>
335 <form action="sql.php3" method="post"
336 onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
337 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
338 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
339 <input type="hidden" name="pos" value="<?php echo $unlim_num_rows - $session_max_rows; ?>" />
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 $caption4; ?>"<?php echo $title4; ?> />
346 </form>
347 </td>
348 <?php
349 } // end move toward
351 // Show all the records if allowed
352 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
353 echo "\n";
355 <td>
356 &nbsp;&nbsp;&nbsp;
357 </td>
358 <td>
359 <form action="sql.php3" method="post">
360 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
361 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
362 <input type="hidden" name="pos" value="0" />
363 <input type="hidden" name="session_max_rows" value="all" />
364 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
365 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
366 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
367 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
368 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
369 </form>
370 </td>
371 <?php
372 } // end show all
373 echo "\n";
375 </tr>
376 </table>
378 <?php
379 } // end of the 'PMA_displayTableNavigation()' function
383 * Displays the headers of the results table
385 * @param array which elements to display
386 * @param array the list of fields properties
387 * @param integer the total number of fields returned by the sql query
389 * @return boolean always true
391 * @global string the current language
392 * @global string the current charset for MySQL
393 * @global integer the server to use (refers to the number in the
394 * configuration file)
395 * @global string the database name
396 * @global string the table name
397 * @global string the sql query
398 * @global string the url to go back in case of errors
399 * @global integer the total number of rows returned by the sql query
400 * @global integer the current position in results
401 * @global integer the maximum number of rows per page
402 * @global array informations used with vertical display mode
403 * @global string the display mode (horizontal/vertical/horizontalflipped)
404 * @global integer the number of row to display between two table headers
405 * @global boolean whether to limit the number of displayed characters of
406 * text type fields or not
408 * @access private
410 * @see PMA_displayTable()
412 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0)
414 global $lang, $convcharset, $server, $db, $table;
415 global $goto;
416 global $sql_query, $num_rows, $pos, $session_max_rows;
417 global $vertical_display, $disp_direction, $repeat_cells;
418 global $dontlimitchars;
420 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
422 <!-- Results table headers -->
423 <tr>
424 <?php
425 echo "\n";
428 $vertical_display['emptypre'] = 0;
429 $vertical_display['emptyafter'] = 0;
430 $vertical_display['textbtn'] = '';
432 // 1. Displays the full/partial text button (part 1)...
433 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
434 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
435 ? ' colspan="2"'
436 : '';
437 } else {
438 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
439 ? ' rowspan="2"'
440 : '';
442 $text_url = 'sql.php3?'
443 . PMA_generate_common_url($db, $table)
444 . '&amp;sql_query=' . urlencode($sql_query)
445 . '&amp;pos=' . $pos
446 . '&amp;session_max_rows=' . $session_max_rows
447 . '&amp;pos=' . $pos
448 . '&amp;disp_direction=' . $disp_direction
449 . '&amp;repeat_cells=' . $repeat_cells
450 . '&amp;goto=' . $goto
451 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
453 // ... before the result table
454 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
455 && $is_display['text_btn'] == '1') {
456 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
457 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
459 <td colspan="<?php echo $fields_cnt; ?>" align="center">
460 <a href="<?php echo $text_url; ?>">
461 <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>
462 </td>
463 </tr>
465 <tr>
466 <?php
467 } // end horizontal/horizontalflipped mode
468 else {
469 echo "\n";
471 <tr>
472 <td colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
473 <a href="<?php echo $text_url; ?>">
474 <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>
475 </td>
476 </tr>
477 <?php
478 } // end vertical mode
481 // ... at the left column of the result table header if possible
482 // and required
483 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
484 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
485 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
486 echo "\n";
488 <td<?php echo $colspan; ?> align="center">
489 <a href="<?php echo $text_url; ?>">
490 <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>
491 </td>
492 <?php
493 } // end horizontal/horizontalflipped mode
494 else {
495 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
496 . ' <a href="' . $text_url . '">' . "\n"
497 . ' <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"
498 . ' </td>' . "\n";
499 } // end vertical mode
502 // ... else if no button, displays empty(ies) col(s) if required
503 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
504 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
505 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
506 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
507 echo "\n";
509 <td<?php echo $colspan; ?>></td>
510 <?php
511 echo "\n";
512 } // end horizontal/horizontalfipped mode
513 else {
514 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
515 } // end vertical mode
518 // 2. Displays the fields' name
519 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
520 // statement (see 2.1.3)
522 // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
523 // Do not show comments, if using horizontalflipped mode, because of space usage
524 if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
525 $comments_map = PMA_getComments($db, $table);
526 } else {
527 $comments_map = array();
530 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfg']['BrowseMIME']) {
531 require('./libraries/transformations.lib.php3');
532 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
536 if ($is_display['sort_lnk'] == '1') {
537 $is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
538 } else {
539 $is_join = FALSE;
541 for ($i = 0; $i < $fields_cnt; $i++) {
543 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
544 if (isset($comments_map[$fields_meta[$i]->name])) {
545 $comments_table_wrap_pre = '<table border="0" cellpadding="0" cellspacing="0"><tr><th>';
546 $comments_table_wrap_post = '</th></tr><tr><th style="font-size: 8pt; font-weight: normal">' . htmlspecialchars($comments_map[$fields_meta[$i]->name]) . '</td></tr></table>';
547 } else {
548 $comments_table_wrap_pre = '';
549 $comments_table_wrap_post = '';
552 // 2.1 Results can be sorted
553 if ($is_display['sort_lnk'] == '1') {
554 // Defines the url used to append/modify a sorting order
555 // 2.1.1 Checks if an hard coded 'order by' clause exists
556 if (eregi('(.*)([[:space:]]ORDER[[:space:]]*BY[[:space:]](.*))', $sql_query, $regs1)) {
557 if (eregi('((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)', $regs1[2], $regs2)) {
558 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
559 $sql_order = trim($regs2[1]);
560 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
561 $sort_expression = trim($after_order[2]);
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 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
567 $sort_expression = trim($after_order[2]);
568 } else {
569 $unsorted_sql_query = trim($regs1[1]);
570 $sql_order = trim($regs1[2]) . ' ASC';
571 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
572 $sort_expression = trim($after_order[2]);
574 } else {
575 $unsorted_sql_query = $sql_query;
578 // 2.1.2 Checks if the current column is used to sort the
579 // results
580 if (empty($sql_order)) {
581 $is_in_sort = FALSE;
582 } else {
583 // $pattern = str_replace('\\', '\\\\', $fields_meta[$i]->name);
584 // $pattern = str_replace('(','\(', $pattern);
585 // $pattern = str_replace(')','\)', $pattern);
586 // $pattern = str_replace('*','\*', $pattern);
588 // field name may be preceded by a space, or any number
589 // of characters followed by a dot (tablename.fieldname)
590 // $is_in_sort = eregi('([[:space:]]|(.*\.))(`?)' . $pattern . '(`?)[ ,$]', $sql_order);
591 // instead of using eregi(), now do a direct comparison
592 // for the sort expression (avoids problems with queries
593 // like "SELECT id, count(id)..." and clicking to sort
594 // on id or on count(id) )
595 $is_in_sort = (PMA_backquote($fields_meta[$i]->name) == $sort_expression ? TRUE : FALSE);
597 // 2.1.3 Checks if the table name is required (it's the case
598 // for a query with a "JOIN" statement and if the column
599 // isn't aliased)
600 if ($is_join
601 && !eregi('([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name, $select_stt[1], $parts)) {
602 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
603 } else {
604 $sort_tbl = '';
606 // 2.1.4 Check the field name for backquotes.
607 // If it contains some, it's probably a function column
608 // like 'COUNT(`field`)'
609 if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
610 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
611 } else {
612 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
614 // 2.1.5 Do define the sorting url
615 if (!$is_in_sort) {
616 // loic1: patch #455484 ("Smart" order)
617 $cfg['Order'] = strtoupper($GLOBALS['cfg']['Order']);
618 if ($cfg['Order'] == 'SMART') {
619 $cfg['Order'] = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
621 $sort_order .= $cfg['Order'];
622 $order_img = '';
624 else if (eregi('[[:space:]]ASC$', $sql_order)) {
625 $sort_order .= ' DESC';
626 $order_img = '&nbsp;<img src="./images/asc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" />';
628 else if (eregi('[[:space:]]DESC$', $sql_order)) {
629 $sort_order .= ' ASC';
630 $order_img = '&nbsp;<img src="./images/desc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" />';
632 if (eregi('(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))', $unsorted_sql_query, $regs3)) {
633 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
634 } else {
635 $sorted_sql_query = $unsorted_sql_query . $sort_order;
637 $url_query = PMA_generate_common_url($db, $table)
638 . '&amp;pos=' . $pos
639 . '&amp;session_max_rows=' . $session_max_rows
640 . '&amp;disp_direction=' . $disp_direction
641 . '&amp;repeat_cells=' . $repeat_cells
642 . '&amp;dontlimitchars=' . $dontlimitchars
643 . '&amp;sql_query=' . urlencode($sorted_sql_query);
645 // 2.1.5 Displays the sorting url
646 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
647 echo "\n";
649 <th <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
650 <?php echo $comments_table_wrap_pre; ?>
651 <a href="sql.php3?<?php echo $url_query; ?>" <?php echo (($disp_direction == 'horizontalflipped' AND $GLOBALS['cfg']['HeaderFlipType'] == 'css') ? 'style = "direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
652 <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)); ?></a><?php echo $order_img . "\n"; ?>
653 <?php echo $comments_table_wrap_post; ?>
654 </th>
655 <?php
657 $vertical_display['desc'][] = ' <th>' . "\n"
658 . $comments_table_wrap_pre
659 . ' <a href="sql.php3?' . $url_query . '">' . "\n"
660 . ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
661 . $comments_table_wrap_post
662 . ' </th>' . "\n";
663 } // end if (2.1)
665 // 2.2 Results can't be sorted
666 else {
667 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
668 echo "\n";
670 <th <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style = "direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
671 <?php echo $comments_table_wrap_pre; ?>
672 <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
673 <?php echo $comments_table_wrap_post; ?>
674 </th>
675 <?php
677 $vertical_display['desc'][] = ' <th>' . "\n"
678 . $comments_table_wrap_pre
679 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
680 . $comments_table_wrap_post
681 . ' </th>';
682 } // end else (2.2)
683 } // end for
685 // 3. Displays the full/partial text button (part 2) at the right
686 // column of the result table header if possible and required...
687 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
688 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
689 && $is_display['text_btn'] == '1') {
690 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
691 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
692 echo "\n";
694 <td<?php echo $colspan; ?> align="center">
695 <a href="<?php echo $text_url; ?>">
696 <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>
697 </td>
698 <?php
699 } // end horizontal/horizontalflipped mode
700 else {
701 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
702 . ' <a href="' . $text_url . '">' . "\n"
703 . ' <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"
704 . ' </td>' . "\n";
705 } // end vertical mode
708 // ... else if no button, displays empty cols if required
709 // (unless coming from Browse mode print view)
710 else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
711 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
712 && (!$GLOBALS['is_header_sent'])) {
713 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
714 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
715 echo "\n";
717 <td<?php echo $colspan; ?>></td>
718 <?php
719 } // end horizontal/horizontalflipped mode
720 else {
721 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
722 } // end vertical mode
725 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
726 echo "\n";
728 </tr>
729 <?php
731 echo "\n";
733 return TRUE;
734 } // end of the 'PMA_displayTableHeaders()' function
739 * Displays the body of the results table
741 * @param integer the link id associated to the query which results have
742 * to be displayed
743 * @param array which elements to display
744 * @param array the list of relations
745 * @param array the analyzed query
747 * @return boolean always true
749 * @global string the current language
750 * @global string the current charset for MySQL
751 * @global integer the server to use (refers to the number in the
752 * configuration file)
753 * @global string the database name
754 * @global string the table name
755 * @global string the sql query
756 * @global string the url to go back in case of errors
757 * @global integer the current position in results
758 * @global integer the maximum number of rows per page
759 * @global array the list of fields properties
760 * @global integer the total number of fields returned by the sql query
761 * @global array informations used with vertical display mode
762 * @global string the display mode (horizontal/vertical/horizontalflipped)
763 * @global integer the number of row to display between two table headers
764 * @global boolean whether to limit the number of displayed characters of
765 * text type fields or not
767 * @access private
769 * @see PMA_displayTable()
771 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
773 global $lang, $convcharset, $server, $db, $table;
774 global $goto;
775 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
776 global $vertical_display, $disp_direction, $repeat_cells;
777 global $dontlimitchars;
779 if (!is_array($map)) {
780 $map = array();
783 <!-- Results table body -->
784 <?php
785 echo "\n";
787 $row_no = 0;
788 $vertical_display['edit'] = array();
789 $vertical_display['delete'] = array();
790 $vertical_display['data'] = array();
792 // Correction uva 19991216 in the while below
793 // Previous code assumed that all tables have keys, specifically that
794 // the phpMyAdmin GUI should support row delete/edit only for such
795 // tables.
796 // Although always using keys is arguably the prescribed way of
797 // defining a relational table, it is not required. This will in
798 // particular be violated by the novice.
799 // We want to encourage phpMyAdmin usage by such novices. So the code
800 // below has been changed to conditionally work as before when the
801 // table being displayed has one or more keys; but to display
802 // delete/edit options correctly for tables without keys.
804 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
805 // to get the NULL values
807 while ($row = PMA_mysql_fetch_array($dt_result)) {
809 // lem9: "vertical display" mode stuff
810 if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
811 echo '<tr>' . "\n";
813 for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
814 echo ' <td>&nbsp;</td>' . "\n";
817 reset($vertical_display['desc']);
818 while (list($key, $val) = each($vertical_display['desc'])) {
819 echo $val;
822 for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
823 echo ' <td>&nbsp;</td>' . "\n";
826 echo '</tr>' . "\n";
827 } // end if
829 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
830 $bgcolor = '#ffffff';
831 } else {
832 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
835 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
836 // loic1: pointer code part
837 $on_mouse = '';
838 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
839 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
840 $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
841 . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
843 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
844 $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
846 } // end if
848 <tr<?php echo $on_mouse; ?>>
849 <?php
850 echo "\n";
853 // 1. Prepares the row (gets primary keys to use)
854 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
855 $primary_key = '';
856 $unique_key = '';
857 $uva_nonprimary_condition = '';
859 // 1.1 Results from a "SELECT" statement -> builds the
860 // "primary" key to use in links
861 if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
862 for ($i = 0; $i < $fields_cnt; ++$i) {
863 $meta = $fields_meta[$i];
865 // do not use an alias in a condition
866 $column_for_condition = $meta->name;
867 reset($analyzed_sql[0]['select_expr']);
868 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
869 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
870 if (!empty($alias)) {
871 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
872 if ($alias == $meta->name) {
873 $column_for_condition = $true_column;
874 } // end if
875 } // end if
876 } // end while
878 // to fix the bug where float fields (primary or not)
879 // can't be matched because of the imprecision of
880 // floating comparison, use CONCAT
881 // (also, the syntax "CONCAT(field) IS NULL"
882 // that we need on the next "if" will work)
883 if ($meta->type == 'real') {
884 $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
885 } else {
886 $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
887 } // end if... else...
889 // loic1: To fix bug #474943 under php4, the row
890 // pointer will depend on whether the "is_null"
891 // php4 function is available or not
892 $pointer = (function_exists('is_null') ? $i : $meta->name);
893 if (!isset($row[$meta->name])
894 || (function_exists('is_null') && is_null($row[$pointer]))) {
895 $condition .= 'IS NULL AND';
896 } else {
897 $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer]) . '\' AND';
899 if ($meta->primary_key > 0) {
900 $primary_key .= $condition;
901 } else if ($meta->unique_key > 0) {
902 $unique_key .= $condition;
904 $uva_nonprimary_condition .= $condition;
905 } // end for
907 // Correction uva 19991216: prefer primary or unique keys
908 // for condition, but use conjunction of all values if no
909 // primary key
910 if ($primary_key) {
911 $uva_condition = $primary_key;
912 } else if ($unique_key) {
913 $uva_condition = $unique_key;
914 } else {
915 $uva_condition = $uva_nonprimary_condition;
917 $uva_condition = urlencode(ereg_replace('[[:space:]]?AND$', '', $uva_condition));
918 } // end if (1.1)
920 // 1.2 Defines the urls for the modify/delete link(s)
921 $url_query = PMA_generate_common_url($db, $table)
922 . '&amp;pos=' . $pos
923 . '&amp;session_max_rows=' . $session_max_rows
924 . '&amp;disp_direction=' . $disp_direction
925 . '&amp;repeat_cells=' . $repeat_cells
926 . '&amp;dontlimitchars=' . $dontlimitchars;
928 // 1.2.1 Modify link(s)
929 if ($is_display['edit_lnk'] == 'ur') { // update row case
930 // $lnk_goto = 'sql.php3'
931 // . '?' . str_replace('&amp;', '&', $url_query)
932 // . '&sql_query=' . urlencode($sql_query)
933 // . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
934 // to reduce the length of the URL, because of some browsers limitations:
935 $lnk_goto = 'sql.php3';
937 $edit_url = 'tbl_change.php3'
938 . '?' . $url_query
939 . '&amp;primary_key=' . $uva_condition
940 . '&amp;sql_query=' . urlencode($sql_query)
941 . '&amp;goto=' . urlencode($lnk_goto);
942 $edit_str = $GLOBALS['strEdit'];
943 } // end if (1.2.1)
945 // 1.2.2 Delete/Kill link(s)
946 if ($is_display['del_lnk'] == 'dr') { // delete row case
947 $lnk_goto = 'sql.php3'
948 . '?' . str_replace('&amp;', '&', $url_query)
949 . '&sql_query=' . urlencode($sql_query)
950 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
951 . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
952 $del_url = 'sql.php3'
953 . '?' . $url_query
954 . '&amp;sql_query=' . urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . ((PMA_MYSQL_INT_VERSION >= 32207) ? urlencode(' LIMIT 1') : '')
955 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
956 . '&amp;goto=' . urlencode($lnk_goto);
957 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
958 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
959 . ((PMA_MYSQL_INT_VERSION >= 32207) ? ' LIMIT 1' : '');
960 $del_str = $GLOBALS['strDelete'];
961 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
962 $lnk_goto = 'sql.php3'
963 . '?' . str_replace('&amp;', '&', $url_query)
964 . '&sql_query=' . urlencode($sql_query)
965 . '&goto=main.php3';
966 $del_url = 'sql.php3?'
967 . PMA_generate_common_url('mysql')
968 . '&amp;sql_query=' . urlencode('KILL ' . $row['Id'])
969 . '&amp;goto=' . urlencode($lnk_goto);
970 $js_conf = 'KILL ' . $row['Id'];
971 $del_str = $GLOBALS['strKill'];
972 } // end if (1.2.2)
974 // 1.3 Displays the links at left if required
975 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
976 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
977 if (!empty($edit_url)) {
978 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
979 echo PMA_linkOrButton($edit_url, $edit_str, '');
980 echo ' </td>' . "\n";
982 if (!empty($del_url)) {
983 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
984 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
985 echo ' </td>' . "\n";
987 } // end if (1.3)
988 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
989 } // end if (1)
991 // 2. Displays the rows' values
992 for ($i = 0; $i < $fields_cnt; ++$i) {
993 $meta = $fields_meta[$i];
994 // loic1: To fix bug #474943 under php4, the row pointer will
995 // depend on whether the "is_null" php4 function is
996 // available or not
997 $pointer = (function_exists('is_null') ? $i : $meta->name);
999 // garvin: Wrap MIME-transformations. [MIME]
1000 $default_function = 'htmlspecialchars'; // default_function
1001 $transform_function = $default_function;
1002 $transform_options = array();
1004 if ($GLOBALS['cfg']['BrowseMIME']) {
1006 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1007 // garvin: for security, never allow to break out from transformations directory
1008 $include_file = eregi_replace('^[\./]*(.*)', '\1', $GLOBALS['mime_map'][$meta->name]['transformation']);
1010 $transformfunction_name = str_replace('.inc.php3', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1012 include('./libraries/transformations/' . $include_file);
1014 if (defined('PMA_TRANSFORMATION_' . strtoupper($transformfunction_name)) && function_exists('PMA_transformation_' . $transformfunction_name)) {
1016 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1017 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1025 $transform_options['wrapper_link'] = '?'
1026 . (isset($url_query) ? $url_query : '')
1027 . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '')
1028 . '&amp;sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '')
1029 . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1030 . '&amp;transform_key=' . urlencode($meta->name);
1033 // n u m e r i c
1034 if ($meta->numeric == 1) {
1036 // lem9: if two fields have the same name (this is possible
1037 // with self-join queries, for example), using $meta->name
1038 // will show both fields NULL even if only one is NULL,
1039 // so use the $pointer
1040 // (works only if function_exists('is_null')
1041 // PS: why not always work with the number ($i), since
1042 // the default second parameter of
1043 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1044 // associative and numeric indices?
1046 //if (!isset($row[$meta->name])
1047 if (!isset($row[$pointer])
1048 || (function_exists('is_null') && is_null($row[$pointer]))) {
1049 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1050 } else if ($row[$pointer] != '') {
1051 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '">';
1053 reset($analyzed_sql[0]['select_expr']);
1054 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1055 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1056 if (!empty($alias)) {
1057 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1058 if ($alias == $meta->name) {
1059 $meta->name = $true_column;
1060 } // end if
1061 } // end if
1062 } // end while
1064 if (isset($map[$meta->name])) {
1065 // Field to display from the foreign table?
1066 if (!empty($map[$meta->name][2])) {
1067 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1068 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1069 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1070 . ' = ' . $row[$pointer];
1071 $dispresult = PMA_mysql_query($dispsql);
1072 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1073 $dispval = PMA_mysql_result($dispresult, 0);
1075 else {
1076 $dispval = $GLOBALS['strLinkNotFound'];
1079 else {
1080 $dispval = '';
1081 } // end if... else...
1082 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1084 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1085 . PMA_generate_common_url($db, $map[$meta->name][0])
1086 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1087 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>'
1088 . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer])) . '</a>';
1089 } else {
1090 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer]));
1092 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1093 } else {
1094 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1097 // b l o b
1099 } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && eregi('BLOB', $meta->type)) {
1100 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1101 // TEXT fields type, however TEXT fields must be displayed
1102 // even if $cfg['ShowBlob'] is false -> get the true type
1103 // of the fields.
1104 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1106 if (eregi('BINARY', $field_flags)) {
1107 $blobtext = '[BLOB';
1108 if (isset($row[$pointer])) {
1109 $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
1110 $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
1111 unset($blob_size);
1114 $blobtext .= ']';
1115 $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options) : $default_function($blobtext));
1117 $vertical_display['data'][$row_no][$i] = ' <td align="center" valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
1118 } else {
1119 //if (!isset($row[$meta->name])
1120 if (!isset($row[$pointer])
1121 || (function_exists('is_null') && is_null($row[$pointer]))) {
1122 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1123 } else if ($row[$pointer] != '') {
1124 // garvin: if a transform function for blob is set, none of these replacements will be made
1125 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1126 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1128 // loic1: displays all space characters, 4 space
1129 // characters for tabulations and <cr>/<lf>
1131 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1132 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1133 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1135 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
1136 } else {
1137 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1140 } else {
1141 //if (!isset($row[$meta->name])
1142 if (!isset($row[$pointer])
1143 || (function_exists('is_null') && is_null($row[$pointer]))) {
1144 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1145 } else if ($row[$pointer] != '') {
1146 // loic1: support blanks in the key
1147 $relation_id = $row[$pointer];
1149 // loic1: Cut text/blob fields even if $cfg['ShowBlob'] is true
1150 if (eregi('BLOB', $meta->type)) {
1151 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1152 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1155 // loic1: displays special characters from binaries
1156 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1157 if (eregi('BINARY', $field_flags)) {
1158 $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]);
1159 $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]);
1160 $row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]);
1161 $row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]);
1162 $row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]);
1163 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1165 // loic1: displays all space characters, 4 space
1166 // characters for tabulations and <cr>/<lf>
1167 else {
1168 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1169 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1170 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1173 // loic1: do not wrap if date field type
1174 $nowrap = (eregi('DATE|TIME', $meta->type) ? ' nowrap="nowrap"' : '');
1175 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"' . $nowrap . '>';
1177 reset($analyzed_sql[0]['select_expr']);
1178 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1179 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1180 if (!empty($alias)) {
1181 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1182 if ($alias == $meta->name) {
1183 $meta->name = $true_column;
1184 } // end if
1185 } // end if
1186 } // end while
1188 if (isset($map[$meta->name])) {
1189 // Field to display from the foreign table?
1190 if (!empty($map[$meta->name][2])) {
1191 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1192 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1193 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1194 . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
1195 $dispresult = @PMA_mysql_query($dispsql);
1196 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1197 $dispval = PMA_mysql_result($dispresult, 0);
1199 else {
1200 $dispval = $GLOBALS['strLinkNotFound'];
1203 else {
1204 $dispval = '';
1206 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1208 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1209 . PMA_generate_common_url($db, $map[$meta->name][0])
1210 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1211 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1212 . $row[$pointer] . '</a>';
1213 } else {
1214 $vertical_display['data'][$row_no][$i] .= $row[$pointer];
1216 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1217 } else {
1218 $vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1222 // lem9: output stored cell
1223 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1224 echo $vertical_display['data'][$row_no][$i];
1227 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1228 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1229 } else {
1230 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1232 } // end for (2)
1234 // 3. Displays the modify/delete links on the right if required
1235 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1236 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1237 if (!empty($edit_url)) {
1238 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
1239 echo PMA_linkOrButton($edit_url, $edit_str, '');
1240 echo ' </td>' . "\n";
1242 if (!empty($del_url)) {
1243 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
1244 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1245 echo ' </td>' . "\n";
1247 } // end if (3)
1249 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1250 echo "\n";
1252 </tr>
1253 <?php
1254 } // end if
1256 // 4. Gather links of del_urls and edit_urls in an array for later
1257 // output
1258 if (!isset($vertical_display['edit'][$row_no])) {
1259 $vertical_display['edit'][$row_no] = '';
1260 $vertical_display['delete'][$row_no] = '';
1263 if (isset($edit_url)) {
1264 $vertical_display['edit'][$row_no] .= ' <td bgcolor="' . $bgcolor . '">' . "\n"
1265 . PMA_linkOrButton($edit_url, $edit_str, '')
1266 . ' </td>' . "\n";
1269 if (isset($del_url)) {
1270 $vertical_display['delete'][$row_no] .= ' <td bgcolor="' . $bgcolor . '">' . "\n"
1271 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''))
1272 . ' </td>' . "\n";
1275 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1276 $row_no++;
1277 } // end while
1279 return TRUE;
1280 } // end of the 'PMA_displayTableBody()' function
1284 * Do display the result table with the vertical direction mode.
1285 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1287 * @return boolean always true
1289 * @global array the information to display
1290 * @global integer the number of row to display between two table headers
1292 * @access private
1294 * @see PMA_displayTable()
1296 function PMA_displayVerticalTable()
1298 global $vertical_display, $repeat_cells;
1300 reset($vertical_display);
1302 // Displays "edit" link at top if required
1303 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit'])) {
1304 echo '<tr>' . "\n";
1305 echo $vertical_display['textbtn'];
1306 reset($vertical_display['edit']);
1307 $foo_counter = 0;
1308 while (list($key, $val) = each($vertical_display['edit'])) {
1309 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1310 echo ' <td>&nbsp;</td>' . "\n";
1313 echo $val;
1314 $foo_counter++;
1315 } // end while
1316 echo '</tr>' . "\n";
1317 } // end if
1319 // Displays "delete" link at top if required
1320 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete'])) {
1321 echo '<tr>' . "\n";
1322 if (!is_array($vertical_display['edit'])) {
1323 echo $vertical_display['textbtn'];
1325 reset($vertical_display['delete']);
1326 $foo_counter = 0;
1327 while (list($key, $val) = each($vertical_display['delete'])) {
1328 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1329 echo '<td>&nbsp;</td>' . "\n";
1332 echo $val;
1333 $foo_counter++;
1334 } // end while
1335 echo '</tr>' . "\n";
1336 } // end if
1338 // Displays data
1339 reset($vertical_display['desc']);
1340 $row_no = 0;
1341 while (list($key, $val) = each($vertical_display['desc'])) {
1342 $row_no++;
1344 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
1345 $bgcolor = '#ffffff';
1346 } else {
1347 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1350 $on_mouse = '';
1351 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
1352 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
1353 $on_mouse = ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1354 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1356 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
1357 $on_mouse .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1359 } // end if
1361 echo '<tr ' . $on_mouse . '>' . "\n";
1362 echo $val;
1364 $foo_counter = 0;
1365 while (list($subkey, $subval) = each($vertical_display['rowdata'][$key])) {
1366 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1367 echo $val;
1370 echo $subval;
1371 $foo_counter++;
1372 } // end while
1374 echo '</tr>' . "\n";
1375 } // end while
1377 // Displays "edit" link at bottom if required
1378 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit'])) {
1379 echo '<tr>' . "\n";
1380 echo $vertical_display['textbtn'];
1381 reset($vertical_display['edit']);
1382 $foo_counter = 0;
1383 while (list($key, $val) = each($vertical_display['edit'])) {
1384 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1385 echo '<td>&nbsp;</td>' . "\n";
1388 echo $val;
1389 $foo_counter++;
1390 } // end while
1391 echo '</tr>' . "\n";
1392 } // end if
1394 // Displays "delete" link at bottom if required
1395 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete'])) {
1396 echo '<tr>' . "\n";
1397 if (!is_array($vertical_display['edit'])) {
1398 echo $vertical_display['textbtn'];
1400 reset($vertical_display['delete']);
1401 $foo_counter = 0;
1402 while (list($key, $val) = each($vertical_display['delete'])) {
1403 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1404 echo '<td>&nbsp;</td>' . "\n";
1407 echo $val;
1408 $foo_counter++;
1409 } // end while
1410 echo '</tr>' . "\n";
1413 return TRUE;
1414 } // end of the 'PMA_displayVerticalTable' function
1418 * Displays a table of results returned by a sql query.
1419 * This function is called by the "sql.php3" script.
1421 * @param integer the link id associated to the query which results have
1422 * to be displayed
1423 * @param array the display mode
1424 * @param array the analyzed query
1426 * @global string the current language
1427 * @global integer the server to use (refers to the number in the
1428 * configuration file)
1429 * @global array the current server config
1430 * @global string the database name
1431 * @global string the table name
1432 * @global string the url to go back in case of errors
1433 * @global string the current sql query
1434 * @global integer the total number of rows returned by the sql query
1435 * @global integer the total number of rows returned by the sql query
1436 * without any programmatically appended "LIMIT" clause
1437 * @global integer the current postion of the first record to be
1438 * displayed
1439 * @global array the list of fields properties
1440 * @global integer the total number of fields returned by the sql query
1441 * @global array informations used with vertical display mode
1442 * @global string the display mode (horizontal/vertical/horizontalflipped)
1443 * @global integer the number of row to display between two table headers
1444 * @global boolean whether to limit the number of displayed characters of
1445 * text type fields or not
1446 * @global array the relation settings
1448 * @access private
1450 * @see PMA_showMessage(), PMA_setDisplayMode(),
1451 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1452 * PMA_displayTableBody()
1454 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1456 global $lang, $server, $cfg, $db, $table;
1457 global $goto;
1458 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1459 global $vertical_display, $disp_direction, $repeat_cells;
1460 global $dontlimitchars;
1461 global $cfgRelation;
1463 // 1. ----- Prepares the work -----
1465 // 1.1 Gets the informations about which functionnalities should be
1466 // displayed
1467 $total = '';
1468 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1469 if ($total == '') {
1470 unset($total);
1473 // 1.2 Defines offsets for the next and previous pages
1474 if ($is_display['nav_bar'] == '1') {
1475 if (!isset($pos)) {
1476 $pos = 0;
1478 if ($GLOBALS['session_max_rows'] == 'all') {
1479 $pos_next = 0;
1480 $pos_prev = 0;
1481 } else {
1482 $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
1483 $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
1484 if ($pos_prev < 0) {
1485 $pos_prev = 0;
1488 } // end if
1490 // 1.3 Urlencodes the query to use in input form fields ($sql_query
1491 // will be stripslashed in 'sql.php3' if the 'magic_quotes_gpc'
1492 // directive is set to 'on')
1493 if (get_magic_quotes_gpc()) {
1494 $encoded_sql_query = urlencode(addslashes($sql_query));
1495 } else {
1496 $encoded_sql_query = urlencode($sql_query);
1499 // 2. ----- Displays the top of the page -----
1501 // 2.1 Displays a messages with position informations
1502 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1503 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1504 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1505 } else {
1506 $selectstring = '';
1508 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1509 ? $total - 1
1510 : $pos_next - 1;
1511 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1512 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1513 PMA_showMessage($GLOBALS['strSQLQuery']);
1516 // 2.3 Displays the navigation bars
1517 if (!isset($table) || strlen(trim($table)) == 0) {
1518 $table = $fields_meta[0]->table;
1520 if ($is_display['nav_bar'] == '1') {
1521 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1522 echo "\n";
1523 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1524 echo "\n" . '<br /><br />' . "\n";
1527 // 2b ----- Get field references from Database -----
1528 // (see the 'relation' config variable)
1529 // loic1, 2002-03-02: extended to php3
1531 // init map
1532 $map = array();
1534 if ($cfgRelation['relwork']) {
1535 // find tables
1536 //$pattern = '`?[[:space:]]+(((ON|on)[[:space:]]+[^,]+)?,|((NATURAL|natural)[[:space:]]+)?(INNER|inner|LEFT|left|RIGHT|right)([[:space:]]+(OUTER|outer))?[[:space:]]+(JOIN|join))[[:space:]]*`?';
1537 //$target = eregi_replace('^.*[[:space:]]+FROM[[:space:]]+`?|`?[[:space:]]*(ON[[:space:]]+[^,]+)?(WHERE[[:space:]]+.*)?$', '', $sql_query);
1538 //$target = eregi_replace('`?[[:space:]]ORDER BY[[:space:]](.*)','',$target);
1539 //$tabs = '(\'' . join('\',\'', split($pattern, $target)) . '\')';
1540 $target=array();
1541 reset($analyzed_sql[0]['table_ref']);
1542 while (list ($table_ref_position, $table_ref) = each ($analyzed_sql[0]['table_ref'])) {
1543 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1545 $tabs = '(\'' . join('\',\'', $target) . '\')';
1547 $local_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
1548 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
1549 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
1550 . ' AND master_table IN ' . $tabs;
1551 $result = @PMA_query_as_cu($local_query, FALSE);
1552 if ($result) {
1553 while ($rel = PMA_mysql_fetch_row($result)) {
1554 // check for display field?
1555 if ($cfgRelation['displaywork']) {
1556 $display_field = PMA_getDisplayField($db, $rel[2]);
1557 $map[$rel[0]] = array($rel[2], $rel[3], $display_field);
1558 } // end if
1559 } // end while
1560 } // end if
1561 } // end 2b
1563 // 3. ----- Displays the results table -----
1564 echo '<!-- Results table -->' . "\n"
1565 . '<table ';
1566 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1567 echo 'border="1" cellpadding="2" cellspacing="0"';
1568 } else {
1569 echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="5"';
1571 echo '>' . "\n";
1572 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt);
1573 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1574 // lem9: vertical output case
1575 if ($disp_direction == 'vertical') {
1576 PMA_displayVerticalTable();
1577 } // end if
1578 unset($vertical_display);
1580 </table>
1581 <?php
1583 echo "\n";
1585 // 4. ----- Displays the navigation bar at the bottom if required -----
1587 if ($is_display['nav_bar'] == '1') {
1588 echo '<br />' . "\n";
1589 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1590 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1591 echo "\n" . '<br /><br />' . "\n";
1593 } // end of the 'PMA_displayTable()' function
1595 } // $__PMA_DISPLAY_TBL_LIB__