2.2.4
[phpmyadmin/arisferyanto.git] / libraries / display_tbl.lib.php3
blobda9763a5e3454e1877e872f90c04bd0053f197c8
1 <?php
2 /* $Id$ */
5 /**
6 * Set of functions used to display the records returned by a sql query
7 */
11 if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')){
12 define('PMA_DISPLAY_TBL_LIB_INCLUDED', 1);
14 /**
15 * Defines the display mode to use for the results of a sql query
17 * It uses a synthetic string that contains all the required informations.
18 * In this string:
19 * - the first two characters stand for the the action to do while
20 * clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
21 * edit link...);
22 * - the next two characters stand for the the action to do while
23 * clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
24 * no delete link...);
25 * - the next characters are boolean values (1/0) and respectively stand
26 * for sorting links, navigation bar, "insert a new row" link, the
27 * bookmark feature and the expand/collapse text/blob fields button.
28 * Of course '0'/'1' means the feature won't/will be enabled.
30 * @param string the synthetic value for display_mode (see ยง1 a few
31 * lines above for explanations)
32 * @param integer the total number of rows returned by the sql query
33 * without any programmatically appended "LIMIT" clause
34 * (just a copy of $unlim_num_rows if it exists, else
35 * computed inside this function)
37 * @return array an array with explicit indexes for all the display
38 * elements
40 * @global string the database name
41 * @global string the table name
42 * @global integer the total number of rows returned by the sql query
43 * without any programmatically appended "LIMIT" clause
44 * @global array the properties of the fields returned by the query
45 * @global string the url to return to in case of error in a sql
46 * statement
48 * @access private
50 * @see PMA_displayTable()
52 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
54 global $db, $table;
55 global $unlim_num_rows, $fields_meta;
56 global $err_url;
58 // 1. Initializes the $do_display array
59 $do_display = array();
60 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
61 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
62 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
63 $do_display['nav_bar'] = (string) $the_disp_mode[5];
64 $do_display['ins_row'] = (string) $the_disp_mode[6];
65 $do_display['bkm_form'] = (string) $the_disp_mode[7];
66 $do_display['text_btn'] = (string) $the_disp_mode[8];
68 // 2. Display mode is not "false for all elements" -> updates the
69 // display mode
70 if ($the_disp_mode != 'nnnn00000') {
71 // 2.1 Statement is a "SELECT COUNT",
72 // "CHECK/ANALYZE/REPAIR/OPTIMIZE" or an "EXPLAIN"
73 if ($GLOBALS['is_count'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
74 $do_display['edit_lnk'] = 'nn'; // no edit link
75 $do_display['del_lnk'] = 'nn'; // no delete link
76 $do_display['sort_lnk'] = (string) '0';
77 $do_display['nav_bar'] = (string) '0';
78 $do_display['ins_row'] = (string) '0';
79 $do_display['bkm_form'] = (string) '1';
80 $do_display['text_btn'] = (string) '0';
82 // 2.2 Statement is a "SHOW..."
83 else if ($GLOBALS['is_show']) {
84 // 2.2.1 TODO : defines edit/delete links depending on show statement
85 $tmp = eregi('^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS)', $GLOBALS['sql_query'], $which);
86 if (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
87 $do_display['edit_lnk'] = 'nn'; // no edit link
88 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
90 else {
91 // Default case -> no links
92 $do_display['edit_lnk'] = 'nn'; // no edit link
93 $do_display['del_lnk'] = 'nn'; // no delete link
95 // 2.2.2 Other settings
96 $do_display['sort_lnk'] = (string) '0';
97 $do_display['nav_bar'] = (string) '0';
98 $do_display['ins_row'] = (string) '0';
99 $do_display['bkm_form'] = (string) '1';
100 $do_display['text_btn'] = (string) '0';
102 // 2.3 Other statements (ie "SELECT" ones) -> updates
103 // $do_display['edit_lnk'], $do_display['del_lnk'] and
104 // $do_display['text_btn'] (keeps other default values)
105 else {
106 $prev_table = $fields_meta[0]->table;
107 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
108 $is_link = ($do_display['edit_lnk'] != 'nn'
109 || $do_display['del_lnk'] != 'nn'
110 || $do_display['sort_lnk'] != '0'
111 || $do_display['ins_row'] != '0');
112 // 2.3.1 Displays text cut/expand button?
113 if ($do_display['text_btn'] == '0' && eregi('BLOB', $fields_meta[$i]->type)) {
114 $do_display['text_btn'] = (string) '1';
115 if (!$is_link) {
116 break;
118 } // end if (2.3.1)
119 // 2.3.2 Displays edit/delete/sort/insert links?
120 if ($is_link
121 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
122 $do_display['edit_lnk'] = 'nn'; // don't display links
123 $do_display['del_lnk'] = 'nn';
124 // TODO: May be problematic with same fields names in
125 // two joined table.
126 // $do_display['sort_lnk'] = (string) '0';
127 $do_display['ins_row'] = (string) '0';
128 if ($do_display['text_btn'] == '1') {
129 break;
131 } // end if (2.3.2)
132 $prev_table = $fields_meta[$i]->table;
133 } // end for
134 } // end if..elseif...else (2.1 -> 2.3)
135 } // end if (2)
137 // 3. Gets the total number of rows if it is unknown
138 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
139 $the_total = $unlim_num_rows;
141 else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
142 && (!empty($db) && !empty($table))) {
143 $local_query = 'SELECT COUNT(*) AS total FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
144 $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
145 $the_total = mysql_result($result, 0, 'total');
146 mysql_free_result($result);
149 // 4. If navigation bar or sorting fields names urls should be
150 // displayed but there is only one row, change these settings to
151 // false
152 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
153 if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
154 $do_display['nav_bar'] = (string) '0';
155 $do_display['sort_lnk'] = (string) '0';
157 } // end if (3)
159 // 5. Updates the synthetic var
160 $the_disp_mode = join('', $do_display);
162 return $do_display;
163 } // end of the 'PMA_setDisplayMode()' function
167 * Displays a navigation bar to browse among the results of a sql query
169 * @param integer the offset for the "next" page
170 * @param integer the offset for the "previous" page
171 * @param string the url-encoded query
173 * @global string the current language
174 * @global integer the server to use (refers to the number in the
175 * configuration file)
176 * @global string the database name
177 * @global string the table name
178 * @global string the url to go back in case of errors
179 * @global integer the total number of rows returned by the sql query
180 * @global integer the total number of rows returned by the sql query
181 * without any programmatically appended "LIMIT" clause
182 * @global integer the current position in results
183 * @global mixed the maximum number of rows per page ('all' = no limit)
184 * @global string the display mode (horizontal/vertical)
185 * @global integer the number of row to display between two table headers
186 * @global boolean whether to limit the number of displayed characters of
187 * text type fields or not
189 * @access private
191 * @see PMA_displayTable()
193 function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
195 global $lang, $server, $db, $table;
196 global $goto;
197 global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
198 global $disp_direction, $repeat_cells;
199 global $dontlimitchars;
202 <!-- Navigation bar -->
203 <table border="0">
204 <tr>
205 <?php
206 // Move to the beginning or to the previous page
207 if ($pos > 0 && $session_max_rows != 'all') {
208 // loic1: patch #474210 from Gosha Sakovich - part 1
209 if ($GLOBALS['cfgNavigationBarIconic']) {
210 $caption1 = '&lt;&lt;';
211 $caption2 = '&nbsp;&lt;&nbsp;';
212 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
213 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
214 } else {
215 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
216 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
217 $title1 = '';
218 $title2 = '';
219 } // end if... else...
221 <td>
222 <form action="sql.php3" method="post">
223 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
224 <input type="hidden" name="server" value="<?php echo $server; ?>" />
225 <input type="hidden" name="db" value="<?php echo $db; ?>" />
226 <input type="hidden" name="table" value="<?php echo $table; ?>" />
227 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
228 <input type="hidden" name="pos" value="0" />
229 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
230 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
231 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
232 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
233 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
234 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
235 </form>
236 </td>
237 <td>
238 <form action="sql.php3" method="post">
239 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
240 <input type="hidden" name="server" value="<?php echo $server; ?>" />
241 <input type="hidden" name="db" value="<?php echo $db; ?>" />
242 <input type="hidden" name="table" value="<?php echo $table; ?>" />
243 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
244 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
245 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
246 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
247 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
248 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
249 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
250 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
251 </form>
252 </td>
253 <?php
254 } // end move back
255 echo "\n";
257 <td>
258 &nbsp;&nbsp;&nbsp;
259 </td>
260 <td align="center">
261 <form action="sql.php3" method="post"
262 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', 1) && checkFormElementInRange(this, 'pos', 0, <?php echo $unlim_num_rows - 1; ?>))">
263 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
264 <input type="hidden" name="server" value="<?php echo $server; ?>" />
265 <input type="hidden" name="db" value="<?php echo $db; ?>" />
266 <input type="hidden" name="table" value="<?php echo $table; ?>" />
267 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
268 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
269 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
270 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?>&nbsp;:" />
271 <input type="text" name="session_max_rows" size="3" value="<?php echo (($session_max_rows != 'all') ? $session_max_rows : $GLOBALS['cfgMaxRows']); ?>" onfocus="this.select()" />
272 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
273 <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" onfocus="this.select()" />
274 <br />
275 <?php
276 // Display mode (horizontal/vertical and repeat headers)
277 $param1 = ' <select name="disp_direction">' . "\n"
278 . ' <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
279 . ' <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
280 . ' </select>' . "\n"
281 . ' ';
282 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n"
283 . ' ';
284 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
286 </form>
287 </td>
288 <td>
289 &nbsp;&nbsp;&nbsp;
290 </td>
291 <?php
292 // Move to the next page or to the last one
293 if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
294 && $session_max_rows != 'all') {
295 // loic1: patch #474210 from Gosha Sakovich - part 2
296 if ($GLOBALS['cfgNavigationBarIconic']) {
297 $caption3 = '&nbsp;&gt;&nbsp;';
298 $caption4 = '&gt;&gt;';
299 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
300 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
301 } else {
302 $caption3 = '&gt; ' . $GLOBALS['strNext'];
303 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
304 $title3 = '';
305 $title4 = '';
306 } // end if... else...
307 echo "\n";
309 <td>
310 <form action="sql.php3" method="post">
311 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
312 <input type="hidden" name="server" value="<?php echo $server; ?>" />
313 <input type="hidden" name="db" value="<?php echo $db; ?>" />
314 <input type="hidden" name="table" value="<?php echo $table; ?>" />
315 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
316 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
317 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
318 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
319 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
320 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
321 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
322 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
323 </form>
324 </td>
325 <td>
326 <form action="sql.php3" method="post"
327 onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
328 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
329 <input type="hidden" name="server" value="<?php echo $server; ?>" />
330 <input type="hidden" name="db" value="<?php echo $db; ?>" />
331 <input type="hidden" name="table" value="<?php echo $table; ?>" />
332 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
333 <input type="hidden" name="pos" value="<?php echo $unlim_num_rows - $session_max_rows; ?>" />
334 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
335 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
336 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
337 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
338 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
339 <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> />
340 </form>
341 </td>
342 <?php
343 } // end move toward
345 // Show all the records if allowed
346 if ($GLOBALS['cfgShowAll'] && ($num_rows < $unlim_num_rows)) {
347 echo "\n";
349 <td>
350 &nbsp;&nbsp;&nbsp;
351 </td>
352 <td>
353 <form action="sql.php3" method="post">
354 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
355 <input type="hidden" name="server" value="<?php echo $server; ?>" />
356 <input type="hidden" name="db" value="<?php echo $db; ?>" />
357 <input type="hidden" name="table" value="<?php echo $table; ?>" />
358 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
359 <input type="hidden" name="pos" value="0" />
360 <input type="hidden" name="session_max_rows" value="all" />
361 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
362 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
363 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
364 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
365 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
366 </form>
367 </td>
368 <?php
369 } // end show all
370 echo "\n";
372 </tr>
373 </table>
375 <?php
376 } // end of the 'PMA_displayTableNavigation()' function
380 * Displays the headers of the results table
382 * @param array which elements to display
383 * @param array the list of fields properties
384 * @param integer the total number of fields returned by the sql query
386 * @return boolean always true
388 * @global string the current language
389 * @global integer the server to use (refers to the number in the
390 * configuration file)
391 * @global string the database name
392 * @global string the table name
393 * @global string the sql query
394 * @global string the url to go back in case of errors
395 * @global integer the total number of rows returned by the sql query
396 * @global integer the current position in results
397 * @global integer the maximum number of rows per page
398 * @global array informations used with vertical display mode
399 * @global string the display mode (horizontal/vertical)
400 * @global integer the number of row to display between two table headers
401 * @global boolean whether to limit the number of displayed characters of
402 * text type fields or not
404 * @access private
406 * @see PMA_displayTable()
408 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0)
410 global $lang, $server, $db, $table;
411 global $goto;
412 global $sql_query, $num_rows, $pos, $session_max_rows;
413 global $vertical_display, $disp_direction, $repeat_cells;
414 global $dontlimitchars;
416 if ($disp_direction == 'horizontal') {
418 <!-- Results table headers -->
419 <tr>
420 <?php
422 echo "\n";
424 $vertical_display['emptypre'] = 0;
425 $vertical_display['emptyafter'] = 0;
427 // 1. Displays the full/partial text button (part 1)...
428 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
429 ? ' colspan="2"'
430 : '';
431 $text_url = 'sql.php3'
432 . '?lang=' . $lang
433 . '&amp;server=' . $server
434 . '&amp;db=' . urlencode($db)
435 . '&amp;table=' . urlencode($table)
436 . '&amp;sql_query=' . urlencode($sql_query)
437 . '&amp;pos=' . $pos
438 . '&amp;session_max_rows=' . $session_max_rows
439 . '&amp;pos=' . $pos
440 . '&amp;disp_direction=' . $disp_direction
441 . '&amp;repeat_cells=' . $repeat_cells
442 . '&amp;goto=' . $goto
443 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
445 // ... before the result table
446 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
447 && $is_display['text_btn'] == '1') {
448 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
449 if ($disp_direction == 'horizontal') {
451 <td colspan="<?php echo $fields_cnt; ?>" align="center">
452 <a href="<?php echo $text_url; ?>">
453 <img src="./images/<?php echo (($dontlimitchars) ? 'partialtext' : 'fulltext'); ?>.png" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
454 </td>
455 </tr>
457 <tr>
458 <?php
461 // ... at the left column of the result table header if possible
462 // and required
463 else if ($GLOBALS['cfgModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
464 echo "\n";
465 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
466 if ($disp_direction == 'horizontal') {
468 <td<?php echo $colspan; ?> align="center">
469 <a href="<?php echo $text_url; ?>">
470 <img src="./images/<?php echo (($dontlimitchars) ? 'partialtext' : 'fulltext'); ?>.png" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
471 </td>
472 <?php
475 // ... else if no button, displays empty(ies) col(s) if required
476 else if ($GLOBALS['cfgModifyDeleteAtLeft']
477 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
478 echo "\n";
479 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
480 if ($disp_direction == 'horizontal') {
482 <td<?php echo $colspan; ?>></td>
483 <?php
486 echo "\n";
488 // 2. Displays the fields' name
489 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
490 // statement (see 2.1.3)
491 if ($is_display['sort_lnk'] == '1') {
492 $is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
493 } else {
494 $is_join = FALSE;
496 for ($i = 0; $i < $fields_cnt; $i++) {
498 // 2.1 Results can be sorted
499 if ($is_display['sort_lnk'] == '1') {
500 // Defines the url used to append/modify a sorting order
501 // 2.1.1 Checks if an hard coded 'order by' clause exists
502 if (eregi('(.*)( ORDER BY (.*))', $sql_query, $regs1)) {
503 if (eregi('((.*)( ASC| DESC)( |$))(.*)', $regs1[2], $regs2)) {
504 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
505 $sql_order = trim($regs2[1]);
507 else if (eregi('((.*)) (LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) {
508 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]);
509 $sql_order = trim($regs3[1]) . ' ASC';
510 } else {
511 $unsorted_sql_query = trim($regs1[1]);
512 $sql_order = trim($regs1[2]) . ' ASC';
514 } else {
515 $unsorted_sql_query = $sql_query;
517 // 2.1.2 Checks if the current column is used to sort the
518 // results
519 if (empty($sql_order)) {
520 $is_in_sort = FALSE;
521 } else {
522 $is_in_sort = eregi(' (`?)' . str_replace('\\', '\\\\', $fields_meta[$i]->name) . '(`?)[ ,$]', $sql_order);
524 // 2.1.3 Checks if the table name is required (it's the case
525 // for a query with a "JOIN" statement and if the column
526 // isn't aliased)
527 if ($is_join
528 && !eregi('([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name, $select_stt[1], $parts)) {
529 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
530 } else {
531 $sort_tbl = '';
533 // 2.1.4 Do define the sorting url
534 if (!$is_in_sort) {
535 // loic1: patch #455484 ("Smart" order)
536 $cfgOrder = strtoupper($GLOBALS['cfgOrder']);
537 if ($cfgOrder == 'SMART') {
538 $cfgOrder = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
540 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ' . $cfgOrder;
541 $order_img = '';
543 else if (substr($sql_order, -3) == 'ASC' && $is_in_sort) {
544 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' DESC';
545 $order_img = '&nbsp;<img src="./images/asc_order.gif" border="0" width="7" height="7" alt="ASC" />';
547 else if (substr($sql_order, -4) == 'DESC' && $is_in_sort) {
548 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ASC';
549 $order_img = '&nbsp;<img src="./images/desc_order.gif" border="0" width="7" height="7" alt="DESC" />';
551 if (eregi('(.*)( LIMIT (.*)| PROCEDURE (.*)| FOR UPDATE| LOCK IN SHARE MODE)', $unsorted_sql_query, $regs3)) {
552 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
553 } else {
554 $sorted_sql_query = $unsorted_sql_query . $sort_order;
556 $url_query = 'lang=' . $lang
557 . '&amp;server=' . $server
558 . '&amp;db=' . urlencode($db)
559 . '&amp;table=' . urlencode($table)
560 . '&amp;pos=' . $pos
561 . '&amp;session_max_rows=' . $session_max_rows
562 . '&amp;disp_direction=' . $disp_direction
563 . '&amp;repeat_cells=' . $repeat_cells
564 . '&amp;dontlimitchars=' . $dontlimitchars
565 . '&amp;sql_query=' . urlencode($sorted_sql_query);
567 // 2.1.5 Displays the sorting url
568 if ($disp_direction == 'horizontal') {
570 <th>
571 <a href="sql.php3?<?php echo $url_query; ?>">
572 <?php echo htmlspecialchars($fields_meta[$i]->name); ?></a><?php echo $order_img . "\n"; ?>
573 </th>
574 <?php
576 $vertical_display['desc'][] = ' <th>' . "\n"
577 . ' <a href="sql.php3?' . $url_query . '">' . "\n"
578 . ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
579 . ' </th>' . "\n";
580 } // end if (2.1)
582 // 2.2 Results can't be sorted
583 else {
584 echo "\n";
585 if ($disp_direction == 'horizontal') {
587 <th>
588 <?php echo htmlspecialchars($fields_meta[$i]->name) . "\n"; ?>
589 </th>
590 <?php
592 $vertical_display['desc'][] = ' <th>' . "\n"
593 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
594 . ' </th>';
595 } // end else (2.2)
596 echo "\n";
597 } // end for
599 // 3. Displays the full/partial text button (part 2) at the right
600 // column of the result table header if possible and required...
601 if ($GLOBALS['cfgModifyDeleteAtRight']
602 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
603 && $is_display['text_btn'] == '1') {
604 echo "\n";
605 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
606 if ($disp_direction == 'horizontal') {
608 <td<?php echo $colspan; ?> align="center">
609 <a href="<?php echo $text_url; ?>">
610 <img src="./images/<?php echo (($dontlimitchars) ? 'partialtext' : 'fulltext'); ?>.png" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
611 </td>
612 <?php
615 // ... else if no button, displays empty cols if required
616 else if ($GLOBALS['cfgModifyDeleteAtRight']
617 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')) {
618 echo "\n" . ' <td' . $colspan . '></td>';
619 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 2 : 1;
621 echo "\n";
623 if ($disp_direction == 'horizontal') {
625 </tr>
626 <?php
628 echo "\n";
630 return TRUE;
631 } // end of the 'PMA_displayTableHeaders()' function
635 * Displays the body of the results table
637 * @param integer the link id associated to the query which results have
638 * to be displayed
639 * @param array which elements to display
640 * @param array the list of relations
642 * @return boolean always true
644 * @global string the current language
645 * @global integer the server to use (refers to the number in the
646 * configuration file)
647 * @global string the database name
648 * @global string the table name
649 * @global string the sql query
650 * @global string the url to go back in case of errors
651 * @global integer the current position in results
652 * @global integer the maximum number of rows per page
653 * @global array the list of fields properties
654 * @global integer the total number of fields returned by the sql query
655 * @global array informations used with vertical display mode
656 * @global string the display mode (horizontal/vertical)
657 * @global integer the number of row to display between two table headers
658 * @global boolean whether to limit the number of displayed characters of
659 * text type fields or not
661 * @access private
663 * @see PMA_displayTable()
665 function PMA_displayTableBody(&$dt_result, &$is_display, $map = array())
667 global $lang, $server, $db, $table;
668 global $goto;
669 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
670 global $vertical_display, $disp_direction, $repeat_cells;
671 global $dontlimitchars;
674 <!-- Results table body -->
675 <?php
676 echo "\n";
678 $foo = 0;
679 $vertical_display['edit'] = array();
680 $vertical_display['delete'] = array();
681 $vertical_display['data'] = array();
683 // Correction uva 19991216 in the while below
684 // Previous code assumed that all tables have keys, specifically that
685 // the phpMyAdmin GUI should support row delete/edit only for such
686 // tables.
687 // Although always using keys is arguably the prescribed way of
688 // defining a relational table, it is not required. This will in
689 // particular be violated by the novice.
690 // We want to encourage phpMyAdmin usage by such novices. So the code
691 // below has been changed to conditionally work as before when the
692 // table being displayed has one or more keys; but to display
693 // delete/edit options correctly for tables without keys.
695 // loic1: use 'mysql_fetch_array' rather than 'mysql_fetch_row' to get
696 // the NULL values
698 while ($row = mysql_fetch_array($dt_result)) {
700 // lem9: "vertical display" mode stuff
701 if (($foo != 0) && ($repeat_cells != 0) && !($foo % $repeat_cells) && $disp_direction == 'horizontal') {
702 echo '<tr>' . "\n";
704 for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
705 echo ' <td>&nbsp;</td>' . "\n";
708 reset($vertical_display['desc']);
709 while (list($key, $val) = each($vertical_display['desc'])) {
710 echo ' ' . $val;
713 for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
714 echo ' <td>&nbsp;</td>' . "\n";
717 echo '</tr>' . "\n";
718 } // end if
720 $bgcolor = ($foo % 2) ? $GLOBALS['cfgBgcolorOne'] : $GLOBALS['cfgBgcolorTwo'];
722 if ($disp_direction == 'horizontal') {
723 // loic1: pointer code part
724 if ($GLOBALS['cfgBrowsePointerColor'] == '') {
725 $on_mouse = '';
726 } else if ($GLOBALS['cfgBrowseMarkRow'] == '1') {
727 $on_mouse = ' onmousedown="setPointer(this, \'' . $GLOBALS['cfgBrowsePointerColor'] . '\', \'' . $bgcolor . '\')"';
728 } else {
729 $on_mouse = ' onmouseover="setPointer(this, \'' . $GLOBALS['cfgBrowsePointerColor'] . '\', \'' . $bgcolor . '\')" onmouseout="setPointer(this, \'' . $bgcolor . '\', \'' . $bgcolor . '\')"';
732 <tr<?php echo $on_mouse; ?>>
733 <?php
735 echo (($disp_direction == 'horizontal') ? "\n" : '');
737 // 1. Prepares the row (gets primary keys to use)
738 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
739 $primary_key = '';
740 $unique_key = '';
741 $uva_nonprimary_condition = '';
743 // 1.1 Results from a "SELECT" statement -> builds the
744 // the "primary" key to use in links
745 if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
746 for ($i = 0; $i < $fields_cnt; ++$i) {
747 $primary = $fields_meta[$i];
748 $condition = ' ' . PMA_backquote($primary->name) . ' ';
749 if (!isset($row[$primary->name])
750 || (function_exists('is_null') && is_null($row[$primary->name]))) {
751 $condition .= 'IS NULL AND';
752 } else {
753 $condition .= '= \'' . PMA_sqlAddslashes($row[$primary->name]) . '\' AND';
755 if ($primary->primary_key > 0) {
756 $primary_key .= $condition;
757 } else if ($primary->unique_key > 0) {
758 $unique_key .= $condition;
760 $uva_nonprimary_condition .= $condition;
761 } // end for
763 // Correction uva 19991216: prefer primary or unique keys
764 // for condition, but use conjunction of all values if no
765 // primary key
766 if ($primary_key) {
767 $uva_condition = $primary_key;
768 } else if ($unique_key) {
769 $uva_condition = $unique_key;
770 } else {
771 $uva_condition = $uva_nonprimary_condition;
773 $uva_condition = urlencode(ereg_replace(' ?AND$', '', $uva_condition));
774 } // end if (1.1)
776 // 1.2 Defines the urls for the modify/delete link(s)
777 $url_query = 'lang=' . $lang
778 . '&amp;server=' . $server
779 . '&amp;db=' . urlencode($db)
780 . '&amp;table=' . urlencode($table)
781 . '&amp;pos=' . $pos
782 . '&amp;session_max_rows=' . $session_max_rows
783 . '&amp;disp_direction=' . $disp_direction
784 . '&amp;repeat_cells=' . $repeat_cells
785 . '&amp;dontlimitchars=' . $dontlimitchars;
787 // 1.2.1 Modify link(s)
788 if ($is_display['edit_lnk'] == 'ur') { // update row case
789 if (!empty($goto)
790 && empty($GLOBALS['QUERY_STRING'])
791 && (empty($GLOBALS['HTTP_SERVER_VARS']) || empty($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']))) {
792 $lnk_goto = $goto;
793 } else {
794 $lnk_goto = 'sql.php3';
796 $edit_url = 'tbl_change.php3'
797 . '?' . $url_query
798 . '&amp;primary_key=' . $uva_condition
799 . '&amp;sql_query=' . urlencode($sql_query)
800 . '&amp;goto=' . urlencode($lnk_goto);
801 $edit_str = $GLOBALS['strEdit'];
802 } // end if (1.2.1)
804 // 1.2.2 Delete/Kill link(s)
805 if ($is_display['del_lnk'] == 'dr') { // delete row case
806 $lnk_goto = 'sql.php3'
807 . '?' . str_replace('&amp;', '&', $url_query)
808 . '&sql_query=' . urlencode($sql_query)
809 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
810 . '&goto=tbl_properties.php3';
811 $del_url = 'sql.php3'
812 . '?' . $url_query
813 . '&amp;sql_query=' . urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . urlencode(' LIMIT 1')
814 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
815 . '&amp;goto=' . urlencode($lnk_goto);
816 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
817 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE)) . ' LIMIT 1';
818 $del_str = $GLOBALS['strDelete'];
819 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
820 $lnk_goto = 'sql.php3'
821 . '?' . str_replace('&amp;', '&', $url_query)
822 . '&sql_query=' . urlencode($sql_query)
823 . '&goto=main.php3';
824 $del_url = 'sql.php3'
825 . '?lang=' . $lang
826 . '&amp;server=' . $server
827 . '&amp;db=mysql'
828 . '&amp;sql_query=' . urlencode('KILL ' . $row['Id'])
829 . '&amp;goto=' . urlencode($lnk_goto);
830 $js_conf = 'KILL ' . $row['Id'];
831 $del_str = $GLOBALS['strKill'];
832 } // end if (1.2.2)
834 // 1.3 Displays the links at left if required
835 if ($GLOBALS['cfgModifyDeleteAtLeft']
836 && ($disp_direction == 'horizontal')) {
837 if (!empty($edit_url)) {
839 <td bgcolor="<?php echo $bgcolor; ?>">
840 <a href="<?php echo $edit_url; ?>">
841 <?php echo $edit_str; ?></a>
842 </td>
843 <?php
845 if (!empty($del_url)) {
846 echo "\n";
848 <td bgcolor="<?php echo $bgcolor; ?>">
849 <a href="<?php echo $del_url; ?>"
850 <?php if (isset($js_conf)) echo 'onclick="return confirmLink(this, \'' . $js_conf . '\')"'; ?>>
851 <?php echo $del_str; ?></a>
852 </td>
853 <?php
855 } // end if (1.3)
856 echo (($disp_direction == 'horizontal') ? "\n" : '');
857 } // end if (1)
859 // 2. Displays the rows' values
860 for ($i = 0; $i < $fields_cnt; ++$i) {
861 $primary = $fields_meta[$i];
862 if ($primary->numeric == 1) {
863 if (!isset($row[$primary->name])
864 || (function_exists('is_null') && is_null($row[$primary->name]))) {
865 $vertical_display['data'][$foo][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
866 } else if ($row[$i] != '') {
867 $vertical_display['data'][$foo][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '">';
868 if (isset($map[$primary->name])) {
869 $vertical_display['data'][$foo][$i] .= '<a href="sql.php3?'
870 . 'lang=' . $lang . '&amp;server=' . $server
871 . '&amp;db=' . urlencode($db) . '&amp;table=' . urlencode($map[$primary->name][0])
872 . '&amp;pos=0&amp;sessionMaxRow=' . $sessionMaxRow . '&amp;dontlimitchars=' . $dontlimitchars
873 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$primary->name][0]) . ' WHERE ' . $map[$primary->name][1] . ' = ' . $row[$i]) . '">'
874 . $row[$primary->name] . '</a>';
875 } else {
876 $vertical_display['data'][$foo][$i] .= $row[$primary->name];
878 $vertical_display['data'][$foo][$i] .= '</td>' . "\n";
879 } else {
880 $vertical_display['data'][$foo][$i] = ' <td align="right" valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
882 } else if ($GLOBALS['cfgShowBlob'] == FALSE && eregi('BLOB', $primary->type)) {
883 // loic1 : mysql_fetch_fields returns BLOB in place of TEXT
884 // fields type, however TEXT fields must be displayed even
885 // if $cfgShowBlob is false -> get the true type of the
886 // fields.
887 $field_flags = mysql_field_flags($dt_result, $i);
888 if (eregi('BINARY', $field_flags)) {
889 $vertical_display['data'][$foo][$i] = ' <td align="center" valign="top" bgcolor="' . $bgcolor . '">[BLOB]</td>' . "\n";
890 } else {
891 if (!isset($row[$primary->name])
892 || (function_exists('is_null') && is_null($row[$primary->name]))) {
893 $vertical_display['data'][$foo][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
894 } else if ($row[$primary->name] != '') {
895 if (strlen($row[$primary->name]) > $GLOBALS['cfgLimitChars'] && ($dontlimitchars != 1)) {
896 $row[$primary->name] = substr($row[$primary->name], 0, $GLOBALS['cfgLimitChars']) . '...';
898 // loic1: displays all space characters, 4 space
899 // characters for tabulations and <cr>/<lf>
900 $row[$primary->name] = htmlspecialchars($row[$primary->name]);
901 $row[$primary->name] = str_replace("\011", '&nbsp;&nbsp;&nbsp;&nbsp;', str_replace(' ', '&nbsp;', $row[$primary->name]));
902 $row[$primary->name] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$primary->name]);
903 $vertical_display['data'][$foo][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">' . $row[$primary->name] . '</td>' . "\n";
904 } else {
905 $vertical_display['data'][$foo][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
908 } else {
909 if (!isset($row[$primary->name])
910 || (function_exists('is_null') && is_null($row[$primary->name]))) {
911 $vertical_display['data'][$foo][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
912 } else if ($row[$primary->name] != '') {
913 // loic1: Cut text/blob fields even if $cfgShowBlob is true
914 if (eregi('BLOB', $primary->type)) {
915 if (strlen($row[$primary->name]) > $GLOBALS['cfgLimitChars'] && ($dontlimitchars != 1)) {
916 $row[$primary->name] = substr($row[$primary->name], 0, $GLOBALS['cfgLimitChars']) . '...';
919 // loic1: displays special characters from binaries
920 $field_flags = mysql_field_flags($dt_result, $i);
921 if (eregi('BINARY', $field_flags)) {
922 $row[$primary->name] = str_replace("\x00", '\0', $row[$primary->name]);
923 $row[$primary->name] = str_replace("\x08", '\b', $row[$primary->name]);
924 $row[$primary->name] = str_replace("\x0a", '\n', $row[$primary->name]);
925 $row[$primary->name] = str_replace("\x0d", '\r', $row[$primary->name]);
926 $row[$primary->name] = str_replace("\x1a", '\Z', $row[$primary->name]);
928 // loic1: displays all space characters, 4 space
929 // characters for tabulations and <cr>/<lf>
930 else {
931 $row[$primary->name] = htmlspecialchars($row[$primary->name]);
932 $row[$primary->name] = str_replace("\011", '&nbsp;&nbsp;&nbsp;&nbsp;', str_replace(' ', '&nbsp;', $row[$primary->name]));
933 $row[$primary->name] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$primary->name]);
935 $vertical_display['data'][$foo][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">' . $row[$primary->name] . '</td>' . "\n";
936 } else {
937 $vertical_display['data'][$foo][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
941 // lem9: output stored cell
942 if ($disp_direction == 'horizontal') {
943 echo $vertical_display['data'][$foo][$i];
946 if (isset($vertical_display['rowdata'][$i][$foo])) {
947 $vertical_display['rowdata'][$i][$foo] .= $vertical_display['data'][$foo][$i];
948 } else {
949 $vertical_display['rowdata'][$i][$foo] = $vertical_display['data'][$foo][$i];
951 } // end for (2)
953 // 3. Displays the modify/delete links on the right if required
954 if ($GLOBALS['cfgModifyDeleteAtRight']
955 && ($disp_direction == 'horizontal')) {
956 if (!empty($edit_url)) {
958 <td bgcolor="<?php echo $bgcolor; ?>">
959 <a href="<?php echo $edit_url; ?>">
960 <?php echo $edit_str; ?></a>
961 </td>
962 <?php
964 if (!empty($del_url)) {
965 echo "\n";
967 <td bgcolor="<?php echo $bgcolor; ?>">
968 <a href="<?php echo $del_url; ?>"
969 <?php if (isset($js_conf)) echo 'onclick="return confirmLink(this, \'' . $js_conf . '\')"'; ?>>
970 <?php echo $del_str; ?></a>
971 </td>
972 <?php
974 } // end if (3)
976 if ($disp_direction == 'horizontal') {
977 echo "\n";
979 </tr>
980 <?php
981 } // end if
983 // 4. Gather links of del_urls and edit_urls in an array for later
984 // output
985 if (!isset($vertical_display['edit'][$foo])) {
986 $vertical_display['edit'][$foo] = '';
987 $vertical_display['delete'][$foo] = '';
989 if (isset($edit_url)) {
990 $vertical_display['edit'][$foo] .= ' <td bgcolor="' . $bgcolor . '">' . "\n"
991 . ' <a href="' . $edit_url . '">' . "\n"
992 . ' ' . $edit_str . '</a>' . "\n"
993 . ' </td>' . "\n";
996 if (isset($del_url)) {
997 $vertical_display['delete'][$foo] .= ' <td bgcolor="' . $bgcolor . '">' . "\n"
998 . ' <a href="' . $del_url . '"';
1000 if (isset($js_conf)) {
1001 $vertical_display['delete'][$foo] .= 'onclick="return confirmLink(this, \'' . $js_conf . '\')"';
1003 if (isset($del_str)) {
1004 $vertical_display['delete'][$foo] .= '>' . "\n"
1005 . ' ' . $del_str . '</a>' . "\n"
1006 . ' </td>' . "\n";
1009 echo (($disp_direction == 'horizontal') ? "\n" : '');
1010 $foo++;
1011 } // end while
1013 return TRUE;
1014 } // end of the 'PMA_displayTableBody()' function
1018 * Do display the result table with the vertical direction mode.
1019 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1021 * @return boolean always true
1023 * @global array the information to display
1024 * @global integer the number of row to display between two table headers
1026 * @access private
1028 * @see PMA_displayTable()
1030 function PMA_displayVerticalTable()
1032 global $vertical_display, $repeat_cells;
1034 reset($vertical_display);
1036 // Displays "edit" link at top if required
1037 if ($GLOBALS['cfgModifyDeleteAtLeft'] && is_array($vertical_display['edit'])) {
1038 echo '<tr>' . "\n";
1039 echo ' <td>&nbsp;</td>' . "\n";
1040 reset($vertical_display['edit']);
1041 $foo_counter = 0;
1042 while (list($key, $val) = each($vertical_display['edit'])) {
1043 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1044 echo ' <td>&nbsp;</td>' . "\n";
1047 echo $val;
1048 $foo_counter++;
1049 } // end while
1050 echo '</tr>' . "\n";
1051 } // end if
1053 // Displays "delete" link at top if required
1054 if ($GLOBALS['cfgModifyDeleteAtLeft'] && is_array($vertical_display['delete'])) {
1055 echo '<tr>' . "\n";
1056 echo '<td>&nbsp;</td>' . "\n";
1057 reset($vertical_display['delete']);
1058 $foo_counter = 0;
1059 while (list($key, $val) = each($vertical_display['delete'])) {
1060 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1061 echo '<td>&nbsp;</td>' . "\n";
1064 echo $val;
1065 $foo_counter++;
1066 } // end while
1067 echo '</tr>' . "\n";
1068 } // end if
1070 // Displays data
1071 reset($vertical_display['desc']);
1072 while (list($key, $val) = each($vertical_display['desc'])) {
1073 echo '<tr>' . "\n";
1074 echo $val;
1076 $foo_counter = 0;
1077 while (list($subkey, $subval) = each($vertical_display['rowdata'][$key])) {
1078 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1079 echo $val;
1082 echo $subval;
1083 $foo_counter++;
1084 } // end while
1086 echo '</tr>' . "\n";
1087 } // end while
1089 // Displays "edit" link at bottom if required
1090 if ($GLOBALS['cfgModifyDeleteAtRight'] && is_array($vertical_display['edit'])) {
1091 echo '<tr>' . "\n";
1092 echo ' <td>&nbsp;</td>' . "\n";
1093 reset($vertical_display['edit']);
1094 $foo_counter = 0;
1095 while (list($key, $val) = each($vertical_display['edit'])) {
1096 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1097 echo '<td>&nbsp;</td>' . "\n";
1100 echo $val;
1101 $foo_counter++;
1102 } // end while
1103 echo '</tr>' . "\n";
1104 } // end if
1106 // Displays "delete" link at bottom if required
1107 if ($GLOBALS['cfgModifyDeleteAtRight'] && is_array($vertical_display['delete'])) {
1108 echo '<tr>' . "\n";
1109 echo '<td>&nbsp;</td>' . "\n";
1110 reset($vertical_display['delete']);
1111 $foo_counter = 0;
1112 while (list($key, $val) = each($vertical_display['delete'])) {
1113 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1114 echo '<td>&nbsp;</td>' . "\n";
1117 echo $val;
1118 $foo_counter++;
1119 } // end while
1120 echo '</tr>' . "\n";
1123 return TRUE;
1124 } // end of the 'PMA_displayVerticalTable' function
1128 * Displays a table of results returned by a sql query.
1129 * This function is called by the "sql.php3" script.
1131 * @param integer the link id associated to the query which results have
1132 * to be displayed
1133 * @param array the display mode
1135 * @global string the current language
1136 * @global integer the server to use (refers to the number in the
1137 * configuration file)
1138 * @global array the current server config
1139 * @global string the database name
1140 * @global string the table name
1141 * @global string the url to go back in case of errors
1142 * @global string the current sql query
1143 * @global integer the total number of rows returned by the sql query
1144 * @global integer the total number of rows returned by the sql query
1145 * without any programmatically appended "LIMIT" clause
1146 * @global integer the current postion of the first record to be
1147 * displayed
1148 * @global array the list of fields properties
1149 * @global integer the total number of fields returned by the sql query
1150 * @global array informations used with vertical display mode
1151 * @global string the display mode (horizontal/vertical)
1152 * @global integer the number of row to display between two table headers
1153 * @global boolean whether to limit the number of displayed characters of
1154 * text type fields or not
1156 * @access private
1158 * @see PMA_showMessage(), PMA_setDisplayMode(),
1159 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1160 * PMA_displayTableBody()
1162 function PMA_displayTable(&$dt_result, &$the_disp_mode)
1164 global $lang, $server, $cfgServer, $db, $table;
1165 global $goto;
1166 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1167 global $vertical_display, $disp_direction, $repeat_cells;
1168 global $dontlimitchars;
1170 // 1. ----- Prepares the work -----
1172 // 1.1 Gets the informations about which functionnalities should be
1173 // displayed
1174 $total = '';
1175 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1176 if ($total == '') {
1177 unset($total);
1180 // 1.2 Defines offsets for the next and previous pages
1181 if ($is_display['nav_bar'] == '1') {
1182 if (!isset($pos)) {
1183 $pos = 0;
1185 if ($GLOBALS['session_max_rows'] == 'all') {
1186 $pos_next = 0;
1187 $pos_prev = 0;
1188 } else {
1189 $pos_next = $pos + $GLOBALS['cfgMaxRows'];
1190 $pos_prev = $pos - $GLOBALS['cfgMaxRows'];
1191 if ($pos_prev < 0) {
1192 $pos_prev = 0;
1195 } // end if
1197 // 1.3 Urlencodes the query to use in input form fields ($sql_query
1198 // will be stripslashed in 'sql.php3' if the 'magic_quotes_gpc'
1199 // directive is set to 'on')
1200 if (get_magic_quotes_gpc()) {
1201 $encoded_sql_query = urlencode(addslashes($sql_query));
1202 } else {
1203 $encoded_sql_query = urlencode($sql_query);
1206 // 2. ----- Displays the top of the page -----
1208 // 2.1 Displays a messages with position informations
1209 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1210 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1211 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1212 } else {
1213 $selectstring = '';
1215 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1216 ? $total
1217 : $pos_next;
1218 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ')');
1219 } else {
1220 PMA_showMessage($GLOBALS['strSQLQuery']);
1223 // 2.3 Displays the navigation bars
1224 if (!isset($table) || strlen(trim($table)) == 0) {
1225 $table = $fields_meta[0]->table;
1227 if ($is_display['nav_bar'] == '1') {
1228 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1229 echo "\n";
1230 } else {
1231 echo "\n" . '<br /><br />' . "\n";
1234 // 2b ----- Get field references from Database -----
1235 // (see the 'relation' config variable)
1236 // (currently not available for PHP3 due to spliti() )
1238 // init map
1239 $map = array();
1241 if (PMA_PHP_INT_VERSION >= 40000
1242 && isset($cfgServer['relation'])
1243 && !empty($cfgServer['relation'])) {
1244 // find tables
1245 $tabs = '(\'' . join('\',\'', spliti('`? *((on [^,]+)?,|(NATURAL )?(inner|left|right)( outer)? join) *`?',
1246 eregi_replace('^.*FROM +`?|`? *(on [^,]+)?(WHERE.*)?$', '', $sql_query))) . '\')';
1248 $local_query = 'SELECT src_column, dest_table, dest_column'
1249 . ' FROM ' . $cfgServer['relation']
1250 . ' WHERE src_table IN ' . $tabs;
1251 $result = @mysql_query($local_query);
1252 if ($result) {
1253 while ($rel = mysql_fetch_row($result)) {
1254 $map[$rel[0]] = array($rel[1], $rel[2]);
1257 } // end 2b
1259 // 3. ----- Displays the results table -----
1261 <!-- Results table -->
1262 <table border="<?php echo $GLOBALS['cfgBorder']; ?>" cellpadding="5">
1263 <?php
1264 echo "\n";
1265 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt);
1266 PMA_displayTableBody($dt_result, $is_display, $map);
1267 // lem9: vertical output case
1268 if ($disp_direction == 'vertical') {
1269 PMA_displayVerticalTable();
1270 } // end if
1271 unset($vertical_display);
1273 </table>
1274 <br />
1275 <?php
1277 echo "\n";
1279 // 4. ----- Displays the navigation bar at the bottom if required -----
1281 if ($is_display['nav_bar'] == '1') {
1282 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1283 } else {
1284 echo "\n" . '<br />' . "\n";
1286 } // end of the 'PMA_displayTable()' function
1288 } // $__PMA_DISPLAY_TBL_LIB__