patch for Copy set of tables to new name pattern.
[phpmyadmin/dennischen.git] / libraries / display_tbl.lib.php
blobd8e29e1019de7fb4bc40a5be277203e6d33e2d93
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" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax" ' : '' ); ?> 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" class="navigation">
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 //page redirection
294 // (unless we are showing all records)
295 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
296 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
297 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
299 if ($nbTotalPage > 1){ //if2
301 <td>
302 <?php
303 $_url_params = array(
304 'db' => $db,
305 'table' => $table,
306 'sql_query' => $sql_query,
307 'goto' => $goto,
309 //<form> to keep the form alignment of button < and <<
310 // and also to know what to execute when the selector changes
311 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
312 echo PMA_pageselector(
313 $_SESSION['tmp_user_values']['max_rows'],
314 $pageNow,
315 $nbTotalPage,
316 200,
321 __('Page number:')
324 </form>
325 </td>
326 <?php
327 } //_if2
328 } //_if1
330 // Display the "Show all" button if allowed
331 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
332 echo "\n";
334 <td>
335 <form action="sql.php" method="post">
336 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
337 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
338 <input type="hidden" name="pos" value="0" />
339 <input type="hidden" name="session_max_rows" value="all" />
340 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
341 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
342 </form>
343 </td>
344 <?php
345 } // end show all
347 // Move to the next page or to the last one
348 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
349 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
351 // display the Next button
352 PMA_displayTableNavigationOneButton('&gt;',
353 __('Next'),
354 $pos_next,
355 $html_sql_query);
357 // prepare some options for the End button
358 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
359 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
360 // no backquote around this message
361 $onclick = '';
362 } else {
363 $input_for_real_end = $onclick = '';
366 // display the End button
367 PMA_displayTableNavigationOneButton('&gt;&gt;',
368 __('End'),
369 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
370 $html_sql_query,
371 'onsubmit="return ' . (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false') . '"',
372 $input_for_real_end,
373 $onclick
375 } // end move toward
377 </tr>
378 </table>
380 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
381 // of $cfg['MaxExactCountViews']; in this case, avoid passing
382 // the 5th parameter to checkFormElementInRange()
383 // (this means we can't validate the upper limit ?>
384 <div>
385 <form action="sql.php" method="post"
386 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) &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 : ''; ?>))">
387 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
388 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
389 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
390 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
391 <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
392 <?php echo __('row(s) starting from row #') . "\n"; ?>
393 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
394 <?php
395 // Display mode (horizontal/vertical and repeat headers)
396 $choices = array(
397 'horizontal' => __('horizontal'),
398 'horizontalflipped' => __('horizontal (rotated headers)'),
399 'vertical' => __('vertical'));
400 $param1 = PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
401 unset($choices);
403 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />' . "\n"
404 . ' ';
405 echo ' ' . sprintf(__('in %s mode and repeat headers after %s cells'), "\n" . $param1, "\n" . $param2) . "\n";
407 </form>
408 </div>
409 <?php
410 } // end of the 'PMA_displayTableNavigation()' function
414 * Displays the headers of the results table
416 * @uses $_SESSION['tmp_user_values']['disp_direction']
417 * @uses $_SESSION['tmp_user_values']['repeat_cells']
418 * @uses $_SESSION['tmp_user_values']['max_rows']
419 * @uses $_SESSION['tmp_user_values']['display_text']
420 * @uses $_SESSION['tmp_user_values']['display_binary']
421 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
422 * @param array which elements to display
423 * @param array the list of fields properties
424 * @param integer the total number of fields returned by the SQL query
425 * @param array the analyzed query
427 * @return boolean $clause_is_unique
429 * @global string $db the database name
430 * @global string $table the table name
431 * @global string $goto the URL to go back in case of errors
432 * @global string $sql_query the SQL query
433 * @global integer $num_rows the total number of rows returned by the
434 * SQL query
435 * @global array $vertical_display informations used with vertical display
436 * mode
438 * @access private
440 * @see PMA_displayTable()
442 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
444 global $db, $table, $goto;
445 global $sql_query, $num_rows;
446 global $vertical_display, $highlight_columns;
448 if ($analyzed_sql == '') {
449 $analyzed_sql = array();
452 // can the result be sorted?
453 if ($is_display['sort_lnk'] == '1') {
455 // Just as fallback
456 $unsorted_sql_query = $sql_query;
457 if (isset($analyzed_sql[0]['unsorted_query'])) {
458 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
460 // Handles the case of multiple clicks on a column's header
461 // which would add many spaces before "ORDER BY" in the
462 // generated query.
463 $unsorted_sql_query = trim($unsorted_sql_query);
465 // sorting by indexes, only if it makes sense (only one table ref)
466 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
467 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
468 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
470 // grab indexes data:
471 $indexes = PMA_Index::getFromTable($table, $db);
473 // do we have any index?
474 if ($indexes) {
476 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
477 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
478 $span = $fields_cnt;
479 if ($is_display['edit_lnk'] != 'nn') {
480 $span++;
482 if ($is_display['del_lnk'] != 'nn') {
483 $span++;
485 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
486 $span++;
488 } else {
489 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
492 echo '<form action="sql.php" method="post">' . "\n";
493 echo PMA_generate_common_hidden_inputs($db, $table);
494 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
495 $used_index = false;
496 $local_order = (isset($sort_expression) ? $sort_expression : '');
497 foreach ($indexes as $index) {
498 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
499 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
500 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
501 echo '<option value="'
502 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
503 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
504 . '>' . htmlspecialchars($index->getName()) . ' ('
505 . __('Ascending') . ')</option>';
506 echo '<option value="'
507 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
508 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
509 . '>' . htmlspecialchars($index->getName()) . ' ('
510 . __('Descending') . ')</option>';
512 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
513 echo '</select>' . "\n";
514 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
515 echo '</form>' . "\n";
521 $vertical_display['emptypre'] = 0;
522 $vertical_display['emptyafter'] = 0;
523 $vertical_display['textbtn'] = '';
525 // Display options (if we are not in print view)
526 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
527 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
528 if ($GLOBALS['cfg']['AjaxEnable']) {
529 echo ' class="ajax" ';
531 echo '>';
532 $url_params = array(
533 'db' => $db,
534 'table' => $table,
535 'sql_query' => $sql_query,
536 'goto' => $goto,
537 'display_options_form' => 1
539 echo PMA_generate_common_hidden_inputs($url_params);
540 echo '<br />';
541 PMA_generate_slider_effect('displayoptions',__('Options'));
542 echo '<fieldset>';
544 echo '<div class="formelement">';
545 $choices = array(
546 'P' => __('Partial texts'),
547 'F' => __('Full texts')
549 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
550 echo '</div>';
552 // prepare full/partial text button or link
553 if ($_SESSION['tmp_user_values']['display_text']=='F') {
554 // currently in fulltext mode so show the opposite link
555 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
556 $tmp_txt = __('Partial texts');
557 $url_params['display_text'] = 'P';
558 } else {
559 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
560 $tmp_txt = __('Full texts');
561 $url_params['display_text'] = 'F';
564 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
565 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
566 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
567 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
570 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
571 echo '<div class="formelement">';
572 $choices = array(
573 'K' => __('Relational key'),
574 'D' => __('Relational display column')
576 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
577 echo '</div>';
580 echo '<div class="formelement">';
581 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
582 echo '<br />';
583 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
584 echo '<br />';
585 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
586 echo '</div>';
588 // I would have preferred to name this "display_transformation".
589 // This is the only way I found to be able to keep this setting sticky
590 // per SQL query, and at the same time have a default that displays
591 // the transformations.
592 echo '<div class="formelement">';
593 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
594 echo '</div>';
596 echo '<div class="clearfloat"></div>';
597 echo '</fieldset>';
599 echo '<fieldset class="tblFooters">';
600 echo '<input type="submit" value="' . __('Go') . '" />';
601 echo '</fieldset>';
602 echo '</div>';
603 echo '</form>';
606 // Start of form for multi-rows edit/delete/export
608 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
609 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
610 echo PMA_generate_common_hidden_inputs($db, $table, 1);
611 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
614 echo '<table id="table_results" class="data';
615 if ($GLOBALS['cfg']['AjaxEnable']) {
616 echo ' ajax';
618 echo '">' . "\n";
619 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
620 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
621 echo '<thead><tr>' . "\n";
624 // 1. Displays the full/partial text button (part 1)...
625 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
626 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
627 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
628 ? ' colspan="4"'
629 : '';
630 } else {
631 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
632 ? ' rowspan="4"'
633 : '';
636 // ... before the result table
637 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
638 && $is_display['text_btn'] == '1') {
639 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
640 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
641 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
643 <th colspan="<?php echo $fields_cnt; ?>"></th>
644 </tr>
645 <tr>
646 <?php
647 } // end horizontal/horizontalflipped mode
648 else {
650 <tr>
651 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
652 </tr>
653 <?php
654 } // end vertical mode
657 // ... at the left column of the result table header if possible
658 // and required
659 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
660 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
661 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
662 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
664 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
665 <?php
666 } // end horizontal/horizontalflipped mode
667 else {
668 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
669 . ' ' . "\n"
670 . ' </th>' . "\n";
671 } // end vertical mode
674 // ... elseif no button, displays empty(ies) col(s) if required
675 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
676 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
677 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
678 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
679 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
681 <td<?php echo $colspan; ?>></td>
682 <?php
683 } // end horizontal/horizontalfipped mode
684 else {
685 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
686 } // end vertical mode
689 // 2. Displays the fields' name
690 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
691 // statement (see 2.1.3)
693 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
694 // Do not show comments, if using horizontalflipped mode, because of space usage
695 if ($GLOBALS['cfg']['ShowBrowseComments']
696 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
697 $comments_map = array();
698 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
699 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
700 $tb = $tbl['table_true_name'];
701 $comments_map[$tb] = PMA_getComments($db, $tb);
702 unset($tb);
707 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
708 require_once './libraries/transformations.lib.php';
709 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
712 // See if we have to highlight any header fields of a WHERE query.
713 // Uses SQL-Parser results.
714 $highlight_columns = array();
715 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
716 isset($analyzed_sql[0]['where_clause_identifiers'])) {
718 $wi = 0;
719 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
720 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
721 $highlight_columns[$wci] = 'true';
726 for ($i = 0; $i < $fields_cnt; $i++) {
727 // See if this column should get highlight because it's used in the
728 // where-query.
729 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
730 $condition_field = true;
731 } else {
732 $condition_field = false;
735 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
736 if (isset($comments_map) &&
737 isset($comments_map[$fields_meta[$i]->table]) &&
738 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
739 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
740 } else {
741 $comments = '';
744 // 2.1 Results can be sorted
745 if ($is_display['sort_lnk'] == '1') {
747 // 2.1.1 Checks if the table name is required; it's the case
748 // for a query with a "JOIN" statement and if the column
749 // isn't aliased, or in queries like
750 // SELECT `1`.`master_field` , `2`.`master_field`
751 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
753 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
754 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
755 } else {
756 $sort_tbl = '';
759 // 2.1.2 Checks if the current column is used to sort the
760 // results
761 // the orgname member does not exist for all MySQL versions
762 // but if found, it's the one on which to sort
763 $name_to_use_in_sort = $fields_meta[$i]->name;
764 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
765 $name_to_use_in_sort = $fields_meta[$i]->orgname;
767 // $name_to_use_in_sort might contain a space due to
768 // formatting of function expressions like "COUNT(name )"
769 // so we remove the space in this situation
770 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
772 if (empty($sort_expression)) {
773 $is_in_sort = false;
774 } else {
775 // Field name may be preceded by a space, or any number
776 // of characters followed by a dot (tablename.fieldname)
777 // so do a direct comparison for the sort expression;
778 // this avoids problems with queries like
779 // "SELECT id, count(id)..." and clicking to sort
780 // on id or on count(id).
781 // Another query to test this:
782 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
783 // (and try clicking on each column's header twice)
784 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
785 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
787 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
789 // 2.1.3 Check the field name for a bracket.
790 // If it contains one, it's probably a function column
791 // like 'COUNT(`field`)'
792 if (strpos($name_to_use_in_sort, '(') !== false) {
793 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
794 } else {
795 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
797 unset($name_to_use_in_sort);
799 // 2.1.4 Do define the sorting URL
800 if (! $is_in_sort) {
801 // patch #455484 ("Smart" order)
802 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
803 if ($GLOBALS['cfg']['Order'] === 'SMART') {
804 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
805 } else {
806 $sort_order .= $GLOBALS['cfg']['Order'];
808 $order_img = '';
809 } elseif ('DESC' == $sort_direction) {
810 $sort_order .= ' ASC';
811 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
812 } else {
813 $sort_order .= ' DESC';
814 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
817 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
818 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
819 } else {
820 $sorted_sql_query = $unsorted_sql_query . $sort_order;
822 $_url_params = array(
823 'db' => $db,
824 'table' => $table,
825 'sql_query' => $sorted_sql_query,
827 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
829 // 2.1.5 Displays the sorting URL
830 // enable sort order swapping for image
831 $order_link_params = array();
832 if (isset($order_img) && $order_img!='') {
833 if (strstr($order_img, 'asc')) {
834 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
835 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
836 } elseif (strstr($order_img, 'desc')) {
837 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
838 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
841 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
842 if (PMA_USR_BROWSER_AGENT == 'IE') {
843 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
844 } else {
845 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
848 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
849 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
850 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
852 $order_link_params['title'] = __('Sort');
853 $order_link_content = ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
854 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
856 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
857 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
858 echo '<th';
859 $th_class = array();
860 if ($condition_field) {
861 $th_class[] = 'condition';
863 $th_class[] = 'column_heading';
864 echo ' class="' . implode(' ', $th_class) . '"';
866 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
867 echo ' valign="bottom"';
869 echo '>' . $order_link . $comments . '</th>';
871 $vertical_display['desc'][] = ' <th '
872 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
873 . $order_link . $comments . ' </th>' . "\n";
874 } // end if (2.1)
876 // 2.2 Results can't be sorted
877 else {
878 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
879 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
880 echo '<th';
881 if ($condition_field) {
882 echo ' class="condition"';
884 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
885 echo ' valign="bottom"';
887 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
888 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
889 echo ' style="direction: ltr; writing-mode: tb-rl;"';
891 echo '>';
892 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
893 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
894 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
895 } else {
896 echo htmlspecialchars($fields_meta[$i]->name);
898 echo "\n" . $comments . '</th>';
900 $vertical_display['desc'][] = ' <th '
901 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
902 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
903 . $comments . ' </th>';
904 } // end else (2.2)
905 } // end for
907 // 3. Displays the needed checkboxes at the right
908 // column of the result table header if possible and required...
909 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
910 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
911 && $is_display['text_btn'] == '1') {
912 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
913 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
914 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
915 echo "\n";
917 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
918 </th>
919 <?php
920 } // end horizontal/horizontalflipped mode
921 else {
922 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
923 . ' ' . "\n"
924 . ' </th>' . "\n";
925 } // end vertical mode
928 // ... elseif no button, displays empty columns if required
929 // (unless coming from Browse mode print view)
930 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
931 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
932 && (!$GLOBALS['is_header_sent'])) {
933 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
934 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
935 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
936 echo "\n";
938 <td<?php echo $colspan; ?>></td>
939 <?php
940 } // end horizontal/horizontalflipped mode
941 else {
942 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
943 } // end vertical mode
946 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
947 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
949 </tr>
950 </thead>
951 <?php
954 return true;
955 } // end of the 'PMA_displayTableHeaders()' function
959 * Prepares the display for a value
961 * @param string $class
962 * @param string $condition_field
963 * @param string $value
965 * @return string the td
967 function PMA_buildValueDisplay($class, $condition_field, $value) {
968 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
972 * Prepares the display for a null value
974 * @param string $class
975 * @param string $condition_field
977 * @return string the td
979 function PMA_buildNullDisplay($class, $condition_field) {
980 // the null class is needed for inline editing
981 return '<td align="right"' . ' class="' . $class . ($condition_field ? ' condition' : '') . ' null"><i>NULL</i></td>';
985 * Prepares the display for an empty value
987 * @param string $class
988 * @param string $condition_field
989 * @param string $align
991 * @return string the td
993 function PMA_buildEmptyDisplay($class, $condition_field, $align = '') {
994 return '<td ' . $align . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>';
998 * Displays the body of the results table
1000 * @uses $_SESSION['tmp_user_values']['disp_direction']
1001 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1002 * @uses $_SESSION['tmp_user_values']['max_rows']
1003 * @uses $_SESSION['tmp_user_values']['display_text']
1004 * @uses $_SESSION['tmp_user_values']['display_binary']
1005 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1006 * @uses $_SESSION['tmp_user_values']['display_blob']
1007 * @param integer the link id associated to the query which results have
1008 * to be displayed
1009 * @param array which elements to display
1010 * @param array the list of relations
1011 * @param array the analyzed query
1013 * @return boolean always true
1015 * @global string $db the database name
1016 * @global string $table the table name
1017 * @global string $goto the URL to go back in case of errors
1018 * @global string $sql_query the SQL query
1019 * @global array $fields_meta the list of fields properties
1020 * @global integer $fields_cnt the total number of fields returned by
1021 * the SQL query
1022 * @global array $vertical_display informations used with vertical display
1023 * mode
1024 * @global array $highlight_columns column names to highlight
1025 * @global array $row current row data
1027 * @access private
1029 * @see PMA_displayTable()
1031 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1032 global $db, $table, $goto;
1033 global $sql_query, $fields_meta, $fields_cnt;
1034 global $vertical_display, $highlight_columns;
1035 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1037 $url_sql_query = $sql_query;
1039 // query without conditions to shorten URLs when needed, 200 is just
1040 // guess, it should depend on remaining URL length
1042 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1043 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1044 strlen($sql_query) > 200) {
1046 $url_sql_query = 'SELECT ';
1047 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1048 $url_sql_query .= ' DISTINCT ';
1050 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1051 if (!empty($analyzed_sql[0]['from_clause'])) {
1052 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1056 if (!is_array($map)) {
1057 $map = array();
1059 $row_no = 0;
1060 $vertical_display['edit'] = array();
1061 $vertical_display['copy'] = array();
1062 $vertical_display['delete'] = array();
1063 $vertical_display['data'] = array();
1064 $vertical_display['row_delete'] = array();
1065 // name of the class added to all inline editable elements
1066 $inline_edit_class = 'inline_edit';
1068 // Correction University of Virginia 19991216 in the while below
1069 // Previous code assumed that all tables have keys, specifically that
1070 // the phpMyAdmin GUI should support row delete/edit only for such
1071 // tables.
1072 // Although always using keys is arguably the prescribed way of
1073 // defining a relational table, it is not required. This will in
1074 // particular be violated by the novice.
1075 // We want to encourage phpMyAdmin usage by such novices. So the code
1076 // below has been changed to conditionally work as before when the
1077 // table being displayed has one or more keys; but to display
1078 // delete/edit options correctly for tables without keys.
1080 $odd_row = true;
1081 while ($row = PMA_DBI_fetch_row($dt_result)) {
1082 // "vertical display" mode stuff
1083 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1084 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1085 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1087 echo '<tr>' . "\n";
1088 if ($vertical_display['emptypre'] > 0) {
1089 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1090 .' &nbsp;</th>' . "\n";
1093 foreach ($vertical_display['desc'] as $val) {
1094 echo $val;
1097 if ($vertical_display['emptyafter'] > 0) {
1098 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1099 .' &nbsp;</th>' . "\n";
1101 echo '</tr>' . "\n";
1102 } // end if
1104 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1105 $odd_row = ! $odd_row;
1107 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1108 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1109 // pointer code part
1110 echo '<tr class="' . $alternating_color_class . '">';
1114 // 1. Prepares the row
1115 // 1.1 Results from a "SELECT" statement -> builds the
1116 // WHERE clause to use in links (a unique key if possible)
1118 * @todo $where_clause could be empty, for example a table
1119 * with only one field and it's a BLOB; in this case,
1120 * avoid to display the delete and edit links
1122 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1123 $where_clause_html = urlencode($where_clause);
1125 // 1.2 Defines the URLs for the modify/delete link(s)
1127 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1128 // We need to copy the value or else the == 'both' check will always return true
1130 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1131 $iconic_spacer = '<div class="nowrap">';
1132 } else {
1133 $iconic_spacer = '';
1136 // 1.2.1 Modify link(s)
1137 if ($is_display['edit_lnk'] == 'ur') { // update row case
1138 $_url_params = array(
1139 'db' => $db,
1140 'table' => $table,
1141 'where_clause' => $where_clause,
1142 'clause_is_unique' => $clause_is_unique,
1143 'sql_query' => $url_sql_query,
1144 'goto' => 'sql.php',
1146 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1147 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1149 $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
1150 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'), true);
1152 // Class definitions required for inline editing jQuery scripts
1153 $edit_anchor_class = "edit_row_anchor";
1154 if( $clause_is_unique == 0) {
1155 $edit_anchor_class .= ' nonunique';
1157 } // end if (1.2.1)
1159 // 1.2.2 Delete/Kill link(s)
1160 if ($is_display['del_lnk'] == 'dr') { // delete row case
1161 $_url_params = array(
1162 'db' => $db,
1163 'table' => $table,
1164 'sql_query' => $url_sql_query,
1165 'message_to_show' => __('The row has been deleted'),
1166 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1168 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1170 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1171 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1173 $_url_params = array(
1174 'db' => $db,
1175 'table' => $table,
1176 'sql_query' => $del_query,
1177 'message_to_show' => __('The row has been deleted'),
1178 'goto' => $lnk_goto,
1180 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1182 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1183 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1184 . ($clause_is_unique ? '' : ' LIMIT 1');
1185 $del_str = PMA_getIcon('b_drop.png', __('Delete'), true);
1186 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1188 $_url_params = array(
1189 'db' => $db,
1190 'table' => $table,
1191 'sql_query' => $url_sql_query,
1192 'goto' => 'main.php',
1194 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1196 $_url_params = array(
1197 'db' => 'mysql',
1198 'sql_query' => 'KILL ' . $row[0],
1199 'goto' => $lnk_goto,
1201 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1202 $del_query = 'KILL ' . $row[0];
1203 $js_conf = 'KILL ' . $row[0];
1204 $del_str = PMA_getIcon('b_drop.png', __('Kill'), true);
1205 } // end if (1.2.2)
1207 // 1.3 Displays the links at left if required
1208 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1209 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1210 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1211 if (! isset($js_conf)) {
1212 $js_conf = '';
1214 echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1215 } // end if (1.3)
1216 } // end if (1)
1218 // 2. Displays the rows' values
1219 for ($i = 0; $i < $fields_cnt; ++$i) {
1220 $meta = $fields_meta[$i];
1221 $not_null_class = $meta->not_null ? 'not_null' : '';
1222 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1223 $pointer = $i;
1224 $is_field_truncated = false;
1225 //If the previous column had blob data, we need to reset the class
1226 // to $inline_edit_class
1227 $class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $alternating_color_class . ' ' . $relation_class;
1229 // See if this column should get highlight because it's used in the
1230 // where-query.
1231 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1232 $condition_field = true;
1233 } else {
1234 $condition_field = false;
1237 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1238 // the row number corresponds to a data row, not HTML table row
1239 $class .= ' row_' . $row_no;
1240 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1241 $class .= ' vpointer';
1243 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1244 $class .= ' vmarker';
1246 }// end if
1248 // Wrap MIME-transformations. [MIME]
1249 $default_function = 'default_function'; // default_function
1250 $transform_function = $default_function;
1251 $transform_options = array();
1253 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1255 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1256 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1258 if (file_exists('./libraries/transformations/' . $include_file)) {
1259 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1261 require_once './libraries/transformations/' . $include_file;
1263 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1264 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1265 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1266 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1268 } // end if file_exists
1269 } // end if transformation is set
1270 } // end if mime/transformation works.
1272 $_url_params = array(
1273 'db' => $db,
1274 'table' => $table,
1275 'where_clause' => $where_clause,
1276 'transform_key' => $meta->name,
1279 if (! empty($sql_query)) {
1280 $_url_params['sql_query'] = $url_sql_query;
1283 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1285 // n u m e r i c
1286 if ($meta->numeric == 1) {
1288 // if two fields have the same name (this is possible
1289 // with self-join queries, for example), using $meta->name
1290 // will show both fields NULL even if only one is NULL,
1291 // so use the $pointer
1293 if (!isset($row[$i]) || is_null($row[$i])) {
1294 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1295 } elseif ($row[$i] != '') {
1297 $nowrap = ' nowrap';
1298 $where_comparison = ' = ' . $row[$i];
1300 $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);
1301 } else {
1302 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, 'align="right"');
1305 // b l o b
1307 } elseif (stristr($meta->type, 'BLOB')) {
1308 // PMA_mysql_fetch_fields returns BLOB in place of
1309 // TEXT fields type so we have to ensure it's really a BLOB
1310 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1312 // remove 'inline_edit' from $class as we can't edit binary data.
1313 $class = str_replace('inline_edit', '', $class);
1315 if (stristr($field_flags, 'BINARY')) {
1316 if (!isset($row[$i]) || is_null($row[$i])) {
1317 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1318 } else {
1319 // for blobstreaming
1320 // if valid BS reference exists
1321 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1322 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1323 } else {
1324 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1327 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1328 unset($blobtext);
1330 // not binary:
1331 } else {
1332 if (!isset($row[$i]) || is_null($row[$i])) {
1333 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1334 } elseif ($row[$i] != '') {
1335 // if a transform function for blob is set, none of these replacements will be made
1336 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1337 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1338 $is_field_truncated = true;
1340 // displays all space characters, 4 space
1341 // characters for tabulations and <cr>/<lf>
1342 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1344 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1345 } else {
1346 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field);
1349 // g e o m e t r y
1350 } elseif ($meta->type == 'geometry') {
1351 $geometry_text = PMA_handle_non_printable_contents('GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1353 // remove 'inline_edit' from $class as we can't edit geometry data.
1354 $class = str_replace('inline_edit', '', $class);
1355 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $geometry_text);
1356 unset($geometry_text);
1358 // n o t n u m e r i c a n d n o t B L O B
1359 } else {
1360 if (!isset($row[$i]) || is_null($row[$i])) {
1361 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1362 } elseif ($row[$i] != '') {
1363 // support blanks in the key
1364 $relation_id = $row[$i];
1366 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1367 // (unless it's a link-type transformation)
1368 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1369 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1370 $is_field_truncated = true;
1373 // displays special characters from binaries
1374 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1375 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1376 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1377 // some results of PROCEDURE ANALYSE() are reported as
1378 // being BINARY but they are quite readable,
1379 // so don't treat them as BINARY
1380 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1381 if ($_SESSION['tmp_user_values']['display_binary']) {
1382 // user asked to see the real contents of BINARY
1383 // fields
1384 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1385 $row[$i] = bin2hex($row[$i]);
1386 } else {
1387 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1389 } else {
1390 // we show the BINARY message and field's size
1391 // (or maybe use a transformation)
1392 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1396 // transform functions may enable no-wrapping:
1397 $function_nowrap = $transform_function . '_nowrap';
1398 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1400 // do not wrap if date field type
1401 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1402 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1403 $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);
1405 } else {
1406 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field);
1410 // output stored cell
1411 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1412 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1413 echo $vertical_display['data'][$row_no][$i];
1416 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1417 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1418 } else {
1419 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1421 } // end for (2)
1423 // 3. Displays the modify/delete links on the right if required
1424 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1425 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1426 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1427 if (! isset($js_conf)) {
1428 $js_conf = '';
1430 echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1431 } // end if (3)
1433 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1434 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1436 </tr>
1437 <?php
1438 } // end if
1440 // 4. Gather links of del_urls and edit_urls in an array for later
1441 // output
1442 if (!isset($vertical_display['edit'][$row_no])) {
1443 $vertical_display['edit'][$row_no] = '';
1444 $vertical_display['copy'][$row_no] = '';
1445 $vertical_display['delete'][$row_no] = '';
1446 $vertical_display['row_delete'][$row_no] = '';
1448 $vertical_class = ' row_' . $row_no;
1449 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1450 $vertical_class .= ' vpointer';
1452 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1453 $vertical_class .= ' vmarker';
1456 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1457 $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);
1458 } else {
1459 unset($vertical_display['row_delete'][$row_no]);
1462 if (isset($edit_url)) {
1463 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1464 } else {
1465 unset($vertical_display['edit'][$row_no]);
1468 if (isset($copy_url)) {
1469 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1470 } else {
1471 unset($vertical_display['copy'][$row_no]);
1474 if (isset($del_url)) {
1475 if (! isset($js_conf)) {
1476 $js_conf = '';
1478 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1479 } else {
1480 unset($vertical_display['delete'][$row_no]);
1483 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1484 $row_no++;
1485 } // end while
1487 // this is needed by PMA_displayTable() to generate the proper param
1488 // in the multi-edit and multi-delete form
1489 return $clause_is_unique;
1490 } // end of the 'PMA_displayTableBody()' function
1494 * Do display the result table with the vertical direction mode.
1496 * @return boolean always true
1498 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1499 * @global array $vertical_display the information to display
1501 * @access private
1503 * @see PMA_displayTable()
1505 function PMA_displayVerticalTable()
1507 global $vertical_display;
1509 // Displays "multi row delete" link at top if required
1510 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1511 echo '<tr>' . "\n";
1512 echo $vertical_display['textbtn'];
1513 $foo_counter = 0;
1514 foreach ($vertical_display['row_delete'] as $val) {
1515 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1516 echo '<th></th>' . "\n";
1519 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1520 $foo_counter++;
1521 } // end while
1522 echo '</tr>' . "\n";
1523 } // end if
1525 // Displays "edit" link at top if required
1526 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1527 echo '<tr>' . "\n";
1528 if (!is_array($vertical_display['row_delete'])) {
1529 echo $vertical_display['textbtn'];
1531 $foo_counter = 0;
1532 foreach ($vertical_display['edit'] as $val) {
1533 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1534 echo ' <th></th>' . "\n";
1537 echo $val;
1538 $foo_counter++;
1539 } // end while
1540 echo '</tr>' . "\n";
1541 } // end if
1543 // Displays "copy" link at top if required
1544 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1545 echo '<tr>' . "\n";
1546 if (!is_array($vertical_display['row_delete'])) {
1547 echo $vertical_display['textbtn'];
1549 $foo_counter = 0;
1550 foreach ($vertical_display['copy'] as $val) {
1551 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1552 echo ' <th></th>' . "\n";
1555 echo $val;
1556 $foo_counter++;
1557 } // end while
1558 echo '</tr>' . "\n";
1559 } // end if
1561 // Displays "delete" link at top if required
1562 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1563 echo '<tr>' . "\n";
1564 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1565 echo $vertical_display['textbtn'];
1567 $foo_counter = 0;
1568 foreach ($vertical_display['delete'] as $val) {
1569 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1570 echo '<th></th>' . "\n";
1573 echo $val;
1574 $foo_counter++;
1575 } // end while
1576 echo '</tr>' . "\n";
1577 } // end if
1579 // Displays data
1580 foreach ($vertical_display['desc'] AS $key => $val) {
1582 echo '<tr>' . "\n";
1583 echo $val;
1585 $foo_counter = 0;
1586 foreach ($vertical_display['rowdata'][$key] as $subval) {
1587 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1588 echo $val;
1591 echo $subval;
1592 $foo_counter++;
1593 } // end while
1595 echo '</tr>' . "\n";
1596 } // end while
1598 // Displays "multi row delete" link at bottom if required
1599 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1600 echo '<tr>' . "\n";
1601 echo $vertical_display['textbtn'];
1602 $foo_counter = 0;
1603 foreach ($vertical_display['row_delete'] as $val) {
1604 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1605 echo '<th></th>' . "\n";
1608 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1609 $foo_counter++;
1610 } // end while
1611 echo '</tr>' . "\n";
1612 } // end if
1614 // Displays "edit" link at bottom if required
1615 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1616 echo '<tr>' . "\n";
1617 if (!is_array($vertical_display['row_delete'])) {
1618 echo $vertical_display['textbtn'];
1620 $foo_counter = 0;
1621 foreach ($vertical_display['edit'] as $val) {
1622 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1623 echo '<th></th>' . "\n";
1626 echo $val;
1627 $foo_counter++;
1628 } // end while
1629 echo '</tr>' . "\n";
1630 } // end if
1632 // Displays "copy" link at bottom if required
1633 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1634 echo '<tr>' . "\n";
1635 if (!is_array($vertical_display['row_delete'])) {
1636 echo $vertical_display['textbtn'];
1638 $foo_counter = 0;
1639 foreach ($vertical_display['copy'] as $val) {
1640 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1641 echo '<th></th>' . "\n";
1644 echo $val;
1645 $foo_counter++;
1646 } // end while
1647 echo '</tr>' . "\n";
1648 } // end if
1650 // Displays "delete" link at bottom if required
1651 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1652 echo '<tr>' . "\n";
1653 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1654 echo $vertical_display['textbtn'];
1656 $foo_counter = 0;
1657 foreach ($vertical_display['delete'] as $val) {
1658 if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
1659 echo '<th></th>' . "\n";
1662 echo $val;
1663 $foo_counter++;
1664 } // end while
1665 echo '</tr>' . "\n";
1668 return true;
1669 } // end of the 'PMA_displayVerticalTable' function
1673 * @uses $_SESSION['tmp_user_values']['disp_direction']
1674 * @uses $_REQUEST['disp_direction']
1675 * @uses $GLOBALS['cfg']['DefaultDisplay']
1676 * @uses $_SESSION['tmp_user_values']['repeat_cells']
1677 * @uses $_REQUEST['repeat_cells']
1678 * @uses $GLOBALS['cfg']['RepeatCells']
1679 * @uses $_SESSION['tmp_user_values']['max_rows']
1680 * @uses $_REQUEST['session_max_rows']
1681 * @uses $GLOBALS['cfg']['MaxRows']
1682 * @uses $_SESSION['tmp_user_values']['pos']
1683 * @uses $_REQUEST['pos']
1684 * @uses $_SESSION['tmp_user_values']['display_text']
1685 * @uses $_REQUEST['display_text']
1686 * @uses $_SESSION['tmp_user_values']['relational_display']
1687 * @uses $_REQUEST['relational_display']
1688 * @uses $_SESSION['tmp_user_values']['display_binary']
1689 * @uses $_REQUEST['display_binary']
1690 * @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
1691 * @uses $_REQUEST['display_binary_as_hex']
1692 * @uses $_SESSION['tmp_user_values']['display_blob']
1693 * @uses $_REQUEST['display_blob']
1694 * @uses PMA_isValid()
1695 * @uses $GLOBALS['sql_query']
1696 * @todo make maximum remembered queries configurable
1697 * @todo move/split into SQL class!?
1698 * @todo currently this is called twice unnecessary
1699 * @todo ignore LIMIT and ORDER in query!?
1701 function PMA_displayTable_checkConfigParams()
1703 $sql_md5 = md5($GLOBALS['sql_query']);
1705 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1707 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1708 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1709 unset($_REQUEST['disp_direction']);
1710 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1711 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1714 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1715 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1716 unset($_REQUEST['repeat_cells']);
1717 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1718 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1721 // as this is a form value, the type is always string so we cannot
1722 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1723 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1724 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1725 || $_REQUEST['session_max_rows'] == 'all') {
1726 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1727 unset($_REQUEST['session_max_rows']);
1728 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1729 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1732 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1733 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1734 unset($_REQUEST['pos']);
1735 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1736 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1739 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1740 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1741 unset($_REQUEST['display_text']);
1742 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1743 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1746 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1747 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1748 unset($_REQUEST['relational_display']);
1749 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1750 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1753 if (isset($_REQUEST['display_binary'])) {
1754 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1755 unset($_REQUEST['display_binary']);
1756 } elseif (isset($_REQUEST['display_options_form'])) {
1757 // we know that the checkbox was unchecked
1758 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1759 } else {
1760 // selected by default because some operations like OPTIMIZE TABLE
1761 // and all queries involving functions return "binary" contents,
1762 // according to low-level field flags
1763 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1766 if (isset($_REQUEST['display_binary_as_hex'])) {
1767 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1768 unset($_REQUEST['display_binary_as_hex']);
1769 } elseif (isset($_REQUEST['display_options_form'])) {
1770 // we know that the checkbox was unchecked
1771 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1772 } else {
1773 // display_binary_as_hex config option
1774 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1775 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1779 if (isset($_REQUEST['display_blob'])) {
1780 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1781 unset($_REQUEST['display_blob']);
1782 } elseif (isset($_REQUEST['display_options_form'])) {
1783 // we know that the checkbox was unchecked
1784 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1787 if (isset($_REQUEST['hide_transformation'])) {
1788 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1789 unset($_REQUEST['hide_transformation']);
1790 } elseif (isset($_REQUEST['display_options_form'])) {
1791 // we know that the checkbox was unchecked
1792 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1795 // move current query to the last position, to be removed last
1796 // so only least executed query will be removed if maximum remembered queries
1797 // limit is reached
1798 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
1799 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
1800 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
1802 // do not exceed a maximum number of queries to remember
1803 if (count($_SESSION['tmp_user_values']['query']) > 10) {
1804 array_shift($_SESSION['tmp_user_values']['query']);
1805 //echo 'deleting one element ...';
1808 // populate query configuration
1809 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
1810 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
1811 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
1812 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
1813 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
1814 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
1815 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
1816 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
1817 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
1818 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
1821 * debugging
1822 echo '<pre>';
1823 var_dump($_SESSION['tmp_user_values']);
1824 echo '</pre>';
1829 * Displays a table of results returned by a SQL query.
1830 * This function is called by the "sql.php" script.
1832 * @param integer the link id associated to the query which results have
1833 * to be displayed
1834 * @param array the display mode
1835 * @param array the analyzed query
1837 * @uses $_SESSION['tmp_user_values']['pos']
1838 * @global string $db the database name
1839 * @global string $table the table name
1840 * @global string $goto the URL to go back in case of errors
1841 * @global string $sql_query the current SQL query
1842 * @global integer $num_rows the total number of rows returned by the
1843 * SQL query
1844 * @global integer $unlim_num_rows the total number of rows returned by the
1845 * SQL query without any programmatically
1846 * appended "LIMIT" clause
1847 * @global array $fields_meta the list of fields properties
1848 * @global integer $fields_cnt the total number of fields returned by
1849 * the SQL query
1850 * @global array $vertical_display informations used with vertical display
1851 * mode
1852 * @global array $highlight_columns column names to highlight
1853 * @global array $cfgRelation the relation settings
1855 * @access private
1857 * @see PMA_showMessage(), PMA_setDisplayMode(),
1858 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1859 * PMA_displayTableBody(), PMA_displayResultsOperations()
1861 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1863 global $db, $table, $goto;
1864 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1865 global $vertical_display, $highlight_columns;
1866 global $cfgRelation;
1867 global $showtable;
1869 // why was this called here? (already called from sql.php)
1870 //PMA_displayTable_checkConfigParams();
1873 * @todo move this to a central place
1874 * @todo for other future table types
1876 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1878 if ($is_innodb
1879 && ! isset($analyzed_sql[0]['queryflags']['union'])
1880 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1881 && (empty($analyzed_sql[0]['where_clause'])
1882 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1883 // "j u s t b r o w s i n g"
1884 $pre_count = '~';
1885 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')), true);
1886 } else {
1887 $pre_count = '';
1888 $after_count = '';
1891 // 1. ----- Prepares the work -----
1893 // 1.1 Gets the informations about which functionalities should be
1894 // displayed
1895 $total = '';
1896 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1898 // 1.2 Defines offsets for the next and previous pages
1899 if ($is_display['nav_bar'] == '1') {
1900 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
1901 $pos_next = 0;
1902 $pos_prev = 0;
1903 } else {
1904 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
1905 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
1906 if ($pos_prev < 0) {
1907 $pos_prev = 0;
1910 } // end if
1912 // 1.3 Find the sort expression
1914 // we need $sort_expression and $sort_expression_nodirection
1915 // even if there are many table references
1916 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1917 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1919 * Get rid of ASC|DESC
1921 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1922 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1923 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1924 unset($matches);
1925 } else {
1926 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1929 // 1.4 Prepares display of first and last value of the sorted column
1931 if (! empty($sort_expression_nodirection)) {
1932 if (strpos($sort_expression_nodirection, '.') === false) {
1933 $sort_table = $table;
1934 $sort_column = $sort_expression_nodirection;
1935 } else {
1936 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1938 $sort_table = PMA_unQuote($sort_table);
1939 $sort_column = PMA_unQuote($sort_column);
1940 // find the sorted column index in row result
1941 // (this might be a multi-table query)
1942 $sorted_column_index = false;
1943 foreach($fields_meta as $key => $meta) {
1944 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1945 $sorted_column_index = $key;
1946 break;
1949 if ($sorted_column_index !== false) {
1950 // fetch first row of the result set
1951 $row = PMA_DBI_fetch_row($dt_result);
1952 // initializing default arguments
1953 $default_function = 'default_function';
1954 $transform_function = $default_function;
1955 $transform_options = array();
1956 // check for non printable sorted row data
1957 $meta = $fields_meta[$sorted_column_index];
1958 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
1959 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
1960 } else {
1961 $column_for_first_row = $row[$sorted_column_index];
1963 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
1964 // fetch last row of the result set
1965 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1966 $row = PMA_DBI_fetch_row($dt_result);
1967 // check for non printable sorted row data
1968 $meta = $fields_meta[$sorted_column_index];
1969 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
1970 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
1971 } else {
1972 $column_for_last_row = $row[$sorted_column_index];
1974 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
1975 // reset to first row for the loop in PMA_displayTableBody()
1976 PMA_DBI_data_seek($dt_result, 0);
1977 // we could also use here $sort_expression_nodirection
1978 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1979 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
1981 unset($sorted_column_index, $sort_table, $sort_column);
1984 // 2. ----- Displays the top of the page -----
1986 // 2.1 Displays a messages with position informations
1987 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1988 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1989 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
1990 } else {
1991 $selectstring = '';
1993 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
1994 ? $total - 1
1995 : $pos_next - 1;
1997 if (PMA_Table::isView($db, $table)
1998 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1999 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2000 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2001 $message->addParam('[/a]');
2002 $message_view_warning = PMA_showHint($message);
2003 } else {
2004 $message_view_warning = false;
2007 $message = PMA_Message::success(__('Showing rows'));
2008 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2009 if ($message_view_warning) {
2010 $message->addMessage('...', ' - ');
2011 $message->addMessage($message_view_warning);
2012 $message->addMessage('(');
2013 } else {
2014 $message->addMessage($last_shown_rec, ' - ');
2015 $message->addMessage(' (');
2016 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2017 $message->addString(__('total'));
2018 if (!empty($after_count)) {
2019 $message->addMessage($after_count);
2021 $message->addMessage($selectstring, '');
2022 $message->addMessage(', ', '');
2025 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2026 $messagge_qt->addParam($GLOBALS['querytime']);
2028 $message->addMessage($messagge_qt, '');
2029 $message->addMessage(')', '');
2031 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2033 PMA_showMessage($message, $sql_query, 'success');
2035 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2036 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2039 // 2.3 Displays the navigation bars
2040 if (! strlen($table)) {
2041 if (isset($analyzed_sql[0]['query_type'])
2042 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2043 // table does not always contain a real table name,
2044 // for example in MySQL 5.0.x, the query SHOW STATUS
2045 // returns STATUS as a table name
2046 $table = $fields_meta[0]->table;
2047 } else {
2048 $table = '';
2052 if ($is_display['nav_bar'] == '1') {
2053 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2054 echo "\n";
2055 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2056 echo "\n" . '<br /><br />' . "\n";
2059 // 2b ----- Get field references from Database -----
2060 // (see the 'relation' configuration variable)
2062 // initialize map
2063 $map = array();
2065 // find tables
2066 $target=array();
2067 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2068 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2069 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2072 $tabs = '(\'' . join('\',\'', $target) . '\')';
2074 if (! strlen($table)) {
2075 $exist_rel = false;
2076 } else {
2077 // To be able to later display a link to the related table,
2078 // we verify both types of relations: either those that are
2079 // native foreign keys or those defined in the phpMyAdmin
2080 // configuration storage. If no PMA storage, we won't be able
2081 // to use the "column to display" notion (for example show
2082 // the name related to a numeric id).
2083 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2084 if ($exist_rel) {
2085 foreach ($exist_rel AS $master_field => $rel) {
2086 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2087 $map[$master_field] = array($rel['foreign_table'],
2088 $rel['foreign_field'],
2089 $display_field,
2090 $rel['foreign_db']);
2091 } // end while
2092 } // end if
2093 } // end if
2094 // end 2b
2096 // 3. ----- Displays the results table -----
2097 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2098 $url_query = '';
2099 echo '<tbody>' . "\n";
2100 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2101 // vertical output case
2102 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2103 PMA_displayVerticalTable();
2104 } // end if
2105 unset($vertical_display);
2106 echo '</tbody>' . "\n";
2108 </table>
2110 <?php
2111 // 4. ----- Displays the link for multi-fields edit and delete
2113 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2115 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2117 $_url_params = array(
2118 'db' => $db,
2119 'table' => $table,
2120 'sql_query' => $sql_query,
2121 'goto' => $goto,
2123 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2125 $_url_params['checkall'] = '1';
2126 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2128 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2129 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
2130 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
2131 } else {
2132 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
2133 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
2135 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2136 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2137 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2138 echo '<img class="selectallarrow" width="38" height="22"'
2139 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2140 .' alt="' . __('With selected:') . '" />';
2142 echo $checkall_link . "\n"
2143 .' / ' . "\n"
2144 .$uncheckall_link . "\n"
2145 .'<i>' . __('With selected:') . '</i>' . "\n";
2147 PMA_buttonOrImage('submit_mult', 'mult_submit',
2148 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2149 PMA_buttonOrImage('submit_mult', 'mult_submit',
2150 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2151 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2152 PMA_buttonOrImage('submit_mult', 'mult_submit',
2153 'submit_mult_export', __('Export'),
2154 'b_tblexport.png', 'export');
2156 echo "\n";
2158 echo '<input type="hidden" name="sql_query"'
2159 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2161 if (! empty($GLOBALS['url_query'])) {
2162 echo '<input type="hidden" name="url_query"'
2163 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2166 echo '<input type="hidden" name="clause_is_unique"'
2167 .' value="' . $clause_is_unique . '" />' . "\n";
2169 echo '</form>' . "\n";
2172 // 5. ----- Displays the navigation bar at the bottom if required -----
2174 if ($is_display['nav_bar'] == '1') {
2175 echo '<br />' . "\n";
2176 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2177 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2178 echo "\n" . '<br /><br />' . "\n";
2181 // 6. ----- Displays "Query results operations"
2182 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2183 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2185 } // end of the 'PMA_displayTable()' function
2187 function default_function($buffer) {
2188 $buffer = htmlspecialchars($buffer);
2189 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2190 str_replace(' ', ' &nbsp;', $buffer));
2191 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2193 return $buffer;
2197 * Displays operations that are available on results.
2199 * @param array the display mode
2200 * @param array the analyzed query
2202 * @uses $_SESSION['tmp_user_values']['pos']
2203 * @uses $_SESSION['tmp_user_values']['display_text']
2204 * @global string $db the database name
2205 * @global string $table the table name
2206 * @global string $sql_query the current SQL query
2207 * @global integer $unlim_num_rows the total number of rows returned by the
2208 * SQL query without any programmatically
2209 * appended "LIMIT" clause
2211 * @access private
2213 * @see PMA_showMessage(), PMA_setDisplayMode(),
2214 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2215 * PMA_displayTableBody(), PMA_displayResultsOperations()
2217 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2218 global $db, $table, $sql_query, $unlim_num_rows;
2220 $header_shown = FALSE;
2221 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2223 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2224 // Displays "printable view" link if required
2225 if ($the_disp_mode[9] == '1') {
2227 if (!$header_shown) {
2228 echo $header;
2229 $header_shown = TRUE;
2232 $_url_params = array(
2233 'db' => $db,
2234 'table' => $table,
2235 'printview' => '1',
2236 'sql_query' => $sql_query,
2238 $url_query = PMA_generate_common_url($_url_params);
2240 echo PMA_linkOrButton(
2241 'sql.php' . $url_query,
2242 PMA_getIcon('b_print.png', __('Print view'), false, true),
2243 '', true, true, 'print_view') . "\n";
2245 if ($_SESSION['tmp_user_values']['display_text']) {
2246 $_url_params['display_text'] = 'F';
2247 echo PMA_linkOrButton(
2248 'sql.php' . PMA_generate_common_url($_url_params),
2249 PMA_getIcon('b_print.png', __('Print view (with full texts)'), false, true),
2250 '', true, true, 'print_view') . "\n";
2251 unset($_url_params['display_text']);
2253 } // end displays "printable view"
2256 // Export link
2257 // (the url_query has extra parameters that won't be used to export)
2258 // (the single_table parameter is used in display_export.lib.php
2259 // to hide the SQL and the structure export dialogs)
2260 // If the parser found a PROCEDURE clause
2261 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2262 // display the Export link).
2263 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2264 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2265 $_url_params['single_table'] = 'true';
2267 if (!$header_shown) {
2268 echo $header;
2269 $header_shown = TRUE;
2271 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2274 * At this point we don't know the table name; this can happen
2275 * for example with a query like
2276 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2277 * As a workaround we set in the table parameter the name of the
2278 * first table of this database, so that tbl_export.php and
2279 * the script it calls do not fail
2281 if (empty($_url_params['table'])) {
2282 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2285 echo PMA_linkOrButton(
2286 'tbl_export.php' . PMA_generate_common_url($_url_params),
2287 PMA_getIcon('b_tblexport.png', __('Export'), false, true),
2288 '', true, true, '') . "\n";
2290 // show chart
2291 echo PMA_linkOrButton(
2292 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2293 PMA_getIcon('b_chart.png', __('Display chart'), false, true),
2294 '', true, true, '') . "\n";
2297 // CREATE VIEW
2300 * @todo detect privileges to create a view
2301 * (but see 2006-01-19 note in display_create_table.lib.php,
2302 * I think we cannot detect db-specific privileges reliably)
2303 * Note: we don't display a Create view link if we found a PROCEDURE clause
2305 if (!$header_shown) {
2306 echo $header;
2307 $header_shown = TRUE;
2309 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2310 echo PMA_linkOrButton(
2311 'view_create.php' . $url_query,
2312 PMA_getIcon('b_views.png', __('Create view'), false, true),
2313 '', true, true, '') . "\n";
2315 if ($header_shown) {
2316 echo '</fieldset><br />';
2321 * Verifies what to do with non-printable contents (binary or BLOB)
2322 * in Browse mode.
2324 * @uses is_null()
2325 * @uses isset()
2326 * @uses strlen()
2327 * @uses PMA_formatByteDown()
2328 * @uses strpos()
2329 * @uses str_replace()
2330 * @param string $category BLOB|BINARY|GEOMETRY
2331 * @param string $content the binary content
2332 * @param string $transform_function
2333 * @param string $transform_options
2334 * @param string $default_function
2335 * @param object $meta the meta-information about this field
2336 * @return mixed string or float
2338 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2339 $result = '[' . $category;
2340 if (is_null($content)) {
2341 $result .= ' - NULL';
2342 $size = 0;
2343 } elseif (isset($content)) {
2344 $size = strlen($content);
2345 $display_size = PMA_formatByteDown($size, 3, 1);
2346 $result .= ' - '. $display_size[0] . $display_size[1];
2348 $result .= ']';
2350 if (strpos($transform_function, 'octetstream')) {
2351 $result = $content;
2353 if ($size > 0) {
2354 if ($default_function != $transform_function) {
2355 $result = $transform_function($result, $transform_options, $meta);
2356 } else {
2357 $result = $default_function($result, array(), $meta);
2358 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2359 // in this case, restart from the original $content
2360 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2362 /* Create link to download */
2363 if (count($url_params) > 0) {
2364 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2368 return($result);
2372 * Prepares the displayable content of a data cell in Browse mode,
2373 * taking into account foreign key description field and transformations
2375 * @uses is_array()
2376 * @uses PMA_backquote()
2377 * @uses PMA_DBI_try_query()
2378 * @uses PMA_DBI_num_rows()
2379 * @uses PMA_DBI_fetch_row()
2380 * @uses PMA_DBI_free_result()
2381 * @uses $GLOBALS['printview']
2382 * @uses htmlspecialchars()
2383 * @uses PMA_generate_common_url()
2384 * @param string $class
2385 * @param string $condition_field
2386 * @param string $analyzed_sql
2387 * @param object $meta the meta-information about this field
2388 * @param string $map
2389 * @param string $data
2390 * @param string $transform_function
2391 * @param string $default_function
2392 * @param string $nowrap
2393 * @param string $where_comparison
2394 * @param bool $is_field_truncated
2395 * @return string formatted data
2397 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 ) {
2399 // Define classes to be added to this data field based on the type of data
2400 $enum_class = '';
2401 if(strpos($meta->flags, 'enum') !== false) {
2402 $enum_class = ' enum';
2405 $set_class = '';
2406 if(strpos($meta->flags, 'set') !== false) {
2407 $set_class = ' set';
2410 $mime_type_class = '';
2411 if(isset($meta->mimetype)) {
2412 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
2415 // continue the <td> tag started before calling this function:
2416 $result = ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap
2417 . ' ' . ($is_field_truncated ? ' truncated' : '')
2418 . ($transform_function != $default_function ? ' transformed' : '')
2419 . $enum_class . $set_class . $mime_type_class . '">';
2421 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2422 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2423 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2424 if (isset($alias) && strlen($alias)) {
2425 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2426 if ($alias == $meta->name) {
2427 // this change in the parameter does not matter
2428 // outside of the function
2429 $meta->name = $true_column;
2430 } // end if
2431 } // end if
2432 } // end foreach
2433 } // end if
2435 if (isset($map[$meta->name])) {
2436 // Field to display from the foreign table?
2437 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2438 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2439 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2440 . '.' . PMA_backquote($map[$meta->name][0])
2441 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2442 . $where_comparison;
2443 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2444 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2445 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2446 } else {
2447 $dispval = __('Link not found');
2449 @PMA_DBI_free_result($dispresult);
2450 } else {
2451 $dispval = '';
2452 } // end if... else...
2454 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2455 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2456 } else {
2458 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2459 // user chose "relational key" in the display options, so
2460 // the title contains the display field
2461 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2462 } else {
2463 $title = ' title="' . htmlspecialchars($data) . '"';
2466 $_url_params = array(
2467 'db' => $map[$meta->name][3],
2468 'table' => $map[$meta->name][0],
2469 'pos' => '0',
2470 'sql_query' => 'SELECT * FROM '
2471 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2472 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2473 . $where_comparison,
2475 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2476 . '"' . $title . '>';
2478 if ($transform_function != $default_function) {
2479 // always apply a transformation on the real data,
2480 // not on the display field
2481 $result .= $transform_function($data, $transform_options, $meta);
2482 } else {
2483 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2484 // user chose "relational display field" in the
2485 // display options, so show display field in the cell
2486 $result .= $transform_function($dispval, array(), $meta);
2487 } else {
2488 // otherwise display data in the cell
2489 $result .= $transform_function($data, array(), $meta);
2492 $result .= '</a>';
2494 } else {
2495 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2497 $result .= '</td>' . "\n";
2499 return $result;
2503 * Generates a checkbox for multi-row submits
2505 * @uses htmlspecialchars
2506 * @param string $del_url
2507 * @param array $is_display
2508 * @param string $row_no
2509 * @param string $where_clause_html
2510 * @param string $del_query
2511 * @param string $id_suffix
2512 * @param string $class
2513 * @return string the generated HTML
2516 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class) {
2517 $ret = '';
2518 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2519 $ret .= '<td ';
2520 if (! empty($class)) {
2521 $ret .= 'class="' . $class . '"';
2523 $ret .= ' align="center">'
2524 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2525 . ' class="multi_checkbox"'
2526 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2527 . ' </td>';
2529 return $ret;
2533 * Generates an Edit link
2535 * @uses PMA_linkOrButton()
2536 * @param string $edit_url
2537 * @param string $class
2538 * @param string $edit_str
2539 * @param string $where_clause
2540 * @param string $where_clause_html
2541 * @return string the generated HTML
2543 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) {
2544 $ret = '';
2545 if (! empty($edit_url)) {
2546 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2547 . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE);
2549 * Where clause for selecting this row uniquely is provided as
2550 * a hidden input. Used by jQuery scripts for handling inline editing
2552 if(! empty($where_clause)) {
2553 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2555 $ret .= '</span></td>';
2557 return $ret;
2561 * Generates an Copy link
2563 * @uses PMA_linkOrButton()
2564 * @param string $copy_url
2565 * @param string $copy_str
2566 * @param string $where_clause
2567 * @param string $where_clause_html
2568 * @return string the generated HTML
2570 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class) {
2571 $ret = '';
2572 if (! empty($copy_url)) {
2573 $ret .= '<td ';
2574 if (! empty($class)) {
2575 $ret .= 'class="' . $class . '" ';
2577 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2578 . PMA_linkOrButton($copy_url, $copy_str, array(), FALSE);
2580 * Where clause for selecting this row uniquely is provided as
2581 * a hidden input. Used by jQuery scripts for handling inline editing
2583 if(! empty($where_clause)) {
2584 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2586 $ret .= '</span></td>';
2588 return $ret;
2592 * Generates a Delete link
2594 * @uses PMA_linkOrButton()
2595 * @param string $del_url
2596 * @param string $del_str
2597 * @param string $js_conf
2598 * @param string $class
2599 * @return string the generated HTML
2601 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
2602 $ret = '';
2603 if (! empty($del_url)) {
2604 $ret .= '<td ';
2605 if (! empty($class)) {
2606 $ret .= 'class="' . $class . '" ';
2608 $ret .= 'align="center" ' . ' >'
2609 . PMA_linkOrButton($del_url, $del_str, $js_conf, FALSE)
2610 . '</td>';
2612 return $ret;
2616 * Generates checkbox and links at some position (left or right)
2617 * (only called for horizontal mode)
2619 * @uses PMA_generateCheckboxForMulti()
2620 * @uses PMA_generateEditLink()
2621 * @uses PMA_generateDeleteLink()
2622 * @uses PMA_generateCopyLink()
2623 * @param string $position
2624 * @param string $del_url
2625 * @param array $is_display
2626 * @param string $row_no
2627 * @param string $where_clause
2628 * @param string $where_clause_html
2629 * @param string $del_query
2630 * @param string $id_suffix
2631 * @param string $edit_url
2632 * @param string $copy_url
2633 * @param string $class
2634 * @param string $edit_str
2635 * @param string $del_str
2636 * @param string $js_conf
2637 * @return string the generated HTML
2639 function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf) {
2640 $ret = '';
2642 if ($position == 'left') {
2643 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2645 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2647 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2649 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2651 } elseif ($position == 'right') {
2652 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2654 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2656 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2658 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');
2660 return $ret;