2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once './libraries/Table.class.php';
14 * Set of functions used to display the records returned by a SQL query
18 * Defines the display mode to use for the results of a SQL query
20 * It uses a synthetic string that contains all the required informations.
22 * - the first two characters stand for the action to do while
23 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
25 * - the next two characters stand for the action to do while
26 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
28 * - the next characters are boolean values (1/0) and respectively stand
29 * for sorting links, navigation bar, "insert a new row" link, the
30 * bookmark feature, the expand/collapse text/blob fields button and
31 * the "display printable view" option.
32 * Of course '0'/'1' means the feature won't/will be enabled.
34 * @param string the synthetic value for display_mode (see �1 a few
35 * lines above for explanations)
36 * @param integer the total number of rows returned by the SQL query
37 * without any programmatically appended "LIMIT" clause
38 * (just a copy of $unlim_num_rows if it exists, else
39 * computed inside this function)
41 * @return array an array with explicit indexes for all the display
44 * @global string the database name
45 * @global string the table name
46 * @global integer the total number of rows returned by the SQL query
47 * without any programmatically appended "LIMIT" clause
48 * @global array the properties of the fields returned by the query
49 * @global string the URL to return to in case of error in a SQL
54 * @see PMA_displayTable()
56 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
59 global $unlim_num_rows, $fields_meta;
62 // 1. Initializes the $do_display array
63 $do_display = array();
64 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
65 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
66 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
67 $do_display['nav_bar'] = (string) $the_disp_mode[5];
68 $do_display['ins_row'] = (string) $the_disp_mode[6];
69 $do_display['bkm_form'] = (string) $the_disp_mode[7];
70 $do_display['text_btn'] = (string) $the_disp_mode[8];
71 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
73 // 2. Display mode is not "false for all elements" -> updates the
75 if ($the_disp_mode != 'nnnn000000') {
76 // 2.0 Print view -> set all elements to false!
77 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
78 $do_display['edit_lnk'] = 'nn'; // no edit link
79 $do_display['del_lnk'] = 'nn'; // no delete link
80 $do_display['sort_lnk'] = (string) '0';
81 $do_display['nav_bar'] = (string) '0';
82 $do_display['ins_row'] = (string) '0';
83 $do_display['bkm_form'] = (string) '0';
84 $do_display['text_btn'] = (string) '0';
85 $do_display['pview_lnk'] = (string) '0';
87 // 2.1 Statement is a "SELECT COUNT", a
88 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
89 // contains a "PROC ANALYSE" part
90 elseif ($GLOBALS['is_count'] ||
$GLOBALS['is_analyse'] ||
$GLOBALS['is_maint'] ||
$GLOBALS['is_explain']) {
91 $do_display['edit_lnk'] = 'nn'; // no edit link
92 $do_display['del_lnk'] = 'nn'; // no delete link
93 $do_display['sort_lnk'] = (string) '0';
94 $do_display['nav_bar'] = (string) '0';
95 $do_display['ins_row'] = (string) '0';
96 $do_display['bkm_form'] = (string) '1';
97 if ($GLOBALS['is_maint']) {
98 $do_display['text_btn'] = (string) '1';
100 $do_display['text_btn'] = (string) '0';
102 $do_display['pview_lnk'] = (string) '1';
104 // 2.2 Statement is a "SHOW..."
105 elseif ($GLOBALS['is_show']) {
108 * @todo defines edit/delete links depending on show statement
110 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
111 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
112 $do_display['edit_lnk'] = 'nn'; // no edit link
113 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
115 // Default case -> no links
116 $do_display['edit_lnk'] = 'nn'; // no edit link
117 $do_display['del_lnk'] = 'nn'; // no delete link
119 // 2.2.2 Other settings
120 $do_display['sort_lnk'] = (string) '0';
121 $do_display['nav_bar'] = (string) '0';
122 $do_display['ins_row'] = (string) '0';
123 $do_display['bkm_form'] = (string) '1';
124 $do_display['text_btn'] = (string) '1';
125 $do_display['pview_lnk'] = (string) '1';
127 // 2.3 Other statements (ie "SELECT" ones) -> updates
128 // $do_display['edit_lnk'], $do_display['del_lnk'] and
129 // $do_display['text_btn'] (keeps other default values)
131 $prev_table = $fields_meta[0]->table
;
132 $do_display['text_btn'] = (string) '1';
133 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++
) {
134 $is_link = ($do_display['edit_lnk'] != 'nn'
135 ||
$do_display['del_lnk'] != 'nn'
136 ||
$do_display['sort_lnk'] != '0'
137 ||
$do_display['ins_row'] != '0');
138 // 2.3.2 Displays edit/delete/sort/insert links?
140 && ($fields_meta[$i]->table
== '' ||
$fields_meta[$i]->table
!= $prev_table)) {
141 $do_display['edit_lnk'] = 'nn'; // don't display links
142 $do_display['del_lnk'] = 'nn';
144 * @todo May be problematic with same fields names in two joined table.
146 // $do_display['sort_lnk'] = (string) '0';
147 $do_display['ins_row'] = (string) '0';
148 if ($do_display['text_btn'] == '1') {
152 // 2.3.3 Always display print view link
153 $do_display['pview_lnk'] = (string) '1';
154 $prev_table = $fields_meta[$i]->table
;
156 } // end if..elseif...else (2.1 -> 2.3)
159 // 3. Gets the total number of rows if it is unknown
160 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
161 $the_total = $unlim_num_rows;
162 } elseif (($do_display['nav_bar'] == '1' ||
$do_display['sort_lnk'] == '1')
163 && (strlen($db) && !empty($table))) {
164 $the_total = PMA_Table
::countRecords($db, $table, true);
167 // 4. If navigation bar or sorting fields names URLs should be
168 // displayed but there is only one row, change these settings to
170 if ($do_display['nav_bar'] == '1' ||
$do_display['sort_lnk'] == '1') {
172 // - Do not display sort links if less than 2 rows.
173 // - For a VIEW we (probably) did not count the number of rows
174 // so don't test this number here, it would remove the possibility
175 // of sorting VIEW results.
176 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table
::isView($db, $table)) {
177 // garvin: force display of navbar for vertical/horizontal display-choice.
178 // $do_display['nav_bar'] = (string) '0';
179 $do_display['sort_lnk'] = (string) '0';
183 // 5. Updates the synthetic var
184 $the_disp_mode = join('', $do_display);
187 } // end of the 'PMA_setDisplayMode()' function
191 * Displays a navigation bar to browse among the results of a SQL query
193 * @uses $_SESSION['userconf']['disp_direction']
194 * @uses $_SESSION['userconf']['repeat_cells']
195 * @uses $_SESSION['userconf']['max_rows']
196 * @uses $_SESSION['userconf']['pos']
197 * @param integer the offset for the "next" page
198 * @param integer the offset for the "previous" page
199 * @param string the URL-encoded query
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
204 * @global integer $num_rows the total number of rows returned by the
206 * @global integer $unlim_num_rows the total number of rows returned by the
207 * SQL any programmatically appended "LIMIT" clause
208 * @global boolean $is_innodb whether its InnoDB or not
209 * @global array $showtable table definitions
213 * @see PMA_displayTable()
215 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query)
217 global $db, $table, $goto;
218 global $num_rows, $unlim_num_rows;
222 // here, using htmlentities() would cause problems if the query
223 // contains accented characters
224 $html_sql_query = htmlspecialchars($sql_query);
227 * @todo move this to a central place
228 * @todo for other future table types
230 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
234 <!-- Navigation bar
-->
235 <table border
="0" cellpadding
="2" cellspacing
="0">
238 // Move to the beginning or to the previous page
239 if ($_SESSION['userconf']['pos'] && $_SESSION['userconf']['max_rows'] != 'all') {
240 // loic1: patch #474210 from Gosha Sakovich - part 1
241 if ($GLOBALS['cfg']['NavigationBarIconic']) {
242 $caption1 = '<<';
243 $caption2 = ' < ';
244 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
245 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
247 $caption1 = $GLOBALS['strPos1'] . ' <<';
248 $caption2 = $GLOBALS['strPrevious'] . ' <';
251 } // end if... else...
254 <form action
="sql.php" method
="post">
255 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
256 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
257 <input type
="hidden" name
="pos" value
="0" />
258 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
259 <input type
="submit" name
="navig" value
="<?php echo $caption1; ?>"<?php
echo $title1; ?
> />
263 <form action
="sql.php" method
="post">
264 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
265 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
266 <input type
="hidden" name
="pos" value
="<?php echo $pos_prev; ?>" />
267 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
268 <input type
="submit" name
="navig" value
="<?php echo $caption2; ?>"<?php
echo $title2; ?
> />
278 <?php
// if displaying a VIEW, $unlim_num_rows could be zero because
279 // of $cfg['MaxExactCountViews']; in this case, avoid passing
280 // the 5th parameter to checkFormElementInRange()
281 // (this means we can't validate the upper limit ?>
282 <form action
="sql.php" method
="post"
283 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 : ''; ?>))">
284 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
285 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
286 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
287 <input type
="submit" name
="navig" value
="<?php echo $GLOBALS['strShow']; ?> :" />
288 <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()" />
289 <?php
echo $GLOBALS['strRowsFrom'] . "\n"; ?
>
290 <input type
="text" name
="pos" size
="6" value
="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus
="this.select()" />
293 // Display mode (horizontal/vertical and repeat headers)
294 $param1 = ' <select name="disp_direction">' . "\n"
295 . ' <option value="horizontal"' . (($_SESSION['userconf']['disp_direction'] == 'horizontal') ?
' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
296 . ' <option value="horizontalflipped"' . (($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ?
' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
297 . ' <option value="vertical"' . (($_SESSION['userconf']['disp_direction'] == 'vertical') ?
' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
298 . ' </select>' . "\n"
300 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['userconf']['repeat_cells'] . '" class="textfield" />' . "\n"
302 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
310 // Move to the next page or to the last one
311 if (($_SESSION['userconf']['pos'] +
$_SESSION['userconf']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['userconf']['max_rows']
312 && $_SESSION['userconf']['max_rows'] != 'all') {
313 // loic1: patch #474210 from Gosha Sakovich - part 2
314 if ($GLOBALS['cfg']['NavigationBarIconic']) {
315 $caption3 = ' > ';
316 $caption4 = '>>';
317 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
318 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
320 $caption3 = '> ' . $GLOBALS['strNext'];
321 $caption4 = '>> ' . $GLOBALS['strEnd'];
324 } // end if... else...
328 <form action
="sql.php" method
="post">
329 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
330 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
331 <input type
="hidden" name
="pos" value
="<?php echo $pos_next; ?>" />
332 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
333 <input type
="submit" name
="navig" value
="<?php echo $caption3; ?>"<?php
echo $title3; ?
> />
337 <form action
="sql.php" method
="post"
338 onsubmit
="return <?php echo (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['userconf']['max_rows']) ? 'true' : 'false'); ?>">
339 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
340 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
341 <input type
="hidden" name
="pos" value
="<?php echo @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows'])- 1) * $_SESSION['userconf']['max_rows']); ?>" />
343 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
344 echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
345 // no backquote around this message
346 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
349 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
350 <input type
="submit" name
="navig" value
="<?php echo $caption4; ?>"<?php
echo $title4; ?
> <?php
echo (empty($onclick) ?
'' : $onclick); ?
>/>
358 // (unless we are showing all records)
359 if ('all' != $_SESSION['userconf']['max_rows']) { //if1
360 $pageNow = @floor
($_SESSION['userconf']['pos'] / $_SESSION['userconf']['max_rows']) +
1;
361 $nbTotalPage = @ceil
($unlim_num_rows / $_SESSION['userconf']['max_rows']);
363 if ($nbTotalPage > 1){ //if2
369 <?php
//<form> for keep the form alignment of button < and << ?>
371 <?php
echo PMA_pageselector(
372 'sql.php?sql_query=' . urlencode($sql_query) .
373 '&goto=' . $goto .
374 '&' . PMA_generate_common_url($db, $table) .
376 $_SESSION['userconf']['max_rows'],
384 $GLOBALS['strPageNumber']
394 // Display the "Show all" button if allowed
395 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
402 <form action
="sql.php" method
="post">
403 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
404 <input type
="hidden" name
="sql_query" value
="<?php echo $html_sql_query; ?>" />
405 <input type
="hidden" name
="pos" value
="0" />
406 <input type
="hidden" name
="session_max_rows" value
="all" />
407 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
408 <input type
="submit" name
="navig" value
="<?php echo $GLOBALS['strShowAll']; ?>" />
419 } // end of the 'PMA_displayTableNavigation()' function
423 * Displays the headers of the results table
425 * @uses $_SESSION['userconf']['disp_direction']
426 * @uses $_SESSION['userconf']['repeat_cells']
427 * @uses $_SESSION['userconf']['max_rows']
428 * @uses $_SESSION['userconf']['dontlimitchars']
429 * @param array which elements to display
430 * @param array the list of fields properties
431 * @param integer the total number of fields returned by the SQL query
432 * @param array the analyzed query
434 * @return boolean always true
436 * @global string $db the database name
437 * @global string $table the table name
438 * @global string $goto the URL to go back in case of errors
439 * @global string $sql_query the SQL query
440 * @global integer $num_rows the total number of rows returned by the
442 * @global array $vertical_display informations used with vertical display
447 * @see PMA_displayTable()
449 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
451 global $db, $table, $goto;
452 global $sql_query, $num_rows;
453 global $vertical_display, $highlight_columns;
455 if ($analyzed_sql == '') {
456 $analyzed_sql = array();
459 // can the result be sorted?
460 if ($is_display['sort_lnk'] == '1') {
463 $unsorted_sql_query = $sql_query;
464 if (isset($analyzed_sql[0]['unsorted_query'])) {
465 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
468 // we need $sort_expression and $sort_expression_nodir
469 // even if there are many table references
471 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
474 * Get rid of ASC|DESC
477 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
478 $sort_expression_nodir = isset($matches[1]) ?
trim($matches[1]) : $sort_expression;
480 // sorting by indexes, only if it makes sense (only one table ref)
481 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
482 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
483 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
485 // grab indexes data:
486 PMA_DBI_select_db($db);
487 if (!defined('PMA_IDX_INCLUDED')) {
488 $ret_keys = PMA_get_indexes($table);
492 foreach ($ret_keys as $row) {
494 if ($row['Key_name'] != $prev_index){
495 $indexes[] = $row['Key_name'];
496 $prev_index = $row['Key_name'];
498 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
499 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
500 if (isset($row['Cardinality'])) {
501 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
503 // I don't know what does the following column mean....
504 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
505 $indexes_info[$row['Key_name']]['Comment'] = (isset($row['Comment']))
508 $indexes_info[$row['Key_name']]['Index_type'] = (isset($row['Index_type']))
512 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
513 if (isset($row['Sub_part'])) {
514 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
518 // do we have any index?
519 if (isset($indexes_data)) {
521 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
522 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
524 if ($is_display['edit_lnk'] != 'nn') {
527 if ($is_display['del_lnk'] != 'nn') {
530 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
534 $span = $num_rows +
floor($num_rows/$_SESSION['userconf']['repeat_cells']) +
1;
537 echo '<form action="sql.php" method="post">' . "\n";
538 echo PMA_generate_common_hidden_inputs($db, $table, 5);
539 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
541 $local_order = (isset($sort_expression) ?
$sort_expression : '');
542 foreach ($indexes_data AS $key => $val) {
545 foreach ($val AS $key2 => $val2) {
546 $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
547 $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
549 $asc_sort = substr($asc_sort, 0, -3);
550 $desc_sort = substr($desc_sort, 0, -3);
551 $used_index = $used_index ||
$local_order == $asc_sort ||
$local_order == $desc_sort;
552 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ?
' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
554 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ?
' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
557 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ?
'' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
559 echo '</select>' . "\n";
560 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
562 echo '</form>' . "\n";
568 $vertical_display['emptypre'] = 0;
569 $vertical_display['emptyafter'] = 0;
570 $vertical_display['textbtn'] = '';
573 // Start of form for multi-rows delete
575 if ($is_display['del_lnk'] == 'dr' ||
$is_display['del_lnk'] == 'kp') {
576 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
577 echo PMA_generate_common_hidden_inputs($db, $table, 1);
578 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
581 echo '<table id="table_results" class="data">' . "\n";
582 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
583 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
584 echo '<thead><tr>' . "\n";
587 // 1. Displays the full/partial text button (part 1)...
588 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
589 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
590 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
594 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
601 'sql_query' => $sql_query,
604 $text_message = '<img class="fulltext" width="50" height="20"';
605 if ($_SESSION['userconf']['dontlimitchars']) {
606 $url_params['dontlimitchars'] = '0';
608 . ' src="' . $GLOBALS['pmaThemeImage'] . 's_partialtext.png"'
609 . ' alt="' . $GLOBALS['strPartialText'] . '"'
610 . ' title="' . $GLOBALS['strPartialText'] . '"';
612 $url_params['dontlimitchars'] = '1';
614 . ' src="' . $GLOBALS['pmaThemeImage'] . 's_fulltext.png"'
615 . ' alt="' . $GLOBALS['strFullText'] . '"'
616 . ' title="' . $GLOBALS['strFullText'] . '"';
618 $text_message .= ' />';
619 $text_url = 'sql.php' . PMA_generate_common_url($url_params);
620 $text_link = PMA_linkOrButton($text_url, $text_message, array(), false);
622 // ... before the result table
623 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
624 && $is_display['text_btn'] == '1') {
625 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 0;
626 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
627 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
629 <th colspan
="<?php echo $fields_cnt; ?>"><?php
echo $text_link; ?
></th
>
633 } // end horizontal/horizontalflipped mode
637 <th colspan
="<?php echo $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1; ?>">
638 <?php
echo $text_link; ?
></th
>
641 } // end vertical mode
644 // ... at the left column of the result table header if possible
646 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
647 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 0;
648 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
649 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
651 <th
<?php
echo $colspan; ?
>><?php
echo $text_link; ?
></th
>
653 } // end horizontal/horizontalflipped mode
655 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
656 . ' ' . $text_link . "\n"
658 } // end vertical mode
661 // ... elseif no button, displays empty(ies) col(s) if required
662 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
663 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')) {
664 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 0;
665 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
666 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
668 <td
<?php
echo $colspan; ?
>></td
>
670 } // end horizontal/horizontalfipped mode
672 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
673 } // end vertical mode
676 // 2. Displays the fields' name
677 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
678 // statement (see 2.1.3)
680 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
681 // Do not show comments, if using horizontalflipped mode, because of space usage
682 if ($GLOBALS['cfg']['ShowBrowseComments']
683 && ($GLOBALS['cfgRelation']['commwork']
684 || PMA_MYSQL_INT_VERSION
>= 40100)
685 && $_SESSION['userconf']['disp_direction'] != 'horizontalflipped') {
686 $comments_map = array();
687 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
688 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
689 $tb = $tbl['table_true_name'];
690 $comments_map[$tb] = PMA_getComments($db, $tb);
696 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
697 require_once './libraries/transformations.lib.php';
698 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
701 if ($is_display['sort_lnk'] == '1') {
702 //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
703 $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ?
true : false);
704 $select_expr = $analyzed_sql[0]['select_expr_clause'];
709 // garvin: See if we have to highlight any header fields of a WHERE query.
710 // Uses SQL-Parser results.
711 $highlight_columns = array();
712 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
713 isset($analyzed_sql[0]['where_clause_identifiers'])) {
716 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
717 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
718 $highlight_columns[$wci] = 'true';
723 for ($i = 0; $i < $fields_cnt; $i++
) {
724 // garvin: See if this column should get highlight because it's used in the
726 if (isset($highlight_columns[$fields_meta[$i]->name
]) ||
isset($highlight_columns[PMA_backquote($fields_meta[$i]->name
)])) {
727 $condition_field = true;
729 $condition_field = false;
732 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
733 if (isset($comments_map) &&
734 isset($comments_map[$fields_meta[$i]->table
]) &&
735 isset($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
])) {
736 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table
][$fields_meta[$i]->name
]) . '</span>';
741 // 2.1 Results can be sorted
742 if ($is_display['sort_lnk'] == '1') {
744 // 2.1.1 Checks if the table name is required; it's the case
745 // for a query with a "JOIN" statement and if the column
746 // isn't aliased, or in queries like
747 // SELECT `1`.`master_field` , `2`.`master_field`
748 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
750 * we prefer always using table if existing
751 * and second this code does not correctly check $fields_meta[$i]->table
753 && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts))
754 || (isset($analyzed_sql[0]['select_expr'][$i]['expr'])
755 && isset($analyzed_sql[0]['select_expr'][$i]['column'])
756 && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
757 $analyzed_sql[0]['select_expr'][$i]['column']
758 && isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table))) {
760 if (isset($fields_meta[$i]->table
) && strlen($fields_meta[$i]->table
)) {
761 $sort_tbl = PMA_backquote($fields_meta[$i]->table
) . '.';
766 // 2.1.2 Checks if the current column is used to sort the
768 if (empty($sort_expression)) {
771 // field name may be preceded by a space, or any number
772 // of characters followed by a dot (tablename.fieldname)
773 // so do a direct comparison
774 // for the sort expression (avoids problems with queries
775 // like "SELECT id, count(id)..." and clicking to sort
776 // on id or on count(id))
777 $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name
) == $sort_expression_nodir ?
true : false);
779 // 2.1.3 Check the field name for backquotes.
780 // If it contains some, it's probably a function column
781 // like 'COUNT(`field`)'
782 if (strpos($fields_meta[$i]->name
, '`') !== false) {
783 $sort_order = ' ORDER BY ' . PMA_backquote($fields_meta[$i]->name
) . ' ';
785 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name
) . ' ';
788 // 2.1.4 Do define the sorting URL
790 // loic1: patch #455484 ("Smart" order)
791 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
792 if ($GLOBALS['cfg']['Order'] === 'SMART') {
793 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type
)) ?
'DESC' : 'ASC';
795 $sort_order .= $GLOBALS['cfg']['Order'];
798 } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
799 $sort_order .= ' ASC';
800 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
802 $sort_order .= ' DESC';
803 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
806 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
807 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
809 $sorted_sql_query = $unsorted_sql_query . $sort_order;
811 $url_query = PMA_generate_common_url($db, $table)
812 . '&sql_query=' . urlencode($sorted_sql_query);
813 $order_url = 'sql.php?' . $url_query;
815 // 2.1.5 Displays the sorting URL
816 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
817 // enable sort order swapping for image
818 $order_link_params = array();
819 if (isset($order_img) && $order_img!='') {
820 if (strstr($order_img, 'asc')) {
821 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
822 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
823 } elseif (strstr($order_img, 'desc')) {
824 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
825 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
828 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
829 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
830 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
832 $order_link_params['title'] = $GLOBALS['strSort'];
833 $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
));
834 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
836 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
837 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
839 if ($condition_field) {
840 echo ' class="condition"';
842 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
843 echo ' valign="bottom"';
845 echo '>' . $order_link . $comments . '</th>';
847 $vertical_display['desc'][] = ' <th '
848 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
849 . $order_link . $comments . ' </th>' . "\n";
852 // 2.2 Results can't be sorted
854 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
855 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
857 if ($condition_field) {
858 echo ' class="condition"';
860 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
861 echo ' valign="bottom"';
863 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
864 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
865 echo ' style="direction: ltr; writing-mode: tb-rl;"';
868 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
869 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
870 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name
), '<br />');
872 echo htmlspecialchars($fields_meta[$i]->name
);
874 echo "\n" . $comments . '</th>';
876 $vertical_display['desc'][] = ' <th '
877 . ($condition_field ?
' class="condition"' : '') . '>' . "\n"
878 . ' ' . htmlspecialchars($fields_meta[$i]->name
) . "\n"
879 . $comments . ' </th>';
883 // 3. Displays the full/partial text button (part 2) at the right
884 // column of the result table header if possible and required...
885 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
886 && ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn')
887 && $is_display['text_btn'] == '1') {
888 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 1;
889 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
890 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
893 <th
<?php
echo $colspan; ?
>>
894 <?php
echo $text_link; ?
>
897 } // end horizontal/horizontalflipped mode
899 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
900 . ' ' . $text_link . "\n"
902 } // end vertical mode
905 // ... elseif no button, displays empty columns if required
906 // (unless coming from Browse mode print view)
907 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
908 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
909 && (!$GLOBALS['is_header_sent'])) {
910 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ?
3 : 1;
911 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
912 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
915 <td
<?php
echo $colspan; ?
>></td
>
917 } // end horizontal/horizontalflipped mode
919 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
920 } // end vertical mode
923 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
924 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
932 } // end of the 'PMA_displayTableHeaders()' function
937 * Displays the body of the results table
939 * @uses $_SESSION['userconf']['disp_direction']
940 * @uses $_SESSION['userconf']['repeat_cells']
941 * @uses $_SESSION['userconf']['max_rows']
942 * @uses $_SESSION['userconf']['dontlimitchars']
943 * @param integer the link id associated to the query which results have
945 * @param array which elements to display
946 * @param array the list of relations
947 * @param array the analyzed query
949 * @return boolean always true
951 * @global string $db the database name
952 * @global string $table the table name
953 * @global string $goto the URL to go back in case of errors
954 * @global string $sql_query the SQL query
955 * @global array $fields_meta the list of fields properties
956 * @global integer $fields_cnt the total number of fields returned by
958 * @global array $vertical_display informations used with vertical display
960 * @global array $highlight_columns column names to highlight
961 * @global array $row current row data
965 * @see PMA_displayTable()
967 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
968 global $db, $table, $goto;
969 global $sql_query, $fields_meta, $fields_cnt;
970 global $vertical_display, $highlight_columns;
971 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
973 $url_sql_query = $sql_query;
975 // query without conditions to shorten URLs when needed, 200 is just
976 // guess, it should depend on remaining URL length
978 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
979 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
980 strlen($sql_query) > 200) {
982 $url_sql_query = 'SELECT ';
983 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
984 $url_sql_query .= ' DISTINCT ';
986 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
987 if (!empty($analyzed_sql[0]['from_clause'])) {
988 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
992 if (!is_array($map)) {
996 $vertical_display['edit'] = array();
997 $vertical_display['delete'] = array();
998 $vertical_display['data'] = array();
999 $vertical_display['row_delete'] = array();
1001 // Correction University of Virginia 19991216 in the while below
1002 // Previous code assumed that all tables have keys, specifically that
1003 // the phpMyAdmin GUI should support row delete/edit only for such
1005 // Although always using keys is arguably the prescribed way of
1006 // defining a relational table, it is not required. This will in
1007 // particular be violated by the novice.
1008 // We want to encourage phpMyAdmin usage by such novices. So the code
1009 // below has been changed to conditionally work as before when the
1010 // table being displayed has one or more keys; but to display
1011 // delete/edit options correctly for tables without keys.
1013 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
1014 // to get the NULL values
1016 // rabus: This function needs a little rework.
1017 // Using MYSQL_BOTH just pollutes the memory!
1019 // ne0x: Use function PMA_DBI_fetch_array() due to mysqli
1020 // compatibility. Now this function is wrapped.
1023 while ($row = PMA_DBI_fetch_row($dt_result)) {
1024 // lem9: "vertical display" mode stuff
1025 if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no %
$_SESSION['userconf']['repeat_cells'])
1026 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1027 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
1030 if ($vertical_display['emptypre'] > 0) {
1031 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1032 .' </th>' . "\n";
1035 foreach ($vertical_display['desc'] as $val) {
1039 if ($vertical_display['emptyafter'] > 0) {
1040 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1041 .' </th>' . "\n";
1043 echo '</tr>' . "\n";
1046 $class = $odd_row ?
'odd' : 'even';
1047 $odd_row = ! $odd_row;
1048 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1049 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1050 // loic1: pointer code part
1051 echo ' <tr class="' . $class . '">' . "\n";
1056 // 1. Prepares the row (gets primary keys to use)
1057 // 1.1 Results from a "SELECT" statement -> builds the
1058 // "primary" key to use in links
1060 * @todo $unique_condition could be empty, for example a table
1061 * with only one field and it's a BLOB; in this case,
1062 * avoid to display the delete and edit links
1064 $unique_condition = urlencode(PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row));
1066 // 1.2 Defines the URLs for the modify/delete link(s)
1067 $url_query = PMA_generate_common_url($db, $table);
1069 if ($is_display['edit_lnk'] != 'nn' ||
$is_display['del_lnk'] != 'nn') {
1070 // We need to copy the value or else the == 'both' check will always return true
1072 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1073 $iconic_spacer = '<div class="nowrap">';
1075 $iconic_spacer = '';
1078 // 1.2.1 Modify link(s)
1079 if ($is_display['edit_lnk'] == 'ur') { // update row case
1080 $lnk_goto = 'sql.php';
1082 $edit_url = 'tbl_change.php'
1084 . '&primary_key=' . $unique_condition
1085 . '&sql_query=' . urlencode($url_sql_query)
1086 . '&goto=' . urlencode($lnk_goto);
1087 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1088 $edit_str = $GLOBALS['strEdit'];
1090 $edit_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" />';
1091 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1092 $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>';
1097 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])) {
1098 $bookmark_go = '<a href="import.php?'
1099 . PMA_generate_common_url($row[1], '')
1100 . '&id_bookmark=' . $row[0]
1101 . '&action_bookmark=0'
1102 . '&action_bookmark_all=1'
1103 . '&SQL=' . $GLOBALS['strExecuteBookmarked']
1104 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1106 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1107 $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
1109 $bookmark_go .= $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" />';
1110 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1111 $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>';
1115 $bookmark_go .= '</a>';
1120 // 1.2.2 Delete/Kill link(s)
1121 if ($is_display['del_lnk'] == 'dr') { // delete row case
1122 $lnk_goto = 'sql.php'
1123 . '?' . str_replace('&', '&', $url_query)
1124 . '&sql_query=' . urlencode($url_sql_query)
1125 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1126 . '&goto=' . (empty($goto) ?
'tbl_sql.php' : $goto);
1127 $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $unique_condition . '+LIMIT+1';
1128 $del_url = 'sql.php'
1130 . '&sql_query=' . $del_query
1131 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1132 . '&goto=' . urlencode($lnk_goto);
1133 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
1134 . ' WHERE ' . trim(PMA_jsFormat(urldecode($unique_condition), false))
1136 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1137 $del_str = $GLOBALS['strDelete'];
1139 $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" />';
1140 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1141 $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>';
1144 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1145 $lnk_goto = 'sql.php'
1146 . '?' . str_replace('&', '&', $url_query)
1147 . '&sql_query=' . urlencode($url_sql_query)
1149 $del_url = 'sql.php?'
1150 . PMA_generate_common_url('mysql')
1151 . '&sql_query=' . urlencode('KILL ' . $row[0])
1152 . '&goto=' . urlencode($lnk_goto);
1153 $del_query = urlencode('KILL ' . $row[0]);
1154 $js_conf = 'KILL ' . $row[0];
1155 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1156 $del_str = $GLOBALS['strKill'];
1158 $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" />';
1159 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1160 $del_str .= ' ' . $GLOBALS['strKill'] . '</div>';
1165 // 1.3 Displays the links at left if required
1166 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1167 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1168 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1169 $doWriteModifyAt = 'left';
1170 require './libraries/display_tbl_links.lib.php';
1174 // 2. Displays the rows' values
1175 for ($i = 0; $i < $fields_cnt; ++
$i) {
1176 $meta = $fields_meta[$i];
1177 // loic1: To fix bug #474943 under php4, the row pointer will
1178 // depend on whether the "is_null" php4 function is
1180 $pointer = (function_exists('is_null') ?
$i : $meta->name
);
1181 // garvin: See if this column should get highlight because it's used in the
1183 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name
]) ||
isset($highlight_columns[PMA_backquote($meta->name
)]))) {
1184 $condition_field = true;
1186 $condition_field = false;
1190 if ($_SESSION['userconf']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) ||
($GLOBALS['printview'] != '1'))) {
1191 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1192 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1193 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1195 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1196 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1198 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1202 // garvin: Wrap MIME-transformations. [MIME]
1203 $default_function = 'default_function'; // default_function
1204 $transform_function = $default_function;
1205 $transform_options = array();
1207 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1209 if (isset($GLOBALS['mime_map'][$meta->name
]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name
]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name
]['transformation'])) {
1210 $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name
]['transformation']);
1212 if (file_exists('./libraries/transformations/' . $include_file)) {
1213 $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name
]['transformation']);
1215 require_once './libraries/transformations/' . $include_file;
1217 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1218 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1219 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name
]['transformation_options']) ?
$GLOBALS['mime_map'][$meta->name
]['transformation_options'] : ''));
1220 $meta->mimetype
= str_replace('_', '/', $GLOBALS['mime_map'][$meta->name
]['mimetype']);
1222 } // end if file_exists
1223 } // end if transformation is set
1224 } // end if mime/transformation works.
1226 $transform_options['wrapper_link'] = '?'
1227 . (isset($url_query) ?
$url_query : '')
1228 . '&primary_key=' . (isset($unique_condition) ?
$unique_condition : '')
1229 . '&sql_query=' . (empty($sql_query) ?
'' : urlencode($url_sql_query))
1230 . '&goto=' . (isset($sql_goto) ?
urlencode($lnk_goto) : '')
1231 . '&transform_key=' . urlencode($meta->name
);
1235 if ($meta->numeric == 1) {
1238 // lem9: if two fields have the same name (this is possible
1239 // with self-join queries, for example), using $meta->name
1240 // will show both fields NULL even if only one is NULL,
1241 // so use the $pointer
1242 // (works only if function_exists('is_null')
1243 // PS: why not always work with the number ($i), since
1244 // the default second parameter of
1245 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1246 // associative and numeric indices?
1248 //if (!isset($row[$meta->name])
1249 if (!isset($row[$i]) ||
is_null($row[$i])) {
1250 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"><i>NULL</i></td>' . "\n";
1251 } elseif ($row[$i] != '') {
1252 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . ' nowrap">';
1254 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1255 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1256 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1257 if (isset($alias) && strlen($alias)) {
1258 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1259 if ($alias == $meta->name
) {
1260 $meta->name
= $true_column;
1266 if (isset($map[$meta->name
])) {
1267 // Field to display from the foreign table?
1268 if (isset($map[$meta->name
][2]) && strlen($map[$meta->name
][2])) {
1269 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name
][2])
1270 . ' FROM ' . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
1271 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
1273 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE
);
1274 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1275 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
1277 $dispval = $GLOBALS['strLinkNotFound'];
1279 @PMA_DBI_free_result
($dispresult);
1282 } // end if... else...
1284 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1285 $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>';
1287 $title = (!empty($dispval))?
' title="' . htmlspecialchars($dispval) . '"' : '';
1289 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1290 . PMA_generate_common_url($map[$meta->name
][3], $map[$meta->name
][0])
1292 . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name
][0]) . ' WHERE ' . PMA_backquote($map[$meta->name
][1]) . ' = ' . $row[$i]) . '"' . $title . '>'
1293 . ($transform_function != $default_function ?
$transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>';
1296 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ?
$transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
1298 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1300 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ?
' condition' : '') . '"> </td>' . "\n";
1305 } elseif ($GLOBALS['cfg']['ShowBlob'] == false && stristr($meta->type
, 'BLOB')) {
1306 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1307 // TEXT fields type, however TEXT fields must be displayed
1308 // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type
1310 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1311 if (stristr($field_flags, 'BINARY')) {
1312 $blobtext = '[BLOB';
1313 if (!isset($row[$i]) ||
is_null($row[$i])) {
1314 $blobtext .= ' - NULL';
1316 } elseif (isset($row[$i])) {
1317 $blob_size = strlen($row[$i]);
1318 $display_blob_size = PMA_formatByteDown($blob_size, 3, 1);
1319 $blobtext .= ' - '. $display_blob_size[0] . ' ' . $display_blob_size[1];
1320 unset($display_blob_size);
1324 if (strpos($transform_function, 'octetstream')) {
1325 $blobtext = $row[$i];
1327 if ($blob_size > 0) {
1328 $blobtext = ($default_function != $transform_function ?
$transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
1332 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '">' . $blobtext . '</td>';
1334 if (!isset($row[$i]) ||
is_null($row[$i])) {
1335 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"><i>NULL</i></td>' . "\n";
1336 } elseif ($row[$i] != '') {
1337 // garvin: if a transform function for blob is set, none of these replacements will be made
1338 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ! $_SESSION['userconf']['dontlimitchars']) {
1339 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1341 // loic1: displays all space characters, 4 space
1342 // characters for tabulations and <cr>/<lf>
1343 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1345 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1347 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"> </td>' . "\n";
1351 if (!isset($row[$i]) ||
is_null($row[$i])) {
1352 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"><i>NULL</i></td>' . "\n";
1353 } elseif ($row[$i] != '') {
1354 // loic1: support blanks in the key
1355 $relation_id = $row[$i];
1357 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1358 // lem9: (unless it's a link-type transformation)
1359 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ! $_SESSION['userconf']['dontlimitchars'] && !strpos($transform_function, 'link') === true) {
1360 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1363 // loic1: displays special characters from binaries
1364 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1365 if (isset($meta->_type
) && $meta->_type
=== MYSQLI_TYPE_BIT
) {
1366 $db_value = $row[$i];
1368 for ($j = 0; $j < ceil($meta->length
/ 8); $j++
) {
1369 $row[$i] .= sprintf('%08d', decbin(ord(substr($db_value, $j, 1))));
1371 $row[$i] = substr($row[$i], -$meta->length
);
1372 } elseif (stristr($field_flags, 'BINARY')) {
1373 $row[$i] = str_replace("\x00", '\0', $row[$i]);
1374 $row[$i] = str_replace("\x08", '\b', $row[$i]);
1375 $row[$i] = str_replace("\x0a", '\n', $row[$i]);
1376 $row[$i] = str_replace("\x0d", '\r', $row[$i]);
1377 $row[$i] = str_replace("\x1a", '\Z', $row[$i]);
1378 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1380 // loic1: displays all space characters, 4 space
1381 // characters for tabulations and <cr>/<lf>
1383 $row[$i] = ($default_function != $transform_function ?
$transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1386 // garvin: transform functions may enable no-wrapping:
1387 $function_nowrap = $transform_function . '_nowrap';
1388 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ?
$function_nowrap($transform_options) : false);
1390 // loic1: do not wrap if date field type
1391 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type
) ||
$bool_nowrap) ?
' nowrap' : '');
1392 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . $nowrap . ($condition_field ?
' condition' : '') . '">';
1394 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1395 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1396 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1397 if (isset($alias) && strlen($alias)) {
1398 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1399 if ($alias == $meta->name
) {
1400 $meta->name
= $true_column;
1406 if (isset($map[$meta->name
])) {
1407 // Field to display from the foreign table?
1408 if (isset($map[$meta->name
][2]) && strlen($map[$meta->name
][2])) {
1409 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name
][2])
1410 . ' FROM ' . PMA_backquote($map[$meta->name
][3]) . '.' . PMA_backquote($map[$meta->name
][0])
1411 . ' WHERE ' . PMA_backquote($map[$meta->name
][1])
1412 . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1413 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE
);
1414 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1415 list($dispval) = PMA_DBI_fetch_row($dispresult);
1416 @PMA_DBI_free_result
($dispresult);
1418 $dispval = $GLOBALS['strLinkNotFound'];
1423 $title = (!empty($dispval))?
' title="' . htmlspecialchars($dispval) . '"' : '';
1425 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1426 . PMA_generate_common_url($map[$meta->name
][3], $map[$meta->name
][0])
1428 . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name
][0]) . ' WHERE ' . PMA_backquote($map[$meta->name
][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1429 . $row[$i] . '</a>';
1431 $vertical_display['data'][$row_no][$i] .= $row[$i];
1433 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1435 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ?
' condition' : '') . '"> </td>' . "\n";
1439 // lem9: output stored cell
1440 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1441 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1442 echo $vertical_display['data'][$row_no][$i];
1445 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1446 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1448 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1452 // 3. Displays the modify/delete links on the right if required
1453 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1454 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1455 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1456 $doWriteModifyAt = 'right';
1457 require './libraries/display_tbl_links.lib.php';
1460 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1461 ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1467 // 4. Gather links of del_urls and edit_urls in an array for later
1469 if (!isset($vertical_display['edit'][$row_no])) {
1470 $vertical_display['edit'][$row_no] = '';
1471 $vertical_display['delete'][$row_no] = '';
1472 $vertical_display['row_delete'][$row_no] = '';
1475 $column_style_vertical = '';
1476 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1477 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1478 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1480 $column_marker_vertical = '';
1481 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1482 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1485 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1486 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1487 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition . ']"'
1488 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1489 . ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ?
'checked="checked"' : '') . ' />' . "\n"
1492 unset($vertical_display['row_delete'][$row_no]);
1495 if (isset($edit_url)) {
1496 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1497 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1501 unset($vertical_display['edit'][$row_no]);
1504 if (isset($del_url)) {
1505 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1506 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ?
$js_conf : ''), false)
1509 unset($vertical_display['delete'][$row_no]);
1512 echo (($_SESSION['userconf']['disp_direction'] == 'horizontal' ||
$_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ?
"\n" : '');
1516 if (isset($url_query)) {
1517 $GLOBALS['url_query'] = $url_query;
1521 } // end of the 'PMA_displayTableBody()' function
1525 * Do display the result table with the vertical direction mode.
1526 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1528 * @return boolean always true
1530 * @uses $_SESSION['userconf']['repeat_cells']
1531 * @global array $vertical_display the information to display
1535 * @see PMA_displayTable()
1537 function PMA_displayVerticalTable()
1539 global $vertical_display;
1541 // Displays "multi row delete" link at top if required
1542 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1544 echo $vertical_display['textbtn'];
1546 foreach ($vertical_display['row_delete'] as $val) {
1547 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1548 echo '<th> </th>' . "\n";
1551 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1554 echo '</tr>' . "\n";
1557 // Displays "edit" link at top if required
1558 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1560 if (!is_array($vertical_display['row_delete'])) {
1561 echo $vertical_display['textbtn'];
1564 foreach ($vertical_display['edit'] as $val) {
1565 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1566 echo ' <th> </th>' . "\n";
1572 echo '</tr>' . "\n";
1575 // Displays "delete" link at top if required
1576 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1578 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1579 echo $vertical_display['textbtn'];
1582 foreach ($vertical_display['delete'] as $val) {
1583 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1584 echo '<th> </th>' . "\n";
1590 echo '</tr>' . "\n";
1594 foreach ($vertical_display['desc'] AS $key => $val) {
1600 foreach ($vertical_display['rowdata'][$key] as $subval) {
1601 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) and !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1609 echo '</tr>' . "\n";
1612 // Displays "multi row delete" link at bottom if required
1613 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1615 echo $vertical_display['textbtn'];
1617 foreach ($vertical_display['row_delete'] as $val) {
1618 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1619 echo '<th> </th>' . "\n";
1622 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1625 echo '</tr>' . "\n";
1628 // Displays "edit" link at bottom if required
1629 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 ||
!empty($vertical_display['textbtn']))) {
1631 if (!is_array($vertical_display['row_delete'])) {
1632 echo $vertical_display['textbtn'];
1635 foreach ($vertical_display['edit'] as $val) {
1636 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1637 echo '<th> </th>' . "\n";
1643 echo '</tr>' . "\n";
1646 // Displays "delete" link at bottom if required
1647 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ||
!empty($vertical_display['textbtn']))) {
1649 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1650 echo $vertical_display['textbtn'];
1653 foreach ($vertical_display['delete'] as $val) {
1654 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter %
$_SESSION['userconf']['repeat_cells'])) {
1655 echo '<th> </th>' . "\n";
1661 echo '</tr>' . "\n";
1665 } // end of the 'PMA_displayVerticalTable' function
1669 * @uses $_SESSION['userconf']['disp_direction']
1670 * @uses $_REQUEST['disp_direction']
1671 * @uses $GLOBALS['cfg']['DefaultDisplay']
1672 * @uses $_SESSION['userconf']['repeat_cells']
1673 * @uses $_REQUEST['repeat_cells']
1674 * @uses $GLOBALS['cfg']['RepeatCells']
1675 * @uses $_SESSION['userconf']['max_rows']
1676 * @uses $_REQUEST['session_max_rows']
1677 * @uses $GLOBALS['cfg']['MaxRows']
1678 * @uses $_SESSION['userconf']['pos']
1679 * @uses $_REQUEST['pos']
1680 * @uses $_SESSION['userconf']['dontlimitchars']
1681 * @uses $_REQUEST['dontlimitchars']
1682 * @uses PMA_isValid()
1683 * @uses $GLOBALS['sql_query']
1684 * @todo make maximum remembered queries configurable
1685 * @todo move/split into SQL class!?
1686 * @todo currently this is called twice unnecessary
1687 * @todo ignore LIMIT and ORDER in query!?
1689 function PMA_displayTable_checkConfigParams()
1691 $sql_key = md5($GLOBALS['sql_query']);
1693 $_SESSION['userconf']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1695 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1696 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1697 unset($_REQUEST['disp_direction']);
1698 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['disp_direction'])) {
1699 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1702 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1703 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1704 unset($_REQUEST['repeat_cells']);
1705 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['repeat_cells'])) {
1706 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1709 if (PMA_isValid($_REQUEST['session_max_rows'], 'numeric') ||
$_REQUEST['session_max_rows'] == 'all') {
1710 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1711 unset($_REQUEST['session_max_rows']);
1712 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['max_rows'])) {
1713 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1716 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1717 $_SESSION['userconf']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1718 unset($_REQUEST['pos']);
1719 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['pos'])) {
1720 $_SESSION['userconf']['query'][$sql_key]['pos'] = 0;
1723 if (PMA_isValid($_REQUEST['dontlimitchars'], array('0', '1'))) {
1724 $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'] = (int) $_REQUEST['dontlimitchars'];
1725 unset($_REQUEST['dontlimitchars']);
1726 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['dontlimitchars'])) {
1727 $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'] = 0;
1730 // move current query to the last position, to be removed last
1731 // so only least executed query will be removed if maximum remembered queries
1733 $tmp = $_SESSION['userconf']['query'][$sql_key];
1734 unset($_SESSION['userconf']['query'][$sql_key]);
1735 $_SESSION['userconf']['query'][$sql_key] = $tmp;
1737 // do not exceed a maximum number of queries to remember
1738 if (count($_SESSION['userconf']['query']) > 10) {
1739 array_shift($_SESSION['userconf']['query']);
1740 //echo 'deleting one element ...';
1743 // populate query configuration
1744 $_SESSION['userconf']['dontlimitchars'] = $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'];
1745 $_SESSION['userconf']['pos'] = $_SESSION['userconf']['query'][$sql_key]['pos'];
1746 $_SESSION['userconf']['max_rows'] = $_SESSION['userconf']['query'][$sql_key]['max_rows'];
1747 $_SESSION['userconf']['repeat_cells'] = $_SESSION['userconf']['query'][$sql_key]['repeat_cells'];
1748 $_SESSION['userconf']['disp_direction'] = $_SESSION['userconf']['query'][$sql_key]['disp_direction'];
1753 var_dump($_SESSION['userconf']);
1759 * Displays a table of results returned by a SQL query.
1760 * This function is called by the "sql.php" script.
1762 * @param integer the link id associated to the query which results have
1764 * @param array the display mode
1765 * @param array the analyzed query
1767 * @uses $_SESSION['userconf']['pos']
1768 * @global string $db the database name
1769 * @global string $table the table name
1770 * @global string $goto the URL to go back in case of errors
1771 * @global string $sql_query the current SQL query
1772 * @global integer $num_rows the total number of rows returned by the
1774 * @global integer $unlim_num_rows the total number of rows returned by the
1775 * SQL query without any programmatically
1776 * appended "LIMIT" clause
1777 * @global array $fields_meta the list of fields properties
1778 * @global integer $fields_cnt the total number of fields returned by
1780 * @global array $vertical_display informations used with vertical display
1782 * @global array $highlight_columns column names to highlight
1783 * @global array $cfgRelation the relation settings
1787 * @see PMA_showMessage(), PMA_setDisplayMode(),
1788 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1789 * PMA_displayTableBody(), PMA_displayResultsOperations()
1791 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1793 global $db, $table, $goto;
1794 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1795 global $vertical_display, $highlight_columns;
1796 global $cfgRelation;
1799 PMA_displayTable_checkConfigParams();
1802 * @todo move this to a central place
1803 * @todo for other future table types
1805 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1808 && ! isset($analyzed_sql[0]['queryflags']['union'])
1809 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1810 && (empty($analyzed_sql[0]['where_clause'])
1811 ||
$analyzed_sql[0]['where_clause'] == '1 ')) {
1812 // "j u s t b r o w s i n g"
1814 $after_count = '[sup]1[/sup]';
1820 // 1. ----- Prepares the work -----
1822 // 1.1 Gets the informations about which functionalities should be
1825 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1827 // 1.2 Defines offsets for the next and previous pages
1828 if ($is_display['nav_bar'] == '1') {
1829 if ($_SESSION['userconf']['max_rows'] == 'all') {
1833 $pos_next = $_SESSION['userconf']['pos'] +
$_SESSION['userconf']['max_rows'];
1834 $pos_prev = $_SESSION['userconf']['pos'] - $_SESSION['userconf']['max_rows'];
1835 if ($pos_prev < 0) {
1841 // 1.3 URL-encodes the query to use in input form fields
1842 $encoded_sql_query = urlencode($sql_query);
1844 // 2. ----- Displays the top of the page -----
1846 // 2.1 Displays a messages with position informations
1847 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1848 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1849 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1853 $last_shown_rec = ($_SESSION['userconf']['max_rows'] == 'all' ||
$pos_next > $total)
1856 PMA_showMessage($GLOBALS['strShowingRecords'] . ' ' . $_SESSION['userconf']['pos'] . ' - ' . $last_shown_rec . ' (' . $pre_count . PMA_formatNumber($total, 0) . $after_count . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1858 if (PMA_Table
::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCount']) {
1859 echo '<div class="notice">' . "\n";
1860 echo PMA_sanitize(sprintf($GLOBALS['strViewMaxExactCount'], PMA_formatNumber($GLOBALS['cfg']['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n";
1861 echo '</div>' . "\n";
1864 echo '<div class="notice">' . "\n";
1865 echo '<sup>1</sup>' . PMA_sanitize($GLOBALS['strApproximateCount']) . "\n";
1866 echo '</div>' . "\n";
1869 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
1870 PMA_showMessage($GLOBALS['strSQLQuery']);
1873 // 2.3 Displays the navigation bars
1874 if (! strlen($table)) {
1875 if (isset($analyzed_sql[0]['query_type'])
1876 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1877 // table does not always contain a real table name,
1878 // for example in MySQL 5.0.x, the query SHOW STATUS
1879 // returns STATUS as a table name
1880 $table = $fields_meta[0]->table
;
1886 if ($is_display['nav_bar'] == '1') {
1887 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1889 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
1890 echo "\n" . '<br /><br />' . "\n";
1893 // 2b ----- Get field references from Database -----
1894 // (see the 'relation' configuration variable)
1895 // loic1, 2002-03-02: extended to php3
1902 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1903 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1904 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1907 $tabs = '(\'' . join('\',\'', $target) . '\')';
1909 if ($cfgRelation['displaywork']) {
1910 if (! strlen($table)) {
1913 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1915 foreach ($exist_rel AS $master_field => $rel) {
1916 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
1917 $map[$master_field] = array($rel['foreign_table'],
1918 $rel['foreign_field'],
1920 $rel['foreign_db']);
1927 // 3. ----- Displays the results table -----
1928 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1930 echo '<tbody>' . "\n";
1931 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1932 // vertical output case
1933 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1934 PMA_displayVerticalTable();
1936 unset($vertical_display);
1937 echo '</tbody>' . "\n";
1942 // 4. ----- Displays the link for multi-fields delete
1944 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1946 $delete_text = $is_display['del_lnk'] == 'dr' ?
$GLOBALS['strDelete'] : $GLOBALS['strKill'];
1948 $uncheckall_url = 'sql.php?'
1949 . PMA_generate_common_url($db, $table)
1950 . '&sql_query=' . urlencode($sql_query)
1951 . '&goto=' . $goto;
1952 $checkall_url = $uncheckall_url . '&checkall=1';
1954 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1955 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
1956 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
1958 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
1959 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
1961 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
1962 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
1963 if ($_SESSION['userconf']['disp_direction'] != 'vertical') {
1964 echo '<img class="selectallarrow" width="38" height="22"'
1965 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
1966 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
1968 echo $checkall_link . "\n"
1970 .$uncheckall_link . "\n"
1971 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
1973 if ($GLOBALS['cfg']['PropertiesIconic']) {
1974 PMA_buttonOrImage('submit_mult', 'mult_submit',
1975 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
1976 PMA_buttonOrImage('submit_mult', 'mult_submit',
1977 'submit_mult_delete', $delete_text, 'b_drop.png');
1978 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1979 PMA_buttonOrImage('submit_mult', 'mult_submit',
1980 'submit_mult_export', $GLOBALS['strExport'],
1985 echo ' <input type="submit" name="submit_mult"'
1986 .' value="' . htmlspecialchars($GLOBALS['strEdit']) . '"'
1987 .' title="' . $GLOBALS['strEdit'] . '" />' . "\n";
1988 echo ' <input type="submit" name="submit_mult"'
1989 .' value="' . htmlspecialchars($delete_text) . '"'
1990 .' title="' . $delete_text . '" />' . "\n";
1991 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1992 echo ' <input type="submit" name="submit_mult"'
1993 .' value="' . htmlspecialchars($GLOBALS['strExport']) . '"'
1994 .' title="' . $GLOBALS['strExport'] . '" />' . "\n";
1997 echo '<input type="hidden" name="sql_query"'
1998 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1999 echo '<input type="hidden" name="url_query"'
2000 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2001 echo '</form>' . "\n";
2004 // 5. ----- Displays the navigation bar at the bottom if required -----
2006 if ($is_display['nav_bar'] == '1') {
2007 echo '<br />' . "\n";
2008 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
2009 } elseif (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2010 echo "\n" . '<br /><br />' . "\n";
2013 // 6. ----- Displays "Query results operations"
2014 if (!isset($GLOBALS['printview']) ||
$GLOBALS['printview'] != '1') {
2015 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2017 } // end of the 'PMA_displayTable()' function
2019 function default_function($buffer) {
2020 $buffer = htmlspecialchars($buffer);
2021 $buffer = str_replace("\011", ' ',
2022 str_replace(' ', ' ', $buffer));
2023 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2029 * Displays operations that are available on results.
2031 * @param array the display mode
2032 * @param array the analyzed query
2034 * @uses $_SESSION['userconf']['pos']
2035 * @uses $_SESSION['userconf']['dontlimitchars']
2036 * @global string $db the database name
2037 * @global string $table the table name
2038 * @global string $sql_query the current SQL query
2039 * @global integer $unlim_num_rows the total number of rows returned by the
2040 * SQL query without any programmatically
2041 * appended "LIMIT" clause
2045 * @see PMA_showMessage(), PMA_setDisplayMode(),
2046 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2047 * PMA_displayTableBody(), PMA_displayResultsOperations()
2049 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2050 global $db, $table, $sql_query, $unlim_num_rows;
2052 $header_shown = FALSE;
2053 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
2055 if ($the_disp_mode[6] == '1' ||
$the_disp_mode[9] == '1') {
2056 // Displays "printable view" link if required
2057 if ($the_disp_mode[9] == '1') {
2059 if (!$header_shown) {
2061 $header_shown = TRUE;
2065 . PMA_generate_common_url($db, $table)
2066 . '&printview=1'
2067 . '&sql_query=' . urlencode($sql_query);
2068 echo ' <!-- Print view -->' . "\n";
2069 echo PMA_linkOrButton(
2070 'sql.php' . $url_query,
2071 ($GLOBALS['cfg']['PropertiesIconic'] ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintView'] . '"/>' : '') . $GLOBALS['strPrintView'],
2072 '', true, true, 'print_view') . "\n";
2074 if (! $_SESSION['userconf']['dontlimitchars']) {
2075 echo ' ' . "\n";
2076 echo PMA_linkOrButton(
2077 'sql.php' . $url_query . '&dontlimitchars=1',
2078 ($GLOBALS['cfg']['PropertiesIconic'] ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintViewFull'] . '"/>' : '') . $GLOBALS['strPrintViewFull'],
2079 '', true, true, 'print_view') . "\n";
2081 } // end displays "printable view"
2087 // (the url_query has extra parameters that won't be used to export)
2088 // (the single_table parameter is used in display_export.lib.php
2089 // to hide the SQL and the structure export dialogs)
2090 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview)) {
2091 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2092 $single_table = '&single_table=true';
2096 if (!$header_shown) {
2098 $header_shown = TRUE;
2100 echo ' <!-- Export -->' . "\n";
2101 echo ' ' . "\n";
2102 echo PMA_linkOrButton(
2103 'tbl_export.php' . $url_query . '&unlim_num_rows=' . $unlim_num_rows . $single_table,
2104 ($GLOBALS['cfg']['PropertiesIconic'] ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_tblexport.png" height="16" width="16" alt="' . $GLOBALS['strExport'] . '" />' : '') . $GLOBALS['strExport'],
2105 '', true, true, '') . "\n";
2111 * @todo detect privileges to create a view
2112 * (but see 2006-01-19 note in display_create_table.lib.php,
2113 * I think we cannot detect db-specific privileges reliably)
2115 if (PMA_MYSQL_INT_VERSION
>= 50000) {
2116 if (!$header_shown) {
2118 $header_shown = TRUE;
2120 echo ' <!-- Create View -->' . "\n";
2121 echo ' ' . "\n";
2122 echo PMA_linkOrButton(
2123 'view_create.php' . $url_query,
2124 ($GLOBALS['cfg']['PropertiesIconic'] ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_views.png" height="16" width="16" alt="CREATE VIEW" />' : '') . 'CREATE VIEW',
2125 '', true, true, '') . "\n";
2128 if ($header_shown) {
2129 echo '</fieldset><br />';