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/Table.class.php';
13 require_once './libraries/Index.class.php';
16 * Defines the display mode to use for the results of a SQL query
18 * It uses a synthetic string that contains all the required informations.
20 * - the first two characters stand for the action to do while
21 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
23 * - the next two characters stand for the action to do while
24 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
26 * - the next characters are boolean values (1/0) and respectively stand
27 * for sorting links, navigation bar, "insert a new row" link, the
28 * bookmark feature, the expand/collapse text/blob fields button and
29 * the "display printable view" option.
30 * Of course '0'/'1' means the feature won't/will be enabled.
32 * @param string the synthetic value for display_mode (see a few
33 * lines above for explanations)
34 * @param integer the total number of rows returned by the SQL query
35 * without any programmatically appended "LIMIT" clause
36 * (just a copy of $unlim_num_rows if it exists, else
37 * computed inside this function)
39 * @return array an array with explicit indexes for all the display
42 * @global string the database name
43 * @global string the table name
44 * @global integer the total number of rows returned by the SQL query
45 * without any programmatically appended "LIMIT" clause
46 * @global array the properties of the fields returned by the query
47 * @global string the URL to return to in case of error in a SQL
52 * @see PMA_displayTable()
54 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
57 global $unlim_num_rows, $fields_meta;
60 // 1. Initializes the $do_display array
61 $do_display = array();
62 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
63 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
64 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
65 $do_display['nav_bar'] = (string) $the_disp_mode[5];
66 $do_display['ins_row'] = (string) $the_disp_mode[6];
67 $do_display['bkm_form'] = (string) $the_disp_mode[7];
68 $do_display['text_btn'] = (string) $the_disp_mode[8];
69 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
71 // 2. Display mode is not "false for all elements" -> updates the
73 if ($the_disp_mode != 'nnnn000000') {
74 // 2.0 Print view -> set all elements to false!
75 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
76 $do_display['edit_lnk'] = 'nn'; // no edit link
77 $do_display['del_lnk'] = 'nn'; // no delete link
78 $do_display['sort_lnk'] = (string) '0';
79 $do_display['nav_bar'] = (string) '0';
80 $do_display['ins_row'] = (string) '0';
81 $do_display['bkm_form'] = (string) '0';
82 $do_display['text_btn'] = (string) '0';
83 $do_display['pview_lnk'] = (string) '0';
85 // 2.1 Statement is a "SELECT COUNT", a
86 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
87 // contains a "PROC ANALYSE" part
88 elseif ($GLOBALS['is_count'] ||
$GLOBALS['is_analyse'] ||
$GLOBALS['is_maint'] ||
$GLOBALS['is_explain']) {
89 $do_display['edit_lnk'] = 'nn'; // no edit link
90 $do_display['del_lnk'] = 'nn'; // no delete link
91 $do_display['sort_lnk'] = (string) '0';
92 $do_display['nav_bar'] = (string) '0';
93 $do_display['ins_row'] = (string) '0';
94 $do_display['bkm_form'] = (string) '1';
95 if ($GLOBALS['is_maint']) {
96 $do_display['text_btn'] = (string) '1';
98 $do_display['text_btn'] = (string) '0';
100 $do_display['pview_lnk'] = (string) '1';
102 // 2.2 Statement is a "SHOW..."
103 elseif ($GLOBALS['is_show']) {
106 * @todo defines edit/delete links depending on show statement
108 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
109 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
110 $do_display['edit_lnk'] = 'nn'; // no edit link
111 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
113 // Default case -> no links
114 $do_display['edit_lnk'] = 'nn'; // no edit link
115 $do_display['del_lnk'] = 'nn'; // no delete link
117 // 2.2.2 Other settings
118 $do_display['sort_lnk'] = (string) '0';
119 $do_display['nav_bar'] = (string) '0';
120 $do_display['ins_row'] = (string) '0';
121 $do_display['bkm_form'] = (string) '1';
122 $do_display['text_btn'] = (string) '1';
123 $do_display['pview_lnk'] = (string) '1';
125 // 2.3 Other statements (ie "SELECT" ones) -> updates
126 // $do_display['edit_lnk'], $do_display['del_lnk'] and
127 // $do_display['text_btn'] (keeps other default values)
129 $prev_table = $fields_meta[0]->table
;
130 $do_display['text_btn'] = (string) '1';
131 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++
) {
132 $is_link = ($do_display['edit_lnk'] != 'nn'
133 ||
$do_display['del_lnk'] != 'nn'
134 ||
$do_display['sort_lnk'] != '0'
135 ||
$do_display['ins_row'] != '0');
136 // 2.3.2 Displays edit/delete/sort/insert links?
138 && ($fields_meta[$i]->table
== '' ||
$fields_meta[$i]->table
!= $prev_table)) {
139 $do_display['edit_lnk'] = 'nn'; // don't display links
140 $do_display['del_lnk'] = 'nn';
142 * @todo May be problematic with same fields names in two joined table.
144 // $do_display['sort_lnk'] = (string) '0';
145 $do_display['ins_row'] = (string) '0';
146 if ($do_display['text_btn'] == '1') {
150 // 2.3.3 Always display print view link
151 $do_display['pview_lnk'] = (string) '1';
152 $prev_table = $fields_meta[$i]->table
;
154 } // end if..elseif...else (2.1 -> 2.3)
157 // 3. Gets the total number of rows if it is unknown
158 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
159 $the_total = $unlim_num_rows;
160 } elseif (($do_display['nav_bar'] == '1' ||
$do_display['sort_lnk'] == '1')
161 && (strlen($db) && !empty($table))) {
162 $the_total = PMA_Table
::countRecords($db, $table, true);
165 // 4. If navigation bar or sorting fields names URLs should be
166 // displayed but there is only one row, change these settings to
168 if ($do_display['nav_bar'] == '1' ||
$do_display['sort_lnk'] == '1') {
170 // - Do not display sort links if less than 2 rows.
171 // - For a VIEW we (probably) did not count the number of rows
172 // so don't test this number here, it would remove the possibility
173 // of sorting VIEW results.
174 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table
::isView($db, $table)) {
175 // garvin: force display of navbar for vertical/horizontal display-choice.
176 // $do_display['nav_bar'] = (string) '0';
177 $do_display['sort_lnk'] = (string) '0';
181 // 5. Updates the synthetic var
182 $the_disp_mode = join('', $do_display);
185 } // end of the 'PMA_setDisplayMode()' function
189 * Displays a navigation bar to browse among the results of a SQL query
191 * @uses $_SESSION['userconf']['disp_direction']
192 * @uses $_SESSION['userconf']['repeat_cells']
193 * @uses $_SESSION['userconf']['max_rows']
194 * @uses $_SESSION['userconf']['pos']
195 * @param integer the offset for the "next" page
196 * @param integer the offset for the "previous" page
197 * @param string the URL-encoded query
199 * @global string $db the database name
200 * @global string $table the table name
201 * @global string $goto the URL to go back in case of errors
202 * @global integer $num_rows the total number of rows returned by the
204 * @global integer $unlim_num_rows the total number of rows returned by the
205 * SQL any programmatically appended "LIMIT" clause
206 * @global boolean $is_innodb whether its InnoDB or not
207 * @global array $showtable table definitions
211 * @see PMA_displayTable()
213 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query)
215 global $db, $table, $goto;
216 global $num_rows, $unlim_num_rows;
220 // here, using htmlentities() would cause problems if the query
221 // contains accented characters
222 $html_sql_query = htmlspecialchars($sql_query);
225 * @todo move this to a central place
226 * @todo for other future table types
228 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
232 <!-- Navigation bar
-->
233 <table border
="0" cellpadding
="2" cellspacing
="0">
236 // Move to the beginning or to the previous page
237 if ($_SESSION['userconf']['pos'] && $_SESSION['userconf']['max_rows'] != 'all') {
238 // loic1: patch #474210 from Gosha Sakovich - part 1
239 if ($GLOBALS['cfg']['NavigationBarIconic']) {
240 $caption1 = '<<';
241 $caption2 = ' < ';
242 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
243 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
245 $caption1 = $GLOBALS['strPos1'] . ' <<';
246 $caption2 = $GLOBALS['strPrevious'] . ' <';
249 } // end if... else...
252 <form action
="sql.php" method
="post">
253 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
254 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
255 <input type
="hidden" name
="pos" value
="0" />
256 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
257 <input type
="submit" name
="navig" value
="<?php echo $caption1; ?>"<?php
echo $title1; ?
> />
261 <form action
="sql.php" method
="post">
262 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
263 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
264 <input type
="hidden" name
="pos" value
="<?php echo $pos_prev; ?>" />
265 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
266 <input type
="submit" name
="navig" value
="<?php echo $caption2; ?>"<?php
echo $title2; ?
> />
276 <?php
// if displaying a VIEW, $unlim_num_rows could be zero because
277 // of $cfg['MaxExactCountViews']; in this case, avoid passing
278 // the 5th parameter to checkFormElementInRange()
279 // (this means we can't validate the upper limit ?>
280 <form action
="sql.php" method
="post"
281 onsubmit
="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 1) && checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
282 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
283 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
284 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
285 <input type
="submit" name
="navig" value
="<?php echo $GLOBALS['strShow']; ?> :" />
286 <input type
="text" name
="session_max_rows" size
="3" value
="<?php echo (($_SESSION['userconf']['max_rows'] != 'all') ? $_SESSION['userconf']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus
="this.select()" />
287 <?php
echo $GLOBALS['strRowsFrom'] . "\n"; ?
>
288 <input type
="text" name
="pos" size
="6" value
="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus
="this.select()" />
291 // Display mode (horizontal/vertical and repeat headers)
292 $param1 = ' <select name="disp_direction">' . "\n"
293 . ' <option value="horizontal"' . (($_SESSION['userconf']['disp_direction'] == 'horizontal') ?
' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
294 . ' <option value="horizontalflipped"' . (($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ?
' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
295 . ' <option value="vertical"' . (($_SESSION['userconf']['disp_direction'] == 'vertical') ?
' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
296 . ' </select>' . "\n"
298 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['userconf']['repeat_cells'] . '" class="textfield" />' . "\n"
300 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
308 // Move to the next page or to the last one
309 if (($_SESSION['userconf']['pos'] +
$_SESSION['userconf']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['userconf']['max_rows']
310 && $_SESSION['userconf']['max_rows'] != 'all') {
311 // loic1: patch #474210 from Gosha Sakovich - part 2
312 if ($GLOBALS['cfg']['NavigationBarIconic']) {
313 $caption3 = ' > ';
314 $caption4 = '>>';
315 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
316 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
318 $caption3 = '> ' . $GLOBALS['strNext'];
319 $caption4 = '>> ' . $GLOBALS['strEnd'];
322 } // end if... else...
326 <form action
="sql.php" method
="post">
327 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
328 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
329 <input type
="hidden" name
="pos" value
="<?php echo $pos_next; ?>" />
330 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
331 <input type
="submit" name
="navig" value
="<?php echo $caption3; ?>"<?php
echo $title3; ?
> />
335 <form action
="sql.php" method
="post"
336 onsubmit
="return <?php echo (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['userconf']['max_rows']) ? 'true' : 'false'); ?>">
337 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
338 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
339 <input type
="hidden" name
="pos" value
="<?php echo @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows'])- 1) * $_SESSION['userconf']['max_rows']); ?>" />
341 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
342 echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
343 // no backquote around this message
344 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
347 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
348 <input type
="submit" name
="navig" value
="<?php echo $caption4; ?>"<?php
echo $title4; ?
> <?php
echo (empty($onclick) ?
'' : $onclick); ?
>/>
356 // (unless we are showing all records)
357 if ('all' != $_SESSION['userconf']['max_rows']) { //if1
358 $pageNow = @floor
($_SESSION['userconf']['pos'] / $_SESSION['userconf']['max_rows']) +
1;
359 $nbTotalPage = @ceil
($unlim_num_rows / $_SESSION['userconf']['max_rows']);
361 if ($nbTotalPage > 1){ //if2
367 <?php
//<form> for keep the form alignment of button < and << ?>
370 $_url_params = array(
373 'sql_query' => $sql_query,
376 echo PMA_pageselector(
377 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
378 $_SESSION['userconf']['max_rows'],
386 $GLOBALS['strPageNumber']
395 // Display the "Show all" button if allowed
396 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
403 <form action
="sql.php" method
="post">
404 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
405 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
406 <input type
="hidden" name
="pos" value
="0" />
407 <input type
="hidden" name
="session_max_rows" value
="all" />
408 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
409 <input type
="submit" name
="navig" value
="<?php echo $GLOBALS['strShowAll']; ?>" />
420 } // end of the 'PMA_displayTableNavigation()' function
424 * Displays the headers of the results table
426 * @uses $_SESSION['userconf']['disp_direction']
427 * @uses $_SESSION['userconf']['repeat_cells']
428 * @uses $_SESSION['userconf']['max_rows']
429 * @uses $_SESSION['userconf']['dontlimitchars']
430 * @param array which elements to display
431 * @param array the list of fields properties
432 * @param integer the total number of fields returned by the SQL query
433 * @param array the analyzed query
435 * @return boolean always true
437 * @global string $db the database name
438 * @global string $table the table name
439 * @global string $goto the URL to go back in case of errors
440 * @global string $sql_query the SQL query
441 * @global integer $num_rows the total number of rows returned by the
443 * @global array $vertical_display informations used with vertical display
448 * @see PMA_displayTable()
450 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
452 global $db, $table, $goto;
453 global $sql_query, $num_rows;
454 global $vertical_display, $highlight_columns;
456 if ($analyzed_sql == '') {
457 $analyzed_sql = array();
460 // can the result be sorted?
461 if ($is_display['sort_lnk'] == '1') {
464 $unsorted_sql_query = $sql_query;
465 if (isset($analyzed_sql[0]['unsorted_query'])) {
466 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
469 // we need $sort_expression and $sort_expression_nodirection
470 // even if there are many table references
472 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
475 * Get rid of ASC|DESC
478 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
479 $sort_expression_nodirection = isset($matches[1]) ?
trim($matches[1]) : $sort_expression;
481 // sorting by indexes, only if it makes sense (only one table ref)
482 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
483 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
484 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
486 // grab indexes data:
487 $indexes = PMA_Index
::getFromTable($table, $db);
489 // do we have any index?
492 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
493 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
495 if ($is_display['edit_lnk'] != 'nn') {
498 if ($is_display['del_lnk'] != 'nn') {
501 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
505 $span = $num_rows +
floor($num_rows/$_SESSION['userconf']['repeat_cells']) +
1;
508 echo '<form action="sql.php" method="post">' . "\n";
509 echo PMA_generate_common_hidden_inputs($db, $table);
510 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
512 $local_order = (isset($sort_expression) ?
$sort_expression : '');
513 foreach ($indexes as $index) {
514 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
515 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
516 $used_index = $used_index ||
$local_order == $asc_sort ||
$local_order == $desc_sort;
517 echo '<option value="'
518 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
519 . '"' . ($local_order == $asc_sort ?
' selected="selected"' : '')
520 . '>' . htmlspecialchars($index->getName()) . ' ('
521 . $GLOBALS['strAscending'] . ')</option>';
522 echo '<option value="'
523 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
524 . '"' . ($local_order == $desc_sort ?
' selected="selected"' : '')
525 . '>' . htmlspecialchars($index->getName()) . ' ('
526 . $GLOBALS['strDescending'] . ')</option>';
528 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ?
'' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
529 echo '</select>' . "\n";
530 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
531 echo '</form>' . "\n";
537 $vertical_display['emptypre'] = 0;
538 $vertical_display['emptyafter'] = 0;
539 $vertical_display['textbtn'] = '';
542 // Start of form for multi-rows delete
544 if ($is_display['del_lnk'] == 'dr' ||
$is_display['del_lnk'] == 'kp') {
545 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
546 echo PMA_generate_common_hidden_inputs($db, $table, 1);
547 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
550 echo '<table id="table_results" class="data">' . "\n";
551 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
552 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
553 echo '<thead><tr>' . "\n";
556 // 1. Displays the full/partial text button (part 1)...
557 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
558 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
559 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
563 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
570 'sql_query' => $sql_query,
573 $text_message = '<img class="fulltext" width="50" height="20"';
574 if ($_SESSION['userconf']['dontlimitchars']) {
575 $url_params['dontlimitchars'] = '0';
577 . ' src="' . $GLOBALS['pmaThemeImage'] . 's_partialtext.png"'
578 . ' alt="' . $GLOBALS['strPartialText'] . '"'
579 . ' title="' . $GLOBALS['strPartialText'] . '"';
581 $url_params['dontlimitchars'] = '1';
583 . ' src="' . $GLOBALS['pmaThemeImage'] . 's_fulltext.png"'
584 . ' alt="' . $GLOBALS['strFullText'] . '"'
585 . ' title="' . $GLOBALS['strFullText'] . '"';
587 $text_message .= ' />';
588 $text_url = 'sql.php' . PMA_generate_common_url($url_params);
589 $text_link = PMA_linkOrButton($text_url, $text_message, array(), false);
591 // ... before the result table
592 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
593 && $is_display['text_btn'] == '1') {
594 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 0;
595 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
596 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
598 <th colspan
="<?php echo $fields_cnt; ?>"><?php
echo $text_link; ?
></th
>
602 } // end horizontal/horizontalflipped mode
606 <th colspan
="<?php echo $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1; ?>">
607 <?php
echo $text_link; ?
></th
>
610 } // end vertical mode
613 // ... at the left column of the result table header if possible
615 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
616 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 0;
617 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
618 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
620 <th
<?php
echo $colspan; ?
>><?php
echo $text_link; ?
></th
>
622 } // end horizontal/horizontalflipped mode
624 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
625 . ' ' . $text_link . "\n"
627 } // end vertical mode
630 // ... elseif no button, displays empty(ies) col(s) if required
631 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
632 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')) {
633 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 0;
634 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
635 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
637 <td
<?php
echo $colspan; ?
>></td
>
639 } // end horizontal/horizontalfipped mode
641 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
642 } // end vertical mode
645 // 2. Displays the fields' name
646 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
647 // statement (see 2.1.3)
649 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
650 // Do not show comments, if using horizontalflipped mode, because of space usage
651 if ($GLOBALS['cfg']['ShowBrowseComments']
652 && $_SESSION['userconf']['disp_direction'] != 'horizontalflipped') {
653 $comments_map = array();
654 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
655 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
656 $tb = $tbl['table_true_name'];
657 $comments_map[$tb] = PMA_getComments($db, $tb);
663 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
664 require_once './libraries/transformations.lib.php';
665 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
668 if ($is_display['sort_lnk'] == '1') {
669 $select_expr = $analyzed_sql[0]['select_expr_clause'];
672 // garvin: See if we have to highlight any header fields of a WHERE query.
673 // Uses SQL-Parser results.
674 $highlight_columns = array();
675 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
676 isset($analyzed_sql[0]['where_clause_identifiers'])) {
679 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
680 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
681 $highlight_columns[$wci] = 'true';
686 for ($i = 0; $i < $fields_cnt; $i++
) {
687 // garvin: See if this column should get highlight because it's used in the
689 if (isset($highlight_columns[$fields_meta[$i]->name
]) ||
isset($highlight_columns[PMA_backquote($fields_meta[$i]->name
)])) {
690 $condition_field = true;
692 $condition_field = false;
695 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
696 if (isset($comments_map) &&
697 isset($comments_map[$fields_meta[$i]->table
]) &&
698 isset($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
])) {
699 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
]) . '</span>';
704 // 2.1 Results can be sorted
705 if ($is_display['sort_lnk'] == '1') {
707 // 2.1.1 Checks if the table name is required; it's the case
708 // for a query with a "JOIN" statement and if the column
709 // isn't aliased, or in queries like
710 // SELECT `1`.`master_field` , `2`.`master_field`
711 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
713 if (isset($fields_meta[$i]->table
) && strlen($fields_meta[$i]->table
)) {
714 $sort_tbl = PMA_backquote($fields_meta[$i]->table
) . '.';
719 // 2.1.2 Checks if the current column is used to sort the
721 // the orgname member does not exist for all MySQL versions
722 // but if found, it's the one on which to sort
723 $name_to_use_in_sort = $fields_meta[$i]->name
;
724 if (isset($fields_meta[$i]->orgname
)) {
725 $name_to_use_in_sort = $fields_meta[$i]->orgname
;
727 // $name_to_use_in_sort might contain a space due to
728 // formatting of function expressions like "COUNT(name )"
729 // so we remove spaces; this might cause problems with spaces
730 // inside a column name.
731 $name_to_use_in_sort = str_replace(' ', '', $name_to_use_in_sort);
733 if (empty($sort_expression)) {
736 // field name may be preceded by a space, or any number
737 // of characters followed by a dot (tablename.fieldname)
738 // so do a direct comparison
739 // for the sort expression (avoids problems with queries
740 // like "SELECT id, count(id)..." and clicking to sort
741 // on id or on count(id))
742 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ?
true : false);
744 // 2.1.3 Check the field name for a bracket.
745 // If it contains one, it's probably a function column
746 // like 'COUNT(`field`)'
747 if (strpos($name_to_use_in_sort, '(') !== false) {
748 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
750 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
752 unset($name_to_use_in_sort);
754 // 2.1.4 Do define the sorting URL
756 // loic1: patch #455484 ("Smart" order)
757 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
758 if ($GLOBALS['cfg']['Order'] === 'SMART') {
759 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type
)) ?
'DESC' : 'ASC';
761 $sort_order .= $GLOBALS['cfg']['Order'];
764 } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
765 $sort_order .= ' ASC';
766 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
768 $sort_order .= ' DESC';
769 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
772 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
773 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
775 $sorted_sql_query = $unsorted_sql_query . $sort_order;
777 $_url_params = array(
780 'sql_query' => $sorted_sql_query,
782 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
784 // 2.1.5 Displays the sorting URL
785 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
786 // enable sort order swapping for image
787 $order_link_params = array();
788 if (isset($order_img) && $order_img!='') {
789 if (strstr($order_img, 'asc')) {
790 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
791 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
792 } elseif (strstr($order_img, 'desc')) {
793 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
794 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
797 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
798 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
799 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
801 $order_link_params['title'] = $GLOBALS['strSort'];
802 $order_link_content = ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ?
PMA_flipstring(htmlspecialchars($fields_meta[$i]->name
), "<br />\n") : htmlspecialchars($fields_meta[$i]->name
));
803 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
805 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
806 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
808 if ($condition_field) {
809 echo ' class="condition"';
811 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
812 echo ' valign="bottom"';
814 echo '>' . $order_link . $comments . '</th>';
816 $vertical_display['desc'][] = ' <th '
817 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
818 . $order_link . $comments . ' </th>' . "\n";
821 // 2.2 Results can't be sorted
823 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
824 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
826 if ($condition_field) {
827 echo ' class="condition"';
829 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
830 echo ' valign="bottom"';
832 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
833 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
834 echo ' style="direction: ltr; writing-mode: tb-rl;"';
837 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
838 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
839 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name
), '<br />');
841 echo htmlspecialchars($fields_meta[$i]->name
);
843 echo "\n" . $comments . '</th>';
845 $vertical_display['desc'][] = ' <th '
846 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
847 . ' ' . htmlspecialchars($fields_meta[$i]->name
) . "\n"
848 . $comments . ' </th>';
852 // 3. Displays the full/partial text button (part 2) at the right
853 // column of the result table header if possible and required...
854 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
855 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')
856 && $is_display['text_btn'] == '1') {
857 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 1;
858 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
859 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
862 <th
<?php
echo $colspan; ?
>>
863 <?php
echo $text_link; ?
>
866 } // end horizontal/horizontalflipped mode
868 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
869 . ' ' . $text_link . "\n"
871 } // end vertical mode
874 // ... elseif no button, displays empty columns if required
875 // (unless coming from Browse mode print view)
876 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
877 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
878 && (!$GLOBALS['is_header_sent'])) {
879 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 1;
880 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
881 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
884 <td
<?php
echo $colspan; ?
>></td
>
886 } // end horizontal/horizontalflipped mode
888 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
889 } // end vertical mode
892 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
893 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
901 } // end of the 'PMA_displayTableHeaders()' function
906 * Displays the body of the results table
908 * @uses $_SESSION['userconf']['disp_direction']
909 * @uses $_SESSION['userconf']['repeat_cells']
910 * @uses $_SESSION['userconf']['max_rows']
911 * @uses $_SESSION['userconf']['dontlimitchars']
912 * @param integer the link id associated to the query which results have
914 * @param array which elements to display
915 * @param array the list of relations
916 * @param array the analyzed query
918 * @return boolean always true
920 * @global string $db the database name
921 * @global string $table the table name
922 * @global string $goto the URL to go back in case of errors
923 * @global string $sql_query the SQL query
924 * @global array $fields_meta the list of fields properties
925 * @global integer $fields_cnt the total number of fields returned by
927 * @global array $vertical_display informations used with vertical display
929 * @global array $highlight_columns column names to highlight
930 * @global array $row current row data
934 * @see PMA_displayTable()
936 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
937 global $db, $table, $goto;
938 global $sql_query, $fields_meta, $fields_cnt;
939 global $vertical_display, $highlight_columns;
940 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
942 $url_sql_query = $sql_query;
944 // query without conditions to shorten URLs when needed, 200 is just
945 // guess, it should depend on remaining URL length
947 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
948 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
949 strlen($sql_query) > 200) {
951 $url_sql_query = 'SELECT ';
952 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
953 $url_sql_query .= ' DISTINCT ';
955 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
956 if (!empty($analyzed_sql[0]['from_clause'])) {
957 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
961 if (!is_array($map)) {
965 $vertical_display['edit'] = array();
966 $vertical_display['delete'] = array();
967 $vertical_display['data'] = array();
968 $vertical_display['row_delete'] = array();
970 // Correction University of Virginia 19991216 in the while below
971 // Previous code assumed that all tables have keys, specifically that
972 // the phpMyAdmin GUI should support row delete/edit only for such
974 // Although always using keys is arguably the prescribed way of
975 // defining a relational table, it is not required. This will in
976 // particular be violated by the novice.
977 // We want to encourage phpMyAdmin usage by such novices. So the code
978 // below has been changed to conditionally work as before when the
979 // table being displayed has one or more keys; but to display
980 // delete/edit options correctly for tables without keys.
982 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
983 // to get the NULL values
985 // rabus: This function needs a little rework.
986 // Using MYSQL_BOTH just pollutes the memory!
988 // ne0x: Use function PMA_DBI_fetch_array() due to mysqli
989 // compatibility. Now this function is wrapped.
992 while ($row = PMA_DBI_fetch_row($dt_result)) {
993 // lem9: "vertical display" mode stuff
994 if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no %
$_SESSION['userconf']['repeat_cells'])
995 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
996 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
999 if ($vertical_display['emptypre'] > 0) {
1000 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1001 .' </th>' . "\n";
1004 foreach ($vertical_display['desc'] as $val) {
1008 if ($vertical_display['emptyafter'] > 0) {
1009 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1010 .' </th>' . "\n";
1012 echo '</tr>' . "\n";
1015 $class = $odd_row ?
'odd' : 'even';
1016 $odd_row = ! $odd_row;
1017 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1018 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1019 // loic1: pointer code part
1020 echo ' <tr class="' . $class . '">' . "\n";
1025 // 1. Prepares the row (gets primary keys to use)
1026 // 1.1 Results from a "SELECT" statement -> builds the
1027 // "primary" key to use in links
1029 * @todo $unique_condition could be empty, for example a table
1030 * with only one field and it's a BLOB; in this case,
1031 * avoid to display the delete and edit links
1033 //$unique_condition = urlencode(PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row));
1034 $unique_condition = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1035 $unique_condition_html = htmlspecialchars($unique_condition);
1037 // 1.2 Defines the URLs for the modify/delete link(s)
1039 if ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn') {
1040 // We need to copy the value or else the == 'both' check will always return true
1042 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1043 $iconic_spacer = '<div class="nowrap">';
1045 $iconic_spacer = '';
1048 // 1.2.1 Modify link(s)
1049 if ($is_display['edit_lnk'] == 'ur') { // update row case
1050 $_url_params = array(
1053 'primary_key' => $unique_condition,
1054 'sql_query' => $url_sql_query,
1055 'goto' => 'sql.php',
1057 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
1059 $edit_str = PMA_getIcon('b_edit.png', $GLOBALS['strEdit'], true);
1062 if (isset($GLOBALS['cfg']['Bookmark']['table']) && isset($GLOBALS['cfg']['Bookmark']['db']) && $table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
1063 $_url_params = array(
1065 'id_bookmark' => $row[0],
1066 'action_bookmark' => '0',
1067 'action_bookmark_all' => '1',
1068 'SQL' => $GLOBALS['strExecuteBookmarked'],
1070 $bookmark_go = '<a href="import.php'
1071 . PMA_generate_common_url($_url_params)
1072 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1074 $bookmark_go .= PMA_getIcon('b_bookmark.png', $GLOBALS['strExecuteBookmarked'], true);
1076 $bookmark_go .= '</a>';
1081 // 1.2.2 Delete/Kill link(s)
1082 if ($is_display['del_lnk'] == 'dr') { // delete row case
1083 $_url_params = array(
1086 'sql_query' => $url_sql_query,
1087 'zero_rows' => $GLOBALS['strDeleted'],
1088 'goto' => (empty($goto) ?
'tbl_sql.php' : $goto),
1090 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1092 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1093 . ' WHERE' . $unique_condition . ' LIMIT 1';
1095 $_url_params = array(
1098 'sql_query' => $del_query,
1099 'zero_rows' => $GLOBALS['strDeleted'],
1100 'goto' => $lnk_goto,
1102 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1104 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1105 . ' WHERE ' . trim(PMA_jsFormat($unique_condition, false))
1107 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strDelete'], true);
1108 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1110 $_url_params = array(
1113 'sql_query' => $url_sql_query,
1114 'goto' => 'main.php',
1116 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1118 $_url_params = array(
1120 'sql_query' => 'KILL ' . $row[0],
1121 'goto' => $lnk_goto,
1123 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1124 $del_query = 'KILL ' . $row[0];
1125 $js_conf = 'KILL ' . $row[0];
1126 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strKill'], true);
1129 // 1.3 Displays the links at left if required
1130 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1131 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1132 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1133 $doWriteModifyAt = 'left';
1134 require './libraries/display_tbl_links.lib.php';
1138 // 2. Displays the rows' values
1139 for ($i = 0; $i < $fields_cnt; ++
$i) {
1140 $meta = $fields_meta[$i];
1142 // garvin: See if this column should get highlight because it's used in the
1144 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name
]) ||
isset($highlight_columns[PMA_backquote($meta->name
)]))) {
1145 $condition_field = true;
1147 $condition_field = false;
1151 if ($_SESSION['userconf']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) ||
($GLOBALS['printview'] != '1'))) {
1152 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1153 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1154 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1156 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1157 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1159 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1163 // garvin: Wrap MIME-transformations. [MIME]
1164 $default_function = 'default_function'; // default_function
1165 $transform_function = $default_function;
1166 $transform_options = array();
1168 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1170 if (isset($GLOBALS['mime_map'][$meta->name
]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name
]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name
]['transformation'])) {
1171 $include_file = $GLOBALS['mime_map'][$meta->name
]['transformation'];
1173 if (file_exists('./libraries/transformations/' . $include_file)) {
1174 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name
]['transformation']);
1176 require_once './libraries/transformations/' . $include_file;
1178 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1179 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1180 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name
]['transformation_options']) ?
$GLOBALS['mime_map'][$meta->name
]['transformation_options'] : ''));
1181 $meta->mimetype
= str_replace('_', '/', $GLOBALS['mime_map'][$meta->name
]['mimetype']);
1183 } // end if file_exists
1184 } // end if transformation is set
1185 } // end if mime/transformation works.
1187 $_url_params = array(
1190 'primary_key' => $unique_condition,
1191 // $sql_goto ??? typo?
1192 //'goto' => (isset($sql_goto) ? $lnk_goto : ''),
1193 'transform_key' => $meta->name
,
1196 if (! empty($sql_query)) {
1197 $_url_params['sql_query'] = $url_sql_query;
1200 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1203 if ($meta->numeric == 1) {
1205 // lem9: if two fields have the same name (this is possible
1206 // with self-join queries, for example), using $meta->name
1207 // will show both fields NULL even if only one is NULL,
1208 // so use the $pointer
1209 // PS: why not always work with the number ($i), since
1210 // the default second parameter of
1211 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1212 // associative and numeric indices?
1214 //if (!isset($row[$meta->name])
1215 if (!isset($row[$i]) ||
is_null($row[$i])) {
1216 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"><i>NULL</i></td>' . "\n";
1217 } elseif ($row[$i] != '') {
1218 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . ' nowrap">';
1220 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1221 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1222 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1223 if (isset($alias) && strlen($alias)) {
1224 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1225 if ($alias == $meta->name
) {
1226 $meta->name
= $true_column;
1232 if (isset($map[$meta->name
])) {
1233 // Field to display from the foreign table?
1234 if (isset($map[$meta->name
][2]) && strlen($map[$meta->name
][2])) {
1235 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name
][2])
1236 . ' FROM ' . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
1237 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
1239 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE
);
1240 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1241 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
1243 $dispval = $GLOBALS['strLinkNotFound'];
1245 @PMA_DBI_free_result
($dispresult);
1248 } // end if... else...
1250 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1251 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ?
$transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' <code>[->' . $dispval . ']</code>';
1253 $title = (!empty($dispval))?
' title="' . htmlspecialchars($dispval) . '"' : '';
1255 $_url_params = array(
1256 'db' => $map[$meta->name
][3],
1257 'table' => $map[$meta->name
][0],
1259 'sql_query' => 'SELECT * FROM '
1260 . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
1261 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
1264 $vertical_display['data'][$row_no][$i]
1265 .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
1266 . '"' . $title . '>'
1267 . ($transform_function != $default_function
1268 ?
$transform_function($row[$i], $transform_options, $meta)
1269 : $transform_function($row[$i], array(), $meta))
1273 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ?
$transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
1275 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1277 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ?
' condition' : '') . '"> </td>' . "\n";
1282 } elseif ($GLOBALS['cfg']['ShowBlob'] == false && stristr($meta->type
, 'BLOB')) {
1283 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1284 // TEXT fields type, however TEXT fields must be displayed
1285 // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type
1287 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1288 if (stristr($field_flags, 'BINARY')) {
1289 $blobtext = '[BLOB';
1290 if (!isset($row[$i]) ||
is_null($row[$i])) {
1291 $blobtext .= ' - NULL';
1293 } elseif (isset($row[$i])) {
1294 $blob_size = strlen($row[$i]);
1295 $display_blob_size = PMA_formatByteDown($blob_size, 3, 1);
1296 $blobtext .= ' - '. $display_blob_size[0] . ' ' . $display_blob_size[1];
1297 unset($display_blob_size);
1301 if (strpos($transform_function, 'octetstream')) {
1302 $blobtext = $row[$i];
1304 if ($blob_size > 0) {
1305 $blobtext = ($default_function != $transform_function ?
$transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
1309 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '">' . $blobtext . '</td>';
1311 if (!isset($row[$i]) ||
is_null($row[$i])) {
1312 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"><i>NULL</i></td>' . "\n";
1313 } elseif ($row[$i] != '') {
1314 // garvin: if a transform function for blob is set, none of these replacements will be made
1315 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ! $_SESSION['userconf']['dontlimitchars']) {
1316 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1318 // loic1: displays all space characters, 4 space
1319 // characters for tabulations and <cr>/<lf>
1320 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1322 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1324 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"> </td>' . "\n";
1328 if (!isset($row[$i]) ||
is_null($row[$i])) {
1329 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"><i>NULL</i></td>' . "\n";
1330 } elseif ($row[$i] != '') {
1331 // loic1: support blanks in the key
1332 $relation_id = $row[$i];
1334 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1335 // lem9: (unless it's a link-type transformation)
1336 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ! $_SESSION['userconf']['dontlimitchars'] && !strpos($transform_function, 'link') === true) {
1337 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1340 // loic1: displays special characters from binaries
1341 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1342 if (isset($meta->_type
) && $meta->_type
=== MYSQLI_TYPE_BIT
) {
1343 $db_value = $row[$i];
1345 for ($j = 0; $j < ceil($meta->length
/ 8); $j++
) {
1346 $row[$i] .= sprintf('%08d', decbin(ord(substr($db_value, $j, 1))));
1348 $row[$i] = substr($row[$i], -$meta->length
);
1349 } elseif (stristr($field_flags, 'BINARY')) {
1350 $row[$i] = str_replace("\x00", '\0', $row[$i]);
1351 $row[$i] = str_replace("\x08", '\b', $row[$i]);
1352 $row[$i] = str_replace("\x0a", '\n', $row[$i]);
1353 $row[$i] = str_replace("\x0d", '\r', $row[$i]);
1354 $row[$i] = str_replace("\x1a", '\Z', $row[$i]);
1355 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1357 // loic1: displays all space characters, 4 space
1358 // characters for tabulations and <cr>/<lf>
1360 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1363 // garvin: transform functions may enable no-wrapping:
1364 $function_nowrap = $transform_function . '_nowrap';
1365 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ?
$function_nowrap($transform_options) : false);
1367 // loic1: do not wrap if date field type
1368 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type
) ||
$bool_nowrap) ?
' nowrap' : '');
1369 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . $nowrap . ($condition_field ?
' condition' : '') . '">';
1371 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1372 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1373 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1374 if (isset($alias) && strlen($alias)) {
1375 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1376 if ($alias == $meta->name
) {
1377 $meta->name
= $true_column;
1383 if (isset($map[$meta->name
])) {
1384 // Field to display from the foreign table?
1385 if (isset($map[$meta->name
][2]) && strlen($map[$meta->name
][2])) {
1386 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name
][2])
1387 . ' FROM ' . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
1388 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
1389 . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1390 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE
);
1391 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1392 list($dispval) = PMA_DBI_fetch_row($dispresult);
1393 @PMA_DBI_free_result
($dispresult);
1395 $dispval = $GLOBALS['strLinkNotFound'];
1400 $title = (!empty($dispval))?
' title="' . htmlspecialchars($dispval) . '"' : '';
1402 $_url_params = array(
1403 'db' => $map[$meta->name
][3],
1404 'table' => $map[$meta->name
][0],
1406 'sql_query' => 'SELECT * FROM '
1407 . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
1408 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
1409 . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'',
1411 $vertical_display['data'][$row_no][$i]
1412 .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
1413 . '"' . $title . '>' . $row[$i] . '</a>';
1415 $vertical_display['data'][$row_no][$i] .= $row[$i];
1417 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1419 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"> </td>' . "\n";
1423 // lem9: output stored cell
1424 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1425 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1426 echo $vertical_display['data'][$row_no][$i];
1429 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1430 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1432 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1436 // 3. Displays the modify/delete links on the right if required
1437 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1438 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1439 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1440 $doWriteModifyAt = 'right';
1441 require './libraries/display_tbl_links.lib.php';
1444 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1445 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1451 // 4. Gather links of del_urls and edit_urls in an array for later
1453 if (!isset($vertical_display['edit'][$row_no])) {
1454 $vertical_display['edit'][$row_no] = '';
1455 $vertical_display['delete'][$row_no] = '';
1456 $vertical_display['row_delete'][$row_no] = '';
1459 $column_style_vertical = '';
1460 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1461 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1462 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1464 $column_marker_vertical = '';
1465 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1466 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1469 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1470 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1471 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition_html . ']"'
1472 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1473 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ?
'checked="checked"' : '') . ' />' . "\n"
1476 unset($vertical_display['row_delete'][$row_no]);
1479 if (isset($edit_url)) {
1480 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1481 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1485 unset($vertical_display['edit'][$row_no]);
1488 if (isset($del_url)) {
1489 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1490 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ?
$js_conf : ''), false)
1493 unset($vertical_display['delete'][$row_no]);
1496 echo (($_SESSION['userconf']['disp_direction'] == 'horizontal' ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ?
"\n" : '');
1501 } // end of the 'PMA_displayTableBody()' function
1505 * Do display the result table with the vertical direction mode.
1506 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1508 * @return boolean always true
1510 * @uses $_SESSION['userconf']['repeat_cells']
1511 * @global array $vertical_display the information to display
1515 * @see PMA_displayTable()
1517 function PMA_displayVerticalTable()
1519 global $vertical_display;
1521 // Displays "multi row delete" link at top if required
1522 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1524 echo $vertical_display['textbtn'];
1526 foreach ($vertical_display['row_delete'] as $val) {
1527 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1528 echo '<th> </th>' . "\n";
1531 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1534 echo '</tr>' . "\n";
1537 // Displays "edit" link at top if required
1538 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1540 if (!is_array($vertical_display['row_delete'])) {
1541 echo $vertical_display['textbtn'];
1544 foreach ($vertical_display['edit'] as $val) {
1545 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1546 echo ' <th> </th>' . "\n";
1552 echo '</tr>' . "\n";
1555 // Displays "delete" link at top if required
1556 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1558 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1559 echo $vertical_display['textbtn'];
1562 foreach ($vertical_display['delete'] as $val) {
1563 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1564 echo '<th> </th>' . "\n";
1570 echo '</tr>' . "\n";
1574 foreach ($vertical_display['desc'] AS $key => $val) {
1580 foreach ($vertical_display['rowdata'][$key] as $subval) {
1581 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) and !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1589 echo '</tr>' . "\n";
1592 // Displays "multi row delete" link at bottom if required
1593 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1595 echo $vertical_display['textbtn'];
1597 foreach ($vertical_display['row_delete'] as $val) {
1598 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1599 echo '<th> </th>' . "\n";
1602 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1605 echo '</tr>' . "\n";
1608 // Displays "edit" link at bottom if required
1609 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1611 if (!is_array($vertical_display['row_delete'])) {
1612 echo $vertical_display['textbtn'];
1615 foreach ($vertical_display['edit'] as $val) {
1616 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1617 echo '<th> </th>' . "\n";
1623 echo '</tr>' . "\n";
1626 // Displays "delete" link at bottom if required
1627 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1629 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1630 echo $vertical_display['textbtn'];
1633 foreach ($vertical_display['delete'] as $val) {
1634 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1635 echo '<th> </th>' . "\n";
1641 echo '</tr>' . "\n";
1645 } // end of the 'PMA_displayVerticalTable' function
1649 * @uses $_SESSION['userconf']['disp_direction']
1650 * @uses $_REQUEST['disp_direction']
1651 * @uses $GLOBALS['cfg']['DefaultDisplay']
1652 * @uses $_SESSION['userconf']['repeat_cells']
1653 * @uses $_REQUEST['repeat_cells']
1654 * @uses $GLOBALS['cfg']['RepeatCells']
1655 * @uses $_SESSION['userconf']['max_rows']
1656 * @uses $_REQUEST['session_max_rows']
1657 * @uses $GLOBALS['cfg']['MaxRows']
1658 * @uses $_SESSION['userconf']['pos']
1659 * @uses $_REQUEST['pos']
1660 * @uses $_SESSION['userconf']['dontlimitchars']
1661 * @uses $_REQUEST['dontlimitchars']
1662 * @uses PMA_isValid()
1663 * @uses $GLOBALS['sql_query']
1664 * @todo make maximum remembered queries configurable
1665 * @todo move/split into SQL class!?
1666 * @todo currently this is called twice unnecessary
1667 * @todo ignore LIMIT and ORDER in query!?
1669 function PMA_displayTable_checkConfigParams()
1671 $sql_key = md5($GLOBALS['sql_query']);
1673 $_SESSION['userconf']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1675 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1676 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1677 unset($_REQUEST['disp_direction']);
1678 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['disp_direction'])) {
1679 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1682 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1683 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1684 unset($_REQUEST['repeat_cells']);
1685 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['repeat_cells'])) {
1686 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1689 if (PMA_isValid($_REQUEST['session_max_rows'], 'numeric') ||
$_REQUEST['session_max_rows'] == 'all') {
1690 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1691 unset($_REQUEST['session_max_rows']);
1692 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['max_rows'])) {
1693 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1696 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1697 $_SESSION['userconf']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1698 unset($_REQUEST['pos']);
1699 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['pos'])) {
1700 $_SESSION['userconf']['query'][$sql_key]['pos'] = 0;
1703 if (PMA_isValid($_REQUEST['dontlimitchars'], array('0', '1'))) {
1704 $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'] = (int) $_REQUEST['dontlimitchars'];
1705 unset($_REQUEST['dontlimitchars']);
1706 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['dontlimitchars'])) {
1707 $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'] = 0;
1710 // move current query to the last position, to be removed last
1711 // so only least executed query will be removed if maximum remembered queries
1713 $tmp = $_SESSION['userconf']['query'][$sql_key];
1714 unset($_SESSION['userconf']['query'][$sql_key]);
1715 $_SESSION['userconf']['query'][$sql_key] = $tmp;
1717 // do not exceed a maximum number of queries to remember
1718 if (count($_SESSION['userconf']['query']) > 10) {
1719 array_shift($_SESSION['userconf']['query']);
1720 //echo 'deleting one element ...';
1723 // populate query configuration
1724 $_SESSION['userconf']['dontlimitchars'] = $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'];
1725 $_SESSION['userconf']['pos'] = $_SESSION['userconf']['query'][$sql_key]['pos'];
1726 $_SESSION['userconf']['max_rows'] = $_SESSION['userconf']['query'][$sql_key]['max_rows'];
1727 $_SESSION['userconf']['repeat_cells'] = $_SESSION['userconf']['query'][$sql_key]['repeat_cells'];
1728 $_SESSION['userconf']['disp_direction'] = $_SESSION['userconf']['query'][$sql_key]['disp_direction'];
1733 var_dump($_SESSION['userconf']);
1739 * Displays a table of results returned by a SQL query.
1740 * This function is called by the "sql.php" script.
1742 * @param integer the link id associated to the query which results have
1744 * @param array the display mode
1745 * @param array the analyzed query
1747 * @uses $_SESSION['userconf']['pos']
1748 * @global string $db the database name
1749 * @global string $table the table name
1750 * @global string $goto the URL to go back in case of errors
1751 * @global string $sql_query the current SQL query
1752 * @global integer $num_rows the total number of rows returned by the
1754 * @global integer $unlim_num_rows the total number of rows returned by the
1755 * SQL query without any programmatically
1756 * appended "LIMIT" clause
1757 * @global array $fields_meta the list of fields properties
1758 * @global integer $fields_cnt the total number of fields returned by
1760 * @global array $vertical_display informations used with vertical display
1762 * @global array $highlight_columns column names to highlight
1763 * @global array $cfgRelation the relation settings
1767 * @see PMA_showMessage(), PMA_setDisplayMode(),
1768 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1769 * PMA_displayTableBody(), PMA_displayResultsOperations()
1771 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1773 global $db, $table, $goto;
1774 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1775 global $vertical_display, $highlight_columns;
1776 global $cfgRelation;
1779 PMA_displayTable_checkConfigParams();
1782 * @todo move this to a central place
1783 * @todo for other future table types
1785 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1788 && ! isset($analyzed_sql[0]['queryflags']['union'])
1789 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1790 && (empty($analyzed_sql[0]['where_clause'])
1791 ||
$analyzed_sql[0]['where_clause'] == '1 ')) {
1792 // "j u s t b r o w s i n g"
1794 $after_count = PMA_showHint($GLOBALS['strApproximateCount'], true);
1800 // 1. ----- Prepares the work -----
1802 // 1.1 Gets the informations about which functionalities should be
1805 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1807 // 1.2 Defines offsets for the next and previous pages
1808 if ($is_display['nav_bar'] == '1') {
1809 if ($_SESSION['userconf']['max_rows'] == 'all') {
1813 $pos_next = $_SESSION['userconf']['pos'] +
$_SESSION['userconf']['max_rows'];
1814 $pos_prev = $_SESSION['userconf']['pos'] - $_SESSION['userconf']['max_rows'];
1815 if ($pos_prev < 0) {
1821 // 1.3 URL-encodes the query to use in input form fields
1822 // @todo where is this used?
1823 //$encoded_sql_query = urlencode($sql_query);
1825 // 2. ----- Displays the top of the page -----
1827 // 2.1 Displays a messages with position informations
1828 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1829 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1830 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1834 $last_shown_rec = ($_SESSION['userconf']['max_rows'] == 'all' ||
$pos_next > $total)
1838 if (PMA_Table
::isView($db, $table)
1839 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1840 $message = PMA_Message
::notice('strViewMaxExactCount');
1841 $message->addParam($GLOBALS['cfg']['MaxExactCountViews']);
1842 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1843 $message->addParam('[/a]');
1844 $message_view_warning = PMA_showHint($message);
1846 $message_view_warning = false;
1849 $message = PMA_Message
::success('strShowingRecords');
1850 $message->addMessage($_SESSION['userconf']['pos']);
1851 if ($message_view_warning) {
1852 $message->addMessage('...', ' - ');
1853 $message->addMessage($message_view_warning);
1854 $message->addMessage('(');
1856 $message->addMessage($last_shown_rec, ' - ');
1857 $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
1858 $message->addString('strTotal');
1859 $message->addMessage($selectstring, '');
1860 $message->addMessage(', ', '');
1863 $messagge_qt = PMA_Message
::notice('strQueryTime');
1864 $messagge_qt->addParam($GLOBALS['querytime']);
1866 $message->addMessage($messagge_qt, '');
1867 $message->addMessage(')', '');
1869 PMA_showMessage($message, $sql_query, 'success');
1871 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
1872 PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
1875 // 2.3 Displays the navigation bars
1876 if (! strlen($table)) {
1877 if (isset($analyzed_sql[0]['query_type'])
1878 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1879 // table does not always contain a real table name,
1880 // for example in MySQL 5.0.x, the query SHOW STATUS
1881 // returns STATUS as a table name
1882 $table = $fields_meta[0]->table
;
1888 if ($is_display['nav_bar'] == '1') {
1889 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1891 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
1892 echo "\n" . '<br /><br />' . "\n";
1895 // 2b ----- Get field references from Database -----
1896 // (see the 'relation' configuration variable)
1897 // loic1, 2002-03-02: extended to php3
1904 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1905 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1906 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1909 $tabs = '(\'' . join('\',\'', $target) . '\')';
1911 if ($cfgRelation['displaywork']) {
1912 if (! strlen($table)) {
1915 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1917 foreach ($exist_rel AS $master_field => $rel) {
1918 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
1919 $map[$master_field] = array($rel['foreign_table'],
1920 $rel['foreign_field'],
1922 $rel['foreign_db']);
1929 // 3. ----- Displays the results table -----
1930 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1932 echo '<tbody>' . "\n";
1933 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1934 // vertical output case
1935 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1936 PMA_displayVerticalTable();
1938 unset($vertical_display);
1939 echo '</tbody>' . "\n";
1944 // 4. ----- Displays the link for multi-fields delete
1946 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1948 $delete_text = $is_display['del_lnk'] == 'dr' ?
$GLOBALS['strDelete'] : $GLOBALS['strKill'];
1950 $_url_params = array(
1953 'sql_query' => $sql_query,
1956 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1958 $_url_params['checkall'] = '1';
1959 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1961 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1962 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
1963 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
1965 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
1966 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
1968 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
1969 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
1970 if ($_SESSION['userconf']['disp_direction'] != 'vertical') {
1971 echo '<img class="selectallarrow" width="38" height="22"'
1972 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
1973 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
1975 echo $checkall_link . "\n"
1977 .$uncheckall_link . "\n"
1978 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
1980 PMA_buttonOrImage('submit_mult', 'mult_submit',
1981 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
1982 PMA_buttonOrImage('submit_mult', 'mult_submit',
1983 'submit_mult_delete', $delete_text, 'b_drop.png');
1984 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1985 PMA_buttonOrImage('submit_mult', 'mult_submit',
1986 'submit_mult_export', $GLOBALS['strExport'],
1991 echo '<input type="hidden" name="sql_query"'
1992 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1993 echo '<input type="hidden" name="url_query"'
1994 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
1995 echo '</form>' . "\n";
1998 // 5. ----- Displays the navigation bar at the bottom if required -----
2000 if ($is_display['nav_bar'] == '1') {
2001 echo '<br />' . "\n";
2002 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
2003 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2004 echo "\n" . '<br /><br />' . "\n";
2007 // 6. ----- Displays "Query results operations"
2008 if (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2009 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2011 } // end of the 'PMA_displayTable()' function
2013 function default_function($buffer) {
2014 $buffer = htmlspecialchars($buffer);
2015 $buffer = str_replace("\011", ' ',
2016 str_replace(' ', ' ', $buffer));
2017 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2023 * Displays operations that are available on results.
2025 * @param array the display mode
2026 * @param array the analyzed query
2028 * @uses $_SESSION['userconf']['pos']
2029 * @uses $_SESSION['userconf']['dontlimitchars']
2030 * @global string $db the database name
2031 * @global string $table the table name
2032 * @global string $sql_query the current SQL query
2033 * @global integer $unlim_num_rows the total number of rows returned by the
2034 * SQL query without any programmatically
2035 * appended "LIMIT" clause
2039 * @see PMA_showMessage(), PMA_setDisplayMode(),
2040 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2041 * PMA_displayTableBody(), PMA_displayResultsOperations()
2043 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2044 global $db, $table, $sql_query, $unlim_num_rows;
2046 $header_shown = FALSE;
2047 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
2049 if ($the_disp_mode[6] == '1' ||
$the_disp_mode[9] == '1') {
2050 // Displays "printable view" link if required
2051 if ($the_disp_mode[9] == '1') {
2053 if (!$header_shown) {
2055 $header_shown = TRUE;
2058 $_url_params = array(
2062 'sql_query' => $sql_query,
2064 $url_query = PMA_generate_common_url($_url_params);
2066 echo PMA_linkOrButton(
2067 'sql.php' . $url_query,
2068 PMA_getIcon('b_print.png', $GLOBALS['strPrintView'], false, true),
2069 '', true, true, 'print_view') . "\n";
2071 if (! $_SESSION['userconf']['dontlimitchars']) {
2072 $_url_params['dontlimitchars'] = 1;
2073 echo PMA_linkOrButton(
2074 'sql.php' . PMA_generate_common_url($_url_params),
2075 PMA_getIcon('b_print.png', $GLOBALS['strPrintViewFull'], false, true),
2076 '', true, true, 'print_view') . "\n";
2077 unset($_url_params['dontlimitchars']);
2079 } // end displays "printable view"
2083 // (the url_query has extra parameters that won't be used to export)
2084 // (the single_table parameter is used in display_export.lib.php
2085 // to hide the SQL and the structure export dialogs)
2086 // If the parser found a PROCEDURE clause
2087 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2088 // display the Export link).
2089 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2090 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2091 $_url_params['single_table'] = 'true';
2093 if (!$header_shown) {
2095 $header_shown = TRUE;
2097 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2098 echo PMA_linkOrButton(
2099 'tbl_export.php' . PMA_generate_common_url($_url_params),
2100 PMA_getIcon('b_tblexport.png', $GLOBALS['strExport'], false, true),
2101 '', true, true, '') . "\n";
2107 * @todo detect privileges to create a view
2108 * (but see 2006-01-19 note in display_create_table.lib.php,
2109 * I think we cannot detect db-specific privileges reliably)
2110 * Note: we don't display a Create view link if we found a PROCEDURE clause
2112 if (!$header_shown) {
2114 $header_shown = TRUE;
2116 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2117 echo PMA_linkOrButton(
2118 'view_create.php' . $url_query,
2119 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2120 '', true, true, '') . "\n";
2122 if ($header_shown) {
2123 echo '</fieldset><br />';