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);
294 // (unless we are showing all records)
295 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
296 $pageNow = @floor
($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) +
1;
297 $nbTotalPage = @ceil
($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
299 if ($nbTotalPage > 1){ //if2
303 $_url_params = array(
306 'sql_query' => $sql_query,
309 //<form> to keep the form alignment of button < and <<
310 // and also to know what to execute when the selector changes
311 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
312 echo PMA_pageselector(
313 $_SESSION['tmp_user_values']['max_rows'],
330 // Display the "Show all" button if allowed
331 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
335 <form action
="sql.php" method
="post">
336 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
337 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
338 <input type
="hidden" name
="pos" value
="0" />
339 <input type
="hidden" name
="session_max_rows" value
="all" />
340 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
341 <input type
="submit" name
="navig" value
="<?php echo __('Show all'); ?>" />
347 // Move to the next page or to the last one
348 if (($_SESSION['tmp_user_values']['pos'] +
$_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
349 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
351 // display the Next button
352 PMA_displayTableNavigationOneButton('>',
357 // prepare some options for the End button
358 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
359 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
360 // no backquote around this message
363 $input_for_real_end = $onclick = '';
366 // display the End button
367 PMA_displayTableNavigationOneButton('>>',
369 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
371 'onsubmit="return ' . (($_SESSION['tmp_user_values']['pos'] +
$_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) ?
'true' : 'false') . '"',
380 <?php
// if displaying a VIEW, $unlim_num_rows could be zero because
381 // of $cfg['MaxExactCountViews']; in this case, avoid passing
382 // the 5th parameter to checkFormElementInRange()
383 // (this means we can't validate the upper limit ?>
385 <form action
="sql.php" method
="post"
386 onsubmit
="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) && checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
387 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
388 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
389 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
390 <input type
="submit" name
="navig" <?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
' class="ajax"' : ''); ?
> value
="<?php echo __('Show'); ?> :" />
391 <input type
="text" name
="session_max_rows" size
="3" value
="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus
="this.select()" />
392 <?php
echo __('row(s) starting from row #') . "\n"; ?
>
393 <input type
="text" name
="pos" size
="6" value
="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus
="this.select()" />
395 // Display mode (horizontal/vertical and repeat headers)
397 'horizontal' => __('horizontal'),
398 'horizontalflipped' => __('horizontal (rotated headers)'),
399 'vertical' => __('vertical'));
400 $param1 = PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
403 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />' . "\n"
405 echo ' ' . sprintf(__('in %s mode and repeat headers after %s cells'), "\n" . $param1, "\n" . $param2) . "\n";
410 } // end of the 'PMA_displayTableNavigation()' function
414 * Displays the headers of the results table
416 * @uses $_SESSION['tmp_user_values']['disp_direction']
417 * @uses $_SESSION['tmp_user_values']['repeat_cells']
418 * @uses $_SESSION['tmp_user_values']['max_rows']
419 * @uses $_SESSION['tmp_user_values']['display_text']
420 * @uses $_SESSION['tmp_user_values']['display_binary']
421 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
422 * @param array which elements to display
423 * @param array the list of fields properties
424 * @param integer the total number of fields returned by the SQL query
425 * @param array the analyzed query
427 * @return boolean $clause_is_unique
429 * @global string $db the database name
430 * @global string $table the table name
431 * @global string $goto the URL to go back in case of errors
432 * @global string $sql_query the SQL query
433 * @global integer $num_rows the total number of rows returned by the
435 * @global array $vertical_display informations used with vertical display
440 * @see PMA_displayTable()
442 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
444 global $db, $table, $goto;
445 global $sql_query, $num_rows;
446 global $vertical_display, $highlight_columns;
448 if ($analyzed_sql == '') {
449 $analyzed_sql = array();
452 // can the result be sorted?
453 if ($is_display['sort_lnk'] == '1') {
456 $unsorted_sql_query = $sql_query;
457 if (isset($analyzed_sql[0]['unsorted_query'])) {
458 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
460 // Handles the case of multiple clicks on a column's header
461 // which would add many spaces before "ORDER BY" in the
463 $unsorted_sql_query = trim($unsorted_sql_query);
465 // sorting by indexes, only if it makes sense (only one table ref)
466 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
467 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
468 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
470 // grab indexes data:
471 $indexes = PMA_Index
::getFromTable($table, $db);
473 // do we have any index?
476 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
477 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
479 if ($is_display['edit_lnk'] != 'nn') {
482 if ($is_display['del_lnk'] != 'nn') {
485 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
489 $span = $num_rows +
floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) +
1;
492 echo '<form action="sql.php" method="post">' . "\n";
493 echo PMA_generate_common_hidden_inputs($db, $table);
494 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
496 $local_order = (isset($sort_expression) ?
$sort_expression : '');
497 foreach ($indexes as $index) {
498 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
499 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
500 $used_index = $used_index ||
$local_order == $asc_sort ||
$local_order == $desc_sort;
501 echo '<option value="'
502 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
503 . '"' . ($local_order == $asc_sort ?
' selected="selected"' : '')
504 . '>' . htmlspecialchars($index->getName()) . ' ('
505 . __('Ascending') . ')</option>';
506 echo '<option value="'
507 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
508 . '"' . ($local_order == $desc_sort ?
' selected="selected"' : '')
509 . '>' . htmlspecialchars($index->getName()) . ' ('
510 . __('Descending') . ')</option>';
512 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ?
'' : ' selected="selected"') . '>' . __('None') . '</option>';
513 echo '</select>' . "\n";
514 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
515 echo '</form>' . "\n";
521 $vertical_display['emptypre'] = 0;
522 $vertical_display['emptyafter'] = 0;
523 $vertical_display['textbtn'] = '';
525 // Display options (if we are not in print view)
526 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
527 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
528 if ($GLOBALS['cfg']['AjaxEnable']) {
529 echo ' class="ajax" ';
535 'sql_query' => $sql_query,
537 'display_options_form' => 1
539 echo PMA_generate_common_hidden_inputs($url_params);
541 PMA_generate_slider_effect('displayoptions',__('Options'));
544 echo '<div class="formelement">';
546 'P' => __('Partial texts'),
547 'F' => __('Full texts')
549 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
552 // prepare full/partial text button or link
553 if ($_SESSION['tmp_user_values']['display_text']=='F') {
554 // currently in fulltext mode so show the opposite link
555 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
556 $tmp_txt = __('Partial texts');
557 $url_params['display_text'] = 'P';
559 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
560 $tmp_txt = __('Full texts');
561 $url_params['display_text'] = 'F';
564 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
565 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
566 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
567 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
570 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
571 echo '<div class="formelement">';
573 'K' => __('Relational key'),
574 'D' => __('Relational display column')
576 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
580 echo '<div class="formelement">';
581 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
583 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
585 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
588 // I would have preferred to name this "display_transformation".
589 // This is the only way I found to be able to keep this setting sticky
590 // per SQL query, and at the same time have a default that displays
591 // the transformations.
592 echo '<div class="formelement">';
593 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
596 echo '<div class="clearfloat"></div>';
599 echo '<fieldset class="tblFooters">';
600 echo '<input type="submit" value="' . __('Go') . '" />';
606 // Start of form for multi-rows edit/delete/export
608 if ($is_display['del_lnk'] == 'dr' ||
$is_display['del_lnk'] == 'kp') {
609 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
610 echo PMA_generate_common_hidden_inputs($db, $table, 1);
611 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
614 echo '<table id="table_results" class="data';
615 if ($GLOBALS['cfg']['AjaxEnable']) {
619 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
620 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
621 echo '<thead><tr>' . "\n";
624 // 1. Displays the full/partial text button (part 1)...
625 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
626 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
627 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
631 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
636 // ... before the result table
637 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
638 && $is_display['text_btn'] == '1') {
639 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
640 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
641 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
643 <th colspan
="<?php echo $fields_cnt; ?>"></th
>
647 } // end horizontal/horizontalflipped mode
651 <th colspan
="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th
>
654 } // end vertical mode
657 // ... at the left column of the result table header if possible
659 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
660 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
661 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
662 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
664 <th
<?php
echo $colspan; ?
>><?php
echo $full_or_partial_text_link;?
></th
>
666 } // end horizontal/horizontalflipped mode
668 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
671 } // end vertical mode
674 // ... elseif no button, displays empty(ies) col(s) if required
675 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
676 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')) {
677 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 0;
678 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
679 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
681 <td
<?php
echo $colspan; ?
>></td
>
683 } // end horizontal/horizontalfipped mode
685 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
686 } // end vertical mode
689 // 2. Displays the fields' name
690 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
691 // statement (see 2.1.3)
693 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
694 // Do not show comments, if using horizontalflipped mode, because of space usage
695 if ($GLOBALS['cfg']['ShowBrowseComments']
696 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
697 $comments_map = array();
698 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
699 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
700 $tb = $tbl['table_true_name'];
701 $comments_map[$tb] = PMA_getComments($db, $tb);
707 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
708 require_once './libraries/transformations.lib.php';
709 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
712 // See if we have to highlight any header fields of a WHERE query.
713 // Uses SQL-Parser results.
714 $highlight_columns = array();
715 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
716 isset($analyzed_sql[0]['where_clause_identifiers'])) {
719 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
720 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
721 $highlight_columns[$wci] = 'true';
726 for ($i = 0; $i < $fields_cnt; $i++
) {
727 // See if this column should get highlight because it's used in the
729 if (isset($highlight_columns[$fields_meta[$i]->name
]) ||
isset($highlight_columns[PMA_backquote($fields_meta[$i]->name
)])) {
730 $condition_field = true;
732 $condition_field = false;
735 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
736 if (isset($comments_map) &&
737 isset($comments_map[$fields_meta[$i]->table
]) &&
738 isset($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
])) {
739 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
]) . '</span>';
744 // 2.1 Results can be sorted
745 if ($is_display['sort_lnk'] == '1') {
747 // 2.1.1 Checks if the table name is required; it's the case
748 // for a query with a "JOIN" statement and if the column
749 // isn't aliased, or in queries like
750 // SELECT `1`.`master_field` , `2`.`master_field`
751 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
753 if (isset($fields_meta[$i]->table
) && strlen($fields_meta[$i]->table
)) {
754 $sort_tbl = PMA_backquote($fields_meta[$i]->table
) . '.';
759 // 2.1.2 Checks if the current column is used to sort the
761 // the orgname member does not exist for all MySQL versions
762 // but if found, it's the one on which to sort
763 $name_to_use_in_sort = $fields_meta[$i]->name
;
764 if (isset($fields_meta[$i]->orgname
) && strlen($fields_meta[$i]->orgname
)) {
765 $name_to_use_in_sort = $fields_meta[$i]->orgname
;
767 // $name_to_use_in_sort might contain a space due to
768 // formatting of function expressions like "COUNT(name )"
769 // so we remove the space in this situation
770 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
772 if (empty($sort_expression)) {
775 // Field name may be preceded by a space, or any number
776 // of characters followed by a dot (tablename.fieldname)
777 // so do a direct comparison for the sort expression;
778 // this avoids problems with queries like
779 // "SELECT id, count(id)..." and clicking to sort
780 // on id or on count(id).
781 // Another query to test this:
782 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
783 // (and try clicking on each column's header twice)
784 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
785 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
787 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ?
true : false);
789 // 2.1.3 Check the field name for a bracket.
790 // If it contains one, it's probably a function column
791 // like 'COUNT(`field`)'
792 if (strpos($name_to_use_in_sort, '(') !== false) {
793 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
795 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
797 unset($name_to_use_in_sort);
799 // 2.1.4 Do define the sorting URL
801 // patch #455484 ("Smart" order)
802 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
803 if ($GLOBALS['cfg']['Order'] === 'SMART') {
804 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type
)) ?
'DESC' : 'ASC';
806 $sort_order .= $GLOBALS['cfg']['Order'];
809 } elseif ('DESC' == $sort_direction) {
810 $sort_order .= ' ASC';
811 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
813 $sort_order .= ' DESC';
814 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
817 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
818 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
820 $sorted_sql_query = $unsorted_sql_query . $sort_order;
822 $_url_params = array(
825 'sql_query' => $sorted_sql_query,
827 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
829 // 2.1.5 Displays the sorting URL
830 // enable sort order swapping for image
831 $order_link_params = array();
832 if (isset($order_img) && $order_img!='') {
833 if (strstr($order_img, 'asc')) {
834 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
835 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
836 } elseif (strstr($order_img, 'desc')) {
837 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
838 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
841 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
842 if (PMA_USR_BROWSER_AGENT
== 'IE') {
843 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
845 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
848 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
849 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
850 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
852 $order_link_params['title'] = __('Sort');
853 $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
));
854 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
856 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
857 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
860 if ($condition_field) {
861 $th_class[] = 'condition';
863 $th_class[] = 'column_heading';
864 echo ' class="' . implode(' ', $th_class) . '"';
866 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
867 echo ' valign="bottom"';
869 echo '>' . $order_link . $comments . '</th>';
871 $vertical_display['desc'][] = ' <th '
872 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
873 . $order_link . $comments . ' </th>' . "\n";
876 // 2.2 Results can't be sorted
878 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
879 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
881 if ($condition_field) {
882 echo ' class="condition"';
884 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
885 echo ' valign="bottom"';
887 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
888 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
889 echo ' style="direction: ltr; writing-mode: tb-rl;"';
892 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
893 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
894 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name
), '<br />');
896 echo htmlspecialchars($fields_meta[$i]->name
);
898 echo "\n" . $comments . '</th>';
900 $vertical_display['desc'][] = ' <th '
901 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
902 . ' ' . htmlspecialchars($fields_meta[$i]->name
) . "\n"
903 . $comments . ' </th>';
907 // 3. Displays the needed checkboxes at the right
908 // column of the result table header if possible and required...
909 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
910 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')
911 && $is_display['text_btn'] == '1') {
912 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 1;
913 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
914 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
917 <th
<?php
echo $colspan; ?
>><?php
echo $full_or_partial_text_link;?
>
920 } // end horizontal/horizontalflipped mode
922 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
925 } // end vertical mode
928 // ... elseif no button, displays empty columns if required
929 // (unless coming from Browse mode print view)
930 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
931 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
932 && (!$GLOBALS['is_header_sent'])) {
933 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
4 : 1;
934 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
935 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
938 <td
<?php
echo $colspan; ?
>></td
>
940 } // end horizontal/horizontalflipped mode
942 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
943 } // end vertical mode
946 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
947 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
955 } // end of the 'PMA_displayTableHeaders()' function
959 * Prepares the display for a value
961 * @param string $class
962 * @param string $condition_field
963 * @param string $value
965 * @return string the td
967 function PMA_buildValueDisplay($class, $condition_field, $value) {
968 return '<td align="left"' . ' class="' . $class . ($condition_field ?
' condition' : '') . '">' . $value . '</td>';
972 * Prepares the display for a null value
974 * @param string $class
975 * @param string $condition_field
977 * @return string the td
979 function PMA_buildNullDisplay($class, $condition_field) {
980 // the null class is needed for inline editing
981 return '<td align="right"' . ' class="' . $class . ($condition_field ?
' condition' : '') . ' null"><i>NULL</i></td>';
985 * Prepares the display for an empty value
987 * @param string $class
988 * @param string $condition_field
989 * @param string $align
991 * @return string the td
993 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '') {
995 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
999 * Adds the relavant classes.
1001 * @param string $class
1002 * @param string $condition_field
1003 * @param object $meta the meta-information about this field
1004 * @param string $nowrap
1005 * @param bool $is_field_truncated
1006 * @param string $transform_function
1007 * @param string $default_function
1009 * @return string the list of classes
1011 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '') {
1012 // Define classes to be added to this data field based on the type of data
1014 if(strpos($meta->flags
, 'enum') !== false) {
1015 $enum_class = ' enum';
1019 if(strpos($meta->flags
, 'set') !== false) {
1020 $set_class = ' set';
1023 $mime_type_class = '';
1024 if(isset($meta->mimetype
)) {
1025 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype
);
1028 $result = $class . ($condition_field ?
' condition' : '') . $nowrap
1029 . ' ' . ($is_field_truncated ?
' truncated' : '')
1030 . ($transform_function != $default_function ?
' transformed' : '')
1031 . $enum_class . $set_class . $mime_type_class;
1036 * Displays the body of the results table
1038 * @uses $_SESSION['tmp_user_values']['disp_direction']
1039 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1040 * @uses $_SESSION['tmp_user_values']['max_rows']
1041 * @uses $_SESSION['tmp_user_values']['display_text']
1042 * @uses $_SESSION['tmp_user_values']['display_binary']
1043 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1044 * @uses $_SESSION['tmp_user_values']['display_blob']
1045 * @param integer the link id associated to the query which results have
1047 * @param array which elements to display
1048 * @param array the list of relations
1049 * @param array the analyzed query
1051 * @return boolean always true
1053 * @global string $db the database name
1054 * @global string $table the table name
1055 * @global string $goto the URL to go back in case of errors
1056 * @global string $sql_query the SQL query
1057 * @global array $fields_meta the list of fields properties
1058 * @global integer $fields_cnt the total number of fields returned by
1060 * @global array $vertical_display informations used with vertical display
1062 * @global array $highlight_columns column names to highlight
1063 * @global array $row current row data
1067 * @see PMA_displayTable()
1069 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1070 global $db, $table, $goto;
1071 global $sql_query, $fields_meta, $fields_cnt;
1072 global $vertical_display, $highlight_columns;
1073 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1075 $url_sql_query = $sql_query;
1077 // query without conditions to shorten URLs when needed, 200 is just
1078 // guess, it should depend on remaining URL length
1080 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1081 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1082 strlen($sql_query) > 200) {
1084 $url_sql_query = 'SELECT ';
1085 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1086 $url_sql_query .= ' DISTINCT ';
1088 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1089 if (!empty($analyzed_sql[0]['from_clause'])) {
1090 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1094 if (!is_array($map)) {
1098 $vertical_display['edit'] = array();
1099 $vertical_display['copy'] = array();
1100 $vertical_display['delete'] = array();
1101 $vertical_display['data'] = array();
1102 $vertical_display['row_delete'] = array();
1103 // name of the class added to all inline editable elements
1104 $inline_edit_class = 'inline_edit';
1106 // Correction University of Virginia 19991216 in the while below
1107 // Previous code assumed that all tables have keys, specifically that
1108 // the phpMyAdmin GUI should support row delete/edit only for such
1110 // Although always using keys is arguably the prescribed way of
1111 // defining a relational table, it is not required. This will in
1112 // particular be violated by the novice.
1113 // We want to encourage phpMyAdmin usage by such novices. So the code
1114 // below has been changed to conditionally work as before when the
1115 // table being displayed has one or more keys; but to display
1116 // delete/edit options correctly for tables without keys.
1119 while ($row = PMA_DBI_fetch_row($dt_result)) {
1120 // "vertical display" mode stuff
1121 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no %
$_SESSION['tmp_user_values']['repeat_cells'])
1122 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1123 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1126 if ($vertical_display['emptypre'] > 0) {
1127 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1128 .' </th>' . "\n";
1131 foreach ($vertical_display['desc'] as $val) {
1135 if ($vertical_display['emptyafter'] > 0) {
1136 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1137 .' </th>' . "\n";
1139 echo '</tr>' . "\n";
1142 $alternating_color_class = ($odd_row ?
'odd' : 'even');
1143 $odd_row = ! $odd_row;
1145 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1146 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1147 // pointer code part
1148 echo '<tr class="' . $alternating_color_class . '">';
1152 // 1. Prepares the row
1153 // 1.1 Results from a "SELECT" statement -> builds the
1154 // WHERE clause to use in links (a unique key if possible)
1156 * @todo $where_clause could be empty, for example a table
1157 * with only one field and it's a BLOB; in this case,
1158 * avoid to display the delete and edit links
1160 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1161 $where_clause_html = urlencode($where_clause);
1163 // 1.2 Defines the URLs for the modify/delete link(s)
1165 if ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn') {
1166 // We need to copy the value or else the == 'both' check will always return true
1168 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1169 $iconic_spacer = '<div class="nowrap">';
1171 $iconic_spacer = '';
1174 // 1.2.1 Modify link(s)
1175 if ($is_display['edit_lnk'] == 'ur') { // update row case
1176 $_url_params = array(
1179 'where_clause' => $where_clause,
1180 'clause_is_unique' => $clause_is_unique,
1181 'sql_query' => $url_sql_query,
1182 'goto' => 'sql.php',
1184 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params +
array('default_action' => 'update'));
1185 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params +
array('default_action' => 'insert'));
1187 $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
1188 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'), true);
1190 // Class definitions required for inline editing jQuery scripts
1191 $edit_anchor_class = "edit_row_anchor";
1192 if( $clause_is_unique == 0) {
1193 $edit_anchor_class .= ' nonunique';
1197 // 1.2.2 Delete/Kill link(s)
1198 if ($is_display['del_lnk'] == 'dr') { // delete row case
1199 $_url_params = array(
1202 'sql_query' => $url_sql_query,
1203 'message_to_show' => __('The row has been deleted'),
1204 'goto' => (empty($goto) ?
'tbl_sql.php' : $goto),
1206 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1208 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1209 . ' WHERE ' . $where_clause . ($clause_is_unique ?
'' : ' LIMIT 1');
1211 $_url_params = array(
1214 'sql_query' => $del_query,
1215 'message_to_show' => __('The row has been deleted'),
1216 'goto' => $lnk_goto,
1218 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1220 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1221 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1222 . ($clause_is_unique ?
'' : ' LIMIT 1');
1223 $del_str = PMA_getIcon('b_drop.png', __('Delete'), true);
1224 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1226 $_url_params = array(
1229 'sql_query' => $url_sql_query,
1230 'goto' => 'main.php',
1232 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1234 $_url_params = array(
1236 'sql_query' => 'KILL ' . $row[0],
1237 'goto' => $lnk_goto,
1239 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1240 $del_query = 'KILL ' . $row[0];
1241 $js_conf = 'KILL ' . $row[0];
1242 $del_str = PMA_getIcon('b_drop.png', __('Kill'), true);
1245 // 1.3 Displays the links at left if required
1246 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1247 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1248 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1249 if (! isset($js_conf)) {
1252 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);
1256 // 2. Displays the rows' values
1257 for ($i = 0; $i < $fields_cnt; ++
$i) {
1258 $meta = $fields_meta[$i];
1259 $not_null_class = $meta->not_null ?
'not_null' : '';
1260 $relation_class = isset($map[$meta->name
]) ?
'relation' : '';
1262 $is_field_truncated = false;
1263 //If the previous column had blob data, we need to reset the class
1264 // to $inline_edit_class
1265 $class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $alternating_color_class . ' ' . $relation_class;
1267 // See if this column should get highlight because it's used in the
1269 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name
]) ||
isset($highlight_columns[PMA_backquote($meta->name
)]))) {
1270 $condition_field = true;
1272 $condition_field = false;
1275 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) ||
($GLOBALS['printview'] != '1'))) {
1276 // the row number corresponds to a data row, not HTML table row
1277 $class .= ' row_' . $row_no;
1278 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1279 $class .= ' vpointer';
1281 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1282 $class .= ' vmarker';
1286 // Wrap MIME-transformations. [MIME]
1287 $default_function = 'default_function'; // default_function
1288 $transform_function = $default_function;
1289 $transform_options = array();
1291 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1293 if (isset($GLOBALS['mime_map'][$meta->name
]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name
]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name
]['transformation'])) {
1294 $include_file = $GLOBALS['mime_map'][$meta->name
]['transformation'];
1296 if (file_exists('./libraries/transformations/' . $include_file)) {
1297 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name
]['transformation']);
1299 require_once './libraries/transformations/' . $include_file;
1301 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1302 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1303 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name
]['transformation_options']) ?
$GLOBALS['mime_map'][$meta->name
]['transformation_options'] : ''));
1304 $meta->mimetype
= str_replace('_', '/', $GLOBALS['mime_map'][$meta->name
]['mimetype']);
1306 } // end if file_exists
1307 } // end if transformation is set
1308 } // end if mime/transformation works.
1310 $_url_params = array(
1313 'where_clause' => $where_clause,
1314 'transform_key' => $meta->name
,
1317 if (! empty($sql_query)) {
1318 $_url_params['sql_query'] = $url_sql_query;
1321 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1324 if ($meta->numeric == 1) {
1326 // if two fields have the same name (this is possible
1327 // with self-join queries, for example), using $meta->name
1328 // will show both fields NULL even if only one is NULL,
1329 // so use the $pointer
1331 if (!isset($row[$i]) ||
is_null($row[$i])) {
1332 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1333 } elseif ($row[$i] != '') {
1335 $nowrap = ' nowrap';
1336 $where_comparison = ' = ' . $row[$i];
1338 $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);
1340 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1345 } elseif (stristr($meta->type
, 'BLOB')) {
1346 // PMA_mysql_fetch_fields returns BLOB in place of
1347 // TEXT fields type so we have to ensure it's really a BLOB
1348 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1350 // remove 'inline_edit' from $class as we can't edit binary data.
1351 $class = str_replace('inline_edit', '', $class);
1353 if (stristr($field_flags, 'BINARY')) {
1354 if (!isset($row[$i]) ||
is_null($row[$i])) {
1355 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1357 // for blobstreaming
1358 // if valid BS reference exists
1359 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1360 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1362 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ?
$row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1365 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1370 if (!isset($row[$i]) ||
is_null($row[$i])) {
1371 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1372 } elseif ($row[$i] != '') {
1373 // if a transform function for blob is set, none of these replacements will be made
1374 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1375 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1376 $is_field_truncated = true;
1378 // displays all space characters, 4 space
1379 // characters for tabulations and <cr>/<lf>
1380 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1382 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1384 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1388 } elseif ($meta->type
== 'geometry') {
1389 $geometry_text = PMA_handle_non_printable_contents('GEOMETRY', (isset($row[$i]) ?
$row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1391 // remove 'inline_edit' from $class as we can't edit geometry data.
1392 $class = str_replace('inline_edit', '', $class);
1393 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $geometry_text);
1394 unset($geometry_text);
1396 // n o t n u m e r i c a n d n o t B L O B
1398 if (!isset($row[$i]) ||
is_null($row[$i])) {
1399 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1400 } elseif ($row[$i] != '') {
1401 // support blanks in the key
1402 $relation_id = $row[$i];
1404 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1405 // (unless it's a link-type transformation)
1406 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1407 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1408 $is_field_truncated = true;
1411 // displays special characters from binaries
1412 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1413 if (isset($meta->_type
) && $meta->_type
=== MYSQLI_TYPE_BIT
) {
1414 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length
);
1415 // some results of PROCEDURE ANALYSE() are reported as
1416 // being BINARY but they are quite readable,
1417 // so don't treat them as BINARY
1418 } elseif (stristr($field_flags, 'BINARY') && $meta->type
== 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1419 if ($_SESSION['tmp_user_values']['display_binary']) {
1420 // user asked to see the real contents of BINARY
1422 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1423 $row[$i] = bin2hex($row[$i]);
1425 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1428 // we show the BINARY message and field's size
1429 // (or maybe use a transformation)
1430 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1434 // transform functions may enable no-wrapping:
1435 $function_nowrap = $transform_function . '_nowrap';
1436 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ?
$function_nowrap($transform_options) : false);
1438 // do not wrap if date field type
1439 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type
) ||
$bool_nowrap) ?
' nowrap' : '');
1440 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1441 $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);
1444 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1448 // output stored cell
1449 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1450 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1451 echo $vertical_display['data'][$row_no][$i];
1454 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1455 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1457 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1461 // 3. Displays the modify/delete links on the right if required
1462 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1463 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1464 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1465 if (! isset($js_conf)) {
1468 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);
1471 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1472 ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1478 // 4. Gather links of del_urls and edit_urls in an array for later
1480 if (!isset($vertical_display['edit'][$row_no])) {
1481 $vertical_display['edit'][$row_no] = '';
1482 $vertical_display['copy'][$row_no] = '';
1483 $vertical_display['delete'][$row_no] = '';
1484 $vertical_display['row_delete'][$row_no] = '';
1486 $vertical_class = ' row_' . $row_no;
1487 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1488 $vertical_class .= ' vpointer';
1490 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1491 $vertical_class .= ' vmarker';
1494 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1495 $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);
1497 unset($vertical_display['row_delete'][$row_no]);
1500 if (isset($edit_url)) {
1501 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1503 unset($vertical_display['edit'][$row_no]);
1506 if (isset($copy_url)) {
1507 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1509 unset($vertical_display['copy'][$row_no]);
1512 if (isset($del_url)) {
1513 if (! isset($js_conf)) {
1516 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1518 unset($vertical_display['delete'][$row_no]);
1521 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' ||
$_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ?
"\n" : '');
1525 // this is needed by PMA_displayTable() to generate the proper param
1526 // in the multi-edit and multi-delete form
1527 return $clause_is_unique;
1528 } // end of the 'PMA_displayTableBody()' function
1532 * Do display the result table with the vertical direction mode.
1534 * @return boolean always true
1536 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1537 * @global array $vertical_display the information to display
1541 * @see PMA_displayTable()
1543 function PMA_displayVerticalTable()
1545 global $vertical_display;
1547 // Displays "multi row delete" link at top if required
1548 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1550 echo $vertical_display['textbtn'];
1552 foreach ($vertical_display['row_delete'] as $val) {
1553 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1554 echo '<th></th>' . "\n";
1557 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1560 echo '</tr>' . "\n";
1563 // Displays "edit" link at top if required
1564 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1566 if (!is_array($vertical_display['row_delete'])) {
1567 echo $vertical_display['textbtn'];
1570 foreach ($vertical_display['edit'] as $val) {
1571 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1572 echo ' <th></th>' . "\n";
1578 echo '</tr>' . "\n";
1581 // Displays "copy" link at top if required
1582 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 ||
!empty($vertical_display['textbtn']))) {
1584 if (!is_array($vertical_display['row_delete'])) {
1585 echo $vertical_display['textbtn'];
1588 foreach ($vertical_display['copy'] as $val) {
1589 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1590 echo ' <th></th>' . "\n";
1596 echo '</tr>' . "\n";
1599 // Displays "delete" link at top if required
1600 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1602 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1603 echo $vertical_display['textbtn'];
1606 foreach ($vertical_display['delete'] as $val) {
1607 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1608 echo '<th></th>' . "\n";
1614 echo '</tr>' . "\n";
1618 foreach ($vertical_display['desc'] AS $key => $val) {
1624 foreach ($vertical_display['rowdata'][$key] as $subval) {
1625 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1633 echo '</tr>' . "\n";
1636 // Displays "multi row delete" link at bottom if required
1637 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1639 echo $vertical_display['textbtn'];
1641 foreach ($vertical_display['row_delete'] as $val) {
1642 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1643 echo '<th></th>' . "\n";
1646 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1649 echo '</tr>' . "\n";
1652 // Displays "edit" link at bottom if required
1653 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1655 if (!is_array($vertical_display['row_delete'])) {
1656 echo $vertical_display['textbtn'];
1659 foreach ($vertical_display['edit'] as $val) {
1660 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1661 echo '<th></th>' . "\n";
1667 echo '</tr>' . "\n";
1670 // Displays "copy" link at bottom if required
1671 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 ||
!empty($vertical_display['textbtn']))) {
1673 if (!is_array($vertical_display['row_delete'])) {
1674 echo $vertical_display['textbtn'];
1677 foreach ($vertical_display['copy'] as $val) {
1678 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1679 echo '<th></th>' . "\n";
1685 echo '</tr>' . "\n";
1688 // Displays "delete" link at bottom if required
1689 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1691 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1692 echo $vertical_display['textbtn'];
1695 foreach ($vertical_display['delete'] as $val) {
1696 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['tmp_user_values']['repeat_cells'])) {
1697 echo '<th></th>' . "\n";
1703 echo '</tr>' . "\n";
1707 } // end of the 'PMA_displayVerticalTable' function
1711 * @uses $_SESSION['tmp_user_values']['disp_direction']
1712 * @uses $_REQUEST['disp_direction']
1713 * @uses $GLOBALS['cfg']['DefaultDisplay']
1714 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1715 * @uses $_REQUEST['repeat_cells']
1716 * @uses $GLOBALS['cfg']['RepeatCells']
1717 * @uses $_SESSION['tmp_user_values']['max_rows']
1718 * @uses $_REQUEST['session_max_rows']
1719 * @uses $GLOBALS['cfg']['MaxRows']
1720 * @uses $_SESSION['tmp_user_values']['pos']
1721 * @uses $_REQUEST['pos']
1722 * @uses $_SESSION['tmp_user_values']['display_text']
1723 * @uses $_REQUEST['display_text']
1724 * @uses $_SESSION['tmp_user_values']['relational_display']
1725 * @uses $_REQUEST['relational_display']
1726 * @uses $_SESSION['tmp_user_values']['display_binary']
1727 * @uses $_REQUEST['display_binary']
1728 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1729 * @uses $_REQUEST['display_binary_as_hex']
1730 * @uses $_SESSION['tmp_user_values']['display_blob']
1731 * @uses $_REQUEST['display_blob']
1732 * @uses PMA_isValid()
1733 * @uses $GLOBALS['sql_query']
1734 * @todo make maximum remembered queries configurable
1735 * @todo move/split into SQL class!?
1736 * @todo currently this is called twice unnecessary
1737 * @todo ignore LIMIT and ORDER in query!?
1739 function PMA_displayTable_checkConfigParams()
1741 $sql_md5 = md5($GLOBALS['sql_query']);
1743 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1745 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1746 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1747 unset($_REQUEST['disp_direction']);
1748 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1749 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1752 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1753 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1754 unset($_REQUEST['repeat_cells']);
1755 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1756 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1759 // as this is a form value, the type is always string so we cannot
1760 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1761 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1762 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1763 ||
$_REQUEST['session_max_rows'] == 'all') {
1764 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1765 unset($_REQUEST['session_max_rows']);
1766 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1767 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1770 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1771 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1772 unset($_REQUEST['pos']);
1773 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1774 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1777 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1778 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1779 unset($_REQUEST['display_text']);
1780 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1781 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1784 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1785 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1786 unset($_REQUEST['relational_display']);
1787 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1788 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1791 if (isset($_REQUEST['display_binary'])) {
1792 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1793 unset($_REQUEST['display_binary']);
1794 } elseif (isset($_REQUEST['display_options_form'])) {
1795 // we know that the checkbox was unchecked
1796 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1798 // selected by default because some operations like OPTIMIZE TABLE
1799 // and all queries involving functions return "binary" contents,
1800 // according to low-level field flags
1801 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1804 if (isset($_REQUEST['display_binary_as_hex'])) {
1805 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1806 unset($_REQUEST['display_binary_as_hex']);
1807 } elseif (isset($_REQUEST['display_options_form'])) {
1808 // we know that the checkbox was unchecked
1809 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1811 // display_binary_as_hex config option
1812 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1813 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1817 if (isset($_REQUEST['display_blob'])) {
1818 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1819 unset($_REQUEST['display_blob']);
1820 } elseif (isset($_REQUEST['display_options_form'])) {
1821 // we know that the checkbox was unchecked
1822 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1825 if (isset($_REQUEST['hide_transformation'])) {
1826 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1827 unset($_REQUEST['hide_transformation']);
1828 } elseif (isset($_REQUEST['display_options_form'])) {
1829 // we know that the checkbox was unchecked
1830 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1833 // move current query to the last position, to be removed last
1834 // so only least executed query will be removed if maximum remembered queries
1836 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
1837 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
1838 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
1840 // do not exceed a maximum number of queries to remember
1841 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1842 array_shift($_SESSION['tmp_user_values']['query']);
1843 //echo 'deleting one element ...';
1846 // populate query configuration
1847 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
1848 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
1849 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ?
true : false;
1850 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ?
true : false;
1851 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ?
true : false;
1852 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ?
true : false;
1853 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
1854 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
1855 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
1856 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
1861 var_dump($_SESSION['tmp_user_values']);
1867 * Displays a table of results returned by a SQL query.
1868 * This function is called by the "sql.php" script.
1870 * @param integer the link id associated to the query which results have
1872 * @param array the display mode
1873 * @param array the analyzed query
1875 * @uses $_SESSION['tmp_user_values']['pos']
1876 * @global string $db the database name
1877 * @global string $table the table name
1878 * @global string $goto the URL to go back in case of errors
1879 * @global string $sql_query the current SQL query
1880 * @global integer $num_rows the total number of rows returned by the
1882 * @global integer $unlim_num_rows the total number of rows returned by the
1883 * SQL query without any programmatically
1884 * appended "LIMIT" clause
1885 * @global array $fields_meta the list of fields properties
1886 * @global integer $fields_cnt the total number of fields returned by
1888 * @global array $vertical_display informations used with vertical display
1890 * @global array $highlight_columns column names to highlight
1891 * @global array $cfgRelation the relation settings
1895 * @see PMA_showMessage(), PMA_setDisplayMode(),
1896 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1897 * PMA_displayTableBody(), PMA_displayResultsOperations()
1899 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1901 global $db, $table, $goto;
1902 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1903 global $vertical_display, $highlight_columns;
1904 global $cfgRelation;
1907 // why was this called here? (already called from sql.php)
1908 //PMA_displayTable_checkConfigParams();
1911 * @todo move this to a central place
1912 * @todo for other future table types
1914 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1917 && ! isset($analyzed_sql[0]['queryflags']['union'])
1918 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1919 && (empty($analyzed_sql[0]['where_clause'])
1920 ||
$analyzed_sql[0]['where_clause'] == '1 ')) {
1921 // "j u s t b r o w s i n g"
1923 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')), true);
1929 // 1. ----- Prepares the work -----
1931 // 1.1 Gets the informations about which functionalities should be
1934 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1936 // 1.2 Defines offsets for the next and previous pages
1937 if ($is_display['nav_bar'] == '1') {
1938 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1942 $pos_next = $_SESSION['tmp_user_values']['pos'] +
$_SESSION['tmp_user_values']['max_rows'];
1943 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1944 if ($pos_prev < 0) {
1950 // 1.3 Find the sort expression
1952 // we need $sort_expression and $sort_expression_nodirection
1953 // even if there are many table references
1954 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1955 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1957 * Get rid of ASC|DESC
1959 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1960 $sort_expression_nodirection = isset($matches[1]) ?
trim($matches[1]) : $sort_expression;
1961 $sort_direction = isset($matches[2]) ?
trim($matches[2]) : '';
1964 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1967 // 1.4 Prepares display of first and last value of the sorted column
1969 if (! empty($sort_expression_nodirection)) {
1970 if (strpos($sort_expression_nodirection, '.') === false) {
1971 $sort_table = $table;
1972 $sort_column = $sort_expression_nodirection;
1974 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1976 $sort_table = PMA_unQuote($sort_table);
1977 $sort_column = PMA_unQuote($sort_column);
1978 // find the sorted column index in row result
1979 // (this might be a multi-table query)
1980 $sorted_column_index = false;
1981 foreach($fields_meta as $key => $meta) {
1982 if ($meta->table
== $sort_table && $meta->name
== $sort_column) {
1983 $sorted_column_index = $key;
1987 if ($sorted_column_index !== false) {
1988 // fetch first row of the result set
1989 $row = PMA_DBI_fetch_row($dt_result);
1990 // initializing default arguments
1991 $default_function = 'default_function';
1992 $transform_function = $default_function;
1993 $transform_options = array();
1994 // check for non printable sorted row data
1995 $meta = $fields_meta[$sorted_column_index];
1996 if (stristr($meta->type
, 'BLOB') ||
$meta->type
== 'geometry') {
1997 $column_for_first_row = PMA_handle_non_printable_contents($meta->type
, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
1999 $column_for_first_row = $row[$sorted_column_index];
2001 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2002 // fetch last row of the result set
2003 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2004 $row = PMA_DBI_fetch_row($dt_result);
2005 // check for non printable sorted row data
2006 $meta = $fields_meta[$sorted_column_index];
2007 if (stristr($meta->type
, 'BLOB') ||
$meta->type
== 'geometry') {
2008 $column_for_last_row = PMA_handle_non_printable_contents($meta->type
, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2010 $column_for_last_row = $row[$sorted_column_index];
2012 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2013 // reset to first row for the loop in PMA_displayTableBody()
2014 PMA_DBI_data_seek($dt_result, 0);
2015 // we could also use here $sort_expression_nodirection
2016 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2017 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2019 unset($sorted_column_index, $sort_table, $sort_column);
2022 // 2. ----- Displays the top of the page -----
2024 // 2.1 Displays a messages with position informations
2025 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2026 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2027 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2031 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' ||
$pos_next > $total)
2035 if (PMA_Table
::isView($db, $table)
2036 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2037 $message = PMA_Message
::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2038 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2039 $message->addParam('[/a]');
2040 $message_view_warning = PMA_showHint($message);
2042 $message_view_warning = false;
2045 $message = PMA_Message
::success(__('Showing rows'));
2046 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2047 if ($message_view_warning) {
2048 $message->addMessage('...', ' - ');
2049 $message->addMessage($message_view_warning);
2050 $message->addMessage('(');
2052 $message->addMessage($last_shown_rec, ' - ');
2053 $message->addMessage(' (');
2054 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2055 $message->addString(__('total'));
2056 if (!empty($after_count)) {
2057 $message->addMessage($after_count);
2059 $message->addMessage($selectstring, '');
2060 $message->addMessage(', ', '');
2063 $messagge_qt = PMA_Message
::notice(__('Query took %01.4f sec'));
2064 $messagge_qt->addParam($GLOBALS['querytime']);
2066 $message->addMessage($messagge_qt, '');
2067 $message->addMessage(')', '');
2069 $message->addMessage(isset($sorted_column_message) ?
$sorted_column_message : '', '');
2071 PMA_showMessage($message, $sql_query, 'success');
2073 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2074 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2077 // 2.3 Displays the navigation bars
2078 if (! strlen($table)) {
2079 if (isset($analyzed_sql[0]['query_type'])
2080 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2081 // table does not always contain a real table name,
2082 // for example in MySQL 5.0.x, the query SHOW STATUS
2083 // returns STATUS as a table name
2084 $table = $fields_meta[0]->table
;
2090 if ($is_display['nav_bar'] == '1') {
2091 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2093 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2094 echo "\n" . '<br /><br />' . "\n";
2097 // 2b ----- Get field references from Database -----
2098 // (see the 'relation' configuration variable)
2105 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2106 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2107 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2110 $tabs = '(\'' . join('\',\'', $target) . '\')';
2112 if (! strlen($table)) {
2115 // To be able to later display a link to the related table,
2116 // we verify both types of relations: either those that are
2117 // native foreign keys or those defined in the phpMyAdmin
2118 // configuration storage. If no PMA storage, we won't be able
2119 // to use the "column to display" notion (for example show
2120 // the name related to a numeric id).
2121 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2123 foreach ($exist_rel AS $master_field => $rel) {
2124 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2125 $map[$master_field] = array($rel['foreign_table'],
2126 $rel['foreign_field'],
2128 $rel['foreign_db']);
2134 // 3. ----- Displays the results table -----
2135 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2137 echo '<tbody>' . "\n";
2138 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2139 // vertical output case
2140 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2141 PMA_displayVerticalTable();
2143 unset($vertical_display);
2144 echo '</tbody>' . "\n";
2149 // 4. ----- Displays the link for multi-fields edit and delete
2151 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2153 $delete_text = $is_display['del_lnk'] == 'dr' ?
__('Delete') : __('Kill');
2155 $_url_params = array(
2158 'sql_query' => $sql_query,
2161 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2163 $_url_params['checkall'] = '1';
2164 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2166 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2167 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2168 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2170 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2171 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2173 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2174 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2175 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2176 echo '<img class="selectallarrow" width="38" height="22"'
2177 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2178 .' alt="' . __('With selected:') . '" />';
2180 echo $checkall_link . "\n"
2182 .$uncheckall_link . "\n"
2183 .'<i>' . __('With selected:') . '</i>' . "\n";
2185 PMA_buttonOrImage('submit_mult', 'mult_submit',
2186 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2187 PMA_buttonOrImage('submit_mult', 'mult_submit',
2188 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2189 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2190 PMA_buttonOrImage('submit_mult', 'mult_submit',
2191 'submit_mult_export', __('Export'),
2192 'b_tblexport.png', 'export');
2196 echo '<input type="hidden" name="sql_query"'
2197 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2199 if (! empty($GLOBALS['url_query'])) {
2200 echo '<input type="hidden" name="url_query"'
2201 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2204 echo '<input type="hidden" name="clause_is_unique"'
2205 .' value="' . $clause_is_unique . '" />' . "\n";
2207 echo '</form>' . "\n";
2210 // 5. ----- Displays the navigation bar at the bottom if required -----
2212 if ($is_display['nav_bar'] == '1') {
2213 echo '<br />' . "\n";
2214 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2215 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2216 echo "\n" . '<br /><br />' . "\n";
2219 // 6. ----- Displays "Query results operations"
2220 if (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2221 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2223 } // end of the 'PMA_displayTable()' function
2225 function default_function($buffer) {
2226 $buffer = htmlspecialchars($buffer);
2227 $buffer = str_replace("\011", ' ',
2228 str_replace(' ', ' ', $buffer));
2229 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2235 * Displays operations that are available on results.
2237 * @param array the display mode
2238 * @param array the analyzed query
2240 * @uses $_SESSION['tmp_user_values']['pos']
2241 * @uses $_SESSION['tmp_user_values']['display_text']
2242 * @global string $db the database name
2243 * @global string $table the table name
2244 * @global string $sql_query the current SQL query
2245 * @global integer $unlim_num_rows the total number of rows returned by the
2246 * SQL query without any programmatically
2247 * appended "LIMIT" clause
2251 * @see PMA_showMessage(), PMA_setDisplayMode(),
2252 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2253 * PMA_displayTableBody(), PMA_displayResultsOperations()
2255 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2256 global $db, $table, $sql_query, $unlim_num_rows;
2258 $header_shown = FALSE;
2259 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2261 if ($the_disp_mode[6] == '1' ||
$the_disp_mode[9] == '1') {
2262 // Displays "printable view" link if required
2263 if ($the_disp_mode[9] == '1') {
2265 if (!$header_shown) {
2267 $header_shown = TRUE;
2270 $_url_params = array(
2274 'sql_query' => $sql_query,
2276 $url_query = PMA_generate_common_url($_url_params);
2278 echo PMA_linkOrButton(
2279 'sql.php' . $url_query,
2280 PMA_getIcon('b_print.png', __('Print view'), false, true),
2281 '', true, true, 'print_view') . "\n";
2283 if ($_SESSION['tmp_user_values']['display_text']) {
2284 $_url_params['display_text'] = 'F';
2285 echo PMA_linkOrButton(
2286 'sql.php' . PMA_generate_common_url($_url_params),
2287 PMA_getIcon('b_print.png', __('Print view (with full texts)'), false, true),
2288 '', true, true, 'print_view') . "\n";
2289 unset($_url_params['display_text']);
2291 } // end displays "printable view"
2295 // (the url_query has extra parameters that won't be used to export)
2296 // (the single_table parameter is used in display_export.lib.php
2297 // to hide the SQL and the structure export dialogs)
2298 // If the parser found a PROCEDURE clause
2299 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2300 // display the Export link).
2301 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2302 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2303 $_url_params['single_table'] = 'true';
2305 if (!$header_shown) {
2307 $header_shown = TRUE;
2309 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2312 * At this point we don't know the table name; this can happen
2313 * for example with a query like
2314 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2315 * As a workaround we set in the table parameter the name of the
2316 * first table of this database, so that tbl_export.php and
2317 * the script it calls do not fail
2319 if (empty($_url_params['table'])) {
2320 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2323 echo PMA_linkOrButton(
2324 'tbl_export.php' . PMA_generate_common_url($_url_params),
2325 PMA_getIcon('b_tblexport.png', __('Export'), false, true),
2326 '', true, true, '') . "\n";
2329 echo PMA_linkOrButton(
2330 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2331 PMA_getIcon('b_chart.png', __('Display chart'), false, true),
2332 '', true, true, '') . "\n";
2338 * @todo detect privileges to create a view
2339 * (but see 2006-01-19 note in display_create_table.lib.php,
2340 * I think we cannot detect db-specific privileges reliably)
2341 * Note: we don't display a Create view link if we found a PROCEDURE clause
2343 if (!$header_shown) {
2345 $header_shown = TRUE;
2347 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2348 echo PMA_linkOrButton(
2349 'view_create.php' . $url_query,
2350 PMA_getIcon('b_views.png', __('Create view'), false, true),
2351 '', true, true, '') . "\n";
2353 if ($header_shown) {
2354 echo '</fieldset><br />';
2359 * Verifies what to do with non-printable contents (binary or BLOB)
2365 * @uses PMA_formatByteDown()
2367 * @uses str_replace()
2368 * @param string $category BLOB|BINARY|GEOMETRY
2369 * @param string $content the binary content
2370 * @param string $transform_function
2371 * @param string $transform_options
2372 * @param string $default_function
2373 * @param object $meta the meta-information about this field
2374 * @return mixed string or float
2376 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2377 $result = '[' . $category;
2378 if (is_null($content)) {
2379 $result .= ' - NULL';
2381 } elseif (isset($content)) {
2382 $size = strlen($content);
2383 $display_size = PMA_formatByteDown($size, 3, 1);
2384 $result .= ' - '. $display_size[0] . $display_size[1];
2388 if (strpos($transform_function, 'octetstream')) {
2392 if ($default_function != $transform_function) {
2393 $result = $transform_function($result, $transform_options, $meta);
2395 $result = $default_function($result, array(), $meta);
2396 if (stristr($meta->type
, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2397 // in this case, restart from the original $content
2398 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2400 /* Create link to download */
2401 if (count($url_params) > 0) {
2402 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2410 * Prepares the displayable content of a data cell in Browse mode,
2411 * taking into account foreign key description field and transformations
2414 * @uses PMA_backquote()
2415 * @uses PMA_DBI_try_query()
2416 * @uses PMA_DBI_num_rows()
2417 * @uses PMA_DBI_fetch_row()
2418 * @uses PMA_DBI_free_result()
2419 * @uses $GLOBALS['printview']
2420 * @uses htmlspecialchars()
2421 * @uses PMA_generate_common_url()
2422 * @param string $class
2423 * @param string $condition_field
2424 * @param string $analyzed_sql
2425 * @param object $meta the meta-information about this field
2426 * @param string $map
2427 * @param string $data
2428 * @param string $transform_function
2429 * @param string $default_function
2430 * @param string $nowrap
2431 * @param string $where_comparison
2432 * @param bool $is_field_truncated
2433 * @return string formatted data
2435 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 ) {
2437 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2439 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2440 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2441 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2442 if (isset($alias) && strlen($alias)) {
2443 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2444 if ($alias == $meta->name
) {
2445 // this change in the parameter does not matter
2446 // outside of the function
2447 $meta->name
= $true_column;
2453 if (isset($map[$meta->name
])) {
2454 // Field to display from the foreign table?
2455 if (isset($map[$meta->name
][2]) && strlen($map[$meta->name
][2])) {
2456 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name
][2])
2457 . ' FROM ' . PMA_backquote($map[$meta->name
][3])
2458 . '.' . PMA_backquote($map[$meta->name
][0])
2459 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
2460 . $where_comparison;
2461 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE
);
2462 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2463 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2465 $dispval = __('Link not found');
2467 @PMA_DBI_free_result
($dispresult);
2470 } // end if... else...
2472 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2473 $result .= ($transform_function != $default_function ?
$transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[->' . $dispval . ']</code>';
2476 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2477 // user chose "relational key" in the display options, so
2478 // the title contains the display field
2479 $title = (! empty($dispval))?
' title="' . htmlspecialchars($dispval) . '"' : '';
2481 $title = ' title="' . htmlspecialchars($data) . '"';
2484 $_url_params = array(
2485 'db' => $map[$meta->name
][3],
2486 'table' => $map[$meta->name
][0],
2488 'sql_query' => 'SELECT * FROM '
2489 . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
2490 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
2491 . $where_comparison,
2493 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2494 . '"' . $title . '>';
2496 if ($transform_function != $default_function) {
2497 // always apply a transformation on the real data,
2498 // not on the display field
2499 $result .= $transform_function($data, $transform_options, $meta);
2501 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2502 // user chose "relational display field" in the
2503 // display options, so show display field in the cell
2504 $result .= $transform_function($dispval, array(), $meta);
2506 // otherwise display data in the cell
2507 $result .= $transform_function($data, array(), $meta);
2513 $result .= ($transform_function != $default_function ?
$transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2515 $result .= '</td>' . "\n";
2521 * Generates a checkbox for multi-row submits
2523 * @uses htmlspecialchars
2524 * @param string $del_url
2525 * @param array $is_display
2526 * @param string $row_no
2527 * @param string $where_clause_html
2528 * @param string $del_query
2529 * @param string $id_suffix
2530 * @param string $class
2531 * @return string the generated HTML
2534 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class) {
2536 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2538 if (! empty($class)) {
2539 $ret .= 'class="' . $class . '"';
2541 $ret .= ' align="center">'
2542 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2543 . ' class="multi_checkbox"'
2544 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ?
'checked="checked"' : '') . ' />'
2551 * Generates an Edit link
2553 * @uses PMA_linkOrButton()
2554 * @param string $edit_url
2555 * @param string $class
2556 * @param string $edit_str
2557 * @param string $where_clause
2558 * @param string $where_clause_html
2559 * @return string the generated HTML
2561 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) {
2563 if (! empty($edit_url)) {
2564 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2565 . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE);
2567 * Where clause for selecting this row uniquely is provided as
2568 * a hidden input. Used by jQuery scripts for handling inline editing
2570 if(! empty($where_clause)) {
2571 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2573 $ret .= '</span></td>';
2579 * Generates an Copy link
2581 * @uses PMA_linkOrButton()
2582 * @param string $copy_url
2583 * @param string $copy_str
2584 * @param string $where_clause
2585 * @param string $where_clause_html
2586 * @return string the generated HTML
2588 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class) {
2590 if (! empty($copy_url)) {
2592 if (! empty($class)) {
2593 $ret .= 'class="' . $class . '" ';
2595 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2596 . PMA_linkOrButton($copy_url, $copy_str, array(), FALSE);
2598 * Where clause for selecting this row uniquely is provided as
2599 * a hidden input. Used by jQuery scripts for handling inline editing
2601 if(! empty($where_clause)) {
2602 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2604 $ret .= '</span></td>';
2610 * Generates a Delete link
2612 * @uses PMA_linkOrButton()
2613 * @param string $del_url
2614 * @param string $del_str
2615 * @param string $js_conf
2616 * @param string $class
2617 * @return string the generated HTML
2619 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
2621 if (! empty($del_url)) {
2623 if (! empty($class)) {
2624 $ret .= 'class="' . $class . '" ';
2626 $ret .= 'align="center" ' . ' >'
2627 . PMA_linkOrButton($del_url, $del_str, $js_conf, FALSE)
2634 * Generates checkbox and links at some position (left or right)
2635 * (only called for horizontal mode)
2637 * @uses PMA_generateCheckboxForMulti()
2638 * @uses PMA_generateEditLink()
2639 * @uses PMA_generateDeleteLink()
2640 * @uses PMA_generateCopyLink()
2641 * @param string $position
2642 * @param string $del_url
2643 * @param array $is_display
2644 * @param string $row_no
2645 * @param string $where_clause
2646 * @param string $where_clause_html
2647 * @param string $del_query
2648 * @param string $id_suffix
2649 * @param string $edit_url
2650 * @param string $copy_url
2651 * @param string $class
2652 * @param string $edit_str
2653 * @param string $del_str
2654 * @param string $js_conf
2655 * @return string the generated HTML
2657 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) {
2660 if ($position == 'left') {
2661 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2663 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2665 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2667 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2669 } elseif ($position == 'right') {
2670 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2672 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2674 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2676 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');