Updated documentation.
[openemr.git] / interface / main / myadmin / libraries / display_tbl.lib.php
blob8862a9d0bfcea92ad6d1d4c2b09efdfe98b8b728
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 /**
10 * Defines the display mode to use for the results of a sql query
12 * It uses a synthetic string that contains all the required informations.
13 * In this string:
14 * - the first two characters stand for the action to do while
15 * clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
16 * edit link...);
17 * - the next two characters stand for the action to do while
18 * clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
19 * no delete link...);
20 * - the next characters are boolean values (1/0) and respectively stand
21 * for sorting links, navigation bar, "insert a new row" link, the
22 * bookmark feature, the expand/collapse text/blob fields button and
23 * the "display printable view" option.
24 * Of course '0'/'1' means the feature won't/will be enabled.
26 * @param string the synthetic value for display_mode (see ยง1 a few
27 * lines above for explanations)
28 * @param integer the total number of rows returned by the sql query
29 * without any programmatically appended "LIMIT" clause
30 * (just a copy of $unlim_num_rows if it exists, else
31 * computed inside this function)
33 * @return array an array with explicit indexes for all the display
34 * elements
36 * @global string the database name
37 * @global string the table name
38 * @global integer the total number of rows returned by the sql query
39 * without any programmatically appended "LIMIT" clause
40 * @global array the properties of the fields returned by the query
41 * @global string the url to return to in case of error in a sql
42 * statement
44 * @access private
46 * @see PMA_displayTable()
48 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
50 global $db, $table;
51 global $unlim_num_rows, $fields_meta;
52 global $err_url;
54 // 1. Initializes the $do_display array
55 $do_display = array();
56 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
57 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
58 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
59 $do_display['nav_bar'] = (string) $the_disp_mode[5];
60 $do_display['ins_row'] = (string) $the_disp_mode[6];
61 $do_display['bkm_form'] = (string) $the_disp_mode[7];
62 $do_display['text_btn'] = (string) $the_disp_mode[8];
63 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
65 // 2. Display mode is not "false for all elements" -> updates the
66 // display mode
67 if ($the_disp_mode != 'nnnn000000') {
68 // 2.0 Print view -> set all elements to FALSE!
69 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
70 $do_display['edit_lnk'] = 'nn'; // no edit link
71 $do_display['del_lnk'] = 'nn'; // no delete link
72 $do_display['sort_lnk'] = (string) '0';
73 $do_display['nav_bar'] = (string) '0';
74 $do_display['ins_row'] = (string) '0';
75 $do_display['bkm_form'] = (string) '0';
76 $do_display['text_btn'] = (string) '0';
77 $do_display['pview_lnk'] = (string) '0';
79 // 2.1 Statement is a "SELECT COUNT", a
80 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
81 // contains a "PROC ANALYSE" part
82 else if ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
83 $do_display['edit_lnk'] = 'nn'; // no edit link
84 $do_display['del_lnk'] = 'nn'; // no delete link
85 $do_display['sort_lnk'] = (string) '0';
86 $do_display['nav_bar'] = (string) '0';
87 $do_display['ins_row'] = (string) '0';
88 $do_display['bkm_form'] = (string) '1';
89 $do_display['text_btn'] = (string) '0';
90 $do_display['pview_lnk'] = (string) '1';
92 // 2.2 Statement is a "SHOW..."
93 else if ($GLOBALS['is_show']) {
94 // 2.2.1 TODO : defines edit/delete links depending on show statement
95 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
96 if (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
97 $do_display['edit_lnk'] = 'nn'; // no edit link
98 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
100 else {
101 // Default case -> no links
102 $do_display['edit_lnk'] = 'nn'; // no edit link
103 $do_display['del_lnk'] = 'nn'; // no delete link
105 // 2.2.2 Other settings
106 $do_display['sort_lnk'] = (string) '0';
107 $do_display['nav_bar'] = (string) '0';
108 $do_display['ins_row'] = (string) '0';
109 $do_display['bkm_form'] = (string) '1';
110 $do_display['text_btn'] = (string) '1';
111 $do_display['pview_lnk'] = (string) '1';
113 // 2.3 Other statements (ie "SELECT" ones) -> updates
114 // $do_display['edit_lnk'], $do_display['del_lnk'] and
115 // $do_display['text_btn'] (keeps other default values)
116 else {
117 $prev_table = $fields_meta[0]->table;
118 $do_display['text_btn'] = (string) '1';
119 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
120 $is_link = ($do_display['edit_lnk'] != 'nn'
121 || $do_display['del_lnk'] != 'nn'
122 || $do_display['sort_lnk'] != '0'
123 || $do_display['ins_row'] != '0');
124 // 2.3.2 Displays edit/delete/sort/insert links?
125 if ($is_link
126 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
127 $do_display['edit_lnk'] = 'nn'; // don't display links
128 $do_display['del_lnk'] = 'nn';
129 // TODO: May be problematic with same fields names in
130 // two joined table.
131 // $do_display['sort_lnk'] = (string) '0';
132 $do_display['ins_row'] = (string) '0';
133 if ($do_display['text_btn'] == '1') {
134 break;
136 } // end if (2.3.2)
137 // 2.3.3 Always display print view link
138 $do_display['pview_lnk'] = (string) '1';
139 $prev_table = $fields_meta[$i]->table;
140 } // end for
141 } // end if..elseif...else (2.1 -> 2.3)
142 } // end if (2)
144 // 3. Gets the total number of rows if it is unknown
145 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
146 $the_total = $unlim_num_rows;
148 else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
149 && (!empty($db) && !empty($table))) {
150 $the_total = PMA_countRecords($db, $table, TRUE);
153 // 4. If navigation bar or sorting fields names urls should be
154 // displayed but there is only one row, change these settings to
155 // false
156 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
158 if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
159 // garvin: force display of navbar for vertical/horizontal display-choice.
160 // $do_display['nav_bar'] = (string) '0';
161 $do_display['sort_lnk'] = (string) '0';
164 } // end if (3)
166 // 5. Updates the synthetic var
167 $the_disp_mode = join('', $do_display);
169 return $do_display;
170 } // end of the 'PMA_setDisplayMode()' function
174 * Displays a navigation bar to browse among the results of a sql query
176 * @param integer the offset for the "next" page
177 * @param integer the offset for the "previous" page
178 * @param string the url-encoded query
180 * @global string the current language
181 * @global string the currect charset for MySQL
182 * @global integer the server to use (refers to the number in the
183 * configuration file)
184 * @global string the database name
185 * @global string the table name
186 * @global string the url to go back in case of errors
187 * @global integer the total number of rows returned by the sql query
188 * @global integer the total number of rows returned by the sql query
189 * without any programmatically appended "LIMIT" clause
190 * @global integer the current position in results
191 * @global mixed the maximum number of rows per page ('all' = no limit)
192 * @global string the display mode (horizontal/vertical/horizontalflipped)
193 * @global integer the number of row to display between two table headers
194 * @global boolean whether to limit the number of displayed characters of
195 * text type fields or not
197 * @access private
199 * @see PMA_displayTable()
201 function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
203 global $lang, $convcharset, $server, $db, $table;
204 global $goto;
205 global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
206 global $disp_direction, $repeat_cells;
207 global $dontlimitchars;
210 <!-- Navigation bar -->
211 <table border="0">
212 <tr>
213 <?php
214 // Move to the beginning or to the previous page
215 if ($pos > 0 && $session_max_rows != 'all') {
216 // loic1: patch #474210 from Gosha Sakovich - part 1
217 if ($GLOBALS['cfg']['NavigationBarIconic']) {
218 $caption1 = '&lt;&lt;';
219 $caption2 = '&nbsp;&lt;&nbsp;';
220 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
221 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
222 } else {
223 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
224 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
225 $title1 = '';
226 $title2 = '';
227 } // end if... else...
229 <td>
230 <form action="sql.php" method="post">
231 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
232 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
233 <input type="hidden" name="pos" value="0" />
234 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
235 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
236 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
237 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
238 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
239 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
240 </form>
241 </td>
242 <td>
243 <form action="sql.php" method="post">
244 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
245 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
246 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
247 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
248 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
249 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
250 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
251 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
252 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
253 </form>
254 </td>
255 <?php
256 } // end move back
257 echo "\n";
259 <td>
260 &nbsp;&nbsp;&nbsp;
261 </td>
262 <td align="center">
263 <form action="sql.php" method="post"
264 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', 1) && checkFormElementInRange(this, 'pos', 0, <?php echo $unlim_num_rows - 1; ?>))">
265 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
266 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
267 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
268 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
269 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
270 <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()" />
271 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
272 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
273 <br />
274 <?php
275 // Display mode (horizontal/vertical and repeat headers)
276 $param1 = ' <select name="disp_direction">' . "\n"
277 . ' <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
278 . ' <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</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 . '" class="textfield" />' . "\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['cfg']['NavigationBarIconic']) {
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.php" method="post">
311 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
312 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
313 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
314 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
315 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
316 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
317 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
318 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
319 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
320 </form>
321 </td>
322 <td>
323 <form action="sql.php" method="post"
324 onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
325 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
326 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
327 <input type="hidden" name="pos" value="<?php echo $unlim_num_rows - $session_max_rows; ?>" />
328 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
329 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
330 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
331 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
332 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
333 <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> />
334 </form>
335 </td>
336 <?php
337 } // end move toward
340 //page redirection
341 $pageNow = @floor($pos / $session_max_rows) + 1;
342 $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
344 if ($nbTotalPage > 1){ //if1
346 <td>
347 &nbsp;&nbsp;&nbsp;
348 </td>
349 <td>
350 <?php //<form> for keep the form alignment of button < and << ?>
351 <form>
352 <?php echo $GLOBALS['strPageNumber']; ?>
353 <select name="goToPage" onChange="goToUrl(this, '<?php echo "sql.php?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;"; ?>')">
355 <?php
356 if ($nbTotalPage < 200) {
357 $firstPage = 1;
358 $lastPage = $nbTotalPage;
359 } else {
360 $range = 20;
361 $firstPage = ($pageNow - $range < 1 ? 1 : $pageNow - $range);
362 $lastPage = ($pageNow + $range > $nbTotalPage ? $nbTotalPage : $pageNow + $range);
364 for ($i=$firstPage; $i<=$lastPage; $i++){
365 if ($i == $pageNow) {
366 $selected = 'selected="selected"';
367 } else {
368 $selected = "";
370 echo " <option ".$selected." value=\"".(($i - 1) * $session_max_rows)."\">".$i."</option>\n";
374 </select>
375 </form>
376 </td>
377 <?php
378 } //_if1
381 // Show all the records if allowed
382 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
383 echo "\n";
385 <td>
386 &nbsp;&nbsp;&nbsp;
387 </td>
388 <td>
389 <form action="sql.php" method="post">
390 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
391 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
392 <input type="hidden" name="pos" value="0" />
393 <input type="hidden" name="session_max_rows" value="all" />
394 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
395 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
396 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
397 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
398 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
399 </form>
400 </td>
401 <?php
402 } // end show all
403 echo "\n";
405 </tr>
406 </table>
408 <?php
409 } // end of the 'PMA_displayTableNavigation()' function
413 * Displays the headers of the results table
415 * @param array which elements to display
416 * @param array the list of fields properties
417 * @param integer the total number of fields returned by the sql query
418 * @param array the analyzed query
420 * @return boolean always true
422 * @global string the current language
423 * @global string the current charset for MySQL
424 * @global integer the server to use (refers to the number in the
425 * configuration file)
426 * @global string the database name
427 * @global string the table name
428 * @global string the sql query
429 * @global string the url to go back in case of errors
430 * @global integer the total number of rows returned by the sql query
431 * @global integer the current position in results
432 * @global integer the maximum number of rows per page
433 * @global array informations used with vertical display mode
434 * @global string the display mode (horizontal/vertical/horizontalflipped)
435 * @global integer the number of row to display between two table headers
436 * @global boolean whether to limit the number of displayed characters of
437 * text type fields or not
439 * @access private
441 * @see PMA_displayTable()
443 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
445 global $lang, $convcharset, $server, $db, $table;
446 global $goto;
447 global $sql_query, $num_rows, $pos, $session_max_rows;
448 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
449 global $dontlimitchars;
451 if ($analyzed_sql == '') {
452 $analyzed_sql = array();
455 // can be result sorted?
456 if ($is_display['sort_lnk'] == '1') {
457 // Defines the url used to append/modify a sorting order
458 // Nijel: This was originally done inside loop below, but I see
459 // no reason to do this for each column.
460 if (preg_match('@(.*)([[:space:]]ORDER[[:space:]]*BY[[:space:]](.*))@si', $sql_query, $regs1)) {
461 if (preg_match('@((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)@si', $regs1[2], $regs2)) {
462 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
463 $sql_order = trim($regs2[1]);
464 preg_match('@(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)@si',$sql_order,$after_order);
465 $sort_expression = trim($after_order[2]);
467 else if (preg_match('@((.*))[[:space:]]+(LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)@si', $regs1[2], $regs3)) {
468 $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]);
469 $sql_order = trim($regs3[1]) . ' ASC';
470 preg_match('@(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)@si',$sql_order,$after_order);
471 $sort_expression = trim($after_order[2]);
472 } else {
473 $unsorted_sql_query = trim($regs1[1]);
474 $sql_order = trim($regs1[2]) . ' ASC';
475 preg_match('@(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)@si',$sql_order,$after_order);
476 $sort_expression = trim($after_order[2]);
478 } else {
479 $unsorted_sql_query = $sql_query;
482 // sorting by indexes, only if it makes sense
483 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
484 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
485 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
487 // grab indexes data:
488 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
489 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
490 $idx_cnt = mysql_num_rows($result);
492 $prev_index = '';
493 for ($i = 0; $i < $idx_cnt; $i++) {
494 $row = (defined('PMA_IDX_INCLUDED') ? $ret_keys[$i] : PMA_mysql_fetch_array($result));
496 if ($row['Key_name'] != $prev_index ){
497 $indexes[] = $row['Key_name'];
498 $prev_index = $row['Key_name'];
500 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
501 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
502 if (isset($row['Cardinality'])) {
503 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
505 // I don't know what does following column mean....
506 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
507 $indexes_info[$row['Key_name']]['Comment'] = (isset($row['Comment']))
508 ? $row['Comment']
509 : '';
510 $indexes_info[$row['Key_name']]['Index_type'] = (isset($row['Index_type']))
511 ? $row['Index_type']
512 : '';
514 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
515 if (isset($row['Sub_part'])) {
516 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
518 } // end while
520 // do we have any index?
521 if (isset($indexes_data)) {
523 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
524 $span = $fields_cnt;
525 } else {
526 $span = $num_rows + floor($num_rows/$repeat_cells) + 1;
528 if ($is_display['edit_lnk'] != 'nn') $span++;
529 if ($is_display['del_lnk'] != 'nn') $span++;
532 <tr>
533 <td colspan="<?php echo $span; ?>" align="center">
534 <?php
535 echo '<form action="sql.php" method="POST">' . "\n";
536 echo PMA_generate_common_hidden_inputs($db, $table, 5);
537 echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
538 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
539 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
540 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
541 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
542 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">&nbsp;';
543 $used_index = false;
544 $local_order = (isset($sql_order) ? str_replace(' ', ' ', $sql_order) : '');
545 foreach($indexes_data AS $key => $val) {
546 $asc_sort = 'ORDER BY ';
547 $desc_sort = 'ORDER BY ';
548 foreach($val AS $key2 => $val2) {
549 $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
550 $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
552 $asc_sort = substr($asc_sort, 0, -3);
553 $desc_sort = substr($desc_sort, 0, -3);
554 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
555 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
556 echo "\n";
557 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
558 echo "\n";
560 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"' ) . '>' . $GLOBALS['strNone'] . '</option>';
561 echo "\n";
562 echo '</select>&nbsp;';
563 echo "\n";
564 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
565 echo "\n";
566 echo '</form>';
567 echo "\n";
569 </td>
570 </tr>
571 <?php
577 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
579 <!-- Results table headers -->
580 <tr>
581 <?php
582 echo "\n";
585 $vertical_display['emptypre'] = 0;
586 $vertical_display['emptyafter'] = 0;
587 $vertical_display['textbtn'] = '';
590 // Start of form for multi-rows delete
592 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp' ) {
593 echo '<form method="post" action="tbl_row_delete.php" name="rowsDeleteForm">' . "\n";
594 echo PMA_generate_common_hidden_inputs($db, $table, 1);
595 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
596 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
597 echo '<input type="hidden" name="goto" value="' . $goto . '" />' . "\n";
598 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
601 // 1. Displays the full/partial text button (part 1)...
602 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
603 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
604 ? ' colspan="3"'
605 : '';
606 } else {
607 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
608 ? ' rowspan="3"'
609 : '';
611 $text_url = 'sql.php?'
612 . PMA_generate_common_url($db, $table)
613 . '&amp;sql_query=' . urlencode($sql_query)
614 . '&amp;pos=' . $pos
615 . '&amp;session_max_rows=' . $session_max_rows
616 . '&amp;pos=' . $pos
617 . '&amp;disp_direction=' . $disp_direction
618 . '&amp;repeat_cells=' . $repeat_cells
619 . '&amp;goto=' . $goto
620 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
622 // ... before the result table
623 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
624 && $is_display['text_btn'] == '1') {
625 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
626 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
628 <td colspan="<?php echo $fields_cnt; ?>" align="center">
629 <a href="<?php echo $text_url; ?>">
630 <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>
631 </td>
632 </tr>
634 <tr>
635 <?php
636 } // end horizontal/horizontalflipped mode
637 else {
638 echo "\n";
640 <tr>
641 <td colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
642 <a href="<?php echo $text_url; ?>">
643 <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>
644 </td>
645 </tr>
646 <?php
647 } // end vertical mode
650 // ... at the left column of the result table header if possible
651 // and required
652 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
653 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
654 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
655 echo "\n";
657 <td<?php echo $colspan; ?> align="center">
658 <a href="<?php echo $text_url; ?>">
659 <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>
660 </td>
661 <?php
662 } // end horizontal/horizontalflipped mode
663 else {
664 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
665 . ' <a href="' . $text_url . '">' . "\n"
666 . ' <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"
667 . ' </td>' . "\n";
668 } // end vertical mode
671 // ... else if no button, displays empty(ies) col(s) if required
672 else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
673 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
674 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
675 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
676 echo "\n";
678 <td<?php echo $colspan; ?>></td>
679 <?php
680 echo "\n";
681 } // end horizontal/horizontalfipped mode
682 else {
683 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
684 } // end vertical mode
687 // 2. Displays the fields' name
688 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
689 // statement (see 2.1.3)
691 // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
692 // Do not show comments, if using horizontalflipped mode, because of space usage
693 if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
694 $comments_map = PMA_getComments($db, $table);
695 } else {
696 $comments_map = array();
699 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
700 require_once('./libraries/transformations.lib.php');
701 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
704 if ($is_display['sort_lnk'] == '1') {
705 $is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@i', $sql_query, $select_stt);
706 } else {
707 $is_join = FALSE;
710 // garvin: See if we have to highlight any header fields of a WHERE query.
711 // Uses SQL-Parser results.
712 $highlight_columns = array();
713 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
714 isset($analyzed_sql[0]['where_clause_identifiers'])) {
716 $wi = 0;
717 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
718 foreach($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
719 $highlight_columns[$wci] = 'true';
724 for ($i = 0; $i < $fields_cnt; $i++) {
725 // garvin: See if this column should get highlight because it's used in the
726 // where-query.
727 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
728 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
729 } else {
730 $column_style = '';
733 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
734 if (isset($comments_map[$fields_meta[$i]->name])) {
735 $comments_table_wrap_pre = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><th>';
736 $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>';
737 } else {
738 $comments_table_wrap_pre = '';
739 $comments_table_wrap_post = '';
742 // 2.1 Results can be sorted
743 if ($is_display['sort_lnk'] == '1') {
745 // 2.1.1 Checks if the table name is required; it's the case
746 // for a query with a "JOIN" statement and if the column
747 // isn't aliased, or in queries like
748 // SELECT `1`.`master_field` , `2`.`master_field`
749 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
751 if (($is_join
752 && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name . '~i', $select_stt[1], $parts))
753 || ( isset($analyzed_sql[0]['select_expr'][$i]['expr'])
754 && isset($analyzed_sql[0]['select_expr'][$i]['column'])
755 && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
756 $analyzed_sql[0]['select_expr'][$i]['column']) ) {
757 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
758 } else {
759 $sort_tbl = '';
761 // 2.1.2 Checks if the current column is used to sort the
762 // results
763 if (empty($sql_order)) {
764 $is_in_sort = FALSE;
765 } else {
766 // field name may be preceded by a space, or any number
767 // of characters followed by a dot (tablename.fieldname)
768 // so do a direct comparison
769 // for the sort expression (avoids problems with queries
770 // like "SELECT id, count(id)..." and clicking to sort
771 // on id or on count(id) )
772 $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression ? TRUE : FALSE);
774 // 2.1.3 Check the field name for backquotes.
775 // If it contains some, it's probably a function column
776 // like 'COUNT(`field`)'
777 if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
778 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
779 } else {
780 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
782 // 2.1.4 Do define the sorting url
783 if (!$is_in_sort) {
784 // loic1: patch #455484 ("Smart" order)
785 $cfg['Order'] = strtoupper($GLOBALS['cfg']['Order']);
786 if ($cfg['Order'] == 'SMART') {
787 $cfg['Order'] = (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
789 $sort_order .= $cfg['Order'];
790 $order_img = '';
792 else if (preg_match('@[[:space:]]ASC$@i', $sql_order)) {
793 $sort_order .= ' DESC';
794 $order_img = '&nbsp;<img src="./images/asc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" />';
796 else if (preg_match('@[[:space:]]DESC$@i', $sql_order)) {
797 $sort_order .= ' ASC';
798 $order_img = '&nbsp;<img src="./images/desc_order.png" border="0" width="7" height="7" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" />';
800 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
801 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
802 } else {
803 $sorted_sql_query = $unsorted_sql_query . $sort_order;
805 $url_query = PMA_generate_common_url($db, $table)
806 . '&amp;pos=' . $pos
807 . '&amp;session_max_rows=' . $session_max_rows
808 . '&amp;disp_direction=' . $disp_direction
809 . '&amp;repeat_cells=' . $repeat_cells
810 . '&amp;dontlimitchars=' . $dontlimitchars
811 . '&amp;sql_query=' . urlencode($sorted_sql_query);
813 // 2.1.5 Displays the sorting url
814 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
815 echo "\n";
817 <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
818 <?php echo $comments_table_wrap_pre; ?>
819 <a href="sql.php?<?php echo $url_query; ?>" <?php echo (($disp_direction == 'horizontalflipped' AND $GLOBALS['cfg']['HeaderFlipType'] == 'css') ? 'style="direction: ltr; writing-mode: tb-rl;"' : '') . ' title="' . $GLOBALS['strSort'] . '"'; ?>>
820 <?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"; ?>
821 <?php echo $comments_table_wrap_post; ?>
822 </th>
823 <?php
825 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
826 . $comments_table_wrap_pre
827 . ' <a href="sql.php?' . $url_query . '">' . "\n"
828 . ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
829 . $comments_table_wrap_post
830 . ' </th>' . "\n";
831 } // end if (2.1)
833 // 2.2 Results can't be sorted
834 else {
835 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
836 echo "\n";
838 <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;"' : ''); ?>>
839 <?php echo $comments_table_wrap_pre; ?>
840 <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
841 <?php echo $comments_table_wrap_post; ?>
842 </th>
843 <?php
845 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
846 . $comments_table_wrap_pre
847 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
848 . $comments_table_wrap_post
849 . ' </th>';
850 } // end else (2.2)
851 } // end for
853 // 3. Displays the full/partial text button (part 2) at the right
854 // column of the result table header if possible and required...
855 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
856 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
857 && $is_display['text_btn'] == '1') {
858 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
859 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
860 echo "\n";
862 <td<?php echo $colspan; ?> align="center">
863 <a href="<?php echo $text_url; ?>">
864 <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>
865 </td>
866 <?php
867 } // end horizontal/horizontalflipped mode
868 else {
869 $vertical_display['textbtn'] = ' <td' . $rowspan . ' align="center" valign="middle">' . "\n"
870 . ' <a href="' . $text_url . '">' . "\n"
871 . ' <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"
872 . ' </td>' . "\n";
873 } // end vertical mode
876 // ... else if no button, displays empty cols if required
877 // (unless coming from Browse mode print view)
878 else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
879 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
880 && (!$GLOBALS['is_header_sent'])) {
881 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
882 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
883 echo "\n";
885 <td<?php echo $colspan; ?>></td>
886 <?php
887 } // end horizontal/horizontalflipped mode
888 else {
889 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
890 } // end vertical mode
893 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
894 echo "\n";
896 </tr>
897 <?php
899 echo "\n";
901 return TRUE;
902 } // end of the 'PMA_displayTableHeaders()' function
907 * Displays the body of the results table
909 * @param integer the link id associated to the query which results have
910 * to be displayed
911 * @param array which elements to display
912 * @param array the list of relations
913 * @param array the analyzed query
915 * @return boolean always true
917 * @global string the current language
918 * @global string the current charset for MySQL
919 * @global integer the server to use (refers to the number in the
920 * configuration file)
921 * @global string the database name
922 * @global string the table name
923 * @global string the sql query
924 * @global string the url to go back in case of errors
925 * @global integer the current position in results
926 * @global integer the maximum number of rows per page
927 * @global array the list of fields properties
928 * @global integer the total number of fields returned by the sql query
929 * @global array informations used with vertical display mode
930 * @global string the display mode (horizontal/vertical/horizontalflipped)
931 * @global integer the number of row to display between two table headers
932 * @global boolean whether to limit the number of displayed characters of
933 * text type fields or not
935 * @access private
937 * @see PMA_displayTable()
939 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
941 global $lang, $convcharset, $server, $db, $table;
942 global $goto;
943 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
944 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
945 global $dontlimitchars;
947 if (!is_array($map)) {
948 $map = array();
951 <!-- Results table body -->
952 <?php
953 echo "\n";
955 $row_no = 0;
956 $vertical_display['edit'] = array();
957 $vertical_display['delete'] = array();
958 $vertical_display['data'] = array();
959 $vertical_display['row_delete'] = array();
961 // Correction uva 19991216 in the while below
962 // Previous code assumed that all tables have keys, specifically that
963 // the phpMyAdmin GUI should support row delete/edit only for such
964 // tables.
965 // Although always using keys is arguably the prescribed way of
966 // defining a relational table, it is not required. This will in
967 // particular be violated by the novice.
968 // We want to encourage phpMyAdmin usage by such novices. So the code
969 // below has been changed to conditionally work as before when the
970 // table being displayed has one or more keys; but to display
971 // delete/edit options correctly for tables without keys.
973 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
974 // to get the NULL values
976 while ($row = PMA_mysql_fetch_array($dt_result)) {
978 // lem9: "vertical display" mode stuff
979 if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
980 echo '<tr>' . "\n";
982 for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
983 echo ' <td>&nbsp;</td>' . "\n";
986 foreach($vertical_display['desc'] AS $key => $val) {
987 echo $val;
990 for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
991 echo ' <td>&nbsp;</td>' . "\n";
994 echo '</tr>' . "\n";
995 } // end if
997 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
998 $bgcolor = '#ffffff';
999 } else {
1000 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1003 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1004 // loic1: pointer code part
1005 $on_mouse = '';
1006 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
1007 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
1008 $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1009 . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1011 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
1012 $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1014 } // end if
1016 <tr<?php echo $on_mouse; ?>>
1017 <?php
1018 echo "\n";
1021 // 1. Prepares the row (gets primary keys to use)
1022 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1023 $primary_key = '';
1024 $unique_key = '';
1025 $uva_nonprimary_condition = '';
1027 // 1.1 Results from a "SELECT" statement -> builds the
1028 // "primary" key to use in links
1029 if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
1030 for ($i = 0; $i < $fields_cnt; ++$i) {
1031 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1032 $meta = $fields_meta[$i];
1034 // do not use an alias in a condition
1035 $column_for_condition = $meta->name;
1036 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1037 foreach($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1038 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1039 if (!empty($alias)) {
1040 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1041 if ($alias == $meta->name) {
1042 $column_for_condition = $true_column;
1043 } // end if
1044 } // end if
1045 } // end while
1048 // to fix the bug where float fields (primary or not)
1049 // can't be matched because of the imprecision of
1050 // floating comparison, use CONCAT
1051 // (also, the syntax "CONCAT(field) IS NULL"
1052 // that we need on the next "if" will work)
1053 if ($meta->type == 'real') {
1054 $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
1055 } else {
1056 $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
1057 } // end if... else...
1059 // loic1: To fix bug #474943 under php4, the row
1060 // pointer will depend on whether the "is_null"
1061 // php4 function is available or not
1062 $pointer = (function_exists('is_null') ? $i : $meta->name);
1063 if (!isset($row[$meta->name])
1064 || (function_exists('is_null') && is_null($row[$pointer]))) {
1065 $condition .= 'IS NULL AND';
1066 } else {
1067 if ($meta->type == 'blob'
1068 // hexify only if this is a true not empty BLOB
1069 && stristr($field_flags, 'BINARY')
1070 && !empty($row[$pointer])) {
1071 $condition .= 'LIKE 0x' . bin2hex($row[$pointer]). ' AND';
1072 } else {
1073 $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND';
1076 if ($meta->primary_key > 0) {
1077 $primary_key .= $condition;
1078 } else if ($meta->unique_key > 0) {
1079 $unique_key .= $condition;
1081 $uva_nonprimary_condition .= $condition;
1082 } // end for
1084 // Correction uva 19991216: prefer primary or unique keys
1085 // for condition, but use conjunction of all values if no
1086 // primary key
1087 if ($primary_key) {
1088 $uva_condition = $primary_key;
1089 } else if ($unique_key) {
1090 $uva_condition = $unique_key;
1091 } else {
1092 $uva_condition = $uva_nonprimary_condition;
1095 $uva_condition = urlencode(preg_replace('|\s?AND$|', '', $uva_condition));
1096 } // end if (1.1)
1098 // 1.2 Defines the urls for the modify/delete link(s)
1099 $url_query = PMA_generate_common_url($db, $table)
1100 . '&amp;pos=' . $pos
1101 . '&amp;session_max_rows=' . $session_max_rows
1102 . '&amp;disp_direction=' . $disp_direction
1103 . '&amp;repeat_cells=' . $repeat_cells
1104 . '&amp;dontlimitchars=' . $dontlimitchars;
1106 // We need to copy the value or else the == 'both' check will always return true
1107 $propicon = (string)$GLOBALS['cfg']['PropertiesIconic'];
1109 if ($propicon == 'both') {
1110 $iconic_spacer = '<nobr>';
1111 } else {
1112 $iconic_spacer = '';
1115 // 1.2.1 Modify link(s)
1116 if ($is_display['edit_lnk'] == 'ur') { // update row case
1117 // $lnk_goto = 'sql.php'
1118 // . '?' . str_replace('&amp;', '&', $url_query)
1119 // . '&sql_query=' . urlencode($sql_query)
1120 // . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
1121 // to reduce the length of the URL, because of some browsers limitations:
1122 $lnk_goto = 'sql.php';
1124 $edit_url = 'tbl_change.php'
1125 . '?' . $url_query
1126 . '&amp;primary_key=' . $uva_condition
1127 . '&amp;sql_query=' . urlencode($sql_query)
1128 . '&amp;goto=' . urlencode($lnk_goto);
1129 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
1130 $edit_str = $GLOBALS['strEdit'];
1131 } else {
1132 $edit_str = $iconic_spacer . '<img width="12" height="13" src="images/button_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" border="0" />';
1133 if ($propicon == 'both') {
1134 $edit_str .= '&nbsp;' . $GLOBALS['strEdit'] . '</nobr>';
1137 } // end if (1.2.1)
1139 if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) {
1140 $bookmark_go = '<a href="read_dump.php?'
1141 . PMA_generate_common_url($row['dbase'], '')
1142 . '&amp;id_bookmark=' . $row['id']
1143 . '&amp;action_bookmark=0'
1144 . '&amp;SQL=' . $GLOBALS['strExecuteBookmarked']
1145 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1147 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
1148 $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
1149 } else {
1150 $bookmark_go .= $iconic_spacer . '<img width="12" height="13" src="images/button_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" border="0" />';
1151 if ($propicon == 'both') {
1152 $bookmark_go .= '&nbsp;' . $GLOBALS['strExecuteBookmarked'] . '</nobr>';
1156 $bookmark_go .= '</a>';
1157 } else {
1158 $bookmark_go = '';
1161 // 1.2.2 Delete/Kill link(s)
1162 if ($is_display['del_lnk'] == 'dr') { // delete row case
1163 $lnk_goto = 'sql.php'
1164 . '?' . str_replace('&amp;', '&', $url_query)
1165 . '&sql_query=' . urlencode($sql_query)
1166 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1167 . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
1168 $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1';
1169 $del_url = 'sql.php'
1170 . '?' . $url_query
1171 . '&amp;sql_query=' . $del_query
1172 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1173 . '&amp;goto=' . urlencode($lnk_goto);
1174 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
1175 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
1176 . ' LIMIT 1';
1177 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
1178 $del_str = $GLOBALS['strDelete'];
1179 } else {
1180 $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" border="0" />';
1181 if ($propicon == 'both') {
1182 $del_str .= '&nbsp;' . $GLOBALS['strDelete'] . '</nobr>';
1185 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
1186 $lnk_goto = 'sql.php'
1187 . '?' . str_replace('&amp;', '&', $url_query)
1188 . '&sql_query=' . urlencode($sql_query)
1189 . '&goto=main.php';
1190 $del_url = 'sql.php?'
1191 . PMA_generate_common_url('mysql')
1192 . '&amp;sql_query=' . urlencode('KILL ' . $row['Id'])
1193 . '&amp;goto=' . urlencode($lnk_goto);
1194 $del_query = urlencode('KILL ' . $row['Id']);
1195 $js_conf = 'KILL ' . $row['Id'];
1196 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
1197 $del_str = $GLOBALS['strKill'];
1198 } else {
1199 $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" border="0" />';
1200 if ($propicon == 'both') {
1201 $del_str .= '&nbsp;' . $GLOBALS['strKill'] . '</nobr>';
1204 } // end if (1.2.2)
1206 // 1.3 Displays the links at left if required
1207 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1208 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1209 require('./libraries/display_tbl_links.lib.php');
1210 } // end if (1.3)
1211 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1212 } // end if (1)
1214 // 2. Displays the rows' values
1215 for ($i = 0; $i < $fields_cnt; ++$i) {
1216 $meta = $fields_meta[$i];
1217 // loic1: To fix bug #474943 under php4, the row pointer will
1218 // depend on whether the "is_null" php4 function is
1219 // available or not
1220 $pointer = (function_exists('is_null') ? $i : $meta->name);
1222 // garvin: See if this column should get highlight because it's used in the
1223 // where-query.
1224 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1225 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
1226 } else {
1227 $column_style = '';
1230 // garvin: Wrap MIME-transformations. [MIME]
1231 $default_function = 'default_function'; // default_function
1232 $transform_function = $default_function;
1233 $transform_options = array();
1235 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1237 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1238 $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
1240 if (file_exists('./libraries/transformations/' . $include_file)) {
1241 $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1243 require_once('./libraries/transformations/' . $include_file);
1245 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1246 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1247 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1248 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1250 } // end if file_exists
1251 } // end if transformation is set
1252 } // end if mime/transformation works.
1254 $transform_options['wrapper_link'] = '?'
1255 . (isset($url_query) ? $url_query : '')
1256 . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '')
1257 . '&amp;sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '')
1258 . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1259 . '&amp;transform_key=' . urlencode($meta->name);
1262 // n u m e r i c
1263 if ($meta->numeric == 1) {
1266 // lem9: if two fields have the same name (this is possible
1267 // with self-join queries, for example), using $meta->name
1268 // will show both fields NULL even if only one is NULL,
1269 // so use the $pointer
1270 // (works only if function_exists('is_null')
1271 // PS: why not always work with the number ($i), since
1272 // the default second parameter of
1273 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1274 // associative and numeric indices?
1276 //if (!isset($row[$meta->name])
1277 if (!isset($row[$pointer])
1278 || (function_exists('is_null') && is_null($row[$pointer]))) {
1279 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1280 } else if ($row[$pointer] != '') {
1281 $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" nowrap="nowrap">';
1283 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1284 foreach($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1285 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1286 if (!empty($alias)) {
1287 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1288 if ($alias == $meta->name) {
1289 $meta->name = $true_column;
1290 } // end if
1291 } // end if
1292 } // end while
1295 if (isset($map[$meta->name])) {
1296 // Field to display from the foreign table?
1297 if (!empty($map[$meta->name][2])) {
1298 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1299 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1300 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1301 . ' = ' . $row[$pointer];
1302 $dispresult = PMA_mysql_query($dispsql);
1303 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1304 $dispval = PMA_mysql_result($dispresult, 0);
1306 else {
1307 $dispval = $GLOBALS['strLinkNotFound'];
1310 else {
1311 $dispval = '';
1312 } // end if... else...
1314 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1315 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
1316 } else {
1317 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1319 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1320 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1321 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1322 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>'
1323 . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . '</a>';
1325 } else {
1326 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta));
1328 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1329 } else {
1330 $vertical_display['data'][$row_no][$i] = ' <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" nowrap="nowrap">&nbsp;</td>' . "\n";
1333 // b l o b
1335 } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) {
1336 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1337 // TEXT fields type, however TEXT fields must be displayed
1338 // even if $cfg['ShowBlob'] is false -> get the true type
1339 // of the fields.
1340 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1341 if (stristr($field_flags, 'BINARY')) {
1342 $blobtext = '[BLOB';
1343 if (isset($row[$pointer])) {
1344 $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
1345 $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
1346 unset($blob_size);
1349 $blobtext .= ']';
1350 $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
1352 $vertical_display['data'][$row_no][$i] = ' <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
1353 } else {
1354 //if (!isset($row[$meta->name])
1355 if (!isset($row[$pointer])
1356 || (function_exists('is_null') && is_null($row[$pointer]))) {
1357 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1358 } else if ($row[$pointer] != '') {
1359 // garvin: if a transform function for blob is set, none of these replacements will be made
1360 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1361 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1363 // loic1: displays all space characters, 4 space
1364 // characters for tabulations and <cr>/<lf>
1365 $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta));
1367 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
1368 } else {
1369 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1372 } else {
1373 //if (!isset($row[$meta->name])
1374 if (!isset($row[$pointer])
1375 || (function_exists('is_null') && is_null($row[$pointer]))) {
1376 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
1377 } else if ($row[$pointer] != '') {
1378 // loic1: support blanks in the key
1379 $relation_id = $row[$pointer];
1381 // nijel: Cut all fields to $cfg['LimitChars']
1382 if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1383 $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1386 // loic1: displays special characters from binaries
1387 $field_flags = PMA_mysql_field_flags($dt_result, $i);
1388 if (stristr($field_flags, 'BINARY')) {
1389 $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]);
1390 $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]);
1391 $row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]);
1392 $row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]);
1393 $row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]);
1394 $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta));
1396 // loic1: displays all space characters, 4 space
1397 // characters for tabulations and <cr>/<lf>
1398 else {
1399 $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta));
1402 // garvin: transform functions may enable nowrapping:
1403 $function_nowrap = $transform_function . '_nowrap';
1404 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1406 // loic1: do not wrap if date field type
1407 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap="nowrap"' : '');
1408 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
1410 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1411 foreach($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1412 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1413 if (!empty($alias)) {
1414 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1415 if ($alias == $meta->name) {
1416 $meta->name = $true_column;
1417 } // end if
1418 } // end if
1419 } // end while
1422 if (isset($map[$meta->name])) {
1423 // Field to display from the foreign table?
1424 if (!empty($map[$meta->name][2])) {
1425 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1426 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1427 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1428 . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
1429 $dispresult = @PMA_mysql_query($dispsql);
1430 if ($dispresult && mysql_num_rows($dispresult) > 0) {
1431 $dispval = PMA_mysql_result($dispresult, 0);
1433 else {
1434 $dispval = $GLOBALS['strLinkNotFound'];
1437 else {
1438 $dispval = '';
1440 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1442 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1443 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1444 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1445 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1446 . $row[$pointer] . '</a>';
1447 } else {
1448 $vertical_display['data'][$row_no][$i] .= $row[$pointer];
1450 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1451 } else {
1452 $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
1456 // lem9: output stored cell
1457 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1458 echo $vertical_display['data'][$row_no][$i];
1461 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1462 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1463 } else {
1464 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1466 } // end for (2)
1468 // 3. Displays the modify/delete links on the right if required
1469 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1470 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1471 require('./libraries/display_tbl_links.lib.php');
1472 } // end if (3)
1474 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1475 echo "\n";
1477 </tr>
1478 <?php
1479 } // end if
1481 // 4. Gather links of del_urls and edit_urls in an array for later
1482 // output
1483 if (!isset($vertical_display['edit'][$row_no])) {
1484 $vertical_display['edit'][$row_no] = '';
1485 $vertical_display['delete'][$row_no] = '';
1486 $vertical_display['row_delete'][$row_no] = '';
1490 if (!empty($del_url)) {
1491 $vertical_display['row_delete'][$row_no] .= ' <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1492 . ' <input type="checkbox" name="rows_to_delete[' . $uva_condition . ']" value="' . $del_query . '" />' . "\n"
1493 . ' </td>' . "\n";
1494 } else {
1495 unset($vertical_display['row_delete'][$row_no]);
1498 if (isset($edit_url)) {
1499 $vertical_display['edit'][$row_no] .= ' <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1500 . PMA_linkOrButton($edit_url, $edit_str, '')
1501 . $bookmark_go
1502 . ' </td>' . "\n";
1503 } else {
1504 unset($vertical_display['edit'][$row_no]);
1507 if (isset($del_url)) {
1508 $vertical_display['delete'][$row_no] .= ' <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n"
1509 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''))
1510 . ' </td>' . "\n";
1511 } else {
1512 unset($vertical_display['delete'][$row_no]);
1515 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1516 $row_no++;
1517 } // end while
1519 if (isset($url_query)) {
1520 $GLOBALS['url_query'] = $url_query;
1523 return TRUE;
1524 } // end of the 'PMA_displayTableBody()' function
1528 * Do display the result table with the vertical direction mode.
1529 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1531 * @return boolean always true
1533 * @global array the information to display
1534 * @global integer the number of row to display between two table headers
1536 * @access private
1538 * @see PMA_displayTable()
1540 function PMA_displayVerticalTable()
1542 global $vertical_display, $repeat_cells;
1544 // Displays "multi row delete" link at top if required
1545 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1546 echo '<tr>' . "\n";
1547 echo $vertical_display['textbtn'];
1548 $foo_counter = 0;
1549 foreach($vertical_display['row_delete'] AS $key => $val) {
1550 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1551 echo '<td>&nbsp;</td>' . "\n";
1554 echo $val;
1555 $foo_counter++;
1556 } // end while
1557 echo '</tr>' . "\n";
1558 } // end if
1560 // Displays "edit" link at top if required
1561 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1562 echo '<tr>' . "\n";
1563 if (!is_array($vertical_display['row_delete'])) {
1564 echo $vertical_display['textbtn'];
1566 $foo_counter = 0;
1567 foreach($vertical_display['edit'] AS $key => $val) {
1568 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1569 echo ' <td>&nbsp;</td>' . "\n";
1572 echo $val;
1573 $foo_counter++;
1574 } // end while
1575 echo '</tr>' . "\n";
1576 } // end if
1578 // Displays "delete" link at top if required
1579 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1580 echo '<tr>' . "\n";
1581 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1582 echo $vertical_display['textbtn'];
1584 $foo_counter = 0;
1585 foreach($vertical_display['delete'] AS $key => $val) {
1586 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1587 echo '<td>&nbsp;</td>' . "\n";
1590 echo $val;
1591 $foo_counter++;
1592 } // end while
1593 echo '</tr>' . "\n";
1594 } // end if
1596 // Displays data
1597 $row_no = 0;
1598 foreach($vertical_display['desc'] AS $key => $val) {
1599 $row_no++;
1601 if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
1602 $bgcolor = '#ffffff';
1603 } else {
1604 $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1607 $on_mouse = '';
1608 if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
1609 if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
1610 $on_mouse = ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1611 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1613 if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
1614 $on_mouse .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1616 } // end if
1618 echo '<tr ' . $on_mouse . '>' . "\n";
1619 echo $val;
1621 $foo_counter = 0;
1622 foreach($vertical_display['rowdata'][$key] AS $subkey => $subval) {
1623 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1624 echo $val;
1627 echo $subval;
1628 $foo_counter++;
1629 } // end while
1631 echo '</tr>' . "\n";
1632 } // end while
1634 // Displays "multi row delete" link at bottom if required
1635 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1636 echo '<tr>' . "\n";
1637 echo $vertical_display['textbtn'];
1638 $foo_counter = 0;
1639 foreach($vertical_display['row_delete'] AS $key => $val) {
1640 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1641 echo '<td>&nbsp;</td>' . "\n";
1644 echo $val;
1645 $foo_counter++;
1646 } // end while
1647 echo '</tr>' . "\n";
1648 } // end if
1650 // Displays "edit" link at bottom if required
1651 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1652 echo '<tr>' . "\n";
1653 if (!is_array($vertical_display['row_delete'])) {
1654 echo $vertical_display['textbtn'];
1656 $foo_counter = 0;
1657 foreach($vertical_display['edit'] AS $key => $val) {
1658 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1659 echo '<td>&nbsp;</td>' . "\n";
1662 echo $val;
1663 $foo_counter++;
1664 } // end while
1665 echo '</tr>' . "\n";
1666 } // end if
1668 // Displays "delete" link at bottom if required
1669 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1670 echo '<tr>' . "\n";
1671 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1672 echo $vertical_display['textbtn'];
1674 $foo_counter = 0;
1675 foreach($vertical_display['delete'] AS $key => $val) {
1676 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1677 echo '<td>&nbsp;</td>' . "\n";
1680 echo $val;
1681 $foo_counter++;
1682 } // end while
1683 echo '</tr>' . "\n";
1686 return TRUE;
1687 } // end of the 'PMA_displayVerticalTable' function
1691 * Displays a table of results returned by a sql query.
1692 * This function is called by the "sql.php" script.
1694 * @param integer the link id associated to the query which results have
1695 * to be displayed
1696 * @param array the display mode
1697 * @param array the analyzed query
1699 * @global string the current language
1700 * @global integer the server to use (refers to the number in the
1701 * configuration file)
1702 * @global array the current server config
1703 * @global string the database name
1704 * @global string the table name
1705 * @global string the url to go back in case of errors
1706 * @global string the current sql query
1707 * @global integer the total number of rows returned by the sql query
1708 * @global integer the total number of rows returned by the sql query
1709 * without any programmatically appended "LIMIT" clause
1710 * @global integer the current postion of the first record to be
1711 * displayed
1712 * @global array the list of fields properties
1713 * @global integer the total number of fields returned by the sql query
1714 * @global array informations used with vertical display mode
1715 * @global string the display mode (horizontal/vertical/horizontalflipped)
1716 * @global integer the number of row to display between two table headers
1717 * @global boolean whether to limit the number of displayed characters of
1718 * text type fields or not
1719 * @global array the relation settings
1721 * @access private
1723 * @see PMA_showMessage(), PMA_setDisplayMode(),
1724 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1725 * PMA_displayTableBody()
1727 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1729 global $lang, $server, $cfg, $db, $table;
1730 global $goto;
1731 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1732 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
1733 global $dontlimitchars;
1734 global $cfgRelation;
1736 // 1. ----- Prepares the work -----
1738 // 1.1 Gets the informations about which functionnalities should be
1739 // displayed
1740 $total = '';
1741 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1742 if ($total == '') {
1743 unset($total);
1746 // 1.2 Defines offsets for the next and previous pages
1747 if ($is_display['nav_bar'] == '1') {
1748 if (!isset($pos)) {
1749 $pos = 0;
1751 if ($GLOBALS['session_max_rows'] == 'all') {
1752 $pos_next = 0;
1753 $pos_prev = 0;
1754 } else {
1755 $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
1756 $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
1757 if ($pos_prev < 0) {
1758 $pos_prev = 0;
1761 } // end if
1763 // 1.3 Urlencodes the query to use in input form fields
1764 $encoded_sql_query = urlencode($sql_query);
1766 // 2. ----- Displays the top of the page -----
1768 // 2.1 Displays a messages with position informations
1769 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1770 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1771 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1772 } else {
1773 $selectstring = '';
1775 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1776 ? $total - 1
1777 : $pos_next - 1;
1778 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1779 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1780 PMA_showMessage($GLOBALS['strSQLQuery']);
1783 // 2.3 Displays the navigation bars
1784 if (!isset($table) || strlen(trim($table)) == 0) {
1785 $table = $fields_meta[0]->table;
1787 if ($is_display['nav_bar'] == '1') {
1788 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1789 echo "\n";
1790 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1791 echo "\n" . '<br /><br />' . "\n";
1794 // 2b ----- Get field references from Database -----
1795 // (see the 'relation' config variable)
1796 // loic1, 2002-03-02: extended to php3
1798 // init map
1799 $map = array();
1801 // find tables
1803 $target=array();
1804 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1805 foreach($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1806 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1809 $tabs = '(\'' . join('\',\'', $target) . '\')';
1811 if ($cfgRelation['displaywork']) {
1812 if (empty($table)) {
1813 $exist_rel = FALSE;
1814 } else {
1815 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1816 if ($exist_rel) {
1817 foreach($exist_rel AS $master_field => $rel) {
1818 $display_field = PMA_getDisplayField($rel['foreign_db'],$rel['foreign_table']);
1819 $map[$master_field] = array($rel['foreign_table'],
1820 $rel['foreign_field'],
1821 $display_field,
1822 $rel['foreign_db']);
1823 } // end while
1824 } // end if
1825 } // end if
1826 } // end if
1827 // end 2b
1829 // 3. ----- Displays the results table -----
1830 echo '<!-- Results table -->' . "\n"
1831 . '<table ';
1832 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1833 echo 'border="1" cellpadding="2" cellspacing="0"';
1834 } else {
1835 echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="5"';
1837 echo '>' . "\n";
1838 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1839 $url_query='';
1840 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1841 // vertical output case
1842 if ($disp_direction == 'vertical') {
1843 PMA_displayVerticalTable();
1844 } // end if
1845 unset($vertical_display);
1847 </table>
1848 <?php
1850 echo "\n";
1852 // 4. ----- Displays the link for multi-fields delete
1854 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
1856 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
1857 $propicon = (string)$GLOBALS['cfg']['PropertiesIconic'];
1859 // echo '&nbsp;&nbsp;&nbsp;<img src="./images/arrow_' . $GLOBALS['text_dir'] . '.gif" border="0" width="38" height="22" alt="' . $GLOBALS['strWithChecked'] . '" />';
1860 echo '&nbsp;&nbsp;<i>' . $GLOBALS['strWithChecked'] . '</i>'. "\n";
1862 if ($cfg['PropertiesIconic']) {
1863 /* Opera has trouble with <input type="image"> */
1864 /* IE has trouble with <button> */
1865 if (PMA_USR_BROWSER_AGENT != 'IE') {
1866 echo ' <button class="mult_submit" type="submit" name="submit_mult" value="row_edit" title="' . $GLOBALS['strEdit'] . '">' . "\n"
1867 . '<img src="./images/button_edit.png" title="' . $GLOBALS['strEdit'] . '" alt="' . $GLOBALS['strEdit'] . '" width="11" height="13" />' . (($propicon == 'both') ? '&nbsp;' . $GLOBALS['strEdit'] : '') . "\n"
1868 . '</button>';
1870 echo '&nbsp;<button class="mult_submit" type="submit" name="submit_mult" value="row_delete" title="' . $delete_text . '">' . "\n"
1871 . '<img src="./images/button_drop.png" title="' . $delete_text . '" alt="' . $delete_text . '" width="11" height="13" />' . (($propicon == 'both') ? '&nbsp;' . $delete_text : '') . "\n"
1872 . '</button>';
1874 } else {
1875 echo ' <input type="image" name="submit_mult_edit" value="row_edit" title="' . $GLOBALS['strEdit'] . '" src="./images/button_edit.png" />' . (($propicon == 'both') ? '&nbsp;' . $GLOBALS['strEdit'] : '');
1876 echo '&nbsp;<input type="image" name="submit_mult" value="row_delete" title="' . $delete_text . '" src="./images/button_drop.png" />' . (($propicon == 'both') ? '&nbsp;' . $delete_text : '');
1878 echo "\n";
1879 } else {
1880 echo ' <input type="submit" name="submit_mult" value="row_edit" title="' . $GLOBALS['strEdit'] . '" />' . "\n";
1881 echo '&nbsp;<input type="submit" name="submit_mult" value="row_delete" title="' . $delete_text . '" />' . "\n";
1883 echo '<input type="hidden" name="sql_query" value="' . $sql_query . '" />' . "\n";
1884 echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
1885 echo '<input type="hidden" name="url_query" value="' . $GLOBALS['url_query'] . '" />' . "\n";
1886 echo '<br />' . "\n";
1887 echo '</form>' . "\n";
1890 // 5. ----- Displays the navigation bar at the bottom if required -----
1892 if ($is_display['nav_bar'] == '1') {
1893 echo '<br />' . "\n";
1894 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1895 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1896 echo "\n" . '<br /><br />' . "\n";
1898 } // end of the 'PMA_displayTable()' function
1900 function default_function($buffer) {
1901 $buffer = htmlspecialchars($buffer);
1902 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $buffer));
1903 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
1905 return $buffer;