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 synthetic value for display_mode (see a few
32 * lines above for explanations)
33 * @param integer the total number of rows returned by the SQL query
34 * without any programmatically appended "LIMIT" clause
35 * (just a copy of $unlim_num_rows if it exists, else
36 * computed inside this function)
38 * @return array an array with explicit indexes for all the display
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 // 2.0 Print view -> set all elements to false!
74 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
75 $do_display['edit_lnk'] = 'nn'; // no edit link
76 $do_display['del_lnk'] = 'nn'; // no delete link
77 $do_display['sort_lnk'] = (string) '0';
78 $do_display['nav_bar'] = (string) '0';
79 $do_display['ins_row'] = (string) '0';
80 $do_display['bkm_form'] = (string) '0';
81 $do_display['text_btn'] = (string) '0';
82 $do_display['pview_lnk'] = (string) '0';
84 // 2.1 Statement is a "SELECT COUNT", a
85 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
86 // contains a "PROC ANALYSE" part
87 elseif ($GLOBALS['is_count'] ||
$GLOBALS['is_analyse'] ||
$GLOBALS['is_maint'] ||
$GLOBALS['is_explain']) {
88 $do_display['edit_lnk'] = 'nn'; // no edit link
89 $do_display['del_lnk'] = 'nn'; // no delete link
90 $do_display['sort_lnk'] = (string) '0';
91 $do_display['nav_bar'] = (string) '0';
92 $do_display['ins_row'] = (string) '0';
93 $do_display['bkm_form'] = (string) '1';
94 if ($GLOBALS['is_maint']) {
95 $do_display['text_btn'] = (string) '1';
97 $do_display['text_btn'] = (string) '0';
99 $do_display['pview_lnk'] = (string) '1';
101 // 2.2 Statement is a "SHOW..."
102 elseif ($GLOBALS['is_show']) {
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)
128 $prev_table = $fields_meta[0]->table
;
129 $do_display['text_btn'] = (string) '1';
130 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++
) {
131 $is_link = ($do_display['edit_lnk'] != 'nn'
132 ||
$do_display['del_lnk'] != 'nn'
133 ||
$do_display['sort_lnk'] != '0'
134 ||
$do_display['ins_row'] != '0');
135 // 2.3.2 Displays edit/delete/sort/insert links?
137 && ($fields_meta[$i]->table
== '' ||
$fields_meta[$i]->table
!= $prev_table)) {
138 $do_display['edit_lnk'] = 'nn'; // don't display links
139 $do_display['del_lnk'] = 'nn';
141 * @todo May be problematic with same fields names in two joined table.
143 // $do_display['sort_lnk'] = (string) '0';
144 $do_display['ins_row'] = (string) '0';
145 if ($do_display['text_btn'] == '1') {
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 * Displays a navigation button
190 * @uses $GLOBALS['cfg']['NavigationBarIconic']
191 * @uses PMA_generate_common_hidden_inputs()
193 * @param string iconic caption for button
194 * @param string text for button
195 * @param integer position for next query
196 * @param string query ready for display
197 * @param string optional onsubmit clause
198 * @param string optional hidden field for special treatment
199 * @param string optional onclick clause
201 * @global string $db the database name
202 * @global string $table the table name
203 * @global string $goto the URL to go back in case of errors
207 * @see PMA_displayTableNavigation()
209 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '') {
211 global $db, $table, $goto;
213 $caption_output = '';
214 // for true or 'both'
215 if ($GLOBALS['cfg']['NavigationBarIconic']) {
216 $caption_output .= $caption;
218 // for false or 'both'
219 if (false === $GLOBALS['cfg']['NavigationBarIconic'] ||
'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
220 $caption_output .= ' ' . $title;
222 $title_output = ' title="' . $title . '"';
225 <form action
="sql.php" method
="post" <?php
echo $onsubmit; ?
>>
226 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
227 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
228 <input type
="hidden" name
="pos" value
="<?php echo $pos; ?>" />
229 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
230 <?php
echo $input_for_real_end; ?
>
231 <input type
="submit" name
="navig" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax" ' : '' ); ?
> value
="<?php echo $caption_output; ?>"<?php
echo $title_output . $onclick; ?
> />
235 } // end function PMA_displayTableNavigationOneButton()
238 * Displays a navigation bar to browse among the results of a SQL query
240 * @uses $_SESSION['tmp_user_values']['disp_direction']
241 * @uses $_SESSION['tmp_user_values']['repeat_cells']
242 * @uses $_SESSION['tmp_user_values']['max_rows']
243 * @uses $_SESSION['tmp_user_values']['pos']
244 * @param integer the offset for the "next" page
245 * @param integer the offset for the "previous" page
246 * @param string the URL-encoded query
247 * @param string the id for the direction dropdown
249 * @global string $db the database name
250 * @global string $table the table name
251 * @global string $goto the URL to go back in case of errors
252 * @global integer $num_rows the total number of rows returned by the
254 * @global integer $unlim_num_rows the total number of rows returned by the
255 * SQL any programmatically appended "LIMIT" clause
256 * @global boolean $is_innodb whether its InnoDB or not
257 * @global array $showtable table definitions
261 * @see PMA_displayTable()
263 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
265 global $db, $table, $goto;
266 global $num_rows, $unlim_num_rows;
270 // here, using htmlentities() would cause problems if the query
271 // contains accented characters
272 $html_sql_query = htmlspecialchars($sql_query);
275 * @todo move this to a central place
276 * @todo for other future table types
278 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
282 <!-- Navigation bar
-->
283 <table border
="0" cellpadding
="2" cellspacing
="0" class="navigation">
286 // Move to the beginning or to the previous page
287 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
288 PMA_displayTableNavigationOneButton('<<', __('Begin'), 0, $html_sql_query);
289 PMA_displayTableNavigationOneButton('<', __('Previous'), $pos_prev, $html_sql_query);
297 <?php
// if displaying a VIEW, $unlim_num_rows could be zero because
298 // of $cfg['MaxExactCountViews']; in this case, avoid passing
299 // the 5th parameter to checkFormElementInRange()
300 // (this means we can't validate the upper limit ?>
301 <form action
="sql.php" method
="post"
302 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 : ''; ?>))">
303 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
304 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
305 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
306 <input type
="submit" name
="navig" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
> value
="<?php echo __('Show'); ?> :" />
307 <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()" />
308 <?php
echo __('row(s) starting from row #') . "\n"; ?
>
309 <input type
="text" name
="pos" size
="6" value
="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus
="this.select()" />
312 // Display mode (horizontal/vertical and repeat headers)
314 'horizontal' => __('horizontal'),
315 'horizontalflipped' => __('horizontal (rotated headers)'),
316 'vertical' => __('vertical'));
317 $param1 = PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
320 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />' . "\n"
322 echo ' ' . sprintf(__('in %s mode and repeat headers after %s cells'), "\n" . $param1, "\n" . $param2) . "\n";
330 // Move to the next page or to the last one
331 if (($_SESSION['tmp_user_values']['pos'] +
$_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
332 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
334 // display the Next button
335 PMA_displayTableNavigationOneButton('>',
340 // prepare some options for the End button
341 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
342 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
343 // no backquote around this message
346 $input_for_real_end = $onclick = '';
349 // display the End button
350 PMA_displayTableNavigationOneButton('>>',
352 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
354 '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') . '"',
362 // (unless we are showing all records)
363 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
364 $pageNow = @floor
($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) +
1;
365 $nbTotalPage = @ceil
($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
367 if ($nbTotalPage > 1){ //if2
374 $_url_params = array(
377 'sql_query' => $sql_query,
380 //<form> to keep the form alignment of button < and <<
381 // and also to know what to execute when the selector changes
382 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
383 echo PMA_pageselector(
384 $_SESSION['tmp_user_values']['max_rows'],
401 // Display the "Show all" button if allowed
402 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
409 <form action
="sql.php" method
="post">
410 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
411 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
412 <input type
="hidden" name
="pos" value
="0" />
413 <input type
="hidden" name
="session_max_rows" value
="all" />
414 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
415 <input type
="submit" name
="navig" value
="<?php echo __('Show all'); ?>" />
426 } // end of the 'PMA_displayTableNavigation()' function
430 * Displays the headers of the results table
432 * @uses $_SESSION['tmp_user_values']['disp_direction']
433 * @uses $_SESSION['tmp_user_values']['repeat_cells']
434 * @uses $_SESSION['tmp_user_values']['max_rows']
435 * @uses $_SESSION['tmp_user_values']['display_text']
436 * @uses $_SESSION['tmp_user_values']['display_binary']
437 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
438 * @param array which elements to display
439 * @param array the list of fields properties
440 * @param integer the total number of fields returned by the SQL query
441 * @param array the analyzed query
443 * @return boolean $clause_is_unique
445 * @global string $db the database name
446 * @global string $table the table name
447 * @global string $goto the URL to go back in case of errors
448 * @global string $sql_query the SQL query
449 * @global integer $num_rows the total number of rows returned by the
451 * @global array $vertical_display informations used with vertical display
456 * @see PMA_displayTable()
458 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
460 global $db, $table, $goto;
461 global $sql_query, $num_rows;
462 global $vertical_display, $highlight_columns;
464 if ($analyzed_sql == '') {
465 $analyzed_sql = array();
468 // can the result be sorted?
469 if ($is_display['sort_lnk'] == '1') {
472 $unsorted_sql_query = $sql_query;
473 if (isset($analyzed_sql[0]['unsorted_query'])) {
474 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
476 // Handles the case of multiple clicks on a column's header
477 // which would add many spaces before "ORDER BY" in the
479 $unsorted_sql_query = trim($unsorted_sql_query);
481 // sorting by indexes, only if it makes sense (only one table ref)
482 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
483 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
484 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
486 // grab indexes data:
487 $indexes = PMA_Index
::getFromTable($table, $db);
489 // do we have any index?
492 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
493 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
495 if ($is_display['edit_lnk'] != 'nn') {
498 if ($is_display['del_lnk'] != 'nn') {
501 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
505 $span = $num_rows +
floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) +
1;
508 echo '<form action="sql.php" method="post">' . "\n";
509 echo PMA_generate_common_hidden_inputs($db, $table);
510 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
512 $local_order = (isset($sort_expression) ?
$sort_expression : '');
513 foreach ($indexes as $index) {
514 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
515 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
516 $used_index = $used_index ||
$local_order == $asc_sort ||
$local_order == $desc_sort;
517 echo '<option value="'
518 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
519 . '"' . ($local_order == $asc_sort ?
' selected="selected"' : '')
520 . '>' . htmlspecialchars($index->getName()) . ' ('
521 . __('Ascending') . ')</option>';
522 echo '<option value="'
523 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
524 . '"' . ($local_order == $desc_sort ?
' selected="selected"' : '')
525 . '>' . htmlspecialchars($index->getName()) . ' ('
526 . __('Descending') . ')</option>';
528 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ?
'' : ' selected="selected"') . '>' . __('None') . '</option>';
529 echo '</select>' . "\n";
530 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
531 echo '</form>' . "\n";
537 $vertical_display['emptypre'] = 0;
538 $vertical_display['emptyafter'] = 0;
539 $vertical_display['textbtn'] = '';
541 // Display options (if we are not in print view)
542 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
543 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
544 if ($GLOBALS['cfg']['AjaxEnable']) {
545 echo ' class="ajax" ';
551 'sql_query' => $sql_query,
553 'display_options_form' => 1
555 echo PMA_generate_common_hidden_inputs($url_params);
557 PMA_generate_slider_effect('displayoptions',__('Options'));
560 echo '<div class="formelement">';
562 'P' => __('Partial texts'),
563 'F' => __('Full texts')
565 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
568 // prepare full/partial text button or link
569 if ($_SESSION['tmp_user_values']['display_text']=='F') {
570 // currently in fulltext mode so show the opposite link
571 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
572 $tmp_txt = __('Partial texts');
573 $url_params['display_text'] = 'P';
575 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
576 $tmp_txt = __('Full texts');
577 $url_params['display_text'] = 'F';
580 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
581 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
582 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
583 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
586 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
587 echo '<div class="formelement">';
589 'K' => __('Relational key'),
590 'D' => __('Relational display column')
592 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
596 echo '<div class="formelement">';
597 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
599 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
601 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
604 // I would have preferred to name this "display_transformation".
605 // This is the only way I found to be able to keep this setting sticky
606 // per SQL query, and at the same time have a default that displays
607 // the transformations.
608 echo '<div class="formelement">';
609 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
612 echo '<div class="clearfloat"></div>';
615 echo '<fieldset class="tblFooters">';
616 echo '<input type="submit" value="' . __('Go') . '" />';
622 // Start of form for multi-rows edit/delete/export
624 if ($is_display['del_lnk'] == 'dr' ||
$is_display['del_lnk'] == 'kp') {
625 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
626 echo PMA_generate_common_hidden_inputs($db, $table, 1);
627 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
630 echo '<table id="table_results" class="data';
631 if ($GLOBALS['cfg']['AjaxEnable']) {
635 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
636 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
637 echo '<thead><tr>' . "\n";
640 // 1. Displays the full/partial text button (part 1)...
641 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
642 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
643 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
647 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
652 // ... before the result table
653 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
654 && $is_display['text_btn'] == '1') {
655 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
656 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
657 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
659 <th colspan
="<?php echo $fields_cnt; ?>"></th
>
663 } // end horizontal/horizontalflipped mode
667 <th colspan
="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th
>
670 } // end vertical mode
673 // ... at the left column of the result table header if possible
675 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
676 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
677 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
678 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
680 <th
<?php
echo $colspan; ?
>><?php
echo $full_or_partial_text_link;?
></th
>
682 } // end horizontal/horizontalflipped mode
684 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
687 } // end vertical mode
690 // ... elseif no button, displays empty(ies) col(s) if required
691 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
692 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')) {
693 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
694 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
695 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
697 <td
<?php
echo $colspan; ?
>></td
>
699 } // end horizontal/horizontalfipped mode
701 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
702 } // end vertical mode
705 // 2. Displays the fields' name
706 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
707 // statement (see 2.1.3)
709 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
710 // Do not show comments, if using horizontalflipped mode, because of space usage
711 if ($GLOBALS['cfg']['ShowBrowseComments']
712 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
713 $comments_map = array();
714 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
715 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
716 $tb = $tbl['table_true_name'];
717 $comments_map[$tb] = PMA_getComments($db, $tb);
723 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
724 require_once './libraries/transformations.lib.php';
725 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
728 // See if we have to highlight any header fields of a WHERE query.
729 // Uses SQL-Parser results.
730 $highlight_columns = array();
731 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
732 isset($analyzed_sql[0]['where_clause_identifiers'])) {
735 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
736 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
737 $highlight_columns[$wci] = 'true';
742 for ($i = 0; $i < $fields_cnt; $i++
) {
743 // See if this column should get highlight because it's used in the
745 if (isset($highlight_columns[$fields_meta[$i]->name
]) ||
isset($highlight_columns[PMA_backquote($fields_meta[$i]->name
)])) {
746 $condition_field = true;
748 $condition_field = false;
751 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
752 if (isset($comments_map) &&
753 isset($comments_map[$fields_meta[$i]->table
]) &&
754 isset($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
])) {
755 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
]) . '</span>';
760 // 2.1 Results can be sorted
761 if ($is_display['sort_lnk'] == '1') {
763 // 2.1.1 Checks if the table name is required; it's the case
764 // for a query with a "JOIN" statement and if the column
765 // isn't aliased, or in queries like
766 // SELECT `1`.`master_field` , `2`.`master_field`
767 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
769 if (isset($fields_meta[$i]->table
) && strlen($fields_meta[$i]->table
)) {
770 $sort_tbl = PMA_backquote($fields_meta[$i]->table
) . '.';
775 // 2.1.2 Checks if the current column is used to sort the
777 // the orgname member does not exist for all MySQL versions
778 // but if found, it's the one on which to sort
779 $name_to_use_in_sort = $fields_meta[$i]->name
;
780 if (isset($fields_meta[$i]->orgname
) && strlen($fields_meta[$i]->orgname
)) {
781 $name_to_use_in_sort = $fields_meta[$i]->orgname
;
783 // $name_to_use_in_sort might contain a space due to
784 // formatting of function expressions like "COUNT(name )"
785 // so we remove the space in this situation
786 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
788 if (empty($sort_expression)) {
791 // Field name may be preceded by a space, or any number
792 // of characters followed by a dot (tablename.fieldname)
793 // so do a direct comparison for the sort expression;
794 // this avoids problems with queries like
795 // "SELECT id, count(id)..." and clicking to sort
796 // on id or on count(id).
797 // Another query to test this:
798 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
799 // (and try clicking on each column's header twice)
800 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
801 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
803 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ?
true : false);
805 // 2.1.3 Check the field name for a bracket.
806 // If it contains one, it's probably a function column
807 // like 'COUNT(`field`)'
808 if (strpos($name_to_use_in_sort, '(') !== false) {
809 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
811 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
813 unset($name_to_use_in_sort);
815 // 2.1.4 Do define the sorting URL
817 // patch #455484 ("Smart" order)
818 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
819 if ($GLOBALS['cfg']['Order'] === 'SMART') {
820 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type
)) ?
'DESC' : 'ASC';
822 $sort_order .= $GLOBALS['cfg']['Order'];
825 } elseif ('DESC' == $sort_direction) {
826 $sort_order .= ' ASC';
827 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
829 $sort_order .= ' DESC';
830 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
833 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
834 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
836 $sorted_sql_query = $unsorted_sql_query . $sort_order;
838 $_url_params = array(
841 'sql_query' => $sorted_sql_query,
843 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
845 // 2.1.5 Displays the sorting URL
846 // enable sort order swapping for image
847 $order_link_params = array();
848 if (isset($order_img) && $order_img!='') {
849 if (strstr($order_img, 'asc')) {
850 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
851 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
852 } elseif (strstr($order_img, 'desc')) {
853 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
854 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
857 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
858 if (PMA_USR_BROWSER_AGENT
== 'IE') {
859 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
861 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
864 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
865 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
866 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
868 $order_link_params['title'] = __('Sort');
869 $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
));
870 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
872 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
873 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
876 if ($condition_field) {
877 $th_class[] = 'condition';
879 $th_class[] = 'column_heading';
880 echo ' class="' . implode(' ', $th_class) . '"';
882 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
883 echo ' valign="bottom"';
885 echo '>' . $order_link . $comments . '</th>';
887 $vertical_display['desc'][] = ' <th '
888 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
889 . $order_link . $comments . ' </th>' . "\n";
892 // 2.2 Results can't be sorted
894 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
895 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
897 if ($condition_field) {
898 echo ' class="condition"';
900 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
901 echo ' valign="bottom"';
903 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
904 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
905 echo ' style="direction: ltr; writing-mode: tb-rl;"';
908 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
909 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
910 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name
), '<br />');
912 echo htmlspecialchars($fields_meta[$i]->name
);
914 echo "\n" . $comments . '</th>';
916 $vertical_display['desc'][] = ' <th '
917 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
918 . ' ' . htmlspecialchars($fields_meta[$i]->name
) . "\n"
919 . $comments . ' </th>';
923 // 3. Displays the needed checkboxes at the right
924 // column of the result table header if possible and required...
925 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
926 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')
927 && $is_display['text_btn'] == '1') {
928 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 1;
929 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
930 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
933 <th
<?php
echo $colspan; ?
>><?php
echo $full_or_partial_text_link;?
>
936 } // end horizontal/horizontalflipped mode
938 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
941 } // end vertical mode
944 // ... elseif no button, displays empty columns if required
945 // (unless coming from Browse mode print view)
946 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
947 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
948 && (!$GLOBALS['is_header_sent'])) {
949 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 1;
950 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
951 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
954 <td
<?php
echo $colspan; ?
>></td
>
956 } // end horizontal/horizontalflipped mode
958 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
959 } // end vertical mode
962 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
963 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
971 } // end of the 'PMA_displayTableHeaders()' function
975 * Prepares the display for a value
977 * @param string $class
978 * @param string $condition_field
979 * @param string $value
981 * @return string the td
983 function PMA_buildValueDisplay($class, $condition_field, $value) {
984 return '<td align="left"' . ' class="' . $class . ($condition_field ?
' condition' : '') . '">' . $value . '</td>';
988 * Prepares the display for a null value
990 * @param string $class
991 * @param string $condition_field
993 * @return string the td
995 function PMA_buildNullDisplay($class, $condition_field) {
996 // the null class is needed for inline editing
997 return '<td align="right"' . ' class="' . $class . ($condition_field ?
' condition' : '') . ' null"><i>NULL</i></td>';
1001 * Prepares the display for an empty value
1003 * @param string $class
1004 * @param string $condition_field
1005 * @param string $align
1007 * @return string the td
1009 function PMA_buildEmptyDisplay($class, $condition_field, $align = '') {
1010 return '<td ' . $align . ' class="' . $class . ' nowrap' . ($condition_field ?
' condition' : '') . '"> </td>';
1014 * Displays the body of the results table
1016 * @uses $_SESSION['tmp_user_values']['disp_direction']
1017 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1018 * @uses $_SESSION['tmp_user_values']['max_rows']
1019 * @uses $_SESSION['tmp_user_values']['display_text']
1020 * @uses $_SESSION['tmp_user_values']['display_binary']
1021 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1022 * @uses $_SESSION['tmp_user_values']['display_blob']
1023 * @param integer the link id associated to the query which results have
1025 * @param array which elements to display
1026 * @param array the list of relations
1027 * @param array the analyzed query
1029 * @return boolean always true
1031 * @global string $db the database name
1032 * @global string $table the table name
1033 * @global string $goto the URL to go back in case of errors
1034 * @global string $sql_query the SQL query
1035 * @global array $fields_meta the list of fields properties
1036 * @global integer $fields_cnt the total number of fields returned by
1038 * @global array $vertical_display informations used with vertical display
1040 * @global array $highlight_columns column names to highlight
1041 * @global array $row current row data
1045 * @see PMA_displayTable()
1047 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1048 global $db, $table, $goto;
1049 global $sql_query, $fields_meta, $fields_cnt;
1050 global $vertical_display, $highlight_columns;
1051 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1053 $url_sql_query = $sql_query;
1055 // query without conditions to shorten URLs when needed, 200 is just
1056 // guess, it should depend on remaining URL length
1058 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1059 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1060 strlen($sql_query) > 200) {
1062 $url_sql_query = 'SELECT ';
1063 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1064 $url_sql_query .= ' DISTINCT ';
1066 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1067 if (!empty($analyzed_sql[0]['from_clause'])) {
1068 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1072 if (!is_array($map)) {
1076 $vertical_display['edit'] = array();
1077 $vertical_display['copy'] = array();
1078 $vertical_display['delete'] = array();
1079 $vertical_display['data'] = array();
1080 $vertical_display['row_delete'] = array();
1081 // name of the class added to all inline editable elements
1082 $inline_edit_class = 'inline_edit';
1084 // Correction University of Virginia 19991216 in the while below
1085 // Previous code assumed that all tables have keys, specifically that
1086 // the phpMyAdmin GUI should support row delete/edit only for such
1088 // Although always using keys is arguably the prescribed way of
1089 // defining a relational table, it is not required. This will in
1090 // particular be violated by the novice.
1091 // We want to encourage phpMyAdmin usage by such novices. So the code
1092 // below has been changed to conditionally work as before when the
1093 // table being displayed has one or more keys; but to display
1094 // delete/edit options correctly for tables without keys.
1097 while ($row = PMA_DBI_fetch_row($dt_result)) {
1098 // "vertical display" mode stuff
1099 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no %
$_SESSION['tmp_user_values']['repeat_cells'])
1100 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1101 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1104 if ($vertical_display['emptypre'] > 0) {
1105 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1106 .' </th>' . "\n";
1109 foreach ($vertical_display['desc'] as $val) {
1113 if ($vertical_display['emptyafter'] > 0) {
1114 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1115 .' </th>' . "\n";
1117 echo '</tr>' . "\n";
1120 $alternating_color_class = ($odd_row ?
'odd' : 'even');
1121 $odd_row = ! $odd_row;
1123 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1124 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1125 // pointer code part
1126 echo '<tr class="' . $alternating_color_class . '">';
1130 // 1. Prepares the row
1131 // 1.1 Results from a "SELECT" statement -> builds the
1132 // WHERE clause to use in links (a unique key if possible)
1134 * @todo $where_clause could be empty, for example a table
1135 * with only one field and it's a BLOB; in this case,
1136 * avoid to display the delete and edit links
1138 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1139 $where_clause_html = urlencode($where_clause);
1141 // 1.2 Defines the URLs for the modify/delete link(s)
1143 if ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn') {
1144 // We need to copy the value or else the == 'both' check will always return true
1146 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1147 $iconic_spacer = '<div class="nowrap">';
1149 $iconic_spacer = '';
1152 // 1.2.1 Modify link(s)
1153 if ($is_display['edit_lnk'] == 'ur') { // update row case
1154 $_url_params = array(
1157 'where_clause' => $where_clause,
1158 'clause_is_unique' => $clause_is_unique,
1159 'sql_query' => $url_sql_query,
1160 'goto' => 'sql.php',
1162 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params +
array('default_action' => 'update'));
1163 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params +
array('default_action' => 'insert'));
1165 $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
1166 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'), true);
1168 // Class definitions required for inline editing jQuery scripts
1169 $edit_anchor_class = "edit_row_anchor";
1170 if( $clause_is_unique == 0) {
1171 $edit_anchor_class .= ' nonunique';
1175 // 1.2.2 Delete/Kill link(s)
1176 if ($is_display['del_lnk'] == 'dr') { // delete row case
1177 $_url_params = array(
1180 'sql_query' => $url_sql_query,
1181 'message_to_show' => __('The row has been deleted'),
1182 'goto' => (empty($goto) ?
'tbl_sql.php' : $goto),
1184 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1186 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1187 . ' WHERE ' . $where_clause . ($clause_is_unique ?
'' : ' LIMIT 1');
1189 $_url_params = array(
1192 'sql_query' => $del_query,
1193 'message_to_show' => __('The row has been deleted'),
1194 'goto' => $lnk_goto,
1196 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1198 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1199 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1200 . ($clause_is_unique ?
'' : ' LIMIT 1');
1201 $del_str = PMA_getIcon('b_drop.png', __('Delete'), true);
1202 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1204 $_url_params = array(
1207 'sql_query' => $url_sql_query,
1208 'goto' => 'main.php',
1210 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1212 $_url_params = array(
1214 'sql_query' => 'KILL ' . $row[0],
1215 'goto' => $lnk_goto,
1217 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1218 $del_query = 'KILL ' . $row[0];
1219 $js_conf = 'KILL ' . $row[0];
1220 $del_str = PMA_getIcon('b_drop.png', __('Kill'), true);
1223 // 1.3 Displays the links at left if required
1224 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1225 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1226 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1227 if (! isset($js_conf)) {
1230 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);
1234 // 2. Displays the rows' values
1235 for ($i = 0; $i < $fields_cnt; ++
$i) {
1236 $meta = $fields_meta[$i];
1237 $not_null_class = $meta->not_null ?
'not_null' : '';
1239 $is_field_truncated = false;
1240 //If the previous column had blob data, we need to reset the class
1241 // to $inline_edit_class
1242 $class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $alternating_color_class;
1244 // See if this column should get highlight because it's used in the
1246 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name
]) ||
isset($highlight_columns[PMA_backquote($meta->name
)]))) {
1247 $condition_field = true;
1249 $condition_field = false;
1252 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) ||
($GLOBALS['printview'] != '1'))) {
1253 // the row number corresponds to a data row, not HTML table row
1254 $class .= ' row_' . $row_no;
1255 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1256 $class .= ' vpointer';
1258 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1259 $class .= ' vmarker';
1263 // Wrap MIME-transformations. [MIME]
1264 $default_function = 'default_function'; // default_function
1265 $transform_function = $default_function;
1266 $transform_options = array();
1268 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1270 if (isset($GLOBALS['mime_map'][$meta->name
]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name
]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name
]['transformation'])) {
1271 $include_file = $GLOBALS['mime_map'][$meta->name
]['transformation'];
1273 if (file_exists('./libraries/transformations/' . $include_file)) {
1274 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name
]['transformation']);
1276 require_once './libraries/transformations/' . $include_file;
1278 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1279 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1280 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name
]['transformation_options']) ?
$GLOBALS['mime_map'][$meta->name
]['transformation_options'] : ''));
1281 $meta->mimetype
= str_replace('_', '/', $GLOBALS['mime_map'][$meta->name
]['mimetype']);
1283 } // end if file_exists
1284 } // end if transformation is set
1285 } // end if mime/transformation works.
1287 $_url_params = array(
1290 'where_clause' => $where_clause,
1291 'transform_key' => $meta->name
,
1294 if (! empty($sql_query)) {
1295 $_url_params['sql_query'] = $url_sql_query;
1298 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1301 if ($meta->numeric == 1) {
1303 // if two fields have the same name (this is possible
1304 // with self-join queries, for example), using $meta->name
1305 // will show both fields NULL even if only one is NULL,
1306 // so use the $pointer
1308 if (!isset($row[$i]) ||
is_null($row[$i])) {
1309 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1310 } elseif ($row[$i] != '') {
1312 $nowrap = ' nowrap';
1313 $where_comparison = ' = ' . $row[$i];
1315 $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);
1317 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, 'align="right"');
1322 } elseif (stristr($meta->type
, 'BLOB')) {
1323 // PMA_mysql_fetch_fields returns BLOB in place of
1324 // TEXT fields type so we have to ensure it's really a BLOB
1325 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1327 // reset $class from $inline_edit_class to just 'data'
1328 // as we can't edit binary data
1331 if (stristr($field_flags, 'BINARY')) {
1332 if (!isset($row[$i]) ||
is_null($row[$i])) {
1333 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1335 // for blobstreaming
1336 // if valid BS reference exists
1337 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1338 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1340 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ?
$row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1343 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1348 if (!isset($row[$i]) ||
is_null($row[$i])) {
1349 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1350 } elseif ($row[$i] != '') {
1351 // if a transform function for blob is set, none of these replacements will be made
1352 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1353 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1354 $is_field_truncated = true;
1356 // displays all space characters, 4 space
1357 // characters for tabulations and <cr>/<lf>
1358 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1360 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1362 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field);
1366 } elseif ($meta->type
== 'geometry') {
1367 $geometry_text = PMA_handle_non_printable_contents('GEOMETRY', (isset($row[$i]) ?
$row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1368 // reset $class from $inline_edit_class to 'data'
1369 // as we can't edit geometry data
1371 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $geometry_text);
1372 unset($geometry_text);
1374 // n o t n u m e r i c a n d n o t B L O B
1376 if (!isset($row[$i]) ||
is_null($row[$i])) {
1377 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1378 } elseif ($row[$i] != '') {
1379 // support blanks in the key
1380 $relation_id = $row[$i];
1382 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1383 // (unless it's a link-type transformation)
1384 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1385 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1386 $is_field_truncated = true;
1389 // displays special characters from binaries
1390 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1391 if (isset($meta->_type
) && $meta->_type
=== MYSQLI_TYPE_BIT
) {
1392 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length
);
1393 // some results of PROCEDURE ANALYSE() are reported as
1394 // being BINARY but they are quite readable,
1395 // so don't treat them as BINARY
1396 } elseif (stristr($field_flags, 'BINARY') && $meta->type
== 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1397 if ($_SESSION['tmp_user_values']['display_binary']) {
1398 // user asked to see the real contents of BINARY
1400 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1401 $row[$i] = bin2hex($row[$i]);
1403 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1406 // we show the BINARY message and field's size
1407 // (or maybe use a transformation)
1408 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1412 // transform functions may enable no-wrapping:
1413 $function_nowrap = $transform_function . '_nowrap';
1414 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ?
$function_nowrap($transform_options) : false);
1416 // do not wrap if date field type
1417 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type
) ||
$bool_nowrap) ?
' nowrap' : '');
1418 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1419 $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);
1422 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field);
1426 // output stored cell
1427 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1428 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1429 echo $vertical_display['data'][$row_no][$i];
1432 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1433 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1435 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1439 // 3. Displays the modify/delete links on the right if required
1440 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1441 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1442 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1443 if (! isset($js_conf)) {
1446 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);
1449 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1450 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1456 // 4. Gather links of del_urls and edit_urls in an array for later
1458 if (!isset($vertical_display['edit'][$row_no])) {
1459 $vertical_display['edit'][$row_no] = '';
1460 $vertical_display['copy'][$row_no] = '';
1461 $vertical_display['delete'][$row_no] = '';
1462 $vertical_display['row_delete'][$row_no] = '';
1464 $vertical_class = ' row_' . $row_no;
1465 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1466 $vertical_class .= ' vpointer';
1468 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1469 $vertical_class .= ' vmarker';
1472 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1473 $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);
1475 unset($vertical_display['row_delete'][$row_no]);
1478 if (isset($edit_url)) {
1479 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1481 unset($vertical_display['edit'][$row_no]);
1484 if (isset($copy_url)) {
1485 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1487 unset($vertical_display['copy'][$row_no]);
1490 if (isset($del_url)) {
1491 if (! isset($js_conf)) {
1494 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1496 unset($vertical_display['delete'][$row_no]);
1499 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ?
"\n" : '');
1503 // this is needed by PMA_displayTable() to generate the proper param
1504 // in the multi-edit and multi-delete form
1505 return $clause_is_unique;
1506 } // end of the 'PMA_displayTableBody()' function
1510 * Do display the result table with the vertical direction mode.
1512 * @return boolean always true
1514 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1515 * @global array $vertical_display the information to display
1519 * @see PMA_displayTable()
1521 function PMA_displayVerticalTable()
1523 global $vertical_display;
1525 // Displays "multi row delete" link at top if required
1526 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1528 echo $vertical_display['textbtn'];
1530 foreach ($vertical_display['row_delete'] as $val) {
1531 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1532 echo '<th></th>' . "\n";
1535 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1538 echo '</tr>' . "\n";
1541 // Displays "edit" link at top if required
1542 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1544 if (!is_array($vertical_display['row_delete'])) {
1545 echo $vertical_display['textbtn'];
1548 foreach ($vertical_display['edit'] as $val) {
1549 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1550 echo ' <th></th>' . "\n";
1556 echo '</tr>' . "\n";
1559 // Displays "copy" link at top if required
1560 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 ||
!empty($vertical_display['textbtn']))) {
1562 if (!is_array($vertical_display['row_delete'])) {
1563 echo $vertical_display['textbtn'];
1566 foreach ($vertical_display['copy'] as $val) {
1567 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1568 echo ' <th></th>' . "\n";
1574 echo '</tr>' . "\n";
1577 // Displays "delete" link at top if required
1578 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1580 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1581 echo $vertical_display['textbtn'];
1584 foreach ($vertical_display['delete'] as $val) {
1585 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1586 echo '<th></th>' . "\n";
1592 echo '</tr>' . "\n";
1596 foreach ($vertical_display['desc'] AS $key => $val) {
1602 foreach ($vertical_display['rowdata'][$key] as $subval) {
1603 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1611 echo '</tr>' . "\n";
1614 // Displays "multi row delete" link at bottom if required
1615 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1617 echo $vertical_display['textbtn'];
1619 foreach ($vertical_display['row_delete'] as $val) {
1620 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1621 echo '<th></th>' . "\n";
1624 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1627 echo '</tr>' . "\n";
1630 // Displays "edit" link at bottom if required
1631 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1633 if (!is_array($vertical_display['row_delete'])) {
1634 echo $vertical_display['textbtn'];
1637 foreach ($vertical_display['edit'] as $val) {
1638 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1639 echo '<th></th>' . "\n";
1645 echo '</tr>' . "\n";
1648 // Displays "copy" link at bottom if required
1649 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 ||
!empty($vertical_display['textbtn']))) {
1651 if (!is_array($vertical_display['row_delete'])) {
1652 echo $vertical_display['textbtn'];
1655 foreach ($vertical_display['copy'] as $val) {
1656 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1657 echo '<th></th>' . "\n";
1663 echo '</tr>' . "\n";
1666 // Displays "delete" link at bottom if required
1667 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1669 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1670 echo $vertical_display['textbtn'];
1673 foreach ($vertical_display['delete'] as $val) {
1674 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1675 echo '<th></th>' . "\n";
1681 echo '</tr>' . "\n";
1685 } // end of the 'PMA_displayVerticalTable' function
1689 * @uses $_SESSION['tmp_user_values']['disp_direction']
1690 * @uses $_REQUEST['disp_direction']
1691 * @uses $GLOBALS['cfg']['DefaultDisplay']
1692 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1693 * @uses $_REQUEST['repeat_cells']
1694 * @uses $GLOBALS['cfg']['RepeatCells']
1695 * @uses $_SESSION['tmp_user_values']['max_rows']
1696 * @uses $_REQUEST['session_max_rows']
1697 * @uses $GLOBALS['cfg']['MaxRows']
1698 * @uses $_SESSION['tmp_user_values']['pos']
1699 * @uses $_REQUEST['pos']
1700 * @uses $_SESSION['tmp_user_values']['display_text']
1701 * @uses $_REQUEST['display_text']
1702 * @uses $_SESSION['tmp_user_values']['relational_display']
1703 * @uses $_REQUEST['relational_display']
1704 * @uses $_SESSION['tmp_user_values']['display_binary']
1705 * @uses $_REQUEST['display_binary']
1706 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1707 * @uses $_REQUEST['display_binary_as_hex']
1708 * @uses $_SESSION['tmp_user_values']['display_blob']
1709 * @uses $_REQUEST['display_blob']
1710 * @uses PMA_isValid()
1711 * @uses $GLOBALS['sql_query']
1712 * @todo make maximum remembered queries configurable
1713 * @todo move/split into SQL class!?
1714 * @todo currently this is called twice unnecessary
1715 * @todo ignore LIMIT and ORDER in query!?
1717 function PMA_displayTable_checkConfigParams()
1719 $sql_md5 = md5($GLOBALS['sql_query']);
1721 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1723 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1724 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1725 unset($_REQUEST['disp_direction']);
1726 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1727 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1730 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1731 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1732 unset($_REQUEST['repeat_cells']);
1733 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1734 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1737 // as this is a form value, the type is always string so we cannot
1738 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1739 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1740 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1741 ||
$_REQUEST['session_max_rows'] == 'all') {
1742 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1743 unset($_REQUEST['session_max_rows']);
1744 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1745 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1748 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1749 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1750 unset($_REQUEST['pos']);
1751 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1752 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1755 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1756 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1757 unset($_REQUEST['display_text']);
1758 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1759 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1762 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1763 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1764 unset($_REQUEST['relational_display']);
1765 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1766 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1769 if (isset($_REQUEST['display_binary'])) {
1770 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1771 unset($_REQUEST['display_binary']);
1772 } elseif (isset($_REQUEST['display_options_form'])) {
1773 // we know that the checkbox was unchecked
1774 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1776 // selected by default because some operations like OPTIMIZE TABLE
1777 // and all queries involving functions return "binary" contents,
1778 // according to low-level field flags
1779 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1782 if (isset($_REQUEST['display_binary_as_hex'])) {
1783 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1784 unset($_REQUEST['display_binary_as_hex']);
1785 } elseif (isset($_REQUEST['display_options_form'])) {
1786 // we know that the checkbox was unchecked
1787 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1789 // display_binary_as_hex config option
1790 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1791 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1795 if (isset($_REQUEST['display_blob'])) {
1796 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1797 unset($_REQUEST['display_blob']);
1798 } elseif (isset($_REQUEST['display_options_form'])) {
1799 // we know that the checkbox was unchecked
1800 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1803 if (isset($_REQUEST['hide_transformation'])) {
1804 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1805 unset($_REQUEST['hide_transformation']);
1806 } elseif (isset($_REQUEST['display_options_form'])) {
1807 // we know that the checkbox was unchecked
1808 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1811 // move current query to the last position, to be removed last
1812 // so only least executed query will be removed if maximum remembered queries
1814 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
1815 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
1816 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
1818 // do not exceed a maximum number of queries to remember
1819 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1820 array_shift($_SESSION['tmp_user_values']['query']);
1821 //echo 'deleting one element ...';
1824 // populate query configuration
1825 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
1826 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
1827 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ?
true : false;
1828 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ?
true : false;
1829 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ?
true : false;
1830 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ?
true : false;
1831 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
1832 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
1833 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
1834 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
1839 var_dump($_SESSION['tmp_user_values']);
1845 * Displays a table of results returned by a SQL query.
1846 * This function is called by the "sql.php" script.
1848 * @param integer the link id associated to the query which results have
1850 * @param array the display mode
1851 * @param array the analyzed query
1853 * @uses $_SESSION['tmp_user_values']['pos']
1854 * @global string $db the database name
1855 * @global string $table the table name
1856 * @global string $goto the URL to go back in case of errors
1857 * @global string $sql_query the current SQL query
1858 * @global integer $num_rows the total number of rows returned by the
1860 * @global integer $unlim_num_rows the total number of rows returned by the
1861 * SQL query without any programmatically
1862 * appended "LIMIT" clause
1863 * @global array $fields_meta the list of fields properties
1864 * @global integer $fields_cnt the total number of fields returned by
1866 * @global array $vertical_display informations used with vertical display
1868 * @global array $highlight_columns column names to highlight
1869 * @global array $cfgRelation the relation settings
1873 * @see PMA_showMessage(), PMA_setDisplayMode(),
1874 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1875 * PMA_displayTableBody(), PMA_displayResultsOperations()
1877 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1879 global $db, $table, $goto;
1880 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1881 global $vertical_display, $highlight_columns;
1882 global $cfgRelation;
1885 // why was this called here? (already called from sql.php)
1886 //PMA_displayTable_checkConfigParams();
1889 * @todo move this to a central place
1890 * @todo for other future table types
1892 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1895 && ! isset($analyzed_sql[0]['queryflags']['union'])
1896 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1897 && (empty($analyzed_sql[0]['where_clause'])
1898 ||
$analyzed_sql[0]['where_clause'] == '1 ')) {
1899 // "j u s t b r o w s i n g"
1901 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')), true);
1907 // 1. ----- Prepares the work -----
1909 // 1.1 Gets the informations about which functionalities should be
1912 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1914 // 1.2 Defines offsets for the next and previous pages
1915 if ($is_display['nav_bar'] == '1') {
1916 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1920 $pos_next = $_SESSION['tmp_user_values']['pos'] +
$_SESSION['tmp_user_values']['max_rows'];
1921 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1922 if ($pos_prev < 0) {
1928 // 1.3 Find the sort expression
1930 // we need $sort_expression and $sort_expression_nodirection
1931 // even if there are many table references
1932 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1933 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1935 * Get rid of ASC|DESC
1937 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1938 $sort_expression_nodirection = isset($matches[1]) ?
trim($matches[1]) : $sort_expression;
1939 $sort_direction = isset($matches[2]) ?
trim($matches[2]) : '';
1942 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1945 // 1.4 Prepares display of first and last value of the sorted column
1947 if (! empty($sort_expression_nodirection)) {
1948 if (strpos($sort_expression_nodirection, '.') === false) {
1949 $sort_table = $table;
1950 $sort_column = $sort_expression_nodirection;
1952 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1954 $sort_table = PMA_unQuote($sort_table);
1955 $sort_column = PMA_unQuote($sort_column);
1956 // find the sorted column index in row result
1957 // (this might be a multi-table query)
1958 $sorted_column_index = false;
1959 foreach($fields_meta as $key => $meta) {
1960 if ($meta->table
== $sort_table && $meta->name
== $sort_column) {
1961 $sorted_column_index = $key;
1965 if ($sorted_column_index !== false) {
1966 // fetch first row of the result set
1967 $row = PMA_DBI_fetch_row($dt_result);
1968 // initializing default arguments
1969 $default_function = 'default_function';
1970 $transform_function = $default_function;
1971 $transform_options = array();
1972 // check for non printable sorted row data
1973 $meta = $fields_meta[$sorted_column_index];
1974 if (stristr($meta->type
, 'BLOB') ||
$meta->type
== 'geometry') {
1975 $column_for_first_row = PMA_handle_non_printable_contents($meta->type
, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
1977 $column_for_first_row = $row[$sorted_column_index];
1979 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
1980 // fetch last row of the result set
1981 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1982 $row = PMA_DBI_fetch_row($dt_result);
1983 // check for non printable sorted row data
1984 $meta = $fields_meta[$sorted_column_index];
1985 if (stristr($meta->type
, 'BLOB') ||
$meta->type
== 'geometry') {
1986 $column_for_last_row = PMA_handle_non_printable_contents($meta->type
, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
1988 $column_for_last_row = $row[$sorted_column_index];
1990 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
1991 // reset to first row for the loop in PMA_displayTableBody()
1992 PMA_DBI_data_seek($dt_result, 0);
1993 // we could also use here $sort_expression_nodirection
1994 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1995 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
1997 unset($sorted_column_index, $sort_table, $sort_column);
2000 // 2. ----- Displays the top of the page -----
2002 // 2.1 Displays a messages with position informations
2003 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2004 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2005 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2009 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' ||
$pos_next > $total)
2013 if (PMA_Table
::isView($db, $table)
2014 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2015 $message = PMA_Message
::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2016 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2017 $message->addParam('[/a]');
2018 $message_view_warning = PMA_showHint($message);
2020 $message_view_warning = false;
2023 $message = PMA_Message
::success(__('Showing rows'));
2024 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2025 if ($message_view_warning) {
2026 $message->addMessage('...', ' - ');
2027 $message->addMessage($message_view_warning);
2028 $message->addMessage('(');
2030 $message->addMessage($last_shown_rec, ' - ');
2031 $message->addMessage(' (');
2032 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2033 $message->addString(__('total'));
2034 if (!empty($after_count)) {
2035 $message->addMessage($after_count);
2037 $message->addMessage($selectstring, '');
2038 $message->addMessage(', ', '');
2041 $messagge_qt = PMA_Message
::notice(__('Query took %01.4f sec'));
2042 $messagge_qt->addParam($GLOBALS['querytime']);
2044 $message->addMessage($messagge_qt, '');
2045 $message->addMessage(')', '');
2047 $message->addMessage(isset($sorted_column_message) ?
$sorted_column_message : '', '');
2049 PMA_showMessage($message, $sql_query, 'success');
2051 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2052 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2055 // 2.3 Displays the navigation bars
2056 if (! strlen($table)) {
2057 if (isset($analyzed_sql[0]['query_type'])
2058 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2059 // table does not always contain a real table name,
2060 // for example in MySQL 5.0.x, the query SHOW STATUS
2061 // returns STATUS as a table name
2062 $table = $fields_meta[0]->table
;
2068 if ($is_display['nav_bar'] == '1') {
2069 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2071 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2072 echo "\n" . '<br /><br />' . "\n";
2075 // 2b ----- Get field references from Database -----
2076 // (see the 'relation' configuration variable)
2083 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2084 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2085 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2088 $tabs = '(\'' . join('\',\'', $target) . '\')';
2090 if (! strlen($table)) {
2093 // To be able to later display a link to the related table,
2094 // we verify both types of relations: either those that are
2095 // native foreign keys or those defined in the phpMyAdmin
2096 // configuration storage. If no PMA storage, we won't be able
2097 // to use the "column to display" notion (for example show
2098 // the name related to a numeric id).
2099 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2101 foreach ($exist_rel AS $master_field => $rel) {
2102 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2103 $map[$master_field] = array($rel['foreign_table'],
2104 $rel['foreign_field'],
2106 $rel['foreign_db']);
2112 // 3. ----- Displays the results table -----
2113 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2115 echo '<tbody>' . "\n";
2116 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2117 // vertical output case
2118 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2119 PMA_displayVerticalTable();
2121 unset($vertical_display);
2122 echo '</tbody>' . "\n";
2127 // 4. ----- Displays the link for multi-fields edit and delete
2129 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2131 $delete_text = $is_display['del_lnk'] == 'dr' ?
__('Delete') : __('Kill');
2133 $_url_params = array(
2136 'sql_query' => $sql_query,
2139 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2141 $_url_params['checkall'] = '1';
2142 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2144 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2145 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2146 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2148 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2149 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2151 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2152 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2153 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2154 echo '<img class="selectallarrow" width="38" height="22"'
2155 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2156 .' alt="' . __('With selected:') . '" />';
2158 echo $checkall_link . "\n"
2160 .$uncheckall_link . "\n"
2161 .'<i>' . __('With selected:') . '</i>' . "\n";
2163 PMA_buttonOrImage('submit_mult', 'mult_submit',
2164 'submit_mult_change', __('Change'), 'b_edit.png');
2165 PMA_buttonOrImage('submit_mult', 'mult_submit',
2166 'submit_mult_delete', $delete_text, 'b_drop.png');
2167 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2168 PMA_buttonOrImage('submit_mult', 'mult_submit',
2169 'submit_mult_export', __('Export'),
2174 echo '<input type="hidden" name="sql_query"'
2175 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2177 if (! empty($GLOBALS['url_query'])) {
2178 echo '<input type="hidden" name="url_query"'
2179 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2182 echo '<input type="hidden" name="clause_is_unique"'
2183 .' value="' . $clause_is_unique . '" />' . "\n";
2185 echo '</form>' . "\n";
2188 // 5. ----- Displays the navigation bar at the bottom if required -----
2190 if ($is_display['nav_bar'] == '1') {
2191 echo '<br />' . "\n";
2192 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2193 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2194 echo "\n" . '<br /><br />' . "\n";
2197 // 6. ----- Displays "Query results operations"
2198 if (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2199 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2201 } // end of the 'PMA_displayTable()' function
2203 function default_function($buffer) {
2204 $buffer = htmlspecialchars($buffer);
2205 $buffer = str_replace("\011", ' ',
2206 str_replace(' ', ' ', $buffer));
2207 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2213 * Displays operations that are available on results.
2215 * @param array the display mode
2216 * @param array the analyzed query
2218 * @uses $_SESSION['tmp_user_values']['pos']
2219 * @uses $_SESSION['tmp_user_values']['display_text']
2220 * @global string $db the database name
2221 * @global string $table the table name
2222 * @global string $sql_query the current SQL query
2223 * @global integer $unlim_num_rows the total number of rows returned by the
2224 * SQL query without any programmatically
2225 * appended "LIMIT" clause
2229 * @see PMA_showMessage(), PMA_setDisplayMode(),
2230 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2231 * PMA_displayTableBody(), PMA_displayResultsOperations()
2233 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2234 global $db, $table, $sql_query, $unlim_num_rows;
2236 $header_shown = FALSE;
2237 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2239 if ($the_disp_mode[6] == '1' ||
$the_disp_mode[9] == '1') {
2240 // Displays "printable view" link if required
2241 if ($the_disp_mode[9] == '1') {
2243 if (!$header_shown) {
2245 $header_shown = TRUE;
2248 $_url_params = array(
2252 'sql_query' => $sql_query,
2254 $url_query = PMA_generate_common_url($_url_params);
2256 echo PMA_linkOrButton(
2257 'sql.php' . $url_query,
2258 PMA_getIcon('b_print.png', __('Print view'), false, true),
2259 '', true, true, 'print_view') . "\n";
2261 if ($_SESSION['tmp_user_values']['display_text']) {
2262 $_url_params['display_text'] = 'F';
2263 echo PMA_linkOrButton(
2264 'sql.php' . PMA_generate_common_url($_url_params),
2265 PMA_getIcon('b_print.png', __('Print view (with full texts)'), false, true),
2266 '', true, true, 'print_view') . "\n";
2267 unset($_url_params['display_text']);
2269 } // end displays "printable view"
2273 // (the url_query has extra parameters that won't be used to export)
2274 // (the single_table parameter is used in display_export.lib.php
2275 // to hide the SQL and the structure export dialogs)
2276 // If the parser found a PROCEDURE clause
2277 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2278 // display the Export link).
2279 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2280 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2281 $_url_params['single_table'] = 'true';
2283 if (!$header_shown) {
2285 $header_shown = TRUE;
2287 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2290 * At this point we don't know the table name; this can happen
2291 * for example with a query like
2292 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2293 * As a workaround we set in the table parameter the name of the
2294 * first table of this database, so that tbl_export.php and
2295 * the script it calls do not fail
2297 if (empty($_url_params['table'])) {
2298 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2301 echo PMA_linkOrButton(
2302 'tbl_export.php' . PMA_generate_common_url($_url_params),
2303 PMA_getIcon('b_tblexport.png', __('Export'), false, true),
2304 '', true, true, '') . "\n";
2307 echo PMA_linkOrButton(
2308 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2309 PMA_getIcon('b_chart.png', __('Display chart'), false, true),
2310 '', true, true, '') . "\n";
2316 * @todo detect privileges to create a view
2317 * (but see 2006-01-19 note in display_create_table.lib.php,
2318 * I think we cannot detect db-specific privileges reliably)
2319 * Note: we don't display a Create view link if we found a PROCEDURE clause
2321 if (!$header_shown) {
2323 $header_shown = TRUE;
2325 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2326 echo PMA_linkOrButton(
2327 'view_create.php' . $url_query,
2328 PMA_getIcon('b_views.png', __('Create view'), false, true),
2329 '', true, true, '') . "\n";
2331 if ($header_shown) {
2332 echo '</fieldset><br />';
2337 * Verifies what to do with non-printable contents (binary or BLOB)
2343 * @uses PMA_formatByteDown()
2345 * @uses str_replace()
2346 * @param string $category BLOB|BINARY|GEOMETRY
2347 * @param string $content the binary content
2348 * @param string $transform_function
2349 * @param string $transform_options
2350 * @param string $default_function
2351 * @param object $meta the meta-information about this field
2352 * @return mixed string or float
2354 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2355 $result = '[' . $category;
2356 if (is_null($content)) {
2357 $result .= ' - NULL';
2359 } elseif (isset($content)) {
2360 $size = strlen($content);
2361 $display_size = PMA_formatByteDown($size, 3, 1);
2362 $result .= ' - '. $display_size[0] . $display_size[1];
2366 if (strpos($transform_function, 'octetstream')) {
2370 if ($default_function != $transform_function) {
2371 $result = $transform_function($result, $transform_options, $meta);
2373 $result = $default_function($result, array(), $meta);
2374 if (stristr($meta->type
, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2375 // in this case, restart from the original $content
2376 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2378 /* Create link to download */
2379 if (count($url_params) > 0) {
2380 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2388 * Prepares the displayable content of a data cell in Browse mode,
2389 * taking into account foreign key description field and transformations
2392 * @uses PMA_backquote()
2393 * @uses PMA_DBI_try_query()
2394 * @uses PMA_DBI_num_rows()
2395 * @uses PMA_DBI_fetch_row()
2396 * @uses PMA_DBI_free_result()
2397 * @uses $GLOBALS['printview']
2398 * @uses htmlspecialchars()
2399 * @uses PMA_generate_common_url()
2400 * @param string $class
2401 * @param string $condition_field
2402 * @param string $analyzed_sql
2403 * @param object $meta the meta-information about this field
2404 * @param string $map
2405 * @param string $data
2406 * @param string $transform_function
2407 * @param string $default_function
2408 * @param string $nowrap
2409 * @param string $where_comparison
2410 * @param bool $is_field_truncated
2411 * @return string formatted data
2413 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 ) {
2415 // Define classes to be added to this data field based on the type of data
2417 if(strpos($meta->flags
, 'enum') !== false) {
2418 $enum_class = ' enum';
2421 $mime_type_class = '';
2422 if(isset($meta->mimetype
)) {
2423 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype
);
2426 // continue the <td> tag started before calling this function:
2427 $result = ' class="' . $class . ($condition_field ?
' condition' : '') . $nowrap
2428 . ' ' . ($is_field_truncated ?
' truncated' : '')
2429 . ($transform_function != $default_function ?
' transformed' : '')
2430 . (isset($map[$meta->name
]) ?
' relation' : '')
2431 . $enum_class . $mime_type_class . '">';
2433 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2434 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2435 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2436 if (isset($alias) && strlen($alias)) {
2437 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2438 if ($alias == $meta->name
) {
2439 // this change in the parameter does not matter
2440 // outside of the function
2441 $meta->name
= $true_column;
2447 if (isset($map[$meta->name
])) {
2448 // Field to display from the foreign table?
2449 if (isset($map[$meta->name
][2]) && strlen($map[$meta->name
][2])) {
2450 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name
][2])
2451 . ' FROM ' . PMA_backquote($map[$meta->name
][3])
2452 . '.' . PMA_backquote($map[$meta->name
][0])
2453 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
2454 . $where_comparison;
2455 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE
);
2456 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2457 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2459 $dispval = __('Link not found');
2461 @PMA_DBI_free_result
($dispresult);
2464 } // end if... else...
2466 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2467 $result .= ($transform_function != $default_function ?
$transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[->' . $dispval . ']</code>';
2470 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2471 // user chose "relational key" in the display options, so
2472 // the title contains the display field
2473 $title = (! empty($dispval))?
' title="' . htmlspecialchars($dispval) . '"' : '';
2475 $title = ' title="' . htmlspecialchars($data) . '"';
2478 $_url_params = array(
2479 'db' => $map[$meta->name
][3],
2480 'table' => $map[$meta->name
][0],
2482 'sql_query' => 'SELECT * FROM '
2483 . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
2484 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
2485 . $where_comparison,
2487 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2488 . '"' . $title . '>';
2490 if ($transform_function != $default_function) {
2491 // always apply a transformation on the real data,
2492 // not on the display field
2493 $result .= $transform_function($data, $transform_options, $meta);
2495 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2496 // user chose "relational display field" in the
2497 // display options, so show display field in the cell
2498 $result .= $transform_function($dispval, array(), $meta);
2500 // otherwise display data in the cell
2501 $result .= $transform_function($data, array(), $meta);
2507 $result .= ($transform_function != $default_function ?
$transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2509 $result .= '</td>' . "\n";
2515 * Generates a checkbox for multi-row submits
2517 * @uses htmlspecialchars
2518 * @param string $del_url
2519 * @param array $is_display
2520 * @param string $row_no
2521 * @param string $where_clause_html
2522 * @param string $del_query
2523 * @param string $id_suffix
2524 * @param string $class
2525 * @return string the generated HTML
2528 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class) {
2530 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2532 if (! empty($class)) {
2533 $ret .= 'class="' . $class . '"';
2535 $ret .= ' align="center">'
2536 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2537 . ' class="multi_checkbox"'
2538 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ?
'checked="checked"' : '') . ' />'
2545 * Generates an Edit link
2547 * @uses PMA_linkOrButton()
2548 * @param string $edit_url
2549 * @param string $class
2550 * @param string $edit_str
2551 * @param string $where_clause
2552 * @param string $where_clause_html
2553 * @return string the generated HTML
2555 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) {
2557 if (! empty($edit_url)) {
2558 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2559 . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE);
2561 * Where clause for selecting this row uniquely is provided as
2562 * a hidden input. Used by jQuery scripts for handling inline editing
2564 if(! empty($where_clause)) {
2565 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2567 $ret .= '</span></td>';
2573 * Generates an Copy link
2575 * @uses PMA_linkOrButton()
2576 * @param string $copy_url
2577 * @param string $copy_str
2578 * @param string $where_clause
2579 * @param string $where_clause_html
2580 * @return string the generated HTML
2582 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class) {
2584 if (! empty($copy_url)) {
2586 if (! empty($class)) {
2587 $ret .= 'class="' . $class . '" ';
2589 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2590 . PMA_linkOrButton($copy_url, $copy_str, array(), FALSE);
2592 * Where clause for selecting this row uniquely is provided as
2593 * a hidden input. Used by jQuery scripts for handling inline editing
2595 if(! empty($where_clause)) {
2596 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2598 $ret .= '</span></td>';
2604 * Generates a Delete link
2606 * @uses PMA_linkOrButton()
2607 * @param string $del_url
2608 * @param string $del_str
2609 * @param string $js_conf
2610 * @param string $class
2611 * @return string the generated HTML
2613 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
2615 if (! empty($del_url)) {
2617 if (! empty($class)) {
2618 $ret .= 'class="' . $class . '" ';
2620 $ret .= 'align="center" ' . ' >'
2621 . PMA_linkOrButton($del_url, $del_str, $js_conf, FALSE)
2628 * Generates checkbox and links at some position (left or right)
2629 * (only called for horizontal mode)
2631 * @uses PMA_generateCheckboxForMulti()
2632 * @uses PMA_generateEditLink()
2633 * @uses PMA_generateDeleteLink()
2634 * @uses PMA_generateCopyLink()
2635 * @param string $position
2636 * @param string $del_url
2637 * @param array $is_display
2638 * @param string $row_no
2639 * @param string $where_clause
2640 * @param string $where_clause_html
2641 * @param string $del_query
2642 * @param string $id_suffix
2643 * @param string $edit_url
2644 * @param string $copy_url
2645 * @param string $class
2646 * @param string $edit_str
2647 * @param string $del_str
2648 * @param string $js_conf
2649 * @return string the generated HTML
2651 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) {
2654 if ($position == 'left') {
2655 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2657 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2659 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2661 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2663 } elseif ($position == 'right') {
2664 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2666 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2668 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2670 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');