bug #2966078 Incorrect LIMIT is saved and sticks while browsing
[phpmyadmin/madhuracj.git] / libraries / display_tbl.lib.php
blobf4809d37a6ef6efe6841df238c60257c94d8e90b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * library for displaying table with results from all sort of select queries
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
13 require_once './libraries/Table.class.php';
14 require_once './libraries/Index.class.php';
16 /**
17 * Defines the display mode to use for the results of a SQL query
19 * It uses a synthetic string that contains all the required informations.
20 * In this string:
21 * - the first two characters stand for the action to do while
22 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
23 * edit link...);
24 * - the next two characters stand for the action to do while
25 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
26 * no delete link...);
27 * - the next characters are boolean values (1/0) and respectively stand
28 * for sorting links, navigation bar, "insert a new row" link, the
29 * bookmark feature, the expand/collapse text/blob fields button and
30 * the "display printable view" option.
31 * Of course '0'/'1' means the feature won't/will be enabled.
33 * @param string the synthetic value for display_mode (see a few
34 * lines above for explanations)
35 * @param integer the total number of rows returned by the SQL query
36 * without any programmatically appended "LIMIT" clause
37 * (just a copy of $unlim_num_rows if it exists, else
38 * computed inside this function)
40 * @return array an array with explicit indexes for all the display
41 * elements
43 * @global string the database name
44 * @global string the table name
45 * @global integer the total number of rows returned by the SQL query
46 * without any programmatically appended "LIMIT" clause
47 * @global array the properties of the fields returned by the query
48 * @global string the URL to return to in case of error in a SQL
49 * statement
51 * @access private
53 * @see PMA_displayTable()
55 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
57 global $db, $table;
58 global $unlim_num_rows, $fields_meta;
59 global $err_url;
61 // 1. Initializes the $do_display array
62 $do_display = array();
63 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
64 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
65 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
66 $do_display['nav_bar'] = (string) $the_disp_mode[5];
67 $do_display['ins_row'] = (string) $the_disp_mode[6];
68 $do_display['bkm_form'] = (string) $the_disp_mode[7];
69 $do_display['text_btn'] = (string) $the_disp_mode[8];
70 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
72 // 2. Display mode is not "false for all elements" -> updates the
73 // display mode
74 if ($the_disp_mode != 'nnnn000000') {
75 // 2.0 Print view -> set all elements to false!
76 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
77 $do_display['edit_lnk'] = 'nn'; // no edit link
78 $do_display['del_lnk'] = 'nn'; // no delete link
79 $do_display['sort_lnk'] = (string) '0';
80 $do_display['nav_bar'] = (string) '0';
81 $do_display['ins_row'] = (string) '0';
82 $do_display['bkm_form'] = (string) '0';
83 $do_display['text_btn'] = (string) '0';
84 $do_display['pview_lnk'] = (string) '0';
86 // 2.1 Statement is a "SELECT COUNT", a
87 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
88 // contains a "PROC ANALYSE" part
89 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
90 $do_display['edit_lnk'] = 'nn'; // no edit link
91 $do_display['del_lnk'] = 'nn'; // no delete link
92 $do_display['sort_lnk'] = (string) '0';
93 $do_display['nav_bar'] = (string) '0';
94 $do_display['ins_row'] = (string) '0';
95 $do_display['bkm_form'] = (string) '1';
96 if ($GLOBALS['is_maint']) {
97 $do_display['text_btn'] = (string) '1';
98 } else {
99 $do_display['text_btn'] = (string) '0';
101 $do_display['pview_lnk'] = (string) '1';
103 // 2.2 Statement is a "SHOW..."
104 elseif ($GLOBALS['is_show']) {
106 * 2.2.1
107 * @todo defines edit/delete links depending on show statement
109 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
110 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
111 $do_display['edit_lnk'] = 'nn'; // no edit link
112 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
113 } else {
114 // Default case -> no links
115 $do_display['edit_lnk'] = 'nn'; // no edit link
116 $do_display['del_lnk'] = 'nn'; // no delete link
118 // 2.2.2 Other settings
119 $do_display['sort_lnk'] = (string) '0';
120 $do_display['nav_bar'] = (string) '0';
121 $do_display['ins_row'] = (string) '0';
122 $do_display['bkm_form'] = (string) '1';
123 $do_display['text_btn'] = (string) '1';
124 $do_display['pview_lnk'] = (string) '1';
126 // 2.3 Other statements (ie "SELECT" ones) -> updates
127 // $do_display['edit_lnk'], $do_display['del_lnk'] and
128 // $do_display['text_btn'] (keeps other default values)
129 else {
130 $prev_table = $fields_meta[0]->table;
131 $do_display['text_btn'] = (string) '1';
132 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
133 $is_link = ($do_display['edit_lnk'] != 'nn'
134 || $do_display['del_lnk'] != 'nn'
135 || $do_display['sort_lnk'] != '0'
136 || $do_display['ins_row'] != '0');
137 // 2.3.2 Displays edit/delete/sort/insert links?
138 if ($is_link
139 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
140 $do_display['edit_lnk'] = 'nn'; // don't display links
141 $do_display['del_lnk'] = 'nn';
143 * @todo May be problematic with same fields names in two joined table.
145 // $do_display['sort_lnk'] = (string) '0';
146 $do_display['ins_row'] = (string) '0';
147 if ($do_display['text_btn'] == '1') {
148 break;
150 } // end if (2.3.2)
151 // 2.3.3 Always display print view link
152 $do_display['pview_lnk'] = (string) '1';
153 $prev_table = $fields_meta[$i]->table;
154 } // end for
155 } // end if..elseif...else (2.1 -> 2.3)
156 } // end if (2)
158 // 3. Gets the total number of rows if it is unknown
159 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
160 $the_total = $unlim_num_rows;
161 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
162 && (strlen($db) && !empty($table))) {
163 $the_total = PMA_Table::countRecords($db, $table);
166 // 4. If navigation bar or sorting fields names URLs should be
167 // displayed but there is only one row, change these settings to
168 // false
169 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
171 // - Do not display sort links if less than 2 rows.
172 // - For a VIEW we (probably) did not count the number of rows
173 // so don't test this number here, it would remove the possibility
174 // of sorting VIEW results.
175 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
176 // garvin: force display of navbar for vertical/horizontal display-choice.
177 // $do_display['nav_bar'] = (string) '0';
178 $do_display['sort_lnk'] = (string) '0';
180 } // end if (3)
182 // 5. Updates the synthetic var
183 $the_disp_mode = join('', $do_display);
185 return $do_display;
186 } // end of the 'PMA_setDisplayMode()' function
190 * Displays a navigation button
192 * @uses $GLOBALS['cfg']['NavigationBarIconic']
193 * @uses PMA_generate_common_hidden_inputs()
195 * @param string iconic caption for button
196 * @param string text for button
197 * @param integer position for next query
198 * @param string query ready for display
199 * @param string optional onsubmit clause
200 * @param string optional hidden field for special treatment
201 * @param string optional onclick clause
203 * @global string $db the database name
204 * @global string $table the table name
205 * @global string $goto the URL to go back in case of errors
207 * @access private
209 * @see PMA_displayTableNavigation()
211 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '') {
213 global $db, $table, $goto;
215 $caption_output = '';
216 // for true or 'both'
217 if ($GLOBALS['cfg']['NavigationBarIconic']) {
218 $caption_output .= $caption;
220 // for false or 'both'
221 if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
222 $caption_output .= '&nbsp;' . $title;
224 $title_output = ' title="' . $title . '"';
226 <td>
227 <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
228 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
229 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
230 <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
231 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
232 <?php echo $input_for_real_end; ?>
233 <input type="submit" name="navig" value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
234 </form>
235 </td>
236 <?php
237 } // end function PMA_displayTableNavigationOneButton()
240 * Displays a navigation bar to browse among the results of a SQL query
242 * @uses $_SESSION['tmp_user_values']['disp_direction']
243 * @uses $_SESSION['tmp_user_values']['repeat_cells']
244 * @uses $_SESSION['tmp_user_values']['max_rows']
245 * @uses $_SESSION['tmp_user_values']['pos']
246 * @param integer the offset for the "next" page
247 * @param integer the offset for the "previous" page
248 * @param string the URL-encoded query
249 * @param string the id for the direction dropdown
251 * @global string $db the database name
252 * @global string $table the table name
253 * @global string $goto the URL to go back in case of errors
254 * @global integer $num_rows the total number of rows returned by the
255 * SQL query
256 * @global integer $unlim_num_rows the total number of rows returned by the
257 * SQL any programmatically appended "LIMIT" clause
258 * @global boolean $is_innodb whether its InnoDB or not
259 * @global array $showtable table definitions
261 * @access private
263 * @see PMA_displayTable()
265 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
267 global $db, $table, $goto;
268 global $num_rows, $unlim_num_rows;
269 global $is_innodb;
270 global $showtable;
272 // here, using htmlentities() would cause problems if the query
273 // contains accented characters
274 $html_sql_query = htmlspecialchars($sql_query);
277 * @todo move this to a central place
278 * @todo for other future table types
280 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
284 <!-- Navigation bar -->
285 <table border="0" cellpadding="2" cellspacing="0">
286 <tr>
287 <?php
288 // Move to the beginning or to the previous page
289 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
290 PMA_displayTableNavigationOneButton('&lt;&lt;', $GLOBALS['strPos1'], 0, $html_sql_query);
291 PMA_displayTableNavigationOneButton('&lt;', $GLOBALS['strPrevious'], $pos_prev, $html_sql_query);
293 } // end move back
295 <td>
296 &nbsp;&nbsp;&nbsp;
297 </td>
298 <td align="center">
299 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
300 // of $cfg['MaxExactCountViews']; in this case, avoid passing
301 // the 5th parameter to checkFormElementInRange()
302 // (this means we can't validate the upper limit ?>
303 <form action="sql.php" method="post"
304 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
305 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
306 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
307 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
308 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
309 <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
310 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
311 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
312 <br />
313 <?php
314 // Display mode (horizontal/vertical and repeat headers)
315 $choices = array(
316 'horizontal' => $GLOBALS['strRowsModeHorizontal'],
317 'horizontalflipped' => $GLOBALS['strRowsModeFlippedHorizontal'],
318 'vertical' => $GLOBALS['strRowsModeVertical']);
319 $param1 = PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
320 unset($choices);
322 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />' . "\n"
323 . ' ';
324 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
326 </form>
327 </td>
328 <td>
329 &nbsp;&nbsp;&nbsp;
330 </td>
331 <?php
332 // Move to the next page or to the last one
333 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
334 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
336 // display the Next button
337 PMA_displayTableNavigationOneButton('&gt;',
338 $GLOBALS['strNext'],
339 $pos_next,
340 $html_sql_query);
342 // prepare some options for the End button
343 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
344 $input_for_real_end = '<input type="hidden" name="find_real_end" value="1" />';
345 // no backquote around this message
346 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
347 } else {
348 $input_for_real_end = $onclick = '';
351 // display the End button
352 PMA_displayTableNavigationOneButton('&gt;&gt;',
353 $GLOBALS['strEnd'],
354 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
355 $html_sql_query,
356 'onsubmit="return ' . (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false') . '"',
357 $input_for_real_end,
358 $onclick
360 } // end move toward
363 //page redirection
364 // (unless we are showing all records)
365 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
366 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
367 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
369 if ($nbTotalPage > 1){ //if2
371 <td>
372 &nbsp;&nbsp;&nbsp;
373 </td>
374 <td>
375 <?php //<form> for keep the form alignment of button < and << ?>
376 <form action="none">
377 <?php
378 $_url_params = array(
379 'db' => $db,
380 'table' => $table,
381 'sql_query' => $sql_query,
382 'goto' => $goto,
384 echo PMA_pageselector(
385 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
386 $_SESSION['tmp_user_values']['max_rows'],
387 $pageNow,
388 $nbTotalPage,
389 200,
394 $GLOBALS['strPageNumber']
397 </form>
398 </td>
399 <?php
400 } //_if2
401 } //_if1
403 // Display the "Show all" button if allowed
404 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
405 echo "\n";
407 <td>
408 &nbsp;&nbsp;&nbsp;
409 </td>
410 <td>
411 <form action="sql.php" method="post">
412 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
413 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
414 <input type="hidden" name="pos" value="0" />
415 <input type="hidden" name="session_max_rows" value="all" />
416 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
417 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
418 </form>
419 </td>
420 <?php
421 } // end show all
422 echo "\n";
424 </tr>
425 </table>
427 <?php
428 } // end of the 'PMA_displayTableNavigation()' function
432 * Displays the headers of the results table
434 * @uses $_SESSION['tmp_user_values']['disp_direction']
435 * @uses $_SESSION['tmp_user_values']['repeat_cells']
436 * @uses $_SESSION['tmp_user_values']['max_rows']
437 * @uses $_SESSION['tmp_user_values']['display_text']
438 * @uses $_SESSION['tmp_user_values']['display_binary']
439 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
440 * @param array which elements to display
441 * @param array the list of fields properties
442 * @param integer the total number of fields returned by the SQL query
443 * @param array the analyzed query
445 * @return boolean $clause_is_unique
447 * @global string $db the database name
448 * @global string $table the table name
449 * @global string $goto the URL to go back in case of errors
450 * @global string $sql_query the SQL query
451 * @global integer $num_rows the total number of rows returned by the
452 * SQL query
453 * @global array $vertical_display informations used with vertical display
454 * mode
456 * @access private
458 * @see PMA_displayTable()
460 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
462 global $db, $table, $goto;
463 global $sql_query, $num_rows;
464 global $vertical_display, $highlight_columns;
466 if ($analyzed_sql == '') {
467 $analyzed_sql = array();
470 // can the result be sorted?
471 if ($is_display['sort_lnk'] == '1') {
473 // Just as fallback
474 $unsorted_sql_query = $sql_query;
475 if (isset($analyzed_sql[0]['unsorted_query'])) {
476 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
478 // Handles the case of multiple clicks on a column's header
479 // which would add many spaces before "ORDER BY" in the
480 // generated query.
481 $unsorted_sql_query = trim($unsorted_sql_query);
483 // sorting by indexes, only if it makes sense (only one table ref)
484 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
485 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
486 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
488 // grab indexes data:
489 $indexes = PMA_Index::getFromTable($table, $db);
491 // do we have any index?
492 if ($indexes) {
494 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
495 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
496 $span = $fields_cnt;
497 if ($is_display['edit_lnk'] != 'nn') {
498 $span++;
500 if ($is_display['del_lnk'] != 'nn') {
501 $span++;
503 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
504 $span++;
506 } else {
507 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
510 echo '<form action="sql.php" method="post">' . "\n";
511 echo PMA_generate_common_hidden_inputs($db, $table);
512 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
513 $used_index = false;
514 $local_order = (isset($sort_expression) ? $sort_expression : '');
515 foreach ($indexes as $index) {
516 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
517 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
518 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
519 echo '<option value="'
520 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
521 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
522 . '>' . htmlspecialchars($index->getName()) . ' ('
523 . $GLOBALS['strAscending'] . ')</option>';
524 echo '<option value="'
525 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
526 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
527 . '>' . htmlspecialchars($index->getName()) . ' ('
528 . $GLOBALS['strDescending'] . ')</option>';
530 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
531 echo '</select>' . "\n";
532 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
533 echo '</form>' . "\n";
539 $vertical_display['emptypre'] = 0;
540 $vertical_display['emptyafter'] = 0;
541 $vertical_display['textbtn'] = '';
543 // Display options (if we are not in print view)
544 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
545 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
546 $url_params = array(
547 'db' => $db,
548 'table' => $table,
549 'sql_query' => $sql_query,
550 'goto' => $goto,
551 'display_options_form' => 1
553 echo PMA_generate_common_hidden_inputs($url_params);
554 echo '<br />';
555 PMA_generate_slider_effect('displayoptions',$GLOBALS['strOptions']);
556 echo '<fieldset>';
558 echo '<div class="formelement">';
559 $choices = array(
560 'P' => $GLOBALS['strPartialText'],
561 'F' => $GLOBALS['strFullText']
563 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
564 echo '</div>';
566 // prepare full/partial text button or link
567 if ($_SESSION['tmp_user_values']['display_text']=='F') {
568 // currently in fulltext mode so show the opposite link
569 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
570 $tmp_txt = $GLOBALS['strPartialText'];
571 $url_params['display_text'] = 'P';
572 } else {
573 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
574 $tmp_txt = $GLOBALS['strFullText'];
575 $url_params['display_text'] = 'F';
578 $tmp_image = '<img class="fulltext" width="50" height="20" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
579 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
580 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
581 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
584 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
585 echo '<div class="formelement">';
586 $choices = array(
587 'K' => $GLOBALS['strRelationalKey'],
588 'D' => $GLOBALS['strRelationalDisplayField']
590 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
591 echo '</div>';
594 echo '<div class="formelement">';
595 PMA_display_html_checkbox('display_binary', $GLOBALS['strShowBinaryContents'], ! empty($_SESSION['tmp_user_values']['display_binary']), false);
596 echo '<br />';
597 PMA_display_html_checkbox('display_blob', $GLOBALS['strShowBLOBContents'], ! empty($_SESSION['tmp_user_values']['display_blob']), false);
598 echo '<br />';
599 PMA_display_html_checkbox('display_binary_as_hex', $GLOBALS['strShowBinaryContentsAsHex'], ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
600 echo '</div>';
602 // I would have preferred to name this "display_transformation".
603 // This is the only way I found to be able to keep this setting sticky
604 // per SQL query, and at the same time have a default that displays
605 // the transformations.
606 echo '<div class="formelement">';
607 PMA_display_html_checkbox('hide_transformation', $GLOBALS['strHide'] . ' ' . $GLOBALS['strMIME_transformation'], ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
608 echo '</div>';
610 echo '<div class="clearfloat"></div>';
611 echo '</fieldset>';
613 echo '<fieldset class="tblFooters">';
614 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
615 echo '</fieldset>';
616 echo '</div>';
617 echo '</form>';
620 // Start of form for multi-rows edit/delete/export
622 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
623 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
624 echo PMA_generate_common_hidden_inputs($db, $table, 1);
625 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
628 echo '<table id="table_results" class="data">' . "\n";
629 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
630 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
631 echo '<thead><tr>' . "\n";
634 // 1. Displays the full/partial text button (part 1)...
635 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
636 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
637 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
638 ? ' colspan="3"'
639 : '';
640 } else {
641 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
642 ? ' rowspan="3"'
643 : '';
646 // ... before the result table
647 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
648 && $is_display['text_btn'] == '1') {
649 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
650 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
651 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
653 <th colspan="<?php echo $fields_cnt; ?>"></th>
654 </tr>
655 <tr>
656 <?php
657 } // end horizontal/horizontalflipped mode
658 else {
660 <tr>
661 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
662 </tr>
663 <?php
664 } // end vertical mode
667 // ... at the left column of the result table header if possible
668 // and required
669 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
670 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
671 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
672 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
674 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
675 <?php
676 } // end horizontal/horizontalflipped mode
677 else {
678 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
679 . ' ' . "\n"
680 . ' </th>' . "\n";
681 } // end vertical mode
684 // ... elseif no button, displays empty(ies) col(s) if required
685 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
686 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
687 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
688 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
689 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
691 <td<?php echo $colspan; ?>></td>
692 <?php
693 } // end horizontal/horizontalfipped mode
694 else {
695 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
696 } // end vertical mode
699 // 2. Displays the fields' name
700 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
701 // statement (see 2.1.3)
703 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
704 // Do not show comments, if using horizontalflipped mode, because of space usage
705 if ($GLOBALS['cfg']['ShowBrowseComments']
706 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
707 $comments_map = array();
708 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
709 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
710 $tb = $tbl['table_true_name'];
711 $comments_map[$tb] = PMA_getComments($db, $tb);
712 unset($tb);
717 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
718 require_once './libraries/transformations.lib.php';
719 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
722 if ($is_display['sort_lnk'] == '1') {
723 $select_expr = $analyzed_sql[0]['select_expr_clause'];
726 // garvin: See if we have to highlight any header fields of a WHERE query.
727 // Uses SQL-Parser results.
728 $highlight_columns = array();
729 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
730 isset($analyzed_sql[0]['where_clause_identifiers'])) {
732 $wi = 0;
733 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
734 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
735 $highlight_columns[$wci] = 'true';
740 for ($i = 0; $i < $fields_cnt; $i++) {
741 // garvin: See if this column should get highlight because it's used in the
742 // where-query.
743 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
744 $condition_field = true;
745 } else {
746 $condition_field = false;
749 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
750 if (isset($comments_map) &&
751 isset($comments_map[$fields_meta[$i]->table]) &&
752 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
753 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
754 } else {
755 $comments = '';
758 // 2.1 Results can be sorted
759 if ($is_display['sort_lnk'] == '1') {
761 // 2.1.1 Checks if the table name is required; it's the case
762 // for a query with a "JOIN" statement and if the column
763 // isn't aliased, or in queries like
764 // SELECT `1`.`master_field` , `2`.`master_field`
765 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
767 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
768 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
769 } else {
770 $sort_tbl = '';
773 // 2.1.2 Checks if the current column is used to sort the
774 // results
775 // the orgname member does not exist for all MySQL versions
776 // but if found, it's the one on which to sort
777 $name_to_use_in_sort = $fields_meta[$i]->name;
778 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
779 $name_to_use_in_sort = $fields_meta[$i]->orgname;
781 // $name_to_use_in_sort might contain a space due to
782 // formatting of function expressions like "COUNT(name )"
783 // so we remove the space in this situation
784 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
786 if (empty($sort_expression)) {
787 $is_in_sort = false;
788 } else {
789 // Field name may be preceded by a space, or any number
790 // of characters followed by a dot (tablename.fieldname)
791 // so do a direct comparison for the sort expression;
792 // this avoids problems with queries like
793 // "SELECT id, count(id)..." and clicking to sort
794 // on id or on count(id).
795 // Another query to test this:
796 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
797 // (and try clicking on each column's header twice)
798 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
799 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
801 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
803 // 2.1.3 Check the field name for a bracket.
804 // If it contains one, it's probably a function column
805 // like 'COUNT(`field`)'
806 if (strpos($name_to_use_in_sort, '(') !== false) {
807 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
808 } else {
809 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
811 unset($name_to_use_in_sort);
813 // 2.1.4 Do define the sorting URL
814 if (! $is_in_sort) {
815 // loic1: patch #455484 ("Smart" order)
816 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
817 if ($GLOBALS['cfg']['Order'] === 'SMART') {
818 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
819 } else {
820 $sort_order .= $GLOBALS['cfg']['Order'];
822 $order_img = '';
823 } elseif ('DESC' == $sort_direction) {
824 $sort_order .= ' ASC';
825 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
826 } else {
827 $sort_order .= ' DESC';
828 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
831 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
832 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
833 } else {
834 $sorted_sql_query = $unsorted_sql_query . $sort_order;
836 $_url_params = array(
837 'db' => $db,
838 'table' => $table,
839 'sql_query' => $sorted_sql_query,
841 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
843 // 2.1.5 Displays the sorting URL
844 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
845 // enable sort order swapping for image
846 $order_link_params = array();
847 if (isset($order_img) && $order_img!='') {
848 if (strstr($order_img, 'asc')) {
849 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
850 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
851 } elseif (strstr($order_img, 'desc')) {
852 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
853 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
856 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
857 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
858 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
860 $order_link_params['title'] = $GLOBALS['strSort'];
861 $order_link_content = ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
862 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
864 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
865 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
866 echo '<th';
867 if ($condition_field) {
868 echo ' class="condition"';
870 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
871 echo ' valign="bottom"';
873 echo '>' . $order_link . $comments . '</th>';
875 $vertical_display['desc'][] = ' <th '
876 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
877 . $order_link . $comments . ' </th>' . "\n";
878 } // end if (2.1)
880 // 2.2 Results can't be sorted
881 else {
882 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
883 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
884 echo '<th';
885 if ($condition_field) {
886 echo ' class="condition"';
888 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
889 echo ' valign="bottom"';
891 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
892 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
893 echo ' style="direction: ltr; writing-mode: tb-rl;"';
895 echo '>';
896 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
897 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
898 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
899 } else {
900 echo htmlspecialchars($fields_meta[$i]->name);
902 echo "\n" . $comments . '</th>';
904 $vertical_display['desc'][] = ' <th '
905 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
906 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
907 . $comments . ' </th>';
908 } // end else (2.2)
909 } // end for
911 // 3. Displays the needed checkboxes at the right
912 // column of the result table header if possible and required...
913 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
914 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
915 && $is_display['text_btn'] == '1') {
916 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
917 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
918 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
919 echo "\n";
921 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
922 </th>
923 <?php
924 } // end horizontal/horizontalflipped mode
925 else {
926 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
927 . ' ' . "\n"
928 . ' </th>' . "\n";
929 } // end vertical mode
932 // ... elseif no button, displays empty columns if required
933 // (unless coming from Browse mode print view)
934 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
935 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
936 && (!$GLOBALS['is_header_sent'])) {
937 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
938 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
939 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
940 echo "\n";
942 <td<?php echo $colspan; ?>></td>
943 <?php
944 } // end horizontal/horizontalflipped mode
945 else {
946 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
947 } // end vertical mode
950 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
951 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
953 </tr>
954 </thead>
955 <?php
958 return true;
959 } // end of the 'PMA_displayTableHeaders()' function
964 * Displays the body of the results table
966 * @uses $_SESSION['tmp_user_values']['disp_direction']
967 * @uses $_SESSION['tmp_user_values']['repeat_cells']
968 * @uses $_SESSION['tmp_user_values']['max_rows']
969 * @uses $_SESSION['tmp_user_values']['display_text']
970 * @uses $_SESSION['tmp_user_values']['display_binary']
971 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
972 * @uses $_SESSION['tmp_user_values']['display_blob']
973 * @param integer the link id associated to the query which results have
974 * to be displayed
975 * @param array which elements to display
976 * @param array the list of relations
977 * @param array the analyzed query
979 * @return boolean always true
981 * @global string $db the database name
982 * @global string $table the table name
983 * @global string $goto the URL to go back in case of errors
984 * @global string $sql_query the SQL query
985 * @global array $fields_meta the list of fields properties
986 * @global integer $fields_cnt the total number of fields returned by
987 * the SQL query
988 * @global array $vertical_display informations used with vertical display
989 * mode
990 * @global array $highlight_columns column names to highlight
991 * @global array $row current row data
993 * @access private
995 * @see PMA_displayTable()
997 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
998 global $db, $table, $goto;
999 global $sql_query, $fields_meta, $fields_cnt;
1000 global $vertical_display, $highlight_columns;
1001 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1003 $url_sql_query = $sql_query;
1005 // query without conditions to shorten URLs when needed, 200 is just
1006 // guess, it should depend on remaining URL length
1008 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1009 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1010 strlen($sql_query) > 200) {
1012 $url_sql_query = 'SELECT ';
1013 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1014 $url_sql_query .= ' DISTINCT ';
1016 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1017 if (!empty($analyzed_sql[0]['from_clause'])) {
1018 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1022 if (!is_array($map)) {
1023 $map = array();
1025 $row_no = 0;
1026 $vertical_display['edit'] = array();
1027 $vertical_display['delete'] = array();
1028 $vertical_display['data'] = array();
1029 $vertical_display['row_delete'] = array();
1031 // Correction University of Virginia 19991216 in the while below
1032 // Previous code assumed that all tables have keys, specifically that
1033 // the phpMyAdmin GUI should support row delete/edit only for such
1034 // tables.
1035 // Although always using keys is arguably the prescribed way of
1036 // defining a relational table, it is not required. This will in
1037 // particular be violated by the novice.
1038 // We want to encourage phpMyAdmin usage by such novices. So the code
1039 // below has been changed to conditionally work as before when the
1040 // table being displayed has one or more keys; but to display
1041 // delete/edit options correctly for tables without keys.
1043 $odd_row = true;
1044 while ($row = PMA_DBI_fetch_row($dt_result)) {
1045 // lem9: "vertical display" mode stuff
1046 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1047 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1048 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1050 echo '<tr>' . "\n";
1051 if ($vertical_display['emptypre'] > 0) {
1052 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1053 .' &nbsp;</th>' . "\n";
1056 foreach ($vertical_display['desc'] as $val) {
1057 echo $val;
1060 if ($vertical_display['emptyafter'] > 0) {
1061 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1062 .' &nbsp;</th>' . "\n";
1064 echo '</tr>' . "\n";
1065 } // end if
1067 $class = $odd_row ? 'odd' : 'even';
1068 $odd_row = ! $odd_row;
1069 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1070 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1071 // loic1: pointer code part
1072 echo ' <tr class="' . $class . '">' . "\n";
1073 $class = '';
1077 // 1. Prepares the row
1078 // 1.1 Results from a "SELECT" statement -> builds the
1079 // WHERE clause to use in links (a unique key if possible)
1081 * @todo $where_clause could be empty, for example a table
1082 * with only one field and it's a BLOB; in this case,
1083 * avoid to display the delete and edit links
1085 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1086 $where_clause_html = urlencode($where_clause);
1088 // 1.2 Defines the URLs for the modify/delete link(s)
1090 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1091 // We need to copy the value or else the == 'both' check will always return true
1093 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1094 $iconic_spacer = '<div class="nowrap">';
1095 } else {
1096 $iconic_spacer = '';
1099 // 1.2.1 Modify link(s)
1100 if ($is_display['edit_lnk'] == 'ur') { // update row case
1101 $_url_params = array(
1102 'db' => $db,
1103 'table' => $table,
1104 'where_clause' => $where_clause,
1105 'clause_is_unique' => $clause_is_unique,
1106 'sql_query' => $url_sql_query,
1107 'goto' => 'sql.php',
1109 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
1111 $edit_str = PMA_getIcon('b_edit.png', $GLOBALS['strEdit'], true);
1112 } // end if (1.2.1)
1114 if (isset($GLOBALS['cfg']['Bookmark']['table']) && isset($GLOBALS['cfg']['Bookmark']['db']) && $table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
1115 $_url_params = array(
1116 'db' => $row[1],
1117 'id_bookmark' => $row[0],
1118 'action_bookmark' => '0',
1119 'action_bookmark_all' => '1',
1120 'SQL' => $GLOBALS['strExecuteBookmarked'],
1122 $bookmark_go = '<a href="import.php'
1123 . PMA_generate_common_url($_url_params)
1124 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1126 $bookmark_go .= PMA_getIcon('b_bookmark.png', $GLOBALS['strExecuteBookmarked'], true);
1128 $bookmark_go .= '</a>';
1129 } else {
1130 $bookmark_go = '';
1133 // 1.2.2 Delete/Kill link(s)
1134 if ($is_display['del_lnk'] == 'dr') { // delete row case
1135 $_url_params = array(
1136 'db' => $db,
1137 'table' => $table,
1138 'sql_query' => $url_sql_query,
1139 'zero_rows' => $GLOBALS['strDeleted'],
1140 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1142 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1144 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1145 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1147 $_url_params = array(
1148 'db' => $db,
1149 'table' => $table,
1150 'sql_query' => $del_query,
1151 'zero_rows' => $GLOBALS['strDeleted'],
1152 'goto' => $lnk_goto,
1154 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1156 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1157 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1158 . ($clause_is_unique ? '' : ' LIMIT 1');
1159 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strDelete'], true);
1160 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1162 $_url_params = array(
1163 'db' => $db,
1164 'table' => $table,
1165 'sql_query' => $url_sql_query,
1166 'goto' => 'main.php',
1168 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1170 $_url_params = array(
1171 'db' => 'mysql',
1172 'sql_query' => 'KILL ' . $row[0],
1173 'goto' => $lnk_goto,
1175 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1176 $del_query = 'KILL ' . $row[0];
1177 $js_conf = 'KILL ' . $row[0];
1178 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strKill'], true);
1179 } // end if (1.2.2)
1181 // 1.3 Displays the links at left if required
1182 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1183 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1184 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1185 $doWriteModifyAt = 'left';
1186 require './libraries/display_tbl_links.lib.php';
1187 } // end if (1.3)
1188 } // end if (1)
1190 // 2. Displays the rows' values
1191 for ($i = 0; $i < $fields_cnt; ++$i) {
1192 $meta = $fields_meta[$i];
1193 $pointer = $i;
1194 // garvin: See if this column should get highlight because it's used in the
1195 // where-query.
1196 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1197 $condition_field = true;
1198 } else {
1199 $condition_field = false;
1202 $mouse_events = '';
1203 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1204 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1205 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1206 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1208 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1209 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1210 } else {
1211 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1213 }// end if
1215 // garvin: Wrap MIME-transformations. [MIME]
1216 $default_function = 'default_function'; // default_function
1217 $transform_function = $default_function;
1218 $transform_options = array();
1220 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1222 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1223 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1225 if (file_exists('./libraries/transformations/' . $include_file)) {
1226 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1228 require_once './libraries/transformations/' . $include_file;
1230 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1231 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1232 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1233 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1235 } // end if file_exists
1236 } // end if transformation is set
1237 } // end if mime/transformation works.
1239 $_url_params = array(
1240 'db' => $db,
1241 'table' => $table,
1242 'where_clause' => $where_clause,
1243 'transform_key' => $meta->name,
1246 if (! empty($sql_query)) {
1247 $_url_params['sql_query'] = $url_sql_query;
1250 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1252 // n u m e r i c
1253 if ($meta->numeric == 1) {
1255 // lem9: if two fields have the same name (this is possible
1256 // with self-join queries, for example), using $meta->name
1257 // will show both fields NULL even if only one is NULL,
1258 // so use the $pointer
1260 if (!isset($row[$i]) || is_null($row[$i])) {
1261 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1262 } elseif ($row[$i] != '') {
1264 $nowrap = ' nowrap';
1265 $where_comparison = ' = ' . $row[$i];
1267 $vertical_display['data'][$row_no][$i] = '<td align="right"' . PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options);
1268 } else {
1269 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1272 // b l o b
1274 } elseif (stristr($meta->type, 'BLOB')) {
1275 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1276 // TEXT fields type so we have to ensure it's really a BLOB
1277 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1278 if (stristr($field_flags, 'BINARY')) {
1279 // rajk - for blobstreaming
1281 $bs_reference_exists = $allBSTablesExist = FALSE;
1283 // load PMA configuration
1284 $PMA_Config = $_SESSION['PMA_Config'];
1286 // if PMA configuration exists
1287 if ($PMA_Config) {
1288 // load BS variables
1289 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
1291 // if BS plugins exist
1292 if ($pluginsExist) {
1293 // load BS databases
1294 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
1296 // if BS db array and specified db string not empty and valid
1297 if (!empty($bs_tables) && strlen($db) > 0) {
1298 $bs_tables = $bs_tables[$db];
1300 if (isset($bs_tables)) {
1301 $allBSTablesExist = TRUE;
1303 // check if BS tables exist for given database
1304 foreach ($bs_tables as $table_key=>$bs_tbl)
1305 if (!$bs_tables[$table_key]['Exists']) {
1306 $allBSTablesExist = FALSE;
1307 break;
1314 // if necessary BS tables exist
1315 if ($allBSTablesExist) {
1316 $bs_reference_exists = PMA_BS_ReferenceExists($row[$i], $db);
1319 // if valid BS reference exists
1320 if ($bs_reference_exists) {
1321 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1322 } else {
1323 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1326 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
1327 unset($blobtext);
1328 // not binary:
1329 } else {
1330 if (!isset($row[$i]) || is_null($row[$i])) {
1331 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1332 } elseif ($row[$i] != '') {
1333 // garvin: if a transform function for blob is set, none of these replacements will be made
1334 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1335 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1337 // loic1: displays all space characters, 4 space
1338 // characters for tabulations and <cr>/<lf>
1339 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1341 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1342 } else {
1343 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1346 // n o t n u m e r i c a n d n o t B L O B
1347 } else {
1348 if (!isset($row[$i]) || is_null($row[$i])) {
1349 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1350 } elseif ($row[$i] != '') {
1351 // loic1: support blanks in the key
1352 $relation_id = $row[$i];
1354 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1355 // lem9: (unless it's a link-type transformation)
1356 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1357 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1360 // loic1: displays special characters from binaries
1361 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1362 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1363 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1364 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string') {
1365 if ($_SESSION['tmp_user_values']['display_binary'] || (isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1366 // user asked to see the real contents of BINARY
1367 // fields, or we detected a PROCEDURE ANALYSE in
1368 // the query (results are reported as being
1369 // binary strings)
1370 if ($_SESSION['tmp_user_values']['display_binary_as_hex']) {
1371 $row[$i] = bin2hex($row[$i]);
1373 else {
1374 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1376 } else {
1377 // we show the BINARY message and field's size
1378 // (or maybe use a transformation)
1379 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
1383 // garvin: transform functions may enable no-wrapping:
1384 $function_nowrap = $transform_function . '_nowrap';
1385 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1387 // loic1: do not wrap if date field type
1388 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1389 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1390 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options);
1392 } else {
1393 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1397 // lem9: output stored cell
1398 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1399 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1400 echo $vertical_display['data'][$row_no][$i];
1403 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1404 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1405 } else {
1406 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1408 } // end for (2)
1410 // 3. Displays the modify/delete links on the right if required
1411 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1412 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1413 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1414 $doWriteModifyAt = 'right';
1415 require './libraries/display_tbl_links.lib.php';
1416 } // end if (3)
1418 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1419 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1421 </tr>
1422 <?php
1423 } // end if
1425 // 4. Gather links of del_urls and edit_urls in an array for later
1426 // output
1427 if (!isset($vertical_display['edit'][$row_no])) {
1428 $vertical_display['edit'][$row_no] = '';
1429 $vertical_display['delete'][$row_no] = '';
1430 $vertical_display['row_delete'][$row_no] = '';
1433 $column_style_vertical = '';
1434 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1435 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1436 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1438 $column_marker_vertical = '';
1439 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1440 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1443 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1444 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1445 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $where_clause_html . ']"'
1446 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1447 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1448 . ' </td>' . "\n";
1449 } else {
1450 unset($vertical_display['row_delete'][$row_no]);
1453 if (isset($edit_url)) {
1454 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1455 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1456 . $bookmark_go
1457 . ' </td>' . "\n";
1458 } else {
1459 unset($vertical_display['edit'][$row_no]);
1462 if (isset($del_url)) {
1463 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1464 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1465 . ' </td>' . "\n";
1466 } else {
1467 unset($vertical_display['delete'][$row_no]);
1470 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1471 $row_no++;
1472 } // end while
1474 // this is needed by PMA_displayTable() to generate the proper param
1475 // in the multi-edit and multi-delete form
1476 return $clause_is_unique;
1477 } // end of the 'PMA_displayTableBody()' function
1481 * Do display the result table with the vertical direction mode.
1482 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1484 * @return boolean always true
1486 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1487 * @global array $vertical_display the information to display
1489 * @access private
1491 * @see PMA_displayTable()
1493 function PMA_displayVerticalTable()
1495 global $vertical_display;
1497 // Displays "multi row delete" link at top if required
1498 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1499 echo '<tr>' . "\n";
1500 echo $vertical_display['textbtn'];
1501 $foo_counter = 0;
1502 foreach ($vertical_display['row_delete'] as $val) {
1503 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1504 echo '<th></th>' . "\n";
1507 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1508 $foo_counter++;
1509 } // end while
1510 echo '</tr>' . "\n";
1511 } // end if
1513 // Displays "edit" link at top if required
1514 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1515 echo '<tr>' . "\n";
1516 if (!is_array($vertical_display['row_delete'])) {
1517 echo $vertical_display['textbtn'];
1519 $foo_counter = 0;
1520 foreach ($vertical_display['edit'] as $val) {
1521 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1522 echo ' <th></th>' . "\n";
1525 echo $val;
1526 $foo_counter++;
1527 } // end while
1528 echo '</tr>' . "\n";
1529 } // end if
1531 // Displays "delete" link at top if required
1532 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1533 echo '<tr>' . "\n";
1534 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1535 echo $vertical_display['textbtn'];
1537 $foo_counter = 0;
1538 foreach ($vertical_display['delete'] as $val) {
1539 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1540 echo '<th></th>' . "\n";
1543 echo $val;
1544 $foo_counter++;
1545 } // end while
1546 echo '</tr>' . "\n";
1547 } // end if
1549 // Displays data
1550 foreach ($vertical_display['desc'] AS $key => $val) {
1552 echo '<tr>' . "\n";
1553 echo $val;
1555 $foo_counter = 0;
1556 foreach ($vertical_display['rowdata'][$key] as $subval) {
1557 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1558 echo $val;
1561 echo $subval;
1562 $foo_counter++;
1563 } // end while
1565 echo '</tr>' . "\n";
1566 } // end while
1568 // Displays "multi row delete" link at bottom if required
1569 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1570 echo '<tr>' . "\n";
1571 echo $vertical_display['textbtn'];
1572 $foo_counter = 0;
1573 foreach ($vertical_display['row_delete'] as $val) {
1574 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1575 echo '<th></th>' . "\n";
1578 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1579 $foo_counter++;
1580 } // end while
1581 echo '</tr>' . "\n";
1582 } // end if
1584 // Displays "edit" link at bottom if required
1585 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1586 echo '<tr>' . "\n";
1587 if (!is_array($vertical_display['row_delete'])) {
1588 echo $vertical_display['textbtn'];
1590 $foo_counter = 0;
1591 foreach ($vertical_display['edit'] as $val) {
1592 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1593 echo '<th></th>' . "\n";
1596 echo $val;
1597 $foo_counter++;
1598 } // end while
1599 echo '</tr>' . "\n";
1600 } // end if
1602 // Displays "delete" link at bottom if required
1603 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1604 echo '<tr>' . "\n";
1605 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1606 echo $vertical_display['textbtn'];
1608 $foo_counter = 0;
1609 foreach ($vertical_display['delete'] as $val) {
1610 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1611 echo '<th></th>' . "\n";
1614 echo $val;
1615 $foo_counter++;
1616 } // end while
1617 echo '</tr>' . "\n";
1620 return true;
1621 } // end of the 'PMA_displayVerticalTable' function
1625 * @uses $_SESSION['tmp_user_values']['disp_direction']
1626 * @uses $_REQUEST['disp_direction']
1627 * @uses $GLOBALS['cfg']['DefaultDisplay']
1628 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1629 * @uses $_REQUEST['repeat_cells']
1630 * @uses $GLOBALS['cfg']['RepeatCells']
1631 * @uses $_SESSION['tmp_user_values']['max_rows']
1632 * @uses $_REQUEST['session_max_rows']
1633 * @uses $GLOBALS['cfg']['MaxRows']
1634 * @uses $_SESSION['tmp_user_values']['pos']
1635 * @uses $_REQUEST['pos']
1636 * @uses $_SESSION['tmp_user_values']['display_text']
1637 * @uses $_REQUEST['display_text']
1638 * @uses $_SESSION['tmp_user_values']['relational_display']
1639 * @uses $_REQUEST['relational_display']
1640 * @uses $_SESSION['tmp_user_values']['display_binary']
1641 * @uses $_REQUEST['display_binary']
1642 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1643 * @uses $_REQUEST['display_binary_as_hex']
1644 * @uses $_SESSION['tmp_user_values']['display_blob']
1645 * @uses $_REQUEST['display_blob']
1646 * @uses PMA_isValid()
1647 * @uses $GLOBALS['sql_query']
1648 * @todo make maximum remembered queries configurable
1649 * @todo move/split into SQL class!?
1650 * @todo currently this is called twice unnecessary
1651 * @todo ignore LIMIT and ORDER in query!?
1653 function PMA_displayTable_checkConfigParams()
1655 $sql_key = md5($GLOBALS['sql_query']);
1657 $_SESSION['tmp_user_values']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1659 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1660 $_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1661 unset($_REQUEST['disp_direction']);
1662 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'])) {
1663 $_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1666 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1667 $_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1668 unset($_REQUEST['repeat_cells']);
1669 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'])) {
1670 $_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1673 // as this is a form value, the type is always string so we cannot
1674 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1675 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1676 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1677 || $_REQUEST['session_max_rows'] == 'all') {
1678 $_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1679 unset($_REQUEST['session_max_rows']);
1680 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'])) {
1681 $_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1684 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1685 $_SESSION['tmp_user_values']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1686 unset($_REQUEST['pos']);
1687 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['pos'])) {
1688 $_SESSION['tmp_user_values']['query'][$sql_key]['pos'] = 0;
1691 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1692 $_SESSION['tmp_user_values']['query'][$sql_key]['display_text'] = $_REQUEST['display_text'];
1693 unset($_REQUEST['display_text']);
1694 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['display_text'])) {
1695 $_SESSION['tmp_user_values']['query'][$sql_key]['display_text'] = 'P';
1698 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1699 $_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'] = $_REQUEST['relational_display'];
1700 unset($_REQUEST['relational_display']);
1701 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'])) {
1702 $_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'] = 'K';
1705 if (isset($_REQUEST['display_binary'])) {
1706 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary'] = true;
1707 unset($_REQUEST['display_binary']);
1708 } elseif (isset($_REQUEST['display_options_form'])) {
1709 // we know that the checkbox was unchecked
1710 unset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary']);
1711 } else {
1712 // selected by default because some operations like OPTIMIZE TABLE
1713 // and all queries involving functions return "binary" contents,
1714 // according to low-level field flags
1715 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary'] = true;
1718 if (isset($_REQUEST['display_binary_as_hex'])) {
1719 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex'] = true;
1720 unset($_REQUEST['display_binary_as_hex']);
1721 } elseif (isset($_REQUEST['display_options_form'])) {
1722 // we know that the checkbox was unchecked
1723 unset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex']);
1724 } else {
1725 // display_binary_as_hex config option
1726 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1727 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex'] = true;
1731 if (isset($_REQUEST['display_blob'])) {
1732 $_SESSION['tmp_user_values']['query'][$sql_key]['display_blob'] = true;
1733 unset($_REQUEST['display_blob']);
1734 } elseif (isset($_REQUEST['display_options_form'])) {
1735 // we know that the checkbox was unchecked
1736 unset($_SESSION['tmp_user_values']['query'][$sql_key]['display_blob']);
1739 if (isset($_REQUEST['hide_transformation'])) {
1740 $_SESSION['tmp_user_values']['query'][$sql_key]['hide_transformation'] = true;
1741 unset($_REQUEST['hide_transformation']);
1742 } elseif (isset($_REQUEST['display_options_form'])) {
1743 // we know that the checkbox was unchecked
1744 unset($_SESSION['tmp_user_values']['query'][$sql_key]['hide_transformation']);
1747 // move current query to the last position, to be removed last
1748 // so only least executed query will be removed if maximum remembered queries
1749 // limit is reached
1750 $tmp = $_SESSION['tmp_user_values']['query'][$sql_key];
1751 unset($_SESSION['tmp_user_values']['query'][$sql_key]);
1752 $_SESSION['tmp_user_values']['query'][$sql_key] = $tmp;
1754 // do not exceed a maximum number of queries to remember
1755 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1756 array_shift($_SESSION['tmp_user_values']['query']);
1757 //echo 'deleting one element ...';
1760 // populate query configuration
1761 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_key]['display_text'];
1762 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'];
1763 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary']) ? true : false;
1764 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex']) ? true : false;
1765 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['display_blob']) ? true : false;
1766 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['hide_transformation']) ? true : false;
1767 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_key]['pos'];
1768 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'];
1769 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'];
1770 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'];
1773 * debugging
1774 echo '<pre>';
1775 var_dump($_SESSION['tmp_user_values']);
1776 echo '</pre>';
1781 * Displays a table of results returned by a SQL query.
1782 * This function is called by the "sql.php" script.
1784 * @param integer the link id associated to the query which results have
1785 * to be displayed
1786 * @param array the display mode
1787 * @param array the analyzed query
1789 * @uses $_SESSION['tmp_user_values']['pos']
1790 * @global string $db the database name
1791 * @global string $table the table name
1792 * @global string $goto the URL to go back in case of errors
1793 * @global string $sql_query the current SQL query
1794 * @global integer $num_rows the total number of rows returned by the
1795 * SQL query
1796 * @global integer $unlim_num_rows the total number of rows returned by the
1797 * SQL query without any programmatically
1798 * appended "LIMIT" clause
1799 * @global array $fields_meta the list of fields properties
1800 * @global integer $fields_cnt the total number of fields returned by
1801 * the SQL query
1802 * @global array $vertical_display informations used with vertical display
1803 * mode
1804 * @global array $highlight_columns column names to highlight
1805 * @global array $cfgRelation the relation settings
1807 * @access private
1809 * @see PMA_showMessage(), PMA_setDisplayMode(),
1810 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1811 * PMA_displayTableBody(), PMA_displayResultsOperations()
1813 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1815 global $db, $table, $goto;
1816 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1817 global $vertical_display, $highlight_columns;
1818 global $cfgRelation;
1819 global $showtable;
1821 // why was this called here? (already called from sql.php)
1822 //PMA_displayTable_checkConfigParams();
1825 * @todo move this to a central place
1826 * @todo for other future table types
1828 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1830 if ($is_innodb
1831 && ! isset($analyzed_sql[0]['queryflags']['union'])
1832 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1833 && (empty($analyzed_sql[0]['where_clause'])
1834 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1835 // "j u s t b r o w s i n g"
1836 $pre_count = '~';
1837 $after_count = PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount']), true);
1838 } else {
1839 $pre_count = '';
1840 $after_count = '';
1843 // 1. ----- Prepares the work -----
1845 // 1.1 Gets the informations about which functionalities should be
1846 // displayed
1847 $total = '';
1848 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1850 // 1.2 Defines offsets for the next and previous pages
1851 if ($is_display['nav_bar'] == '1') {
1852 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1853 $pos_next = 0;
1854 $pos_prev = 0;
1855 } else {
1856 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
1857 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1858 if ($pos_prev < 0) {
1859 $pos_prev = 0;
1862 } // end if
1864 // 1.3 Find the sort expression
1866 // we need $sort_expression and $sort_expression_nodirection
1867 // even if there are many table references
1868 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1869 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1871 * Get rid of ASC|DESC
1873 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1874 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1875 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1876 unset($matches);
1877 } else {
1878 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1881 // 1.4 Prepares display of first and last value of the sorted column
1883 if (! empty($sort_expression_nodirection)) {
1884 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1885 $sort_table = PMA_unQuote($sort_table);
1886 $sort_column = PMA_unQuote($sort_column);
1887 // find the sorted column index in row result
1888 // (this might be a multi-table query)
1889 $sorted_column_index = false;
1890 foreach($fields_meta as $key => $meta) {
1891 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1892 $sorted_column_index = $key;
1893 break;
1896 if ($sorted_column_index !== false) {
1897 // fetch first row of the result set
1898 $row = PMA_DBI_fetch_row($dt_result);
1899 $column_for_first_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1900 // fetch last row of the result set
1901 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1902 $row = PMA_DBI_fetch_row($dt_result);
1903 $column_for_last_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1904 // reset to first row for the loop in PMA_displayTableBody()
1905 PMA_DBI_data_seek($dt_result, 0);
1906 // we could also use here $sort_expression_nodirection
1907 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1908 unset($row, $column_for_first_row, $column_for_last_row);
1910 unset($sorted_column_index, $sort_table, $sort_column);
1913 // 2. ----- Displays the top of the page -----
1915 // 2.1 Displays a messages with position informations
1916 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1917 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1918 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1919 } else {
1920 $selectstring = '';
1922 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
1923 ? $total - 1
1924 : $pos_next - 1;
1926 if (PMA_Table::isView($db, $table)
1927 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1928 $message = PMA_Message::notice('strViewHasAtLeast');
1929 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1930 $message->addParam('[/a]');
1931 $message_view_warning = PMA_showHint($message);
1932 } else {
1933 $message_view_warning = false;
1936 $message = PMA_Message::success('strShowingRecords');
1937 $message->addMessage($_SESSION['tmp_user_values']['pos']);
1938 if ($message_view_warning) {
1939 $message->addMessage('...', ' - ');
1940 $message->addMessage($message_view_warning);
1941 $message->addMessage('(');
1942 } else {
1943 $message->addMessage($last_shown_rec, ' - ');
1944 $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
1945 $message->addString('strTotal');
1946 $message->addMessage($selectstring, '');
1947 $message->addMessage(', ', '');
1950 $messagge_qt = PMA_Message::notice('strQueryTime');
1951 $messagge_qt->addParam($GLOBALS['querytime']);
1953 $message->addMessage($messagge_qt, '');
1954 $message->addMessage(')', '');
1956 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
1958 PMA_showMessage($message, $sql_query, 'success');
1960 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1961 PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
1964 // 2.3 Displays the navigation bars
1965 if (! strlen($table)) {
1966 if (isset($analyzed_sql[0]['query_type'])
1967 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1968 // table does not always contain a real table name,
1969 // for example in MySQL 5.0.x, the query SHOW STATUS
1970 // returns STATUS as a table name
1971 $table = $fields_meta[0]->table;
1972 } else {
1973 $table = '';
1977 if ($is_display['nav_bar'] == '1') {
1978 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
1979 echo "\n";
1980 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1981 echo "\n" . '<br /><br />' . "\n";
1984 // 2b ----- Get field references from Database -----
1985 // (see the 'relation' configuration variable)
1986 // loic1, 2002-03-02: extended to php3
1988 // initialize map
1989 $map = array();
1991 // find tables
1992 $target=array();
1993 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1994 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1995 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1998 $tabs = '(\'' . join('\',\'', $target) . '\')';
2000 if ($cfgRelation['displaywork']) {
2001 if (! strlen($table)) {
2002 $exist_rel = false;
2003 } else {
2004 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2005 if ($exist_rel) {
2006 foreach ($exist_rel AS $master_field => $rel) {
2007 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2008 $map[$master_field] = array($rel['foreign_table'],
2009 $rel['foreign_field'],
2010 $display_field,
2011 $rel['foreign_db']);
2012 } // end while
2013 } // end if
2014 } // end if
2015 } // end if
2016 // end 2b
2018 // 3. ----- Displays the results table -----
2019 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2020 $url_query = '';
2021 echo '<tbody>' . "\n";
2022 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2023 // vertical output case
2024 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2025 PMA_displayVerticalTable();
2026 } // end if
2027 unset($vertical_display);
2028 echo '</tbody>' . "\n";
2030 </table>
2032 <?php
2033 // 4. ----- Displays the link for multi-fields edit and delete
2035 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2037 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
2039 $_url_params = array(
2040 'db' => $db,
2041 'table' => $table,
2042 'sql_query' => $sql_query,
2043 'goto' => $goto,
2045 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2047 $_url_params['checkall'] = '1';
2048 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2050 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2051 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2052 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2053 } else {
2054 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2055 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2057 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
2058 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
2059 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2060 echo '<img class="selectallarrow" width="38" height="22"'
2061 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2062 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
2064 echo $checkall_link . "\n"
2065 .' / ' . "\n"
2066 .$uncheckall_link . "\n"
2067 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
2069 PMA_buttonOrImage('submit_mult', 'mult_submit',
2070 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
2071 PMA_buttonOrImage('submit_mult', 'mult_submit',
2072 'submit_mult_delete', $delete_text, 'b_drop.png');
2073 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
2074 PMA_buttonOrImage('submit_mult', 'mult_submit',
2075 'submit_mult_export', $GLOBALS['strExport'],
2076 'b_tblexport.png');
2078 echo "\n";
2080 echo '<input type="hidden" name="sql_query"'
2081 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2082 echo '<input type="hidden" name="url_query"'
2083 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2085 echo '<input type="hidden" name="clause_is_unique"'
2086 .' value="' . $clause_is_unique . '" />' . "\n";
2088 echo '</form>' . "\n";
2091 // 5. ----- Displays the navigation bar at the bottom if required -----
2093 if ($is_display['nav_bar'] == '1') {
2094 echo '<br />' . "\n";
2095 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2096 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2097 echo "\n" . '<br /><br />' . "\n";
2100 // 6. ----- Displays "Query results operations"
2101 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2102 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2104 } // end of the 'PMA_displayTable()' function
2106 function default_function($buffer) {
2107 $buffer = htmlspecialchars($buffer);
2108 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2109 str_replace(' ', ' &nbsp;', $buffer));
2110 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2112 return $buffer;
2116 * Displays operations that are available on results.
2118 * @param array the display mode
2119 * @param array the analyzed query
2121 * @uses $_SESSION['tmp_user_values']['pos']
2122 * @uses $_SESSION['tmp_user_values']['display_text']
2123 * @global string $db the database name
2124 * @global string $table the table name
2125 * @global string $sql_query the current SQL query
2126 * @global integer $unlim_num_rows the total number of rows returned by the
2127 * SQL query without any programmatically
2128 * appended "LIMIT" clause
2130 * @access private
2132 * @see PMA_showMessage(), PMA_setDisplayMode(),
2133 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2134 * PMA_displayTableBody(), PMA_displayResultsOperations()
2136 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2137 global $db, $table, $sql_query, $unlim_num_rows;
2139 $header_shown = FALSE;
2140 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
2142 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2143 // Displays "printable view" link if required
2144 if ($the_disp_mode[9] == '1') {
2146 if (!$header_shown) {
2147 echo $header;
2148 $header_shown = TRUE;
2151 $_url_params = array(
2152 'db' => $db,
2153 'table' => $table,
2154 'printview' => '1',
2155 'sql_query' => $sql_query,
2157 $url_query = PMA_generate_common_url($_url_params);
2159 echo PMA_linkOrButton(
2160 'sql.php' . $url_query,
2161 PMA_getIcon('b_print.png', $GLOBALS['strPrintView'], false, true),
2162 '', true, true, 'print_view') . "\n";
2164 if ($_SESSION['tmp_user_values']['display_text']) {
2165 $_url_params['display_text'] = 'F';
2166 echo PMA_linkOrButton(
2167 'sql.php' . PMA_generate_common_url($_url_params),
2168 PMA_getIcon('b_print.png', $GLOBALS['strPrintViewFull'], false, true),
2169 '', true, true, 'print_view') . "\n";
2170 unset($_url_params['display_text']);
2172 } // end displays "printable view"
2175 // Export link
2176 // (the url_query has extra parameters that won't be used to export)
2177 // (the single_table parameter is used in display_export.lib.php
2178 // to hide the SQL and the structure export dialogs)
2179 // If the parser found a PROCEDURE clause
2180 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2181 // display the Export link).
2182 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2183 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2184 $_url_params['single_table'] = 'true';
2186 if (!$header_shown) {
2187 echo $header;
2188 $header_shown = TRUE;
2190 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2193 * At this point we don't know the table name; this can happen
2194 * for example with a query like
2195 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2196 * As a workaround we set in the table parameter the name of the
2197 * first table of this database, so that tbl_export.php and
2198 * the script it calls do not fail
2200 if (empty($_url_params['table'])) {
2201 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2204 echo PMA_linkOrButton(
2205 'tbl_export.php' . PMA_generate_common_url($_url_params),
2206 PMA_getIcon('b_tblexport.png', $GLOBALS['strExport'], false, true),
2207 '', true, true, '') . "\n";
2210 // CREATE VIEW
2213 * @todo detect privileges to create a view
2214 * (but see 2006-01-19 note in display_create_table.lib.php,
2215 * I think we cannot detect db-specific privileges reliably)
2216 * Note: we don't display a Create view link if we found a PROCEDURE clause
2218 if (!$header_shown) {
2219 echo $header;
2220 $header_shown = TRUE;
2222 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2223 echo PMA_linkOrButton(
2224 'view_create.php' . $url_query,
2225 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2226 '', true, true, '') . "\n";
2228 if ($header_shown) {
2229 echo '</fieldset><br />';
2234 * Verifies what to do with non-printable contents (binary or BLOB)
2235 * in Browse mode.
2237 * @uses is_null()
2238 * @uses isset()
2239 * @uses strlen()
2240 * @uses PMA_formatByteDown()
2241 * @uses strpos()
2242 * @uses str_replace()
2243 * @param string $category BLOB|BINARY
2244 * @param string $content the binary content
2245 * @param string $transform_function
2246 * @param string $transform_options
2247 * @param string $default_function
2248 * @param object $meta the meta-information about this field
2249 * @return mixed string or float
2251 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta) {
2252 $result = '[' . $category;
2253 if (is_null($content)) {
2254 $result .= ' - NULL';
2255 $size = 0;
2256 } elseif (isset($content)) {
2257 $size = strlen($content);
2258 $display_size = PMA_formatByteDown($size, 3, 1);
2259 $result .= ' - '. $display_size[0] . $display_size[1];
2261 $result .= ']';
2263 if (strpos($transform_function, 'octetstream')) {
2264 $result = $content;
2266 if ($size > 0) {
2267 if ($default_function != $transform_function) {
2268 $result = $transform_function($result, $transform_options, $meta);
2269 } else {
2270 $result = $default_function($result, array(), $meta);
2271 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2272 // in this case, restart from the original $content
2273 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2277 return($result);
2281 * Prepares the displayable content of a data cell in Browse mode,
2282 * taking into account foreign key description field and transformations
2284 * @uses is_array()
2285 * @uses PMA_backquote()
2286 * @uses PMA_DBI_try_query()
2287 * @uses PMA_DBI_num_rows()
2288 * @uses PMA_DBI_fetch_row()
2289 * @uses $GLOBALS['strLinkNotFound']
2290 * @uses PMA_DBI_free_result()
2291 * @uses $GLOBALS['printview']
2292 * @uses htmlspecialchars()
2293 * @uses PMA_generate_common_url()
2294 * @param string $mouse_events
2295 * @param string $class
2296 * @param string $condition_field
2297 * @param string $analyzed_sql
2298 * @param object $meta the meta-information about this field
2299 * @param string $map
2300 * @param string $data
2301 * @param string $transform_function
2302 * @param string $default_function
2303 * @param string $nowrap
2304 * @param string $where_comparison
2305 * @return string formatted data
2307 function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options) {
2309 // continue the <td> tag started before calling this function:
2310 $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . '">';
2312 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2313 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2314 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2315 if (isset($alias) && strlen($alias)) {
2316 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2317 if ($alias == $meta->name) {
2318 // this change in the parameter does not matter
2319 // outside of the function
2320 $meta->name = $true_column;
2321 } // end if
2322 } // end if
2323 } // end foreach
2324 } // end if
2326 if (isset($map[$meta->name])) {
2327 // Field to display from the foreign table?
2328 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2329 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2330 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2331 . '.' . PMA_backquote($map[$meta->name][0])
2332 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2333 . $where_comparison;
2334 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2335 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2336 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2337 } else {
2338 $dispval = $GLOBALS['strLinkNotFound'];
2340 @PMA_DBI_free_result($dispresult);
2341 } else {
2342 $dispval = '';
2343 } // end if... else...
2345 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2346 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2347 } else {
2349 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2350 // user chose "relational key" in the display options, so
2351 // the title contains the display field
2352 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2353 } else {
2354 $title = ' title="' . htmlspecialchars($data) . '"';
2357 $_url_params = array(
2358 'db' => $map[$meta->name][3],
2359 'table' => $map[$meta->name][0],
2360 'pos' => '0',
2361 'sql_query' => 'SELECT * FROM '
2362 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2363 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2364 . $where_comparison,
2366 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2367 . '"' . $title . '>';
2369 if ($transform_function != $default_function) {
2370 // always apply a transformation on the real data,
2371 // not on the display field
2372 $result .= $transform_function($data, $transform_options, $meta);
2373 } else {
2374 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2375 // user chose "relational display field" in the
2376 // display options, so show display field in the cell
2377 $result .= $transform_function($dispval, array(), $meta);
2378 } else {
2379 // otherwise display data in the cell
2380 $result .= $transform_function($data, array(), $meta);
2383 $result .= '</a>';
2385 } else {
2386 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2388 $result .= '</td>' . "\n";
2390 return $result;