3.3.2-rc1
[phpmyadmin/madhuracj.git] / libraries / display_tbl.lib.php
blob41bb9876562d8d03b30e112cebe7280952970f8c
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 // some results of PROCEDURE ANALYSE() are reported as
1365 // being BINARY but they are quite readable,
1366 // so don't treat them as BINARY
1367 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1368 if ($_SESSION['tmp_user_values']['display_binary']) {
1369 // user asked to see the real contents of BINARY
1370 // fields
1371 if ($_SESSION['tmp_user_values']['display_binary_as_hex']) {
1372 $row[$i] = bin2hex($row[$i]);
1374 else {
1375 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1377 } else {
1378 // we show the BINARY message and field's size
1379 // (or maybe use a transformation)
1380 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
1384 // garvin: transform functions may enable no-wrapping:
1385 $function_nowrap = $transform_function . '_nowrap';
1386 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1388 // loic1: do not wrap if date field type
1389 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1390 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1391 $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);
1393 } else {
1394 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1398 // lem9: output stored cell
1399 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1400 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1401 echo $vertical_display['data'][$row_no][$i];
1404 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1405 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1406 } else {
1407 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1409 } // end for (2)
1411 // 3. Displays the modify/delete links on the right if required
1412 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1413 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1414 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1415 $doWriteModifyAt = 'right';
1416 require './libraries/display_tbl_links.lib.php';
1417 } // end if (3)
1419 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1420 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1422 </tr>
1423 <?php
1424 } // end if
1426 // 4. Gather links of del_urls and edit_urls in an array for later
1427 // output
1428 if (!isset($vertical_display['edit'][$row_no])) {
1429 $vertical_display['edit'][$row_no] = '';
1430 $vertical_display['delete'][$row_no] = '';
1431 $vertical_display['row_delete'][$row_no] = '';
1434 $column_style_vertical = '';
1435 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1436 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1437 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1439 $column_marker_vertical = '';
1440 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1441 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1444 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1445 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1446 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $where_clause_html . ']"'
1447 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1448 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1449 . ' </td>' . "\n";
1450 } else {
1451 unset($vertical_display['row_delete'][$row_no]);
1454 if (isset($edit_url)) {
1455 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1456 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1457 . $bookmark_go
1458 . ' </td>' . "\n";
1459 } else {
1460 unset($vertical_display['edit'][$row_no]);
1463 if (isset($del_url)) {
1464 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1465 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1466 . ' </td>' . "\n";
1467 } else {
1468 unset($vertical_display['delete'][$row_no]);
1471 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1472 $row_no++;
1473 } // end while
1475 // this is needed by PMA_displayTable() to generate the proper param
1476 // in the multi-edit and multi-delete form
1477 return $clause_is_unique;
1478 } // end of the 'PMA_displayTableBody()' function
1482 * Do display the result table with the vertical direction mode.
1483 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1485 * @return boolean always true
1487 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1488 * @global array $vertical_display the information to display
1490 * @access private
1492 * @see PMA_displayTable()
1494 function PMA_displayVerticalTable()
1496 global $vertical_display;
1498 // Displays "multi row delete" link at top if required
1499 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1500 echo '<tr>' . "\n";
1501 echo $vertical_display['textbtn'];
1502 $foo_counter = 0;
1503 foreach ($vertical_display['row_delete'] as $val) {
1504 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1505 echo '<th></th>' . "\n";
1508 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1509 $foo_counter++;
1510 } // end while
1511 echo '</tr>' . "\n";
1512 } // end if
1514 // Displays "edit" link at top if required
1515 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1516 echo '<tr>' . "\n";
1517 if (!is_array($vertical_display['row_delete'])) {
1518 echo $vertical_display['textbtn'];
1520 $foo_counter = 0;
1521 foreach ($vertical_display['edit'] as $val) {
1522 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1523 echo ' <th></th>' . "\n";
1526 echo $val;
1527 $foo_counter++;
1528 } // end while
1529 echo '</tr>' . "\n";
1530 } // end if
1532 // Displays "delete" link at top if required
1533 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1534 echo '<tr>' . "\n";
1535 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1536 echo $vertical_display['textbtn'];
1538 $foo_counter = 0;
1539 foreach ($vertical_display['delete'] as $val) {
1540 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1541 echo '<th></th>' . "\n";
1544 echo $val;
1545 $foo_counter++;
1546 } // end while
1547 echo '</tr>' . "\n";
1548 } // end if
1550 // Displays data
1551 foreach ($vertical_display['desc'] AS $key => $val) {
1553 echo '<tr>' . "\n";
1554 echo $val;
1556 $foo_counter = 0;
1557 foreach ($vertical_display['rowdata'][$key] as $subval) {
1558 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1559 echo $val;
1562 echo $subval;
1563 $foo_counter++;
1564 } // end while
1566 echo '</tr>' . "\n";
1567 } // end while
1569 // Displays "multi row delete" link at bottom if required
1570 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1571 echo '<tr>' . "\n";
1572 echo $vertical_display['textbtn'];
1573 $foo_counter = 0;
1574 foreach ($vertical_display['row_delete'] as $val) {
1575 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1576 echo '<th></th>' . "\n";
1579 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1580 $foo_counter++;
1581 } // end while
1582 echo '</tr>' . "\n";
1583 } // end if
1585 // Displays "edit" link at bottom if required
1586 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1587 echo '<tr>' . "\n";
1588 if (!is_array($vertical_display['row_delete'])) {
1589 echo $vertical_display['textbtn'];
1591 $foo_counter = 0;
1592 foreach ($vertical_display['edit'] as $val) {
1593 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1594 echo '<th></th>' . "\n";
1597 echo $val;
1598 $foo_counter++;
1599 } // end while
1600 echo '</tr>' . "\n";
1601 } // end if
1603 // Displays "delete" link at bottom if required
1604 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1605 echo '<tr>' . "\n";
1606 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1607 echo $vertical_display['textbtn'];
1609 $foo_counter = 0;
1610 foreach ($vertical_display['delete'] as $val) {
1611 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1612 echo '<th></th>' . "\n";
1615 echo $val;
1616 $foo_counter++;
1617 } // end while
1618 echo '</tr>' . "\n";
1621 return true;
1622 } // end of the 'PMA_displayVerticalTable' function
1626 * @uses $_SESSION['tmp_user_values']['disp_direction']
1627 * @uses $_REQUEST['disp_direction']
1628 * @uses $GLOBALS['cfg']['DefaultDisplay']
1629 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1630 * @uses $_REQUEST['repeat_cells']
1631 * @uses $GLOBALS['cfg']['RepeatCells']
1632 * @uses $_SESSION['tmp_user_values']['max_rows']
1633 * @uses $_REQUEST['session_max_rows']
1634 * @uses $GLOBALS['cfg']['MaxRows']
1635 * @uses $_SESSION['tmp_user_values']['pos']
1636 * @uses $_REQUEST['pos']
1637 * @uses $_SESSION['tmp_user_values']['display_text']
1638 * @uses $_REQUEST['display_text']
1639 * @uses $_SESSION['tmp_user_values']['relational_display']
1640 * @uses $_REQUEST['relational_display']
1641 * @uses $_SESSION['tmp_user_values']['display_binary']
1642 * @uses $_REQUEST['display_binary']
1643 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1644 * @uses $_REQUEST['display_binary_as_hex']
1645 * @uses $_SESSION['tmp_user_values']['display_blob']
1646 * @uses $_REQUEST['display_blob']
1647 * @uses PMA_isValid()
1648 * @uses $GLOBALS['sql_query']
1649 * @todo make maximum remembered queries configurable
1650 * @todo move/split into SQL class!?
1651 * @todo currently this is called twice unnecessary
1652 * @todo ignore LIMIT and ORDER in query!?
1654 function PMA_displayTable_checkConfigParams()
1656 $sql_key = md5($GLOBALS['sql_query']);
1658 $_SESSION['tmp_user_values']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1660 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1661 $_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1662 unset($_REQUEST['disp_direction']);
1663 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'])) {
1664 $_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1667 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1668 $_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1669 unset($_REQUEST['repeat_cells']);
1670 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'])) {
1671 $_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1674 // as this is a form value, the type is always string so we cannot
1675 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1676 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1677 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1678 || $_REQUEST['session_max_rows'] == 'all') {
1679 $_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1680 unset($_REQUEST['session_max_rows']);
1681 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'])) {
1682 $_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1685 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1686 $_SESSION['tmp_user_values']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1687 unset($_REQUEST['pos']);
1688 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['pos'])) {
1689 $_SESSION['tmp_user_values']['query'][$sql_key]['pos'] = 0;
1692 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1693 $_SESSION['tmp_user_values']['query'][$sql_key]['display_text'] = $_REQUEST['display_text'];
1694 unset($_REQUEST['display_text']);
1695 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['display_text'])) {
1696 $_SESSION['tmp_user_values']['query'][$sql_key]['display_text'] = 'P';
1699 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1700 $_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'] = $_REQUEST['relational_display'];
1701 unset($_REQUEST['relational_display']);
1702 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'])) {
1703 $_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'] = 'K';
1706 if (isset($_REQUEST['display_binary'])) {
1707 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary'] = true;
1708 unset($_REQUEST['display_binary']);
1709 } elseif (isset($_REQUEST['display_options_form'])) {
1710 // we know that the checkbox was unchecked
1711 unset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary']);
1712 } else {
1713 // selected by default because some operations like OPTIMIZE TABLE
1714 // and all queries involving functions return "binary" contents,
1715 // according to low-level field flags
1716 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary'] = true;
1719 if (isset($_REQUEST['display_binary_as_hex'])) {
1720 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex'] = true;
1721 unset($_REQUEST['display_binary_as_hex']);
1722 } elseif (isset($_REQUEST['display_options_form'])) {
1723 // we know that the checkbox was unchecked
1724 unset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex']);
1725 } else {
1726 // display_binary_as_hex config option
1727 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1728 $_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex'] = true;
1732 if (isset($_REQUEST['display_blob'])) {
1733 $_SESSION['tmp_user_values']['query'][$sql_key]['display_blob'] = true;
1734 unset($_REQUEST['display_blob']);
1735 } elseif (isset($_REQUEST['display_options_form'])) {
1736 // we know that the checkbox was unchecked
1737 unset($_SESSION['tmp_user_values']['query'][$sql_key]['display_blob']);
1740 if (isset($_REQUEST['hide_transformation'])) {
1741 $_SESSION['tmp_user_values']['query'][$sql_key]['hide_transformation'] = true;
1742 unset($_REQUEST['hide_transformation']);
1743 } elseif (isset($_REQUEST['display_options_form'])) {
1744 // we know that the checkbox was unchecked
1745 unset($_SESSION['tmp_user_values']['query'][$sql_key]['hide_transformation']);
1748 // move current query to the last position, to be removed last
1749 // so only least executed query will be removed if maximum remembered queries
1750 // limit is reached
1751 $tmp = $_SESSION['tmp_user_values']['query'][$sql_key];
1752 unset($_SESSION['tmp_user_values']['query'][$sql_key]);
1753 $_SESSION['tmp_user_values']['query'][$sql_key] = $tmp;
1755 // do not exceed a maximum number of queries to remember
1756 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1757 array_shift($_SESSION['tmp_user_values']['query']);
1758 //echo 'deleting one element ...';
1761 // populate query configuration
1762 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_key]['display_text'];
1763 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_key]['relational_display'];
1764 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary']) ? true : false;
1765 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['display_binary_as_hex']) ? true : false;
1766 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['display_blob']) ? true : false;
1767 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_key]['hide_transformation']) ? true : false;
1768 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_key]['pos'];
1769 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_key]['max_rows'];
1770 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_key]['repeat_cells'];
1771 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_key]['disp_direction'];
1774 * debugging
1775 echo '<pre>';
1776 var_dump($_SESSION['tmp_user_values']);
1777 echo '</pre>';
1782 * Displays a table of results returned by a SQL query.
1783 * This function is called by the "sql.php" script.
1785 * @param integer the link id associated to the query which results have
1786 * to be displayed
1787 * @param array the display mode
1788 * @param array the analyzed query
1790 * @uses $_SESSION['tmp_user_values']['pos']
1791 * @global string $db the database name
1792 * @global string $table the table name
1793 * @global string $goto the URL to go back in case of errors
1794 * @global string $sql_query the current SQL query
1795 * @global integer $num_rows the total number of rows returned by the
1796 * SQL query
1797 * @global integer $unlim_num_rows the total number of rows returned by the
1798 * SQL query without any programmatically
1799 * appended "LIMIT" clause
1800 * @global array $fields_meta the list of fields properties
1801 * @global integer $fields_cnt the total number of fields returned by
1802 * the SQL query
1803 * @global array $vertical_display informations used with vertical display
1804 * mode
1805 * @global array $highlight_columns column names to highlight
1806 * @global array $cfgRelation the relation settings
1808 * @access private
1810 * @see PMA_showMessage(), PMA_setDisplayMode(),
1811 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1812 * PMA_displayTableBody(), PMA_displayResultsOperations()
1814 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1816 global $db, $table, $goto;
1817 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1818 global $vertical_display, $highlight_columns;
1819 global $cfgRelation;
1820 global $showtable;
1822 // why was this called here? (already called from sql.php)
1823 //PMA_displayTable_checkConfigParams();
1826 * @todo move this to a central place
1827 * @todo for other future table types
1829 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1831 if ($is_innodb
1832 && ! isset($analyzed_sql[0]['queryflags']['union'])
1833 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1834 && (empty($analyzed_sql[0]['where_clause'])
1835 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1836 // "j u s t b r o w s i n g"
1837 $pre_count = '~';
1838 $after_count = PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount']), true);
1839 } else {
1840 $pre_count = '';
1841 $after_count = '';
1844 // 1. ----- Prepares the work -----
1846 // 1.1 Gets the informations about which functionalities should be
1847 // displayed
1848 $total = '';
1849 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1851 // 1.2 Defines offsets for the next and previous pages
1852 if ($is_display['nav_bar'] == '1') {
1853 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1854 $pos_next = 0;
1855 $pos_prev = 0;
1856 } else {
1857 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
1858 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1859 if ($pos_prev < 0) {
1860 $pos_prev = 0;
1863 } // end if
1865 // 1.3 Find the sort expression
1867 // we need $sort_expression and $sort_expression_nodirection
1868 // even if there are many table references
1869 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1870 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1872 * Get rid of ASC|DESC
1874 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1875 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1876 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1877 unset($matches);
1878 } else {
1879 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1882 // 1.4 Prepares display of first and last value of the sorted column
1884 if (! empty($sort_expression_nodirection)) {
1885 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1886 $sort_table = PMA_unQuote($sort_table);
1887 $sort_column = PMA_unQuote($sort_column);
1888 // find the sorted column index in row result
1889 // (this might be a multi-table query)
1890 $sorted_column_index = false;
1891 foreach($fields_meta as $key => $meta) {
1892 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1893 $sorted_column_index = $key;
1894 break;
1897 if ($sorted_column_index !== false) {
1898 // fetch first row of the result set
1899 $row = PMA_DBI_fetch_row($dt_result);
1900 $column_for_first_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1901 // fetch last row of the result set
1902 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1903 $row = PMA_DBI_fetch_row($dt_result);
1904 $column_for_last_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1905 // reset to first row for the loop in PMA_displayTableBody()
1906 PMA_DBI_data_seek($dt_result, 0);
1907 // we could also use here $sort_expression_nodirection
1908 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1909 unset($row, $column_for_first_row, $column_for_last_row);
1911 unset($sorted_column_index, $sort_table, $sort_column);
1914 // 2. ----- Displays the top of the page -----
1916 // 2.1 Displays a messages with position informations
1917 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1918 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1919 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1920 } else {
1921 $selectstring = '';
1923 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
1924 ? $total - 1
1925 : $pos_next - 1;
1927 if (PMA_Table::isView($db, $table)
1928 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1929 $message = PMA_Message::notice('strViewHasAtLeast');
1930 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1931 $message->addParam('[/a]');
1932 $message_view_warning = PMA_showHint($message);
1933 } else {
1934 $message_view_warning = false;
1937 $message = PMA_Message::success('strShowingRecords');
1938 $message->addMessage($_SESSION['tmp_user_values']['pos']);
1939 if ($message_view_warning) {
1940 $message->addMessage('...', ' - ');
1941 $message->addMessage($message_view_warning);
1942 $message->addMessage('(');
1943 } else {
1944 $message->addMessage($last_shown_rec, ' - ');
1945 $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
1946 $message->addString('strTotal');
1947 $message->addMessage($selectstring, '');
1948 $message->addMessage(', ', '');
1951 $messagge_qt = PMA_Message::notice('strQueryTime');
1952 $messagge_qt->addParam($GLOBALS['querytime']);
1954 $message->addMessage($messagge_qt, '');
1955 $message->addMessage(')', '');
1957 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
1959 PMA_showMessage($message, $sql_query, 'success');
1961 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1962 PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
1965 // 2.3 Displays the navigation bars
1966 if (! strlen($table)) {
1967 if (isset($analyzed_sql[0]['query_type'])
1968 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1969 // table does not always contain a real table name,
1970 // for example in MySQL 5.0.x, the query SHOW STATUS
1971 // returns STATUS as a table name
1972 $table = $fields_meta[0]->table;
1973 } else {
1974 $table = '';
1978 if ($is_display['nav_bar'] == '1') {
1979 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
1980 echo "\n";
1981 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1982 echo "\n" . '<br /><br />' . "\n";
1985 // 2b ----- Get field references from Database -----
1986 // (see the 'relation' configuration variable)
1987 // loic1, 2002-03-02: extended to php3
1989 // initialize map
1990 $map = array();
1992 // find tables
1993 $target=array();
1994 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1995 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1996 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1999 $tabs = '(\'' . join('\',\'', $target) . '\')';
2001 if ($cfgRelation['displaywork']) {
2002 if (! strlen($table)) {
2003 $exist_rel = false;
2004 } else {
2005 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2006 if ($exist_rel) {
2007 foreach ($exist_rel AS $master_field => $rel) {
2008 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2009 $map[$master_field] = array($rel['foreign_table'],
2010 $rel['foreign_field'],
2011 $display_field,
2012 $rel['foreign_db']);
2013 } // end while
2014 } // end if
2015 } // end if
2016 } // end if
2017 // end 2b
2019 // 3. ----- Displays the results table -----
2020 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2021 $url_query = '';
2022 echo '<tbody>' . "\n";
2023 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2024 // vertical output case
2025 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2026 PMA_displayVerticalTable();
2027 } // end if
2028 unset($vertical_display);
2029 echo '</tbody>' . "\n";
2031 </table>
2033 <?php
2034 // 4. ----- Displays the link for multi-fields edit and delete
2036 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2038 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
2040 $_url_params = array(
2041 'db' => $db,
2042 'table' => $table,
2043 'sql_query' => $sql_query,
2044 'goto' => $goto,
2046 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2048 $_url_params['checkall'] = '1';
2049 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2051 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2052 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2053 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2054 } else {
2055 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2056 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2058 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
2059 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
2060 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2061 echo '<img class="selectallarrow" width="38" height="22"'
2062 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2063 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
2065 echo $checkall_link . "\n"
2066 .' / ' . "\n"
2067 .$uncheckall_link . "\n"
2068 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
2070 PMA_buttonOrImage('submit_mult', 'mult_submit',
2071 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
2072 PMA_buttonOrImage('submit_mult', 'mult_submit',
2073 'submit_mult_delete', $delete_text, 'b_drop.png');
2074 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
2075 PMA_buttonOrImage('submit_mult', 'mult_submit',
2076 'submit_mult_export', $GLOBALS['strExport'],
2077 'b_tblexport.png');
2079 echo "\n";
2081 echo '<input type="hidden" name="sql_query"'
2082 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2083 echo '<input type="hidden" name="url_query"'
2084 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2086 echo '<input type="hidden" name="clause_is_unique"'
2087 .' value="' . $clause_is_unique . '" />' . "\n";
2089 echo '</form>' . "\n";
2092 // 5. ----- Displays the navigation bar at the bottom if required -----
2094 if ($is_display['nav_bar'] == '1') {
2095 echo '<br />' . "\n";
2096 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2097 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2098 echo "\n" . '<br /><br />' . "\n";
2101 // 6. ----- Displays "Query results operations"
2102 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2103 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2105 } // end of the 'PMA_displayTable()' function
2107 function default_function($buffer) {
2108 $buffer = htmlspecialchars($buffer);
2109 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2110 str_replace(' ', ' &nbsp;', $buffer));
2111 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2113 return $buffer;
2117 * Displays operations that are available on results.
2119 * @param array the display mode
2120 * @param array the analyzed query
2122 * @uses $_SESSION['tmp_user_values']['pos']
2123 * @uses $_SESSION['tmp_user_values']['display_text']
2124 * @global string $db the database name
2125 * @global string $table the table name
2126 * @global string $sql_query the current SQL query
2127 * @global integer $unlim_num_rows the total number of rows returned by the
2128 * SQL query without any programmatically
2129 * appended "LIMIT" clause
2131 * @access private
2133 * @see PMA_showMessage(), PMA_setDisplayMode(),
2134 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2135 * PMA_displayTableBody(), PMA_displayResultsOperations()
2137 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2138 global $db, $table, $sql_query, $unlim_num_rows;
2140 $header_shown = FALSE;
2141 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
2143 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2144 // Displays "printable view" link if required
2145 if ($the_disp_mode[9] == '1') {
2147 if (!$header_shown) {
2148 echo $header;
2149 $header_shown = TRUE;
2152 $_url_params = array(
2153 'db' => $db,
2154 'table' => $table,
2155 'printview' => '1',
2156 'sql_query' => $sql_query,
2158 $url_query = PMA_generate_common_url($_url_params);
2160 echo PMA_linkOrButton(
2161 'sql.php' . $url_query,
2162 PMA_getIcon('b_print.png', $GLOBALS['strPrintView'], false, true),
2163 '', true, true, 'print_view') . "\n";
2165 if ($_SESSION['tmp_user_values']['display_text']) {
2166 $_url_params['display_text'] = 'F';
2167 echo PMA_linkOrButton(
2168 'sql.php' . PMA_generate_common_url($_url_params),
2169 PMA_getIcon('b_print.png', $GLOBALS['strPrintViewFull'], false, true),
2170 '', true, true, 'print_view') . "\n";
2171 unset($_url_params['display_text']);
2173 } // end displays "printable view"
2176 // Export link
2177 // (the url_query has extra parameters that won't be used to export)
2178 // (the single_table parameter is used in display_export.lib.php
2179 // to hide the SQL and the structure export dialogs)
2180 // If the parser found a PROCEDURE clause
2181 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2182 // display the Export link).
2183 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2184 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2185 $_url_params['single_table'] = 'true';
2187 if (!$header_shown) {
2188 echo $header;
2189 $header_shown = TRUE;
2191 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2194 * At this point we don't know the table name; this can happen
2195 * for example with a query like
2196 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2197 * As a workaround we set in the table parameter the name of the
2198 * first table of this database, so that tbl_export.php and
2199 * the script it calls do not fail
2201 if (empty($_url_params['table'])) {
2202 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2205 echo PMA_linkOrButton(
2206 'tbl_export.php' . PMA_generate_common_url($_url_params),
2207 PMA_getIcon('b_tblexport.png', $GLOBALS['strExport'], false, true),
2208 '', true, true, '') . "\n";
2211 // CREATE VIEW
2214 * @todo detect privileges to create a view
2215 * (but see 2006-01-19 note in display_create_table.lib.php,
2216 * I think we cannot detect db-specific privileges reliably)
2217 * Note: we don't display a Create view link if we found a PROCEDURE clause
2219 if (!$header_shown) {
2220 echo $header;
2221 $header_shown = TRUE;
2223 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2224 echo PMA_linkOrButton(
2225 'view_create.php' . $url_query,
2226 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2227 '', true, true, '') . "\n";
2229 if ($header_shown) {
2230 echo '</fieldset><br />';
2235 * Verifies what to do with non-printable contents (binary or BLOB)
2236 * in Browse mode.
2238 * @uses is_null()
2239 * @uses isset()
2240 * @uses strlen()
2241 * @uses PMA_formatByteDown()
2242 * @uses strpos()
2243 * @uses str_replace()
2244 * @param string $category BLOB|BINARY
2245 * @param string $content the binary content
2246 * @param string $transform_function
2247 * @param string $transform_options
2248 * @param string $default_function
2249 * @param object $meta the meta-information about this field
2250 * @return mixed string or float
2252 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta) {
2253 $result = '[' . $category;
2254 if (is_null($content)) {
2255 $result .= ' - NULL';
2256 $size = 0;
2257 } elseif (isset($content)) {
2258 $size = strlen($content);
2259 $display_size = PMA_formatByteDown($size, 3, 1);
2260 $result .= ' - '. $display_size[0] . $display_size[1];
2262 $result .= ']';
2264 if (strpos($transform_function, 'octetstream')) {
2265 $result = $content;
2267 if ($size > 0) {
2268 if ($default_function != $transform_function) {
2269 $result = $transform_function($result, $transform_options, $meta);
2270 } else {
2271 $result = $default_function($result, array(), $meta);
2272 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2273 // in this case, restart from the original $content
2274 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2278 return($result);
2282 * Prepares the displayable content of a data cell in Browse mode,
2283 * taking into account foreign key description field and transformations
2285 * @uses is_array()
2286 * @uses PMA_backquote()
2287 * @uses PMA_DBI_try_query()
2288 * @uses PMA_DBI_num_rows()
2289 * @uses PMA_DBI_fetch_row()
2290 * @uses $GLOBALS['strLinkNotFound']
2291 * @uses PMA_DBI_free_result()
2292 * @uses $GLOBALS['printview']
2293 * @uses htmlspecialchars()
2294 * @uses PMA_generate_common_url()
2295 * @param string $mouse_events
2296 * @param string $class
2297 * @param string $condition_field
2298 * @param string $analyzed_sql
2299 * @param object $meta the meta-information about this field
2300 * @param string $map
2301 * @param string $data
2302 * @param string $transform_function
2303 * @param string $default_function
2304 * @param string $nowrap
2305 * @param string $where_comparison
2306 * @return string formatted data
2308 function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options) {
2310 // continue the <td> tag started before calling this function:
2311 $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . '">';
2313 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2314 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2315 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2316 if (isset($alias) && strlen($alias)) {
2317 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2318 if ($alias == $meta->name) {
2319 // this change in the parameter does not matter
2320 // outside of the function
2321 $meta->name = $true_column;
2322 } // end if
2323 } // end if
2324 } // end foreach
2325 } // end if
2327 if (isset($map[$meta->name])) {
2328 // Field to display from the foreign table?
2329 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2330 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2331 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2332 . '.' . PMA_backquote($map[$meta->name][0])
2333 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2334 . $where_comparison;
2335 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2336 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2337 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2338 } else {
2339 $dispval = $GLOBALS['strLinkNotFound'];
2341 @PMA_DBI_free_result($dispresult);
2342 } else {
2343 $dispval = '';
2344 } // end if... else...
2346 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2347 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2348 } else {
2350 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2351 // user chose "relational key" in the display options, so
2352 // the title contains the display field
2353 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2354 } else {
2355 $title = ' title="' . htmlspecialchars($data) . '"';
2358 $_url_params = array(
2359 'db' => $map[$meta->name][3],
2360 'table' => $map[$meta->name][0],
2361 'pos' => '0',
2362 'sql_query' => 'SELECT * FROM '
2363 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2364 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2365 . $where_comparison,
2367 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2368 . '"' . $title . '>';
2370 if ($transform_function != $default_function) {
2371 // always apply a transformation on the real data,
2372 // not on the display field
2373 $result .= $transform_function($data, $transform_options, $meta);
2374 } else {
2375 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2376 // user chose "relational display field" in the
2377 // display options, so show display field in the cell
2378 $result .= $transform_function($dispval, array(), $meta);
2379 } else {
2380 // otherwise display data in the cell
2381 $result .= $transform_function($data, array(), $meta);
2384 $result .= '</a>';
2386 } else {
2387 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2389 $result .= '</td>' . "\n";
2391 return $result;