PHP3 compatibility
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php3
blob9fcb677822a58ee922b3e66a9107b0419604f03b
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 $the_total = PMA_countRecords($db, $table, TRUE);
162 // 4. If navigation bar or sorting fields names urls should be
163 // displayed but there is only one row, change these settings to
164 // false
165 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
167 if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
168 // garvin: force display of navbar for vertical/horizontal display-choice.
169 // $do_display['nav_bar'] = (string) '0';
170 $do_display['sort_lnk'] = (string) '0';
173 } // end if (3)
175 // 5. Updates the synthetic var
176 $the_disp_mode = join('', $do_display);
178 return $do_display;
179 } // end of the 'PMA_setDisplayMode()' function
183 * Displays a navigation bar to browse among the results of a sql query
185 * @param integer the offset for the "next" page
186 * @param integer the offset for the "previous" page
187 * @param string the url-encoded query
189 * @global string the current language
190 * @global string the currect charset for MySQL
191 * @global integer the server to use (refers to the number in the
192 * configuration file)
193 * @global string the database name
194 * @global string the table name
195 * @global string the url to go back in case of errors
196 * @global integer the total number of rows returned by the sql query
197 * @global integer the total number of rows returned by the sql query
198 * without any programmatically appended "LIMIT" clause
199 * @global integer the current position in results
200 * @global mixed the maximum number of rows per page ('all' = no limit)
201 * @global string the display mode (horizontal/vertical/horizontalflipped)
202 * @global integer the number of row to display between two table headers
203 * @global boolean whether to limit the number of displayed characters of
204 * text type fields or not
206 * @access private
208 * @see PMA_displayTable()
210 function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
212 global $lang, $convcharset, $server, $db, $table;
213 global $goto;
214 global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
215 global $disp_direction, $repeat_cells;
216 global $dontlimitchars;
219 <!-- Navigation bar -->
220 <table border="0">
221 <tr>
222 <?php
223 // Move to the beginning or to the previous page
224 if ($pos > 0 && $session_max_rows != 'all') {
225 // loic1: patch #474210 from Gosha Sakovich - part 1
226 if ($GLOBALS['cfg']['NavigationBarIconic']) {
227 $caption1 = '&lt;&lt;';
228 $caption2 = '&nbsp;&lt;&nbsp;';
229 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
230 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
231 } else {
232 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
233 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
234 $title1 = '';
235 $title2 = '';
236 } // end if... else...
238 <td>
239 <form action="sql.php3" method="post">
240 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
241 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
242 <input type="hidden" name="pos" value="0" />
243 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
244 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
245 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
246 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
247 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
248 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
249 </form>
250 </td>
251 <td>
252 <form action="sql.php3" method="post">
253 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
254 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
255 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
256 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
257 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
258 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
259 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
260 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
261 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
262 </form>
263 </td>
264 <?php
265 } // end move back
266 echo "\n";
268 <td>
269 &nbsp;&nbsp;&nbsp;
270 </td>
271 <td align="center">
272 <form action="sql.php3" method="post"
273 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', 1) && checkFormElementInRange(this, 'pos', 0, <?php echo $unlim_num_rows - 1; ?>))">
274 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
275 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
276 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
277 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
278 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
279 <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()" />
280 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
281 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
282 <br />
283 <?php
284 // Display mode (horizontal/vertical and repeat headers)
285 $param1 = ' <select name="disp_direction">' . "\n"
286 . ' <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
287 . ' <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
288 . ' <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
289 . ' </select>' . "\n"
290 . ' ';
291 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
292 . ' ';
293 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
295 </form>
296 </td>
297 <td>
298 &nbsp;&nbsp;&nbsp;
299 </td>
300 <?php
301 // Move to the next page or to the last one
302 if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
303 && $session_max_rows != 'all') {
304 // loic1: patch #474210 from Gosha Sakovich - part 2
305 if ($GLOBALS['cfg']['NavigationBarIconic']) {
306 $caption3 = '&nbsp;&gt;&nbsp;';
307 $caption4 = '&gt;&gt;';
308 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
309 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
310 } else {
311 $caption3 = '&gt; ' . $GLOBALS['strNext'];
312 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
313 $title3 = '';
314 $title4 = '';
315 } // end if... else...
316 echo "\n";
318 <td>
319 <form action="sql.php3" method="post">
320 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
321 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
322 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
323 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
324 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
325 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
326 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
327 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
328 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
329 </form>
330 </td>
331 <td>
332 <form action="sql.php3" method="post"
333 onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
334 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
335 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
336 <input type="hidden" name="pos" value="<?php echo $unlim_num_rows - $session_max_rows; ?>" />
337 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
338 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
339 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
340 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
341 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
342 <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> />
343 </form>
344 </td>
345 <?php
346 } // end move toward
349 //page redirection
350 $pageNow = @floor($pos / $session_max_rows) + 1;
351 $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
353 if ($nbTotalPage > 1){ //if1
355 <td>
356 &nbsp;&nbsp;&nbsp;
357 </td>
358 <td>
359 <?php //<form> for keep the form alignment of button < and << ?>
360 <form>
361 <?php echo $GLOBALS['strPageNumber']; ?>
362 <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;"; ?>')">
364 <?php
365 for ($i=1; $i<=$nbTotalPage; $i++){
366 if ($i == $pageNow) {
367 $selected = 'selected="selected"';
368 } else {
369 $selected = "";
371 echo " <option ".$selected." value=\"".(($i - 1) * $session_max_rows)."\">".$i."</option>\n";
375 </select>
376 </form>
377 </td>
378 <?php
379 } //_if1
382 // Show all the records if allowed
383 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
384 echo "\n";
386 <td>
387 &nbsp;&nbsp;&nbsp;
388 </td>
389 <td>
390 <form action="sql.php3" method="post">
391 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
392 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
393 <input type="hidden" name="pos" value="0" />
394 <input type="hidden" name="session_max_rows" value="all" />
395 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
396 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
397 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
398 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
399 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
400 </form>
401 </td>
402 <?php
403 } // end show all
404 echo "\n";
406 </tr>
407 </table>
409 <?php
410 } // end of the 'PMA_displayTableNavigation()' function
414 * Displays the headers of the results table
416 * @param array which elements to display
417 * @param array the list of fields properties
418 * @param integer the total number of fields returned by the sql query
419 * @param array the analyzed query
421 * @return boolean always true
423 * @global string the current language
424 * @global string the current charset for MySQL
425 * @global integer the server to use (refers to the number in the
426 * configuration file)
427 * @global string the database name
428 * @global string the table name
429 * @global string the sql query
430 * @global string the url to go back in case of errors
431 * @global integer the total number of rows returned by the sql query
432 * @global integer the current position in results
433 * @global integer the maximum number of rows per page
434 * @global array informations used with vertical display mode
435 * @global string the display mode (horizontal/vertical/horizontalflipped)
436 * @global integer the number of row to display between two table headers
437 * @global boolean whether to limit the number of displayed characters of
438 * text type fields or not
440 * @access private
442 * @see PMA_displayTable()
444 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
446 global $lang, $convcharset, $server, $db, $table;
447 global $goto;
448 global $sql_query, $num_rows, $pos, $session_max_rows;
449 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
450 global $dontlimitchars;
452 if ($analyzed_sql == '') {
453 $analyzed_sql = array();
456 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
458 <!-- Results table headers -->
459 <tr>
460 <?php
461 echo "\n";
464 $vertical_display['emptypre'] = 0;
465 $vertical_display['emptyafter'] = 0;
466 $vertical_display['textbtn'] = '';
468 // 1. Displays the full/partial text button (part 1)...
469 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
470 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
471 ? ' colspan="2"'
472 : '';
473 } else {
474 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
475 ? ' rowspan="2"'
476 : '';
478 $text_url = 'sql.php3?'
479 . PMA_generate_common_url($db, $table)
480 . '&amp;sql_query=' . urlencode($sql_query)
481 . '&amp;pos=' . $pos
482 . '&amp;session_max_rows=' . $session_max_rows
483 . '&amp;pos=' . $pos
484 . '&amp;disp_direction=' . $disp_direction
485 . '&amp;repeat_cells=' . $repeat_cells
486 . '&amp;goto=' . $goto
487 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
489 // ... before the result table
490 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
491 && $is_display['text_btn'] == '1') {
492 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 0;
493 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
495 <td colspan="<?php echo $fields_cnt; ?>" align="center">
496 <a href="<?php echo $text_url; ?>">
497 <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>
498 </td>
499 </tr>
501 <tr>
502 <?php
503 } // end horizontal/horizontalflipped mode
504 else {
505 echo "\n";
507 <tr>
508 <td colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
509 <a href="<?php echo $text_url; ?>">
510 <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>
511 </td>
512 </tr>
513 <?php
514 } // end vertical mode
517 // ... at the left column of the result table header if possible
518 // and required
519 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
520 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 0;
521 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
522 echo "\n";
524 <td<?php echo $colspan; ?> align="center">
525 <a href="<?php echo $text_url; ?>">
526 <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>
527 </td>
528 <?php
529 } // end horizontal/horizontalflipped mode
530 else {
531 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
532 . ' <a href="' . $text_url . '">' . "\n"
533 . ' <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"
534 . ' </td>' . "\n";
535 } // end vertical mode
538 // ... else if no button, displays empty(ies) col(s) if required
539 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
540 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
541 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 0;
542 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
543 echo "\n";
545 <td<?php echo $colspan; ?>></td>
546 <?php
547 echo "\n";
548 } // end horizontal/horizontalfipped mode
549 else {
550 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
551 } // end vertical mode
554 // 2. Displays the fields' name
555 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
556 // statement (see 2.1.3)
558 // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
559 // Do not show comments, if using horizontalflipped mode, because of space usage
560 if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
561 $comments_map = PMA_getComments($db, $table);
562 } else {
563 $comments_map = array();
566 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
567 require('./libraries/transformations.lib.php3');
568 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
572 if ($is_display['sort_lnk'] == '1') {
573 $is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
574 } else {
575 $is_join = FALSE;
578 // garvin: See if we have to highlight any header fields of a WHERE query.
579 // Uses SQL-Parser results.
580 $highlight_columns = array();
581 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
582 isset($analyzed_sql[0]['where_clause_identifiers'])) {
584 $wi = 0;
585 @reset($analyzed_sql[0]['where_clause_identifiers']);
586 while(list($wci_nr, $wci) = each($analyzed_sql[0]['where_clause_identifiers'])) {
587 $highlight_columns[$wci] = 'true';
591 for ($i = 0; $i < $fields_cnt; $i++) {
592 // garvin: See if this column should get highlight because it's used in the
593 // where-query.
594 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
595 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
596 } else {
597 $column_style = '';
600 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
601 if (isset($comments_map[$fields_meta[$i]->name])) {
602 $comments_table_wrap_pre = '<table border="0" cellpadding="0" cellspacing="0"><tr><th>';
603 $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>';
604 } else {
605 $comments_table_wrap_pre = '';
606 $comments_table_wrap_post = '';
609 // 2.1 Results can be sorted
610 if ($is_display['sort_lnk'] == '1') {
611 // Defines the url used to append/modify a sorting order
612 // 2.1.1 Checks if an hard coded 'order by' clause exists
613 if (eregi('(.*)([[:space:]]ORDER[[:space:]]*BY[[:space:]](.*))', $sql_query, $regs1)) {
614 if (eregi('((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)', $regs1[2], $regs2)) {
615 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
616 $sql_order = trim($regs2[1]);
617 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
618 $sort_expression = trim($after_order[2]);
620 else if (eregi('((.*))[[:space:]]+(LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) {
621 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]);
622 $sql_order = trim($regs3[1]) . ' ASC';
623 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
624 $sort_expression = trim($after_order[2]);
625 } else {
626 $unsorted_sql_query = trim($regs1[1]);
627 $sql_order = trim($regs1[2]) . ' ASC';
628 eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
629 $sort_expression = trim($after_order[2]);
631 } else {
632 $unsorted_sql_query = $sql_query;
635 // 2.1.2 Checks if the current column is used to sort the
636 // results
637 if (empty($sql_order)) {
638 $is_in_sort = FALSE;
639 } else {
640 // $pattern = str_replace('\\', '\\\\', $fields_meta[$i]->name);
641 // $pattern = str_replace('(','\(', $pattern);
642 // $pattern = str_replace(')','\)', $pattern);
643 // $pattern = str_replace('*','\*', $pattern);
645 // field name may be preceded by a space, or any number
646 // of characters followed by a dot (tablename.fieldname)
647 // $is_in_sort = eregi('([[:space:]]|(.*\.))(`?)' . $pattern . '(`?)[ ,$]', $sql_order);
648 // instead of using eregi(), now do a direct comparison
649 // for the sort expression (avoids problems with queries
650 // like "SELECT id, count(id)..." and clicking to sort
651 // on id or on count(id) )
652 $is_in_sort = (PMA_backquote($fields_meta[$i]->name) == $sort_expression ? TRUE : FALSE);
654 // 2.1.3 Checks if the table name is required (it's the case
655 // for a query with a "JOIN" statement and if the column
656 // isn't aliased)
657 if ($is_join
658 && !eregi('([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name, $select_stt[1], $parts)) {
659 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
660 } else {
661 $sort_tbl = '';
663 // 2.1.4 Check the field name for backquotes.
664 // If it contains some, it's probably a function column
665 // like 'COUNT(`field`)'
666 if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
667 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
668 } else {
669 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
671 // 2.1.5 Do define the sorting url
672 if (!$is_in_sort) {
673 // loic1: patch #455484 ("Smart" order)
674 $cfg['Order'] = strtoupper($GLOBALS['cfg']['Order']);
675 if ($cfg['Order'] == 'SMART') {
676 $cfg['Order'] = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
678 $sort_order .= $cfg['Order'];
679 $order_img = '';
681 else if (eregi('[[:space:]]ASC$', $sql_order)) {
682 $sort_order .= ' DESC';
683 $order_img = '&nbsp;<img src="./images/asc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" />';
685 else if (eregi('[[:space:]]DESC$', $sql_order)) {
686 $sort_order .= ' ASC';
687 $order_img = '&nbsp;<img src="./images/desc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" />';
689 if (eregi('(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))', $unsorted_sql_query, $regs3)) {
690 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
691 } else {
692 $sorted_sql_query = $unsorted_sql_query . $sort_order;
694 $url_query = PMA_generate_common_url($db, $table)
695 . '&amp;pos=' . $pos
696 . '&amp;session_max_rows=' . $session_max_rows
697 . '&amp;disp_direction=' . $disp_direction
698 . '&amp;repeat_cells=' . $repeat_cells
699 . '&amp;dontlimitchars=' . $dontlimitchars
700 . '&amp;sql_query=' . urlencode($sorted_sql_query);
702 // 2.1.5 Displays the sorting url
703 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
704 echo "\n";
706 <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
707 <?php echo $comments_table_wrap_pre; ?>
708 <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;"' : ''); ?>>
709 <?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"; ?>
710 <?php echo $comments_table_wrap_post; ?>
711 </th>
712 <?php
714 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
715 . $comments_table_wrap_pre
716 . ' <a href="sql.php3?' . $url_query . '">' . "\n"
717 . ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
718 . $comments_table_wrap_post
719 . ' </th>' . "\n";
720 } // end if (2.1)
722 // 2.2 Results can't be sorted
723 else {
724 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
725 echo "\n";
727 <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;"' : ''); ?>>
728 <?php echo $comments_table_wrap_pre; ?>
729 <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
730 <?php echo $comments_table_wrap_post; ?>
731 </th>
732 <?php
734 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
735 . $comments_table_wrap_pre
736 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
737 . $comments_table_wrap_post
738 . ' </th>';
739 } // end else (2.2)
740 } // end for
742 // 3. Displays the full/partial text button (part 2) at the right
743 // column of the result table header if possible and required...
744 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
745 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
746 && $is_display['text_btn'] == '1') {
747 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
748 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
749 echo "\n";
751 <td<?php echo $colspan; ?> align="center">
752 <a href="<?php echo $text_url; ?>">
753 <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>
754 </td>
755 <?php
756 } // end horizontal/horizontalflipped mode
757 else {
758 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
759 . ' <a href="' . $text_url . '">' . "\n"
760 . ' <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"
761 . ' </td>' . "\n";
762 } // end vertical mode
765 // ... else if no button, displays empty cols if required
766 // (unless coming from Browse mode print view)
767 else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
768 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
769 && (!$GLOBALS['is_header_sent'])) {
770 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
771 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
772 echo "\n";
774 <td<?php echo $colspan; ?>></td>
775 <?php
776 } // end horizontal/horizontalflipped mode
777 else {
778 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
779 } // end vertical mode
782 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
783 echo "\n";
785 </tr>
786 <?php
788 echo "\n";
790 return TRUE;
791 } // end of the 'PMA_displayTableHeaders()' function
796 * Displays the body of the results table
798 * @param integer the link id associated to the query which results have
799 * to be displayed
800 * @param array which elements to display
801 * @param array the list of relations
802 * @param array the analyzed query
804 * @return boolean always true
806 * @global string the current language
807 * @global string the current charset for MySQL
808 * @global integer the server to use (refers to the number in the
809 * configuration file)
810 * @global string the database name
811 * @global string the table name
812 * @global string the sql query
813 * @global string the url to go back in case of errors
814 * @global integer the current position in results
815 * @global integer the maximum number of rows per page
816 * @global array the list of fields properties
817 * @global integer the total number of fields returned by the sql query
818 * @global array informations used with vertical display mode
819 * @global string the display mode (horizontal/vertical/horizontalflipped)
820 * @global integer the number of row to display between two table headers
821 * @global boolean whether to limit the number of displayed characters of
822 * text type fields or not
824 * @access private
826 * @see PMA_displayTable()
828 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
830 global $lang, $convcharset, $server, $db, $table;
831 global $goto;
832 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
833 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
834 global $dontlimitchars;
836 if (!is_array($map)) {
837 $map = array();
840 <!-- Results table body -->
841 <?php
842 echo "\n";
844 $row_no = 0;
845 $vertical_display['edit'] = array();
846 $vertical_display['delete'] = array();
847 $vertical_display['data'] = array();
849 // Correction uva 19991216 in the while below
850 // Previous code assumed that all tables have keys, specifically that
851 // the phpMyAdmin GUI should support row delete/edit only for such
852 // tables.
853 // Although always using keys is arguably the prescribed way of
854 // defining a relational table, it is not required. This will in
855 // particular be violated by the novice.
856 // We want to encourage phpMyAdmin usage by such novices. So the code
857 // below has been changed to conditionally work as before when the
858 // table being displayed has one or more keys; but to display
859 // delete/edit options correctly for tables without keys.
861 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
862 // to get the NULL values
864 while ($row = PMA_mysql_fetch_array($dt_result)) {
866 // lem9: "vertical display" mode stuff
867 if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
868 echo '<tr>' . "\n";
870 for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
871 echo ' <td>&nbsp;</td>' . "\n";
874 reset($vertical_display['desc']);
875 while (list($key, $val) = each($vertical_display['desc'])) {
876 echo $val;
879 for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
880 echo ' <td>&nbsp;</td>' . "\n";
883 echo '</tr>' . "\n";
884 } // end if
886 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
887 $bgcolor = '#ffffff';
888 } else {
889 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
892 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
893 // loic1: pointer code part
894 $on_mouse = '';
895 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
896 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
897 $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
898 . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
900 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
901 $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
903 } // end if
905 <tr<?php echo $on_mouse; ?>>
906 <?php
907 echo "\n";
910 // 1. Prepares the row (gets primary keys to use)
911 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
912 $primary_key = '';
913 $unique_key = '';
914 $uva_nonprimary_condition = '';
916 // 1.1 Results from a "SELECT" statement -> builds the
917 // "primary" key to use in links
918 if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
919 for ($i = 0; $i < $fields_cnt; ++$i) {
920 $meta = $fields_meta[$i];
922 // do not use an alias in a condition
923 $column_for_condition = $meta->name;
924 reset($analyzed_sql[0]['select_expr']);
925 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
926 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
927 if (!empty($alias)) {
928 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
929 if ($alias == $meta->name) {
930 $column_for_condition = $true_column;
931 } // end if
932 } // end if
933 } // end while
935 // to fix the bug where float fields (primary or not)
936 // can't be matched because of the imprecision of
937 // floating comparison, use CONCAT
938 // (also, the syntax "CONCAT(field) IS NULL"
939 // that we need on the next "if" will work)
940 if ($meta->type == 'real') {
941 $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
942 } else {
943 $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
944 } // end if... else...
946 // loic1: To fix bug #474943 under php4, the row
947 // pointer will depend on whether the "is_null"
948 // php4 function is available or not
949 $pointer = (function_exists('is_null') ? $i : $meta->name);
950 if (!isset($row[$meta->name])
951 || (function_exists('is_null') && is_null($row[$pointer]))) {
952 $condition .= 'IS NULL AND';
953 } else {
954 if ($meta->type == 'blob') {
955 $condition .= 'LIKE 0x' . bin2hex($row[$pointer]). ' AND';
956 } else {
957 $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND';
960 if ($meta->primary_key > 0) {
961 $primary_key .= $condition;
962 } else if ($meta->unique_key > 0) {
963 $unique_key .= $condition;
965 $uva_nonprimary_condition .= $condition;
966 } // end for
968 // Correction uva 19991216: prefer primary or unique keys
969 // for condition, but use conjunction of all values if no
970 // primary key
971 if ($primary_key) {
972 $uva_condition = $primary_key;
973 } else if ($unique_key) {
974 $uva_condition = $unique_key;
975 } else {
976 $uva_condition = $uva_nonprimary_condition;
979 $uva_condition = urlencode(ereg_replace('[[:space:]]?AND$', '', $uva_condition));
980 } // end if (1.1)
982 // 1.2 Defines the urls for the modify/delete link(s)
983 $url_query = PMA_generate_common_url($db, $table)
984 . '&amp;pos=' . $pos
985 . '&amp;session_max_rows=' . $session_max_rows
986 . '&amp;disp_direction=' . $disp_direction
987 . '&amp;repeat_cells=' . $repeat_cells
988 . '&amp;dontlimitchars=' . $dontlimitchars;
990 // 1.2.1 Modify link(s)
991 if ($is_display['edit_lnk'] == 'ur') { // update row case
992 // $lnk_goto = 'sql.php3'
993 // . '?' . str_replace('&amp;', '&', $url_query)
994 // . '&sql_query=' . urlencode($sql_query)
995 // . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
996 // to reduce the length of the URL, because of some browsers limitations:
997 $lnk_goto = 'sql.php3';
999 $edit_url = 'tbl_change.php3'
1000 . '?' . $url_query
1001 . '&amp;primary_key=' . $uva_condition
1002 . '&amp;sql_query=' . urlencode($sql_query)
1003 . '&amp;goto=' . urlencode($lnk_goto);
1004 $edit_str = $GLOBALS['strEdit'];
1005 } // end if (1.2.1)
1007 if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) {
1008 $bookmark_go = '<form method="post" action="read_dump.php3">'
1009 . PMA_generate_common_hidden_inputs($row['dbase'], '')
1010 . '<input type="hidden" name="id_bookmark" value="' . $row['id'] . '" />'
1011 . '<input type="hidden" name="action_bookmark" value="0" />'
1012 . '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />'
1013 . '</form>';
1014 } else {
1015 $bookmark_go = '';
1018 // 1.2.2 Delete/Kill link(s)
1019 if ($is_display['del_lnk'] == 'dr') { // delete row case
1020 $lnk_goto = 'sql.php3'
1021 . '?' . str_replace('&amp;', '&', $url_query)
1022 . '&sql_query=' . urlencode($sql_query)
1023 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1024 . '&goto=' . (empty($goto) ? 'tbl_properties.php3' : $goto);
1025 $del_url = 'sql.php3'
1026 . '?' . $url_query
1027 . '&amp;sql_query=' . urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . ((PMA_MYSQL_INT_VERSION >= 32207) ? urlencode(' LIMIT 1') : '')
1028 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1029 . '&amp;goto=' . urlencode($lnk_goto);
1030 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
1031 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
1032 . ((PMA_MYSQL_INT_VERSION >= 32207) ? ' LIMIT 1' : '');
1033 $del_str = $GLOBALS['strDelete'];
1034 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
1035 $lnk_goto = 'sql.php3'
1036 . '?' . str_replace('&amp;', '&', $url_query)
1037 . '&sql_query=' . urlencode($sql_query)
1038 . '&goto=main.php3';
1039 $del_url = 'sql.php3?'
1040 . PMA_generate_common_url('mysql')
1041 . '&amp;sql_query=' . urlencode('KILL ' . $row['Id'])
1042 . '&amp;goto=' . urlencode($lnk_goto);
1043 $js_conf = 'KILL ' . $row['Id'];
1044 $del_str = $GLOBALS['strKill'];
1045 } // end if (1.2.2)
1047 // 1.3 Displays the links at left if required
1048 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1049 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1050 if (!empty($edit_url)) {
1051 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1052 echo PMA_linkOrButton($edit_url, $edit_str, '');
1053 echo $bookmark_go;
1054 echo ' </td>' . "\n";
1056 if (!empty($del_url)) {
1057 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1058 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1059 echo ' </td>' . "\n";
1061 } // end if (1.3)
1062 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1063 } // end if (1)
1065 // 2. Displays the rows' values
1066 for ($i = 0; $i < $fields_cnt; ++$i) {
1067 $meta = $fields_meta[$i];
1068 // loic1: To fix bug #474943 under php4, the row pointer will
1069 // depend on whether the "is_null" php4 function is
1070 // available or not
1071 $pointer = (function_exists('is_null') ? $i : $meta->name);
1073 // garvin: See if this column should get highlight because it's used in the
1074 // where-query.
1075 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1076 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
1077 } else {
1078 $column_style = '';
1081 // garvin: Wrap MIME-transformations. [MIME]
1082 $default_function = 'htmlspecialchars'; // default_function
1083 $transform_function = $default_function;
1084 $transform_options = array();
1086 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1088 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1089 // garvin: for security, never allow to break out from transformations directory
1090 $include_file = eregi_replace('\.\.*', '.', $GLOBALS['mime_map'][$meta->name]['transformation']);
1092 if (file_exists('./libraries/transformations/' . $include_file)) {
1093 $transformfunction_name = str_replace('.inc.php3', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1095 include('./libraries/transformations/' . $include_file);
1097 if (defined('PMA_TRANSFORMATION_' . strtoupper($transformfunction_name)) && function_exists('PMA_transformation_' . $transformfunction_name)) {
1098 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1099 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1101 } // end if file_exists
1102 } // end if transformation is set
1103 } // end if mime/transformation works.
1105 $transform_options['wrapper_link'] = '?'
1106 . (isset($url_query) ? $url_query : '')
1107 . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '')
1108 . '&amp;sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '')
1109 . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1110 . '&amp;transform_key=' . urlencode($meta->name);
1113 // n u m e r i c
1114 if ($meta->numeric == 1) {
1117 // lem9: if two fields have the same name (this is possible
1118 // with self-join queries, for example), using $meta->name
1119 // will show both fields NULL even if only one is NULL,
1120 // so use the $pointer
1121 // (works only if function_exists('is_null')
1122 // PS: why not always work with the number ($i), since
1123 // the default second parameter of
1124 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1125 // associative and numeric indices?
1127 //if (!isset($row[$meta->name])
1128 if (!isset($row[$pointer])
1129 || (function_exists('is_null') && is_null($row[$pointer]))) {
1130 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1131 } else if ($row[$pointer] != '') {
1132 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" nowrap="nowrap">';
1134 reset($analyzed_sql[0]['select_expr']);
1135 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1136 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1137 if (!empty($alias)) {
1138 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1139 if ($alias == $meta->name) {
1140 $meta->name = $true_column;
1141 } // end if
1142 } // end if
1143 } // end while
1145 if (isset($map[$meta->name])) {
1146 // Field to display from the foreign table?
1147 if (!empty($map[$meta->name][2])) {
1148 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1149 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1150 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1151 . ' = ' . $row[$pointer];
1152 $dispresult = PMA_mysql_query($dispsql);
1153 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1154 $dispval = PMA_mysql_result($dispresult, 0);
1156 else {
1157 $dispval = $GLOBALS['strLinkNotFound'];
1160 else {
1161 $dispval = '';
1162 } // end if... else...
1163 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1165 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1166 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1167 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1168 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>'
1169 . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer])) . '</a>';
1170 } else {
1171 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer]));
1173 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1174 } else {
1175 $vertical_display['data'][$row_no][$i] = ' <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" nowrap="nowrap">&nbsp;</td>' . "\n";
1178 // b l o b
1180 } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && eregi('BLOB', $meta->type)) {
1181 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1182 // TEXT fields type, however TEXT fields must be displayed
1183 // even if $cfg['ShowBlob'] is false -> get the true type
1184 // of the fields.
1185 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1187 if (eregi('BINARY', $field_flags)) {
1188 $blobtext = '[BLOB';
1189 if (isset($row[$pointer])) {
1190 $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
1191 $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
1192 unset($blob_size);
1195 $blobtext .= ']';
1196 $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options) : $default_function($blobtext));
1198 $vertical_display['data'][$row_no][$i] = ' <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
1199 } else {
1200 //if (!isset($row[$meta->name])
1201 if (!isset($row[$pointer])
1202 || (function_exists('is_null') && is_null($row[$pointer]))) {
1203 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1204 } else if ($row[$pointer] != '') {
1205 // garvin: if a transform function for blob is set, none of these replacements will be made
1206 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1207 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1209 // loic1: displays all space characters, 4 space
1210 // characters for tabulations and <cr>/<lf>
1211 $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options) : $default_function($row[$pointer]));
1212 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1213 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1215 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
1216 } else {
1217 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1220 } else {
1221 //if (!isset($row[$meta->name])
1222 if (!isset($row[$pointer])
1223 || (function_exists('is_null') && is_null($row[$pointer]))) {
1224 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1225 } else if ($row[$pointer] != '') {
1226 // loic1: support blanks in the key
1227 $relation_id = $row[$pointer];
1229 // loic1: Cut text/blob fields even if $cfg['ShowBlob'] is true
1230 if (eregi('BLOB', $meta->type)) {
1231 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1232 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1235 // loic1: displays special characters from binaries
1236 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1237 if (eregi('BINARY', $field_flags)) {
1238 $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]);
1239 $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]);
1240 $row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]);
1241 $row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]);
1242 $row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]);
1243 $row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
1245 // loic1: displays all space characters, 4 space
1246 // characters for tabulations and <cr>/<lf>
1247 else {
1248 $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options) : $default_function($row[$pointer]));
1249 $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
1250 $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
1253 // garvin: transform functions may enable nowrapping:
1254 $function_nowrap = $transform_function . '_nowrap';
1255 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1257 // loic1: do not wrap if date field type
1258 $nowrap = ((eregi('DATE|TIME', $meta->type) || $bool_nowrap) ? ' nowrap="nowrap"' : '');
1259 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
1261 reset($analyzed_sql[0]['select_expr']);
1262 while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
1263 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1264 if (!empty($alias)) {
1265 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1266 if ($alias == $meta->name) {
1267 $meta->name = $true_column;
1268 } // end if
1269 } // end if
1270 } // end while
1272 if (isset($map[$meta->name])) {
1273 // Field to display from the foreign table?
1274 if (!empty($map[$meta->name][2])) {
1275 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1276 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1277 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1278 . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
1279 $dispresult = @PMA_mysql_query($dispsql);
1280 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1281 $dispval = PMA_mysql_result($dispresult, 0);
1283 else {
1284 $dispval = $GLOBALS['strLinkNotFound'];
1287 else {
1288 $dispval = '';
1290 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1292 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php3?'
1293 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1294 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1295 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1296 . $row[$pointer] . '</a>';
1297 } else {
1298 $vertical_display['data'][$row_no][$i] .= $row[$pointer];
1300 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1301 } else {
1302 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1306 // lem9: output stored cell
1307 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1308 echo $vertical_display['data'][$row_no][$i];
1311 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1312 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1313 } else {
1314 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1316 } // end for (2)
1318 // 3. Displays the modify/delete links on the right if required
1319 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1320 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1321 if (!empty($edit_url)) {
1322 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1323 echo PMA_linkOrButton($edit_url, $edit_str, '');
1324 echo $bookmark_go;
1325 echo ' </td>' . "\n";
1327 if (!empty($del_url)) {
1328 echo ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n";
1329 echo PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''));
1330 echo ' </td>' . "\n";
1332 } // end if (3)
1334 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1335 echo "\n";
1337 </tr>
1338 <?php
1339 } // end if
1341 // 4. Gather links of del_urls and edit_urls in an array for later
1342 // output
1343 if (!isset($vertical_display['edit'][$row_no])) {
1344 $vertical_display['edit'][$row_no] = '';
1345 $vertical_display['delete'][$row_no] = '';
1348 if (isset($edit_url)) {
1349 $vertical_display['edit'][$row_no] .= ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1350 . PMA_linkOrButton($edit_url, $edit_str, '')
1351 . $bookmark_go
1352 . ' </td>' . "\n";
1355 if (isset($del_url)) {
1356 $vertical_display['delete'][$row_no] .= ' <td valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1357 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''))
1358 . ' </td>' . "\n";
1361 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1362 $row_no++;
1363 } // end while
1365 return TRUE;
1366 } // end of the 'PMA_displayTableBody()' function
1370 * Do display the result table with the vertical direction mode.
1371 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1373 * @return boolean always true
1375 * @global array the information to display
1376 * @global integer the number of row to display between two table headers
1378 * @access private
1380 * @see PMA_displayTable()
1382 function PMA_displayVerticalTable()
1384 global $vertical_display, $repeat_cells;
1386 reset($vertical_display);
1388 // Displays "edit" link at top if required
1389 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit'])) {
1390 echo '<tr>' . "\n";
1391 echo $vertical_display['textbtn'];
1392 reset($vertical_display['edit']);
1393 $foo_counter = 0;
1394 while (list($key, $val) = each($vertical_display['edit'])) {
1395 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1396 echo ' <td>&nbsp;</td>' . "\n";
1399 echo $val;
1400 $foo_counter++;
1401 } // end while
1402 echo '</tr>' . "\n";
1403 } // end if
1405 // Displays "delete" link at top if required
1406 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete'])) {
1407 echo '<tr>' . "\n";
1408 if (!is_array($vertical_display['edit'])) {
1409 echo $vertical_display['textbtn'];
1411 reset($vertical_display['delete']);
1412 $foo_counter = 0;
1413 while (list($key, $val) = each($vertical_display['delete'])) {
1414 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1415 echo '<td>&nbsp;</td>' . "\n";
1418 echo $val;
1419 $foo_counter++;
1420 } // end while
1421 echo '</tr>' . "\n";
1422 } // end if
1424 // Displays data
1425 reset($vertical_display['desc']);
1426 $row_no = 0;
1427 while (list($key, $val) = each($vertical_display['desc'])) {
1428 $row_no++;
1430 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
1431 $bgcolor = '#ffffff';
1432 } else {
1433 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1436 $on_mouse = '';
1437 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
1438 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
1439 $on_mouse = ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1440 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1442 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
1443 $on_mouse .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1445 } // end if
1447 echo '<tr ' . $on_mouse . '>' . "\n";
1448 echo $val;
1450 $foo_counter = 0;
1451 while (list($subkey, $subval) = each($vertical_display['rowdata'][$key])) {
1452 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1453 echo $val;
1456 echo $subval;
1457 $foo_counter++;
1458 } // end while
1460 echo '</tr>' . "\n";
1461 } // end while
1463 // Displays "edit" link at bottom if required
1464 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit'])) {
1465 echo '<tr>' . "\n";
1466 echo $vertical_display['textbtn'];
1467 reset($vertical_display['edit']);
1468 $foo_counter = 0;
1469 while (list($key, $val) = each($vertical_display['edit'])) {
1470 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1471 echo '<td>&nbsp;</td>' . "\n";
1474 echo $val;
1475 $foo_counter++;
1476 } // end while
1477 echo '</tr>' . "\n";
1478 } // end if
1480 // Displays "delete" link at bottom if required
1481 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete'])) {
1482 echo '<tr>' . "\n";
1483 if (!is_array($vertical_display['edit'])) {
1484 echo $vertical_display['textbtn'];
1486 reset($vertical_display['delete']);
1487 $foo_counter = 0;
1488 while (list($key, $val) = each($vertical_display['delete'])) {
1489 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1490 echo '<td>&nbsp;</td>' . "\n";
1493 echo $val;
1494 $foo_counter++;
1495 } // end while
1496 echo '</tr>' . "\n";
1499 return TRUE;
1500 } // end of the 'PMA_displayVerticalTable' function
1504 * Displays a table of results returned by a sql query.
1505 * This function is called by the "sql.php3" script.
1507 * @param integer the link id associated to the query which results have
1508 * to be displayed
1509 * @param array the display mode
1510 * @param array the analyzed query
1512 * @global string the current language
1513 * @global integer the server to use (refers to the number in the
1514 * configuration file)
1515 * @global array the current server config
1516 * @global string the database name
1517 * @global string the table name
1518 * @global string the url to go back in case of errors
1519 * @global string the current sql query
1520 * @global integer the total number of rows returned by the sql query
1521 * @global integer the total number of rows returned by the sql query
1522 * without any programmatically appended "LIMIT" clause
1523 * @global integer the current postion of the first record to be
1524 * displayed
1525 * @global array the list of fields properties
1526 * @global integer the total number of fields returned by the sql query
1527 * @global array informations used with vertical display mode
1528 * @global string the display mode (horizontal/vertical/horizontalflipped)
1529 * @global integer the number of row to display between two table headers
1530 * @global boolean whether to limit the number of displayed characters of
1531 * text type fields or not
1532 * @global array the relation settings
1534 * @access private
1536 * @see PMA_showMessage(), PMA_setDisplayMode(),
1537 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1538 * PMA_displayTableBody()
1540 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1542 global $lang, $server, $cfg, $db, $table;
1543 global $goto;
1544 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1545 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
1546 global $dontlimitchars;
1547 global $cfgRelation;
1549 // 1. ----- Prepares the work -----
1551 // 1.1 Gets the informations about which functionnalities should be
1552 // displayed
1553 $total = '';
1554 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1555 if ($total == '') {
1556 unset($total);
1559 // 1.2 Defines offsets for the next and previous pages
1560 if ($is_display['nav_bar'] == '1') {
1561 if (!isset($pos)) {
1562 $pos = 0;
1564 if ($GLOBALS['session_max_rows'] == 'all') {
1565 $pos_next = 0;
1566 $pos_prev = 0;
1567 } else {
1568 $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
1569 $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
1570 if ($pos_prev < 0) {
1571 $pos_prev = 0;
1574 } // end if
1576 // 1.3 Urlencodes the query to use in input form fields
1577 $encoded_sql_query = urlencode($sql_query);
1579 // 2. ----- Displays the top of the page -----
1581 // 2.1 Displays a messages with position informations
1582 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1583 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1584 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1585 } else {
1586 $selectstring = '';
1588 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1589 ? $total - 1
1590 : $pos_next - 1;
1591 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1592 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1593 PMA_showMessage($GLOBALS['strSQLQuery']);
1596 // 2.3 Displays the navigation bars
1597 if (!isset($table) || strlen(trim($table)) == 0) {
1598 $table = $fields_meta[0]->table;
1600 if ($is_display['nav_bar'] == '1') {
1601 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1602 echo "\n";
1603 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1604 echo "\n" . '<br /><br />' . "\n";
1607 // 2b ----- Get field references from Database -----
1608 // (see the 'relation' config variable)
1609 // loic1, 2002-03-02: extended to php3
1611 // init map
1612 $map = array();
1614 if ($cfgRelation['relwork']) {
1615 // find tables
1616 //$pattern = '`?[[:space:]]+(((ON|on)[[:space:]]+[^,]+)?,|((NATURAL|natural)[[:space:]]+)?(INNER|inner|LEFT|left|RIGHT|right)([[:space:]]+(OUTER|outer))?[[:space:]]+(JOIN|join))[[:space:]]*`?';
1617 //$target = eregi_replace('^.*[[:space:]]+FROM[[:space:]]+`?|`?[[:space:]]*(ON[[:space:]]+[^,]+)?(WHERE[[:space:]]+.*)?$', '', $sql_query);
1618 //$target = eregi_replace('`?[[:space:]]ORDER BY[[:space:]](.*)','',$target);
1619 //$tabs = '(\'' . join('\',\'', split($pattern, $target)) . '\')';
1620 $target=array();
1621 reset($analyzed_sql[0]['table_ref']);
1622 while (list ($table_ref_position, $table_ref) = each ($analyzed_sql[0]['table_ref'])) {
1623 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1625 $tabs = '(\'' . join('\',\'', $target) . '\')';
1627 $local_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
1628 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
1629 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
1630 . ' AND master_table IN ' . $tabs;
1631 $result = @PMA_query_as_cu($local_query, FALSE);
1632 if ($result) {
1633 while ($rel = PMA_mysql_fetch_row($result)) {
1634 // check for display field?
1635 if ($cfgRelation['displaywork']) {
1636 $display_field = PMA_getDisplayField($rel[1], $rel[2]);
1637 $map[$rel[0]] = array($rel[2], $rel[3], $display_field, $rel[1]);
1638 } // end if
1639 } // end while
1640 } // end if
1641 } // end 2b
1643 // 3. ----- Displays the results table -----
1644 echo '<!-- Results table -->' . "\n"
1645 . '<table ';
1646 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1647 echo 'border="1" cellpadding="2" cellspacing="0"';
1648 } else {
1649 echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="5"';
1651 echo '>' . "\n";
1652 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1653 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1654 // lem9: vertical output case
1655 if ($disp_direction == 'vertical') {
1656 PMA_displayVerticalTable();
1657 } // end if
1658 unset($vertical_display);
1660 </table>
1661 <?php
1663 echo "\n";
1665 // 4. ----- Displays the navigation bar at the bottom if required -----
1667 if ($is_display['nav_bar'] == '1') {
1668 echo '<br />' . "\n";
1669 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1670 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1671 echo "\n" . '<br /><br />' . "\n";
1673 } // end of the 'PMA_displayTable()' function
1675 } // $__PMA_DISPLAY_TBL_LIB__