Revert initial commit
[phpmyadmin/blinky.git] / libraries / display_tbl.lib.php
blob538409fb082c37e4e389fdbb72ac899cf914af7d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * library for displaying table with results from all sort of select queries
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
13 require_once './libraries/Table.class.php';
14 require_once './libraries/Index.class.php';
16 /**
17 * Defines the display mode to use for the results of a SQL query
19 * It uses a synthetic string that contains all the required informations.
20 * In this string:
21 * - the first two characters stand for the action to do while
22 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
23 * edit link...);
24 * - the next two characters stand for the action to do while
25 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
26 * no delete link...);
27 * - the next characters are boolean values (1/0) and respectively stand
28 * for sorting links, navigation bar, "insert a new row" link, the
29 * bookmark feature, the expand/collapse text/blob fields button and
30 * the "display printable view" option.
31 * Of course '0'/'1' means the feature won't/will be enabled.
33 * @param string the synthetic value for display_mode (see a few
34 * lines above for explanations)
35 * @param integer the total number of rows returned by the SQL query
36 * without any programmatically appended "LIMIT" clause
37 * (just a copy of $unlim_num_rows if it exists, else
38 * computed inside this function)
40 * @return array an array with explicit indexes for all the display
41 * elements
43 * @global string the database name
44 * @global string the table name
45 * @global integer the total number of rows returned by the SQL query
46 * without any programmatically appended "LIMIT" clause
47 * @global array the properties of the fields returned by the query
48 * @global string the URL to return to in case of error in a SQL
49 * statement
51 * @access private
53 * @see PMA_displayTable()
55 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
57 global $db, $table;
58 global $unlim_num_rows, $fields_meta;
59 global $err_url;
61 // 1. Initializes the $do_display array
62 $do_display = array();
63 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
64 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
65 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
66 $do_display['nav_bar'] = (string) $the_disp_mode[5];
67 $do_display['ins_row'] = (string) $the_disp_mode[6];
68 $do_display['bkm_form'] = (string) $the_disp_mode[7];
69 $do_display['text_btn'] = (string) $the_disp_mode[8];
70 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
72 // 2. Display mode is not "false for all elements" -> updates the
73 // display mode
74 if ($the_disp_mode != 'nnnn000000') {
75 // 2.0 Print view -> set all elements to false!
76 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
77 $do_display['edit_lnk'] = 'nn'; // no edit link
78 $do_display['del_lnk'] = 'nn'; // no delete link
79 $do_display['sort_lnk'] = (string) '0';
80 $do_display['nav_bar'] = (string) '0';
81 $do_display['ins_row'] = (string) '0';
82 $do_display['bkm_form'] = (string) '0';
83 $do_display['text_btn'] = (string) '0';
84 $do_display['pview_lnk'] = (string) '0';
86 // 2.1 Statement is a "SELECT COUNT", a
87 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
88 // contains a "PROC ANALYSE" part
89 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
90 $do_display['edit_lnk'] = 'nn'; // no edit link
91 $do_display['del_lnk'] = 'nn'; // no delete link
92 $do_display['sort_lnk'] = (string) '0';
93 $do_display['nav_bar'] = (string) '0';
94 $do_display['ins_row'] = (string) '0';
95 $do_display['bkm_form'] = (string) '1';
96 if ($GLOBALS['is_maint']) {
97 $do_display['text_btn'] = (string) '1';
98 } else {
99 $do_display['text_btn'] = (string) '0';
101 $do_display['pview_lnk'] = (string) '1';
103 // 2.2 Statement is a "SHOW..."
104 elseif ($GLOBALS['is_show']) {
106 * 2.2.1
107 * @todo defines edit/delete links depending on show statement
109 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
110 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
111 $do_display['edit_lnk'] = 'nn'; // no edit link
112 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
113 } else {
114 // Default case -> no links
115 $do_display['edit_lnk'] = 'nn'; // no edit link
116 $do_display['del_lnk'] = 'nn'; // no delete link
118 // 2.2.2 Other settings
119 $do_display['sort_lnk'] = (string) '0';
120 $do_display['nav_bar'] = (string) '0';
121 $do_display['ins_row'] = (string) '0';
122 $do_display['bkm_form'] = (string) '1';
123 $do_display['text_btn'] = (string) '1';
124 $do_display['pview_lnk'] = (string) '1';
126 // 2.3 Other statements (ie "SELECT" ones) -> updates
127 // $do_display['edit_lnk'], $do_display['del_lnk'] and
128 // $do_display['text_btn'] (keeps other default values)
129 else {
130 $prev_table = $fields_meta[0]->table;
131 $do_display['text_btn'] = (string) '1';
132 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
133 $is_link = ($do_display['edit_lnk'] != 'nn'
134 || $do_display['del_lnk'] != 'nn'
135 || $do_display['sort_lnk'] != '0'
136 || $do_display['ins_row'] != '0');
137 // 2.3.2 Displays edit/delete/sort/insert links?
138 if ($is_link
139 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
140 $do_display['edit_lnk'] = 'nn'; // don't display links
141 $do_display['del_lnk'] = 'nn';
143 * @todo May be problematic with same fields names in two joined table.
145 // $do_display['sort_lnk'] = (string) '0';
146 $do_display['ins_row'] = (string) '0';
147 if ($do_display['text_btn'] == '1') {
148 break;
150 } // end if (2.3.2)
151 // 2.3.3 Always display print view link
152 $do_display['pview_lnk'] = (string) '1';
153 $prev_table = $fields_meta[$i]->table;
154 } // end for
155 } // end if..elseif...else (2.1 -> 2.3)
156 } // end if (2)
158 // 3. Gets the total number of rows if it is unknown
159 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
160 $the_total = $unlim_num_rows;
161 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
162 && (strlen($db) && !empty($table))) {
163 $the_total = PMA_Table::countRecords($db, $table);
166 // 4. If navigation bar or sorting fields names URLs should be
167 // displayed but there is only one row, change these settings to
168 // false
169 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
171 // - Do not display sort links if less than 2 rows.
172 // - For a VIEW we (probably) did not count the number of rows
173 // so don't test this number here, it would remove the possibility
174 // of sorting VIEW results.
175 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
176 // force display of navbar for vertical/horizontal display-choice.
177 // $do_display['nav_bar'] = (string) '0';
178 $do_display['sort_lnk'] = (string) '0';
180 } // end if (3)
182 // 5. Updates the synthetic var
183 $the_disp_mode = join('', $do_display);
185 return $do_display;
186 } // end of the 'PMA_setDisplayMode()' function
190 * Displays a navigation button
192 * @uses $GLOBALS['cfg']['NavigationBarIconic']
193 * @uses PMA_generate_common_hidden_inputs()
195 * @param string iconic caption for button
196 * @param string text for button
197 * @param integer position for next query
198 * @param string query ready for display
199 * @param string optional onsubmit clause
200 * @param string optional hidden field for special treatment
201 * @param string optional onclick clause
203 * @global string $db the database name
204 * @global string $table the table name
205 * @global string $goto the URL to go back in case of errors
207 * @access private
209 * @see PMA_displayTableNavigation()
211 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '') {
213 global $db, $table, $goto;
215 $caption_output = '';
216 // for true or 'both'
217 if ($GLOBALS['cfg']['NavigationBarIconic']) {
218 $caption_output .= $caption;
220 // for false or 'both'
221 if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
222 $caption_output .= '&nbsp;' . $title;
224 $title_output = ' title="' . $title . '"';
226 <td>
227 <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
228 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
229 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
230 <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
231 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
232 <?php echo $input_for_real_end; ?>
233 <input type="submit" name="navig" value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
234 </form>
235 </td>
236 <?php
237 } // end function PMA_displayTableNavigationOneButton()
240 * Displays a navigation bar to browse among the results of a SQL query
242 * @uses $_SESSION['tmp_user_values']['disp_direction']
243 * @uses $_SESSION['tmp_user_values']['repeat_cells']
244 * @uses $_SESSION['tmp_user_values']['max_rows']
245 * @uses $_SESSION['tmp_user_values']['pos']
246 * @param integer the offset for the "next" page
247 * @param integer the offset for the "previous" page
248 * @param string the URL-encoded query
249 * @param string the id for the direction dropdown
251 * @global string $db the database name
252 * @global string $table the table name
253 * @global string $goto the URL to go back in case of errors
254 * @global integer $num_rows the total number of rows returned by the
255 * SQL query
256 * @global integer $unlim_num_rows the total number of rows returned by the
257 * SQL any programmatically appended "LIMIT" clause
258 * @global boolean $is_innodb whether its InnoDB or not
259 * @global array $showtable table definitions
261 * @access private
263 * @see PMA_displayTable()
265 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
267 global $db, $table, $goto;
268 global $num_rows, $unlim_num_rows;
269 global $is_innodb;
270 global $showtable;
272 // here, using htmlentities() would cause problems if the query
273 // contains accented characters
274 $html_sql_query = htmlspecialchars($sql_query);
277 * @todo move this to a central place
278 * @todo for other future table types
280 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
284 <!-- Navigation bar -->
285 <table border="0" cellpadding="2" cellspacing="0">
286 <tr>
287 <?php
288 // Move to the beginning or to the previous page
289 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
290 PMA_displayTableNavigationOneButton('&lt;&lt;', __('Begin'), 0, $html_sql_query);
291 PMA_displayTableNavigationOneButton('&lt;', __('Previous'), $pos_prev, $html_sql_query);
293 } // end move back
295 <td>
296 &nbsp;&nbsp;&nbsp;
297 </td>
298 <td align="center">
299 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
300 // of $cfg['MaxExactCountViews']; in this case, avoid passing
301 // the 5th parameter to checkFormElementInRange()
302 // (this means we can't validate the upper limit ?>
303 <form action="sql.php" method="post"
304 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
305 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
306 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
307 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
308 <input type="submit" name="navig" value="<?php echo __('Show'); ?> :" />
309 <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
310 <?php echo __('row(s) starting from record #') . "\n"; ?>
311 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
312 <br />
313 <?php
314 // Display mode (horizontal/vertical and repeat headers)
315 $choices = array(
316 'horizontal' => __('horizontal'),
317 'horizontalflipped' => __('horizontal (rotated headers)'),
318 'vertical' => __('vertical'));
319 $param1 = PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
320 unset($choices);
322 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />' . "\n"
323 . ' ';
324 echo ' ' . sprintf(__('in %s mode and repeat headers after %s cells'), "\n" . $param1, "\n" . $param2) . "\n";
326 </form>
327 </td>
328 <td>
329 &nbsp;&nbsp;&nbsp;
330 </td>
331 <?php
332 // Move to the next page or to the last one
333 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
334 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
336 // display the Next button
337 PMA_displayTableNavigationOneButton('&gt;',
338 __('Next'),
339 $pos_next,
340 $html_sql_query);
342 // prepare some options for the End button
343 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
344 $input_for_real_end = '<input type="hidden" name="find_real_end" value="1" />';
345 // no backquote around this message
346 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat(__('This operation could take a long time. Proceed anyway?'), false) . '\')"';
347 } else {
348 $input_for_real_end = $onclick = '';
351 // display the End button
352 PMA_displayTableNavigationOneButton('&gt;&gt;',
353 __('End'),
354 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
355 $html_sql_query,
356 'onsubmit="return ' . (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false') . '"',
357 $input_for_real_end,
358 $onclick
360 } // end move toward
363 //page redirection
364 // (unless we are showing all records)
365 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
366 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
367 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
369 if ($nbTotalPage > 1){ //if2
371 <td>
372 &nbsp;&nbsp;&nbsp;
373 </td>
374 <td>
375 <?php //<form> for keep the form alignment of button < and << ?>
376 <form action="none">
377 <?php
378 $_url_params = array(
379 'db' => $db,
380 'table' => $table,
381 'sql_query' => $sql_query,
382 'goto' => $goto,
384 echo PMA_pageselector(
385 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
386 $_SESSION['tmp_user_values']['max_rows'],
387 $pageNow,
388 $nbTotalPage,
389 200,
394 __('Page number:')
397 </form>
398 </td>
399 <?php
400 } //_if2
401 } //_if1
403 // Display the "Show all" button if allowed
404 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
405 echo "\n";
407 <td>
408 &nbsp;&nbsp;&nbsp;
409 </td>
410 <td>
411 <form action="sql.php" method="post">
412 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
413 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
414 <input type="hidden" name="pos" value="0" />
415 <input type="hidden" name="session_max_rows" value="all" />
416 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
417 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
418 </form>
419 </td>
420 <?php
421 } // end show all
422 echo "\n";
424 </tr>
425 </table>
427 <?php
428 } // end of the 'PMA_displayTableNavigation()' function
432 * Displays the headers of the results table
434 * @uses $_SESSION['tmp_user_values']['disp_direction']
435 * @uses $_SESSION['tmp_user_values']['repeat_cells']
436 * @uses $_SESSION['tmp_user_values']['max_rows']
437 * @uses $_SESSION['tmp_user_values']['display_text']
438 * @uses $_SESSION['tmp_user_values']['display_binary']
439 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
440 * @param array which elements to display
441 * @param array the list of fields properties
442 * @param integer the total number of fields returned by the SQL query
443 * @param array the analyzed query
445 * @return boolean $clause_is_unique
447 * @global string $db the database name
448 * @global string $table the table name
449 * @global string $goto the URL to go back in case of errors
450 * @global string $sql_query the SQL query
451 * @global integer $num_rows the total number of rows returned by the
452 * SQL query
453 * @global array $vertical_display informations used with vertical display
454 * mode
456 * @access private
458 * @see PMA_displayTable()
460 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
462 global $db, $table, $goto;
463 global $sql_query, $num_rows;
464 global $vertical_display, $highlight_columns;
466 if ($analyzed_sql == '') {
467 $analyzed_sql = array();
470 // can the result be sorted?
471 if ($is_display['sort_lnk'] == '1') {
473 // Just as fallback
474 $unsorted_sql_query = $sql_query;
475 if (isset($analyzed_sql[0]['unsorted_query'])) {
476 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
478 // Handles the case of multiple clicks on a column's header
479 // which would add many spaces before "ORDER BY" in the
480 // generated query.
481 $unsorted_sql_query = trim($unsorted_sql_query);
483 // sorting by indexes, only if it makes sense (only one table ref)
484 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
485 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
486 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
488 // grab indexes data:
489 $indexes = PMA_Index::getFromTable($table, $db);
491 // do we have any index?
492 if ($indexes) {
494 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
495 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
496 $span = $fields_cnt;
497 if ($is_display['edit_lnk'] != 'nn') {
498 $span++;
500 if ($is_display['del_lnk'] != 'nn') {
501 $span++;
503 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
504 $span++;
506 } else {
507 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
510 echo '<form action="sql.php" method="post">' . "\n";
511 echo PMA_generate_common_hidden_inputs($db, $table);
512 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
513 $used_index = false;
514 $local_order = (isset($sort_expression) ? $sort_expression : '');
515 foreach ($indexes as $index) {
516 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
517 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
518 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
519 echo '<option value="'
520 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
521 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
522 . '>' . htmlspecialchars($index->getName()) . ' ('
523 . __('Ascending') . ')</option>';
524 echo '<option value="'
525 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
526 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
527 . '>' . htmlspecialchars($index->getName()) . ' ('
528 . __('Descending') . ')</option>';
530 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
531 echo '</select>' . "\n";
532 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
533 echo '</form>' . "\n";
539 $vertical_display['emptypre'] = 0;
540 $vertical_display['emptyafter'] = 0;
541 $vertical_display['textbtn'] = '';
543 // Display options (if we are not in print view)
544 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
545 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
546 $url_params = array(
547 'db' => $db,
548 'table' => $table,
549 'sql_query' => $sql_query,
550 'goto' => $goto,
551 'display_options_form' => 1
553 echo PMA_generate_common_hidden_inputs($url_params);
554 echo '<br />';
555 PMA_generate_slider_effect('displayoptions',__('Options'));
556 echo '<fieldset>';
558 echo '<div class="formelement">';
559 $choices = array(
560 'P' => __('Partial Texts'),
561 'F' => __('Full Texts')
563 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
564 echo '</div>';
566 // prepare full/partial text button or link
567 if ($_SESSION['tmp_user_values']['display_text']=='F') {
568 // currently in fulltext mode so show the opposite link
569 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
570 $tmp_txt = __('Partial Texts');
571 $url_params['display_text'] = 'P';
572 } else {
573 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
574 $tmp_txt = __('Full Texts');
575 $url_params['display_text'] = 'F';
578 $tmp_image = '<img class="fulltext" width="50" height="20" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
579 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
580 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
581 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
584 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
585 echo '<div class="formelement">';
586 $choices = array(
587 'K' => __('Relational key'),
588 'D' => __('Relational display field')
590 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
591 echo '</div>';
594 echo '<div class="formelement">';
595 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
596 echo '<br />';
597 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
598 echo '<br />';
599 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
600 echo '</div>';
602 // I would have preferred to name this "display_transformation".
603 // This is the only way I found to be able to keep this setting sticky
604 // per SQL query, and at the same time have a default that displays
605 // the transformations.
606 echo '<div class="formelement">';
607 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
608 echo '</div>';
610 echo '<div class="clearfloat"></div>';
611 echo '</fieldset>';
613 echo '<fieldset class="tblFooters">';
614 echo '<input type="submit" value="' . __('Go') . '" />';
615 echo '</fieldset>';
616 echo '</div>';
617 echo '</form>';
620 // Start of form for multi-rows edit/delete/export
622 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
623 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
624 echo PMA_generate_common_hidden_inputs($db, $table, 1);
625 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
628 echo '<table id="table_results" class="data">' . "\n";
629 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
630 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
631 echo '<thead><tr>' . "\n";
634 // 1. Displays the full/partial text button (part 1)...
635 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
636 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
637 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
638 ? ' colspan="3"'
639 : '';
640 } else {
641 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
642 ? ' rowspan="3"'
643 : '';
646 // ... before the result table
647 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
648 && $is_display['text_btn'] == '1') {
649 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
650 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
651 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
653 <th colspan="<?php echo $fields_cnt; ?>"></th>
654 </tr>
655 <tr>
656 <?php
657 } // end horizontal/horizontalflipped mode
658 else {
660 <tr>
661 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
662 </tr>
663 <?php
664 } // end vertical mode
667 // ... at the left column of the result table header if possible
668 // and required
669 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
670 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
671 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
672 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
674 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
675 <?php
676 } // end horizontal/horizontalflipped mode
677 else {
678 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
679 . ' ' . "\n"
680 . ' </th>' . "\n";
681 } // end vertical mode
684 // ... elseif no button, displays empty(ies) col(s) if required
685 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
686 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
687 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
688 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
689 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
691 <td<?php echo $colspan; ?>></td>
692 <?php
693 } // end horizontal/horizontalfipped mode
694 else {
695 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
696 } // end vertical mode
699 // 2. Displays the fields' name
700 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
701 // statement (see 2.1.3)
703 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
704 // Do not show comments, if using horizontalflipped mode, because of space usage
705 if ($GLOBALS['cfg']['ShowBrowseComments']
706 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
707 $comments_map = array();
708 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
709 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
710 $tb = $tbl['table_true_name'];
711 $comments_map[$tb] = PMA_getComments($db, $tb);
712 unset($tb);
717 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
718 require_once './libraries/transformations.lib.php';
719 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
722 if ($is_display['sort_lnk'] == '1') {
723 $select_expr = $analyzed_sql[0]['select_expr_clause'];
726 // See if we have to highlight any header fields of a WHERE query.
727 // Uses SQL-Parser results.
728 $highlight_columns = array();
729 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
730 isset($analyzed_sql[0]['where_clause_identifiers'])) {
732 $wi = 0;
733 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
734 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
735 $highlight_columns[$wci] = 'true';
740 for ($i = 0; $i < $fields_cnt; $i++) {
741 // See if this column should get highlight because it's used in the
742 // where-query.
743 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
744 $condition_field = true;
745 } else {
746 $condition_field = false;
749 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
750 if (isset($comments_map) &&
751 isset($comments_map[$fields_meta[$i]->table]) &&
752 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
753 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
754 } else {
755 $comments = '';
758 // 2.1 Results can be sorted
759 if ($is_display['sort_lnk'] == '1') {
761 // 2.1.1 Checks if the table name is required; it's the case
762 // for a query with a "JOIN" statement and if the column
763 // isn't aliased, or in queries like
764 // SELECT `1`.`master_field` , `2`.`master_field`
765 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
767 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
768 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
769 } else {
770 $sort_tbl = '';
773 // 2.1.2 Checks if the current column is used to sort the
774 // results
775 // the orgname member does not exist for all MySQL versions
776 // but if found, it's the one on which to sort
777 $name_to_use_in_sort = $fields_meta[$i]->name;
778 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
779 $name_to_use_in_sort = $fields_meta[$i]->orgname;
781 // $name_to_use_in_sort might contain a space due to
782 // formatting of function expressions like "COUNT(name )"
783 // so we remove the space in this situation
784 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
786 if (empty($sort_expression)) {
787 $is_in_sort = false;
788 } else {
789 // Field name may be preceded by a space, or any number
790 // of characters followed by a dot (tablename.fieldname)
791 // so do a direct comparison for the sort expression;
792 // this avoids problems with queries like
793 // "SELECT id, count(id)..." and clicking to sort
794 // on id or on count(id).
795 // Another query to test this:
796 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
797 // (and try clicking on each column's header twice)
798 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
799 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
801 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
803 // 2.1.3 Check the field name for a bracket.
804 // If it contains one, it's probably a function column
805 // like 'COUNT(`field`)'
806 if (strpos($name_to_use_in_sort, '(') !== false) {
807 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
808 } else {
809 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
811 unset($name_to_use_in_sort);
813 // 2.1.4 Do define the sorting URL
814 if (! $is_in_sort) {
815 // patch #455484 ("Smart" order)
816 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
817 if ($GLOBALS['cfg']['Order'] === 'SMART') {
818 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
819 } else {
820 $sort_order .= $GLOBALS['cfg']['Order'];
822 $order_img = '';
823 } elseif ('DESC' == $sort_direction) {
824 $sort_order .= ' ASC';
825 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
826 } else {
827 $sort_order .= ' DESC';
828 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
831 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
832 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
833 } else {
834 $sorted_sql_query = $unsorted_sql_query . $sort_order;
836 $_url_params = array(
837 'db' => $db,
838 'table' => $table,
839 'sql_query' => $sorted_sql_query,
841 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
843 // 2.1.5 Displays the sorting URL
844 // enable sort order swapping for image
845 $order_link_params = array();
846 if (isset($order_img) && $order_img!='') {
847 if (strstr($order_img, 'asc')) {
848 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
849 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
850 } elseif (strstr($order_img, 'desc')) {
851 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
852 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
855 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
856 if (PMA_USR_BROWSER_AGENT == 'IE') {
857 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
858 } else {
859 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
862 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
863 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
864 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
866 $order_link_params['title'] = __('Sort');
867 $order_link_content = ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
868 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
870 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
871 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
872 echo '<th';
873 if ($condition_field) {
874 echo ' class="condition"';
876 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
877 echo ' valign="bottom"';
879 echo '>' . $order_link . $comments . '</th>';
881 $vertical_display['desc'][] = ' <th '
882 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
883 . $order_link . $comments . ' </th>' . "\n";
884 } // end if (2.1)
886 // 2.2 Results can't be sorted
887 else {
888 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
889 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
890 echo '<th';
891 if ($condition_field) {
892 echo ' class="condition"';
894 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
895 echo ' valign="bottom"';
897 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
898 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
899 echo ' style="direction: ltr; writing-mode: tb-rl;"';
901 echo '>';
902 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
903 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
904 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
905 } else {
906 echo htmlspecialchars($fields_meta[$i]->name);
908 echo "\n" . $comments . '</th>';
910 $vertical_display['desc'][] = ' <th '
911 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
912 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
913 . $comments . ' </th>';
914 } // end else (2.2)
915 } // end for
917 // 3. Displays the needed checkboxes at the right
918 // column of the result table header if possible and required...
919 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
920 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
921 && $is_display['text_btn'] == '1') {
922 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
923 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
924 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
925 echo "\n";
927 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
928 </th>
929 <?php
930 } // end horizontal/horizontalflipped mode
931 else {
932 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
933 . ' ' . "\n"
934 . ' </th>' . "\n";
935 } // end vertical mode
938 // ... elseif no button, displays empty columns if required
939 // (unless coming from Browse mode print view)
940 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
941 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
942 && (!$GLOBALS['is_header_sent'])) {
943 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
944 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
945 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
946 echo "\n";
948 <td<?php echo $colspan; ?>></td>
949 <?php
950 } // end horizontal/horizontalflipped mode
951 else {
952 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
953 } // end vertical mode
956 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
957 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
959 </tr>
960 </thead>
961 <?php
964 return true;
965 } // end of the 'PMA_displayTableHeaders()' function
970 * Displays the body of the results table
972 * @uses $_SESSION['tmp_user_values']['disp_direction']
973 * @uses $_SESSION['tmp_user_values']['repeat_cells']
974 * @uses $_SESSION['tmp_user_values']['max_rows']
975 * @uses $_SESSION['tmp_user_values']['display_text']
976 * @uses $_SESSION['tmp_user_values']['display_binary']
977 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
978 * @uses $_SESSION['tmp_user_values']['display_blob']
979 * @param integer the link id associated to the query which results have
980 * to be displayed
981 * @param array which elements to display
982 * @param array the list of relations
983 * @param array the analyzed query
985 * @return boolean always true
987 * @global string $db the database name
988 * @global string $table the table name
989 * @global string $goto the URL to go back in case of errors
990 * @global string $sql_query the SQL query
991 * @global array $fields_meta the list of fields properties
992 * @global integer $fields_cnt the total number of fields returned by
993 * the SQL query
994 * @global array $vertical_display informations used with vertical display
995 * mode
996 * @global array $highlight_columns column names to highlight
997 * @global array $row current row data
999 * @access private
1001 * @see PMA_displayTable()
1003 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1004 global $db, $table, $goto;
1005 global $sql_query, $fields_meta, $fields_cnt;
1006 global $vertical_display, $highlight_columns;
1007 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1009 $url_sql_query = $sql_query;
1011 // query without conditions to shorten URLs when needed, 200 is just
1012 // guess, it should depend on remaining URL length
1014 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1015 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1016 strlen($sql_query) > 200) {
1018 $url_sql_query = 'SELECT ';
1019 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1020 $url_sql_query .= ' DISTINCT ';
1022 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1023 if (!empty($analyzed_sql[0]['from_clause'])) {
1024 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1028 if (!is_array($map)) {
1029 $map = array();
1031 $row_no = 0;
1032 $vertical_display['edit'] = array();
1033 $vertical_display['delete'] = array();
1034 $vertical_display['data'] = array();
1035 $vertical_display['row_delete'] = array();
1037 // Correction University of Virginia 19991216 in the while below
1038 // Previous code assumed that all tables have keys, specifically that
1039 // the phpMyAdmin GUI should support row delete/edit only for such
1040 // tables.
1041 // Although always using keys is arguably the prescribed way of
1042 // defining a relational table, it is not required. This will in
1043 // particular be violated by the novice.
1044 // We want to encourage phpMyAdmin usage by such novices. So the code
1045 // below has been changed to conditionally work as before when the
1046 // table being displayed has one or more keys; but to display
1047 // delete/edit options correctly for tables without keys.
1049 $odd_row = true;
1050 while ($row = PMA_DBI_fetch_row($dt_result)) {
1051 // "vertical display" mode stuff
1052 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1053 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1054 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1056 echo '<tr>' . "\n";
1057 if ($vertical_display['emptypre'] > 0) {
1058 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1059 .' &nbsp;</th>' . "\n";
1062 foreach ($vertical_display['desc'] as $val) {
1063 echo $val;
1066 if ($vertical_display['emptyafter'] > 0) {
1067 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1068 .' &nbsp;</th>' . "\n";
1070 echo '</tr>' . "\n";
1071 } // end if
1073 $class = $odd_row ? 'odd' : 'even';
1074 $odd_row = ! $odd_row;
1075 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1076 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1077 // pointer code part
1078 echo ' <tr class="' . $class . '">' . "\n";
1079 $class = '';
1083 // 1. Prepares the row
1084 // 1.1 Results from a "SELECT" statement -> builds the
1085 // WHERE clause to use in links (a unique key if possible)
1087 * @todo $where_clause could be empty, for example a table
1088 * with only one field and it's a BLOB; in this case,
1089 * avoid to display the delete and edit links
1091 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1092 $where_clause_html = urlencode($where_clause);
1094 // 1.2 Defines the URLs for the modify/delete link(s)
1096 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1097 // We need to copy the value or else the == 'both' check will always return true
1099 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1100 $iconic_spacer = '<div class="nowrap">';
1101 } else {
1102 $iconic_spacer = '';
1105 // 1.2.1 Modify link(s)
1106 if ($is_display['edit_lnk'] == 'ur') { // update row case
1107 $_url_params = array(
1108 'db' => $db,
1109 'table' => $table,
1110 'where_clause' => $where_clause,
1111 'clause_is_unique' => $clause_is_unique,
1112 'sql_query' => $url_sql_query,
1113 'goto' => 'sql.php',
1115 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
1117 $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
1118 } // end if (1.2.1)
1120 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])) {
1121 $_url_params = array(
1122 'db' => $row[1],
1123 'id_bookmark' => $row[0],
1124 'action_bookmark' => '0',
1125 'action_bookmark_all' => '1',
1126 'SQL' => __('Execute bookmarked query'),
1128 $bookmark_go = '<a href="import.php'
1129 . PMA_generate_common_url($_url_params)
1130 .' " title="' . __('Execute bookmarked query') . '">';
1132 $bookmark_go .= PMA_getIcon('b_bookmark.png', __('Execute bookmarked query'), true);
1134 $bookmark_go .= '</a>';
1135 } else {
1136 $bookmark_go = '';
1139 // 1.2.2 Delete/Kill link(s)
1140 if ($is_display['del_lnk'] == 'dr') { // delete row case
1141 $_url_params = array(
1142 'db' => $db,
1143 'table' => $table,
1144 'sql_query' => $url_sql_query,
1145 'zero_rows' => __('The row has been deleted'),
1146 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1148 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1150 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1151 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1153 $_url_params = array(
1154 'db' => $db,
1155 'table' => $table,
1156 'sql_query' => $del_query,
1157 'zero_rows' => __('The row has been deleted'),
1158 'goto' => $lnk_goto,
1160 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1162 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1163 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1164 . ($clause_is_unique ? '' : ' LIMIT 1');
1165 $del_str = PMA_getIcon('b_drop.png', __('Delete'), true);
1166 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1168 $_url_params = array(
1169 'db' => $db,
1170 'table' => $table,
1171 'sql_query' => $url_sql_query,
1172 'goto' => 'main.php',
1174 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1176 $_url_params = array(
1177 'db' => 'mysql',
1178 'sql_query' => 'KILL ' . $row[0],
1179 'goto' => $lnk_goto,
1181 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1182 $del_query = 'KILL ' . $row[0];
1183 $js_conf = 'KILL ' . $row[0];
1184 $del_str = PMA_getIcon('b_drop.png', __('Kill'), true);
1185 } // end if (1.2.2)
1187 // 1.3 Displays the links at left if required
1188 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1189 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1190 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1191 $doWriteModifyAt = 'left';
1192 require './libraries/display_tbl_links.lib.php';
1193 } // end if (1.3)
1194 } // end if (1)
1196 // 2. Displays the rows' values
1197 for ($i = 0; $i < $fields_cnt; ++$i) {
1198 $meta = $fields_meta[$i];
1199 $pointer = $i;
1200 // See if this column should get highlight because it's used in the
1201 // where-query.
1202 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1203 $condition_field = true;
1204 } else {
1205 $condition_field = false;
1208 $mouse_events = '';
1209 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1210 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1211 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1212 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1214 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1215 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1216 } else {
1217 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1219 }// end if
1221 // Wrap MIME-transformations. [MIME]
1222 $default_function = 'default_function'; // default_function
1223 $transform_function = $default_function;
1224 $transform_options = array();
1226 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1228 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1229 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1231 if (file_exists('./libraries/transformations/' . $include_file)) {
1232 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1234 require_once './libraries/transformations/' . $include_file;
1236 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1237 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1238 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1239 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1241 } // end if file_exists
1242 } // end if transformation is set
1243 } // end if mime/transformation works.
1245 $_url_params = array(
1246 'db' => $db,
1247 'table' => $table,
1248 'where_clause' => $where_clause,
1249 'transform_key' => $meta->name,
1252 if (! empty($sql_query)) {
1253 $_url_params['sql_query'] = $url_sql_query;
1256 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1258 // n u m e r i c
1259 if ($meta->numeric == 1) {
1261 // if two fields have the same name (this is possible
1262 // with self-join queries, for example), using $meta->name
1263 // will show both fields NULL even if only one is NULL,
1264 // so use the $pointer
1266 if (!isset($row[$i]) || is_null($row[$i])) {
1267 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1268 } elseif ($row[$i] != '') {
1270 $nowrap = ' nowrap';
1271 $where_comparison = ' = ' . $row[$i];
1273 $vertical_display['data'][$row_no][$i] = '<td align="right"' . PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options);
1274 } else {
1275 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1278 // b l o b
1280 } elseif (stristr($meta->type, 'BLOB')) {
1281 // PMA_mysql_fetch_fields returns BLOB in place of
1282 // TEXT fields type so we have to ensure it's really a BLOB
1283 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1284 if (stristr($field_flags, 'BINARY')) {
1285 if (!isset($row[$i]) || is_null($row[$i])) {
1286 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1287 } else {
1288 // for blobstreaming
1290 $bs_reference_exists = $allBSTablesExist = FALSE;
1292 // load PMA configuration
1293 $PMA_Config = $GLOBALS['PMA_Config'];
1295 // if PMA configuration exists
1296 if ($PMA_Config) {
1297 // load BS variables
1298 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
1300 // if BS plugins exist
1301 if ($pluginsExist) {
1302 // load BS databases
1303 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
1305 // if BS db array and specified db string not empty and valid
1306 if (!empty($bs_tables) && strlen($db) > 0) {
1307 $bs_tables = $bs_tables[$db];
1309 if (isset($bs_tables)) {
1310 $allBSTablesExist = TRUE;
1312 // check if BS tables exist for given database
1313 foreach ($bs_tables as $table_key=>$bs_tbl)
1314 if (!$bs_tables[$table_key]['Exists']) {
1315 $allBSTablesExist = FALSE;
1316 break;
1323 // if necessary BS tables exist
1324 if ($allBSTablesExist) {
1325 $bs_reference_exists = PMA_BS_ReferenceExists($row[$i], $db);
1328 // if valid BS reference exists
1329 if ($bs_reference_exists) {
1330 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1331 } else {
1332 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1335 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
1336 unset($blobtext);
1338 // not binary:
1339 } else {
1340 if (!isset($row[$i]) || is_null($row[$i])) {
1341 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1342 } elseif ($row[$i] != '') {
1343 // if a transform function for blob is set, none of these replacements will be made
1344 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1345 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1347 // displays all space characters, 4 space
1348 // characters for tabulations and <cr>/<lf>
1349 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1351 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1352 } else {
1353 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1356 // n o t n u m e r i c a n d n o t B L O B
1357 } else {
1358 if (!isset($row[$i]) || is_null($row[$i])) {
1359 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1360 } elseif ($row[$i] != '') {
1361 // support blanks in the key
1362 $relation_id = $row[$i];
1364 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1365 // (unless it's a link-type transformation)
1366 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1367 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1370 // displays special characters from binaries
1371 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1372 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1373 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1374 // some results of PROCEDURE ANALYSE() are reported as
1375 // being BINARY but they are quite readable,
1376 // so don't treat them as BINARY
1377 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1378 if ($_SESSION['tmp_user_values']['display_binary']) {
1379 // user asked to see the real contents of BINARY
1380 // fields
1381 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1382 $row[$i] = bin2hex($row[$i]);
1384 else {
1385 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1387 } else {
1388 // we show the BINARY message and field's size
1389 // (or maybe use a transformation)
1390 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1394 // transform functions may enable no-wrapping:
1395 $function_nowrap = $transform_function . '_nowrap';
1396 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1398 // do not wrap if date field type
1399 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1400 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1401 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options);
1403 } else {
1404 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1408 // output stored cell
1409 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1410 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1411 echo $vertical_display['data'][$row_no][$i];
1414 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1415 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1416 } else {
1417 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1419 } // end for (2)
1421 // 3. Displays the modify/delete links on the right if required
1422 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1423 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1424 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1425 $doWriteModifyAt = 'right';
1426 require './libraries/display_tbl_links.lib.php';
1427 } // end if (3)
1429 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1430 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1432 </tr>
1433 <?php
1434 } // end if
1436 // 4. Gather links of del_urls and edit_urls in an array for later
1437 // output
1438 if (!isset($vertical_display['edit'][$row_no])) {
1439 $vertical_display['edit'][$row_no] = '';
1440 $vertical_display['delete'][$row_no] = '';
1441 $vertical_display['row_delete'][$row_no] = '';
1444 $column_style_vertical = '';
1445 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1446 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1447 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1449 $column_marker_vertical = '';
1450 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1451 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1454 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1455 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1456 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $where_clause_html . ']"'
1457 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1458 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1459 . ' </td>' . "\n";
1460 } else {
1461 unset($vertical_display['row_delete'][$row_no]);
1464 if (isset($edit_url)) {
1465 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1466 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1467 . $bookmark_go
1468 . ' </td>' . "\n";
1469 } else {
1470 unset($vertical_display['edit'][$row_no]);
1473 if (isset($del_url)) {
1474 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1475 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1476 . ' </td>' . "\n";
1477 } else {
1478 unset($vertical_display['delete'][$row_no]);
1481 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1482 $row_no++;
1483 } // end while
1485 // this is needed by PMA_displayTable() to generate the proper param
1486 // in the multi-edit and multi-delete form
1487 return $clause_is_unique;
1488 } // end of the 'PMA_displayTableBody()' function
1492 * Do display the result table with the vertical direction mode.
1493 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1495 * @return boolean always true
1497 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1498 * @global array $vertical_display the information to display
1500 * @access private
1502 * @see PMA_displayTable()
1504 function PMA_displayVerticalTable()
1506 global $vertical_display;
1508 // Displays "multi row delete" link at top if required
1509 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1510 echo '<tr>' . "\n";
1511 echo $vertical_display['textbtn'];
1512 $foo_counter = 0;
1513 foreach ($vertical_display['row_delete'] as $val) {
1514 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1515 echo '<th></th>' . "\n";
1518 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1519 $foo_counter++;
1520 } // end while
1521 echo '</tr>' . "\n";
1522 } // end if
1524 // Displays "edit" link at top if required
1525 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1526 echo '<tr>' . "\n";
1527 if (!is_array($vertical_display['row_delete'])) {
1528 echo $vertical_display['textbtn'];
1530 $foo_counter = 0;
1531 foreach ($vertical_display['edit'] as $val) {
1532 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1533 echo ' <th></th>' . "\n";
1536 echo $val;
1537 $foo_counter++;
1538 } // end while
1539 echo '</tr>' . "\n";
1540 } // end if
1542 // Displays "delete" link at top if required
1543 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1544 echo '<tr>' . "\n";
1545 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1546 echo $vertical_display['textbtn'];
1548 $foo_counter = 0;
1549 foreach ($vertical_display['delete'] as $val) {
1550 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1551 echo '<th></th>' . "\n";
1554 echo $val;
1555 $foo_counter++;
1556 } // end while
1557 echo '</tr>' . "\n";
1558 } // end if
1560 // Displays data
1561 foreach ($vertical_display['desc'] AS $key => $val) {
1563 echo '<tr>' . "\n";
1564 echo $val;
1566 $foo_counter = 0;
1567 foreach ($vertical_display['rowdata'][$key] as $subval) {
1568 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1569 echo $val;
1572 echo $subval;
1573 $foo_counter++;
1574 } // end while
1576 echo '</tr>' . "\n";
1577 } // end while
1579 // Displays "multi row delete" link at bottom if required
1580 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1581 echo '<tr>' . "\n";
1582 echo $vertical_display['textbtn'];
1583 $foo_counter = 0;
1584 foreach ($vertical_display['row_delete'] as $val) {
1585 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1586 echo '<th></th>' . "\n";
1589 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1590 $foo_counter++;
1591 } // end while
1592 echo '</tr>' . "\n";
1593 } // end if
1595 // Displays "edit" link at bottom if required
1596 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1597 echo '<tr>' . "\n";
1598 if (!is_array($vertical_display['row_delete'])) {
1599 echo $vertical_display['textbtn'];
1601 $foo_counter = 0;
1602 foreach ($vertical_display['edit'] as $val) {
1603 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1604 echo '<th></th>' . "\n";
1607 echo $val;
1608 $foo_counter++;
1609 } // end while
1610 echo '</tr>' . "\n";
1611 } // end if
1613 // Displays "delete" link at bottom if required
1614 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1615 echo '<tr>' . "\n";
1616 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1617 echo $vertical_display['textbtn'];
1619 $foo_counter = 0;
1620 foreach ($vertical_display['delete'] as $val) {
1621 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1622 echo '<th></th>' . "\n";
1625 echo $val;
1626 $foo_counter++;
1627 } // end while
1628 echo '</tr>' . "\n";
1631 return true;
1632 } // end of the 'PMA_displayVerticalTable' function
1636 * @uses $_SESSION['tmp_user_values']['disp_direction']
1637 * @uses $_REQUEST['disp_direction']
1638 * @uses $GLOBALS['cfg']['DefaultDisplay']
1639 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1640 * @uses $_REQUEST['repeat_cells']
1641 * @uses $GLOBALS['cfg']['RepeatCells']
1642 * @uses $_SESSION['tmp_user_values']['max_rows']
1643 * @uses $_REQUEST['session_max_rows']
1644 * @uses $GLOBALS['cfg']['MaxRows']
1645 * @uses $_SESSION['tmp_user_values']['pos']
1646 * @uses $_REQUEST['pos']
1647 * @uses $_SESSION['tmp_user_values']['display_text']
1648 * @uses $_REQUEST['display_text']
1649 * @uses $_SESSION['tmp_user_values']['relational_display']
1650 * @uses $_REQUEST['relational_display']
1651 * @uses $_SESSION['tmp_user_values']['display_binary']
1652 * @uses $_REQUEST['display_binary']
1653 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1654 * @uses $_REQUEST['display_binary_as_hex']
1655 * @uses $_SESSION['tmp_user_values']['display_blob']
1656 * @uses $_REQUEST['display_blob']
1657 * @uses PMA_isValid()
1658 * @uses $GLOBALS['sql_query']
1659 * @todo make maximum remembered queries configurable
1660 * @todo move/split into SQL class!?
1661 * @todo currently this is called twice unnecessary
1662 * @todo ignore LIMIT and ORDER in query!?
1664 function PMA_displayTable_checkConfigParams()
1666 $sql_md5 = md5($GLOBALS['sql_query']);
1668 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1670 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1671 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1672 unset($_REQUEST['disp_direction']);
1673 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1674 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1677 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1678 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1679 unset($_REQUEST['repeat_cells']);
1680 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1681 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1684 // as this is a form value, the type is always string so we cannot
1685 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1686 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1687 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1688 || $_REQUEST['session_max_rows'] == 'all') {
1689 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1690 unset($_REQUEST['session_max_rows']);
1691 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1692 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1695 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1696 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1697 unset($_REQUEST['pos']);
1698 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1699 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1702 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1703 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1704 unset($_REQUEST['display_text']);
1705 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1706 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1709 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1710 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1711 unset($_REQUEST['relational_display']);
1712 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1713 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1716 if (isset($_REQUEST['display_binary'])) {
1717 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1718 unset($_REQUEST['display_binary']);
1719 } elseif (isset($_REQUEST['display_options_form'])) {
1720 // we know that the checkbox was unchecked
1721 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1722 } else {
1723 // selected by default because some operations like OPTIMIZE TABLE
1724 // and all queries involving functions return "binary" contents,
1725 // according to low-level field flags
1726 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1729 if (isset($_REQUEST['display_binary_as_hex'])) {
1730 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1731 unset($_REQUEST['display_binary_as_hex']);
1732 } elseif (isset($_REQUEST['display_options_form'])) {
1733 // we know that the checkbox was unchecked
1734 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1735 } else {
1736 // display_binary_as_hex config option
1737 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1738 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1742 if (isset($_REQUEST['display_blob'])) {
1743 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1744 unset($_REQUEST['display_blob']);
1745 } elseif (isset($_REQUEST['display_options_form'])) {
1746 // we know that the checkbox was unchecked
1747 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1750 if (isset($_REQUEST['hide_transformation'])) {
1751 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1752 unset($_REQUEST['hide_transformation']);
1753 } elseif (isset($_REQUEST['display_options_form'])) {
1754 // we know that the checkbox was unchecked
1755 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1758 // move current query to the last position, to be removed last
1759 // so only least executed query will be removed if maximum remembered queries
1760 // limit is reached
1761 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
1762 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
1763 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
1765 // do not exceed a maximum number of queries to remember
1766 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1767 array_shift($_SESSION['tmp_user_values']['query']);
1768 //echo 'deleting one element ...';
1771 // populate query configuration
1772 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
1773 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
1774 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
1775 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
1776 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
1777 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
1778 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
1779 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
1780 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
1781 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
1784 * debugging
1785 echo '<pre>';
1786 var_dump($_SESSION['tmp_user_values']);
1787 echo '</pre>';
1792 * Displays a table of results returned by a SQL query.
1793 * This function is called by the "sql.php" script.
1795 * @param integer the link id associated to the query which results have
1796 * to be displayed
1797 * @param array the display mode
1798 * @param array the analyzed query
1800 * @uses $_SESSION['tmp_user_values']['pos']
1801 * @global string $db the database name
1802 * @global string $table the table name
1803 * @global string $goto the URL to go back in case of errors
1804 * @global string $sql_query the current SQL query
1805 * @global integer $num_rows the total number of rows returned by the
1806 * SQL query
1807 * @global integer $unlim_num_rows the total number of rows returned by the
1808 * SQL query without any programmatically
1809 * appended "LIMIT" clause
1810 * @global array $fields_meta the list of fields properties
1811 * @global integer $fields_cnt the total number of fields returned by
1812 * the SQL query
1813 * @global array $vertical_display informations used with vertical display
1814 * mode
1815 * @global array $highlight_columns column names to highlight
1816 * @global array $cfgRelation the relation settings
1818 * @access private
1820 * @see PMA_showMessage(), PMA_setDisplayMode(),
1821 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1822 * PMA_displayTableBody(), PMA_displayResultsOperations()
1824 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1826 global $db, $table, $goto;
1827 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1828 global $vertical_display, $highlight_columns;
1829 global $cfgRelation;
1830 global $showtable;
1832 // why was this called here? (already called from sql.php)
1833 //PMA_displayTable_checkConfigParams();
1836 * @todo move this to a central place
1837 * @todo for other future table types
1839 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1841 if ($is_innodb
1842 && ! isset($analyzed_sql[0]['queryflags']['union'])
1843 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1844 && (empty($analyzed_sql[0]['where_clause'])
1845 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1846 // "j u s t b r o w s i n g"
1847 $pre_count = '~';
1848 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')), true);
1849 } else {
1850 $pre_count = '';
1851 $after_count = '';
1854 // 1. ----- Prepares the work -----
1856 // 1.1 Gets the informations about which functionalities should be
1857 // displayed
1858 $total = '';
1859 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1861 // 1.2 Defines offsets for the next and previous pages
1862 if ($is_display['nav_bar'] == '1') {
1863 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1864 $pos_next = 0;
1865 $pos_prev = 0;
1866 } else {
1867 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
1868 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1869 if ($pos_prev < 0) {
1870 $pos_prev = 0;
1873 } // end if
1875 // 1.3 Find the sort expression
1877 // we need $sort_expression and $sort_expression_nodirection
1878 // even if there are many table references
1879 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1880 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1882 * Get rid of ASC|DESC
1884 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1885 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1886 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1887 unset($matches);
1888 } else {
1889 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1892 // 1.4 Prepares display of first and last value of the sorted column
1894 if (! empty($sort_expression_nodirection)) {
1895 if (strpos($sort_expression_nodirection, '.') === false) {
1896 $sort_table = $table;
1897 $sort_column = $sort_expression_nodirection;
1898 } else {
1899 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1901 $sort_table = PMA_unQuote($sort_table);
1902 $sort_column = PMA_unQuote($sort_column);
1903 // find the sorted column index in row result
1904 // (this might be a multi-table query)
1905 $sorted_column_index = false;
1906 foreach($fields_meta as $key => $meta) {
1907 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1908 $sorted_column_index = $key;
1909 break;
1912 if ($sorted_column_index !== false) {
1913 // fetch first row of the result set
1914 $row = PMA_DBI_fetch_row($dt_result);
1915 $column_for_first_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1916 // fetch last row of the result set
1917 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1918 $row = PMA_DBI_fetch_row($dt_result);
1919 $column_for_last_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1920 // reset to first row for the loop in PMA_displayTableBody()
1921 PMA_DBI_data_seek($dt_result, 0);
1922 // we could also use here $sort_expression_nodirection
1923 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1924 unset($row, $column_for_first_row, $column_for_last_row);
1926 unset($sorted_column_index, $sort_table, $sort_column);
1929 // 2. ----- Displays the top of the page -----
1931 // 2.1 Displays a messages with position informations
1932 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1933 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1934 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
1935 } else {
1936 $selectstring = '';
1938 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
1939 ? $total - 1
1940 : $pos_next - 1;
1942 if (PMA_Table::isView($db, $table)
1943 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1944 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
1945 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1946 $message->addParam('[/a]');
1947 $message_view_warning = PMA_showHint($message);
1948 } else {
1949 $message_view_warning = false;
1952 $message = PMA_Message::success(__('Showing rows'));
1953 $message->addMessage($_SESSION['tmp_user_values']['pos']);
1954 if ($message_view_warning) {
1955 $message->addMessage('...', ' - ');
1956 $message->addMessage($message_view_warning);
1957 $message->addMessage('(');
1958 } else {
1959 $message->addMessage($last_shown_rec, ' - ');
1960 $message->addMessage(' (');
1961 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
1962 $message->addString(__('total'));
1963 if (!empty($after_count)) {
1964 $message->addMessage($after_count);
1966 $message->addMessage($selectstring, '');
1967 $message->addMessage(', ', '');
1970 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
1971 $messagge_qt->addParam($GLOBALS['querytime']);
1973 $message->addMessage($messagge_qt, '');
1974 $message->addMessage(')', '');
1976 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
1978 PMA_showMessage($message, $sql_query, 'success');
1980 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1981 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
1984 // 2.3 Displays the navigation bars
1985 if (! strlen($table)) {
1986 if (isset($analyzed_sql[0]['query_type'])
1987 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1988 // table does not always contain a real table name,
1989 // for example in MySQL 5.0.x, the query SHOW STATUS
1990 // returns STATUS as a table name
1991 $table = $fields_meta[0]->table;
1992 } else {
1993 $table = '';
1997 if ($is_display['nav_bar'] == '1') {
1998 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
1999 echo "\n";
2000 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2001 echo "\n" . '<br /><br />' . "\n";
2004 // 2b ----- Get field references from Database -----
2005 // (see the 'relation' configuration variable)
2007 // initialize map
2008 $map = array();
2010 // find tables
2011 $target=array();
2012 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2013 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2014 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2017 $tabs = '(\'' . join('\',\'', $target) . '\')';
2019 if ($cfgRelation['displaywork']) {
2020 if (! strlen($table)) {
2021 $exist_rel = false;
2022 } else {
2023 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2024 if ($exist_rel) {
2025 foreach ($exist_rel AS $master_field => $rel) {
2026 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2027 $map[$master_field] = array($rel['foreign_table'],
2028 $rel['foreign_field'],
2029 $display_field,
2030 $rel['foreign_db']);
2031 } // end while
2032 } // end if
2033 } // end if
2034 } // end if
2035 // end 2b
2037 // 3. ----- Displays the results table -----
2038 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2039 $url_query = '';
2040 echo '<tbody>' . "\n";
2041 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2042 // vertical output case
2043 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2044 PMA_displayVerticalTable();
2045 } // end if
2046 unset($vertical_display);
2047 echo '</tbody>' . "\n";
2049 </table>
2051 <?php
2052 // 4. ----- Displays the link for multi-fields edit and delete
2054 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2056 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2058 $_url_params = array(
2059 'db' => $db,
2060 'table' => $table,
2061 'sql_query' => $sql_query,
2062 'goto' => $goto,
2064 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2066 $_url_params['checkall'] = '1';
2067 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2069 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2070 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2071 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2072 } else {
2073 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2074 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2076 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2077 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2078 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2079 echo '<img class="selectallarrow" width="38" height="22"'
2080 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2081 .' alt="' . __('With selected:') . '" />';
2083 echo $checkall_link . "\n"
2084 .' / ' . "\n"
2085 .$uncheckall_link . "\n"
2086 .'<i>' . __('With selected:') . '</i>' . "\n";
2088 PMA_buttonOrImage('submit_mult', 'mult_submit',
2089 'submit_mult_change', __('Change'), 'b_edit.png');
2090 PMA_buttonOrImage('submit_mult', 'mult_submit',
2091 'submit_mult_delete', $delete_text, 'b_drop.png');
2092 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
2093 PMA_buttonOrImage('submit_mult', 'mult_submit',
2094 'submit_mult_export', __('Export'),
2095 'b_tblexport.png');
2097 echo "\n";
2099 echo '<input type="hidden" name="sql_query"'
2100 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2101 echo '<input type="hidden" name="url_query"'
2102 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2104 echo '<input type="hidden" name="clause_is_unique"'
2105 .' value="' . $clause_is_unique . '" />' . "\n";
2107 echo '</form>' . "\n";
2110 // 5. ----- Displays the navigation bar at the bottom if required -----
2112 if ($is_display['nav_bar'] == '1') {
2113 echo '<br />' . "\n";
2114 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2115 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2116 echo "\n" . '<br /><br />' . "\n";
2119 // 6. ----- Displays "Query results operations"
2120 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2121 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2123 } // end of the 'PMA_displayTable()' function
2125 function default_function($buffer) {
2126 $buffer = htmlspecialchars($buffer);
2127 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2128 str_replace(' ', ' &nbsp;', $buffer));
2129 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2131 return $buffer;
2135 * Displays operations that are available on results.
2137 * @param array the display mode
2138 * @param array the analyzed query
2140 * @uses $_SESSION['tmp_user_values']['pos']
2141 * @uses $_SESSION['tmp_user_values']['display_text']
2142 * @global string $db the database name
2143 * @global string $table the table name
2144 * @global string $sql_query the current SQL query
2145 * @global integer $unlim_num_rows the total number of rows returned by the
2146 * SQL query without any programmatically
2147 * appended "LIMIT" clause
2149 * @access private
2151 * @see PMA_showMessage(), PMA_setDisplayMode(),
2152 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2153 * PMA_displayTableBody(), PMA_displayResultsOperations()
2155 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2156 global $db, $table, $sql_query, $unlim_num_rows;
2158 $header_shown = FALSE;
2159 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2161 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2162 // Displays "printable view" link if required
2163 if ($the_disp_mode[9] == '1') {
2165 if (!$header_shown) {
2166 echo $header;
2167 $header_shown = TRUE;
2170 $_url_params = array(
2171 'db' => $db,
2172 'table' => $table,
2173 'printview' => '1',
2174 'sql_query' => $sql_query,
2176 $url_query = PMA_generate_common_url($_url_params);
2178 echo PMA_linkOrButton(
2179 'sql.php' . $url_query,
2180 PMA_getIcon('b_print.png', __('Print view'), false, true),
2181 '', true, true, 'print_view') . "\n";
2183 if ($_SESSION['tmp_user_values']['display_text']) {
2184 $_url_params['display_text'] = 'F';
2185 echo PMA_linkOrButton(
2186 'sql.php' . PMA_generate_common_url($_url_params),
2187 PMA_getIcon('b_print.png', __('Print view (with full texts)'), false, true),
2188 '', true, true, 'print_view') . "\n";
2189 unset($_url_params['display_text']);
2191 } // end displays "printable view"
2194 // Export link
2195 // (the url_query has extra parameters that won't be used to export)
2196 // (the single_table parameter is used in display_export.lib.php
2197 // to hide the SQL and the structure export dialogs)
2198 // If the parser found a PROCEDURE clause
2199 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2200 // display the Export link).
2201 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2202 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2203 $_url_params['single_table'] = 'true';
2205 if (!$header_shown) {
2206 echo $header;
2207 $header_shown = TRUE;
2209 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2212 * At this point we don't know the table name; this can happen
2213 * for example with a query like
2214 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2215 * As a workaround we set in the table parameter the name of the
2216 * first table of this database, so that tbl_export.php and
2217 * the script it calls do not fail
2219 if (empty($_url_params['table'])) {
2220 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2223 echo PMA_linkOrButton(
2224 'tbl_export.php' . PMA_generate_common_url($_url_params),
2225 PMA_getIcon('b_tblexport.png', __('Export'), false, true),
2226 '', true, true, '') . "\n";
2229 // CREATE VIEW
2232 * @todo detect privileges to create a view
2233 * (but see 2006-01-19 note in display_create_table.lib.php,
2234 * I think we cannot detect db-specific privileges reliably)
2235 * Note: we don't display a Create view link if we found a PROCEDURE clause
2237 if (!$header_shown) {
2238 echo $header;
2239 $header_shown = TRUE;
2241 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2242 echo PMA_linkOrButton(
2243 'view_create.php' . $url_query,
2244 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2245 '', true, true, '') . "\n";
2247 if ($header_shown) {
2248 echo '</fieldset><br />';
2253 * Verifies what to do with non-printable contents (binary or BLOB)
2254 * in Browse mode.
2256 * @uses is_null()
2257 * @uses isset()
2258 * @uses strlen()
2259 * @uses PMA_formatByteDown()
2260 * @uses strpos()
2261 * @uses str_replace()
2262 * @param string $category BLOB|BINARY
2263 * @param string $content the binary content
2264 * @param string $transform_function
2265 * @param string $transform_options
2266 * @param string $default_function
2267 * @param object $meta the meta-information about this field
2268 * @return mixed string or float
2270 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2271 $result = '[' . $category;
2272 if (is_null($content)) {
2273 $result .= ' - NULL';
2274 $size = 0;
2275 } elseif (isset($content)) {
2276 $size = strlen($content);
2277 $display_size = PMA_formatByteDown($size, 3, 1);
2278 $result .= ' - '. $display_size[0] . $display_size[1];
2280 $result .= ']';
2282 if (strpos($transform_function, 'octetstream')) {
2283 $result = $content;
2285 if ($size > 0) {
2286 if ($default_function != $transform_function) {
2287 $result = $transform_function($result, $transform_options, $meta);
2288 } else {
2289 $result = $default_function($result, array(), $meta);
2290 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2291 // in this case, restart from the original $content
2292 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2294 /* Create link to download */
2295 if (count($url_params) > 0) {
2296 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2300 return($result);
2304 * Prepares the displayable content of a data cell in Browse mode,
2305 * taking into account foreign key description field and transformations
2307 * @uses is_array()
2308 * @uses PMA_backquote()
2309 * @uses PMA_DBI_try_query()
2310 * @uses PMA_DBI_num_rows()
2311 * @uses PMA_DBI_fetch_row()
2312 * @uses __('Link not found')
2313 * @uses PMA_DBI_free_result()
2314 * @uses $GLOBALS['printview']
2315 * @uses htmlspecialchars()
2316 * @uses PMA_generate_common_url()
2317 * @param string $mouse_events
2318 * @param string $class
2319 * @param string $condition_field
2320 * @param string $analyzed_sql
2321 * @param object $meta the meta-information about this field
2322 * @param string $map
2323 * @param string $data
2324 * @param string $transform_function
2325 * @param string $default_function
2326 * @param string $nowrap
2327 * @param string $where_comparison
2328 * @return string formatted data
2330 function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options) {
2332 // continue the <td> tag started before calling this function:
2333 $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . '">';
2335 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2336 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2337 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2338 if (isset($alias) && strlen($alias)) {
2339 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2340 if ($alias == $meta->name) {
2341 // this change in the parameter does not matter
2342 // outside of the function
2343 $meta->name = $true_column;
2344 } // end if
2345 } // end if
2346 } // end foreach
2347 } // end if
2349 if (isset($map[$meta->name])) {
2350 // Field to display from the foreign table?
2351 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2352 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2353 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2354 . '.' . PMA_backquote($map[$meta->name][0])
2355 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2356 . $where_comparison;
2357 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2358 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2359 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2360 } else {
2361 $dispval = __('Link not found');
2363 @PMA_DBI_free_result($dispresult);
2364 } else {
2365 $dispval = '';
2366 } // end if... else...
2368 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2369 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2370 } else {
2372 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2373 // user chose "relational key" in the display options, so
2374 // the title contains the display field
2375 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2376 } else {
2377 $title = ' title="' . htmlspecialchars($data) . '"';
2380 $_url_params = array(
2381 'db' => $map[$meta->name][3],
2382 'table' => $map[$meta->name][0],
2383 'pos' => '0',
2384 'sql_query' => 'SELECT * FROM '
2385 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2386 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2387 . $where_comparison,
2389 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2390 . '"' . $title . '>';
2392 if ($transform_function != $default_function) {
2393 // always apply a transformation on the real data,
2394 // not on the display field
2395 $result .= $transform_function($data, $transform_options, $meta);
2396 } else {
2397 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2398 // user chose "relational display field" in the
2399 // display options, so show display field in the cell
2400 $result .= $transform_function($dispval, array(), $meta);
2401 } else {
2402 // otherwise display data in the cell
2403 $result .= $transform_function($data, array(), $meta);
2406 $result .= '</a>';
2408 } else {
2409 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2411 $result .= '</td>' . "\n";
2413 return $result;