Bug #703555
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php3
blobab022100f604189e367dc2a9dd68f4091406202a
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
388 * @param array the analyzed query
390 * @return boolean always true
392 * @global string the current language
393 * @global string the current charset for MySQL
394 * @global integer the server to use (refers to the number in the
395 * configuration file)
396 * @global string the database name
397 * @global string the table name
398 * @global string the sql query
399 * @global string the url to go back in case of errors
400 * @global integer the total number of rows returned by the sql query
401 * @global integer the current position in results
402 * @global integer the maximum number of rows per page
403 * @global array informations used with vertical display mode
404 * @global string the display mode (horizontal/vertical/horizontalflipped)
405 * @global integer the number of row to display between two table headers
406 * @global boolean whether to limit the number of displayed characters of
407 * text type fields or not
409 * @access private
411 * @see PMA_displayTable()
413 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = array())
415 global $lang, $convcharset, $server, $db, $table;
416 global $goto;
417 global $sql_query, $num_rows, $pos, $session_max_rows;
418 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
419 global $dontlimitchars;
421 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
423 <!-- Results table headers -->
424 <tr>
425 <?php
426 echo "\n";
429 $vertical_display['emptypre'] = 0;
430 $vertical_display['emptyafter'] = 0;
431 $vertical_display['textbtn'] = '';
433 // 1. Displays the full/partial text button (part 1)...
434 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
435 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
436 ? ' colspan="2"'
437 : '';
438 } else {
439 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
440 ? ' rowspan="2"'
441 : '';
443 $text_url = 'sql.php3?'
444 . PMA_generate_common_url($db, $table)
445 . '&amp;sql_query=' . urlencode($sql_query)
446 . '&amp;pos=' . $pos
447 . '&amp;session_max_rows=' . $session_max_rows
448 . '&amp;pos=' . $pos
449 . '&amp;disp_direction=' . $disp_direction
450 . '&amp;repeat_cells=' . $repeat_cells
451 . '&amp;goto=' . $goto
452 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
454 // ... before the result table
455 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
456 && $is_display['text_btn'] == '1') {
457 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
458 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
460 <td colspan="<?php echo $fields_cnt; ?>" align="center">
461 <a href="<?php echo $text_url; ?>">
462 <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>
463 </td>
464 </tr>
466 <tr>
467 <?php
468 } // end horizontal/horizontalflipped mode
469 else {
470 echo "\n";
472 <tr>
473 <td colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
474 <a href="<?php echo $text_url; ?>">
475 <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>
476 </td>
477 </tr>
478 <?php
479 } // end vertical mode
482 // ... at the left column of the result table header if possible
483 // and required
484 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
485 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
486 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
487 echo "\n";
489 <td<?php echo $colspan; ?> align="center">
490 <a href="<?php echo $text_url; ?>">
491 <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>
492 </td>
493 <?php
494 } // end horizontal/horizontalflipped mode
495 else {
496 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
497 . ' <a href="' . $text_url . '">' . "\n"
498 . ' <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"
499 . ' </td>' . "\n";
500 } // end vertical mode
503 // ... else if no button, displays empty(ies) col(s) if required
504 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
505 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
506 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
507 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
508 echo "\n";
510 <td<?php echo $colspan; ?>></td>
511 <?php
512 echo "\n";
513 } // end horizontal/horizontalfipped mode
514 else {
515 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
516 } // end vertical mode
519 // 2. Displays the fields' name
520 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
521 // statement (see 2.1.3)
523 // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
524 // Do not show comments, if using horizontalflipped mode, because of space usage
525 if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
526 $comments_map = PMA_getComments($db, $table);
527 } else {
528 $comments_map = array();
531 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
532 require('./libraries/transformations.lib.php3');
533 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
537 if ($is_display['sort_lnk'] == '1') {
538 $is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
539 } else {
540 $is_join = FALSE;
543 // garvin: See if we have to highlight any header fields of a WHERE query.
544 // Uses SQL-Parser results.
545 $highlight_columns = array();
546 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
547 isset($analyzed_sql[0]['where_clause_identifiers'])) {
549 $wi = 0;
550 @reset($analyzed_sql[0]['where_clause_identifiers']);
551 while(list($wci_nr, $wci) = each($analyzed_sql[0]['where_clause_identifiers'])) {
552 $highlight_columns[$wci] = 'true';
556 for ($i = 0; $i < $fields_cnt; $i++) {
557 // garvin: See if this column should get highlight because it's used in the
558 // where-query.
559 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
560 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
561 } else {
562 $column_style = '';
565 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
566 if (isset($comments_map[$fields_meta[$i]->name])) {
567 $comments_table_wrap_pre = '<table border="0" cellpadding="0" cellspacing="0"><tr><th>';
568 $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>';
569 } else {
570 $comments_table_wrap_pre = '';
571 $comments_table_wrap_post = '';
574 // 2.1 Results can be sorted
575 if ($is_display['sort_lnk'] == '1') {
576 // Defines the url used to append/modify a sorting order
577 // 2.1.1 Checks if an hard coded 'order by' clause exists
578 if (eregi('(.*)([[:space:]]ORDER[[:space:]]*BY[[:space:]](.*))', $sql_query, $regs1)) {
579 if (eregi('((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)', $regs1[2], $regs2)) {
580 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
581 $sql_order = trim($regs2[1]);
582 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
583 $sort_expression = trim($after_order[2]);
585 else if (eregi('((.*))[[:space:]]+(LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) {
586 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]);
587 $sql_order = trim($regs3[1]) . ' ASC';
588 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
589 $sort_expression = trim($after_order[2]);
590 } else {
591 $unsorted_sql_query = trim($regs1[1]);
592 $sql_order = trim($regs1[2]) . ' ASC';
593 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
594 $sort_expression = trim($after_order[2]);
596 } else {
597 $unsorted_sql_query = $sql_query;
600 // 2.1.2 Checks if the current column is used to sort the
601 // results
602 if (empty($sql_order)) {
603 $is_in_sort = FALSE;
604 } else {
605 // $pattern = str_replace('\\', '\\\\', $fields_meta[$i]->name);
606 // $pattern = str_replace('(','\(', $pattern);
607 // $pattern = str_replace(')','\)', $pattern);
608 // $pattern = str_replace('*','\*', $pattern);
610 // field name may be preceded by a space, or any number
611 // of characters followed by a dot (tablename.fieldname)
612 // $is_in_sort = eregi('([[:space:]]|(.*\.))(`?)' . $pattern . '(`?)[ ,$]', $sql_order);
613 // instead of using eregi(), now do a direct comparison
614 // for the sort expression (avoids problems with queries
615 // like "SELECT id, count(id)..." and clicking to sort
616 // on id or on count(id) )
617 $is_in_sort = (PMA_backquote($fields_meta[$i]->name) == $sort_expression ? TRUE : FALSE);
619 // 2.1.3 Checks if the table name is required (it's the case
620 // for a query with a "JOIN" statement and if the column
621 // isn't aliased)
622 if ($is_join
623 && !eregi('([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name, $select_stt[1], $parts)) {
624 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
625 } else {
626 $sort_tbl = '';
628 // 2.1.4 Check the field name for backquotes.
629 // If it contains some, it's probably a function column
630 // like 'COUNT(`field`)'
631 if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
632 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
633 } else {
634 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
636 // 2.1.5 Do define the sorting url
637 if (!$is_in_sort) {
638 // loic1: patch #455484 ("Smart" order)
639 $cfg['Order'] = strtoupper($GLOBALS['cfg']['Order']);
640 if ($cfg['Order'] == 'SMART') {
641 $cfg['Order'] = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
643 $sort_order .= $cfg['Order'];
644 $order_img = '';
646 else if (eregi('[[:space:]]ASC$', $sql_order)) {
647 $sort_order .= ' DESC';
648 $order_img = '&nbsp;<img src="./images/asc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" />';
650 else if (eregi('[[:space:]]DESC$', $sql_order)) {
651 $sort_order .= ' ASC';
652 $order_img = '&nbsp;<img src="./images/desc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" />';
654 if (eregi('(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))', $unsorted_sql_query, $regs3)) {
655 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
656 } else {
657 $sorted_sql_query = $unsorted_sql_query . $sort_order;
659 $url_query = PMA_generate_common_url($db, $table)
660 . '&amp;pos=' . $pos
661 . '&amp;session_max_rows=' . $session_max_rows
662 . '&amp;disp_direction=' . $disp_direction
663 . '&amp;repeat_cells=' . $repeat_cells
664 . '&amp;dontlimitchars=' . $dontlimitchars
665 . '&amp;sql_query=' . urlencode($sorted_sql_query);
667 // 2.1.5 Displays the sorting url
668 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
669 echo "\n";
671 <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
672 <?php echo $comments_table_wrap_pre; ?>
673 <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;"' : ''); ?>>
674 <?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"; ?>
675 <?php echo $comments_table_wrap_post; ?>
676 </th>
677 <?php
679 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
680 . $comments_table_wrap_pre
681 . ' <a href="sql.php3?' . $url_query . '">' . "\n"
682 . ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
683 . $comments_table_wrap_post
684 . ' </th>' . "\n";
685 } // end if (2.1)
687 // 2.2 Results can't be sorted
688 else {
689 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
690 echo "\n";
692 <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
693 <?php echo $comments_table_wrap_pre; ?>
694 <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
695 <?php echo $comments_table_wrap_post; ?>
696 </th>
697 <?php
699 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
700 . $comments_table_wrap_pre
701 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
702 . $comments_table_wrap_post
703 . ' </th>';
704 } // end else (2.2)
705 } // end for
707 // 3. Displays the full/partial text button (part 2) at the right
708 // column of the result table header if possible and required...
709 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
710 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
711 && $is_display['text_btn'] == '1') {
712 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
713 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
714 echo "\n";
716 <td<?php echo $colspan; ?> align="center">
717 <a href="<?php echo $text_url; ?>">
718 <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>
719 </td>
720 <?php
721 } // end horizontal/horizontalflipped mode
722 else {
723 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
724 . ' <a href="' . $text_url . '">' . "\n"
725 . ' <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"
726 . ' </td>' . "\n";
727 } // end vertical mode
730 // ... else if no button, displays empty cols if required
731 // (unless coming from Browse mode print view)
732 else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
733 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
734 && (!$GLOBALS['is_header_sent'])) {
735 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
736 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
737 echo "\n";
739 <td<?php echo $colspan; ?>></td>
740 <?php
741 } // end horizontal/horizontalflipped mode
742 else {
743 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
744 } // end vertical mode
747 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
748 echo "\n";
750 </tr>
751 <?php
753 echo "\n";
755 return TRUE;
756 } // end of the 'PMA_displayTableHeaders()' function
761 * Displays the body of the results table
763 * @param integer the link id associated to the query which results have
764 * to be displayed
765 * @param array which elements to display
766 * @param array the list of relations
767 * @param array the analyzed query
769 * @return boolean always true
771 * @global string the current language
772 * @global string the current charset for MySQL
773 * @global integer the server to use (refers to the number in the
774 * configuration file)
775 * @global string the database name
776 * @global string the table name
777 * @global string the sql query
778 * @global string the url to go back in case of errors
779 * @global integer the current position in results
780 * @global integer the maximum number of rows per page
781 * @global array the list of fields properties
782 * @global integer the total number of fields returned by the sql query
783 * @global array informations used with vertical display mode
784 * @global string the display mode (horizontal/vertical/horizontalflipped)
785 * @global integer the number of row to display between two table headers
786 * @global boolean whether to limit the number of displayed characters of
787 * text type fields or not
789 * @access private
791 * @see PMA_displayTable()
793 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
795 global $lang, $convcharset, $server, $db, $table;
796 global $goto;
797 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
798 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
799 global $dontlimitchars;
801 if (!is_array($map)) {
802 $map = array();
805 <!-- Results table body -->
806 <?php
807 echo "\n";
809 $row_no = 0;
810 $vertical_display['edit'] = array();
811 $vertical_display['delete'] = array();
812 $vertical_display['data'] = array();
814 // Correction uva 19991216 in the while below
815 // Previous code assumed that all tables have keys, specifically that
816 // the phpMyAdmin GUI should support row delete/edit only for such
817 // tables.
818 // Although always using keys is arguably the prescribed way of
819 // defining a relational table, it is not required. This will in
820 // particular be violated by the novice.
821 // We want to encourage phpMyAdmin usage by such novices. So the code
822 // below has been changed to conditionally work as before when the
823 // table being displayed has one or more keys; but to display
824 // delete/edit options correctly for tables without keys.
826 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
827 // to get the NULL values
829 while ($row = PMA_mysql_fetch_array($dt_result)) {
831 // lem9: "vertical display" mode stuff
832 if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
833 echo '<tr>' . "\n";
835 for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
836 echo ' <td>&nbsp;</td>' . "\n";
839 reset($vertical_display['desc']);
840 while (list($key, $val) = each($vertical_display['desc'])) {
841 echo $val;
844 for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
845 echo ' <td>&nbsp;</td>' . "\n";
848 echo '</tr>' . "\n";
849 } // end if
851 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
852 $bgcolor = '#ffffff';
853 } else {
854 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
857 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
858 // loic1: pointer code part
859 $on_mouse = '';
860 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
861 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
862 $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
863 . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
865 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
866 $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
868 } // end if
870 <tr<?php echo $on_mouse; ?>>
871 <?php
872 echo "\n";
875 // 1. Prepares the row (gets primary keys to use)
876 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
877 $primary_key = '';
878 $unique_key = '';
879 $uva_nonprimary_condition = '';
881 // 1.1 Results from a "SELECT" statement -> builds the
882 // "primary" key to use in links
883 if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
884 for ($i = 0; $i < $fields_cnt; ++$i) {
885 $meta = $fields_meta[$i];
887 // do not use an alias in a condition
888 $column_for_condition = $meta->name;
889 reset($analyzed_sql[0]['select_expr']);
890 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
891 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
892 if (!empty($alias)) {
893 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
894 if ($alias == $meta->name) {
895 $column_for_condition = $true_column;
896 } // end if
897 } // end if
898 } // end while
900 // to fix the bug where float fields (primary or not)
901 // can't be matched because of the imprecision of
902 // floating comparison, use CONCAT
903 // (also, the syntax "CONCAT(field) IS NULL"
904 // that we need on the next "if" will work)
905 if ($meta->type == 'real') {
906 $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
907 } else {
908 $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
909 } // end if... else...
911 // loic1: To fix bug #474943 under php4, the row
912 // pointer will depend on whether the "is_null"
913 // php4 function is available or not
914 $pointer = (function_exists('is_null') ? $i : $meta->name);
915 if (!isset($row[$meta->name])
916 || (function_exists('is_null') && is_null($row[$pointer]))) {
917 $condition .= 'IS NULL AND';
918 } else {
919 $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND';
921 if ($meta->primary_key > 0) {
922 $primary_key .= $condition;
923 } else if ($meta->unique_key > 0) {
924 $unique_key .= $condition;
926 $uva_nonprimary_condition .= $condition;
927 } // end for
929 // Correction uva 19991216: prefer primary or unique keys
930 // for condition, but use conjunction of all values if no
931 // primary key
932 if ($primary_key) {
933 $uva_condition = $primary_key;
934 } else if ($unique_key) {
935 $uva_condition = $unique_key;
936 } else {
937 $uva_condition = $uva_nonprimary_condition;
940 $uva_condition = urlencode(ereg_replace('[[:space:]]?AND$', '', $uva_condition));
941 } // end if (1.1)
943 // 1.2 Defines the urls for the modify/delete link(s)
944 $url_query = PMA_generate_common_url($db, $table)
945 . '&amp;pos=' . $pos
946 . '&amp;session_max_rows=' . $session_max_rows
947 . '&amp;disp_direction=' . $disp_direction
948 . '&amp;repeat_cells=' . $repeat_cells
949 . '&amp;dontlimitchars=' . $dontlimitchars;
951 // 1.2.1 Modify link(s)
952 if ($is_display['edit_lnk'] == 'ur') { // update row case
953 // $lnk_goto = 'sql.php3'
954 // . '?' . str_replace('&amp;', '&', $url_query)
955 // . '&sql_query=' . urlencode($sql_query)
956 // . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
957 // to reduce the length of the URL, because of some browsers limitations:
958 $lnk_goto = 'sql.php3';
960 $edit_url = 'tbl_change.php3'
961 . '?' . $url_query
962 . '&amp;primary_key=' . $uva_condition
963 . '&amp;sql_query=' . urlencode($sql_query)
964 . '&amp;goto=' . urlencode($lnk_goto);
965 $edit_str = $GLOBALS['strEdit'];
966 } // end if (1.2.1)
968 if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) {
969 $bookmark_go = '<form method="post" target="phpmain" action="read_dump.php3">'
970 . PMA_generate_common_hidden_inputs($row['dbase'], '')
971 . '<input type="hidden" name="id_bookmark" value="' . $row['id'] . '" />'
972 . '<input type="hidden" name="action_bookmark" value="0" />'
973 . '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />'
974 . '</form>';
975 } else {
976 $bookmark_go = '';
979 // 1.2.2 Delete/Kill link(s)
980 if ($is_display['del_lnk'] == 'dr') { // delete row case
981 $lnk_goto = 'sql.php3'
982 . '?' . str_replace('&amp;', '&', $url_query)
983 . '&sql_query=' . urlencode($sql_query)
984 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
985 . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
986 $del_url = 'sql.php3'
987 . '?' . $url_query
988 . '&amp;sql_query=' . urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . ((PMA_MYSQL_INT_VERSION >= 32207) ? urlencode(' LIMIT 1') : '')
989 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
990 . '&amp;goto=' . urlencode($lnk_goto);
991 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
992 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
993 . ((PMA_MYSQL_INT_VERSION >= 32207) ? ' LIMIT 1' : '');
994 $del_str = $GLOBALS['strDelete'];
995 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
996 $lnk_goto = 'sql.php3'
997 . '?' . str_replace('&amp;', '&', $url_query)
998 . '&sql_query=' . urlencode($sql_query)
999 . '&goto=main.php3';
1000 $del_url = 'sql.php3?'
1001 . PMA_generate_common_url('mysql')
1002 . '&amp;sql_query=' . urlencode('KILL ' . $row['Id'])
1003 . '&amp;goto=' . urlencode($lnk_goto);
1004 $js_conf = 'KILL ' . $row['Id'];
1005 $del_str = $GLOBALS['strKill'];
1006 } // end if (1.2.2)
1008 // 1.3 Displays the links at left if required
1009 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1010 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1011 if (!empty($edit_url)) {
1012 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1013 echo PMA_linkOrButton($edit_url, $edit_str, '');
1014 echo $bookmark_go;
1015 echo ' </td>' . "\n";
1017 if (!empty($del_url)) {
1018 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1019 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1020 echo ' </td>' . "\n";
1022 } // end if (1.3)
1023 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1024 } // end if (1)
1026 // 2. Displays the rows' values
1027 for ($i = 0; $i < $fields_cnt; ++$i) {
1028 $meta = $fields_meta[$i];
1029 // loic1: To fix bug #474943 under php4, the row pointer will
1030 // depend on whether the "is_null" php4 function is
1031 // available or not
1032 $pointer = (function_exists('is_null') ? $i : $meta->name);
1034 // garvin: See if this column should get highlight because it's used in the
1035 // where-query.
1036 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1037 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
1038 } else {
1039 $column_style = '';
1042 // garvin: Wrap MIME-transformations. [MIME]
1043 $default_function = 'htmlspecialchars'; // default_function
1044 $transform_function = $default_function;
1045 $transform_options = array();
1047 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1049 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1050 // garvin: for security, never allow to break out from transformations directory
1051 $include_file = eregi_replace('\.\.*', '.', $GLOBALS['mime_map'][$meta->name]['transformation']);
1053 if (file_exists('./libraries/transformations/' . $include_file)) {
1054 $transformfunction_name = str_replace('.inc.php3', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1056 @include('./libraries/transformations/' . $include_file);
1058 if (defined('PMA_TRANSFORMATION_' . strtoupper($transformfunction_name)) && function_exists('PMA_transformation_' . $transformfunction_name)) {
1059 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1060 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1062 } // end if file_exists
1063 } // end if transformation is set
1064 } // end if mime/transformation works.
1066 $transform_options['wrapper_link'] = '?'
1067 . (isset($url_query) ? $url_query : '')
1068 . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '')
1069 . '&amp;sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '')
1070 . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1071 . '&amp;transform_key=' . urlencode($meta->name);
1074 // n u m e r i c
1075 if ($meta->numeric == 1) {
1077 // lem9: if two fields have the same name (this is possible
1078 // with self-join queries, for example), using $meta->name
1079 // will show both fields NULL even if only one is NULL,
1080 // so use the $pointer
1081 // (works only if function_exists('is_null')
1082 // PS: why not always work with the number ($i), since
1083 // the default second parameter of
1084 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1085 // associative and numeric indices?
1087 //if (!isset($row[$meta->name])
1088 if (!isset($row[$pointer])
1089 || (function_exists('is_null') && is_null($row[$pointer]))) {
1090 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1091 } else if ($row[$pointer] != '') {
1092 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">';
1094 reset($analyzed_sql[0]['select_expr']);
1095 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1096 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1097 if (!empty($alias)) {
1098 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1099 if ($alias == $meta->name) {
1100 $meta->name = $true_column;
1101 } // end if
1102 } // end if
1103 } // end while
1105 if (isset($map[$meta->name])) {
1106 // Field to display from the foreign table?
1107 if (!empty($map[$meta->name][2])) {
1108 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1109 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1110 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1111 . ' = ' . $row[$pointer];
1112 $dispresult = PMA_mysql_query($dispsql);
1113 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1114 $dispval = PMA_mysql_result($dispresult, 0);
1116 else {
1117 $dispval = $GLOBALS['strLinkNotFound'];
1120 else {
1121 $dispval = '';
1122 } // end if... else...
1123 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1125 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1126 . PMA_generate_common_url($db, $map[$meta->name][0])
1127 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1128 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>'
1129 . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer])) . '</a>';
1130 } else {
1131 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer]));
1133 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1134 } else {
1135 $vertical_display['data'][$row_no][$i] = ' <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1138 // b l o b
1140 } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && eregi('BLOB', $meta->type)) {
1141 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1142 // TEXT fields type, however TEXT fields must be displayed
1143 // even if $cfg['ShowBlob'] is false -> get the true type
1144 // of the fields.
1145 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1147 if (eregi('BINARY', $field_flags)) {
1148 $blobtext = '[BLOB';
1149 if (isset($row[$pointer])) {
1150 $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
1151 $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
1152 unset($blob_size);
1155 $blobtext .= ']';
1156 $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options) : $default_function($blobtext));
1158 $vertical_display['data'][$row_no][$i] = ' <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
1159 } else {
1160 //if (!isset($row[$meta->name])
1161 if (!isset($row[$pointer])
1162 || (function_exists('is_null') && is_null($row[$pointer]))) {
1163 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1164 } else if ($row[$pointer] != '') {
1165 // garvin: if a transform function for blob is set, none of these replacements will be made
1166 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1167 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1169 // loic1: displays all space characters, 4 space
1170 // characters for tabulations and <cr>/<lf>
1172 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1173 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1174 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1176 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
1177 } else {
1178 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1181 } else {
1182 //if (!isset($row[$meta->name])
1183 if (!isset($row[$pointer])
1184 || (function_exists('is_null') && is_null($row[$pointer]))) {
1185 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1186 } else if ($row[$pointer] != '') {
1187 // loic1: support blanks in the key
1188 $relation_id = $row[$pointer];
1190 // loic1: Cut text/blob fields even if $cfg['ShowBlob'] is true
1191 if (eregi('BLOB', $meta->type)) {
1192 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1193 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1196 // loic1: displays special characters from binaries
1197 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1198 if (eregi('BINARY', $field_flags)) {
1199 $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]);
1200 $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]);
1201 $row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]);
1202 $row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]);
1203 $row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]);
1204 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1206 // loic1: displays all space characters, 4 space
1207 // characters for tabulations and <cr>/<lf>
1208 else {
1209 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1210 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1211 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1214 // loic1: do not wrap if date field type
1215 $nowrap = (eregi('DATE|TIME', $meta->type) ? ' nowrap="nowrap"' : '');
1216 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
1218 reset($analyzed_sql[0]['select_expr']);
1219 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1220 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1221 if (!empty($alias)) {
1222 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1223 if ($alias == $meta->name) {
1224 $meta->name = $true_column;
1225 } // end if
1226 } // end if
1227 } // end while
1229 if (isset($map[$meta->name])) {
1230 // Field to display from the foreign table?
1231 if (!empty($map[$meta->name][2])) {
1232 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1233 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1234 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1235 . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
1236 $dispresult = @PMA_mysql_query($dispsql);
1237 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1238 $dispval = PMA_mysql_result($dispresult, 0);
1240 else {
1241 $dispval = $GLOBALS['strLinkNotFound'];
1244 else {
1245 $dispval = '';
1247 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1249 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1250 . PMA_generate_common_url($db, $map[$meta->name][0])
1251 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1252 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1253 . $row[$pointer] . '</a>';
1254 } else {
1255 $vertical_display['data'][$row_no][$i] .= $row[$pointer];
1257 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1258 } else {
1259 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1263 // lem9: output stored cell
1264 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1265 echo $vertical_display['data'][$row_no][$i];
1268 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1269 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1270 } else {
1271 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1273 } // end for (2)
1275 // 3. Displays the modify/delete links on the right if required
1276 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1277 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1278 if (!empty($edit_url)) {
1279 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1280 echo PMA_linkOrButton($edit_url, $edit_str, '');
1281 echo $bookmark_go;
1282 echo ' </td>' . "\n";
1284 if (!empty($del_url)) {
1285 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . ' bgcolor="' . $bgcolor . '">' . "\n";
1286 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1287 echo ' </td>' . "\n";
1289 } // end if (3)
1291 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1292 echo "\n";
1294 </tr>
1295 <?php
1296 } // end if
1298 // 4. Gather links of del_urls and edit_urls in an array for later
1299 // output
1300 if (!isset($vertical_display['edit'][$row_no])) {
1301 $vertical_display['edit'][$row_no] = '';
1302 $vertical_display['delete'][$row_no] = '';
1305 if (isset($edit_url)) {
1306 $vertical_display['edit'][$row_no] .= ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1307 . PMA_linkOrButton($edit_url, $edit_str, '')
1308 . $bookmark_go
1309 . ' </td>' . "\n";
1312 if (isset($del_url)) {
1313 $vertical_display['delete'][$row_no] .= ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1314 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''))
1315 . ' </td>' . "\n";
1318 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1319 $row_no++;
1320 } // end while
1322 return TRUE;
1323 } // end of the 'PMA_displayTableBody()' function
1327 * Do display the result table with the vertical direction mode.
1328 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1330 * @return boolean always true
1332 * @global array the information to display
1333 * @global integer the number of row to display between two table headers
1335 * @access private
1337 * @see PMA_displayTable()
1339 function PMA_displayVerticalTable()
1341 global $vertical_display, $repeat_cells;
1343 reset($vertical_display);
1345 // Displays "edit" link at top if required
1346 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit'])) {
1347 echo '<tr>' . "\n";
1348 echo $vertical_display['textbtn'];
1349 reset($vertical_display['edit']);
1350 $foo_counter = 0;
1351 while (list($key, $val) = each($vertical_display['edit'])) {
1352 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1353 echo ' <td>&nbsp;</td>' . "\n";
1356 echo $val;
1357 $foo_counter++;
1358 } // end while
1359 echo '</tr>' . "\n";
1360 } // end if
1362 // Displays "delete" link at top if required
1363 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete'])) {
1364 echo '<tr>' . "\n";
1365 if (!is_array($vertical_display['edit'])) {
1366 echo $vertical_display['textbtn'];
1368 reset($vertical_display['delete']);
1369 $foo_counter = 0;
1370 while (list($key, $val) = each($vertical_display['delete'])) {
1371 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1372 echo '<td>&nbsp;</td>' . "\n";
1375 echo $val;
1376 $foo_counter++;
1377 } // end while
1378 echo '</tr>' . "\n";
1379 } // end if
1381 // Displays data
1382 reset($vertical_display['desc']);
1383 $row_no = 0;
1384 while (list($key, $val) = each($vertical_display['desc'])) {
1385 $row_no++;
1387 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
1388 $bgcolor = '#ffffff';
1389 } else {
1390 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1393 $on_mouse = '';
1394 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
1395 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
1396 $on_mouse = ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1397 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1399 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
1400 $on_mouse .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1402 } // end if
1404 echo '<tr ' . $on_mouse . '>' . "\n";
1405 echo $val;
1407 $foo_counter = 0;
1408 while (list($subkey, $subval) = each($vertical_display['rowdata'][$key])) {
1409 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1410 echo $val;
1413 echo $subval;
1414 $foo_counter++;
1415 } // end while
1417 echo '</tr>' . "\n";
1418 } // end while
1420 // Displays "edit" link at bottom if required
1421 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit'])) {
1422 echo '<tr>' . "\n";
1423 echo $vertical_display['textbtn'];
1424 reset($vertical_display['edit']);
1425 $foo_counter = 0;
1426 while (list($key, $val) = each($vertical_display['edit'])) {
1427 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1428 echo '<td>&nbsp;</td>' . "\n";
1431 echo $val;
1432 $foo_counter++;
1433 } // end while
1434 echo '</tr>' . "\n";
1435 } // end if
1437 // Displays "delete" link at bottom if required
1438 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete'])) {
1439 echo '<tr>' . "\n";
1440 if (!is_array($vertical_display['edit'])) {
1441 echo $vertical_display['textbtn'];
1443 reset($vertical_display['delete']);
1444 $foo_counter = 0;
1445 while (list($key, $val) = each($vertical_display['delete'])) {
1446 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1447 echo '<td>&nbsp;</td>' . "\n";
1450 echo $val;
1451 $foo_counter++;
1452 } // end while
1453 echo '</tr>' . "\n";
1456 return TRUE;
1457 } // end of the 'PMA_displayVerticalTable' function
1461 * Displays a table of results returned by a sql query.
1462 * This function is called by the "sql.php3" script.
1464 * @param integer the link id associated to the query which results have
1465 * to be displayed
1466 * @param array the display mode
1467 * @param array the analyzed query
1469 * @global string the current language
1470 * @global integer the server to use (refers to the number in the
1471 * configuration file)
1472 * @global array the current server config
1473 * @global string the database name
1474 * @global string the table name
1475 * @global string the url to go back in case of errors
1476 * @global string the current sql query
1477 * @global integer the total number of rows returned by the sql query
1478 * @global integer the total number of rows returned by the sql query
1479 * without any programmatically appended "LIMIT" clause
1480 * @global integer the current postion of the first record to be
1481 * displayed
1482 * @global array the list of fields properties
1483 * @global integer the total number of fields returned by the sql query
1484 * @global array informations used with vertical display mode
1485 * @global string the display mode (horizontal/vertical/horizontalflipped)
1486 * @global integer the number of row to display between two table headers
1487 * @global boolean whether to limit the number of displayed characters of
1488 * text type fields or not
1489 * @global array the relation settings
1491 * @access private
1493 * @see PMA_showMessage(), PMA_setDisplayMode(),
1494 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1495 * PMA_displayTableBody()
1497 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1499 global $lang, $server, $cfg, $db, $table;
1500 global $goto;
1501 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1502 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
1503 global $dontlimitchars;
1504 global $cfgRelation;
1506 // 1. ----- Prepares the work -----
1508 // 1.1 Gets the informations about which functionnalities should be
1509 // displayed
1510 $total = '';
1511 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1512 if ($total == '') {
1513 unset($total);
1516 // 1.2 Defines offsets for the next and previous pages
1517 if ($is_display['nav_bar'] == '1') {
1518 if (!isset($pos)) {
1519 $pos = 0;
1521 if ($GLOBALS['session_max_rows'] == 'all') {
1522 $pos_next = 0;
1523 $pos_prev = 0;
1524 } else {
1525 $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
1526 $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
1527 if ($pos_prev < 0) {
1528 $pos_prev = 0;
1531 } // end if
1533 // 1.3 Urlencodes the query to use in input form fields
1534 $encoded_sql_query = urlencode($sql_query);
1536 // 2. ----- Displays the top of the page -----
1538 // 2.1 Displays a messages with position informations
1539 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1540 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1541 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1542 } else {
1543 $selectstring = '';
1545 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1546 ? $total - 1
1547 : $pos_next - 1;
1548 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1549 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1550 PMA_showMessage($GLOBALS['strSQLQuery']);
1553 // 2.3 Displays the navigation bars
1554 if (!isset($table) || strlen(trim($table)) == 0) {
1555 $table = $fields_meta[0]->table;
1557 if ($is_display['nav_bar'] == '1') {
1558 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1559 echo "\n";
1560 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1561 echo "\n" . '<br /><br />' . "\n";
1564 // 2b ----- Get field references from Database -----
1565 // (see the 'relation' config variable)
1566 // loic1, 2002-03-02: extended to php3
1568 // init map
1569 $map = array();
1571 if ($cfgRelation['relwork']) {
1572 // find tables
1573 //$pattern = '`?[[:space:]]+(((ON|on)[[:space:]]+[^,]+)?,|((NATURAL|natural)[[:space:]]+)?(INNER|inner|LEFT|left|RIGHT|right)([[:space:]]+(OUTER|outer))?[[:space:]]+(JOIN|join))[[:space:]]*`?';
1574 //$target = eregi_replace('^.*[[:space:]]+FROM[[:space:]]+`?|`?[[:space:]]*(ON[[:space:]]+[^,]+)?(WHERE[[:space:]]+.*)?$', '', $sql_query);
1575 //$target = eregi_replace('`?[[:space:]]ORDER BY[[:space:]](.*)','',$target);
1576 //$tabs = '(\'' . join('\',\'', split($pattern, $target)) . '\')';
1577 $target=array();
1578 reset($analyzed_sql[0]['table_ref']);
1579 while (list ($table_ref_position, $table_ref) = each ($analyzed_sql[0]['table_ref'])) {
1580 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1582 $tabs = '(\'' . join('\',\'', $target) . '\')';
1584 $local_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
1585 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
1586 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
1587 . ' AND master_table IN ' . $tabs;
1588 $result = @PMA_query_as_cu($local_query, FALSE);
1589 if ($result) {
1590 while ($rel = PMA_mysql_fetch_row($result)) {
1591 // check for display field?
1592 if ($cfgRelation['displaywork']) {
1593 $display_field = PMA_getDisplayField($db, $rel[2]);
1594 $map[$rel[0]] = array($rel[2], $rel[3], $display_field);
1595 } // end if
1596 } // end while
1597 } // end if
1598 } // end 2b
1600 // 3. ----- Displays the results table -----
1601 echo '<!-- Results table -->' . "\n"
1602 . '<table ';
1603 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1604 echo 'border="1" cellpadding="2" cellspacing="0"';
1605 } else {
1606 echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="5"';
1608 echo '>' . "\n";
1609 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1610 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1611 // lem9: vertical output case
1612 if ($disp_direction == 'vertical') {
1613 PMA_displayVerticalTable();
1614 } // end if
1615 unset($vertical_display);
1617 </table>
1618 <?php
1620 echo "\n";
1622 // 4. ----- Displays the navigation bar at the bottom if required -----
1624 if ($is_display['nav_bar'] == '1') {
1625 echo '<br />' . "\n";
1626 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1627 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1628 echo "\n" . '<br /><br />' . "\n";
1630 } // end of the 'PMA_displayTable()' function
1632 } // $__PMA_DISPLAY_TBL_LIB__