xhtml typo
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php3
blobed60b37b11526bc6fe68d23dcf18c410b0399e60
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
352 //page redirection
353 $pageNow = @floor($pos / $session_max_rows) + 1;
354 $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
356 if ($nbTotalPage > 1){ //if1
358 <td>
359 &nbsp;&nbsp;&nbsp;
360 </td>
361 <td>
362 <?php //<form> for keep the form alignment of button < and << ?>
363 <form>
364 <?php echo $GLOBALS['strPageNumber']; ?>
365 <select name="goToPage" onChange="goToUrl(this, '<?php echo "sql.php3?sql_query=".$encoded_query."&amp;session_max_rows=".$session_max_rows."&amp;disp_direction=".$disp_direction."&amp;repeat_cells=".$repeat_cells."&amp;goto=".$goto."&amp;dontlimitchars=".$dontlimitchars."&amp;".PMA_generate_common_url($db, $table)."&amp;"; ?>')">
367 <?php
368 for ($i=1; $i<=$nbTotalPage; $i++){
369 if ($i == $pageNow) {
370 $selected = 'selected="selected"';
371 } else {
372 $selected = "";
374 echo " <option ".$selected." value=\"".(($i - 1) * $session_max_rows)."\">".$i."</option>\n";
378 </select>
379 </form>
380 </td>
381 <?php
382 } //_if1
385 // Show all the records if allowed
386 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
387 echo "\n";
389 <td>
390 &nbsp;&nbsp;&nbsp;
391 </td>
392 <td>
393 <form action="sql.php3" method="post">
394 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
395 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
396 <input type="hidden" name="pos" value="0" />
397 <input type="hidden" name="session_max_rows" value="all" />
398 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
399 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
400 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
401 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
402 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
403 </form>
404 </td>
405 <?php
406 } // end show all
407 echo "\n";
409 </tr>
410 </table>
412 <?php
413 } // end of the 'PMA_displayTableNavigation()' function
417 * Displays the headers of the results table
419 * @param array which elements to display
420 * @param array the list of fields properties
421 * @param integer the total number of fields returned by the sql query
422 * @param array the analyzed query
424 * @return boolean always true
426 * @global string the current language
427 * @global string the current charset for MySQL
428 * @global integer the server to use (refers to the number in the
429 * configuration file)
430 * @global string the database name
431 * @global string the table name
432 * @global string the sql query
433 * @global string the url to go back in case of errors
434 * @global integer the total number of rows returned by the sql query
435 * @global integer the current position in results
436 * @global integer the maximum number of rows per page
437 * @global array informations used with vertical display mode
438 * @global string the display mode (horizontal/vertical/horizontalflipped)
439 * @global integer the number of row to display between two table headers
440 * @global boolean whether to limit the number of displayed characters of
441 * text type fields or not
443 * @access private
445 * @see PMA_displayTable()
447 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = array())
449 global $lang, $convcharset, $server, $db, $table;
450 global $goto;
451 global $sql_query, $num_rows, $pos, $session_max_rows;
452 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
453 global $dontlimitchars;
455 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
457 <!-- Results table headers -->
458 <tr>
459 <?php
460 echo "\n";
463 $vertical_display['emptypre'] = 0;
464 $vertical_display['emptyafter'] = 0;
465 $vertical_display['textbtn'] = '';
467 // 1. Displays the full/partial text button (part 1)...
468 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
469 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
470 ? ' colspan="2"'
471 : '';
472 } else {
473 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
474 ? ' rowspan="2"'
475 : '';
477 $text_url = 'sql.php3?'
478 . PMA_generate_common_url($db, $table)
479 . '&amp;sql_query=' . urlencode($sql_query)
480 . '&amp;pos=' . $pos
481 . '&amp;session_max_rows=' . $session_max_rows
482 . '&amp;pos=' . $pos
483 . '&amp;disp_direction=' . $disp_direction
484 . '&amp;repeat_cells=' . $repeat_cells
485 . '&amp;goto=' . $goto
486 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
488 // ... before the result table
489 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
490 && $is_display['text_btn'] == '1') {
491 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
492 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
494 <td colspan="<?php echo $fields_cnt; ?>" align="center">
495 <a href="<?php echo $text_url; ?>">
496 <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>
497 </td>
498 </tr>
500 <tr>
501 <?php
502 } // end horizontal/horizontalflipped mode
503 else {
504 echo "\n";
506 <tr>
507 <td colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
508 <a href="<?php echo $text_url; ?>">
509 <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>
510 </td>
511 </tr>
512 <?php
513 } // end vertical mode
516 // ... at the left column of the result table header if possible
517 // and required
518 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
519 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
520 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
521 echo "\n";
523 <td<?php echo $colspan; ?> align="center">
524 <a href="<?php echo $text_url; ?>">
525 <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>
526 </td>
527 <?php
528 } // end horizontal/horizontalflipped mode
529 else {
530 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
531 . ' <a href="' . $text_url . '">' . "\n"
532 . ' <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"
533 . ' </td>' . "\n";
534 } // end vertical mode
537 // ... else if no button, displays empty(ies) col(s) if required
538 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
539 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
540 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
541 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
542 echo "\n";
544 <td<?php echo $colspan; ?>></td>
545 <?php
546 echo "\n";
547 } // end horizontal/horizontalfipped mode
548 else {
549 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
550 } // end vertical mode
553 // 2. Displays the fields' name
554 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
555 // statement (see 2.1.3)
557 // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
558 // Do not show comments, if using horizontalflipped mode, because of space usage
559 if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
560 $comments_map = PMA_getComments($db, $table);
561 } else {
562 $comments_map = array();
565 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
566 require('./libraries/transformations.lib.php3');
567 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
571 if ($is_display['sort_lnk'] == '1') {
572 $is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
573 } else {
574 $is_join = FALSE;
577 // garvin: See if we have to highlight any header fields of a WHERE query.
578 // Uses SQL-Parser results.
579 $highlight_columns = array();
580 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
581 isset($analyzed_sql[0]['where_clause_identifiers'])) {
583 $wi = 0;
584 @reset($analyzed_sql[0]['where_clause_identifiers']);
585 while(list($wci_nr, $wci) = each($analyzed_sql[0]['where_clause_identifiers'])) {
586 $highlight_columns[$wci] = 'true';
590 for ($i = 0; $i < $fields_cnt; $i++) {
591 // garvin: See if this column should get highlight because it's used in the
592 // where-query.
593 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
594 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
595 } else {
596 $column_style = '';
599 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
600 if (isset($comments_map[$fields_meta[$i]->name])) {
601 $comments_table_wrap_pre = '<table border="0" cellpadding="0" cellspacing="0"><tr><th>';
602 $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>';
603 } else {
604 $comments_table_wrap_pre = '';
605 $comments_table_wrap_post = '';
608 // 2.1 Results can be sorted
609 if ($is_display['sort_lnk'] == '1') {
610 // Defines the url used to append/modify a sorting order
611 // 2.1.1 Checks if an hard coded 'order by' clause exists
612 if (eregi('(.*)([[:space:]]ORDER[[:space:]]*BY[[:space:]](.*))', $sql_query, $regs1)) {
613 if (eregi('((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)', $regs1[2], $regs2)) {
614 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
615 $sql_order = trim($regs2[1]);
616 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
617 $sort_expression = trim($after_order[2]);
619 else if (eregi('((.*))[[:space:]]+(LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) {
620 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]);
621 $sql_order = trim($regs3[1]) . ' ASC';
622 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
623 $sort_expression = trim($after_order[2]);
624 } else {
625 $unsorted_sql_query = trim($regs1[1]);
626 $sql_order = trim($regs1[2]) . ' ASC';
627 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
628 $sort_expression = trim($after_order[2]);
630 } else {
631 $unsorted_sql_query = $sql_query;
634 // 2.1.2 Checks if the current column is used to sort the
635 // results
636 if (empty($sql_order)) {
637 $is_in_sort = FALSE;
638 } else {
639 // $pattern = str_replace('\\', '\\\\', $fields_meta[$i]->name);
640 // $pattern = str_replace('(','\(', $pattern);
641 // $pattern = str_replace(')','\)', $pattern);
642 // $pattern = str_replace('*','\*', $pattern);
644 // field name may be preceded by a space, or any number
645 // of characters followed by a dot (tablename.fieldname)
646 // $is_in_sort = eregi('([[:space:]]|(.*\.))(`?)' . $pattern . '(`?)[ ,$]', $sql_order);
647 // instead of using eregi(), now do a direct comparison
648 // for the sort expression (avoids problems with queries
649 // like "SELECT id, count(id)..." and clicking to sort
650 // on id or on count(id) )
651 $is_in_sort = (PMA_backquote($fields_meta[$i]->name) == $sort_expression ? TRUE : FALSE);
653 // 2.1.3 Checks if the table name is required (it's the case
654 // for a query with a "JOIN" statement and if the column
655 // isn't aliased)
656 if ($is_join
657 && !eregi('([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name, $select_stt[1], $parts)) {
658 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
659 } else {
660 $sort_tbl = '';
662 // 2.1.4 Check the field name for backquotes.
663 // If it contains some, it's probably a function column
664 // like 'COUNT(`field`)'
665 if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
666 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
667 } else {
668 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
670 // 2.1.5 Do define the sorting url
671 if (!$is_in_sort) {
672 // loic1: patch #455484 ("Smart" order)
673 $cfg['Order'] = strtoupper($GLOBALS['cfg']['Order']);
674 if ($cfg['Order'] == 'SMART') {
675 $cfg['Order'] = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
677 $sort_order .= $cfg['Order'];
678 $order_img = '';
680 else if (eregi('[[:space:]]ASC$', $sql_order)) {
681 $sort_order .= ' DESC';
682 $order_img = '&nbsp;<img src="./images/asc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" />';
684 else if (eregi('[[:space:]]DESC$', $sql_order)) {
685 $sort_order .= ' ASC';
686 $order_img = '&nbsp;<img src="./images/desc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" />';
688 if (eregi('(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))', $unsorted_sql_query, $regs3)) {
689 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
690 } else {
691 $sorted_sql_query = $unsorted_sql_query . $sort_order;
693 $url_query = PMA_generate_common_url($db, $table)
694 . '&amp;pos=' . $pos
695 . '&amp;session_max_rows=' . $session_max_rows
696 . '&amp;disp_direction=' . $disp_direction
697 . '&amp;repeat_cells=' . $repeat_cells
698 . '&amp;dontlimitchars=' . $dontlimitchars
699 . '&amp;sql_query=' . urlencode($sorted_sql_query);
701 // 2.1.5 Displays the sorting url
702 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
703 echo "\n";
705 <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
706 <?php echo $comments_table_wrap_pre; ?>
707 <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;"' : ''); ?>>
708 <?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"; ?>
709 <?php echo $comments_table_wrap_post; ?>
710 </th>
711 <?php
713 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
714 . $comments_table_wrap_pre
715 . ' <a href="sql.php3?' . $url_query . '">' . "\n"
716 . ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
717 . $comments_table_wrap_post
718 . ' </th>' . "\n";
719 } // end if (2.1)
721 // 2.2 Results can't be sorted
722 else {
723 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
724 echo "\n";
726 <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;"' : ''); ?>>
727 <?php echo $comments_table_wrap_pre; ?>
728 <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
729 <?php echo $comments_table_wrap_post; ?>
730 </th>
731 <?php
733 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
734 . $comments_table_wrap_pre
735 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
736 . $comments_table_wrap_post
737 . ' </th>';
738 } // end else (2.2)
739 } // end for
741 // 3. Displays the full/partial text button (part 2) at the right
742 // column of the result table header if possible and required...
743 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
744 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
745 && $is_display['text_btn'] == '1') {
746 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
747 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
748 echo "\n";
750 <td<?php echo $colspan; ?> align="center">
751 <a href="<?php echo $text_url; ?>">
752 <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>
753 </td>
754 <?php
755 } // end horizontal/horizontalflipped mode
756 else {
757 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
758 . ' <a href="' . $text_url . '">' . "\n"
759 . ' <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"
760 . ' </td>' . "\n";
761 } // end vertical mode
764 // ... else if no button, displays empty cols if required
765 // (unless coming from Browse mode print view)
766 else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
767 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
768 && (!$GLOBALS['is_header_sent'])) {
769 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
770 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
771 echo "\n";
773 <td<?php echo $colspan; ?>></td>
774 <?php
775 } // end horizontal/horizontalflipped mode
776 else {
777 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
778 } // end vertical mode
781 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
782 echo "\n";
784 </tr>
785 <?php
787 echo "\n";
789 return TRUE;
790 } // end of the 'PMA_displayTableHeaders()' function
795 * Displays the body of the results table
797 * @param integer the link id associated to the query which results have
798 * to be displayed
799 * @param array which elements to display
800 * @param array the list of relations
801 * @param array the analyzed query
803 * @return boolean always true
805 * @global string the current language
806 * @global string the current charset for MySQL
807 * @global integer the server to use (refers to the number in the
808 * configuration file)
809 * @global string the database name
810 * @global string the table name
811 * @global string the sql query
812 * @global string the url to go back in case of errors
813 * @global integer the current position in results
814 * @global integer the maximum number of rows per page
815 * @global array the list of fields properties
816 * @global integer the total number of fields returned by the sql query
817 * @global array informations used with vertical display mode
818 * @global string the display mode (horizontal/vertical/horizontalflipped)
819 * @global integer the number of row to display between two table headers
820 * @global boolean whether to limit the number of displayed characters of
821 * text type fields or not
823 * @access private
825 * @see PMA_displayTable()
827 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
829 global $lang, $convcharset, $server, $db, $table;
830 global $goto;
831 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
832 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
833 global $dontlimitchars;
835 if (!is_array($map)) {
836 $map = array();
839 <!-- Results table body -->
840 <?php
841 echo "\n";
843 $row_no = 0;
844 $vertical_display['edit'] = array();
845 $vertical_display['delete'] = array();
846 $vertical_display['data'] = array();
848 // Correction uva 19991216 in the while below
849 // Previous code assumed that all tables have keys, specifically that
850 // the phpMyAdmin GUI should support row delete/edit only for such
851 // tables.
852 // Although always using keys is arguably the prescribed way of
853 // defining a relational table, it is not required. This will in
854 // particular be violated by the novice.
855 // We want to encourage phpMyAdmin usage by such novices. So the code
856 // below has been changed to conditionally work as before when the
857 // table being displayed has one or more keys; but to display
858 // delete/edit options correctly for tables without keys.
860 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
861 // to get the NULL values
863 while ($row = PMA_mysql_fetch_array($dt_result)) {
865 // lem9: "vertical display" mode stuff
866 if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
867 echo '<tr>' . "\n";
869 for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
870 echo ' <td>&nbsp;</td>' . "\n";
873 reset($vertical_display['desc']);
874 while (list($key, $val) = each($vertical_display['desc'])) {
875 echo $val;
878 for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
879 echo ' <td>&nbsp;</td>' . "\n";
882 echo '</tr>' . "\n";
883 } // end if
885 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
886 $bgcolor = '#ffffff';
887 } else {
888 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
891 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
892 // loic1: pointer code part
893 $on_mouse = '';
894 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
895 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
896 $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
897 . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
899 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
900 $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
902 } // end if
904 <tr<?php echo $on_mouse; ?>>
905 <?php
906 echo "\n";
909 // 1. Prepares the row (gets primary keys to use)
910 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
911 $primary_key = '';
912 $unique_key = '';
913 $uva_nonprimary_condition = '';
915 // 1.1 Results from a "SELECT" statement -> builds the
916 // "primary" key to use in links
917 if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
918 for ($i = 0; $i < $fields_cnt; ++$i) {
919 $meta = $fields_meta[$i];
921 // do not use an alias in a condition
922 $column_for_condition = $meta->name;
923 reset($analyzed_sql[0]['select_expr']);
924 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
925 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
926 if (!empty($alias)) {
927 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
928 if ($alias == $meta->name) {
929 $column_for_condition = $true_column;
930 } // end if
931 } // end if
932 } // end while
934 // to fix the bug where float fields (primary or not)
935 // can't be matched because of the imprecision of
936 // floating comparison, use CONCAT
937 // (also, the syntax "CONCAT(field) IS NULL"
938 // that we need on the next "if" will work)
939 if ($meta->type == 'real') {
940 $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
941 } else {
942 $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
943 } // end if... else...
945 // loic1: To fix bug #474943 under php4, the row
946 // pointer will depend on whether the "is_null"
947 // php4 function is available or not
948 $pointer = (function_exists('is_null') ? $i : $meta->name);
949 if (!isset($row[$meta->name])
950 || (function_exists('is_null') && is_null($row[$pointer]))) {
951 $condition .= 'IS NULL AND';
952 } else {
953 $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND';
955 if ($meta->primary_key > 0) {
956 $primary_key .= $condition;
957 } else if ($meta->unique_key > 0) {
958 $unique_key .= $condition;
960 $uva_nonprimary_condition .= $condition;
961 } // end for
963 // Correction uva 19991216: prefer primary or unique keys
964 // for condition, but use conjunction of all values if no
965 // primary key
966 if ($primary_key) {
967 $uva_condition = $primary_key;
968 } else if ($unique_key) {
969 $uva_condition = $unique_key;
970 } else {
971 $uva_condition = $uva_nonprimary_condition;
974 $uva_condition = urlencode(ereg_replace('[[:space:]]?AND$', '', $uva_condition));
975 } // end if (1.1)
977 // 1.2 Defines the urls for the modify/delete link(s)
978 $url_query = PMA_generate_common_url($db, $table)
979 . '&amp;pos=' . $pos
980 . '&amp;session_max_rows=' . $session_max_rows
981 . '&amp;disp_direction=' . $disp_direction
982 . '&amp;repeat_cells=' . $repeat_cells
983 . '&amp;dontlimitchars=' . $dontlimitchars;
985 // 1.2.1 Modify link(s)
986 if ($is_display['edit_lnk'] == 'ur') { // update row case
987 // $lnk_goto = 'sql.php3'
988 // . '?' . str_replace('&amp;', '&', $url_query)
989 // . '&sql_query=' . urlencode($sql_query)
990 // . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
991 // to reduce the length of the URL, because of some browsers limitations:
992 $lnk_goto = 'sql.php3';
994 $edit_url = 'tbl_change.php3'
995 . '?' . $url_query
996 . '&amp;primary_key=' . $uva_condition
997 . '&amp;sql_query=' . urlencode($sql_query)
998 . '&amp;goto=' . urlencode($lnk_goto);
999 $edit_str = $GLOBALS['strEdit'];
1000 } // end if (1.2.1)
1002 if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) {
1003 $bookmark_go = '<form method="post" target="phpmain" action="read_dump.php3">'
1004 . PMA_generate_common_hidden_inputs($row['dbase'], '')
1005 . '<input type="hidden" name="id_bookmark" value="' . $row['id'] . '" />'
1006 . '<input type="hidden" name="action_bookmark" value="0" />'
1007 . '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />'
1008 . '</form>';
1009 } else {
1010 $bookmark_go = '';
1013 // 1.2.2 Delete/Kill link(s)
1014 if ($is_display['del_lnk'] == 'dr') { // delete row case
1015 $lnk_goto = 'sql.php3'
1016 . '?' . str_replace('&amp;', '&', $url_query)
1017 . '&sql_query=' . urlencode($sql_query)
1018 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1019 . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
1020 $del_url = 'sql.php3'
1021 . '?' . $url_query
1022 . '&amp;sql_query=' . urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . ((PMA_MYSQL_INT_VERSION >= 32207) ? urlencode(' LIMIT 1') : '')
1023 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1024 . '&amp;goto=' . urlencode($lnk_goto);
1025 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
1026 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
1027 . ((PMA_MYSQL_INT_VERSION >= 32207) ? ' LIMIT 1' : '');
1028 $del_str = $GLOBALS['strDelete'];
1029 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
1030 $lnk_goto = 'sql.php3'
1031 . '?' . str_replace('&amp;', '&', $url_query)
1032 . '&sql_query=' . urlencode($sql_query)
1033 . '&goto=main.php3';
1034 $del_url = 'sql.php3?'
1035 . PMA_generate_common_url('mysql')
1036 . '&amp;sql_query=' . urlencode('KILL ' . $row['Id'])
1037 . '&amp;goto=' . urlencode($lnk_goto);
1038 $js_conf = 'KILL ' . $row['Id'];
1039 $del_str = $GLOBALS['strKill'];
1040 } // end if (1.2.2)
1042 // 1.3 Displays the links at left if required
1043 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1044 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1045 if (!empty($edit_url)) {
1046 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1047 echo PMA_linkOrButton($edit_url, $edit_str, '');
1048 echo $bookmark_go;
1049 echo ' </td>' . "\n";
1051 if (!empty($del_url)) {
1052 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1053 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1054 echo ' </td>' . "\n";
1056 } // end if (1.3)
1057 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1058 } // end if (1)
1060 // 2. Displays the rows' values
1061 for ($i = 0; $i < $fields_cnt; ++$i) {
1062 $meta = $fields_meta[$i];
1063 // loic1: To fix bug #474943 under php4, the row pointer will
1064 // depend on whether the "is_null" php4 function is
1065 // available or not
1066 $pointer = (function_exists('is_null') ? $i : $meta->name);
1068 // garvin: See if this column should get highlight because it's used in the
1069 // where-query.
1070 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1071 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
1072 } else {
1073 $column_style = '';
1076 // garvin: Wrap MIME-transformations. [MIME]
1077 $default_function = 'htmlspecialchars'; // default_function
1078 $transform_function = $default_function;
1079 $transform_options = array();
1081 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1083 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1084 // garvin: for security, never allow to break out from transformations directory
1085 $include_file = eregi_replace('\.\.*', '.', $GLOBALS['mime_map'][$meta->name]['transformation']);
1087 if (file_exists('./libraries/transformations/' . $include_file)) {
1088 $transformfunction_name = str_replace('.inc.php3', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1090 @include('./libraries/transformations/' . $include_file);
1092 if (defined('PMA_TRANSFORMATION_' . strtoupper($transformfunction_name)) && function_exists('PMA_transformation_' . $transformfunction_name)) {
1093 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1094 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1096 } // end if file_exists
1097 } // end if transformation is set
1098 } // end if mime/transformation works.
1100 $transform_options['wrapper_link'] = '?'
1101 . (isset($url_query) ? $url_query : '')
1102 . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '')
1103 . '&amp;sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '')
1104 . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1105 . '&amp;transform_key=' . urlencode($meta->name);
1108 // n u m e r i c
1109 if ($meta->numeric == 1) {
1111 // lem9: if two fields have the same name (this is possible
1112 // with self-join queries, for example), using $meta->name
1113 // will show both fields NULL even if only one is NULL,
1114 // so use the $pointer
1115 // (works only if function_exists('is_null')
1116 // PS: why not always work with the number ($i), since
1117 // the default second parameter of
1118 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1119 // associative and numeric indices?
1121 //if (!isset($row[$meta->name])
1122 if (!isset($row[$pointer])
1123 || (function_exists('is_null') && is_null($row[$pointer]))) {
1124 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1125 } else if ($row[$pointer] != '') {
1126 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">';
1128 reset($analyzed_sql[0]['select_expr']);
1129 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1130 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1131 if (!empty($alias)) {
1132 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1133 if ($alias == $meta->name) {
1134 $meta->name = $true_column;
1135 } // end if
1136 } // end if
1137 } // end while
1139 if (isset($map[$meta->name])) {
1140 // Field to display from the foreign table?
1141 if (!empty($map[$meta->name][2])) {
1142 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1143 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1144 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1145 . ' = ' . $row[$pointer];
1146 $dispresult = PMA_mysql_query($dispsql);
1147 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1148 $dispval = PMA_mysql_result($dispresult, 0);
1150 else {
1151 $dispval = $GLOBALS['strLinkNotFound'];
1154 else {
1155 $dispval = '';
1156 } // end if... else...
1157 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1159 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1160 . PMA_generate_common_url($db, $map[$meta->name][0])
1161 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1162 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>'
1163 . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer])) . '</a>';
1164 } else {
1165 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer]));
1167 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1168 } else {
1169 $vertical_display['data'][$row_no][$i] = ' <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1172 // b l o b
1174 } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && eregi('BLOB', $meta->type)) {
1175 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1176 // TEXT fields type, however TEXT fields must be displayed
1177 // even if $cfg['ShowBlob'] is false -> get the true type
1178 // of the fields.
1179 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1181 if (eregi('BINARY', $field_flags)) {
1182 $blobtext = '[BLOB';
1183 if (isset($row[$pointer])) {
1184 $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
1185 $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
1186 unset($blob_size);
1189 $blobtext .= ']';
1190 $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options) : $default_function($blobtext));
1192 $vertical_display['data'][$row_no][$i] = ' <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
1193 } else {
1194 //if (!isset($row[$meta->name])
1195 if (!isset($row[$pointer])
1196 || (function_exists('is_null') && is_null($row[$pointer]))) {
1197 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1198 } else if ($row[$pointer] != '') {
1199 // garvin: if a transform function for blob is set, none of these replacements will be made
1200 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1201 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1203 // loic1: displays all space characters, 4 space
1204 // characters for tabulations and <cr>/<lf>
1206 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1207 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1208 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1210 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
1211 } else {
1212 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1215 } else {
1216 //if (!isset($row[$meta->name])
1217 if (!isset($row[$pointer])
1218 || (function_exists('is_null') && is_null($row[$pointer]))) {
1219 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1220 } else if ($row[$pointer] != '') {
1221 // loic1: support blanks in the key
1222 $relation_id = $row[$pointer];
1224 // loic1: Cut text/blob fields even if $cfg['ShowBlob'] is true
1225 if (eregi('BLOB', $meta->type)) {
1226 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1227 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1230 // loic1: displays special characters from binaries
1231 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1232 if (eregi('BINARY', $field_flags)) {
1233 $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]);
1234 $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]);
1235 $row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]);
1236 $row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]);
1237 $row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]);
1238 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1240 // loic1: displays all space characters, 4 space
1241 // characters for tabulations and <cr>/<lf>
1242 else {
1243 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1244 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1245 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1248 // loic1: do not wrap if date field type
1249 $nowrap = (eregi('DATE|TIME', $meta->type) ? ' nowrap="nowrap"' : '');
1250 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
1252 reset($analyzed_sql[0]['select_expr']);
1253 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1254 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1255 if (!empty($alias)) {
1256 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1257 if ($alias == $meta->name) {
1258 $meta->name = $true_column;
1259 } // end if
1260 } // end if
1261 } // end while
1263 if (isset($map[$meta->name])) {
1264 // Field to display from the foreign table?
1265 if (!empty($map[$meta->name][2])) {
1266 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1267 . ' FROM ' . PMA_backquote($map[$meta->name][0])
1268 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1269 . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
1270 $dispresult = @PMA_mysql_query($dispsql);
1271 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1272 $dispval = PMA_mysql_result($dispresult, 0);
1274 else {
1275 $dispval = $GLOBALS['strLinkNotFound'];
1278 else {
1279 $dispval = '';
1281 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1283 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1284 . PMA_generate_common_url($db, $map[$meta->name][0])
1285 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1286 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1287 . $row[$pointer] . '</a>';
1288 } else {
1289 $vertical_display['data'][$row_no][$i] .= $row[$pointer];
1291 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1292 } else {
1293 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1297 // lem9: output stored cell
1298 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1299 echo $vertical_display['data'][$row_no][$i];
1302 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1303 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1304 } else {
1305 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1307 } // end for (2)
1309 // 3. Displays the modify/delete links on the right if required
1310 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1311 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1312 if (!empty($edit_url)) {
1313 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1314 echo PMA_linkOrButton($edit_url, $edit_str, '');
1315 echo $bookmark_go;
1316 echo ' </td>' . "\n";
1318 if (!empty($del_url)) {
1319 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . ' bgcolor="' . $bgcolor . '">' . "\n";
1320 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1321 echo ' </td>' . "\n";
1323 } // end if (3)
1325 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1326 echo "\n";
1328 </tr>
1329 <?php
1330 } // end if
1332 // 4. Gather links of del_urls and edit_urls in an array for later
1333 // output
1334 if (!isset($vertical_display['edit'][$row_no])) {
1335 $vertical_display['edit'][$row_no] = '';
1336 $vertical_display['delete'][$row_no] = '';
1339 if (isset($edit_url)) {
1340 $vertical_display['edit'][$row_no] .= ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1341 . PMA_linkOrButton($edit_url, $edit_str, '')
1342 . $bookmark_go
1343 . ' </td>' . "\n";
1346 if (isset($del_url)) {
1347 $vertical_display['delete'][$row_no] .= ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1348 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''))
1349 . ' </td>' . "\n";
1352 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1353 $row_no++;
1354 } // end while
1356 return TRUE;
1357 } // end of the 'PMA_displayTableBody()' function
1361 * Do display the result table with the vertical direction mode.
1362 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1364 * @return boolean always true
1366 * @global array the information to display
1367 * @global integer the number of row to display between two table headers
1369 * @access private
1371 * @see PMA_displayTable()
1373 function PMA_displayVerticalTable()
1375 global $vertical_display, $repeat_cells;
1377 reset($vertical_display);
1379 // Displays "edit" link at top if required
1380 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit'])) {
1381 echo '<tr>' . "\n";
1382 echo $vertical_display['textbtn'];
1383 reset($vertical_display['edit']);
1384 $foo_counter = 0;
1385 while (list($key, $val) = each($vertical_display['edit'])) {
1386 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1387 echo ' <td>&nbsp;</td>' . "\n";
1390 echo $val;
1391 $foo_counter++;
1392 } // end while
1393 echo '</tr>' . "\n";
1394 } // end if
1396 // Displays "delete" link at top if required
1397 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete'])) {
1398 echo '<tr>' . "\n";
1399 if (!is_array($vertical_display['edit'])) {
1400 echo $vertical_display['textbtn'];
1402 reset($vertical_display['delete']);
1403 $foo_counter = 0;
1404 while (list($key, $val) = each($vertical_display['delete'])) {
1405 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1406 echo '<td>&nbsp;</td>' . "\n";
1409 echo $val;
1410 $foo_counter++;
1411 } // end while
1412 echo '</tr>' . "\n";
1413 } // end if
1415 // Displays data
1416 reset($vertical_display['desc']);
1417 $row_no = 0;
1418 while (list($key, $val) = each($vertical_display['desc'])) {
1419 $row_no++;
1421 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
1422 $bgcolor = '#ffffff';
1423 } else {
1424 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1427 $on_mouse = '';
1428 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
1429 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
1430 $on_mouse = ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1431 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1433 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
1434 $on_mouse .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1436 } // end if
1438 echo '<tr ' . $on_mouse . '>' . "\n";
1439 echo $val;
1441 $foo_counter = 0;
1442 while (list($subkey, $subval) = each($vertical_display['rowdata'][$key])) {
1443 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1444 echo $val;
1447 echo $subval;
1448 $foo_counter++;
1449 } // end while
1451 echo '</tr>' . "\n";
1452 } // end while
1454 // Displays "edit" link at bottom if required
1455 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit'])) {
1456 echo '<tr>' . "\n";
1457 echo $vertical_display['textbtn'];
1458 reset($vertical_display['edit']);
1459 $foo_counter = 0;
1460 while (list($key, $val) = each($vertical_display['edit'])) {
1461 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1462 echo '<td>&nbsp;</td>' . "\n";
1465 echo $val;
1466 $foo_counter++;
1467 } // end while
1468 echo '</tr>' . "\n";
1469 } // end if
1471 // Displays "delete" link at bottom if required
1472 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete'])) {
1473 echo '<tr>' . "\n";
1474 if (!is_array($vertical_display['edit'])) {
1475 echo $vertical_display['textbtn'];
1477 reset($vertical_display['delete']);
1478 $foo_counter = 0;
1479 while (list($key, $val) = each($vertical_display['delete'])) {
1480 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1481 echo '<td>&nbsp;</td>' . "\n";
1484 echo $val;
1485 $foo_counter++;
1486 } // end while
1487 echo '</tr>' . "\n";
1490 return TRUE;
1491 } // end of the 'PMA_displayVerticalTable' function
1495 * Displays a table of results returned by a sql query.
1496 * This function is called by the "sql.php3" script.
1498 * @param integer the link id associated to the query which results have
1499 * to be displayed
1500 * @param array the display mode
1501 * @param array the analyzed query
1503 * @global string the current language
1504 * @global integer the server to use (refers to the number in the
1505 * configuration file)
1506 * @global array the current server config
1507 * @global string the database name
1508 * @global string the table name
1509 * @global string the url to go back in case of errors
1510 * @global string the current sql query
1511 * @global integer the total number of rows returned by the sql query
1512 * @global integer the total number of rows returned by the sql query
1513 * without any programmatically appended "LIMIT" clause
1514 * @global integer the current postion of the first record to be
1515 * displayed
1516 * @global array the list of fields properties
1517 * @global integer the total number of fields returned by the sql query
1518 * @global array informations used with vertical display mode
1519 * @global string the display mode (horizontal/vertical/horizontalflipped)
1520 * @global integer the number of row to display between two table headers
1521 * @global boolean whether to limit the number of displayed characters of
1522 * text type fields or not
1523 * @global array the relation settings
1525 * @access private
1527 * @see PMA_showMessage(), PMA_setDisplayMode(),
1528 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1529 * PMA_displayTableBody()
1531 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1533 global $lang, $server, $cfg, $db, $table;
1534 global $goto;
1535 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1536 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
1537 global $dontlimitchars;
1538 global $cfgRelation;
1540 // 1. ----- Prepares the work -----
1542 // 1.1 Gets the informations about which functionnalities should be
1543 // displayed
1544 $total = '';
1545 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1546 if ($total == '') {
1547 unset($total);
1550 // 1.2 Defines offsets for the next and previous pages
1551 if ($is_display['nav_bar'] == '1') {
1552 if (!isset($pos)) {
1553 $pos = 0;
1555 if ($GLOBALS['session_max_rows'] == 'all') {
1556 $pos_next = 0;
1557 $pos_prev = 0;
1558 } else {
1559 $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
1560 $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
1561 if ($pos_prev < 0) {
1562 $pos_prev = 0;
1565 } // end if
1567 // 1.3 Urlencodes the query to use in input form fields
1568 $encoded_sql_query = urlencode($sql_query);
1570 // 2. ----- Displays the top of the page -----
1572 // 2.1 Displays a messages with position informations
1573 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1574 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1575 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1576 } else {
1577 $selectstring = '';
1579 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1580 ? $total - 1
1581 : $pos_next - 1;
1582 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1583 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1584 PMA_showMessage($GLOBALS['strSQLQuery']);
1587 // 2.3 Displays the navigation bars
1588 if (!isset($table) || strlen(trim($table)) == 0) {
1589 $table = $fields_meta[0]->table;
1591 if ($is_display['nav_bar'] == '1') {
1592 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1593 echo "\n";
1594 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1595 echo "\n" . '<br /><br />' . "\n";
1598 // 2b ----- Get field references from Database -----
1599 // (see the 'relation' config variable)
1600 // loic1, 2002-03-02: extended to php3
1602 // init map
1603 $map = array();
1605 if ($cfgRelation['relwork']) {
1606 // find tables
1607 //$pattern = '`?[[:space:]]+(((ON|on)[[:space:]]+[^,]+)?,|((NATURAL|natural)[[:space:]]+)?(INNER|inner|LEFT|left|RIGHT|right)([[:space:]]+(OUTER|outer))?[[:space:]]+(JOIN|join))[[:space:]]*`?';
1608 //$target = eregi_replace('^.*[[:space:]]+FROM[[:space:]]+`?|`?[[:space:]]*(ON[[:space:]]+[^,]+)?(WHERE[[:space:]]+.*)?$', '', $sql_query);
1609 //$target = eregi_replace('`?[[:space:]]ORDER BY[[:space:]](.*)','',$target);
1610 //$tabs = '(\'' . join('\',\'', split($pattern, $target)) . '\')';
1611 $target=array();
1612 reset($analyzed_sql[0]['table_ref']);
1613 while (list ($table_ref_position, $table_ref) = each ($analyzed_sql[0]['table_ref'])) {
1614 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1616 $tabs = '(\'' . join('\',\'', $target) . '\')';
1618 $local_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
1619 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
1620 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
1621 . ' AND master_table IN ' . $tabs;
1622 $result = @PMA_query_as_cu($local_query, FALSE);
1623 if ($result) {
1624 while ($rel = PMA_mysql_fetch_row($result)) {
1625 // check for display field?
1626 if ($cfgRelation['displaywork']) {
1627 $display_field = PMA_getDisplayField($db, $rel[2]);
1628 $map[$rel[0]] = array($rel[2], $rel[3], $display_field);
1629 } // end if
1630 } // end while
1631 } // end if
1632 } // end 2b
1634 // 3. ----- Displays the results table -----
1635 echo '<!-- Results table -->' . "\n"
1636 . '<table ';
1637 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1638 echo 'border="1" cellpadding="2" cellspacing="0"';
1639 } else {
1640 echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="5"';
1642 echo '>' . "\n";
1643 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1644 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1645 // lem9: vertical output case
1646 if ($disp_direction == 'vertical') {
1647 PMA_displayVerticalTable();
1648 } // end if
1649 unset($vertical_display);
1651 </table>
1652 <?php
1654 echo "\n";
1656 // 4. ----- Displays the navigation bar at the bottom if required -----
1658 if ($is_display['nav_bar'] == '1') {
1659 echo '<br />' . "\n";
1660 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1661 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1662 echo "\n" . '<br /><br />' . "\n";
1664 } // end of the 'PMA_displayTable()' function
1666 } // $__PMA_DISPLAY_TBL_LIB__