Translation update done using Pootle.
[phpmyadmin-themes.git] / libraries / display_tbl.lib.php
blobed6b488a7ee28f25c1722fb62378673ff899451b
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 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/Index.class.php';
14 /**
15 * Defines the display mode to use for the results of a SQL query
17 * It uses a synthetic string that contains all the required informations.
18 * In this string:
19 * - the first two characters stand for the action to do while
20 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
21 * edit link...);
22 * - the next two characters stand for the action to do while
23 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
24 * no delete link...);
25 * - the next characters are boolean values (1/0) and respectively stand
26 * for sorting links, navigation bar, "insert a new row" link, the
27 * bookmark feature, the expand/collapse text/blob fields button and
28 * the "display printable view" option.
29 * Of course '0'/'1' means the feature won't/will be enabled.
31 * @param string the synthetic value for display_mode (see a few
32 * lines above for explanations)
33 * @param integer the total number of rows returned by the SQL query
34 * without any programmatically appended "LIMIT" clause
35 * (just a copy of $unlim_num_rows if it exists, else
36 * computed inside this function)
38 * @return array an array with explicit indexes for all the display
39 * elements
41 * @global string the database name
42 * @global string the table name
43 * @global integer the total number of rows returned by the SQL query
44 * without any programmatically appended "LIMIT" clause
45 * @global array the properties of the fields returned by the query
46 * @global string the URL to return to in case of error in a SQL
47 * statement
49 * @access private
51 * @see PMA_displayTable()
53 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
55 global $db, $table;
56 global $unlim_num_rows, $fields_meta;
57 global $err_url;
59 // 1. Initializes the $do_display array
60 $do_display = array();
61 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
62 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
63 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
64 $do_display['nav_bar'] = (string) $the_disp_mode[5];
65 $do_display['ins_row'] = (string) $the_disp_mode[6];
66 $do_display['bkm_form'] = (string) $the_disp_mode[7];
67 $do_display['text_btn'] = (string) $the_disp_mode[8];
68 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
70 // 2. Display mode is not "false for all elements" -> updates the
71 // display mode
72 if ($the_disp_mode != 'nnnn000000') {
73 // 2.0 Print view -> set all elements to false!
74 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
75 $do_display['edit_lnk'] = 'nn'; // no edit link
76 $do_display['del_lnk'] = 'nn'; // no delete link
77 $do_display['sort_lnk'] = (string) '0';
78 $do_display['nav_bar'] = (string) '0';
79 $do_display['ins_row'] = (string) '0';
80 $do_display['bkm_form'] = (string) '0';
81 $do_display['text_btn'] = (string) '0';
82 $do_display['pview_lnk'] = (string) '0';
84 // 2.1 Statement is a "SELECT COUNT", a
85 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
86 // contains a "PROC ANALYSE" part
87 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
88 $do_display['edit_lnk'] = 'nn'; // no edit link
89 $do_display['del_lnk'] = 'nn'; // no delete link
90 $do_display['sort_lnk'] = (string) '0';
91 $do_display['nav_bar'] = (string) '0';
92 $do_display['ins_row'] = (string) '0';
93 $do_display['bkm_form'] = (string) '1';
94 if ($GLOBALS['is_maint']) {
95 $do_display['text_btn'] = (string) '1';
96 } else {
97 $do_display['text_btn'] = (string) '0';
99 $do_display['pview_lnk'] = (string) '1';
101 // 2.2 Statement is a "SHOW..."
102 elseif ($GLOBALS['is_show']) {
104 * 2.2.1
105 * @todo defines edit/delete links depending on show statement
107 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
108 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
109 $do_display['edit_lnk'] = 'nn'; // no edit link
110 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
111 } else {
112 // Default case -> no links
113 $do_display['edit_lnk'] = 'nn'; // no edit link
114 $do_display['del_lnk'] = 'nn'; // no delete link
116 // 2.2.2 Other settings
117 $do_display['sort_lnk'] = (string) '0';
118 $do_display['nav_bar'] = (string) '0';
119 $do_display['ins_row'] = (string) '0';
120 $do_display['bkm_form'] = (string) '1';
121 $do_display['text_btn'] = (string) '1';
122 $do_display['pview_lnk'] = (string) '1';
124 // 2.3 Other statements (ie "SELECT" ones) -> updates
125 // $do_display['edit_lnk'], $do_display['del_lnk'] and
126 // $do_display['text_btn'] (keeps other default values)
127 else {
128 $prev_table = $fields_meta[0]->table;
129 $do_display['text_btn'] = (string) '1';
130 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
131 $is_link = ($do_display['edit_lnk'] != 'nn'
132 || $do_display['del_lnk'] != 'nn'
133 || $do_display['sort_lnk'] != '0'
134 || $do_display['ins_row'] != '0');
135 // 2.3.2 Displays edit/delete/sort/insert links?
136 if ($is_link
137 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
138 $do_display['edit_lnk'] = 'nn'; // don't display links
139 $do_display['del_lnk'] = 'nn';
141 * @todo May be problematic with same fields names in two joined table.
143 // $do_display['sort_lnk'] = (string) '0';
144 $do_display['ins_row'] = (string) '0';
145 if ($do_display['text_btn'] == '1') {
146 break;
148 } // end if (2.3.2)
149 // 2.3.3 Always display print view link
150 $do_display['pview_lnk'] = (string) '1';
151 $prev_table = $fields_meta[$i]->table;
152 } // end for
153 } // end if..elseif...else (2.1 -> 2.3)
154 } // end if (2)
156 // 3. Gets the total number of rows if it is unknown
157 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
158 $the_total = $unlim_num_rows;
159 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
160 && (strlen($db) && !empty($table))) {
161 $the_total = PMA_Table::countRecords($db, $table);
164 // 4. If navigation bar or sorting fields names URLs should be
165 // displayed but there is only one row, change these settings to
166 // false
167 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
169 // - Do not display sort links if less than 2 rows.
170 // - For a VIEW we (probably) did not count the number of rows
171 // so don't test this number here, it would remove the possibility
172 // of sorting VIEW results.
173 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
174 // force display of navbar for vertical/horizontal display-choice.
175 // $do_display['nav_bar'] = (string) '0';
176 $do_display['sort_lnk'] = (string) '0';
178 } // end if (3)
180 // 5. Updates the synthetic var
181 $the_disp_mode = join('', $do_display);
183 return $do_display;
184 } // end of the 'PMA_setDisplayMode()' function
188 * Displays a navigation button
190 * @uses $GLOBALS['cfg']['NavigationBarIconic']
191 * @uses PMA_generate_common_hidden_inputs()
193 * @param string iconic caption for button
194 * @param string text for button
195 * @param integer position for next query
196 * @param string query ready for display
197 * @param string optional onsubmit clause
198 * @param string optional hidden field for special treatment
199 * @param string optional onclick clause
201 * @global string $db the database name
202 * @global string $table the table name
203 * @global string $goto the URL to go back in case of errors
205 * @access private
207 * @see PMA_displayTableNavigation()
209 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '') {
211 global $db, $table, $goto;
213 $caption_output = '';
214 // for true or 'both'
215 if ($GLOBALS['cfg']['NavigationBarIconic']) {
216 $caption_output .= $caption;
218 // for false or 'both'
219 if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
220 $caption_output .= '&nbsp;' . $title;
222 $title_output = ' title="' . $title . '"';
224 <td>
225 <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
226 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
227 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
228 <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
229 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
230 <?php echo $input_for_real_end; ?>
231 <input type="submit" name="navig" value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
232 </form>
233 </td>
234 <?php
235 } // end function PMA_displayTableNavigationOneButton()
238 * Displays a navigation bar to browse among the results of a SQL query
240 * @uses $_SESSION['tmp_user_values']['disp_direction']
241 * @uses $_SESSION['tmp_user_values']['repeat_cells']
242 * @uses $_SESSION['tmp_user_values']['max_rows']
243 * @uses $_SESSION['tmp_user_values']['pos']
244 * @param integer the offset for the "next" page
245 * @param integer the offset for the "previous" page
246 * @param string the URL-encoded query
247 * @param string the id for the direction dropdown
249 * @global string $db the database name
250 * @global string $table the table name
251 * @global string $goto the URL to go back in case of errors
252 * @global integer $num_rows the total number of rows returned by the
253 * SQL query
254 * @global integer $unlim_num_rows the total number of rows returned by the
255 * SQL any programmatically appended "LIMIT" clause
256 * @global boolean $is_innodb whether its InnoDB or not
257 * @global array $showtable table definitions
259 * @access private
261 * @see PMA_displayTable()
263 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
265 global $db, $table, $goto;
266 global $num_rows, $unlim_num_rows;
267 global $is_innodb;
268 global $showtable;
270 // here, using htmlentities() would cause problems if the query
271 // contains accented characters
272 $html_sql_query = htmlspecialchars($sql_query);
275 * @todo move this to a central place
276 * @todo for other future table types
278 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
282 <!-- Navigation bar -->
283 <table border="0" cellpadding="2" cellspacing="0">
284 <tr>
285 <?php
286 // Move to the beginning or to the previous page
287 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
288 PMA_displayTableNavigationOneButton('&lt;&lt;', __('Begin'), 0, $html_sql_query);
289 PMA_displayTableNavigationOneButton('&lt;', __('Previous'), $pos_prev, $html_sql_query);
291 } // end move back
293 <td>
294 &nbsp;&nbsp;&nbsp;
295 </td>
296 <td align="center">
297 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
298 // of $cfg['MaxExactCountViews']; in this case, avoid passing
299 // the 5th parameter to checkFormElementInRange()
300 // (this means we can't validate the upper limit ?>
301 <form action="sql.php" method="post"
302 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) &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 : ''; ?>))">
303 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
304 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
305 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
306 <input type="submit" name="navig" value="<?php echo __('Show'); ?> :" />
307 <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
308 <?php echo __('row(s) starting from row #') . "\n"; ?>
309 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
310 <br />
311 <?php
312 // Display mode (horizontal/vertical and repeat headers)
313 $choices = array(
314 'horizontal' => __('horizontal'),
315 'horizontalflipped' => __('horizontal (rotated headers)'),
316 'vertical' => __('vertical'));
317 $param1 = PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
318 unset($choices);
320 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />' . "\n"
321 . ' ';
322 echo ' ' . sprintf(__('in %s mode and repeat headers after %s cells'), "\n" . $param1, "\n" . $param2) . "\n";
324 </form>
325 </td>
326 <td>
327 &nbsp;&nbsp;&nbsp;
328 </td>
329 <?php
330 // Move to the next page or to the last one
331 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
332 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
334 // display the Next button
335 PMA_displayTableNavigationOneButton('&gt;',
336 __('Next'),
337 $pos_next,
338 $html_sql_query);
340 // prepare some options for the End button
341 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
342 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
343 // no backquote around this message
344 $onclick = '';
345 } else {
346 $input_for_real_end = $onclick = '';
349 // display the End button
350 PMA_displayTableNavigationOneButton('&gt;&gt;',
351 __('End'),
352 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
353 $html_sql_query,
354 'onsubmit="return ' . (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false') . '"',
355 $input_for_real_end,
356 $onclick
358 } // end move toward
361 //page redirection
362 // (unless we are showing all records)
363 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
364 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
365 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
367 if ($nbTotalPage > 1){ //if2
369 <td>
370 &nbsp;&nbsp;&nbsp;
371 </td>
372 <td>
373 <?php //<form> for keep the form alignment of button < and << ?>
374 <form action="none">
375 <?php
376 $_url_params = array(
377 'db' => $db,
378 'table' => $table,
379 'sql_query' => $sql_query,
380 'goto' => $goto,
382 echo PMA_pageselector(
383 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
384 $_SESSION['tmp_user_values']['max_rows'],
385 $pageNow,
386 $nbTotalPage,
387 200,
392 __('Page number:')
395 </form>
396 </td>
397 <?php
398 } //_if2
399 } //_if1
401 // Display the "Show all" button if allowed
402 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
403 echo "\n";
405 <td>
406 &nbsp;&nbsp;&nbsp;
407 </td>
408 <td>
409 <form action="sql.php" method="post">
410 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
411 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
412 <input type="hidden" name="pos" value="0" />
413 <input type="hidden" name="session_max_rows" value="all" />
414 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
415 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
416 </form>
417 </td>
418 <?php
419 } // end show all
420 echo "\n";
422 </tr>
423 </table>
425 <?php
426 } // end of the 'PMA_displayTableNavigation()' function
430 * Displays the headers of the results table
432 * @uses $_SESSION['tmp_user_values']['disp_direction']
433 * @uses $_SESSION['tmp_user_values']['repeat_cells']
434 * @uses $_SESSION['tmp_user_values']['max_rows']
435 * @uses $_SESSION['tmp_user_values']['display_text']
436 * @uses $_SESSION['tmp_user_values']['display_binary']
437 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
438 * @param array which elements to display
439 * @param array the list of fields properties
440 * @param integer the total number of fields returned by the SQL query
441 * @param array the analyzed query
443 * @return boolean $clause_is_unique
445 * @global string $db the database name
446 * @global string $table the table name
447 * @global string $goto the URL to go back in case of errors
448 * @global string $sql_query the SQL query
449 * @global integer $num_rows the total number of rows returned by the
450 * SQL query
451 * @global array $vertical_display informations used with vertical display
452 * mode
454 * @access private
456 * @see PMA_displayTable()
458 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
460 global $db, $table, $goto;
461 global $sql_query, $num_rows;
462 global $vertical_display, $highlight_columns;
464 if ($analyzed_sql == '') {
465 $analyzed_sql = array();
468 // can the result be sorted?
469 if ($is_display['sort_lnk'] == '1') {
471 // Just as fallback
472 $unsorted_sql_query = $sql_query;
473 if (isset($analyzed_sql[0]['unsorted_query'])) {
474 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
476 // Handles the case of multiple clicks on a column's header
477 // which would add many spaces before "ORDER BY" in the
478 // generated query.
479 $unsorted_sql_query = trim($unsorted_sql_query);
481 // sorting by indexes, only if it makes sense (only one table ref)
482 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
483 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
484 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
486 // grab indexes data:
487 $indexes = PMA_Index::getFromTable($table, $db);
489 // do we have any index?
490 if ($indexes) {
492 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
493 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
494 $span = $fields_cnt;
495 if ($is_display['edit_lnk'] != 'nn') {
496 $span++;
498 if ($is_display['del_lnk'] != 'nn') {
499 $span++;
501 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
502 $span++;
504 } else {
505 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
508 echo '<form action="sql.php" method="post">' . "\n";
509 echo PMA_generate_common_hidden_inputs($db, $table);
510 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
511 $used_index = false;
512 $local_order = (isset($sort_expression) ? $sort_expression : '');
513 foreach ($indexes as $index) {
514 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
515 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
516 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
517 echo '<option value="'
518 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
519 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
520 . '>' . htmlspecialchars($index->getName()) . ' ('
521 . __('Ascending') . ')</option>';
522 echo '<option value="'
523 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
524 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
525 . '>' . htmlspecialchars($index->getName()) . ' ('
526 . __('Descending') . ')</option>';
528 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
529 echo '</select>' . "\n";
530 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
531 echo '</form>' . "\n";
537 $vertical_display['emptypre'] = 0;
538 $vertical_display['emptyafter'] = 0;
539 $vertical_display['textbtn'] = '';
541 // Display options (if we are not in print view)
542 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
543 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
544 $url_params = array(
545 'db' => $db,
546 'table' => $table,
547 'sql_query' => $sql_query,
548 'goto' => $goto,
549 'display_options_form' => 1
551 echo PMA_generate_common_hidden_inputs($url_params);
552 echo '<br />';
553 PMA_generate_slider_effect('displayoptions',__('Options'));
554 echo '<fieldset>';
556 echo '<div class="formelement">';
557 $choices = array(
558 'P' => __('Partial texts'),
559 'F' => __('Full texts')
561 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
562 echo '</div>';
564 // prepare full/partial text button or link
565 if ($_SESSION['tmp_user_values']['display_text']=='F') {
566 // currently in fulltext mode so show the opposite link
567 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
568 $tmp_txt = __('Partial texts');
569 $url_params['display_text'] = 'P';
570 } else {
571 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
572 $tmp_txt = __('Full texts');
573 $url_params['display_text'] = 'F';
576 $tmp_image = '<img class="fulltext" width="50" height="20" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
577 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
578 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
579 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
582 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
583 echo '<div class="formelement">';
584 $choices = array(
585 'K' => __('Relational key'),
586 'D' => __('Relational display column')
588 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
589 echo '</div>';
592 echo '<div class="formelement">';
593 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
594 echo '<br />';
595 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
596 echo '<br />';
597 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
598 echo '</div>';
600 // I would have preferred to name this "display_transformation".
601 // This is the only way I found to be able to keep this setting sticky
602 // per SQL query, and at the same time have a default that displays
603 // the transformations.
604 echo '<div class="formelement">';
605 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
606 echo '</div>';
608 echo '<div class="clearfloat"></div>';
609 echo '</fieldset>';
611 echo '<fieldset class="tblFooters">';
612 echo '<input type="submit" value="' . __('Go') . '" />';
613 echo '</fieldset>';
614 echo '</div>';
615 echo '</form>';
618 // Start of form for multi-rows edit/delete/export
620 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
621 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
622 echo PMA_generate_common_hidden_inputs($db, $table, 1);
623 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
626 echo '<table id="table_results" class="data">' . "\n";
627 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
628 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
629 echo '<thead><tr>' . "\n";
632 // 1. Displays the full/partial text button (part 1)...
633 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
634 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
635 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
636 ? ' colspan="3"'
637 : '';
638 } else {
639 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
640 ? ' rowspan="3"'
641 : '';
644 // ... before the result table
645 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
646 && $is_display['text_btn'] == '1') {
647 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
648 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
649 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
651 <th colspan="<?php echo $fields_cnt; ?>"></th>
652 </tr>
653 <tr>
654 <?php
655 } // end horizontal/horizontalflipped mode
656 else {
658 <tr>
659 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
660 </tr>
661 <?php
662 } // end vertical mode
665 // ... at the left column of the result table header if possible
666 // and required
667 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
668 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
669 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
670 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
672 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
673 <?php
674 } // end horizontal/horizontalflipped mode
675 else {
676 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
677 . ' ' . "\n"
678 . ' </th>' . "\n";
679 } // end vertical mode
682 // ... elseif no button, displays empty(ies) col(s) if required
683 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
684 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
685 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
686 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
687 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
689 <td<?php echo $colspan; ?>></td>
690 <?php
691 } // end horizontal/horizontalfipped mode
692 else {
693 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
694 } // end vertical mode
697 // 2. Displays the fields' name
698 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
699 // statement (see 2.1.3)
701 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
702 // Do not show comments, if using horizontalflipped mode, because of space usage
703 if ($GLOBALS['cfg']['ShowBrowseComments']
704 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
705 $comments_map = array();
706 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
707 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
708 $tb = $tbl['table_true_name'];
709 $comments_map[$tb] = PMA_getComments($db, $tb);
710 unset($tb);
715 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
716 require_once './libraries/transformations.lib.php';
717 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
720 // See if we have to highlight any header fields of a WHERE query.
721 // Uses SQL-Parser results.
722 $highlight_columns = array();
723 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
724 isset($analyzed_sql[0]['where_clause_identifiers'])) {
726 $wi = 0;
727 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
728 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
729 $highlight_columns[$wci] = 'true';
734 for ($i = 0; $i < $fields_cnt; $i++) {
735 // See if this column should get highlight because it's used in the
736 // where-query.
737 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
738 $condition_field = true;
739 } else {
740 $condition_field = false;
743 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
744 if (isset($comments_map) &&
745 isset($comments_map[$fields_meta[$i]->table]) &&
746 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
747 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
748 } else {
749 $comments = '';
752 // 2.1 Results can be sorted
753 if ($is_display['sort_lnk'] == '1') {
755 // 2.1.1 Checks if the table name is required; it's the case
756 // for a query with a "JOIN" statement and if the column
757 // isn't aliased, or in queries like
758 // SELECT `1`.`master_field` , `2`.`master_field`
759 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
761 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
762 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
763 } else {
764 $sort_tbl = '';
767 // 2.1.2 Checks if the current column is used to sort the
768 // results
769 // the orgname member does not exist for all MySQL versions
770 // but if found, it's the one on which to sort
771 $name_to_use_in_sort = $fields_meta[$i]->name;
772 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
773 $name_to_use_in_sort = $fields_meta[$i]->orgname;
775 // $name_to_use_in_sort might contain a space due to
776 // formatting of function expressions like "COUNT(name )"
777 // so we remove the space in this situation
778 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
780 if (empty($sort_expression)) {
781 $is_in_sort = false;
782 } else {
783 // Field name may be preceded by a space, or any number
784 // of characters followed by a dot (tablename.fieldname)
785 // so do a direct comparison for the sort expression;
786 // this avoids problems with queries like
787 // "SELECT id, count(id)..." and clicking to sort
788 // on id or on count(id).
789 // Another query to test this:
790 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
791 // (and try clicking on each column's header twice)
792 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
793 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
795 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
797 // 2.1.3 Check the field name for a bracket.
798 // If it contains one, it's probably a function column
799 // like 'COUNT(`field`)'
800 if (strpos($name_to_use_in_sort, '(') !== false) {
801 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
802 } else {
803 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
805 unset($name_to_use_in_sort);
807 // 2.1.4 Do define the sorting URL
808 if (! $is_in_sort) {
809 // patch #455484 ("Smart" order)
810 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
811 if ($GLOBALS['cfg']['Order'] === 'SMART') {
812 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
813 } else {
814 $sort_order .= $GLOBALS['cfg']['Order'];
816 $order_img = '';
817 } elseif ('DESC' == $sort_direction) {
818 $sort_order .= ' ASC';
819 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
820 } else {
821 $sort_order .= ' DESC';
822 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
825 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
826 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
827 } else {
828 $sorted_sql_query = $unsorted_sql_query . $sort_order;
830 $_url_params = array(
831 'db' => $db,
832 'table' => $table,
833 'sql_query' => $sorted_sql_query,
835 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
837 // 2.1.5 Displays the sorting URL
838 // enable sort order swapping for image
839 $order_link_params = array();
840 if (isset($order_img) && $order_img!='') {
841 if (strstr($order_img, 'asc')) {
842 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
843 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
844 } elseif (strstr($order_img, 'desc')) {
845 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
846 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
849 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
850 if (PMA_USR_BROWSER_AGENT == 'IE') {
851 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
852 } else {
853 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
856 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
857 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
858 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
860 $order_link_params['title'] = __('Sort');
861 $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));
862 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
864 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
865 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
866 echo '<th';
867 $th_class = array();
868 if ($condition_field) {
869 $th_class[] = 'condition';
871 $th_class[] = 'column_heading';
872 echo ' class="' . implode(' ', $th_class) . '"';
874 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
875 echo ' valign="bottom"';
877 echo '>' . $order_link . $comments . '</th>';
879 $vertical_display['desc'][] = ' <th '
880 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
881 . $order_link . $comments . ' </th>' . "\n";
882 } // end if (2.1)
884 // 2.2 Results can't be sorted
885 else {
886 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
887 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
888 echo '<th';
889 if ($condition_field) {
890 echo ' class="condition"';
892 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
893 echo ' valign="bottom"';
895 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
896 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
897 echo ' style="direction: ltr; writing-mode: tb-rl;"';
899 echo '>';
900 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
901 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
902 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
903 } else {
904 echo htmlspecialchars($fields_meta[$i]->name);
906 echo "\n" . $comments . '</th>';
908 $vertical_display['desc'][] = ' <th '
909 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
910 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
911 . $comments . ' </th>';
912 } // end else (2.2)
913 } // end for
915 // 3. Displays the needed checkboxes at the right
916 // column of the result table header if possible and required...
917 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
918 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
919 && $is_display['text_btn'] == '1') {
920 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
921 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
922 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
923 echo "\n";
925 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
926 </th>
927 <?php
928 } // end horizontal/horizontalflipped mode
929 else {
930 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
931 . ' ' . "\n"
932 . ' </th>' . "\n";
933 } // end vertical mode
936 // ... elseif no button, displays empty columns if required
937 // (unless coming from Browse mode print view)
938 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
939 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
940 && (!$GLOBALS['is_header_sent'])) {
941 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
942 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
943 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
944 echo "\n";
946 <td<?php echo $colspan; ?>></td>
947 <?php
948 } // end horizontal/horizontalflipped mode
949 else {
950 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
951 } // end vertical mode
954 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
955 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
957 </tr>
958 </thead>
959 <?php
962 return true;
963 } // end of the 'PMA_displayTableHeaders()' function
967 * Prepares the display for a value
969 * @param string $class
970 * @param string $condition_field
971 * @param string $value
973 * @return string the td
975 function PMA_buildValueDisplay($class, $condition_field, $value) {
976 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
980 * Prepares the display for a null value
982 * @param string $class
983 * @param string $condition_field
985 * @return string the td
987 function PMA_buildNullDisplay($class, $condition_field) {
988 // the null class is needed for inline editing
989 return '<td align="right"' . ' class="' . $class . ($condition_field ? ' condition' : '') . ' null"><i>NULL</i></td>';
993 * Prepares the display for an empty value
995 * @param string $class
996 * @param string $condition_field
997 * @param string $align
999 * @return string the td
1001 function PMA_buildEmptyDisplay($class, $condition_field, $align = '') {
1002 return '<td ' . $align . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>';
1006 * Displays the body of the results table
1008 * @uses $_SESSION['tmp_user_values']['disp_direction']
1009 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1010 * @uses $_SESSION['tmp_user_values']['max_rows']
1011 * @uses $_SESSION['tmp_user_values']['display_text']
1012 * @uses $_SESSION['tmp_user_values']['display_binary']
1013 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1014 * @uses $_SESSION['tmp_user_values']['display_blob']
1015 * @param integer the link id associated to the query which results have
1016 * to be displayed
1017 * @param array which elements to display
1018 * @param array the list of relations
1019 * @param array the analyzed query
1021 * @return boolean always true
1023 * @global string $db the database name
1024 * @global string $table the table name
1025 * @global string $goto the URL to go back in case of errors
1026 * @global string $sql_query the SQL query
1027 * @global array $fields_meta the list of fields properties
1028 * @global integer $fields_cnt the total number of fields returned by
1029 * the SQL query
1030 * @global array $vertical_display informations used with vertical display
1031 * mode
1032 * @global array $highlight_columns column names to highlight
1033 * @global array $row current row data
1035 * @access private
1037 * @see PMA_displayTable()
1039 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1040 global $db, $table, $goto;
1041 global $sql_query, $fields_meta, $fields_cnt;
1042 global $vertical_display, $highlight_columns;
1043 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1045 $url_sql_query = $sql_query;
1047 // query without conditions to shorten URLs when needed, 200 is just
1048 // guess, it should depend on remaining URL length
1050 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1051 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1052 strlen($sql_query) > 200) {
1054 $url_sql_query = 'SELECT ';
1055 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1056 $url_sql_query .= ' DISTINCT ';
1058 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1059 if (!empty($analyzed_sql[0]['from_clause'])) {
1060 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1064 if (!is_array($map)) {
1065 $map = array();
1067 $row_no = 0;
1068 $vertical_display['edit'] = array();
1069 $vertical_display['delete'] = array();
1070 $vertical_display['data'] = array();
1071 $vertical_display['row_delete'] = array();
1072 // name of the class added to all inline editable elements
1073 $data_inline_edit_class = 'data_inline_edit';
1075 // Correction University of Virginia 19991216 in the while below
1076 // Previous code assumed that all tables have keys, specifically that
1077 // the phpMyAdmin GUI should support row delete/edit only for such
1078 // tables.
1079 // Although always using keys is arguably the prescribed way of
1080 // defining a relational table, it is not required. This will in
1081 // particular be violated by the novice.
1082 // We want to encourage phpMyAdmin usage by such novices. So the code
1083 // below has been changed to conditionally work as before when the
1084 // table being displayed has one or more keys; but to display
1085 // delete/edit options correctly for tables without keys.
1087 $odd_row = true;
1088 while ($row = PMA_DBI_fetch_row($dt_result)) {
1089 // "vertical display" mode stuff
1090 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1091 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1092 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1094 echo '<tr>' . "\n";
1095 if ($vertical_display['emptypre'] > 0) {
1096 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1097 .' &nbsp;</th>' . "\n";
1100 foreach ($vertical_display['desc'] as $val) {
1101 echo $val;
1104 if ($vertical_display['emptyafter'] > 0) {
1105 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1106 .' &nbsp;</th>' . "\n";
1108 echo '</tr>' . "\n";
1109 } // end if
1111 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1112 $odd_row = ! $odd_row;
1114 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1115 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1116 // pointer code part
1117 echo '<tr class="' . $alternating_color_class . '">';
1121 // 1. Prepares the row
1122 // 1.1 Results from a "SELECT" statement -> builds the
1123 // WHERE clause to use in links (a unique key if possible)
1125 * @todo $where_clause could be empty, for example a table
1126 * with only one field and it's a BLOB; in this case,
1127 * avoid to display the delete and edit links
1129 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1130 $where_clause_html = urlencode($where_clause);
1132 // 1.2 Defines the URLs for the modify/delete link(s)
1134 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1135 // We need to copy the value or else the == 'both' check will always return true
1137 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1138 $iconic_spacer = '<div class="nowrap">';
1139 } else {
1140 $iconic_spacer = '';
1143 // 1.2.1 Modify link(s)
1144 if ($is_display['edit_lnk'] == 'ur') { // update row case
1145 $_url_params = array(
1146 'db' => $db,
1147 'table' => $table,
1148 'where_clause' => $where_clause,
1149 'clause_is_unique' => $clause_is_unique,
1150 'sql_query' => $url_sql_query,
1151 'goto' => 'sql.php',
1153 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
1155 $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
1157 // Class definitions required for inline editing jQuery scripts
1158 $edit_anchor_class = "edit_row_anchor";
1159 if( $clause_is_unique == 0) {
1160 $edit_anchor_class .= ' nonunique';
1162 } // end if (1.2.1)
1164 // 1.2.2 Delete/Kill link(s)
1165 if ($is_display['del_lnk'] == 'dr') { // delete row case
1166 $_url_params = array(
1167 'db' => $db,
1168 'table' => $table,
1169 'sql_query' => $url_sql_query,
1170 'message_to_show' => __('The row has been deleted'),
1171 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1173 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1175 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1176 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1178 $_url_params = array(
1179 'db' => $db,
1180 'table' => $table,
1181 'sql_query' => $del_query,
1182 'message_to_show' => __('The row has been deleted'),
1183 'goto' => $lnk_goto,
1185 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1187 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1188 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1189 . ($clause_is_unique ? '' : ' LIMIT 1');
1190 $del_str = PMA_getIcon('b_drop.png', __('Delete'), true);
1191 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1193 $_url_params = array(
1194 'db' => $db,
1195 'table' => $table,
1196 'sql_query' => $url_sql_query,
1197 'goto' => 'main.php',
1199 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1201 $_url_params = array(
1202 'db' => 'mysql',
1203 'sql_query' => 'KILL ' . $row[0],
1204 'goto' => $lnk_goto,
1206 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1207 $del_query = 'KILL ' . $row[0];
1208 $js_conf = 'KILL ' . $row[0];
1209 $del_str = PMA_getIcon('b_drop.png', __('Kill'), true);
1210 } // end if (1.2.2)
1212 // 1.3 Displays the links at left if required
1213 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1214 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1215 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1216 if (! isset($js_conf)) {
1217 $js_conf = '';
1219 echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $edit_anchor_class, $edit_str, $del_str, $js_conf);
1220 } // end if (1.3)
1221 } // end if (1)
1223 // 2. Displays the rows' values
1224 for ($i = 0; $i < $fields_cnt; ++$i) {
1225 $meta = $fields_meta[$i];
1226 $pointer = $i;
1227 $is_field_truncated = false;
1228 //If the previous column had blob data, we need to reset the class
1229 // to $data_inline_edit_class
1230 $class = $data_inline_edit_class . ' ' . $alternating_color_class;
1232 // See if this column should get highlight because it's used in the
1233 // where-query.
1234 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1235 $condition_field = true;
1236 } else {
1237 $condition_field = false;
1240 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1241 // the row number corresponds to a data row, not HTML table row
1242 $class .= ' row_' . $row_no;
1243 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1244 $class .= ' vpointer';
1246 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1247 $class .= ' vmarker';
1249 }// end if
1251 // Wrap MIME-transformations. [MIME]
1252 $default_function = 'default_function'; // default_function
1253 $transform_function = $default_function;
1254 $transform_options = array();
1256 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1258 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1259 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1261 if (file_exists('./libraries/transformations/' . $include_file)) {
1262 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1264 require_once './libraries/transformations/' . $include_file;
1266 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1267 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1268 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1269 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1271 } // end if file_exists
1272 } // end if transformation is set
1273 } // end if mime/transformation works.
1275 $_url_params = array(
1276 'db' => $db,
1277 'table' => $table,
1278 'where_clause' => $where_clause,
1279 'transform_key' => $meta->name,
1282 if (! empty($sql_query)) {
1283 $_url_params['sql_query'] = $url_sql_query;
1286 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1288 // n u m e r i c
1289 if ($meta->numeric == 1) {
1291 // if two fields have the same name (this is possible
1292 // with self-join queries, for example), using $meta->name
1293 // will show both fields NULL even if only one is NULL,
1294 // so use the $pointer
1296 if (!isset($row[$i]) || is_null($row[$i])) {
1297 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1298 } elseif ($row[$i] != '') {
1300 $nowrap = ' nowrap';
1301 $where_comparison = ' = ' . $row[$i];
1303 $vertical_display['data'][$row_no][$i] = '<td align="right"' . PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated);
1304 } else {
1305 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, 'align="right"');
1308 // b l o b
1310 } elseif (stristr($meta->type, 'BLOB')) {
1311 // PMA_mysql_fetch_fields returns BLOB in place of
1312 // TEXT fields type so we have to ensure it's really a BLOB
1313 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1315 // reset $class from $data_inline_edit_class to '' as we can't edit binary data
1316 $class = '';
1318 if (stristr($field_flags, 'BINARY')) {
1319 if (!isset($row[$i]) || is_null($row[$i])) {
1320 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1321 } else {
1322 // for blobstreaming
1323 // if valid BS reference exists
1324 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1325 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1326 } else {
1327 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1330 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1331 unset($blobtext);
1333 // not binary:
1334 } else {
1335 if (!isset($row[$i]) || is_null($row[$i])) {
1336 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1337 } elseif ($row[$i] != '') {
1338 // if a transform function for blob is set, none of these replacements will be made
1339 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1340 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1341 $is_field_truncated = true;
1343 // displays all space characters, 4 space
1344 // characters for tabulations and <cr>/<lf>
1345 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1347 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1348 } else {
1349 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field);
1352 // g e o m e t r y
1353 } elseif ($meta->type == 'geometry') {
1354 $geometry_text = PMA_handle_non_printable_contents('GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1355 // reset $class from $data_inline_edit_class to '' as we can't edit geometry data
1356 $class = '';
1357 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $geometry_text);
1358 unset($geometry_text);
1360 // n o t n u m e r i c a n d n o t B L O B
1361 } else {
1362 if (!isset($row[$i]) || is_null($row[$i])) {
1363 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1364 } elseif ($row[$i] != '') {
1365 // support blanks in the key
1366 $relation_id = $row[$i];
1368 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1369 // (unless it's a link-type transformation)
1370 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1371 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1372 $is_field_truncated = true;
1375 // displays special characters from binaries
1376 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1377 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1378 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1379 // some results of PROCEDURE ANALYSE() are reported as
1380 // being BINARY but they are quite readable,
1381 // so don't treat them as BINARY
1382 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1383 if ($_SESSION['tmp_user_values']['display_binary']) {
1384 // user asked to see the real contents of BINARY
1385 // fields
1386 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1387 $row[$i] = bin2hex($row[$i]);
1388 } else {
1389 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1391 } else {
1392 // we show the BINARY message and field's size
1393 // (or maybe use a transformation)
1394 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1398 // transform functions may enable no-wrapping:
1399 $function_nowrap = $transform_function . '_nowrap';
1400 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1402 // do not wrap if date field type
1403 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1404 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1405 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated);
1407 } else {
1408 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field);
1412 // output stored cell
1413 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1414 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1415 echo $vertical_display['data'][$row_no][$i];
1418 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1419 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1420 } else {
1421 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1423 } // end for (2)
1425 // 3. Displays the modify/delete links on the right if required
1426 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1427 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1428 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1429 if (! isset($js_conf)) {
1430 $js_conf = '';
1432 echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $edit_anchor_class, $edit_str, $del_str, $js_conf);
1433 } // end if (3)
1435 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1436 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1438 </tr>
1439 <?php
1440 } // end if
1442 // 4. Gather links of del_urls and edit_urls in an array for later
1443 // output
1444 if (!isset($vertical_display['edit'][$row_no])) {
1445 $vertical_display['edit'][$row_no] = '';
1446 $vertical_display['delete'][$row_no] = '';
1447 $vertical_display['row_delete'][$row_no] = '';
1449 $vertical_class = ' row_' . $row_no;
1450 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1451 $vertical_class .= ' vpointer';
1453 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1454 $vertical_class .= ' vmarker';
1457 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1458 $vertical_display['row_delete'][$row_no] .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, '[%_PMA_CHECKBOX_DIR_%]', $alternating_color_class . $vertical_class);
1459 } else {
1460 unset($vertical_display['row_delete'][$row_no]);
1463 if (isset($edit_url)) {
1464 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1465 } else {
1466 unset($vertical_display['edit'][$row_no]);
1469 if (isset($del_url)) {
1470 if (! isset($js_conf)) {
1471 $js_conf = '';
1473 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1474 } else {
1475 unset($vertical_display['delete'][$row_no]);
1478 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1479 $row_no++;
1480 } // end while
1482 // this is needed by PMA_displayTable() to generate the proper param
1483 // in the multi-edit and multi-delete form
1484 return $clause_is_unique;
1485 } // end of the 'PMA_displayTableBody()' function
1489 * Do display the result table with the vertical direction mode.
1491 * @return boolean always true
1493 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1494 * @global array $vertical_display the information to display
1496 * @access private
1498 * @see PMA_displayTable()
1500 function PMA_displayVerticalTable()
1502 global $vertical_display;
1504 // Displays "multi row delete" link at top if required
1505 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1506 echo '<tr>' . "\n";
1507 echo $vertical_display['textbtn'];
1508 $foo_counter = 0;
1509 foreach ($vertical_display['row_delete'] as $val) {
1510 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1511 echo '<th></th>' . "\n";
1514 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1515 $foo_counter++;
1516 } // end while
1517 echo '</tr>' . "\n";
1518 } // end if
1520 // Displays "edit" link at top if required
1521 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1522 echo '<tr>' . "\n";
1523 if (!is_array($vertical_display['row_delete'])) {
1524 echo $vertical_display['textbtn'];
1526 $foo_counter = 0;
1527 foreach ($vertical_display['edit'] as $val) {
1528 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1529 echo ' <th></th>' . "\n";
1532 echo $val;
1533 $foo_counter++;
1534 } // end while
1535 echo '</tr>' . "\n";
1536 } // end if
1538 // Displays "delete" link at top if required
1539 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1540 echo '<tr>' . "\n";
1541 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1542 echo $vertical_display['textbtn'];
1544 $foo_counter = 0;
1545 foreach ($vertical_display['delete'] as $val) {
1546 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1547 echo '<th></th>' . "\n";
1550 echo $val;
1551 $foo_counter++;
1552 } // end while
1553 echo '</tr>' . "\n";
1554 } // end if
1556 // Displays data
1557 foreach ($vertical_display['desc'] AS $key => $val) {
1559 echo '<tr>' . "\n";
1560 echo $val;
1562 $foo_counter = 0;
1563 foreach ($vertical_display['rowdata'][$key] as $subval) {
1564 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1565 echo $val;
1568 echo $subval;
1569 $foo_counter++;
1570 } // end while
1572 echo '</tr>' . "\n";
1573 } // end while
1575 // Displays "multi row delete" link at bottom if required
1576 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1577 echo '<tr>' . "\n";
1578 echo $vertical_display['textbtn'];
1579 $foo_counter = 0;
1580 foreach ($vertical_display['row_delete'] as $val) {
1581 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1582 echo '<th></th>' . "\n";
1585 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1586 $foo_counter++;
1587 } // end while
1588 echo '</tr>' . "\n";
1589 } // end if
1591 // Displays "edit" link at bottom if required
1592 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1593 echo '<tr>' . "\n";
1594 if (!is_array($vertical_display['row_delete'])) {
1595 echo $vertical_display['textbtn'];
1597 $foo_counter = 0;
1598 foreach ($vertical_display['edit'] as $val) {
1599 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1600 echo '<th></th>' . "\n";
1603 echo $val;
1604 $foo_counter++;
1605 } // end while
1606 echo '</tr>' . "\n";
1607 } // end if
1609 // Displays "delete" link at bottom if required
1610 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1611 echo '<tr>' . "\n";
1612 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1613 echo $vertical_display['textbtn'];
1615 $foo_counter = 0;
1616 foreach ($vertical_display['delete'] as $val) {
1617 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1618 echo '<th></th>' . "\n";
1621 echo $val;
1622 $foo_counter++;
1623 } // end while
1624 echo '</tr>' . "\n";
1627 return true;
1628 } // end of the 'PMA_displayVerticalTable' function
1632 * @uses $_SESSION['tmp_user_values']['disp_direction']
1633 * @uses $_REQUEST['disp_direction']
1634 * @uses $GLOBALS['cfg']['DefaultDisplay']
1635 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1636 * @uses $_REQUEST['repeat_cells']
1637 * @uses $GLOBALS['cfg']['RepeatCells']
1638 * @uses $_SESSION['tmp_user_values']['max_rows']
1639 * @uses $_REQUEST['session_max_rows']
1640 * @uses $GLOBALS['cfg']['MaxRows']
1641 * @uses $_SESSION['tmp_user_values']['pos']
1642 * @uses $_REQUEST['pos']
1643 * @uses $_SESSION['tmp_user_values']['display_text']
1644 * @uses $_REQUEST['display_text']
1645 * @uses $_SESSION['tmp_user_values']['relational_display']
1646 * @uses $_REQUEST['relational_display']
1647 * @uses $_SESSION['tmp_user_values']['display_binary']
1648 * @uses $_REQUEST['display_binary']
1649 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1650 * @uses $_REQUEST['display_binary_as_hex']
1651 * @uses $_SESSION['tmp_user_values']['display_blob']
1652 * @uses $_REQUEST['display_blob']
1653 * @uses PMA_isValid()
1654 * @uses $GLOBALS['sql_query']
1655 * @todo make maximum remembered queries configurable
1656 * @todo move/split into SQL class!?
1657 * @todo currently this is called twice unnecessary
1658 * @todo ignore LIMIT and ORDER in query!?
1660 function PMA_displayTable_checkConfigParams()
1662 $sql_md5 = md5($GLOBALS['sql_query']);
1664 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1666 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1667 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1668 unset($_REQUEST['disp_direction']);
1669 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1670 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1673 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1674 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1675 unset($_REQUEST['repeat_cells']);
1676 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1677 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1680 // as this is a form value, the type is always string so we cannot
1681 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1682 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1683 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1684 || $_REQUEST['session_max_rows'] == 'all') {
1685 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1686 unset($_REQUEST['session_max_rows']);
1687 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1688 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1691 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1692 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1693 unset($_REQUEST['pos']);
1694 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1695 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1698 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1699 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1700 unset($_REQUEST['display_text']);
1701 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1702 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1705 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1706 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1707 unset($_REQUEST['relational_display']);
1708 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1709 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1712 if (isset($_REQUEST['display_binary'])) {
1713 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1714 unset($_REQUEST['display_binary']);
1715 } elseif (isset($_REQUEST['display_options_form'])) {
1716 // we know that the checkbox was unchecked
1717 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1718 } else {
1719 // selected by default because some operations like OPTIMIZE TABLE
1720 // and all queries involving functions return "binary" contents,
1721 // according to low-level field flags
1722 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1725 if (isset($_REQUEST['display_binary_as_hex'])) {
1726 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1727 unset($_REQUEST['display_binary_as_hex']);
1728 } elseif (isset($_REQUEST['display_options_form'])) {
1729 // we know that the checkbox was unchecked
1730 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1731 } else {
1732 // display_binary_as_hex config option
1733 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1734 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1738 if (isset($_REQUEST['display_blob'])) {
1739 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1740 unset($_REQUEST['display_blob']);
1741 } elseif (isset($_REQUEST['display_options_form'])) {
1742 // we know that the checkbox was unchecked
1743 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1746 if (isset($_REQUEST['hide_transformation'])) {
1747 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1748 unset($_REQUEST['hide_transformation']);
1749 } elseif (isset($_REQUEST['display_options_form'])) {
1750 // we know that the checkbox was unchecked
1751 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1754 // move current query to the last position, to be removed last
1755 // so only least executed query will be removed if maximum remembered queries
1756 // limit is reached
1757 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
1758 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
1759 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
1761 // do not exceed a maximum number of queries to remember
1762 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1763 array_shift($_SESSION['tmp_user_values']['query']);
1764 //echo 'deleting one element ...';
1767 // populate query configuration
1768 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
1769 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
1770 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
1771 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
1772 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
1773 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
1774 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
1775 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
1776 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
1777 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
1780 * debugging
1781 echo '<pre>';
1782 var_dump($_SESSION['tmp_user_values']);
1783 echo '</pre>';
1788 * Displays a table of results returned by a SQL query.
1789 * This function is called by the "sql.php" script.
1791 * @param integer the link id associated to the query which results have
1792 * to be displayed
1793 * @param array the display mode
1794 * @param array the analyzed query
1796 * @uses $_SESSION['tmp_user_values']['pos']
1797 * @global string $db the database name
1798 * @global string $table the table name
1799 * @global string $goto the URL to go back in case of errors
1800 * @global string $sql_query the current SQL query
1801 * @global integer $num_rows the total number of rows returned by the
1802 * SQL query
1803 * @global integer $unlim_num_rows the total number of rows returned by the
1804 * SQL query without any programmatically
1805 * appended "LIMIT" clause
1806 * @global array $fields_meta the list of fields properties
1807 * @global integer $fields_cnt the total number of fields returned by
1808 * the SQL query
1809 * @global array $vertical_display informations used with vertical display
1810 * mode
1811 * @global array $highlight_columns column names to highlight
1812 * @global array $cfgRelation the relation settings
1814 * @access private
1816 * @see PMA_showMessage(), PMA_setDisplayMode(),
1817 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1818 * PMA_displayTableBody(), PMA_displayResultsOperations()
1820 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1822 global $db, $table, $goto;
1823 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1824 global $vertical_display, $highlight_columns;
1825 global $cfgRelation;
1826 global $showtable;
1828 // why was this called here? (already called from sql.php)
1829 //PMA_displayTable_checkConfigParams();
1832 * @todo move this to a central place
1833 * @todo for other future table types
1835 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1837 if ($is_innodb
1838 && ! isset($analyzed_sql[0]['queryflags']['union'])
1839 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1840 && (empty($analyzed_sql[0]['where_clause'])
1841 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1842 // "j u s t b r o w s i n g"
1843 $pre_count = '~';
1844 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')), true);
1845 } else {
1846 $pre_count = '';
1847 $after_count = '';
1850 // 1. ----- Prepares the work -----
1852 // 1.1 Gets the informations about which functionalities should be
1853 // displayed
1854 $total = '';
1855 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1857 // 1.2 Defines offsets for the next and previous pages
1858 if ($is_display['nav_bar'] == '1') {
1859 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1860 $pos_next = 0;
1861 $pos_prev = 0;
1862 } else {
1863 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
1864 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1865 if ($pos_prev < 0) {
1866 $pos_prev = 0;
1869 } // end if
1871 // 1.3 Find the sort expression
1873 // we need $sort_expression and $sort_expression_nodirection
1874 // even if there are many table references
1875 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1876 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1878 * Get rid of ASC|DESC
1880 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1881 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1882 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1883 unset($matches);
1884 } else {
1885 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1888 // 1.4 Prepares display of first and last value of the sorted column
1890 if (! empty($sort_expression_nodirection)) {
1891 if (strpos($sort_expression_nodirection, '.') === false) {
1892 $sort_table = $table;
1893 $sort_column = $sort_expression_nodirection;
1894 } else {
1895 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1897 $sort_table = PMA_unQuote($sort_table);
1898 $sort_column = PMA_unQuote($sort_column);
1899 // find the sorted column index in row result
1900 // (this might be a multi-table query)
1901 $sorted_column_index = false;
1902 foreach($fields_meta as $key => $meta) {
1903 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1904 $sorted_column_index = $key;
1905 break;
1908 if ($sorted_column_index !== false) {
1909 // fetch first row of the result set
1910 $row = PMA_DBI_fetch_row($dt_result);
1911 $column_for_first_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1912 // fetch last row of the result set
1913 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1914 $row = PMA_DBI_fetch_row($dt_result);
1915 $column_for_last_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
1916 // reset to first row for the loop in PMA_displayTableBody()
1917 PMA_DBI_data_seek($dt_result, 0);
1918 // we could also use here $sort_expression_nodirection
1919 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1920 unset($row, $column_for_first_row, $column_for_last_row);
1922 unset($sorted_column_index, $sort_table, $sort_column);
1925 // 2. ----- Displays the top of the page -----
1927 // 2.1 Displays a messages with position informations
1928 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1929 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1930 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
1931 } else {
1932 $selectstring = '';
1934 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
1935 ? $total - 1
1936 : $pos_next - 1;
1938 if (PMA_Table::isView($db, $table)
1939 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1940 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
1941 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1942 $message->addParam('[/a]');
1943 $message_view_warning = PMA_showHint($message);
1944 } else {
1945 $message_view_warning = false;
1948 $message = PMA_Message::success(__('Showing rows'));
1949 $message->addMessage($_SESSION['tmp_user_values']['pos']);
1950 if ($message_view_warning) {
1951 $message->addMessage('...', ' - ');
1952 $message->addMessage($message_view_warning);
1953 $message->addMessage('(');
1954 } else {
1955 $message->addMessage($last_shown_rec, ' - ');
1956 $message->addMessage(' (');
1957 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
1958 $message->addString(__('total'));
1959 if (!empty($after_count)) {
1960 $message->addMessage($after_count);
1962 $message->addMessage($selectstring, '');
1963 $message->addMessage(', ', '');
1966 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
1967 $messagge_qt->addParam($GLOBALS['querytime']);
1969 $message->addMessage($messagge_qt, '');
1970 $message->addMessage(')', '');
1972 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
1974 PMA_showMessage($message, $sql_query, 'success');
1976 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1977 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
1980 // 2.3 Displays the navigation bars
1981 if (! strlen($table)) {
1982 if (isset($analyzed_sql[0]['query_type'])
1983 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1984 // table does not always contain a real table name,
1985 // for example in MySQL 5.0.x, the query SHOW STATUS
1986 // returns STATUS as a table name
1987 $table = $fields_meta[0]->table;
1988 } else {
1989 $table = '';
1993 if ($is_display['nav_bar'] == '1') {
1994 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
1995 echo "\n";
1996 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1997 echo "\n" . '<br /><br />' . "\n";
2000 // 2b ----- Get field references from Database -----
2001 // (see the 'relation' configuration variable)
2003 // initialize map
2004 $map = array();
2006 // find tables
2007 $target=array();
2008 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2009 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2010 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2013 $tabs = '(\'' . join('\',\'', $target) . '\')';
2015 if ($cfgRelation['displaywork']) {
2016 if (! strlen($table)) {
2017 $exist_rel = false;
2018 } else {
2019 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2020 if ($exist_rel) {
2021 foreach ($exist_rel AS $master_field => $rel) {
2022 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2023 $map[$master_field] = array($rel['foreign_table'],
2024 $rel['foreign_field'],
2025 $display_field,
2026 $rel['foreign_db']);
2027 } // end while
2028 } // end if
2029 } // end if
2030 } // end if
2031 // end 2b
2033 // 3. ----- Displays the results table -----
2034 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2035 $url_query = '';
2036 echo '<tbody>' . "\n";
2037 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2038 // vertical output case
2039 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2040 PMA_displayVerticalTable();
2041 } // end if
2042 unset($vertical_display);
2043 echo '</tbody>' . "\n";
2045 </table>
2047 <?php
2048 // 4. ----- Displays the link for multi-fields edit and delete
2050 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2052 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2054 $_url_params = array(
2055 'db' => $db,
2056 'table' => $table,
2057 'sql_query' => $sql_query,
2058 'goto' => $goto,
2060 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2062 $_url_params['checkall'] = '1';
2063 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2065 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2066 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2067 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2068 } else {
2069 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2070 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2072 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2073 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2074 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2075 echo '<img class="selectallarrow" width="38" height="22"'
2076 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2077 .' alt="' . __('With selected:') . '" />';
2079 echo $checkall_link . "\n"
2080 .' / ' . "\n"
2081 .$uncheckall_link . "\n"
2082 .'<i>' . __('With selected:') . '</i>' . "\n";
2084 PMA_buttonOrImage('submit_mult', 'mult_submit',
2085 'submit_mult_change', __('Change'), 'b_edit.png');
2086 PMA_buttonOrImage('submit_mult', 'mult_submit',
2087 'submit_mult_delete', $delete_text, 'b_drop.png');
2088 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2089 PMA_buttonOrImage('submit_mult', 'mult_submit',
2090 'submit_mult_export', __('Export'),
2091 'b_tblexport.png');
2093 echo "\n";
2095 echo '<input type="hidden" name="sql_query"'
2096 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2098 if (! empty($GLOBALS['url_query'])) {
2099 echo '<input type="hidden" name="url_query"'
2100 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2103 echo '<input type="hidden" name="clause_is_unique"'
2104 .' value="' . $clause_is_unique . '" />' . "\n";
2106 echo '</form>' . "\n";
2109 // 5. ----- Displays the navigation bar at the bottom if required -----
2111 if ($is_display['nav_bar'] == '1') {
2112 echo '<br />' . "\n";
2113 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2114 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2115 echo "\n" . '<br /><br />' . "\n";
2118 // 6. ----- Displays "Query results operations"
2119 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2120 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2122 } // end of the 'PMA_displayTable()' function
2124 function default_function($buffer) {
2125 $buffer = htmlspecialchars($buffer);
2126 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2127 str_replace(' ', ' &nbsp;', $buffer));
2128 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2130 return $buffer;
2134 * Displays operations that are available on results.
2136 * @param array the display mode
2137 * @param array the analyzed query
2139 * @uses $_SESSION['tmp_user_values']['pos']
2140 * @uses $_SESSION['tmp_user_values']['display_text']
2141 * @global string $db the database name
2142 * @global string $table the table name
2143 * @global string $sql_query the current SQL query
2144 * @global integer $unlim_num_rows the total number of rows returned by the
2145 * SQL query without any programmatically
2146 * appended "LIMIT" clause
2148 * @access private
2150 * @see PMA_showMessage(), PMA_setDisplayMode(),
2151 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2152 * PMA_displayTableBody(), PMA_displayResultsOperations()
2154 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2155 global $db, $table, $sql_query, $unlim_num_rows;
2157 $header_shown = FALSE;
2158 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2160 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2161 // Displays "printable view" link if required
2162 if ($the_disp_mode[9] == '1') {
2164 if (!$header_shown) {
2165 echo $header;
2166 $header_shown = TRUE;
2169 $_url_params = array(
2170 'db' => $db,
2171 'table' => $table,
2172 'printview' => '1',
2173 'sql_query' => $sql_query,
2175 $url_query = PMA_generate_common_url($_url_params);
2177 echo PMA_linkOrButton(
2178 'sql.php' . $url_query,
2179 PMA_getIcon('b_print.png', __('Print view'), false, true),
2180 '', true, true, 'print_view') . "\n";
2182 if ($_SESSION['tmp_user_values']['display_text']) {
2183 $_url_params['display_text'] = 'F';
2184 echo PMA_linkOrButton(
2185 'sql.php' . PMA_generate_common_url($_url_params),
2186 PMA_getIcon('b_print.png', __('Print view (with full texts)'), false, true),
2187 '', true, true, 'print_view') . "\n";
2188 unset($_url_params['display_text']);
2190 } // end displays "printable view"
2193 // Export link
2194 // (the url_query has extra parameters that won't be used to export)
2195 // (the single_table parameter is used in display_export.lib.php
2196 // to hide the SQL and the structure export dialogs)
2197 // If the parser found a PROCEDURE clause
2198 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2199 // display the Export link).
2200 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2201 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2202 $_url_params['single_table'] = 'true';
2204 if (!$header_shown) {
2205 echo $header;
2206 $header_shown = TRUE;
2208 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2211 * At this point we don't know the table name; this can happen
2212 * for example with a query like
2213 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2214 * As a workaround we set in the table parameter the name of the
2215 * first table of this database, so that tbl_export.php and
2216 * the script it calls do not fail
2218 if (empty($_url_params['table'])) {
2219 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2222 echo PMA_linkOrButton(
2223 'tbl_export.php' . PMA_generate_common_url($_url_params),
2224 PMA_getIcon('b_tblexport.png', __('Export'), false, true),
2225 '', true, true, '') . "\n";
2227 // show chart
2228 echo PMA_linkOrButton(
2229 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2230 PMA_getIcon('b_chart.png', __('Display chart'), false, true),
2231 '', true, true, '') . "\n";
2234 // CREATE VIEW
2237 * @todo detect privileges to create a view
2238 * (but see 2006-01-19 note in display_create_table.lib.php,
2239 * I think we cannot detect db-specific privileges reliably)
2240 * Note: we don't display a Create view link if we found a PROCEDURE clause
2242 if (!$header_shown) {
2243 echo $header;
2244 $header_shown = TRUE;
2246 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2247 echo PMA_linkOrButton(
2248 'view_create.php' . $url_query,
2249 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2250 '', true, true, '') . "\n";
2252 if ($header_shown) {
2253 echo '</fieldset><br />';
2258 * Verifies what to do with non-printable contents (binary or BLOB)
2259 * in Browse mode.
2261 * @uses is_null()
2262 * @uses isset()
2263 * @uses strlen()
2264 * @uses PMA_formatByteDown()
2265 * @uses strpos()
2266 * @uses str_replace()
2267 * @param string $category BLOB|BINARY|GEOMETRY
2268 * @param string $content the binary content
2269 * @param string $transform_function
2270 * @param string $transform_options
2271 * @param string $default_function
2272 * @param object $meta the meta-information about this field
2273 * @return mixed string or float
2275 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2276 $result = '[' . $category;
2277 if (is_null($content)) {
2278 $result .= ' - NULL';
2279 $size = 0;
2280 } elseif (isset($content)) {
2281 $size = strlen($content);
2282 $display_size = PMA_formatByteDown($size, 3, 1);
2283 $result .= ' - '. $display_size[0] . $display_size[1];
2285 $result .= ']';
2287 if (strpos($transform_function, 'octetstream')) {
2288 $result = $content;
2290 if ($size > 0) {
2291 if ($default_function != $transform_function) {
2292 $result = $transform_function($result, $transform_options, $meta);
2293 } else {
2294 $result = $default_function($result, array(), $meta);
2295 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2296 // in this case, restart from the original $content
2297 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2299 /* Create link to download */
2300 if (count($url_params) > 0) {
2301 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2305 return($result);
2309 * Prepares the displayable content of a data cell in Browse mode,
2310 * taking into account foreign key description field and transformations
2312 * @uses is_array()
2313 * @uses PMA_backquote()
2314 * @uses PMA_DBI_try_query()
2315 * @uses PMA_DBI_num_rows()
2316 * @uses PMA_DBI_fetch_row()
2317 * @uses PMA_DBI_free_result()
2318 * @uses $GLOBALS['printview']
2319 * @uses htmlspecialchars()
2320 * @uses PMA_generate_common_url()
2321 * @param string $class
2322 * @param string $condition_field
2323 * @param string $analyzed_sql
2324 * @param object $meta the meta-information about this field
2325 * @param string $map
2326 * @param string $data
2327 * @param string $transform_function
2328 * @param string $default_function
2329 * @param string $nowrap
2330 * @param string $where_comparison
2331 * @param bool $is_field_truncated
2332 * @return string formatted data
2334 function PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated ) {
2336 // Define classes to be added to this data field based on the type of data
2337 $enum_class = '';
2338 if(strpos($meta->flags, 'enum') !== false) {
2339 $enum_class = ' enum';
2342 $mime_type_class = '';
2343 if(isset($meta->mimetype)) {
2344 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
2347 // continue the <td> tag started before calling this function:
2348 $result = ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap
2349 . ' ' . ($is_field_truncated ? ' truncated' : '')
2350 . ($transform_function != $default_function ? ' transformed' : '')
2351 . (isset($map[$meta->name]) ? ' relation' : '')
2352 . $enum_class . $mime_type_class . '">';
2354 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2355 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2356 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2357 if (isset($alias) && strlen($alias)) {
2358 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2359 if ($alias == $meta->name) {
2360 // this change in the parameter does not matter
2361 // outside of the function
2362 $meta->name = $true_column;
2363 } // end if
2364 } // end if
2365 } // end foreach
2366 } // end if
2368 if (isset($map[$meta->name])) {
2369 // Field to display from the foreign table?
2370 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2371 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2372 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2373 . '.' . PMA_backquote($map[$meta->name][0])
2374 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2375 . $where_comparison;
2376 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2377 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2378 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2379 } else {
2380 $dispval = __('Link not found');
2382 @PMA_DBI_free_result($dispresult);
2383 } else {
2384 $dispval = '';
2385 } // end if... else...
2387 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2388 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2389 } else {
2391 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2392 // user chose "relational key" in the display options, so
2393 // the title contains the display field
2394 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2395 } else {
2396 $title = ' title="' . htmlspecialchars($data) . '"';
2399 $_url_params = array(
2400 'db' => $map[$meta->name][3],
2401 'table' => $map[$meta->name][0],
2402 'pos' => '0',
2403 'sql_query' => 'SELECT * FROM '
2404 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2405 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2406 . $where_comparison,
2408 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2409 . '"' . $title . '>';
2411 if ($transform_function != $default_function) {
2412 // always apply a transformation on the real data,
2413 // not on the display field
2414 $result .= $transform_function($data, $transform_options, $meta);
2415 } else {
2416 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2417 // user chose "relational display field" in the
2418 // display options, so show display field in the cell
2419 $result .= $transform_function($dispval, array(), $meta);
2420 } else {
2421 // otherwise display data in the cell
2422 $result .= $transform_function($data, array(), $meta);
2425 $result .= '</a>';
2427 } else {
2428 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2430 $result .= '</td>' . "\n";
2432 return $result;
2436 * Generates a checkbox for multi-row submits
2438 * @uses htmlspecialchars
2439 * @param string $del_url
2440 * @param array $is_display
2441 * @param string $row_no
2442 * @param string $where_clause_html
2443 * @param string $del_query
2444 * @param string $id_suffix
2445 * @param string $class
2446 * @return string the generated HTML
2449 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class) {
2450 $ret = '';
2451 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2452 $ret .= '<td ';
2453 if (! empty($class)) {
2454 $ret .= 'class="' . $class . '"';
2456 $ret .= ' align="center">'
2457 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2458 . ' class="multi_checkbox"'
2459 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2460 . ' </td>';
2462 return $ret;
2466 * Generates an Edit link
2468 * @uses PMA_linkOrButton()
2469 * @param string $edit_url
2470 * @param string $class
2471 * @param string $edit_str
2472 * @param string $where_clause
2473 * @param string $where_clause_html
2474 * @return string the generated HTML
2476 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) {
2477 $ret = '';
2478 if (! empty($edit_url)) {
2479 $ret .= '<td class="' . $class . '" align="center" ' . ' >'
2480 . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE);
2482 * Where clause for selecting this row uniquely is provided as
2483 * a hidden input. Used by jQuery scripts for handling inline editing
2485 if(! empty($where_clause)) {
2486 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2488 $ret .= '</td>';
2490 return $ret;
2494 * Generates a Delete link
2496 * @uses PMA_linkOrButton()
2497 * @param string $del_url
2498 * @param string $del_str
2499 * @param string $js_conf
2500 * @param string $class
2501 * @return string the generated HTML
2503 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
2504 $ret = '';
2505 if (! empty($del_url)) {
2506 $ret .= '<td ';
2507 if (! empty($class)) {
2508 $ret .= 'class="' . $class . '" ';
2510 $ret .= 'align="center" ' . ' >'
2511 . PMA_linkOrButton($del_url, $del_str, $js_conf, FALSE)
2512 . '</td>';
2514 return $ret;
2518 * Generates checkbox and links at some position (left or right)
2520 * @uses PMA_generateCheckboxForMulti()
2521 * @uses PMA_generateEditLink()
2522 * @uses PMA_generateDeleteLink()
2523 * @param string $position
2524 * @param string $del_url
2525 * @param array $is_display
2526 * @param string $row_no
2527 * @param string $where_clause
2528 * @param string $where_clause_html
2529 * @param string $del_query
2530 * @param string $id_suffix
2531 * @param string $edit_url
2532 * @param string $class
2533 * @param string $edit_str
2534 * @param string $del_str
2535 * @param string $js_conf
2536 * @return string the generated HTML
2538 function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $class, $edit_str, $del_str, $js_conf) {
2539 $ret = '';
2541 if ($position == 'left') {
2542 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2544 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2546 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2548 } elseif ($position == 'right') {
2549 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2551 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2553 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');
2555 return $ret;