bug #3313210 [interface] Columns class sometimes changed for nothing
[phpmyadmin/ammaryasirr.git] / libraries / display_tbl.lib.php
blobc5b46fbc45a2ee277d90c933a5a68b6ea61e069b
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 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/Index.class.php';
14 /**
15 * Defines the display mode to use for the results of a SQL query
17 * It uses a synthetic string that contains all the required informations.
18 * In this string:
19 * - the first two characters stand for the action to do while
20 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
21 * edit link...);
22 * - the next two characters stand for the action to do while
23 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
24 * no delete link...);
25 * - the next characters are boolean values (1/0) and respectively stand
26 * for sorting links, navigation bar, "insert a new row" link, the
27 * bookmark feature, the expand/collapse text/blob fields button and
28 * the "display printable view" option.
29 * Of course '0'/'1' means the feature won't/will be enabled.
31 * @param string the synthetic value for display_mode (see a few
32 * lines above for explanations)
33 * @param integer the total number of rows returned by the SQL query
34 * without any programmatically appended "LIMIT" clause
35 * (just a copy of $unlim_num_rows if it exists, else
36 * computed inside this function)
38 * @return array an array with explicit indexes for all the display
39 * elements
41 * @global string the database name
42 * @global string the table name
43 * @global integer the total number of rows returned by the SQL query
44 * without any programmatically appended "LIMIT" clause
45 * @global array the properties of the fields returned by the query
46 * @global string the URL to return to in case of error in a SQL
47 * statement
49 * @access private
51 * @see PMA_displayTable()
53 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
55 global $db, $table;
56 global $unlim_num_rows, $fields_meta;
57 global $err_url;
59 // 1. Initializes the $do_display array
60 $do_display = array();
61 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
62 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
63 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
64 $do_display['nav_bar'] = (string) $the_disp_mode[5];
65 $do_display['ins_row'] = (string) $the_disp_mode[6];
66 $do_display['bkm_form'] = (string) $the_disp_mode[7];
67 $do_display['text_btn'] = (string) $the_disp_mode[8];
68 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
70 // 2. Display mode is not "false for all elements" -> updates the
71 // display mode
72 if ($the_disp_mode != 'nnnn000000') {
73 // 2.0 Print view -> set all elements to false!
74 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
75 $do_display['edit_lnk'] = 'nn'; // no edit link
76 $do_display['del_lnk'] = 'nn'; // no delete link
77 $do_display['sort_lnk'] = (string) '0';
78 $do_display['nav_bar'] = (string) '0';
79 $do_display['ins_row'] = (string) '0';
80 $do_display['bkm_form'] = (string) '0';
81 $do_display['text_btn'] = (string) '0';
82 $do_display['pview_lnk'] = (string) '0';
84 // 2.1 Statement is a "SELECT COUNT", a
85 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
86 // contains a "PROC ANALYSE" part
87 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
88 $do_display['edit_lnk'] = 'nn'; // no edit link
89 $do_display['del_lnk'] = 'nn'; // no delete link
90 $do_display['sort_lnk'] = (string) '0';
91 $do_display['nav_bar'] = (string) '0';
92 $do_display['ins_row'] = (string) '0';
93 $do_display['bkm_form'] = (string) '1';
94 if ($GLOBALS['is_maint']) {
95 $do_display['text_btn'] = (string) '1';
96 } else {
97 $do_display['text_btn'] = (string) '0';
99 $do_display['pview_lnk'] = (string) '1';
101 // 2.2 Statement is a "SHOW..."
102 elseif ($GLOBALS['is_show']) {
104 * 2.2.1
105 * @todo defines edit/delete links depending on show statement
107 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
108 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
109 $do_display['edit_lnk'] = 'nn'; // no edit link
110 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
111 } else {
112 // Default case -> no links
113 $do_display['edit_lnk'] = 'nn'; // no edit link
114 $do_display['del_lnk'] = 'nn'; // no delete link
116 // 2.2.2 Other settings
117 $do_display['sort_lnk'] = (string) '0';
118 $do_display['nav_bar'] = (string) '0';
119 $do_display['ins_row'] = (string) '0';
120 $do_display['bkm_form'] = (string) '1';
121 $do_display['text_btn'] = (string) '1';
122 $do_display['pview_lnk'] = (string) '1';
124 // 2.3 Other statements (ie "SELECT" ones) -> updates
125 // $do_display['edit_lnk'], $do_display['del_lnk'] and
126 // $do_display['text_btn'] (keeps other default values)
127 else {
128 $prev_table = $fields_meta[0]->table;
129 $do_display['text_btn'] = (string) '1';
130 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
131 $is_link = ($do_display['edit_lnk'] != 'nn'
132 || $do_display['del_lnk'] != 'nn'
133 || $do_display['sort_lnk'] != '0'
134 || $do_display['ins_row'] != '0');
135 // 2.3.2 Displays edit/delete/sort/insert links?
136 if ($is_link
137 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
138 $do_display['edit_lnk'] = 'nn'; // don't display links
139 $do_display['del_lnk'] = 'nn';
141 * @todo May be problematic with same fields names in two joined table.
143 // $do_display['sort_lnk'] = (string) '0';
144 $do_display['ins_row'] = (string) '0';
145 if ($do_display['text_btn'] == '1') {
146 break;
148 } // end if (2.3.2)
149 // 2.3.3 Always display print view link
150 $do_display['pview_lnk'] = (string) '1';
151 $prev_table = $fields_meta[$i]->table;
152 } // end for
153 } // end if..elseif...else (2.1 -> 2.3)
154 } // end if (2)
156 // 3. Gets the total number of rows if it is unknown
157 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
158 $the_total = $unlim_num_rows;
159 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
160 && (strlen($db) && !empty($table))) {
161 $the_total = PMA_Table::countRecords($db, $table);
164 // 4. If navigation bar or sorting fields names URLs should be
165 // displayed but there is only one row, change these settings to
166 // false
167 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
169 // - Do not display sort links if less than 2 rows.
170 // - For a VIEW we (probably) did not count the number of rows
171 // so don't test this number here, it would remove the possibility
172 // of sorting VIEW results.
173 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
174 // force display of navbar for vertical/horizontal display-choice.
175 // $do_display['nav_bar'] = (string) '0';
176 $do_display['sort_lnk'] = (string) '0';
178 } // end if (3)
180 // 5. Updates the synthetic var
181 $the_disp_mode = join('', $do_display);
183 return $do_display;
184 } // end of the 'PMA_setDisplayMode()' function
188 * Displays a navigation button
190 * @uses $GLOBALS['cfg']['NavigationBarIconic']
191 * @uses PMA_generate_common_hidden_inputs()
193 * @param string iconic caption for button
194 * @param string text for button
195 * @param integer position for next query
196 * @param string query ready for display
197 * @param string optional onsubmit clause
198 * @param string optional hidden field for special treatment
199 * @param string optional onclick clause
201 * @global string $db the database name
202 * @global string $table the table name
203 * @global string $goto the URL to go back in case of errors
205 * @access private
207 * @see PMA_displayTableNavigation()
209 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '') {
211 global $db, $table, $goto;
213 $caption_output = '';
214 // for true or 'both'
215 if ($GLOBALS['cfg']['NavigationBarIconic']) {
216 $caption_output .= $caption;
218 // for false or 'both'
219 if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
220 $caption_output .= '&nbsp;' . $title;
222 $title_output = ' title="' . $title . '"';
224 <td>
225 <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
226 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
227 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
228 <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
229 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
230 <?php echo $input_for_real_end; ?>
231 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax" ' : '' ); ?> value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
232 </form>
233 </td>
234 <?php
235 } // end function PMA_displayTableNavigationOneButton()
238 * Displays a navigation bar to browse among the results of a SQL query
240 * @uses $_SESSION['tmp_user_values']['disp_direction']
241 * @uses $_SESSION['tmp_user_values']['repeat_cells']
242 * @uses $_SESSION['tmp_user_values']['max_rows']
243 * @uses $_SESSION['tmp_user_values']['pos']
244 * @param integer the offset for the "next" page
245 * @param integer the offset for the "previous" page
246 * @param string the URL-encoded query
247 * @param string the id for the direction dropdown
249 * @global string $db the database name
250 * @global string $table the table name
251 * @global string $goto the URL to go back in case of errors
252 * @global integer $num_rows the total number of rows returned by the
253 * SQL query
254 * @global integer $unlim_num_rows the total number of rows returned by the
255 * SQL any programmatically appended "LIMIT" clause
256 * @global boolean $is_innodb whether its InnoDB or not
257 * @global array $showtable table definitions
259 * @access private
261 * @see PMA_displayTable()
263 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
265 global $db, $table, $goto;
266 global $num_rows, $unlim_num_rows;
267 global $is_innodb;
268 global $showtable;
270 // here, using htmlentities() would cause problems if the query
271 // contains accented characters
272 $html_sql_query = htmlspecialchars($sql_query);
275 * @todo move this to a central place
276 * @todo for other future table types
278 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
282 <!-- Navigation bar -->
283 <table border="0" cellpadding="2" cellspacing="0" class="navigation">
284 <tr>
285 <?php
286 // Move to the beginning or to the previous page
287 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
288 PMA_displayTableNavigationOneButton('&lt;&lt;', __('Begin'), 0, $html_sql_query);
289 PMA_displayTableNavigationOneButton('&lt;', __('Previous'), $pos_prev, $html_sql_query);
291 } // end move back
293 //page redirection
294 // (unless we are showing all records)
295 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
296 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
297 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
299 if ($nbTotalPage > 1){ //if2
301 <td>
302 <?php
303 $_url_params = array(
304 'db' => $db,
305 'table' => $table,
306 'sql_query' => $sql_query,
307 'goto' => $goto,
309 //<form> to keep the form alignment of button < and <<
310 // and also to know what to execute when the selector changes
311 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
312 echo PMA_pageselector(
313 $_SESSION['tmp_user_values']['max_rows'],
314 $pageNow,
315 $nbTotalPage,
316 200,
321 __('Page number:')
324 </form>
325 </td>
326 <?php
327 } //_if2
328 } //_if1
330 // Display the "Show all" button if allowed
331 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
332 echo "\n";
334 <td>
335 <form action="sql.php" method="post">
336 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
337 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
338 <input type="hidden" name="pos" value="0" />
339 <input type="hidden" name="session_max_rows" value="all" />
340 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
341 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
342 </form>
343 </td>
344 <?php
345 } // end show all
347 // Move to the next page or to the last one
348 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
349 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
351 // display the Next button
352 PMA_displayTableNavigationOneButton('&gt;',
353 __('Next'),
354 $pos_next,
355 $html_sql_query);
357 // prepare some options for the End button
358 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
359 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
360 // no backquote around this message
361 $onclick = '';
362 } else {
363 $input_for_real_end = $onclick = '';
366 // display the End button
367 PMA_displayTableNavigationOneButton('&gt;&gt;',
368 __('End'),
369 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
370 $html_sql_query,
371 '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') . '"',
372 $input_for_real_end,
373 $onclick
375 } // end move toward
377 </tr>
378 </table>
380 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
381 // of $cfg['MaxExactCountViews']; in this case, avoid passing
382 // the 5th parameter to checkFormElementInRange()
383 // (this means we can't validate the upper limit ?>
384 <div>
385 <form action="sql.php" method="post"
386 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
387 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
388 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
389 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
390 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
391 <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()" />
392 <?php echo __('row(s) starting from row #') . "\n"; ?>
393 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
394 <?php
395 // Display mode (horizontal/vertical and repeat headers)
396 $choices = array(
397 'horizontal' => __('horizontal'),
398 'horizontalflipped' => __('horizontal (rotated headers)'),
399 'vertical' => __('vertical'));
400 $param1 = PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
401 unset($choices);
403 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />' . "\n"
404 . ' ';
405 echo ' ' . sprintf(__('in %s mode and repeat headers after %s cells'), "\n" . $param1, "\n" . $param2) . "\n";
407 </form>
408 </div>
409 <?php
410 } // end of the 'PMA_displayTableNavigation()' function
414 * Displays the headers of the results table
416 * @uses $_SESSION['tmp_user_values']['disp_direction']
417 * @uses $_SESSION['tmp_user_values']['repeat_cells']
418 * @uses $_SESSION['tmp_user_values']['max_rows']
419 * @uses $_SESSION['tmp_user_values']['display_text']
420 * @uses $_SESSION['tmp_user_values']['display_binary']
421 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
422 * @param array which elements to display
423 * @param array the list of fields properties
424 * @param integer the total number of fields returned by the SQL query
425 * @param array the analyzed query
427 * @return boolean $clause_is_unique
429 * @global string $db the database name
430 * @global string $table the table name
431 * @global string $goto the URL to go back in case of errors
432 * @global string $sql_query the SQL query
433 * @global integer $num_rows the total number of rows returned by the
434 * SQL query
435 * @global array $vertical_display informations used with vertical display
436 * mode
438 * @access private
440 * @see PMA_displayTable()
442 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
444 global $db, $table, $goto;
445 global $sql_query, $num_rows;
446 global $vertical_display, $highlight_columns;
448 // required to generate sort links that will remember whether the
449 // "Show all" button has been clicked
450 $sql_md5 = md5($GLOBALS['sql_query']);
451 $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
453 if ($analyzed_sql == '') {
454 $analyzed_sql = array();
457 // can the result be sorted?
458 if ($is_display['sort_lnk'] == '1') {
460 // Just as fallback
461 $unsorted_sql_query = $sql_query;
462 if (isset($analyzed_sql[0]['unsorted_query'])) {
463 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
465 // Handles the case of multiple clicks on a column's header
466 // which would add many spaces before "ORDER BY" in the
467 // generated query.
468 $unsorted_sql_query = trim($unsorted_sql_query);
470 // sorting by indexes, only if it makes sense (only one table ref)
471 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
472 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
473 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
475 // grab indexes data:
476 $indexes = PMA_Index::getFromTable($table, $db);
478 // do we have any index?
479 if ($indexes) {
481 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
482 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
483 $span = $fields_cnt;
484 if ($is_display['edit_lnk'] != 'nn') {
485 $span++;
487 if ($is_display['del_lnk'] != 'nn') {
488 $span++;
490 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
491 $span++;
493 } else {
494 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
497 echo '<form action="sql.php" method="post">' . "\n";
498 echo PMA_generate_common_hidden_inputs($db, $table);
499 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
500 $used_index = false;
501 $local_order = (isset($sort_expression) ? $sort_expression : '');
502 foreach ($indexes as $index) {
503 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
504 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
505 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
506 echo '<option value="'
507 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
508 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
509 . '>' . htmlspecialchars($index->getName()) . ' ('
510 . __('Ascending') . ')</option>';
511 echo '<option value="'
512 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
513 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
514 . '>' . htmlspecialchars($index->getName()) . ' ('
515 . __('Descending') . ')</option>';
517 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
518 echo '</select>' . "\n";
519 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
520 echo '</form>' . "\n";
526 $vertical_display['emptypre'] = 0;
527 $vertical_display['emptyafter'] = 0;
528 $vertical_display['textbtn'] = '';
530 // Display options (if we are not in print view)
531 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
532 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
533 if ($GLOBALS['cfg']['AjaxEnable']) {
534 echo ' class="ajax" ';
536 echo '>';
537 $url_params = array(
538 'db' => $db,
539 'table' => $table,
540 'sql_query' => $sql_query,
541 'goto' => $goto,
542 'display_options_form' => 1
544 echo PMA_generate_common_hidden_inputs($url_params);
545 echo '<br />';
546 PMA_generate_slider_effect('displayoptions',__('Options'));
547 echo '<fieldset>';
549 echo '<div class="formelement">';
550 $choices = array(
551 'P' => __('Partial texts'),
552 'F' => __('Full texts')
554 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
555 echo '</div>';
557 // prepare full/partial text button or link
558 if ($_SESSION['tmp_user_values']['display_text']=='F') {
559 // currently in fulltext mode so show the opposite link
560 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
561 $tmp_txt = __('Partial texts');
562 $url_params['display_text'] = 'P';
563 } else {
564 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
565 $tmp_txt = __('Full texts');
566 $url_params['display_text'] = 'F';
569 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
570 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
571 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
572 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
575 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
576 echo '<div class="formelement">';
577 $choices = array(
578 'K' => __('Relational key'),
579 'D' => __('Relational display column')
581 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
582 echo '</div>';
585 echo '<div class="formelement">';
586 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
587 echo '<br />';
588 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
589 echo '<br />';
590 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
591 echo '</div>';
593 // I would have preferred to name this "display_transformation".
594 // This is the only way I found to be able to keep this setting sticky
595 // per SQL query, and at the same time have a default that displays
596 // the transformations.
597 echo '<div class="formelement">';
598 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
599 echo '</div>';
601 echo '<div class="clearfloat"></div>';
602 echo '</fieldset>';
604 echo '<fieldset class="tblFooters">';
605 echo '<input type="submit" value="' . __('Go') . '" />';
606 echo '</fieldset>';
607 echo '</div>';
608 echo '</form>';
611 // Start of form for multi-rows edit/delete/export
613 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
614 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
615 echo PMA_generate_common_hidden_inputs($db, $table, 1);
616 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
619 echo '<table id="table_results" class="data';
620 if ($GLOBALS['cfg']['AjaxEnable']) {
621 echo ' ajax';
623 echo '">' . "\n";
624 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
625 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
626 echo '<thead><tr>' . "\n";
629 // 1. Displays the full/partial text button (part 1)...
630 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
631 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
632 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
633 ? ' colspan="4"'
634 : '';
635 } else {
636 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
637 ? ' rowspan="4"'
638 : '';
641 // ... before the result table
642 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
643 && $is_display['text_btn'] == '1') {
644 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
645 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
646 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
648 <th colspan="<?php echo $fields_cnt; ?>"></th>
649 </tr>
650 <tr>
651 <?php
652 } // end horizontal/horizontalflipped mode
653 else {
655 <tr>
656 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
657 </tr>
658 <?php
659 } // end vertical mode
662 // ... at the left column of the result table header if possible
663 // and required
664 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
665 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
666 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
667 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
669 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
670 <?php
671 } // end horizontal/horizontalflipped mode
672 else {
673 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
674 . ' ' . "\n"
675 . ' </th>' . "\n";
676 } // end vertical mode
679 // ... elseif no button, displays empty(ies) col(s) if required
680 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
681 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
682 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
683 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
684 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
686 <td<?php echo $colspan; ?>></td>
687 <?php
688 } // end horizontal/horizontalfipped mode
689 else {
690 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
691 } // end vertical mode
694 // 2. Displays the fields' name
695 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
696 // statement (see 2.1.3)
698 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
699 // Do not show comments, if using horizontalflipped mode, because of space usage
700 if ($GLOBALS['cfg']['ShowBrowseComments']
701 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
702 $comments_map = array();
703 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
704 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
705 $tb = $tbl['table_true_name'];
706 $comments_map[$tb] = PMA_getComments($db, $tb);
707 unset($tb);
712 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
713 require_once './libraries/transformations.lib.php';
714 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
717 // See if we have to highlight any header fields of a WHERE query.
718 // Uses SQL-Parser results.
719 $highlight_columns = array();
720 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
721 isset($analyzed_sql[0]['where_clause_identifiers'])) {
723 $wi = 0;
724 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
725 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
726 $highlight_columns[$wci] = 'true';
731 for ($i = 0; $i < $fields_cnt; $i++) {
732 // See if this column should get highlight because it's used in the
733 // where-query.
734 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
735 $condition_field = true;
736 } else {
737 $condition_field = false;
740 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
741 if (isset($comments_map) &&
742 isset($comments_map[$fields_meta[$i]->table]) &&
743 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
744 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
745 } else {
746 $comments = '';
749 // 2.1 Results can be sorted
750 if ($is_display['sort_lnk'] == '1') {
752 // 2.1.1 Checks if the table name is required; it's the case
753 // for a query with a "JOIN" statement and if the column
754 // isn't aliased, or in queries like
755 // SELECT `1`.`master_field` , `2`.`master_field`
756 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
758 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
759 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
760 } else {
761 $sort_tbl = '';
764 // 2.1.2 Checks if the current column is used to sort the
765 // results
766 // the orgname member does not exist for all MySQL versions
767 // but if found, it's the one on which to sort
768 $name_to_use_in_sort = $fields_meta[$i]->name;
769 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
770 $name_to_use_in_sort = $fields_meta[$i]->orgname;
772 // $name_to_use_in_sort might contain a space due to
773 // formatting of function expressions like "COUNT(name )"
774 // so we remove the space in this situation
775 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
777 if (empty($sort_expression)) {
778 $is_in_sort = false;
779 } else {
780 // Field name may be preceded by a space, or any number
781 // of characters followed by a dot (tablename.fieldname)
782 // so do a direct comparison for the sort expression;
783 // this avoids problems with queries like
784 // "SELECT id, count(id)..." and clicking to sort
785 // on id or on count(id).
786 // Another query to test this:
787 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
788 // (and try clicking on each column's header twice)
789 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
790 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
792 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
794 // 2.1.3 Check the field name for a bracket.
795 // If it contains one, it's probably a function column
796 // like 'COUNT(`field`)'
797 if (strpos($name_to_use_in_sort, '(') !== false) {
798 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
799 } else {
800 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
802 unset($name_to_use_in_sort);
804 // 2.1.4 Do define the sorting URL
805 if (! $is_in_sort) {
806 // patch #455484 ("Smart" order)
807 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
808 if ($GLOBALS['cfg']['Order'] === 'SMART') {
809 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
810 } else {
811 $sort_order .= $GLOBALS['cfg']['Order'];
813 $order_img = '';
814 } elseif ('DESC' == $sort_direction) {
815 $sort_order .= ' ASC';
816 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
817 } else {
818 $sort_order .= ' DESC';
819 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
822 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
823 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
824 } else {
825 $sorted_sql_query = $unsorted_sql_query . $sort_order;
827 $_url_params = array(
828 'db' => $db,
829 'table' => $table,
830 'sql_query' => $sorted_sql_query,
831 'session_max_rows' => $session_max_rows
833 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
835 // 2.1.5 Displays the sorting URL
836 // enable sort order swapping for image
837 $order_link_params = array();
838 if (isset($order_img) && $order_img!='') {
839 if (strstr($order_img, 'asc')) {
840 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
841 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
842 } elseif (strstr($order_img, 'desc')) {
843 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
844 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
847 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
848 if (PMA_USR_BROWSER_AGENT == 'IE') {
849 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
850 } else {
851 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
854 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
855 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
856 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
858 $order_link_params['title'] = __('Sort');
859 $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));
860 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
862 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
863 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
864 echo '<th';
865 $th_class = array();
866 if ($condition_field) {
867 $th_class[] = 'condition';
869 $th_class[] = 'column_heading';
870 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
871 $th_class[] = 'pointer';
873 echo ' class="' . implode(' ', $th_class) . '"';
875 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
876 echo ' valign="bottom"';
878 echo '>' . $order_link . $comments . '</th>';
880 $vertical_display['desc'][] = ' <th '
881 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
882 . $order_link . $comments . ' </th>' . "\n";
883 } // end if (2.1)
885 // 2.2 Results can't be sorted
886 else {
887 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
888 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
889 echo '<th';
890 if ($condition_field) {
891 echo ' class="condition"';
893 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
894 echo ' valign="bottom"';
896 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
897 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
898 echo ' style="direction: ltr; writing-mode: tb-rl;"';
900 echo '>';
901 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
902 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
903 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
904 } else {
905 echo htmlspecialchars($fields_meta[$i]->name);
907 echo "\n" . $comments . '</th>';
909 $vertical_display['desc'][] = ' <th '
910 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
911 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
912 . $comments . ' </th>';
913 } // end else (2.2)
914 } // end for
916 // 3. Displays the needed checkboxes at the right
917 // column of the result table header if possible and required...
918 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
919 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
920 && $is_display['text_btn'] == '1') {
921 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
922 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
923 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
924 echo "\n";
926 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
927 </th>
928 <?php
929 } // end horizontal/horizontalflipped mode
930 else {
931 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
932 . ' ' . "\n"
933 . ' </th>' . "\n";
934 } // end vertical mode
937 // ... elseif no button, displays empty columns if required
938 // (unless coming from Browse mode print view)
939 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
940 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
941 && (!$GLOBALS['is_header_sent'])) {
942 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
943 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
944 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
945 echo "\n";
947 <td<?php echo $colspan; ?>></td>
948 <?php
949 } // end horizontal/horizontalflipped mode
950 else {
951 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
952 } // end vertical mode
955 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
956 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
958 </tr>
959 </thead>
960 <?php
963 return true;
964 } // end of the 'PMA_displayTableHeaders()' function
968 * Prepares the display for a value
970 * @param string $class
971 * @param string $condition_field
972 * @param string $value
974 * @return string the td
976 function PMA_buildValueDisplay($class, $condition_field, $value) {
977 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
981 * Prepares the display for a null value
983 * @param string $class
984 * @param string $condition_field
986 * @return string the td
988 function PMA_buildNullDisplay($class, $condition_field) {
989 // the null class is needed for inline editing
990 return '<td align="right"' . ' class="' . $class . ($condition_field ? ' condition' : '') . ' null"><i>NULL</i></td>';
994 * Prepares the display for an empty value
996 * @param string $class
997 * @param string $condition_field
998 * @param string $align
1000 * @return string the td
1002 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '') {
1003 $nowrap = ' nowrap';
1004 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1008 * Adds the relavant classes.
1010 * @param string $class
1011 * @param string $condition_field
1012 * @param object $meta the meta-information about this field
1013 * @param string $nowrap
1014 * @param bool $is_field_truncated
1015 * @param string $transform_function
1016 * @param string $default_function
1018 * @return string the list of classes
1020 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '') {
1021 // Define classes to be added to this data field based on the type of data
1022 $enum_class = '';
1023 if(strpos($meta->flags, 'enum') !== false) {
1024 $enum_class = ' enum';
1027 $set_class = '';
1028 if(strpos($meta->flags, 'set') !== false) {
1029 $set_class = ' set';
1032 $bit_class = '';
1033 if(strpos($meta->type, 'bit') !== false) {
1034 $bit_class = ' bit';
1037 $mime_type_class = '';
1038 if(isset($meta->mimetype)) {
1039 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
1042 $result = $class . ($condition_field ? ' condition' : '') . $nowrap
1043 . ' ' . ($is_field_truncated ? ' truncated' : '')
1044 . ($transform_function != $default_function ? ' transformed' : '')
1045 . $enum_class . $set_class . $bit_class . $mime_type_class;
1047 return $result;
1050 * Displays the body of the results table
1052 * @uses $_SESSION['tmp_user_values']['disp_direction']
1053 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1054 * @uses $_SESSION['tmp_user_values']['max_rows']
1055 * @uses $_SESSION['tmp_user_values']['display_text']
1056 * @uses $_SESSION['tmp_user_values']['display_binary']
1057 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1058 * @uses $_SESSION['tmp_user_values']['display_blob']
1059 * @param integer the link id associated to the query which results have
1060 * to be displayed
1061 * @param array which elements to display
1062 * @param array the list of relations
1063 * @param array the analyzed query
1065 * @return boolean always true
1067 * @global string $db the database name
1068 * @global string $table the table name
1069 * @global string $goto the URL to go back in case of errors
1070 * @global string $sql_query the SQL query
1071 * @global array $fields_meta the list of fields properties
1072 * @global integer $fields_cnt the total number of fields returned by
1073 * the SQL query
1074 * @global array $vertical_display informations used with vertical display
1075 * mode
1076 * @global array $highlight_columns column names to highlight
1077 * @global array $row current row data
1079 * @access private
1081 * @see PMA_displayTable()
1083 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1084 global $db, $table, $goto;
1085 global $sql_query, $fields_meta, $fields_cnt;
1086 global $vertical_display, $highlight_columns;
1087 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1089 $url_sql_query = $sql_query;
1091 // query without conditions to shorten URLs when needed, 200 is just
1092 // guess, it should depend on remaining URL length
1094 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1095 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1096 strlen($sql_query) > 200) {
1098 $url_sql_query = 'SELECT ';
1099 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1100 $url_sql_query .= ' DISTINCT ';
1102 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1103 if (!empty($analyzed_sql[0]['from_clause'])) {
1104 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1108 if (!is_array($map)) {
1109 $map = array();
1111 $row_no = 0;
1112 $vertical_display['edit'] = array();
1113 $vertical_display['copy'] = array();
1114 $vertical_display['delete'] = array();
1115 $vertical_display['data'] = array();
1116 $vertical_display['row_delete'] = array();
1117 // name of the class added to all inline editable elements
1118 $inline_edit_class = 'inline_edit';
1120 // Correction University of Virginia 19991216 in the while below
1121 // Previous code assumed that all tables have keys, specifically that
1122 // the phpMyAdmin GUI should support row delete/edit only for such
1123 // tables.
1124 // Although always using keys is arguably the prescribed way of
1125 // defining a relational table, it is not required. This will in
1126 // particular be violated by the novice.
1127 // We want to encourage phpMyAdmin usage by such novices. So the code
1128 // below has been changed to conditionally work as before when the
1129 // table being displayed has one or more keys; but to display
1130 // delete/edit options correctly for tables without keys.
1132 $odd_row = true;
1133 while ($row = PMA_DBI_fetch_row($dt_result)) {
1134 // "vertical display" mode stuff
1135 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1136 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1137 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1139 echo '<tr>' . "\n";
1140 if ($vertical_display['emptypre'] > 0) {
1141 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1142 .' &nbsp;</th>' . "\n";
1145 foreach ($vertical_display['desc'] as $val) {
1146 echo $val;
1149 if ($vertical_display['emptyafter'] > 0) {
1150 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1151 .' &nbsp;</th>' . "\n";
1153 echo '</tr>' . "\n";
1154 } // end if
1156 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1157 $odd_row = ! $odd_row;
1159 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1160 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1161 // pointer code part
1162 echo '<tr class="' . $alternating_color_class . '">';
1166 // 1. Prepares the row
1167 // 1.1 Results from a "SELECT" statement -> builds the
1168 // WHERE clause to use in links (a unique key if possible)
1170 * @todo $where_clause could be empty, for example a table
1171 * with only one field and it's a BLOB; in this case,
1172 * avoid to display the delete and edit links
1174 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1175 $where_clause_html = urlencode($where_clause);
1177 // 1.2 Defines the URLs for the modify/delete link(s)
1179 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1180 // We need to copy the value or else the == 'both' check will always return true
1182 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1183 $iconic_spacer = '<div class="nowrap">';
1184 } else {
1185 $iconic_spacer = '';
1188 // 1.2.1 Modify link(s)
1189 if ($is_display['edit_lnk'] == 'ur') { // update row case
1190 $_url_params = array(
1191 'db' => $db,
1192 'table' => $table,
1193 'where_clause' => $where_clause,
1194 'clause_is_unique' => $clause_is_unique,
1195 'sql_query' => $url_sql_query,
1196 'goto' => 'sql.php',
1198 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1199 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1201 $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
1202 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'), true);
1204 // Class definitions required for inline editing jQuery scripts
1205 $edit_anchor_class = "edit_row_anchor";
1206 if( $clause_is_unique == 0) {
1207 $edit_anchor_class .= ' nonunique';
1209 } // end if (1.2.1)
1211 // 1.2.2 Delete/Kill link(s)
1212 if ($is_display['del_lnk'] == 'dr') { // delete row case
1213 $_url_params = array(
1214 'db' => $db,
1215 'table' => $table,
1216 'sql_query' => $url_sql_query,
1217 'message_to_show' => __('The row has been deleted'),
1218 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1220 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1222 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1223 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1225 $_url_params = array(
1226 'db' => $db,
1227 'table' => $table,
1228 'sql_query' => $del_query,
1229 'message_to_show' => __('The row has been deleted'),
1230 'goto' => $lnk_goto,
1232 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1234 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1235 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1236 . ($clause_is_unique ? '' : ' LIMIT 1');
1237 $del_str = PMA_getIcon('b_drop.png', __('Delete'), true);
1238 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1240 $_url_params = array(
1241 'db' => $db,
1242 'table' => $table,
1243 'sql_query' => $url_sql_query,
1244 'goto' => 'main.php',
1246 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1248 $_url_params = array(
1249 'db' => 'mysql',
1250 'sql_query' => 'KILL ' . $row[0],
1251 'goto' => $lnk_goto,
1253 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1254 $del_query = 'KILL ' . $row[0];
1255 $js_conf = 'KILL ' . $row[0];
1256 $del_str = PMA_getIcon('b_drop.png', __('Kill'), true);
1257 } // end if (1.2.2)
1259 // 1.3 Displays the links at left if required
1260 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1261 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1262 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1263 if (! isset($js_conf)) {
1264 $js_conf = '';
1266 echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1267 } // end if (1.3)
1268 } // end if (1)
1270 // 2. Displays the rows' values
1271 for ($i = 0; $i < $fields_cnt; ++$i) {
1272 $meta = $fields_meta[$i];
1273 $not_null_class = $meta->not_null ? 'not_null' : '';
1274 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1275 $pointer = $i;
1276 $is_field_truncated = false;
1277 //If the previous column had blob data, we need to reset the class
1278 // to $inline_edit_class
1279 $class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $alternating_color_class . ' ' . $relation_class;
1281 // See if this column should get highlight because it's used in the
1282 // where-query.
1283 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1284 $condition_field = true;
1285 } else {
1286 $condition_field = false;
1289 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1290 // the row number corresponds to a data row, not HTML table row
1291 $class .= ' row_' . $row_no;
1292 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1293 $class .= ' vpointer';
1295 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1296 $class .= ' vmarker';
1298 }// end if
1300 // Wrap MIME-transformations. [MIME]
1301 $default_function = 'default_function'; // default_function
1302 $transform_function = $default_function;
1303 $transform_options = array();
1305 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1307 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1308 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1310 if (file_exists('./libraries/transformations/' . $include_file)) {
1311 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1313 require_once './libraries/transformations/' . $include_file;
1315 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1316 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1317 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1318 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1320 } // end if file_exists
1321 } // end if transformation is set
1322 } // end if mime/transformation works.
1324 $_url_params = array(
1325 'db' => $db,
1326 'table' => $table,
1327 'where_clause' => $where_clause,
1328 'transform_key' => $meta->name,
1331 if (! empty($sql_query)) {
1332 $_url_params['sql_query'] = $url_sql_query;
1335 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1337 // n u m e r i c
1338 if ($meta->numeric == 1) {
1340 // if two fields have the same name (this is possible
1341 // with self-join queries, for example), using $meta->name
1342 // will show both fields NULL even if only one is NULL,
1343 // so use the $pointer
1345 if (!isset($row[$i]) || is_null($row[$i])) {
1346 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1347 } elseif ($row[$i] != '') {
1349 $nowrap = ' nowrap';
1350 $where_comparison = ' = ' . $row[$i];
1352 $vertical_display['data'][$row_no][$i] = '<td align="right"' . PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated);
1353 } else {
1354 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1357 // b l o b
1359 } elseif (stristr($meta->type, 'BLOB')) {
1360 // PMA_mysql_fetch_fields returns BLOB in place of
1361 // TEXT fields type so we have to ensure it's really a BLOB
1362 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1364 // remove 'inline_edit' from $class as we can't edit binary data.
1365 $class = str_replace('inline_edit', '', $class);
1367 if (stristr($field_flags, 'BINARY')) {
1368 if (!isset($row[$i]) || is_null($row[$i])) {
1369 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1370 } else {
1371 // for blobstreaming
1372 // if valid BS reference exists
1373 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1374 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1375 } else {
1376 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1379 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1380 unset($blobtext);
1382 // not binary:
1383 } else {
1384 if (!isset($row[$i]) || is_null($row[$i])) {
1385 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1386 } elseif ($row[$i] != '') {
1387 // if a transform function for blob is set, none of these replacements will be made
1388 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1389 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1390 $is_field_truncated = true;
1392 // displays all space characters, 4 space
1393 // characters for tabulations and <cr>/<lf>
1394 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1396 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1397 } else {
1398 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1401 // g e o m e t r y
1402 } elseif ($meta->type == 'geometry') {
1403 $geometry_text = PMA_handle_non_printable_contents('GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1405 // remove 'inline_edit' from $class as we can't edit geometry data.
1406 $class = str_replace('inline_edit', '', $class);
1407 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $geometry_text);
1408 unset($geometry_text);
1410 // n o t n u m e r i c a n d n o t B L O B
1411 } else {
1412 if (!isset($row[$i]) || is_null($row[$i])) {
1413 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1414 } elseif ($row[$i] != '') {
1415 // support blanks in the key
1416 $relation_id = $row[$i];
1418 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1419 // (unless it's a link-type transformation)
1420 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1421 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1422 $is_field_truncated = true;
1425 // displays special characters from binaries
1426 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1427 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1428 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1429 // some results of PROCEDURE ANALYSE() are reported as
1430 // being BINARY but they are quite readable,
1431 // so don't treat them as BINARY
1432 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1433 if ($_SESSION['tmp_user_values']['display_binary']) {
1434 // user asked to see the real contents of BINARY
1435 // fields
1436 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1437 $row[$i] = bin2hex($row[$i]);
1438 } else {
1439 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1441 } else {
1442 // we show the BINARY message and field's size
1443 // (or maybe use a transformation)
1444 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1448 // transform functions may enable no-wrapping:
1449 $function_nowrap = $transform_function . '_nowrap';
1450 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1452 // do not wrap if date field type
1453 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1454 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1455 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated);
1457 } else {
1458 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1462 // output stored cell
1463 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1464 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1465 echo $vertical_display['data'][$row_no][$i];
1468 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1469 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1470 } else {
1471 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1473 } // end for (2)
1475 // 3. Displays the modify/delete links on the right if required
1476 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1477 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1478 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1479 if (! isset($js_conf)) {
1480 $js_conf = '';
1482 echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1483 } // end if (3)
1485 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1486 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1488 </tr>
1489 <?php
1490 } // end if
1492 // 4. Gather links of del_urls and edit_urls in an array for later
1493 // output
1494 if (!isset($vertical_display['edit'][$row_no])) {
1495 $vertical_display['edit'][$row_no] = '';
1496 $vertical_display['copy'][$row_no] = '';
1497 $vertical_display['delete'][$row_no] = '';
1498 $vertical_display['row_delete'][$row_no] = '';
1500 $vertical_class = ' row_' . $row_no;
1501 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1502 $vertical_class .= ' vpointer';
1504 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1505 $vertical_class .= ' vmarker';
1508 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1509 $vertical_display['row_delete'][$row_no] .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, '[%_PMA_CHECKBOX_DIR_%]', $alternating_color_class . $vertical_class);
1510 } else {
1511 unset($vertical_display['row_delete'][$row_no]);
1514 if (isset($edit_url)) {
1515 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1516 } else {
1517 unset($vertical_display['edit'][$row_no]);
1520 if (isset($copy_url)) {
1521 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1522 } else {
1523 unset($vertical_display['copy'][$row_no]);
1526 if (isset($del_url)) {
1527 if (! isset($js_conf)) {
1528 $js_conf = '';
1530 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1531 } else {
1532 unset($vertical_display['delete'][$row_no]);
1535 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1536 $row_no++;
1537 } // end while
1539 // this is needed by PMA_displayTable() to generate the proper param
1540 // in the multi-edit and multi-delete form
1541 return $clause_is_unique;
1542 } // end of the 'PMA_displayTableBody()' function
1546 * Do display the result table with the vertical direction mode.
1548 * @return boolean always true
1550 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1551 * @global array $vertical_display the information to display
1553 * @access private
1555 * @see PMA_displayTable()
1557 function PMA_displayVerticalTable()
1559 global $vertical_display;
1561 // Displays "multi row delete" link at top if required
1562 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1563 echo '<tr>' . "\n";
1564 echo $vertical_display['textbtn'];
1565 $foo_counter = 0;
1566 foreach ($vertical_display['row_delete'] as $val) {
1567 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1568 echo '<th></th>' . "\n";
1571 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1572 $foo_counter++;
1573 } // end while
1574 echo '</tr>' . "\n";
1575 } // end if
1577 // Displays "edit" link at top if required
1578 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1579 echo '<tr>' . "\n";
1580 if (!is_array($vertical_display['row_delete'])) {
1581 echo $vertical_display['textbtn'];
1583 $foo_counter = 0;
1584 foreach ($vertical_display['edit'] as $val) {
1585 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1586 echo ' <th></th>' . "\n";
1589 echo $val;
1590 $foo_counter++;
1591 } // end while
1592 echo '</tr>' . "\n";
1593 } // end if
1595 // Displays "copy" link at top if required
1596 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1597 echo '<tr>' . "\n";
1598 if (!is_array($vertical_display['row_delete'])) {
1599 echo $vertical_display['textbtn'];
1601 $foo_counter = 0;
1602 foreach ($vertical_display['copy'] as $val) {
1603 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1604 echo ' <th></th>' . "\n";
1607 echo $val;
1608 $foo_counter++;
1609 } // end while
1610 echo '</tr>' . "\n";
1611 } // end if
1613 // Displays "delete" link at top if required
1614 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1615 echo '<tr>' . "\n";
1616 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1617 echo $vertical_display['textbtn'];
1619 $foo_counter = 0;
1620 foreach ($vertical_display['delete'] as $val) {
1621 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1622 echo '<th></th>' . "\n";
1625 echo $val;
1626 $foo_counter++;
1627 } // end while
1628 echo '</tr>' . "\n";
1629 } // end if
1631 // Displays data
1632 foreach ($vertical_display['desc'] AS $key => $val) {
1634 echo '<tr>' . "\n";
1635 echo $val;
1637 $foo_counter = 0;
1638 foreach ($vertical_display['rowdata'][$key] as $subval) {
1639 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1640 echo $val;
1643 echo $subval;
1644 $foo_counter++;
1645 } // end while
1647 echo '</tr>' . "\n";
1648 } // end while
1650 // Displays "multi row delete" link at bottom if required
1651 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1652 echo '<tr>' . "\n";
1653 echo $vertical_display['textbtn'];
1654 $foo_counter = 0;
1655 foreach ($vertical_display['row_delete'] as $val) {
1656 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1657 echo '<th></th>' . "\n";
1660 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1661 $foo_counter++;
1662 } // end while
1663 echo '</tr>' . "\n";
1664 } // end if
1666 // Displays "edit" link at bottom if required
1667 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1668 echo '<tr>' . "\n";
1669 if (!is_array($vertical_display['row_delete'])) {
1670 echo $vertical_display['textbtn'];
1672 $foo_counter = 0;
1673 foreach ($vertical_display['edit'] as $val) {
1674 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1675 echo '<th></th>' . "\n";
1678 echo $val;
1679 $foo_counter++;
1680 } // end while
1681 echo '</tr>' . "\n";
1682 } // end if
1684 // Displays "copy" link at bottom if required
1685 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1686 echo '<tr>' . "\n";
1687 if (!is_array($vertical_display['row_delete'])) {
1688 echo $vertical_display['textbtn'];
1690 $foo_counter = 0;
1691 foreach ($vertical_display['copy'] as $val) {
1692 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1693 echo '<th></th>' . "\n";
1696 echo $val;
1697 $foo_counter++;
1698 } // end while
1699 echo '</tr>' . "\n";
1700 } // end if
1702 // Displays "delete" link at bottom if required
1703 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1704 echo '<tr>' . "\n";
1705 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1706 echo $vertical_display['textbtn'];
1708 $foo_counter = 0;
1709 foreach ($vertical_display['delete'] as $val) {
1710 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1711 echo '<th></th>' . "\n";
1714 echo $val;
1715 $foo_counter++;
1716 } // end while
1717 echo '</tr>' . "\n";
1720 return true;
1721 } // end of the 'PMA_displayVerticalTable' function
1725 * @uses $_SESSION['tmp_user_values']['disp_direction']
1726 * @uses $_REQUEST['disp_direction']
1727 * @uses $GLOBALS['cfg']['DefaultDisplay']
1728 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1729 * @uses $_REQUEST['repeat_cells']
1730 * @uses $GLOBALS['cfg']['RepeatCells']
1731 * @uses $_SESSION['tmp_user_values']['max_rows']
1732 * @uses $_REQUEST['session_max_rows']
1733 * @uses $GLOBALS['cfg']['MaxRows']
1734 * @uses $_SESSION['tmp_user_values']['pos']
1735 * @uses $_REQUEST['pos']
1736 * @uses $_SESSION['tmp_user_values']['display_text']
1737 * @uses $_REQUEST['display_text']
1738 * @uses $_SESSION['tmp_user_values']['relational_display']
1739 * @uses $_REQUEST['relational_display']
1740 * @uses $_SESSION['tmp_user_values']['display_binary']
1741 * @uses $_REQUEST['display_binary']
1742 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1743 * @uses $_REQUEST['display_binary_as_hex']
1744 * @uses $_SESSION['tmp_user_values']['display_blob']
1745 * @uses $_REQUEST['display_blob']
1746 * @uses PMA_isValid()
1747 * @uses $GLOBALS['sql_query']
1748 * @todo make maximum remembered queries configurable
1749 * @todo move/split into SQL class!?
1750 * @todo currently this is called twice unnecessary
1751 * @todo ignore LIMIT and ORDER in query!?
1753 function PMA_displayTable_checkConfigParams()
1755 $sql_md5 = md5($GLOBALS['sql_query']);
1757 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1759 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1760 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1761 unset($_REQUEST['disp_direction']);
1762 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1763 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1766 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1767 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1768 unset($_REQUEST['repeat_cells']);
1769 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1770 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1773 // as this is a form value, the type is always string so we cannot
1774 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1775 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1776 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1777 || $_REQUEST['session_max_rows'] == 'all') {
1778 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1779 unset($_REQUEST['session_max_rows']);
1780 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1781 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1784 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1785 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1786 unset($_REQUEST['pos']);
1787 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1788 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1791 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1792 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1793 unset($_REQUEST['display_text']);
1794 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1795 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1798 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1799 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1800 unset($_REQUEST['relational_display']);
1801 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1802 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1805 if (isset($_REQUEST['display_binary'])) {
1806 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1807 unset($_REQUEST['display_binary']);
1808 } elseif (isset($_REQUEST['display_options_form'])) {
1809 // we know that the checkbox was unchecked
1810 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1811 } else {
1812 // selected by default because some operations like OPTIMIZE TABLE
1813 // and all queries involving functions return "binary" contents,
1814 // according to low-level field flags
1815 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1818 if (isset($_REQUEST['display_binary_as_hex'])) {
1819 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1820 unset($_REQUEST['display_binary_as_hex']);
1821 } elseif (isset($_REQUEST['display_options_form'])) {
1822 // we know that the checkbox was unchecked
1823 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1824 } else {
1825 // display_binary_as_hex config option
1826 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1827 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1831 if (isset($_REQUEST['display_blob'])) {
1832 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1833 unset($_REQUEST['display_blob']);
1834 } elseif (isset($_REQUEST['display_options_form'])) {
1835 // we know that the checkbox was unchecked
1836 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1839 if (isset($_REQUEST['hide_transformation'])) {
1840 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1841 unset($_REQUEST['hide_transformation']);
1842 } elseif (isset($_REQUEST['display_options_form'])) {
1843 // we know that the checkbox was unchecked
1844 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1847 // move current query to the last position, to be removed last
1848 // so only least executed query will be removed if maximum remembered queries
1849 // limit is reached
1850 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
1851 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
1852 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
1854 // do not exceed a maximum number of queries to remember
1855 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1856 array_shift($_SESSION['tmp_user_values']['query']);
1857 //echo 'deleting one element ...';
1860 // populate query configuration
1861 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
1862 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
1863 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
1864 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
1865 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
1866 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
1867 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
1868 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
1869 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
1870 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
1873 * debugging
1874 echo '<pre>';
1875 var_dump($_SESSION['tmp_user_values']);
1876 echo '</pre>';
1881 * Displays a table of results returned by a SQL query.
1882 * This function is called by the "sql.php" script.
1884 * @param integer the link id associated to the query which results have
1885 * to be displayed
1886 * @param array the display mode
1887 * @param array the analyzed query
1889 * @uses $_SESSION['tmp_user_values']['pos']
1890 * @global string $db the database name
1891 * @global string $table the table name
1892 * @global string $goto the URL to go back in case of errors
1893 * @global string $sql_query the current SQL query
1894 * @global integer $num_rows the total number of rows returned by the
1895 * SQL query
1896 * @global integer $unlim_num_rows the total number of rows returned by the
1897 * SQL query without any programmatically
1898 * appended "LIMIT" clause
1899 * @global array $fields_meta the list of fields properties
1900 * @global integer $fields_cnt the total number of fields returned by
1901 * the SQL query
1902 * @global array $vertical_display informations used with vertical display
1903 * mode
1904 * @global array $highlight_columns column names to highlight
1905 * @global array $cfgRelation the relation settings
1907 * @access private
1909 * @see PMA_showMessage(), PMA_setDisplayMode(),
1910 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1911 * PMA_displayTableBody(), PMA_displayResultsOperations()
1913 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1915 global $db, $table, $goto;
1916 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1917 global $vertical_display, $highlight_columns;
1918 global $cfgRelation;
1919 global $showtable;
1921 // why was this called here? (already called from sql.php)
1922 //PMA_displayTable_checkConfigParams();
1925 * @todo move this to a central place
1926 * @todo for other future table types
1928 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1930 if ($is_innodb
1931 && ! isset($analyzed_sql[0]['queryflags']['union'])
1932 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1933 && (empty($analyzed_sql[0]['where_clause'])
1934 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1935 // "j u s t b r o w s i n g"
1936 $pre_count = '~';
1937 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')), true);
1938 } else {
1939 $pre_count = '';
1940 $after_count = '';
1943 // 1. ----- Prepares the work -----
1945 // 1.1 Gets the informations about which functionalities should be
1946 // displayed
1947 $total = '';
1948 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1950 // 1.2 Defines offsets for the next and previous pages
1951 if ($is_display['nav_bar'] == '1') {
1952 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1953 $pos_next = 0;
1954 $pos_prev = 0;
1955 } else {
1956 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
1957 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1958 if ($pos_prev < 0) {
1959 $pos_prev = 0;
1962 } // end if
1964 // 1.3 Find the sort expression
1966 // we need $sort_expression and $sort_expression_nodirection
1967 // even if there are many table references
1968 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1969 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1971 * Get rid of ASC|DESC
1973 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1974 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1975 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1976 unset($matches);
1977 } else {
1978 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1981 // 1.4 Prepares display of first and last value of the sorted column
1983 if (! empty($sort_expression_nodirection)) {
1984 if (strpos($sort_expression_nodirection, '.') === false) {
1985 $sort_table = $table;
1986 $sort_column = $sort_expression_nodirection;
1987 } else {
1988 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1990 $sort_table = PMA_unQuote($sort_table);
1991 $sort_column = PMA_unQuote($sort_column);
1992 // find the sorted column index in row result
1993 // (this might be a multi-table query)
1994 $sorted_column_index = false;
1995 foreach($fields_meta as $key => $meta) {
1996 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1997 $sorted_column_index = $key;
1998 break;
2001 if ($sorted_column_index !== false) {
2002 // fetch first row of the result set
2003 $row = PMA_DBI_fetch_row($dt_result);
2004 // initializing default arguments
2005 $default_function = 'default_function';
2006 $transform_function = $default_function;
2007 $transform_options = array();
2008 // check for non printable sorted row data
2009 $meta = $fields_meta[$sorted_column_index];
2010 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2011 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2012 } else {
2013 $column_for_first_row = $row[$sorted_column_index];
2015 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2016 // fetch last row of the result set
2017 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2018 $row = PMA_DBI_fetch_row($dt_result);
2019 // check for non printable sorted row data
2020 $meta = $fields_meta[$sorted_column_index];
2021 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2022 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2023 } else {
2024 $column_for_last_row = $row[$sorted_column_index];
2026 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2027 // reset to first row for the loop in PMA_displayTableBody()
2028 PMA_DBI_data_seek($dt_result, 0);
2029 // we could also use here $sort_expression_nodirection
2030 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2031 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2033 unset($sorted_column_index, $sort_table, $sort_column);
2036 // 2. ----- Displays the top of the page -----
2038 // 2.1 Displays a messages with position informations
2039 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2040 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2041 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2042 } else {
2043 $selectstring = '';
2045 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
2046 ? $total - 1
2047 : $pos_next - 1;
2049 if (PMA_Table::isView($db, $table)
2050 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2051 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2052 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2053 $message->addParam('[/a]');
2054 $message_view_warning = PMA_showHint($message);
2055 } else {
2056 $message_view_warning = false;
2059 $message = PMA_Message::success(__('Showing rows'));
2060 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2061 if ($message_view_warning) {
2062 $message->addMessage('...', ' - ');
2063 $message->addMessage($message_view_warning);
2064 $message->addMessage('(');
2065 } else {
2066 $message->addMessage($last_shown_rec, ' - ');
2067 $message->addMessage(' (');
2068 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2069 $message->addString(__('total'));
2070 if (!empty($after_count)) {
2071 $message->addMessage($after_count);
2073 $message->addMessage($selectstring, '');
2074 $message->addMessage(', ', '');
2077 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2078 $messagge_qt->addParam($GLOBALS['querytime']);
2080 $message->addMessage($messagge_qt, '');
2081 $message->addMessage(')', '');
2083 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2085 PMA_showMessage($message, $sql_query, 'success');
2087 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2088 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2091 // 2.3 Displays the navigation bars
2092 if (! strlen($table)) {
2093 if (isset($analyzed_sql[0]['query_type'])
2094 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2095 // table does not always contain a real table name,
2096 // for example in MySQL 5.0.x, the query SHOW STATUS
2097 // returns STATUS as a table name
2098 $table = $fields_meta[0]->table;
2099 } else {
2100 $table = '';
2104 if ($is_display['nav_bar'] == '1') {
2105 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2106 echo "\n";
2107 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2108 echo "\n" . '<br /><br />' . "\n";
2111 // 2b ----- Get field references from Database -----
2112 // (see the 'relation' configuration variable)
2114 // initialize map
2115 $map = array();
2117 // find tables
2118 $target=array();
2119 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2120 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2121 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2124 $tabs = '(\'' . join('\',\'', $target) . '\')';
2126 if (! strlen($table)) {
2127 $exist_rel = false;
2128 } else {
2129 // To be able to later display a link to the related table,
2130 // we verify both types of relations: either those that are
2131 // native foreign keys or those defined in the phpMyAdmin
2132 // configuration storage. If no PMA storage, we won't be able
2133 // to use the "column to display" notion (for example show
2134 // the name related to a numeric id).
2135 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2136 if ($exist_rel) {
2137 foreach ($exist_rel AS $master_field => $rel) {
2138 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2139 $map[$master_field] = array($rel['foreign_table'],
2140 $rel['foreign_field'],
2141 $display_field,
2142 $rel['foreign_db']);
2143 } // end while
2144 } // end if
2145 } // end if
2146 // end 2b
2148 // 3. ----- Displays the results table -----
2149 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2150 $url_query = '';
2151 echo '<tbody>' . "\n";
2152 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2153 // vertical output case
2154 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2155 PMA_displayVerticalTable();
2156 } // end if
2157 unset($vertical_display);
2158 echo '</tbody>' . "\n";
2160 </table>
2162 <?php
2163 // 4. ----- Displays the link for multi-fields edit and delete
2165 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2167 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2169 $_url_params = array(
2170 'db' => $db,
2171 'table' => $table,
2172 'sql_query' => $sql_query,
2173 'goto' => $goto,
2175 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2177 $_url_params['checkall'] = '1';
2178 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2180 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2181 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2182 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2183 } else {
2184 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2185 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2187 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2188 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2189 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2190 echo '<img class="selectallarrow" width="38" height="22"'
2191 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2192 .' alt="' . __('With selected:') . '" />';
2194 echo $checkall_link . "\n"
2195 .' / ' . "\n"
2196 .$uncheckall_link . "\n"
2197 .'<i>' . __('With selected:') . '</i>' . "\n";
2199 PMA_buttonOrImage('submit_mult', 'mult_submit',
2200 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2201 PMA_buttonOrImage('submit_mult', 'mult_submit',
2202 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2203 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2204 PMA_buttonOrImage('submit_mult', 'mult_submit',
2205 'submit_mult_export', __('Export'),
2206 'b_tblexport.png', 'export');
2208 echo "\n";
2210 echo '<input type="hidden" name="sql_query"'
2211 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2213 if (! empty($GLOBALS['url_query'])) {
2214 echo '<input type="hidden" name="url_query"'
2215 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2218 echo '<input type="hidden" name="clause_is_unique"'
2219 .' value="' . $clause_is_unique . '" />' . "\n";
2221 echo '</form>' . "\n";
2224 // 5. ----- Displays the navigation bar at the bottom if required -----
2226 if ($is_display['nav_bar'] == '1') {
2227 echo '<br />' . "\n";
2228 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2229 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2230 echo "\n" . '<br /><br />' . "\n";
2233 // 6. ----- Displays "Query results operations"
2234 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2235 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2237 } // end of the 'PMA_displayTable()' function
2239 function default_function($buffer) {
2240 $buffer = htmlspecialchars($buffer);
2241 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2242 str_replace(' ', ' &nbsp;', $buffer));
2243 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2245 return $buffer;
2249 * Displays operations that are available on results.
2251 * @param array the display mode
2252 * @param array the analyzed query
2254 * @uses $_SESSION['tmp_user_values']['pos']
2255 * @uses $_SESSION['tmp_user_values']['display_text']
2256 * @global string $db the database name
2257 * @global string $table the table name
2258 * @global string $sql_query the current SQL query
2259 * @global integer $unlim_num_rows the total number of rows returned by the
2260 * SQL query without any programmatically
2261 * appended "LIMIT" clause
2263 * @access private
2265 * @see PMA_showMessage(), PMA_setDisplayMode(),
2266 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2267 * PMA_displayTableBody(), PMA_displayResultsOperations()
2269 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2270 global $db, $table, $sql_query, $unlim_num_rows;
2272 $header_shown = FALSE;
2273 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2275 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2276 // Displays "printable view" link if required
2277 if ($the_disp_mode[9] == '1') {
2279 if (!$header_shown) {
2280 echo $header;
2281 $header_shown = TRUE;
2284 $_url_params = array(
2285 'db' => $db,
2286 'table' => $table,
2287 'printview' => '1',
2288 'sql_query' => $sql_query,
2290 $url_query = PMA_generate_common_url($_url_params);
2292 echo PMA_linkOrButton(
2293 'sql.php' . $url_query,
2294 PMA_getIcon('b_print.png', __('Print view'), false, true),
2295 '', true, true, 'print_view') . "\n";
2297 if ($_SESSION['tmp_user_values']['display_text']) {
2298 $_url_params['display_text'] = 'F';
2299 echo PMA_linkOrButton(
2300 'sql.php' . PMA_generate_common_url($_url_params),
2301 PMA_getIcon('b_print.png', __('Print view (with full texts)'), false, true),
2302 '', true, true, 'print_view') . "\n";
2303 unset($_url_params['display_text']);
2305 } // end displays "printable view"
2308 // Export link
2309 // (the url_query has extra parameters that won't be used to export)
2310 // (the single_table parameter is used in display_export.lib.php
2311 // to hide the SQL and the structure export dialogs)
2312 // If the parser found a PROCEDURE clause
2313 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2314 // display the Export link).
2315 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2316 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2317 $_url_params['single_table'] = 'true';
2319 if (!$header_shown) {
2320 echo $header;
2321 $header_shown = TRUE;
2323 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2326 * At this point we don't know the table name; this can happen
2327 * for example with a query like
2328 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2329 * As a workaround we set in the table parameter the name of the
2330 * first table of this database, so that tbl_export.php and
2331 * the script it calls do not fail
2333 if (empty($_url_params['table'])) {
2334 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2337 echo PMA_linkOrButton(
2338 'tbl_export.php' . PMA_generate_common_url($_url_params),
2339 PMA_getIcon('b_tblexport.png', __('Export'), false, true),
2340 '', true, true, '') . "\n";
2342 // show chart
2343 echo PMA_linkOrButton(
2344 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2345 PMA_getIcon('b_chart.png', __('Display chart'), false, true),
2346 '', true, true, '') . "\n";
2349 // CREATE VIEW
2352 * @todo detect privileges to create a view
2353 * (but see 2006-01-19 note in display_create_table.lib.php,
2354 * I think we cannot detect db-specific privileges reliably)
2355 * Note: we don't display a Create view link if we found a PROCEDURE clause
2357 if (!$header_shown) {
2358 echo $header;
2359 $header_shown = TRUE;
2361 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2362 echo PMA_linkOrButton(
2363 'view_create.php' . $url_query,
2364 PMA_getIcon('b_views.png', __('Create view'), false, true),
2365 '', true, true, '') . "\n";
2367 if ($header_shown) {
2368 echo '</fieldset><br />';
2373 * Verifies what to do with non-printable contents (binary or BLOB)
2374 * in Browse mode.
2376 * @uses is_null()
2377 * @uses isset()
2378 * @uses strlen()
2379 * @uses PMA_formatByteDown()
2380 * @uses strpos()
2381 * @uses str_replace()
2382 * @param string $category BLOB|BINARY|GEOMETRY
2383 * @param string $content the binary content
2384 * @param string $transform_function
2385 * @param string $transform_options
2386 * @param string $default_function
2387 * @param object $meta the meta-information about this field
2388 * @return mixed string or float
2390 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2391 $result = '[' . $category;
2392 if (is_null($content)) {
2393 $result .= ' - NULL';
2394 $size = 0;
2395 } elseif (isset($content)) {
2396 $size = strlen($content);
2397 $display_size = PMA_formatByteDown($size, 3, 1);
2398 $result .= ' - '. $display_size[0] . $display_size[1];
2400 $result .= ']';
2402 if (strpos($transform_function, 'octetstream')) {
2403 $result = $content;
2405 if ($size > 0) {
2406 if ($default_function != $transform_function) {
2407 $result = $transform_function($result, $transform_options, $meta);
2408 } else {
2409 $result = $default_function($result, array(), $meta);
2410 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2411 // in this case, restart from the original $content
2412 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2414 /* Create link to download */
2415 if (count($url_params) > 0) {
2416 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2420 return($result);
2424 * Prepares the displayable content of a data cell in Browse mode,
2425 * taking into account foreign key description field and transformations
2427 * @uses is_array()
2428 * @uses PMA_backquote()
2429 * @uses PMA_DBI_try_query()
2430 * @uses PMA_DBI_num_rows()
2431 * @uses PMA_DBI_fetch_row()
2432 * @uses PMA_DBI_free_result()
2433 * @uses $GLOBALS['printview']
2434 * @uses htmlspecialchars()
2435 * @uses PMA_generate_common_url()
2436 * @param string $class
2437 * @param string $condition_field
2438 * @param string $analyzed_sql
2439 * @param object $meta the meta-information about this field
2440 * @param string $map
2441 * @param string $data
2442 * @param string $transform_function
2443 * @param string $default_function
2444 * @param string $nowrap
2445 * @param string $where_comparison
2446 * @param bool $is_field_truncated
2447 * @return string formatted data
2449 function PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated ) {
2451 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2453 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2454 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2455 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2456 if (isset($alias) && strlen($alias)) {
2457 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2458 if ($alias == $meta->name) {
2459 // this change in the parameter does not matter
2460 // outside of the function
2461 $meta->name = $true_column;
2462 } // end if
2463 } // end if
2464 } // end foreach
2465 } // end if
2467 if (isset($map[$meta->name])) {
2468 // Field to display from the foreign table?
2469 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2470 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2471 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2472 . '.' . PMA_backquote($map[$meta->name][0])
2473 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2474 . $where_comparison;
2475 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2476 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2477 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2478 } else {
2479 $dispval = __('Link not found');
2481 @PMA_DBI_free_result($dispresult);
2482 } else {
2483 $dispval = '';
2484 } // end if... else...
2486 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2487 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2488 } else {
2490 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2491 // user chose "relational key" in the display options, so
2492 // the title contains the display field
2493 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2494 } else {
2495 $title = ' title="' . htmlspecialchars($data) . '"';
2498 $_url_params = array(
2499 'db' => $map[$meta->name][3],
2500 'table' => $map[$meta->name][0],
2501 'pos' => '0',
2502 'sql_query' => 'SELECT * FROM '
2503 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2504 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2505 . $where_comparison,
2507 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2508 . '"' . $title . '>';
2510 if ($transform_function != $default_function) {
2511 // always apply a transformation on the real data,
2512 // not on the display field
2513 $result .= $transform_function($data, $transform_options, $meta);
2514 } else {
2515 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2516 // user chose "relational display field" in the
2517 // display options, so show display field in the cell
2518 $result .= $transform_function($dispval, array(), $meta);
2519 } else {
2520 // otherwise display data in the cell
2521 $result .= $transform_function($data, array(), $meta);
2524 $result .= '</a>';
2526 } else {
2527 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2529 $result .= '</td>' . "\n";
2531 return $result;
2535 * Generates a checkbox for multi-row submits
2537 * @uses htmlspecialchars
2538 * @param string $del_url
2539 * @param array $is_display
2540 * @param string $row_no
2541 * @param string $where_clause_html
2542 * @param string $del_query
2543 * @param string $id_suffix
2544 * @param string $class
2545 * @return string the generated HTML
2548 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class) {
2549 $ret = '';
2550 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2551 $ret .= '<td ';
2552 if (! empty($class)) {
2553 $ret .= 'class="' . $class . '"';
2555 $ret .= ' align="center">'
2556 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2557 . ' class="multi_checkbox"'
2558 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2559 . ' </td>';
2561 return $ret;
2565 * Generates an Edit link
2567 * @uses PMA_linkOrButton()
2568 * @param string $edit_url
2569 * @param string $class
2570 * @param string $edit_str
2571 * @param string $where_clause
2572 * @param string $where_clause_html
2573 * @return string the generated HTML
2575 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) {
2576 $ret = '';
2577 if (! empty($edit_url)) {
2578 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2579 . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE);
2581 * Where clause for selecting this row uniquely is provided as
2582 * a hidden input. Used by jQuery scripts for handling inline editing
2584 if(! empty($where_clause)) {
2585 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2587 $ret .= '</span></td>';
2589 return $ret;
2593 * Generates an Copy link
2595 * @uses PMA_linkOrButton()
2596 * @param string $copy_url
2597 * @param string $copy_str
2598 * @param string $where_clause
2599 * @param string $where_clause_html
2600 * @return string the generated HTML
2602 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class) {
2603 $ret = '';
2604 if (! empty($copy_url)) {
2605 $ret .= '<td ';
2606 if (! empty($class)) {
2607 $ret .= 'class="' . $class . '" ';
2609 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2610 . PMA_linkOrButton($copy_url, $copy_str, array(), FALSE);
2612 * Where clause for selecting this row uniquely is provided as
2613 * a hidden input. Used by jQuery scripts for handling inline editing
2615 if(! empty($where_clause)) {
2616 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2618 $ret .= '</span></td>';
2620 return $ret;
2624 * Generates a Delete link
2626 * @uses PMA_linkOrButton()
2627 * @param string $del_url
2628 * @param string $del_str
2629 * @param string $js_conf
2630 * @param string $class
2631 * @return string the generated HTML
2633 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
2634 $ret = '';
2635 if (! empty($del_url)) {
2636 $ret .= '<td ';
2637 if (! empty($class)) {
2638 $ret .= 'class="' . $class . '" ';
2640 $ret .= 'align="center" ' . ' >'
2641 . PMA_linkOrButton($del_url, $del_str, $js_conf, FALSE)
2642 . '</td>';
2644 return $ret;
2648 * Generates checkbox and links at some position (left or right)
2649 * (only called for horizontal mode)
2651 * @uses PMA_generateCheckboxForMulti()
2652 * @uses PMA_generateEditLink()
2653 * @uses PMA_generateDeleteLink()
2654 * @uses PMA_generateCopyLink()
2655 * @param string $position
2656 * @param string $del_url
2657 * @param array $is_display
2658 * @param string $row_no
2659 * @param string $where_clause
2660 * @param string $where_clause_html
2661 * @param string $del_query
2662 * @param string $id_suffix
2663 * @param string $edit_url
2664 * @param string $copy_url
2665 * @param string $class
2666 * @param string $edit_str
2667 * @param string $del_str
2668 * @param string $js_conf
2669 * @return string the generated HTML
2671 function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf) {
2672 $ret = '';
2674 if ($position == 'left') {
2675 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2677 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2679 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2681 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2683 } elseif ($position == 'right') {
2684 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2686 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2688 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2690 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');
2692 return $ret;