2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * library for displaying table with results from all sort of select queries
12 require_once './libraries/Index.class.php';
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.
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
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
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_disp_mode the synthetic value for display_mode (see a few
32 * lines above for explanations)
33 * @param integer &$the_total 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
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
51 * @see PMA_displayTable()
53 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
56 global $unlim_num_rows, $fields_meta;
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
72 if ($the_disp_mode != 'nnnn000000') {
73 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
74 // 2.0 Print view -> set all elements to false!
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';
83 } elseif ($GLOBALS['is_count'] ||
$GLOBALS['is_analyse']
84 ||
$GLOBALS['is_maint'] ||
$GLOBALS['is_explain']
86 // 2.1 Statement is a "SELECT COUNT", a
87 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
88 // contains a "PROC ANALYSE" part
89 $do_display['edit_lnk'] = 'nn'; // no edit link
90 $do_display['del_lnk'] = 'nn'; // no delete link
91 $do_display['sort_lnk'] = (string) '0';
92 $do_display['nav_bar'] = (string) '0';
93 $do_display['ins_row'] = (string) '0';
94 $do_display['bkm_form'] = (string) '1';
95 if ($GLOBALS['is_maint']) {
96 $do_display['text_btn'] = (string) '1';
98 $do_display['text_btn'] = (string) '0';
100 $do_display['pview_lnk'] = (string) '1';
101 } elseif ($GLOBALS['is_show']) {
102 // 2.2 Statement is a "SHOW..."
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
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 $prev_table = $fields_meta[0]->table
;
128 $do_display['text_btn'] = (string) '1';
129 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++
) {
130 $is_link = ($do_display['edit_lnk'] != 'nn'
131 ||
$do_display['del_lnk'] != 'nn'
132 ||
$do_display['sort_lnk'] != '0'
133 ||
$do_display['ins_row'] != '0');
134 // 2.3.2 Displays edit/delete/sort/insert links?
136 && ($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') {
149 // 2.3.3 Always display print view link
150 $do_display['pview_lnk'] = (string) '1';
151 $prev_table = $fields_meta[$i]->table
;
153 } // end if..elseif...else (2.1 -> 2.3)
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
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';
180 // 5. Updates the synthetic var
181 $the_disp_mode = join('', $do_display);
184 } // end of the 'PMA_setDisplayMode()' function
188 * Return true if we are executing a query in the form of
189 * "SELECT * FROM <a table> ..."
193 function PMA_isSelect()
195 // global variables set from sql.php
196 global $is_count, $is_export, $is_func, $is_analyse;
197 global $analyzed_sql;
199 return ! ($is_count ||
$is_export ||
$is_func ||
$is_analyse)
200 && count($analyzed_sql[0]['select_expr']) == 0
201 && isset($analyzed_sql[0]['queryflags']['select_from'])
202 && count($analyzed_sql[0]['table_ref']) == 1;
207 * Displays a navigation button
209 * @param string $caption iconic caption for button
210 * @param string $title text for button
211 * @param integer $pos position for next query
212 * @param string $html_sql_query query ready for display
213 * @param string $onsubmit optional onsubmit clause
214 * @param string $input_for_real_end optional hidden field for special treatment
215 * @param string $onclick optional onclick clause
219 * @global string $db the database name
220 * @global string $table the table name
221 * @global string $goto the URL to go back in case of errors
225 * @see PMA_displayTableNavigation()
227 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '')
230 global $db, $table, $goto;
232 $caption_output = '';
233 // for true or 'both'
234 if ($GLOBALS['cfg']['NavigationBarIconic']) {
235 $caption_output .= $caption;
237 // for false or 'both'
238 if (false === $GLOBALS['cfg']['NavigationBarIconic'] ||
'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
239 $caption_output .= ' ' . $title;
241 $title_output = ' title="' . $title . '"';
244 <form action
="sql.php" method
="post" <?php
echo $onsubmit; ?
>>
245 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
246 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
247 <input type
="hidden" name
="pos" value
="<?php echo $pos; ?>" />
248 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
249 <?php
echo $input_for_real_end; ?
>
250 <input type
="submit" name
="navig" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax" ' : '' ); ?
> value
="<?php echo $caption_output; ?>"<?php
echo $title_output . $onclick; ?
> />
254 } // end function PMA_displayTableNavigationOneButton()
257 * Displays a navigation bar to browse among the results of a SQL query
259 * @param integer $pos_next the offset for the "next" page
260 * @param integer $pos_prev the offset for the "previous" page
261 * @param string $sql_query the URL-encoded query
262 * @param string $id_for_direction_dropdown the id for the direction dropdown
266 * @global string $db the database name
267 * @global string $table the table name
268 * @global string $goto the URL to go back in case of errors
269 * @global integer $num_rows the total number of rows returned by the
271 * @global integer $unlim_num_rows the total number of rows returned by the
272 * SQL any programmatically appended "LIMIT" clause
273 * @global boolean $is_innodb whether its InnoDB or not
274 * @global array $showtable table definitions
278 * @see PMA_displayTable()
280 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
282 global $db, $table, $goto;
283 global $num_rows, $unlim_num_rows;
287 // here, using htmlentities() would cause problems if the query
288 // contains accented characters
289 $html_sql_query = htmlspecialchars($sql_query);
292 * @todo move this to a central place
293 * @todo for other future table types
295 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
299 <!-- Navigation bar
-->
300 <table border
="0" cellpadding
="0" cellspacing
="0" class="navigation">
302 <td
class="navigation_separator"></td
>
304 // Move to the beginning or to the previous page
305 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
306 PMA_displayTableNavigationOneButton('<<', __('Begin'), 0, $html_sql_query);
307 PMA_displayTableNavigationOneButton('<', __('Previous'), $pos_prev, $html_sql_query);
312 // (unless we are showing all records)
313 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
314 $pageNow = @floor
($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) +
1;
315 $nbTotalPage = @ceil
($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
317 if ($nbTotalPage > 1) { //if2
321 $_url_params = array(
324 'sql_query' => $sql_query,
327 //<form> to keep the form alignment of button < and <<
328 // and also to know what to execute when the selector changes
329 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
330 echo PMA_pageselector(
331 $_SESSION['tmp_user_values']['max_rows'],
347 // Display the "Show all" button if allowed
348 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
352 <form action
="sql.php" method
="post">
353 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
354 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
355 <input type
="hidden" name
="pos" value
="0" />
356 <input type
="hidden" name
="session_max_rows" value
="all" />
357 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
358 <input type
="submit" name
="navig" value
="<?php echo __('Show all'); ?>" />
364 // Move to the next page or to the last one
365 if (($_SESSION['tmp_user_values']['pos'] +
$_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
366 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
368 // display the Next button
369 PMA_displayTableNavigationOneButton('>',
374 // prepare some options for the End button
375 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
376 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
377 // no backquote around this message
380 $input_for_real_end = $onclick = '';
383 // display the End button
384 PMA_displayTableNavigationOneButton('>>',
386 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
388 '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') . '"',
394 // show separator if pagination happen
395 if ($nbTotalPage > 1) {
396 echo '<td><div class="navigation_separator">|</div></td>';
400 <div
class="restore_column hide">
401 <input type
="submit" value
="<?php echo __('Restore column order'); ?>" />
402 <div
class="navigation_separator">|
</div
>
405 if (PMA_isSelect()) {
406 // generate the column order, if it is set
407 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
408 $col_order = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_ORDER
);
410 echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
412 $col_visib = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_VISIB
);
414 echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
416 // generate table create time
417 echo '<input id="table_create_time" type="hidden" value="' .
418 PMA_Table
::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
421 echo '<input id="col_order_hint" type="hidden" value="' . __('Drag to reorder') . '" />';
422 echo '<input id="sort_hint" type="hidden" value="' . __('Click to sort') . '" />';
423 echo '<input id="col_mark_hint" type="hidden" value="' . __('Click to mark/unmark') . '" />';
424 echo '<input id="col_visib_hint" type="hidden" value="' . __('Click the drop-down arrow<br />to toggle column\'s visibility') . '" />';
425 echo '<input id="show_all_col_text" type="hidden" value="' . __('Show all') . '" />';
429 <?php
// if displaying a VIEW, $unlim_num_rows could be zero because
430 // of $cfg['MaxExactCountViews']; in this case, avoid passing
431 // the 5th parameter to checkFormElementInRange()
432 // (this means we can't validate the upper limit ?>
433 <td
class="navigation_goto">
434 <form action
="sql.php" method
="post"
435 onsubmit
="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) && checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
436 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
437 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
438 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
439 <input type
="submit" name
="navig" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
> value
="<?php echo __('Show'); ?> :" />
440 <?php
echo __('Start row') . ': ' . "\n"; ?
>
441 <input type
="text" name
="pos" size
="3" value
="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus
="this.select()" />
442 <?php
echo __('Number of rows') . ': ' . "\n"; ?
>
443 <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()" />
445 if ($GLOBALS['cfg']['ShowDisplayDirection']) {
446 // Display mode (horizontal/vertical and repeat headers)
447 echo __('Mode') . ': ' . "\n";
449 'horizontal' => __('horizontal'),
450 'horizontalflipped' => __('horizontal (rotated headers)'),
451 'vertical' => __('vertical'));
452 echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
456 printf(__('Headers every %s rows'),
457 '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />');
462 <td
class="navigation_separator"></td
>
467 } // end of the 'PMA_displayTableNavigation()' function
471 * Displays the headers of the results table
473 * @param array &$is_display which elements to display
474 * @param array &$fields_meta the list of fields properties
475 * @param integer $fields_cnt the total number of fields returned by the SQL query
476 * @param array $analyzed_sql the analyzed query
477 * @param string $sort_expression sort expression
478 * @param string $sort_expression_nodirection sort expression without direction
479 * @param string $sort_direction sort direction
481 * @return boolean $clause_is_unique
483 * @global string $db the database name
484 * @global string $table the table name
485 * @global string $goto the URL to go back in case of errors
486 * @global string $sql_query the SQL query
487 * @global integer $num_rows the total number of rows returned by the
489 * @global array $vertical_display informations used with vertical display
494 * @see PMA_displayTable()
496 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
498 global $db, $table, $goto;
499 global $sql_query, $num_rows;
500 global $vertical_display, $highlight_columns;
502 // required to generate sort links that will remember whether the
503 // "Show all" button has been clicked
504 $sql_md5 = md5($GLOBALS['sql_query']);
505 $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
507 if ($analyzed_sql == '') {
508 $analyzed_sql = array();
511 // can the result be sorted?
512 if ($is_display['sort_lnk'] == '1') {
515 $unsorted_sql_query = $sql_query;
516 if (isset($analyzed_sql[0]['unsorted_query'])) {
517 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
519 // Handles the case of multiple clicks on a column's header
520 // which would add many spaces before "ORDER BY" in the
522 $unsorted_sql_query = trim($unsorted_sql_query);
524 // sorting by indexes, only if it makes sense (only one table ref)
525 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
526 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
527 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
529 // grab indexes data:
530 $indexes = PMA_Index
::getFromTable($table, $db);
532 // do we have any index?
535 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
536 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
538 if ($is_display['edit_lnk'] != 'nn') {
541 if ($is_display['del_lnk'] != 'nn') {
544 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
548 $span = $num_rows +
floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) +
1;
551 echo '<form action="sql.php" method="post">' . "\n";
552 echo PMA_generate_common_hidden_inputs($db, $table);
553 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
555 $local_order = (isset($sort_expression) ?
$sort_expression : '');
556 foreach ($indexes as $index) {
557 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
558 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
559 $used_index = $used_index ||
$local_order == $asc_sort ||
$local_order == $desc_sort;
560 echo '<option value="'
561 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
562 . '"' . ($local_order == $asc_sort ?
' selected="selected"' : '')
563 . '>' . htmlspecialchars($index->getName()) . ' ('
564 . __('Ascending') . ')</option>';
565 echo '<option value="'
566 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
567 . '"' . ($local_order == $desc_sort ?
' selected="selected"' : '')
568 . '>' . htmlspecialchars($index->getName()) . ' ('
569 . __('Descending') . ')</option>';
571 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ?
'' : ' selected="selected"') . '>' . __('None') . '</option>';
572 echo '</select>' . "\n";
573 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
574 echo '</form>' . "\n";
580 $vertical_display['emptypre'] = 0;
581 $vertical_display['emptyafter'] = 0;
582 $vertical_display['textbtn'] = '';
584 // Display options (if we are not in print view)
585 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
586 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
587 if ($GLOBALS['cfg']['AjaxEnable']) {
588 echo ' class="ajax" ';
594 'sql_query' => $sql_query,
596 'display_options_form' => 1
598 echo PMA_generate_common_hidden_inputs($url_params);
600 PMA_generate_slider_effect('displayoptions',__('Options'));
603 echo '<div class="formelement">';
605 'P' => __('Partial texts'),
606 'F' => __('Full texts')
608 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
611 // prepare full/partial text button or link
612 if ($_SESSION['tmp_user_values']['display_text']=='F') {
613 // currently in fulltext mode so show the opposite link
614 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
615 $tmp_txt = __('Partial texts');
616 $url_params['display_text'] = 'P';
618 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
619 $tmp_txt = __('Full texts');
620 $url_params['display_text'] = 'F';
623 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
624 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
625 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
626 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
629 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
630 echo '<div class="formelement">';
632 'K' => __('Relational key'),
633 'D' => __('Relational display column')
635 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
639 echo '<div class="formelement">';
640 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
642 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
644 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
647 // I would have preferred to name this "display_transformation".
648 // This is the only way I found to be able to keep this setting sticky
649 // per SQL query, and at the same time have a default that displays
650 // the transformations.
651 echo '<div class="formelement">';
652 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
655 echo '<div class="formelement">';
657 'GEOM' => __('Geometry'),
658 'WKT' => __('Well Known Text'),
659 'WKB' => __('Well Known Binary')
661 PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
664 echo '<div class="clearfloat"></div>';
667 echo '<fieldset class="tblFooters">';
668 echo '<input type="submit" value="' . __('Go') . '" />';
674 // Start of form for multi-rows edit/delete/export
676 if ($is_display['del_lnk'] == 'dr' ||
$is_display['del_lnk'] == 'kp') {
677 echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
678 if ($GLOBALS['cfg']['AjaxEnable']) {
679 echo ' class="ajax" ';
682 echo PMA_generate_common_hidden_inputs($db, $table, 1);
683 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
686 echo '<table id="table_results" class="data';
687 if ($GLOBALS['cfg']['AjaxEnable']) {
691 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
692 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
693 echo '<thead><tr>' . "\n";
696 // 1. Displays the full/partial text button (part 1)...
697 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
698 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
699 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
703 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
708 // ... before the result table
709 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
710 && $is_display['text_btn'] == '1') {
711 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
712 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
713 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
715 <th colspan
="<?php echo $fields_cnt; ?>"></th
>
719 } // end horizontal/horizontalflipped mode
723 <th colspan
="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th
>
726 } // end vertical mode
729 // ... at the left column of the result table header if possible
731 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
732 && $is_display['text_btn'] == '1') {
733 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
734 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
735 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
737 <th
<?php
echo $colspan; ?
>><?php
echo $full_or_partial_text_link;?
></th
>
739 } // end horizontal/horizontalflipped mode
741 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
744 } // end vertical mode
747 // ... elseif no button, displays empty(ies) col(s) if required
748 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
749 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')) {
750 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
751 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
752 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
754 <td
<?php
echo $colspan; ?
>></td
>
756 } // end horizontal/horizontalfipped mode
758 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
759 } // end vertical mode
762 // ... elseif display an empty column if the actions links are disabled to match the rest of the table
763 elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none' && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
764 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
768 // 2. Displays the fields' name
769 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
770 // statement (see 2.1.3)
772 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
773 // Do not show comments, if using horizontalflipped mode, because of space usage
774 if ($GLOBALS['cfg']['ShowBrowseComments']
775 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
776 $comments_map = array();
777 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
778 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
779 $tb = $tbl['table_true_name'];
780 $comments_map[$tb] = PMA_getComments($db, $tb);
786 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
787 require_once './libraries/transformations.lib.php';
788 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
791 // See if we have to highlight any header fields of a WHERE query.
792 // Uses SQL-Parser results.
793 $highlight_columns = array();
794 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
795 isset($analyzed_sql[0]['where_clause_identifiers'])) {
798 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
799 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
800 $highlight_columns[$wci] = 'true';
805 if (PMA_isSelect()) {
806 // prepare to get the column order, if available
807 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
808 $col_order = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_ORDER
);
809 $col_visib = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_VISIB
);
815 for ($j = 0; $j < $fields_cnt; $j++
) {
816 // assign $i with appropriate column order
817 $i = $col_order ?
$col_order[$j] : $j;
818 // See if this column should get highlight because it's used in the
820 if (isset($highlight_columns[$fields_meta[$i]->name
]) ||
isset($highlight_columns[PMA_backquote($fields_meta[$i]->name
)])) {
821 $condition_field = true;
823 $condition_field = false;
826 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
827 if (isset($comments_map) &&
828 isset($comments_map[$fields_meta[$i]->table
]) &&
829 isset($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
])) {
830 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
]) . '</span>';
835 // 2.1 Results can be sorted
836 if ($is_display['sort_lnk'] == '1') {
838 // 2.1.1 Checks if the table name is required; it's the case
839 // for a query with a "JOIN" statement and if the column
840 // isn't aliased, or in queries like
841 // SELECT `1`.`master_field` , `2`.`master_field`
842 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
844 if (isset($fields_meta[$i]->table
) && strlen($fields_meta[$i]->table
)) {
845 $sort_tbl = PMA_backquote($fields_meta[$i]->table
) . '.';
850 // 2.1.2 Checks if the current column is used to sort the
852 // the orgname member does not exist for all MySQL versions
853 // but if found, it's the one on which to sort
854 $name_to_use_in_sort = $fields_meta[$i]->name
;
856 if (isset($fields_meta[$i]->orgname
) && strlen($fields_meta[$i]->orgname
)) {
857 $name_to_use_in_sort = $fields_meta[$i]->orgname
;
860 // $name_to_use_in_sort might contain a space due to
861 // formatting of function expressions like "COUNT(name )"
862 // so we remove the space in this situation
863 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
865 if (empty($sort_expression)) {
868 // Field name may be preceded by a space, or any number
869 // of characters followed by a dot (tablename.fieldname)
870 // so do a direct comparison for the sort expression;
871 // this avoids problems with queries like
872 // "SELECT id, count(id)..." and clicking to sort
873 // on id or on count(id).
874 // Another query to test this:
875 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
876 // (and try clicking on each column's header twice)
877 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
878 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
880 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ?
true : false);
882 // 2.1.3 Check the field name for a bracket.
883 // If it contains one, it's probably a function column
884 // like 'COUNT(`field`)'
885 // It still might be a column name of a view. See bug #3383711
887 if (strpos($name_to_use_in_sort, '(') !== false && ! $is_orgname) {
888 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
890 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
892 unset($name_to_use_in_sort);
895 // 2.1.4 Do define the sorting URL
897 // patch #455484 ("Smart" order)
898 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
899 if ($GLOBALS['cfg']['Order'] === 'SMART') {
900 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type
)) ?
'DESC' : 'ASC';
902 $sort_order .= $GLOBALS['cfg']['Order'];
905 } elseif ('DESC' == $sort_direction) {
906 $sort_order .= ' ASC';
907 $order_img = ' <img class="icon ic_s_desc" src="themes/dot.gif" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
909 $sort_order .= ' DESC';
910 $order_img = ' <img class="icon ic_s_asc" src="themes/dot.gif" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
913 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
914 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
916 $sorted_sql_query = $unsorted_sql_query . $sort_order;
918 $_url_params = array(
921 'sql_query' => $sorted_sql_query,
922 'session_max_rows' => $session_max_rows
924 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
926 // 2.1.5 Displays the sorting URL
927 // enable sort order swapping for image
928 $order_link_params = array();
929 if (isset($order_img) && $order_img!='') {
930 if (strstr($order_img, 'asc')) {
931 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
932 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
933 } elseif (strstr($order_img, 'desc')) {
934 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
935 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
938 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
939 if (PMA_USR_BROWSER_AGENT
== 'IE') {
940 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
942 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
945 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
946 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
947 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
949 $order_link_params['title'] = __('Sort');
950 $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
));
951 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
953 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
954 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
957 $th_class[] = 'draggable';
958 if ($col_visib && !$col_visib[$j]) {
959 $th_class[] = 'hide';
961 if ($condition_field) {
962 $th_class[] = 'condition';
964 $th_class[] = 'column_heading';
965 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
966 $th_class[] = 'pointer';
968 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
969 $th_class[] = 'marker';
971 echo ' class="' . implode(' ', $th_class) . '"';
973 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
974 echo ' valign="bottom"';
976 echo '>' . $order_link . $comments . '</th>';
978 $vertical_display['desc'][] = ' <th '
980 . ($condition_field ?
' condition' : '')
982 . $order_link . $comments . ' </th>' . "\n";
985 // 2.2 Results can't be sorted
987 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
988 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
991 $th_class[] = 'draggable';
992 if ($col_visib && !$col_visib[$j]) {
993 $th_class[] = 'hide';
995 if ($condition_field) {
996 $th_class[] = 'condition';
998 echo ' class="' . implode(' ', $th_class) . '"';
999 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1000 echo ' valign="bottom"';
1002 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1003 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
1004 echo ' style="direction: ltr; writing-mode: tb-rl;"';
1007 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1008 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
1009 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name
), '<br />');
1011 echo htmlspecialchars($fields_meta[$i]->name
);
1013 echo "\n" . $comments . '</th>';
1015 $vertical_display['desc'][] = ' <th '
1016 . 'class="draggable'
1017 . ($condition_field ?
' condition"' : '')
1019 . ' ' . htmlspecialchars($fields_meta[$i]->name
) . "\n"
1020 . $comments . ' </th>';
1024 // 3. Displays the needed checkboxes at the right
1025 // column of the result table header if possible and required...
1026 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1027 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')
1028 && $is_display['text_btn'] == '1') {
1029 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 1;
1030 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1031 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1034 <th
<?php
echo $colspan; ?
>><?php
echo $full_or_partial_text_link;?
>
1037 } // end horizontal/horizontalflipped mode
1039 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
1042 } // end vertical mode
1045 // ... elseif no button, displays empty columns if required
1046 // (unless coming from Browse mode print view)
1047 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1048 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
1049 && (!$GLOBALS['is_header_sent'])) {
1050 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 1;
1051 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1052 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1055 <td
<?php
echo $colspan; ?
>></td
>
1057 } // end horizontal/horizontalflipped mode
1059 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
1060 } // end vertical mode
1063 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1064 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1072 } // end of the 'PMA_displayTableHeaders()' function
1076 * Prepares the display for a value
1078 * @param string $class class of table cell
1079 * @param bool $condition_field whether to add CSS class condition
1080 * @param string $value value to display
1082 * @return string the td
1084 function PMA_buildValueDisplay($class, $condition_field, $value)
1086 return '<td align="left"' . ' class="' . $class . ($condition_field ?
' condition' : '') . '">' . $value . '</td>';
1090 * Prepares the display for a null value
1092 * @param string $class class of table cell
1093 * @param bool $condition_field whether to add CSS class condition
1095 * @return string the td
1097 function PMA_buildNullDisplay($class, $condition_field)
1099 // the null class is needed for inline editing
1100 return '<td align="right"' . ' class="' . $class . ($condition_field ?
' condition' : '') . ' null"><i>NULL</i></td>';
1104 * Prepares the display for an empty value
1106 * @param string $class class of table cell
1107 * @param bool $condition_field whether to add CSS class condition
1108 * @param object $meta the meta-information about this field
1109 * @param string $align cell allignment
1111 * @return string the td
1113 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '')
1115 $nowrap = ' nowrap';
1116 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1120 * Adds the relavant classes.
1122 * @param string $class class of table cell
1123 * @param bool $condition_field whether to add CSS class condition
1124 * @param object $meta the meta-information about this field
1125 * @param string $nowrap avoid wrapping
1126 * @param bool $is_field_truncated is field truncated (display ...)
1127 * @param string $transform_function transformation function
1128 * @param string $default_function default transformation function
1130 * @return string the list of classes
1132 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '')
1134 // Define classes to be added to this data field based on the type of data
1136 if (strpos($meta->flags
, 'enum') !== false) {
1137 $enum_class = ' enum';
1141 if (strpos($meta->flags
, 'set') !== false) {
1142 $set_class = ' set';
1146 if (strpos($meta->type
, 'bit') !== false) {
1147 $bit_class = ' bit';
1150 $mime_type_class = '';
1151 if (isset($meta->mimetype
)) {
1152 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype
);
1155 $result = $class . ($condition_field ?
' condition' : '') . $nowrap
1156 . ' ' . ($is_field_truncated ?
' truncated' : '')
1157 . ($transform_function != $default_function ?
' transformed' : '')
1158 . $enum_class . $set_class . $bit_class . $mime_type_class;
1163 * Displays the body of the results table
1165 * @param integer &$dt_result the link id associated to the query which results have
1167 * @param array &$is_display which elements to display
1168 * @param array $map the list of relations
1169 * @param array $analyzed_sql the analyzed query
1171 * @return boolean always true
1173 * @global string $db the database name
1174 * @global string $table the table name
1175 * @global string $goto the URL to go back in case of errors
1176 * @global string $sql_query the SQL query
1177 * @global array $fields_meta the list of fields properties
1178 * @global integer $fields_cnt the total number of fields returned by
1180 * @global array $vertical_display informations used with vertical display
1182 * @global array $highlight_columns column names to highlight
1183 * @global array $row current row data
1187 * @see PMA_displayTable()
1189 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
1191 global $db, $table, $goto;
1192 global $sql_query, $fields_meta, $fields_cnt;
1193 global $vertical_display, $highlight_columns;
1194 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1196 $url_sql_query = $sql_query;
1198 // query without conditions to shorten URLs when needed, 200 is just
1199 // guess, it should depend on remaining URL length
1201 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1202 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1203 strlen($sql_query) > 200) {
1205 $url_sql_query = 'SELECT ';
1206 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1207 $url_sql_query .= ' DISTINCT ';
1209 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1210 if (!empty($analyzed_sql[0]['from_clause'])) {
1211 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1215 if (! is_array($map)) {
1219 $vertical_display['edit'] = array();
1220 $vertical_display['copy'] = array();
1221 $vertical_display['delete'] = array();
1222 $vertical_display['data'] = array();
1223 $vertical_display['row_delete'] = array();
1224 // name of the class added to all inline editable elements
1225 $inline_edit_class = 'inline_edit';
1227 // prepare to get the column order, if available
1228 if (PMA_isSelect()) {
1229 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1230 $col_order = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_ORDER
);
1231 $col_visib = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_VISIB
);
1237 // Correction University of Virginia 19991216 in the while below
1238 // Previous code assumed that all tables have keys, specifically that
1239 // the phpMyAdmin GUI should support row delete/edit only for such
1241 // Although always using keys is arguably the prescribed way of
1242 // defining a relational table, it is not required. This will in
1243 // particular be violated by the novice.
1244 // We want to encourage phpMyAdmin usage by such novices. So the code
1245 // below has been changed to conditionally work as before when the
1246 // table being displayed has one or more keys; but to display
1247 // delete/edit options correctly for tables without keys.
1250 while ($row = PMA_DBI_fetch_row($dt_result)) {
1251 // "vertical display" mode stuff
1252 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no %
$_SESSION['tmp_user_values']['repeat_cells'])
1253 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1254 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1257 if ($vertical_display['emptypre'] > 0) {
1258 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1259 .' </th>' . "\n";
1260 } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1261 echo ' <th></th>' . "\n";
1264 foreach ($vertical_display['desc'] as $val) {
1268 if ($vertical_display['emptyafter'] > 0) {
1269 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1270 .' </th>' . "\n";
1272 echo '</tr>' . "\n";
1275 $alternating_color_class = ($odd_row ?
'odd' : 'even');
1276 $odd_row = ! $odd_row;
1278 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1279 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1280 // pointer code part
1281 echo '<tr class="' . $alternating_color_class . '">';
1285 // 1. Prepares the row
1286 // 1.1 Results from a "SELECT" statement -> builds the
1287 // WHERE clause to use in links (a unique key if possible)
1289 * @todo $where_clause could be empty, for example a table
1290 * with only one field and it's a BLOB; in this case,
1291 * avoid to display the delete and edit links
1293 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1294 $where_clause_html = urlencode($where_clause);
1296 // 1.2 Defines the URLs for the modify/delete link(s)
1298 if ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn') {
1299 // We need to copy the value or else the == 'both' check will always return true
1301 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1302 $iconic_spacer = '<div class="nowrap">';
1304 $iconic_spacer = '';
1307 // 1.2.1 Modify link(s)
1308 if ($is_display['edit_lnk'] == 'ur') { // update row case
1309 $_url_params = array(
1312 'where_clause' => $where_clause,
1313 'clause_is_unique' => $clause_is_unique,
1314 'sql_query' => $url_sql_query,
1315 'goto' => 'sql.php',
1317 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params +
array('default_action' => 'update'));
1318 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params +
array('default_action' => 'insert'));
1320 $edit_str = PMA_getIcon('b_edit.png', __('Edit'));
1321 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'));
1323 // Class definitions required for inline editing jQuery scripts
1324 $edit_anchor_class = "edit_row_anchor";
1325 if ( $clause_is_unique == 0) {
1326 $edit_anchor_class .= ' nonunique';
1330 // 1.2.2 Delete/Kill link(s)
1331 if ($is_display['del_lnk'] == 'dr') { // delete row case
1332 $_url_params = array(
1335 'sql_query' => $url_sql_query,
1336 'message_to_show' => __('The row has been deleted'),
1337 'goto' => (empty($goto) ?
'tbl_sql.php' : $goto),
1339 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1341 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1342 . ' WHERE ' . $where_clause . ($clause_is_unique ?
'' : ' LIMIT 1');
1344 $_url_params = array(
1347 'sql_query' => $del_query,
1348 'message_to_show' => __('The row has been deleted'),
1349 'goto' => $lnk_goto,
1351 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1353 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1354 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1355 . ($clause_is_unique ?
'' : ' LIMIT 1');
1356 $del_str = PMA_getIcon('b_drop.png', __('Delete'));
1357 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1359 $_url_params = array(
1362 'sql_query' => $url_sql_query,
1363 'goto' => 'main.php',
1365 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1367 $_url_params = array(
1369 'sql_query' => 'KILL ' . $row[0],
1370 'goto' => $lnk_goto,
1372 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1373 $del_query = 'KILL ' . $row[0];
1374 $js_conf = 'KILL ' . $row[0];
1375 $del_str = PMA_getIcon('b_drop.png', __('Kill'));
1378 // 1.3 Displays the links at left if required
1379 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1380 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1381 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1382 if (! isset($js_conf)) {
1385 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);
1386 } else if (($GLOBALS['cfg']['RowActionLinks'] == 'none')
1387 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1388 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1389 if (! isset($js_conf)) {
1392 echo PMA_generateCheckboxAndLinks('none', $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);
1396 // 2. Displays the rows' values
1398 for ($j = 0; $j < $fields_cnt; ++
$j) {
1399 // assign $i with appropriate column order
1400 $i = $col_order ?
$col_order[$j] : $j;
1402 $meta = $fields_meta[$i];
1403 $not_null_class = $meta->not_null ?
'not_null' : '';
1404 $relation_class = isset($map[$meta->name
]) ?
'relation' : '';
1405 $hide_class = ($col_visib && !$col_visib[$j] &&
1406 // hide per <td> only if the display direction is not vertical
1407 $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ?
'hide' : '';
1409 $is_field_truncated = false;
1410 //If the previous column had blob data, we need to reset the class
1411 // to $inline_edit_class
1412 $class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $relation_class; //' ' . $alternating_color_class .
1414 // See if this column should get highlight because it's used in the
1416 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name
]) ||
isset($highlight_columns[PMA_backquote($meta->name
)]))) {
1417 $condition_field = true;
1419 $condition_field = false;
1422 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) ||
($GLOBALS['printview'] != '1'))) {
1423 // the row number corresponds to a data row, not HTML table row
1424 $class .= ' row_' . $row_no;
1425 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1426 $class .= ' vpointer';
1428 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1429 $class .= ' vmarker';
1433 // Wrap MIME-transformations. [MIME]
1434 $default_function = 'default_function'; // default_function
1435 $transform_function = $default_function;
1436 $transform_options = array();
1438 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1440 if (isset($GLOBALS['mime_map'][$meta->name
]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name
]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name
]['transformation'])) {
1441 $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name
]['transformation']);
1443 if (file_exists('./libraries/transformations/' . $include_file)) {
1444 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name
]['transformation']);
1446 require_once './libraries/transformations/' . $include_file;
1448 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1449 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1450 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name
]['transformation_options']) ?
$GLOBALS['mime_map'][$meta->name
]['transformation_options'] : ''));
1451 $meta->mimetype
= str_replace('_', '/', $GLOBALS['mime_map'][$meta->name
]['mimetype']);
1453 } // end if file_exists
1454 } // end if transformation is set
1455 } // end if mime/transformation works.
1457 $_url_params = array(
1460 'where_clause' => $where_clause,
1461 'transform_key' => $meta->name
,
1464 if (! empty($sql_query)) {
1465 $_url_params['sql_query'] = $url_sql_query;
1468 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1471 if ($meta->numeric == 1) {
1473 // if two fields have the same name (this is possible
1474 // with self-join queries, for example), using $meta->name
1475 // will show both fields NULL even if only one is NULL,
1476 // so use the $pointer
1478 if (! isset($row[$i]) ||
is_null($row[$i])) {
1479 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1480 } elseif ($row[$i] != '') {
1482 $nowrap = ' nowrap';
1483 $where_comparison = ' = ' . $row[$i];
1485 $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);
1487 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1492 } elseif (stristr($meta->type
, 'BLOB')) {
1493 // PMA_mysql_fetch_fields returns BLOB in place of
1494 // TEXT fields type so we have to ensure it's really a BLOB
1495 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1497 // remove 'inline_edit' from $class as we can't edit binary data.
1498 $class = str_replace('inline_edit', '', $class);
1500 if (stristr($field_flags, 'BINARY')) {
1501 if (! isset($row[$i]) ||
is_null($row[$i])) {
1502 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1504 // for blobstreaming
1505 // if valid BS reference exists
1506 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1507 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1509 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ?
$row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1512 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1517 if (! isset($row[$i]) ||
is_null($row[$i])) {
1518 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1519 } elseif ($row[$i] != '') {
1520 // if a transform function for blob is set, none of these replacements will be made
1521 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1522 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1523 $is_field_truncated = true;
1525 // displays all space characters, 4 space
1526 // characters for tabulations and <cr>/<lf>
1527 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1529 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1531 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1535 } elseif ($meta->type
== 'geometry') {
1537 // Remove 'inline_edit' from $class as we do not allow to inline-edit geometry data.
1538 $class = str_replace('inline_edit', '', $class);
1540 // Display as [GEOMETRY - (size)]
1541 if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
1542 $geometry_text = PMA_handle_non_printable_contents(
1543 'GEOMETRY', (isset($row[$i]) ?
$row[$i] : ''), $transform_function,
1544 $transform_options, $default_function, $meta
1546 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
1547 $class, $condition_field, $geometry_text
1550 // Display in Well Known Text(WKT) format.
1551 } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
1552 // Convert to WKT format
1553 $wktsql = "SELECT ASTEXT (GeomFromWKB(x'" . PMA_substr(bin2hex($row[$i]), 8) . "'))";
1554 $wktresult = PMA_DBI_try_query($wktsql, null, PMA_DBI_QUERY_STORE
);
1555 $wktarr = PMA_DBI_fetch_row($wktresult, 0);
1556 $wktval = $wktarr[0];
1557 @PMA_DBI_free_result
($wktresult);
1559 if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
1560 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1562 $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1563 $is_field_truncated = true;
1566 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1567 $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
1568 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1571 // Display in Well Known Binary(WKB) format.
1573 if ($_SESSION['tmp_user_values']['display_binary']) {
1574 if ($_SESSION['tmp_user_values']['display_binary_as_hex']
1575 && PMA_contains_nonprintable_ascii($row[$i])
1577 $wkbval = PMA_substr(bin2hex($row[$i]), 8);
1579 $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1582 if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
1583 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1585 $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1586 $is_field_truncated = true;
1589 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1590 $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
1591 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1594 $wkbval = PMA_handle_non_printable_contents(
1595 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
1597 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
1601 // n o t n u m e r i c a n d n o t B L O B
1603 if (! isset($row[$i]) ||
is_null($row[$i])) {
1604 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1605 } elseif ($row[$i] != '') {
1606 // support blanks in the key
1607 $relation_id = $row[$i];
1609 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1610 // (unless it's a link-type transformation)
1611 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1612 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1613 $is_field_truncated = true;
1616 // displays special characters from binaries
1617 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1618 if (isset($meta->_type
) && $meta->_type
=== MYSQLI_TYPE_BIT
) {
1619 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length
);
1620 // some results of PROCEDURE ANALYSE() are reported as
1621 // being BINARY but they are quite readable,
1622 // so don't treat them as BINARY
1623 } elseif (stristr($field_flags, 'BINARY') && $meta->type
== 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1624 if ($_SESSION['tmp_user_values']['display_binary']) {
1625 // user asked to see the real contents of BINARY
1627 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1628 $row[$i] = bin2hex($row[$i]);
1630 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1633 // we show the BINARY message and field's size
1634 // (or maybe use a transformation)
1635 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1639 // transform functions may enable no-wrapping:
1640 $function_nowrap = $transform_function . '_nowrap';
1641 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ?
$function_nowrap($transform_options) : false);
1643 // do not wrap if date field type
1644 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type
) ||
$bool_nowrap) ?
' nowrap' : '');
1645 $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
1646 $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);
1649 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1653 // output stored cell
1654 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1655 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1656 echo $vertical_display['data'][$row_no][$i];
1659 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1660 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1662 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1666 // 3. Displays the modify/delete links on the right if required
1667 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1668 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1669 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1670 if (! isset($js_conf)) {
1673 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);
1676 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1677 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1683 // 4. Gather links of del_urls and edit_urls in an array for later
1685 if (! isset($vertical_display['edit'][$row_no])) {
1686 $vertical_display['edit'][$row_no] = '';
1687 $vertical_display['copy'][$row_no] = '';
1688 $vertical_display['delete'][$row_no] = '';
1689 $vertical_display['row_delete'][$row_no] = '';
1691 $vertical_class = ' row_' . $row_no;
1692 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1693 $vertical_class .= ' vpointer';
1695 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1696 $vertical_class .= ' vmarker';
1699 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1700 $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);
1702 unset($vertical_display['row_delete'][$row_no]);
1705 if (isset($edit_url)) {
1706 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1708 unset($vertical_display['edit'][$row_no]);
1711 if (isset($copy_url)) {
1712 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1714 unset($vertical_display['copy'][$row_no]);
1717 if (isset($del_url)) {
1718 if (! isset($js_conf)) {
1721 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1723 unset($vertical_display['delete'][$row_no]);
1726 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ?
"\n" : '');
1730 // this is needed by PMA_displayTable() to generate the proper param
1731 // in the multi-edit and multi-delete form
1732 return $clause_is_unique;
1733 } // end of the 'PMA_displayTableBody()' function
1737 * Do display the result table with the vertical direction mode.
1739 * @return boolean always true
1741 * @global array $vertical_display the information to display
1745 * @see PMA_displayTable()
1747 function PMA_displayVerticalTable()
1749 global $vertical_display;
1751 // Displays "multi row delete" link at top if required
1752 if (($GLOBALS['cfg']['RowActionLinks'] != 'right')
1753 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1755 if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1756 // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
1757 echo '<th></th>' . "\n";
1759 echo $vertical_display['textbtn'];
1760 $cell_displayed = 0;
1761 foreach ($vertical_display['row_delete'] as $val) {
1762 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1764 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
' rowspan="4"' : '') .
1767 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1770 echo '</tr>' . "\n";
1773 // Displays "edit" link at top if required
1774 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1775 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1777 if (! is_array($vertical_display['row_delete'])) {
1778 echo $vertical_display['textbtn'];
1780 foreach ($vertical_display['edit'] as $val) {
1783 echo '</tr>' . "\n";
1786 // Displays "copy" link at top if required
1787 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1788 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 ||
!empty($vertical_display['textbtn']))) {
1790 if (! is_array($vertical_display['row_delete'])) {
1791 echo $vertical_display['textbtn'];
1793 foreach ($vertical_display['copy'] as $val) {
1796 echo '</tr>' . "\n";
1799 // Displays "delete" link at top if required
1800 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1801 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1803 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1804 echo $vertical_display['textbtn'];
1806 foreach ($vertical_display['delete'] as $val) {
1809 echo '</tr>' . "\n";
1812 if (PMA_isSelect()) {
1813 // prepare to get the column order, if available
1814 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1815 $col_order = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_ORDER
);
1816 $col_visib = $pmatable->getUiProp(PMA_Table
::PROP_COLUMN_VISIB
);
1823 foreach ($vertical_display['desc'] AS $j => $val) {
1824 // assign appropriate key with current column order
1825 $key = $col_order ?
$col_order[$j] : $j;
1827 echo '<tr' . (($col_visib && !$col_visib[$j]) ?
' class="hide"' : '') . '>' . "\n";
1830 $cell_displayed = 0;
1831 foreach ($vertical_display['rowdata'][$key] as $subval) {
1832 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1840 echo '</tr>' . "\n";
1843 // Displays "multi row delete" link at bottom if required
1844 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1845 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1847 echo $vertical_display['textbtn'];
1848 $cell_displayed = 0;
1849 foreach ($vertical_display['row_delete'] as $val) {
1850 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1852 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
' rowspan="4"' : '') .
1856 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1859 echo '</tr>' . "\n";
1862 // Displays "edit" link at bottom if required
1863 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1864 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1866 if (! is_array($vertical_display['row_delete'])) {
1867 echo $vertical_display['textbtn'];
1869 foreach ($vertical_display['edit'] as $val) {
1872 echo '</tr>' . "\n";
1875 // Displays "copy" link at bottom if required
1876 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1877 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 ||
!empty($vertical_display['textbtn']))) {
1879 if (! is_array($vertical_display['row_delete'])) {
1880 echo $vertical_display['textbtn'];
1882 foreach ($vertical_display['copy'] as $val) {
1885 echo '</tr>' . "\n";
1888 // Displays "delete" link at bottom if required
1889 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' ||
$GLOBALS['cfg']['RowActionLinks'] == 'both')
1890 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1892 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1893 echo $vertical_display['textbtn'];
1895 foreach ($vertical_display['delete'] as $val) {
1898 echo '</tr>' . "\n";
1902 } // end of the 'PMA_displayVerticalTable' function
1906 * @todo make maximum remembered queries configurable
1907 * @todo move/split into SQL class!?
1908 * @todo currently this is called twice unnecessary
1909 * @todo ignore LIMIT and ORDER in query!?
1911 function PMA_displayTable_checkConfigParams()
1913 $sql_md5 = md5($GLOBALS['sql_query']);
1915 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1917 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1918 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1919 unset($_REQUEST['disp_direction']);
1920 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1921 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1924 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1925 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1926 unset($_REQUEST['repeat_cells']);
1927 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1928 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1931 // as this is a form value, the type is always string so we cannot
1932 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1933 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1934 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1935 ||
$_REQUEST['session_max_rows'] == 'all') {
1936 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1937 unset($_REQUEST['session_max_rows']);
1938 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1939 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1942 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1943 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1944 unset($_REQUEST['pos']);
1945 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1946 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1949 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1950 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1951 unset($_REQUEST['display_text']);
1952 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1953 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1956 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1957 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1958 unset($_REQUEST['relational_display']);
1959 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1960 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1963 if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
1964 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
1965 unset($_REQUEST['geometry_display']);
1966 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
1967 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
1970 if (isset($_REQUEST['display_binary'])) {
1971 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1972 unset($_REQUEST['display_binary']);
1973 } elseif (isset($_REQUEST['display_options_form'])) {
1974 // we know that the checkbox was unchecked
1975 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1977 // selected by default because some operations like OPTIMIZE TABLE
1978 // and all queries involving functions return "binary" contents,
1979 // according to low-level field flags
1980 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1983 if (isset($_REQUEST['display_binary_as_hex'])) {
1984 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1985 unset($_REQUEST['display_binary_as_hex']);
1986 } elseif (isset($_REQUEST['display_options_form'])) {
1987 // we know that the checkbox was unchecked
1988 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1990 // display_binary_as_hex config option
1991 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1992 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1996 if (isset($_REQUEST['display_blob'])) {
1997 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1998 unset($_REQUEST['display_blob']);
1999 } elseif (isset($_REQUEST['display_options_form'])) {
2000 // we know that the checkbox was unchecked
2001 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
2004 if (isset($_REQUEST['hide_transformation'])) {
2005 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
2006 unset($_REQUEST['hide_transformation']);
2007 } elseif (isset($_REQUEST['display_options_form'])) {
2008 // we know that the checkbox was unchecked
2009 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
2012 // move current query to the last position, to be removed last
2013 // so only least executed query will be removed if maximum remembered queries
2015 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
2016 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
2017 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
2019 // do not exceed a maximum number of queries to remember
2020 if (count($_SESSION['tmp_user_values']['query']) > 10) {
2021 array_shift($_SESSION['tmp_user_values']['query']);
2022 //echo 'deleting one element ...';
2025 // populate query configuration
2026 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
2027 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
2028 $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
2029 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ?
true : false;
2030 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ?
true : false;
2031 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ?
true : false;
2032 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ?
true : false;
2033 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
2034 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
2035 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
2036 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
2041 var_dump($_SESSION['tmp_user_values']);
2047 * Displays a table of results returned by a SQL query.
2048 * This function is called by the "sql.php" script.
2050 * @param integer the link id associated to the query which results have
2052 * @param array the display mode
2053 * @param array the analyzed query
2055 * @global string $db the database name
2056 * @global string $table the table name
2057 * @global string $goto the URL to go back in case of errors
2058 * @global string $sql_query the current SQL query
2059 * @global integer $num_rows the total number of rows returned by the
2061 * @global integer $unlim_num_rows the total number of rows returned by the
2062 * SQL query without any programmatically
2063 * appended "LIMIT" clause
2064 * @global array $fields_meta the list of fields properties
2065 * @global integer $fields_cnt the total number of fields returned by
2067 * @global array $vertical_display informations used with vertical display
2069 * @global array $highlight_columns column names to highlight
2070 * @global array $cfgRelation the relation settings
2074 * @see PMA_showMessage(), PMA_setDisplayMode(),
2075 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2076 * PMA_displayTableBody(), PMA_displayResultsOperations()
2078 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
2080 global $db, $table, $goto;
2081 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
2082 global $vertical_display, $highlight_columns;
2083 global $cfgRelation;
2086 // why was this called here? (already called from sql.php)
2087 //PMA_displayTable_checkConfigParams();
2090 * @todo move this to a central place
2091 * @todo for other future table types
2093 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
2096 && ! isset($analyzed_sql[0]['queryflags']['union'])
2097 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
2098 && (empty($analyzed_sql[0]['where_clause'])
2099 ||
$analyzed_sql[0]['where_clause'] == '1 ')) {
2100 // "j u s t b r o w s i n g"
2102 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')));
2108 // 1. ----- Prepares the work -----
2110 // 1.1 Gets the informations about which functionalities should be
2113 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
2115 // 1.2 Defines offsets for the next and previous pages
2116 if ($is_display['nav_bar'] == '1') {
2117 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
2121 $pos_next = $_SESSION['tmp_user_values']['pos'] +
$_SESSION['tmp_user_values']['max_rows'];
2122 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
2123 if ($pos_prev < 0) {
2129 // 1.3 Find the sort expression
2131 // we need $sort_expression and $sort_expression_nodirection
2132 // even if there are many table references
2133 if (! empty($analyzed_sql[0]['order_by_clause'])) {
2134 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
2136 * Get rid of ASC|DESC
2138 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
2139 $sort_expression_nodirection = isset($matches[1]) ?
trim($matches[1]) : $sort_expression;
2140 $sort_direction = isset($matches[2]) ?
trim($matches[2]) : '';
2143 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
2146 // 1.4 Prepares display of first and last value of the sorted column
2148 if (! empty($sort_expression_nodirection)) {
2149 if (strpos($sort_expression_nodirection, '.') === false) {
2150 $sort_table = $table;
2151 $sort_column = $sort_expression_nodirection;
2153 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
2155 $sort_table = PMA_unQuote($sort_table);
2156 $sort_column = PMA_unQuote($sort_column);
2157 // find the sorted column index in row result
2158 // (this might be a multi-table query)
2159 $sorted_column_index = false;
2160 foreach ($fields_meta as $key => $meta) {
2161 if ($meta->table
== $sort_table && $meta->name
== $sort_column) {
2162 $sorted_column_index = $key;
2166 if ($sorted_column_index !== false) {
2167 // fetch first row of the result set
2168 $row = PMA_DBI_fetch_row($dt_result);
2169 // initializing default arguments
2170 $default_function = 'default_function';
2171 $transform_function = $default_function;
2172 $transform_options = array();
2173 // check for non printable sorted row data
2174 $meta = $fields_meta[$sorted_column_index];
2175 if (stristr($meta->type
, 'BLOB') ||
$meta->type
== 'geometry') {
2176 $column_for_first_row = PMA_handle_non_printable_contents($meta->type
, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2178 $column_for_first_row = $row[$sorted_column_index];
2180 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2181 // fetch last row of the result set
2182 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2183 $row = PMA_DBI_fetch_row($dt_result);
2184 // check for non printable sorted row data
2185 $meta = $fields_meta[$sorted_column_index];
2186 if (stristr($meta->type
, 'BLOB') ||
$meta->type
== 'geometry') {
2187 $column_for_last_row = PMA_handle_non_printable_contents($meta->type
, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2189 $column_for_last_row = $row[$sorted_column_index];
2191 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2192 // reset to first row for the loop in PMA_displayTableBody()
2193 PMA_DBI_data_seek($dt_result, 0);
2194 // we could also use here $sort_expression_nodirection
2195 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2196 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2198 unset($sorted_column_index, $sort_table, $sort_column);
2201 // 2. ----- Displays the top of the page -----
2203 // 2.1 Displays a messages with position informations
2204 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2205 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2206 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2210 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' ||
$pos_next > $total)
2214 if (PMA_Table
::isView($db, $table)
2215 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2216 $message = PMA_Message
::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2217 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2218 $message->addParam('[/a]');
2219 $message_view_warning = PMA_showHint($message);
2221 $message_view_warning = false;
2224 $message = PMA_Message
::success(__('Showing rows'));
2225 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2226 if ($message_view_warning) {
2227 $message->addMessage('...', ' - ');
2228 $message->addMessage($message_view_warning);
2229 $message->addMessage('(');
2231 $message->addMessage($last_shown_rec, ' - ');
2232 $message->addMessage(' (');
2233 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2234 $message->addString(__('total'));
2235 if (!empty($after_count)) {
2236 $message->addMessage($after_count);
2238 $message->addMessage($selectstring, '');
2239 $message->addMessage(', ', '');
2242 $messagge_qt = PMA_Message
::notice(__('Query took %01.4f sec'));
2243 $messagge_qt->addParam($GLOBALS['querytime']);
2245 $message->addMessage($messagge_qt, '');
2246 $message->addMessage(')', '');
2248 $message->addMessage(isset($sorted_column_message) ?
$sorted_column_message : '', '');
2250 PMA_showMessage($message, $sql_query, 'success');
2252 } elseif (! isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2253 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2256 // 2.3 Displays the navigation bars
2257 if (! strlen($table)) {
2258 if (isset($analyzed_sql[0]['query_type'])
2259 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2260 // table does not always contain a real table name,
2261 // for example in MySQL 5.0.x, the query SHOW STATUS
2262 // returns STATUS as a table name
2263 $table = $fields_meta[0]->table
;
2269 if ($is_display['nav_bar'] == '1') {
2270 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2272 } elseif (! isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2273 echo "\n" . '<br /><br />' . "\n";
2276 // 2b ----- Get field references from Database -----
2277 // (see the 'relation' configuration variable)
2284 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2285 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2286 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2289 $tabs = '(\'' . join('\',\'', $target) . '\')';
2291 if (! strlen($table)) {
2294 // To be able to later display a link to the related table,
2295 // we verify both types of relations: either those that are
2296 // native foreign keys or those defined in the phpMyAdmin
2297 // configuration storage. If no PMA storage, we won't be able
2298 // to use the "column to display" notion (for example show
2299 // the name related to a numeric id).
2300 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2302 foreach ($exist_rel AS $master_field => $rel) {
2303 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2304 $map[$master_field] = array($rel['foreign_table'],
2305 $rel['foreign_field'],
2307 $rel['foreign_db']);
2313 // 3. ----- Displays the results table -----
2314 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2316 echo '<tbody>' . "\n";
2317 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2318 // vertical output case
2319 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2320 PMA_displayVerticalTable();
2322 unset($vertical_display);
2323 echo '</tbody>' . "\n";
2328 // 4. ----- Displays the link for multi-fields edit and delete
2330 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2332 $delete_text = $is_display['del_lnk'] == 'dr' ?
__('Delete') : __('Kill');
2334 $_url_params = array(
2337 'sql_query' => $sql_query,
2340 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2342 $_url_params['checkall'] = '1';
2343 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2345 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2346 $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
2347 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
2349 $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
2350 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
2352 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2353 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2354 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2355 echo '<img class="selectallarrow" width="38" height="22"'
2356 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2357 .' alt="' . __('With selected:') . '" />';
2359 echo $checkall_link . "\n"
2361 .$uncheckall_link . "\n"
2362 .'<i>' . __('With selected:') . '</i>' . "\n";
2364 PMA_buttonOrImage('submit_mult', 'mult_submit',
2365 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2366 PMA_buttonOrImage('submit_mult', 'mult_submit',
2367 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2368 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2369 PMA_buttonOrImage('submit_mult', 'mult_submit',
2370 'submit_mult_export', __('Export'),
2371 'b_tblexport.png', 'export');
2375 echo '<input type="hidden" name="sql_query"'
2376 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2378 if (! empty($GLOBALS['url_query'])) {
2379 echo '<input type="hidden" name="url_query"'
2380 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2383 echo '<input type="hidden" name="clause_is_unique"'
2384 .' value="' . $clause_is_unique . '" />' . "\n";
2386 echo '</form>' . "\n";
2389 // 5. ----- Displays the navigation bar at the bottom if required -----
2391 if ($is_display['nav_bar'] == '1') {
2392 echo '<br />' . "\n";
2393 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2394 } elseif (! isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2395 echo "\n" . '<br /><br />' . "\n";
2398 // 6. ----- Displays "Query results operations"
2399 if (! isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2400 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2402 } // end of the 'PMA_displayTable()' function
2404 function default_function($buffer)
2406 $buffer = htmlspecialchars($buffer);
2407 $buffer = str_replace("\011", ' ',
2408 str_replace(' ', ' ', $buffer));
2409 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2415 * Displays operations that are available on results.
2417 * @param array the display mode
2418 * @param array the analyzed query
2420 * @global string $db the database name
2421 * @global string $table the table name
2422 * @global string $sql_query the current SQL query
2423 * @global integer $unlim_num_rows the total number of rows returned by the
2424 * SQL query without any programmatically
2425 * appended "LIMIT" clause
2429 * @see PMA_showMessage(), PMA_setDisplayMode(),
2430 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2431 * PMA_displayTableBody(), PMA_displayResultsOperations()
2433 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql)
2435 global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
2437 $header_shown = false;
2438 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2440 if ($the_disp_mode[6] == '1' ||
$the_disp_mode[9] == '1') {
2441 // Displays "printable view" link if required
2442 if ($the_disp_mode[9] == '1') {
2444 if (!$header_shown) {
2446 $header_shown = true;
2449 $_url_params = array(
2453 'sql_query' => $sql_query,
2455 $url_query = PMA_generate_common_url($_url_params);
2457 echo PMA_linkOrButton(
2458 'sql.php' . $url_query,
2459 PMA_getIcon('b_print.png', __('Print view')),
2460 '', true, true, 'print_view') . "\n";
2462 if ($_SESSION['tmp_user_values']['display_text']) {
2463 $_url_params['display_text'] = 'F';
2464 echo PMA_linkOrButton(
2465 'sql.php' . PMA_generate_common_url($_url_params),
2466 PMA_getIcon('b_print.png', __('Print view (with full texts)')),
2467 '', true, true, 'print_view') . "\n";
2468 unset($_url_params['display_text']);
2470 } // end displays "printable view"
2474 // (the url_query has extra parameters that won't be used to export)
2475 // (the single_table parameter is used in display_export.lib.php
2476 // to hide the SQL and the structure export dialogs)
2477 // If the parser found a PROCEDURE clause
2478 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2479 // display the Export link).
2480 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2481 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2482 $_url_params['single_table'] = 'true';
2484 if (!$header_shown) {
2486 $header_shown = true;
2488 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2491 * At this point we don't know the table name; this can happen
2492 * for example with a query like
2493 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2494 * As a workaround we set in the table parameter the name of the
2495 * first table of this database, so that tbl_export.php and
2496 * the script it calls do not fail
2498 if (empty($_url_params['table']) && !empty($_url_params['db'])) {
2499 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2500 /* No result (probably no database selected) */
2501 if ($_url_params['table'] === FALSE) {
2502 unset($_url_params['table']);
2506 echo PMA_linkOrButton(
2507 'tbl_export.php' . PMA_generate_common_url($_url_params),
2508 PMA_getIcon('b_tblexport.png', __('Export')),
2509 '', true, true, '') . "\n";
2512 echo PMA_linkOrButton(
2513 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2514 PMA_getIcon('b_chart.png', __('Display chart')),
2515 '', true, true, '') . "\n";
2518 $geometry_found = false;
2519 // If atleast one geometry field is found
2520 foreach ($fields_meta as $meta) {
2521 if ($meta->type
== 'geometry') {
2522 $geometry_found = true;
2526 if ($geometry_found) {
2527 echo PMA_linkOrButton(
2528 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
2529 PMA_getIcon('b_globe.gif', __('Visualize GIS data')),
2530 '', true, true, '') . "\n";
2537 * @todo detect privileges to create a view
2538 * (but see 2006-01-19 note in display_create_table.lib.php,
2539 * I think we cannot detect db-specific privileges reliably)
2540 * Note: we don't display a Create view link if we found a PROCEDURE clause
2542 if (!$header_shown) {
2544 $header_shown = true;
2546 if (!PMA_DRIZZLE
&& !isset($analyzed_sql[0]['queryflags']['procedure'])) {
2547 echo PMA_linkOrButton(
2548 'view_create.php' . $url_query,
2549 PMA_getIcon('b_views.png', __('Create view')),
2550 '', true, true, '') . "\n";
2552 if ($header_shown) {
2553 echo '</fieldset><br />';
2558 * Verifies what to do with non-printable contents (binary or BLOB)
2561 * @param string $category BLOB|BINARY|GEOMETRY
2562 * @param string $content the binary content
2563 * @param string $transform_function transformation function
2564 * @param string $transform_options transformation parameters
2565 * @param string $default_function default transformation function
2566 * @param object $meta the meta-information about this field
2567 * @return mixed string or float
2569 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array())
2571 $result = '[' . $category;
2572 if (is_null($content)) {
2573 $result .= ' - NULL';
2575 } elseif (isset($content)) {
2576 $size = strlen($content);
2577 $display_size = PMA_formatByteDown($size, 3, 1);
2578 $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
2582 if (strpos($transform_function, 'octetstream')) {
2586 if ($default_function != $transform_function) {
2587 $result = $transform_function($result, $transform_options, $meta);
2589 $result = $default_function($result, array(), $meta);
2590 if (stristr($meta->type
, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2591 // in this case, restart from the original $content
2592 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2594 /* Create link to download */
2595 if (count($url_params) > 0) {
2596 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2604 * Prepares the displayable content of a data cell in Browse mode,
2605 * taking into account foreign key description field and transformations
2607 * @param string $class
2608 * @param string $condition_field
2609 * @param string $analyzed_sql
2610 * @param object $meta the meta-information about this field
2611 * @param string $map
2612 * @param string $data
2613 * @param string $transform_function
2614 * @param string $default_function
2615 * @param string $nowrap
2616 * @param string $where_comparison
2617 * @param bool $is_field_truncated
2618 * @return string formatted data
2620 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 )
2623 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2625 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2626 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2627 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2628 if (isset($alias) && strlen($alias)) {
2629 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2630 if ($alias == $meta->name
) {
2631 // this change in the parameter does not matter
2632 // outside of the function
2633 $meta->name
= $true_column;
2639 if (isset($map[$meta->name
])) {
2640 // Field to display from the foreign table?
2641 if (isset($map[$meta->name
][2]) && strlen($map[$meta->name
][2])) {
2642 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name
][2])
2643 . ' FROM ' . PMA_backquote($map[$meta->name
][3])
2644 . '.' . PMA_backquote($map[$meta->name
][0])
2645 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
2646 . $where_comparison;
2647 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE
);
2648 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2649 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2651 $dispval = __('Link not found');
2653 @PMA_DBI_free_result
($dispresult);
2656 } // end if... else...
2658 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2659 $result .= ($transform_function != $default_function ?
$transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[->' . $dispval . ']</code>';
2662 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2663 // user chose "relational key" in the display options, so
2664 // the title contains the display field
2665 $title = (! empty($dispval))?
' title="' . htmlspecialchars($dispval) . '"' : '';
2667 $title = ' title="' . htmlspecialchars($data) . '"';
2670 $_url_params = array(
2671 'db' => $map[$meta->name
][3],
2672 'table' => $map[$meta->name
][0],
2674 'sql_query' => 'SELECT * FROM '
2675 . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
2676 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
2677 . $where_comparison,
2679 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2680 . '"' . $title . '>';
2682 if ($transform_function != $default_function) {
2683 // always apply a transformation on the real data,
2684 // not on the display field
2685 $result .= $transform_function($data, $transform_options, $meta);
2687 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2688 // user chose "relational display field" in the
2689 // display options, so show display field in the cell
2690 $result .= $transform_function($dispval, array(), $meta);
2692 // otherwise display data in the cell
2693 $result .= $transform_function($data, array(), $meta);
2699 $result .= ($transform_function != $default_function ?
$transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2701 $result .= '</td>' . "\n";
2707 * Generates a checkbox for multi-row submits
2709 * @param string $del_url
2710 * @param array $is_display
2711 * @param string $row_no
2712 * @param string $where_clause_html
2713 * @param string $del_query
2714 * @param string $id_suffix
2715 * @param string $class
2716 * @return string the generated HTML
2719 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class)
2722 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2724 if (! empty($class)) {
2725 $ret .= 'class="' . $class . '"';
2727 $ret .= ' align="center">'
2728 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2729 . ' class="multi_checkbox"'
2730 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ?
'checked="checked"' : '') . ' />'
2737 * Generates an Edit link
2739 * @param string $edit_url
2740 * @param string $class
2741 * @param string $edit_str
2742 * @param string $where_clause
2743 * @param string $where_clause_html
2744 * @return string the generated HTML
2746 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html)
2749 if (! empty($edit_url)) {
2750 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2751 . PMA_linkOrButton($edit_url, $edit_str, array(), false);
2753 * Where clause for selecting this row uniquely is provided as
2754 * a hidden input. Used by jQuery scripts for handling inline editing
2756 if (! empty($where_clause)) {
2757 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2759 $ret .= '</span></td>';
2765 * Generates an Copy link
2767 * @param string $copy_url
2768 * @param string $copy_str
2769 * @param string $where_clause
2770 * @param string $where_clause_html
2771 * @return string the generated HTML
2773 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class)
2776 if (! empty($copy_url)) {
2778 if (! empty($class)) {
2779 $ret .= 'class="' . $class . '" ';
2781 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2782 . PMA_linkOrButton($copy_url, $copy_str, array(), false);
2784 * Where clause for selecting this row uniquely is provided as
2785 * a hidden input. Used by jQuery scripts for handling inline editing
2787 if (! empty($where_clause)) {
2788 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2790 $ret .= '</span></td>';
2796 * Generates a Delete link
2798 * @param string $del_url
2799 * @param string $del_str
2800 * @param string $js_conf
2801 * @param string $class
2802 * @return string the generated HTML
2804 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class)
2807 if (! empty($del_url)) {
2809 if (! empty($class)) {
2810 $ret .= 'class="' . $class . '" ';
2812 $ret .= 'align="center" ' . ' >'
2813 . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
2820 * Generates checkbox and links at some position (left or right)
2821 * (only called for horizontal mode)
2823 * @param string $position
2824 * @param string $del_url
2825 * @param array $is_display
2826 * @param string $row_no
2827 * @param string $where_clause
2828 * @param string $where_clause_html
2829 * @param string $del_query
2830 * @param string $id_suffix
2831 * @param string $edit_url
2832 * @param string $copy_url
2833 * @param string $class
2834 * @param string $edit_str
2835 * @param string $del_str
2836 * @param string $js_conf
2837 * @return string the generated HTML
2839 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)
2843 if ($position == 'left') {
2844 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2846 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2848 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2850 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2852 } elseif ($position == 'right') {
2853 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2855 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2857 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2859 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');
2860 } else { // $position == 'none'
2861 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');