Translation update done using Pootle.
[phpmyadmin.git] / libraries / display_tbl.lib.php
blob28db08d93d8efbedb5cbeb170f524e29974835d8
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_disp_mode the synthetic value for display_mode (see a few
32 * lines above for explanations)
33 * @param integer &$the_total 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 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
74 // 2.0 Print view -> set all elements to false!
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';
83 } elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse']
84 || $GLOBALS['is_maint'] || $GLOBALS['is_explain']
85 ) {
86 // 2.1 Statement is a "SELECT COUNT", a
87 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
88 // contains a "PROC ANALYSE" part
89 $do_display['edit_lnk'] = 'nn'; // no edit link
90 $do_display['del_lnk'] = 'nn'; // no delete link
91 $do_display['sort_lnk'] = (string) '0';
92 $do_display['nav_bar'] = (string) '0';
93 $do_display['ins_row'] = (string) '0';
94 $do_display['bkm_form'] = (string) '1';
95 if ($GLOBALS['is_maint']) {
96 $do_display['text_btn'] = (string) '1';
97 } else {
98 $do_display['text_btn'] = (string) '0';
100 $do_display['pview_lnk'] = (string) '1';
101 } elseif ($GLOBALS['is_show']) {
102 // 2.2 Statement is a "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';
123 } else {
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 $prev_table = $fields_meta[0]->table;
128 $do_display['text_btn'] = (string) '1';
129 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
130 $is_link = ($do_display['edit_lnk'] != 'nn'
131 || $do_display['del_lnk'] != 'nn'
132 || $do_display['sort_lnk'] != '0'
133 || $do_display['ins_row'] != '0');
134 // 2.3.2 Displays edit/delete/sort/insert links?
135 if ($is_link
136 && ($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 * Return true if we are executing a query in the form of
189 * "SELECT * FROM <a table> ..."
191 * @return boolean
193 function PMA_isSelect()
195 // global variables set from sql.php
196 global $is_count, $is_export, $is_func, $is_analyse;
197 global $analyzed_sql;
199 return ! ($is_count || $is_export || $is_func || $is_analyse)
200 && count($analyzed_sql[0]['select_expr']) == 0
201 && isset($analyzed_sql[0]['queryflags']['select_from'])
202 && count($analyzed_sql[0]['table_ref']) == 1;
207 * Displays a navigation button
209 * @param string $caption iconic caption for button
210 * @param string $title text for button
211 * @param integer $pos position for next query
212 * @param string $html_sql_query query ready for display
213 * @param string $onsubmit optional onsubmit clause
214 * @param string $input_for_real_end optional hidden field for special treatment
215 * @param string $onclick optional onclick clause
217 * @return nothing
219 * @global string $db the database name
220 * @global string $table the table name
221 * @global string $goto the URL to go back in case of errors
223 * @access private
225 * @see PMA_displayTableNavigation()
227 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '')
230 global $db, $table, $goto;
232 $caption_output = '';
233 // for true or 'both'
234 if ($GLOBALS['cfg']['NavigationBarIconic']) {
235 $caption_output .= $caption;
237 // for false or 'both'
238 if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
239 $caption_output .= '&nbsp;' . $title;
241 $title_output = ' title="' . $title . '"';
243 <td>
244 <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
245 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
246 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
247 <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
248 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
249 <?php echo $input_for_real_end; ?>
250 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax" ' : '' ); ?> value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
251 </form>
252 </td>
253 <?php
254 } // end function PMA_displayTableNavigationOneButton()
257 * Displays a navigation bar to browse among the results of a SQL query
259 * @param integer $pos_next the offset for the "next" page
260 * @param integer $pos_prev the offset for the "previous" page
261 * @param string $sql_query the URL-encoded query
262 * @param string $id_for_direction_dropdown the id for the direction dropdown
264 * @return nothing
266 * @global string $db the database name
267 * @global string $table the table name
268 * @global string $goto the URL to go back in case of errors
269 * @global integer $num_rows the total number of rows returned by the
270 * SQL query
271 * @global integer $unlim_num_rows the total number of rows returned by the
272 * SQL any programmatically appended "LIMIT" clause
273 * @global boolean $is_innodb whether its InnoDB or not
274 * @global array $showtable table definitions
276 * @access private
278 * @see PMA_displayTable()
280 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
282 global $db, $table, $goto;
283 global $num_rows, $unlim_num_rows;
284 global $is_innodb;
285 global $showtable;
287 // here, using htmlentities() would cause problems if the query
288 // contains accented characters
289 $html_sql_query = htmlspecialchars($sql_query);
292 * @todo move this to a central place
293 * @todo for other future table types
295 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
299 <!-- Navigation bar -->
300 <table border="0" cellpadding="0" cellspacing="0" class="navigation">
301 <tr>
302 <td class="navigation_separator"></td>
303 <?php
304 // Move to the beginning or to the previous page
305 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
306 PMA_displayTableNavigationOneButton('&lt;&lt;', _pgettext('First page', 'Begin'), 0, $html_sql_query);
307 PMA_displayTableNavigationOneButton('&lt;', _pgettext('Previous page', 'Previous'), $pos_prev, $html_sql_query);
309 } // end move back
311 //page redirection
312 // (unless we are showing all records)
313 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
314 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
315 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
317 if ($nbTotalPage > 1) { //if2
319 <td>
320 <?php
321 $_url_params = array(
322 'db' => $db,
323 'table' => $table,
324 'sql_query' => $sql_query,
325 'goto' => $goto,
327 //<form> to keep the form alignment of button < and <<
328 // and also to know what to execute when the selector changes
329 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
330 echo PMA_pageselector(
331 $_SESSION['tmp_user_values']['max_rows'],
332 $pageNow,
333 $nbTotalPage,
334 200,
341 </form>
342 </td>
343 <?php
344 } //_if2
345 } //_if1
347 // Display the "Show all" button if allowed
348 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
349 echo "\n";
351 <td>
352 <form action="sql.php" method="post">
353 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
354 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
355 <input type="hidden" name="pos" value="0" />
356 <input type="hidden" name="session_max_rows" value="all" />
357 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
358 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
359 </form>
360 </td>
361 <?php
362 } // end show all
364 // Move to the next page or to the last one
365 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
366 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
368 // display the Next button
369 PMA_displayTableNavigationOneButton('&gt;',
370 _pgettext('Next page', 'Next'),
371 $pos_next,
372 $html_sql_query);
374 // prepare some options for the End button
375 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
376 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
377 // no backquote around this message
378 $onclick = '';
379 } else {
380 $input_for_real_end = $onclick = '';
383 // display the End button
384 PMA_displayTableNavigationOneButton('&gt;&gt;',
385 _pgettext('Last page', 'End'),
386 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
387 $html_sql_query,
388 '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') . '"',
389 $input_for_real_end,
390 $onclick
392 } // end move toward
394 // show separator if pagination happen
395 if ($nbTotalPage > 1) {
396 echo '<td><div class="navigation_separator">|</div></td>';
399 <td>
400 <div class="save_edited hide">
401 <input type="submit" value="<?php echo __('Save edited data'); ?>" />
402 <div class="navigation_separator">|</div>
403 </div>
404 </td>
405 <td>
406 <div class="restore_column hide">
407 <input type="submit" value="<?php echo __('Restore column order'); ?>" />
408 <div class="navigation_separator">|</div>
409 </div>
410 </td>
412 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
413 // of $cfg['MaxExactCountViews']; in this case, avoid passing
414 // the 5th parameter to checkFormElementInRange()
415 // (this means we can't validate the upper limit ?>
416 <td class="navigation_goto">
417 <form action="sql.php" method="post"
418 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 : ''; ?>))">
419 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
420 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
421 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
422 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
423 <?php echo __('Start row') . ': ' . "\n"; ?>
424 <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
425 <?php echo __('Number of rows') . ': ' . "\n"; ?>
426 <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()" />
427 <?php
428 if ($GLOBALS['cfg']['ShowDisplayDirection']) {
429 // Display mode (horizontal/vertical and repeat headers)
430 echo __('Mode') . ': ' . "\n";
431 $choices = array(
432 'horizontal' => __('horizontal'),
433 'horizontalflipped' => __('horizontal (rotated headers)'),
434 'vertical' => __('vertical'));
435 echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
436 unset($choices);
439 printf(__('Headers every %s rows'),
440 '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />');
441 echo "\n";
443 </form>
444 </td>
445 <td class="navigation_separator"></td>
446 </tr>
447 </table>
449 <?php
450 } // end of the 'PMA_displayTableNavigation()' function
454 * Displays the headers of the results table
456 * @param array &$is_display which elements to display
457 * @param array &$fields_meta the list of fields properties
458 * @param integer $fields_cnt the total number of fields returned by the SQL query
459 * @param array $analyzed_sql the analyzed query
460 * @param string $sort_expression sort expression
461 * @param string $sort_expression_nodirection sort expression without direction
462 * @param string $sort_direction sort direction
464 * @return boolean $clause_is_unique
466 * @global string $db the database name
467 * @global string $table the table name
468 * @global string $goto the URL to go back in case of errors
469 * @global string $sql_query the SQL query
470 * @global integer $num_rows the total number of rows returned by the
471 * SQL query
472 * @global array $vertical_display informations used with vertical display
473 * mode
475 * @access private
477 * @see PMA_displayTable()
479 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
481 global $db, $table, $goto;
482 global $sql_query, $num_rows;
483 global $vertical_display, $highlight_columns;
485 // required to generate sort links that will remember whether the
486 // "Show all" button has been clicked
487 $sql_md5 = md5($GLOBALS['sql_query']);
488 $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
490 if ($analyzed_sql == '') {
491 $analyzed_sql = array();
494 // can the result be sorted?
495 if ($is_display['sort_lnk'] == '1') {
497 // Just as fallback
498 $unsorted_sql_query = $sql_query;
499 if (isset($analyzed_sql[0]['unsorted_query'])) {
500 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
502 // Handles the case of multiple clicks on a column's header
503 // which would add many spaces before "ORDER BY" in the
504 // generated query.
505 $unsorted_sql_query = trim($unsorted_sql_query);
507 // sorting by indexes, only if it makes sense (only one table ref)
508 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
509 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
510 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
512 // grab indexes data:
513 $indexes = PMA_Index::getFromTable($table, $db);
515 // do we have any index?
516 if ($indexes) {
518 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
519 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
520 $span = $fields_cnt;
521 if ($is_display['edit_lnk'] != 'nn') {
522 $span++;
524 if ($is_display['del_lnk'] != 'nn') {
525 $span++;
527 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
528 $span++;
530 } else {
531 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
534 echo '<form action="sql.php" method="post">' . "\n";
535 echo PMA_generate_common_hidden_inputs($db, $table);
536 echo __('Sort by key') . ': <select name="sql_query" class="autosubmit">' . "\n";
537 $used_index = false;
538 $local_order = (isset($sort_expression) ? $sort_expression : '');
539 foreach ($indexes as $index) {
540 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
541 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
542 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
543 echo '<option value="'
544 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
545 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
546 . '>' . htmlspecialchars($index->getName()) . ' ('
547 . __('Ascending') . ')</option>';
548 echo '<option value="'
549 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
550 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
551 . '>' . htmlspecialchars($index->getName()) . ' ('
552 . __('Descending') . ')</option>';
554 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
555 echo '</select>' . "\n";
556 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
557 echo '</form>' . "\n";
563 // Output data needed for grid editing
564 echo '<input id="save_cells_at_once" type="hidden" value="' . $GLOBALS['cfg']['SaveCellsAtOnce'] . '" />';
565 echo '<div class="common_hidden_inputs">';
566 echo PMA_generate_common_hidden_inputs($db, $table);
567 echo '</div>';
568 // Output data needed for column reordering and show/hide column
569 if (PMA_isSelect()) {
570 // generate the column order, if it is set
571 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
572 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
573 if ($col_order) {
574 echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
576 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
577 if ($col_visib) {
578 echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
580 // generate table create time
581 if (! PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) {
582 echo '<input id="table_create_time" type="hidden" value="' .
583 PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
588 $vertical_display['emptypre'] = 0;
589 $vertical_display['emptyafter'] = 0;
590 $vertical_display['textbtn'] = '';
592 // Display options (if we are not in print view)
593 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
594 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
595 if ($GLOBALS['cfg']['AjaxEnable']) {
596 echo ' class="ajax" ';
598 echo '>';
599 $url_params = array(
600 'db' => $db,
601 'table' => $table,
602 'sql_query' => $sql_query,
603 'goto' => $goto,
604 'display_options_form' => 1
606 echo PMA_generate_common_hidden_inputs($url_params);
607 echo '<br />';
608 PMA_generate_slider_effect('displayoptions',__('Options'));
609 echo '<fieldset>';
611 echo '<div class="formelement">';
612 $choices = array(
613 'P' => __('Partial texts'),
614 'F' => __('Full texts')
616 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
617 echo '</div>';
619 // prepare full/partial text button or link
620 if ($_SESSION['tmp_user_values']['display_text']=='F') {
621 // currently in fulltext mode so show the opposite link
622 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
623 $tmp_txt = __('Partial texts');
624 $url_params['display_text'] = 'P';
625 } else {
626 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
627 $tmp_txt = __('Full texts');
628 $url_params['display_text'] = 'F';
631 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
632 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
633 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
634 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
637 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
638 echo '<div class="formelement">';
639 $choices = array(
640 'K' => __('Relational key'),
641 'D' => __('Relational display column')
643 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
644 echo '</div>';
647 echo '<div class="formelement">';
648 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
649 echo '<br />';
650 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
651 echo '<br />';
652 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
653 echo '</div>';
655 // I would have preferred to name this "display_transformation".
656 // This is the only way I found to be able to keep this setting sticky
657 // per SQL query, and at the same time have a default that displays
658 // the transformations.
659 echo '<div class="formelement">';
660 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
661 echo '</div>';
663 echo '<div class="formelement">';
664 $choices = array(
665 'GEOM' => __('Geometry'),
666 'WKT' => __('Well Known Text'),
667 'WKB' => __('Well Known Binary')
669 PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
670 echo '</div>';
672 echo '<div class="clearfloat"></div>';
673 echo '</fieldset>';
675 echo '<fieldset class="tblFooters">';
676 echo '<input type="submit" value="' . __('Go') . '" />';
677 echo '</fieldset>';
678 echo '</div>';
679 echo '</form>';
682 // Start of form for multi-rows edit/delete/export
684 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
685 echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
686 if ($GLOBALS['cfg']['AjaxEnable']) {
687 echo ' class="ajax" ';
689 echo '>' . "\n";
690 echo PMA_generate_common_hidden_inputs($db, $table, 1);
691 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
694 echo '<table id="table_results" class="data';
695 if ($GLOBALS['cfg']['AjaxEnable']) {
696 echo ' ajax';
698 echo '">' . "\n";
699 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
700 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
701 echo '<thead><tr>' . "\n";
704 // 1. Displays the full/partial text button (part 1)...
705 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
706 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
707 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
708 ? ' colspan="4"'
709 : '';
710 } else {
711 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
712 ? ' rowspan="4"'
713 : '';
716 // ... before the result table
717 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
718 && $is_display['text_btn'] == '1') {
719 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
720 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
721 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
723 <th colspan="<?php echo $fields_cnt; ?>"></th>
724 </tr>
725 <tr>
726 <?php
727 } // end horizontal/horizontalflipped mode
728 else {
730 <tr>
731 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
732 </tr>
733 <?php
734 } // end vertical mode
737 // ... at the left column of the result table header if possible
738 // and required
739 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
740 && $is_display['text_btn'] == '1') {
741 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
742 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
743 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
745 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
746 <?php
747 } // end horizontal/horizontalflipped mode
748 else {
749 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
750 . ' ' . "\n"
751 . ' </th>' . "\n";
752 } // end vertical mode
755 // ... elseif no button, displays empty(ies) col(s) if required
756 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
757 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
758 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
759 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
760 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
762 <td<?php echo $colspan; ?>></td>
763 <?php
764 } // end horizontal/horizontalfipped mode
765 else {
766 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
767 } // end vertical mode
770 // ... elseif display an empty column if the actions links are disabled to match the rest of the table
771 elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none' && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
772 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
773 echo '<th></th>';
776 // 2. Displays the fields' name
777 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
778 // statement (see 2.1.3)
780 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
781 // Do not show comments, if using horizontalflipped mode, because of space usage
782 if ($GLOBALS['cfg']['ShowBrowseComments']
783 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
784 $comments_map = array();
785 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
786 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
787 $tb = $tbl['table_true_name'];
788 $comments_map[$tb] = PMA_getComments($db, $tb);
789 unset($tb);
794 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
795 require_once './libraries/transformations.lib.php';
796 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
799 // See if we have to highlight any header fields of a WHERE query.
800 // Uses SQL-Parser results.
801 $highlight_columns = array();
802 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
803 isset($analyzed_sql[0]['where_clause_identifiers'])) {
805 $wi = 0;
806 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
807 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
808 $highlight_columns[$wci] = 'true';
813 if (PMA_isSelect()) {
814 // prepare to get the column order, if available
815 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
816 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
817 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
818 } else {
819 $col_order = false;
820 $col_visib = false;
823 for ($j = 0; $j < $fields_cnt; $j++) {
824 // assign $i with appropriate column order
825 $i = $col_order ? $col_order[$j] : $j;
826 // See if this column should get highlight because it's used in the
827 // where-query.
828 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
829 $condition_field = true;
830 } else {
831 $condition_field = false;
834 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
835 if (isset($comments_map) &&
836 isset($comments_map[$fields_meta[$i]->table]) &&
837 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
838 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
839 } else {
840 $comments = '';
843 // 2.1 Results can be sorted
844 if ($is_display['sort_lnk'] == '1') {
846 // 2.1.1 Checks if the table name is required; it's the case
847 // for a query with a "JOIN" statement and if the column
848 // isn't aliased, or in queries like
849 // SELECT `1`.`master_field` , `2`.`master_field`
850 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
852 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
853 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
854 } else {
855 $sort_tbl = '';
858 // 2.1.2 Checks if the current column is used to sort the
859 // results
860 // the orgname member does not exist for all MySQL versions
861 // but if found, it's the one on which to sort
862 $name_to_use_in_sort = $fields_meta[$i]->name;
863 $is_orgname = false;
864 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
865 $name_to_use_in_sort = $fields_meta[$i]->orgname;
866 $is_orgname = true;
868 // $name_to_use_in_sort might contain a space due to
869 // formatting of function expressions like "COUNT(name )"
870 // so we remove the space in this situation
871 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
873 if (empty($sort_expression)) {
874 $is_in_sort = false;
875 } else {
876 // Field name may be preceded by a space, or any number
877 // of characters followed by a dot (tablename.fieldname)
878 // so do a direct comparison for the sort expression;
879 // this avoids problems with queries like
880 // "SELECT id, count(id)..." and clicking to sort
881 // on id or on count(id).
882 // Another query to test this:
883 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
884 // (and try clicking on each column's header twice)
885 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
886 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
888 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
890 // 2.1.3 Check the field name for a bracket.
891 // If it contains one, it's probably a function column
892 // like 'COUNT(`field`)'
893 // It still might be a column name of a view. See bug #3383711
894 // Check is_orgname.
895 if (strpos($name_to_use_in_sort, '(') !== false && ! $is_orgname) {
896 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
897 } else {
898 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
900 unset($name_to_use_in_sort);
901 unset($is_orgname);
903 // 2.1.4 Do define the sorting URL
904 if (! $is_in_sort) {
905 // patch #455484 ("Smart" order)
906 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
907 if ($GLOBALS['cfg']['Order'] === 'SMART') {
908 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
909 } else {
910 $sort_order .= $GLOBALS['cfg']['Order'];
912 $order_img = '';
913 } elseif ('DESC' == $sort_direction) {
914 $sort_order .= ' ASC';
915 $order_img = ' <img class="icon ic_s_desc" src="themes/dot.gif" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
916 } else {
917 $sort_order .= ' DESC';
918 $order_img = ' <img class="icon ic_s_asc" src="themes/dot.gif" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
921 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
922 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
923 } else {
924 $sorted_sql_query = $unsorted_sql_query . $sort_order;
926 $_url_params = array(
927 'db' => $db,
928 'table' => $table,
929 'sql_query' => $sorted_sql_query,
930 'session_max_rows' => $session_max_rows
932 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
934 // 2.1.5 Displays the sorting URL
935 // enable sort order swapping for image
936 $order_link_params = array();
937 if (isset($order_img) && $order_img!='') {
938 if (strstr($order_img, 'asc')) {
939 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
940 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
941 } elseif (strstr($order_img, 'desc')) {
942 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
943 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
946 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
947 if (PMA_USR_BROWSER_AGENT == 'IE') {
948 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
949 } else {
950 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
953 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
954 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
955 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
957 $order_link_params['title'] = __('Sort');
958 $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));
959 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
961 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
962 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
963 echo '<th';
964 $th_class = array();
965 $th_class[] = 'draggable';
966 if ($col_visib && !$col_visib[$j]) {
967 $th_class[] = 'hide';
969 if ($condition_field) {
970 $th_class[] = 'condition';
972 $th_class[] = 'column_heading';
973 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
974 $th_class[] = 'pointer';
976 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
977 $th_class[] = 'marker';
979 echo ' class="' . implode(' ', $th_class) . '"';
981 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
982 echo ' valign="bottom"';
984 echo '>' . $order_link . $comments . '</th>';
986 $vertical_display['desc'][] = ' <th '
987 . 'class="draggable'
988 . ($condition_field ? ' condition' : '')
989 . '">' . "\n"
990 . $order_link . $comments . ' </th>' . "\n";
991 } // end if (2.1)
993 // 2.2 Results can't be sorted
994 else {
995 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
996 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
997 echo '<th';
998 $th_class = array();
999 $th_class[] = 'draggable';
1000 if ($col_visib && !$col_visib[$j]) {
1001 $th_class[] = 'hide';
1003 if ($condition_field) {
1004 $th_class[] = 'condition';
1006 echo ' class="' . implode(' ', $th_class) . '"';
1007 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1008 echo ' valign="bottom"';
1010 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1011 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
1012 echo ' style="direction: ltr; writing-mode: tb-rl;"';
1014 echo '>';
1015 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1016 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
1017 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
1018 } else {
1019 echo htmlspecialchars($fields_meta[$i]->name);
1021 echo "\n" . $comments . '</th>';
1023 $vertical_display['desc'][] = ' <th '
1024 . 'class="draggable'
1025 . ($condition_field ? ' condition"' : '')
1026 . '">' . "\n"
1027 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
1028 . $comments . ' </th>';
1029 } // end else (2.2)
1030 } // end for
1032 // 3. Displays the needed checkboxes at the right
1033 // column of the result table header if possible and required...
1034 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1035 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
1036 && $is_display['text_btn'] == '1') {
1037 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1038 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1039 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1040 echo "\n";
1042 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
1043 </th>
1044 <?php
1045 } // end horizontal/horizontalflipped mode
1046 else {
1047 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
1048 . ' ' . "\n"
1049 . ' </th>' . "\n";
1050 } // end vertical mode
1053 // ... elseif no button, displays empty columns if required
1054 // (unless coming from Browse mode print view)
1055 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1056 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
1057 && (!$GLOBALS['is_header_sent'])) {
1058 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1059 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1060 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1061 echo "\n";
1063 <td<?php echo $colspan; ?>></td>
1064 <?php
1065 } // end horizontal/horizontalflipped mode
1066 else {
1067 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
1068 } // end vertical mode
1071 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1072 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1074 </tr>
1075 </thead>
1076 <?php
1079 return true;
1080 } // end of the 'PMA_displayTableHeaders()' function
1084 * Prepares the display for a value
1086 * @param string $class class of table cell
1087 * @param bool $condition_field whether to add CSS class condition
1088 * @param string $value value to display
1090 * @return string the td
1092 function PMA_buildValueDisplay($class, $condition_field, $value)
1094 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
1098 * Prepares the display for a null value
1100 * @param string $class class of table cell
1101 * @param bool $condition_field whether to add CSS class condition
1103 * @return string the td
1105 function PMA_buildNullDisplay($class, $condition_field)
1107 // the null class is needed for grid editing
1108 return '<td align="right"' . ' class="' . $class . ($condition_field ? ' condition' : '') . ' null"><i>NULL</i></td>';
1112 * Prepares the display for an empty value
1114 * @param string $class class of table cell
1115 * @param bool $condition_field whether to add CSS class condition
1116 * @param object $meta the meta-information about this field
1117 * @param string $align cell allignment
1119 * @return string the td
1121 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '')
1123 $nowrap = ' nowrap';
1124 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1128 * Adds the relavant classes.
1130 * @param string $class class of table cell
1131 * @param bool $condition_field whether to add CSS class condition
1132 * @param object $meta the meta-information about this field
1133 * @param string $nowrap avoid wrapping
1134 * @param bool $is_field_truncated is field truncated (display ...)
1135 * @param string $transform_function transformation function
1136 * @param string $default_function default transformation function
1138 * @return string the list of classes
1140 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '')
1142 // Define classes to be added to this data field based on the type of data
1143 $enum_class = '';
1144 if (strpos($meta->flags, 'enum') !== false) {
1145 $enum_class = ' enum';
1148 $set_class = '';
1149 if (strpos($meta->flags, 'set') !== false) {
1150 $set_class = ' set';
1153 $bit_class = '';
1154 if (strpos($meta->type, 'bit') !== false) {
1155 $bit_class = ' bit';
1158 $mime_type_class = '';
1159 if (isset($meta->mimetype)) {
1160 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
1163 $result = $class . ($condition_field ? ' condition' : '') . $nowrap
1164 . ' ' . ($is_field_truncated ? ' truncated' : '')
1165 . ($transform_function != $default_function ? ' transformed' : '')
1166 . $enum_class . $set_class . $bit_class . $mime_type_class;
1168 return $result;
1171 * Displays the body of the results table
1173 * @param integer &$dt_result the link id associated to the query which results have
1174 * to be displayed
1175 * @param array &$is_display which elements to display
1176 * @param array $map the list of relations
1177 * @param array $analyzed_sql the analyzed query
1179 * @return boolean always true
1181 * @global string $db the database name
1182 * @global string $table the table name
1183 * @global string $goto the URL to go back in case of errors
1184 * @global string $sql_query the SQL query
1185 * @global array $fields_meta the list of fields properties
1186 * @global integer $fields_cnt the total number of fields returned by
1187 * the SQL query
1188 * @global array $vertical_display informations used with vertical display
1189 * mode
1190 * @global array $highlight_columns column names to highlight
1191 * @global array $row current row data
1193 * @access private
1195 * @see PMA_displayTable()
1197 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
1199 global $db, $table, $goto;
1200 global $sql_query, $fields_meta, $fields_cnt;
1201 global $vertical_display, $highlight_columns;
1202 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1204 $url_sql_query = $sql_query;
1206 // query without conditions to shorten URLs when needed, 200 is just
1207 // guess, it should depend on remaining URL length
1209 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1210 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1211 strlen($sql_query) > 200) {
1213 $url_sql_query = 'SELECT ';
1214 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1215 $url_sql_query .= ' DISTINCT ';
1217 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1218 if (!empty($analyzed_sql[0]['from_clause'])) {
1219 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1223 if (! is_array($map)) {
1224 $map = array();
1226 $row_no = 0;
1227 $vertical_display['edit'] = array();
1228 $vertical_display['copy'] = array();
1229 $vertical_display['delete'] = array();
1230 $vertical_display['data'] = array();
1231 $vertical_display['row_delete'] = array();
1232 // name of the class added to all grid editable elements
1233 $grid_edit_class = 'grid_edit';
1235 // prepare to get the column order, if available
1236 if (PMA_isSelect()) {
1237 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1238 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1239 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1240 } else {
1241 $col_order = false;
1242 $col_visib = false;
1245 // Correction University of Virginia 19991216 in the while below
1246 // Previous code assumed that all tables have keys, specifically that
1247 // the phpMyAdmin GUI should support row delete/edit only for such
1248 // tables.
1249 // Although always using keys is arguably the prescribed way of
1250 // defining a relational table, it is not required. This will in
1251 // particular be violated by the novice.
1252 // We want to encourage phpMyAdmin usage by such novices. So the code
1253 // below has been changed to conditionally work as before when the
1254 // table being displayed has one or more keys; but to display
1255 // delete/edit options correctly for tables without keys.
1257 $odd_row = true;
1258 while ($row = PMA_DBI_fetch_row($dt_result)) {
1259 // "vertical display" mode stuff
1260 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1261 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1262 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1264 echo '<tr>' . "\n";
1265 if ($vertical_display['emptypre'] > 0) {
1266 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1267 .' &nbsp;</th>' . "\n";
1268 } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1269 echo ' <th></th>' . "\n";
1272 foreach ($vertical_display['desc'] as $val) {
1273 echo $val;
1276 if ($vertical_display['emptyafter'] > 0) {
1277 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1278 .' &nbsp;</th>' . "\n";
1280 echo '</tr>' . "\n";
1281 } // end if
1283 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1284 $odd_row = ! $odd_row;
1286 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1287 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1288 // pointer code part
1289 echo '<tr class="' . $alternating_color_class . '">';
1293 // 1. Prepares the row
1294 // 1.1 Results from a "SELECT" statement -> builds the
1295 // WHERE clause to use in links (a unique key if possible)
1297 * @todo $where_clause could be empty, for example a table
1298 * with only one field and it's a BLOB; in this case,
1299 * avoid to display the delete and edit links
1301 list($where_clause, $clause_is_unique, $condition_array) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1302 $where_clause_html = urlencode($where_clause);
1304 // 1.2 Defines the URLs for the modify/delete link(s)
1306 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1307 // We need to copy the value or else the == 'both' check will always return true
1309 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1310 $iconic_spacer = '<div class="nowrap">';
1311 } else {
1312 $iconic_spacer = '';
1315 // 1.2.1 Modify link(s)
1316 if ($is_display['edit_lnk'] == 'ur') { // update row case
1317 $_url_params = array(
1318 'db' => $db,
1319 'table' => $table,
1320 'where_clause' => $where_clause,
1321 'clause_is_unique' => $clause_is_unique,
1322 'sql_query' => $url_sql_query,
1323 'goto' => 'sql.php',
1325 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1326 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1328 $edit_str = PMA_getIcon('b_edit.png', __('Edit'));
1329 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'));
1331 // Class definitions required for grid editing jQuery scripts
1332 $edit_anchor_class = "edit_row_anchor";
1333 if ( $clause_is_unique == 0) {
1334 $edit_anchor_class .= ' nonunique';
1336 } // end if (1.2.1)
1338 // 1.2.2 Delete/Kill link(s)
1339 if ($is_display['del_lnk'] == 'dr') { // delete row case
1340 $_url_params = array(
1341 'db' => $db,
1342 'table' => $table,
1343 'sql_query' => $url_sql_query,
1344 'message_to_show' => __('The row has been deleted'),
1345 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1347 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1349 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1350 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1352 $_url_params = array(
1353 'db' => $db,
1354 'table' => $table,
1355 'sql_query' => $del_query,
1356 'message_to_show' => __('The row has been deleted'),
1357 'goto' => $lnk_goto,
1359 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1361 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1362 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1363 . ($clause_is_unique ? '' : ' LIMIT 1');
1364 $del_str = PMA_getIcon('b_drop.png', __('Delete'));
1365 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1367 $_url_params = array(
1368 'db' => $db,
1369 'table' => $table,
1370 'sql_query' => $url_sql_query,
1371 'goto' => 'main.php',
1373 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1375 $_url_params = array(
1376 'db' => 'mysql',
1377 'sql_query' => 'KILL ' . $row[0],
1378 'goto' => $lnk_goto,
1380 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1381 $del_query = 'KILL ' . $row[0];
1382 $js_conf = 'KILL ' . $row[0];
1383 $del_str = PMA_getIcon('b_drop.png', __('Kill'));
1384 } // end if (1.2.2)
1386 // 1.3 Displays the links at left if required
1387 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1388 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1389 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1390 if (! isset($js_conf)) {
1391 $js_conf = '';
1393 echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1394 } else if (($GLOBALS['cfg']['RowActionLinks'] == 'none')
1395 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1396 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1397 if (! isset($js_conf)) {
1398 $js_conf = '';
1400 echo PMA_generateCheckboxAndLinks('none', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1401 } // end if (1.3)
1402 } // end if (1)
1404 // 2. Displays the rows' values
1406 for ($j = 0; $j < $fields_cnt; ++$j) {
1407 // assign $i with appropriate column order
1408 $i = $col_order ? $col_order[$j] : $j;
1410 $meta = $fields_meta[$i];
1411 $not_null_class = $meta->not_null ? 'not_null' : '';
1412 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1413 $hide_class = ($col_visib && !$col_visib[$j] &&
1414 // hide per <td> only if the display direction is not vertical
1415 $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ? 'hide' : '';
1416 // handle datetime-related class, for grid editing
1417 if (substr($meta->type, 0, 9) == 'timestamp' || $meta->type == 'datetime') {
1418 $field_type_class = 'datetimefield';
1419 } else if ($meta->type == 'date') {
1420 $field_type_class = 'datefield';
1421 } else {
1422 $field_type_class = '';
1424 $pointer = $i;
1425 $is_field_truncated = false;
1426 //If the previous column had blob data, we need to reset the class
1427 // to $inline_edit_class
1428 $class = 'data ' . $grid_edit_class . ' ' . $not_null_class . ' ' . $relation_class . ' ' . $hide_class . ' ' . $field_type_class; //' ' . $alternating_color_class .
1430 // See if this column should get highlight because it's used in the
1431 // where-query.
1432 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1433 $condition_field = true;
1434 } else {
1435 $condition_field = false;
1438 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1439 // the row number corresponds to a data row, not HTML table row
1440 $class .= ' row_' . $row_no;
1441 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1442 $class .= ' vpointer';
1444 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1445 $class .= ' vmarker';
1447 }// end if
1449 // Wrap MIME-transformations. [MIME]
1450 $default_function = 'default_function'; // default_function
1451 $transform_function = $default_function;
1452 $transform_options = array();
1454 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1456 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1457 $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name]['transformation']);
1459 if (file_exists('./libraries/transformations/' . $include_file)) {
1460 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1462 require_once './libraries/transformations/' . $include_file;
1464 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1465 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1466 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1467 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1469 } // end if file_exists
1470 } // end if transformation is set
1471 } // end if mime/transformation works.
1473 $_url_params = array(
1474 'db' => $db,
1475 'table' => $table,
1476 'where_clause' => $where_clause,
1477 'transform_key' => $meta->name,
1480 if (! empty($sql_query)) {
1481 $_url_params['sql_query'] = $url_sql_query;
1484 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1486 // n u m e r i c
1487 if ($meta->numeric == 1) {
1489 // if two fields have the same name (this is possible
1490 // with self-join queries, for example), using $meta->name
1491 // will show both fields NULL even if only one is NULL,
1492 // so use the $pointer
1494 if (! isset($row[$i]) || is_null($row[$i])) {
1495 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1496 } elseif ($row[$i] != '') {
1498 $nowrap = ' nowrap';
1499 $where_comparison = ' = ' . $row[$i];
1501 $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);
1502 } else {
1503 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1506 // b l o b
1508 } elseif (stristr($meta->type, 'BLOB')) {
1509 // PMA_mysql_fetch_fields returns BLOB in place of
1510 // TEXT fields type so we have to ensure it's really a BLOB
1511 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1513 if (stristr($field_flags, 'BINARY')) {
1514 // remove 'grid_edit' from $class as we can't edit binary data.
1515 $class = str_replace('grid_edit', '', $class);
1517 if (! isset($row[$i]) || is_null($row[$i])) {
1518 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1519 } else {
1520 // for blobstreaming
1521 // if valid BS reference exists
1522 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1523 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1524 } else {
1525 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1528 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1529 unset($blobtext);
1531 // not binary:
1532 } else {
1533 if (! isset($row[$i]) || is_null($row[$i])) {
1534 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1535 } elseif ($row[$i] != '') {
1536 // if a transform function for blob is set, none of these replacements will be made
1537 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1538 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1539 $is_field_truncated = true;
1541 // displays all space characters, 4 space
1542 // characters for tabulations and <cr>/<lf>
1543 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1545 if ($is_field_truncated) {
1546 $class .= ' truncated';
1549 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1550 } else {
1551 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1554 // g e o m e t r y
1555 } elseif ($meta->type == 'geometry') {
1557 // Remove 'grid_edit' from $class as we do not allow to inline-edit geometry data.
1558 $class = str_replace('grid_edit', '', $class);
1560 if (! isset($row[$i]) || is_null($row[$i])) {
1561 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1562 } elseif ($row[$i] != '') {
1563 // Display as [GEOMETRY - (size)]
1564 if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
1565 $geometry_text = PMA_handle_non_printable_contents(
1566 'GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function,
1567 $transform_options, $default_function, $meta
1569 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
1570 $class, $condition_field, $geometry_text
1573 // Display in Well Known Text(WKT) format.
1574 } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
1575 // Convert to WKT format
1576 $wktval = PMA_asWKT($row[$i]);
1578 if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
1579 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1581 $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1582 $is_field_truncated = true;
1585 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1586 $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
1587 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1590 // Display in Well Known Binary(WKB) format.
1591 } else {
1592 if ($_SESSION['tmp_user_values']['display_binary']) {
1593 if ($_SESSION['tmp_user_values']['display_binary_as_hex']
1594 && PMA_contains_nonprintable_ascii($row[$i])
1596 $wkbval = PMA_substr(bin2hex($row[$i]), 8);
1597 } else {
1598 $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1601 if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
1602 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1604 $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1605 $is_field_truncated = true;
1608 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1609 $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
1610 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1612 } else {
1613 $wkbval = PMA_handle_non_printable_contents(
1614 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
1616 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
1619 } else {
1620 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1623 // n o t n u m e r i c a n d n o t B L O B
1624 } else {
1625 if (! isset($row[$i]) || is_null($row[$i])) {
1626 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1627 } elseif ($row[$i] != '') {
1628 // support blanks in the key
1629 $relation_id = $row[$i];
1631 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1632 // (unless it's a link-type transformation)
1633 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1634 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1635 $is_field_truncated = true;
1638 // displays special characters from binaries
1639 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1640 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1641 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1642 // some results of PROCEDURE ANALYSE() are reported as
1643 // being BINARY but they are quite readable,
1644 // so don't treat them as BINARY
1645 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1646 if ($_SESSION['tmp_user_values']['display_binary']) {
1647 // user asked to see the real contents of BINARY
1648 // fields
1649 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1650 $row[$i] = bin2hex($row[$i]);
1651 } else {
1652 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1654 } else {
1655 // we show the BINARY message and field's size
1656 // (or maybe use a transformation)
1657 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1661 // transform functions may enable no-wrapping:
1662 $function_nowrap = $transform_function . '_nowrap';
1663 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1665 // do not wrap if date field type
1666 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1667 $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
1668 $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);
1670 } else {
1671 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1675 // output stored cell
1676 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1677 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1678 echo $vertical_display['data'][$row_no][$i];
1681 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1682 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1683 } else {
1684 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1686 } // end for (2)
1688 // 3. Displays the modify/delete links on the right if required
1689 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1690 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1691 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1692 if (! isset($js_conf)) {
1693 $js_conf = '';
1695 echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, 'r', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1696 } // end if (3)
1698 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1699 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1701 </tr>
1702 <?php
1703 } // end if
1705 // 4. Gather links of del_urls and edit_urls in an array for later
1706 // output
1707 if (! isset($vertical_display['edit'][$row_no])) {
1708 $vertical_display['edit'][$row_no] = '';
1709 $vertical_display['copy'][$row_no] = '';
1710 $vertical_display['delete'][$row_no] = '';
1711 $vertical_display['row_delete'][$row_no] = '';
1713 $vertical_class = ' row_' . $row_no;
1714 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1715 $vertical_class .= ' vpointer';
1717 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1718 $vertical_class .= ' vmarker';
1721 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1722 $vertical_display['row_delete'][$row_no] .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, '[%_PMA_CHECKBOX_DIR_%]', $alternating_color_class . $vertical_class);
1723 } else {
1724 unset($vertical_display['row_delete'][$row_no]);
1727 if (isset($edit_url)) {
1728 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1729 } else {
1730 unset($vertical_display['edit'][$row_no]);
1733 if (isset($copy_url)) {
1734 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1735 } else {
1736 unset($vertical_display['copy'][$row_no]);
1739 if (isset($del_url)) {
1740 if (! isset($js_conf)) {
1741 $js_conf = '';
1743 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1744 } else {
1745 unset($vertical_display['delete'][$row_no]);
1748 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1749 $row_no++;
1750 } // end while
1752 // this is needed by PMA_displayTable() to generate the proper param
1753 // in the multi-edit and multi-delete form
1754 return $clause_is_unique;
1755 } // end of the 'PMA_displayTableBody()' function
1759 * Do display the result table with the vertical direction mode.
1761 * @return boolean always true
1763 * @global array $vertical_display the information to display
1765 * @access private
1767 * @see PMA_displayTable()
1769 function PMA_displayVerticalTable()
1771 global $vertical_display;
1773 // Displays "multi row delete" link at top if required
1774 if (($GLOBALS['cfg']['RowActionLinks'] != 'right')
1775 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1776 echo '<tr>' . "\n";
1777 if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1778 // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
1779 echo '<th></th>' . "\n";
1781 echo $vertical_display['textbtn'];
1782 $cell_displayed = 0;
1783 foreach ($vertical_display['row_delete'] as $val) {
1784 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1785 echo '<th' .
1786 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1787 '></th>' . "\n";
1789 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1790 $cell_displayed++;
1791 } // end while
1792 echo '</tr>' . "\n";
1793 } // end if
1795 // Displays "edit" link at top if required
1796 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1797 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1798 echo '<tr>' . "\n";
1799 if (! is_array($vertical_display['row_delete'])) {
1800 echo $vertical_display['textbtn'];
1802 foreach ($vertical_display['edit'] as $val) {
1803 echo $val;
1804 } // end while
1805 echo '</tr>' . "\n";
1806 } // end if
1808 // Displays "copy" link at top if required
1809 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1810 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1811 echo '<tr>' . "\n";
1812 if (! is_array($vertical_display['row_delete'])) {
1813 echo $vertical_display['textbtn'];
1815 foreach ($vertical_display['copy'] as $val) {
1816 echo $val;
1817 } // end while
1818 echo '</tr>' . "\n";
1819 } // end if
1821 // Displays "delete" link at top if required
1822 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1823 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1824 echo '<tr>' . "\n";
1825 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1826 echo $vertical_display['textbtn'];
1828 foreach ($vertical_display['delete'] as $val) {
1829 echo $val;
1830 } // end while
1831 echo '</tr>' . "\n";
1832 } // end if
1834 if (PMA_isSelect()) {
1835 // prepare to get the column order, if available
1836 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1837 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1838 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1839 } else {
1840 $col_order = false;
1841 $col_visib = false;
1844 // Displays data
1845 foreach ($vertical_display['desc'] AS $j => $val) {
1846 // assign appropriate key with current column order
1847 $key = $col_order ? $col_order[$j] : $j;
1849 echo '<tr' . (($col_visib && !$col_visib[$j]) ? ' class="hide"' : '') . '>' . "\n";
1850 echo $val;
1852 $cell_displayed = 0;
1853 foreach ($vertical_display['rowdata'][$key] as $subval) {
1854 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1855 echo $val;
1858 echo $subval;
1859 $cell_displayed++;
1860 } // end while
1862 echo '</tr>' . "\n";
1863 } // end while
1865 // Displays "multi row delete" link at bottom if required
1866 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1867 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1868 echo '<tr>' . "\n";
1869 echo $vertical_display['textbtn'];
1870 $cell_displayed = 0;
1871 foreach ($vertical_display['row_delete'] as $val) {
1872 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1873 echo '<th' .
1874 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1875 '></th>' . "\n";
1878 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1879 $cell_displayed++;
1880 } // end while
1881 echo '</tr>' . "\n";
1882 } // end if
1884 // Displays "edit" link at bottom if required
1885 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1886 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1887 echo '<tr>' . "\n";
1888 if (! is_array($vertical_display['row_delete'])) {
1889 echo $vertical_display['textbtn'];
1891 foreach ($vertical_display['edit'] as $val) {
1892 echo $val;
1893 } // end while
1894 echo '</tr>' . "\n";
1895 } // end if
1897 // Displays "copy" link at bottom if required
1898 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1899 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1900 echo '<tr>' . "\n";
1901 if (! is_array($vertical_display['row_delete'])) {
1902 echo $vertical_display['textbtn'];
1904 foreach ($vertical_display['copy'] as $val) {
1905 echo $val;
1906 } // end while
1907 echo '</tr>' . "\n";
1908 } // end if
1910 // Displays "delete" link at bottom if required
1911 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1912 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1913 echo '<tr>' . "\n";
1914 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1915 echo $vertical_display['textbtn'];
1917 foreach ($vertical_display['delete'] as $val) {
1918 echo $val;
1919 } // end while
1920 echo '</tr>' . "\n";
1923 return true;
1924 } // end of the 'PMA_displayVerticalTable' function
1928 * @todo make maximum remembered queries configurable
1929 * @todo move/split into SQL class!?
1930 * @todo currently this is called twice unnecessary
1931 * @todo ignore LIMIT and ORDER in query!?
1933 function PMA_displayTable_checkConfigParams()
1935 $sql_md5 = md5($GLOBALS['sql_query']);
1937 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1939 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1940 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1941 unset($_REQUEST['disp_direction']);
1942 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1943 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1946 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1947 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1948 unset($_REQUEST['repeat_cells']);
1949 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1950 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1953 // as this is a form value, the type is always string so we cannot
1954 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1955 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1956 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1957 || $_REQUEST['session_max_rows'] == 'all') {
1958 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1959 unset($_REQUEST['session_max_rows']);
1960 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1961 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1964 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1965 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1966 unset($_REQUEST['pos']);
1967 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1968 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1971 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1972 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1973 unset($_REQUEST['display_text']);
1974 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1975 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1978 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1979 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1980 unset($_REQUEST['relational_display']);
1981 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1982 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1985 if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
1986 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
1987 unset($_REQUEST['geometry_display']);
1988 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
1989 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
1992 if (isset($_REQUEST['display_binary'])) {
1993 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1994 unset($_REQUEST['display_binary']);
1995 } elseif (isset($_REQUEST['display_options_form'])) {
1996 // we know that the checkbox was unchecked
1997 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1998 } else {
1999 // selected by default because some operations like OPTIMIZE TABLE
2000 // and all queries involving functions return "binary" contents,
2001 // according to low-level field flags
2002 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
2005 if (isset($_REQUEST['display_binary_as_hex'])) {
2006 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2007 unset($_REQUEST['display_binary_as_hex']);
2008 } elseif (isset($_REQUEST['display_options_form'])) {
2009 // we know that the checkbox was unchecked
2010 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
2011 } else {
2012 // display_binary_as_hex config option
2013 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
2014 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2018 if (isset($_REQUEST['display_blob'])) {
2019 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
2020 unset($_REQUEST['display_blob']);
2021 } elseif (isset($_REQUEST['display_options_form'])) {
2022 // we know that the checkbox was unchecked
2023 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
2026 if (isset($_REQUEST['hide_transformation'])) {
2027 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
2028 unset($_REQUEST['hide_transformation']);
2029 } elseif (isset($_REQUEST['display_options_form'])) {
2030 // we know that the checkbox was unchecked
2031 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
2034 // move current query to the last position, to be removed last
2035 // so only least executed query will be removed if maximum remembered queries
2036 // limit is reached
2037 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
2038 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
2039 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
2041 // do not exceed a maximum number of queries to remember
2042 if (count($_SESSION['tmp_user_values']['query']) > 10) {
2043 array_shift($_SESSION['tmp_user_values']['query']);
2044 //echo 'deleting one element ...';
2047 // populate query configuration
2048 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
2049 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
2050 $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
2051 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
2052 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
2053 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
2054 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
2055 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
2056 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
2057 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
2058 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
2061 * debugging
2062 echo '<pre>';
2063 var_dump($_SESSION['tmp_user_values']);
2064 echo '</pre>';
2069 * Displays a table of results returned by a SQL query.
2070 * This function is called by the "sql.php" script.
2072 * @param integer the link id associated to the query which results have
2073 * to be displayed
2074 * @param array the display mode
2075 * @param array the analyzed query
2077 * @global string $db the database name
2078 * @global string $table the table name
2079 * @global string $goto the URL to go back in case of errors
2080 * @global string $sql_query the current SQL query
2081 * @global integer $num_rows the total number of rows returned by the
2082 * SQL query
2083 * @global integer $unlim_num_rows the total number of rows returned by the
2084 * SQL query without any programmatically
2085 * appended "LIMIT" clause
2086 * @global array $fields_meta the list of fields properties
2087 * @global integer $fields_cnt the total number of fields returned by
2088 * the SQL query
2089 * @global array $vertical_display informations used with vertical display
2090 * mode
2091 * @global array $highlight_columns column names to highlight
2092 * @global array $cfgRelation the relation settings
2094 * @access private
2096 * @see PMA_showMessage(), PMA_setDisplayMode(),
2097 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2098 * PMA_displayTableBody(), PMA_displayResultsOperations()
2100 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
2102 global $db, $table, $goto;
2103 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
2104 global $vertical_display, $highlight_columns;
2105 global $cfgRelation;
2106 global $showtable;
2108 // why was this called here? (already called from sql.php)
2109 //PMA_displayTable_checkConfigParams();
2112 * @todo move this to a central place
2113 * @todo for other future table types
2115 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
2117 if ($is_innodb
2118 && ! isset($analyzed_sql[0]['queryflags']['union'])
2119 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
2120 && (empty($analyzed_sql[0]['where_clause'])
2121 || $analyzed_sql[0]['where_clause'] == '1 ')) {
2122 // "j u s t b r o w s i n g"
2123 $pre_count = '~';
2124 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')));
2125 } else {
2126 $pre_count = '';
2127 $after_count = '';
2130 // 1. ----- Prepares the work -----
2132 // 1.1 Gets the informations about which functionalities should be
2133 // displayed
2134 $total = '';
2135 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
2137 // 1.2 Defines offsets for the next and previous pages
2138 if ($is_display['nav_bar'] == '1') {
2139 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
2140 $pos_next = 0;
2141 $pos_prev = 0;
2142 } else {
2143 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
2144 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
2145 if ($pos_prev < 0) {
2146 $pos_prev = 0;
2149 } // end if
2151 // 1.3 Find the sort expression
2153 // we need $sort_expression and $sort_expression_nodirection
2154 // even if there are many table references
2155 if (! empty($analyzed_sql[0]['order_by_clause'])) {
2156 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
2158 * Get rid of ASC|DESC
2160 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
2161 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
2162 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
2163 unset($matches);
2164 } else {
2165 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
2168 // 1.4 Prepares display of first and last value of the sorted column
2170 if (! empty($sort_expression_nodirection)) {
2171 if (strpos($sort_expression_nodirection, '.') === false) {
2172 $sort_table = $table;
2173 $sort_column = $sort_expression_nodirection;
2174 } else {
2175 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
2177 $sort_table = PMA_unQuote($sort_table);
2178 $sort_column = PMA_unQuote($sort_column);
2179 // find the sorted column index in row result
2180 // (this might be a multi-table query)
2181 $sorted_column_index = false;
2182 foreach ($fields_meta as $key => $meta) {
2183 if ($meta->table == $sort_table && $meta->name == $sort_column) {
2184 $sorted_column_index = $key;
2185 break;
2188 if ($sorted_column_index !== false) {
2189 // fetch first row of the result set
2190 $row = PMA_DBI_fetch_row($dt_result);
2191 // initializing default arguments
2192 $default_function = 'default_function';
2193 $transform_function = $default_function;
2194 $transform_options = array();
2195 // check for non printable sorted row data
2196 $meta = $fields_meta[$sorted_column_index];
2197 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2198 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2199 } else {
2200 $column_for_first_row = $row[$sorted_column_index];
2202 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2203 // fetch last row of the result set
2204 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2205 $row = PMA_DBI_fetch_row($dt_result);
2206 // check for non printable sorted row data
2207 $meta = $fields_meta[$sorted_column_index];
2208 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2209 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2210 } else {
2211 $column_for_last_row = $row[$sorted_column_index];
2213 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2214 // reset to first row for the loop in PMA_displayTableBody()
2215 PMA_DBI_data_seek($dt_result, 0);
2216 // we could also use here $sort_expression_nodirection
2217 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2218 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2220 unset($sorted_column_index, $sort_table, $sort_column);
2223 // 2. ----- Displays the top of the page -----
2225 // 2.1 Displays a messages with position informations
2226 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2227 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2228 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2229 } else {
2230 $selectstring = '';
2232 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
2233 ? $total - 1
2234 : $pos_next - 1;
2236 if (PMA_Table::isView($db, $table)
2237 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2238 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2239 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2240 $message->addParam('[/a]');
2241 $message_view_warning = PMA_showHint($message);
2242 } else {
2243 $message_view_warning = false;
2246 $message = PMA_Message::success(__('Showing rows'));
2247 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2248 if ($message_view_warning) {
2249 $message->addMessage('...', ' - ');
2250 $message->addMessage($message_view_warning);
2251 $message->addMessage('(');
2252 } else {
2253 $message->addMessage($last_shown_rec, ' - ');
2254 $message->addMessage(' (');
2255 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2256 $message->addString(__('total'));
2257 if (!empty($after_count)) {
2258 $message->addMessage($after_count);
2260 $message->addMessage($selectstring, '');
2261 $message->addMessage(', ', '');
2264 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2265 $messagge_qt->addParam($GLOBALS['querytime']);
2267 $message->addMessage($messagge_qt, '');
2268 $message->addMessage(')', '');
2270 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2272 PMA_showMessage($message, $sql_query, 'success');
2274 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2275 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2278 // 2.3 Displays the navigation bars
2279 if (! strlen($table)) {
2280 if (isset($analyzed_sql[0]['query_type'])
2281 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2282 // table does not always contain a real table name,
2283 // for example in MySQL 5.0.x, the query SHOW STATUS
2284 // returns STATUS as a table name
2285 $table = $fields_meta[0]->table;
2286 } else {
2287 $table = '';
2291 if ($is_display['nav_bar'] == '1') {
2292 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2293 echo "\n";
2294 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2295 echo "\n" . '<br /><br />' . "\n";
2298 // 2b ----- Get field references from Database -----
2299 // (see the 'relation' configuration variable)
2301 // initialize map
2302 $map = array();
2304 // find tables
2305 $target=array();
2306 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2307 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2308 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2311 $tabs = '(\'' . join('\',\'', $target) . '\')';
2313 if (! strlen($table)) {
2314 $exist_rel = false;
2315 } else {
2316 // To be able to later display a link to the related table,
2317 // we verify both types of relations: either those that are
2318 // native foreign keys or those defined in the phpMyAdmin
2319 // configuration storage. If no PMA storage, we won't be able
2320 // to use the "column to display" notion (for example show
2321 // the name related to a numeric id).
2322 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2323 if ($exist_rel) {
2324 foreach ($exist_rel AS $master_field => $rel) {
2325 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2326 $map[$master_field] = array($rel['foreign_table'],
2327 $rel['foreign_field'],
2328 $display_field,
2329 $rel['foreign_db']);
2330 } // end while
2331 } // end if
2332 } // end if
2333 // end 2b
2335 // 3. ----- Displays the results table -----
2336 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2337 $url_query = '';
2338 echo '<tbody>' . "\n";
2339 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2340 // vertical output case
2341 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2342 PMA_displayVerticalTable();
2343 } // end if
2344 unset($vertical_display);
2345 echo '</tbody>' . "\n";
2347 </table>
2349 <?php
2350 // 4. ----- Displays the link for multi-fields edit and delete
2352 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2354 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2356 $_url_params = array(
2357 'db' => $db,
2358 'table' => $table,
2359 'sql_query' => $sql_query,
2360 'goto' => $goto,
2362 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2364 $_url_params['checkall'] = '1';
2365 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2367 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2368 $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
2369 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
2370 } else {
2371 $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
2372 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
2374 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2375 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2376 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2377 echo '<img class="selectallarrow" width="38" height="22"'
2378 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2379 .' alt="' . __('With selected:') . '" />';
2381 echo $checkall_link . "\n"
2382 .' / ' . "\n"
2383 .$uncheckall_link . "\n"
2384 .'<i>' . __('With selected:') . '</i>' . "\n";
2386 PMA_buttonOrImage('submit_mult', 'mult_submit',
2387 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2388 PMA_buttonOrImage('submit_mult', 'mult_submit',
2389 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2390 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2391 PMA_buttonOrImage('submit_mult', 'mult_submit',
2392 'submit_mult_export', __('Export'),
2393 'b_tblexport.png', 'export');
2395 echo "\n";
2397 echo '<input type="hidden" name="sql_query"'
2398 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2400 if (! empty($GLOBALS['url_query'])) {
2401 echo '<input type="hidden" name="url_query"'
2402 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2405 echo '<input type="hidden" name="clause_is_unique"'
2406 .' value="' . $clause_is_unique . '" />' . "\n";
2408 echo '</form>' . "\n";
2411 // 5. ----- Displays the navigation bar at the bottom if required -----
2413 if ($is_display['nav_bar'] == '1') {
2414 echo '<br />' . "\n";
2415 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2416 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2417 echo "\n" . '<br /><br />' . "\n";
2420 // 6. ----- Displays "Query results operations"
2421 if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2422 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2424 } // end of the 'PMA_displayTable()' function
2426 function default_function($buffer)
2428 $buffer = htmlspecialchars($buffer);
2429 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2430 str_replace(' ', ' &nbsp;', $buffer));
2431 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2433 return $buffer;
2437 * Displays operations that are available on results.
2439 * @param array the display mode
2440 * @param array the analyzed query
2442 * @global string $db the database name
2443 * @global string $table the table name
2444 * @global string $sql_query the current SQL query
2445 * @global integer $unlim_num_rows the total number of rows returned by the
2446 * SQL query without any programmatically
2447 * appended "LIMIT" clause
2449 * @access private
2451 * @see PMA_showMessage(), PMA_setDisplayMode(),
2452 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2453 * PMA_displayTableBody(), PMA_displayResultsOperations()
2455 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql)
2457 global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
2459 $header_shown = false;
2460 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2462 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2463 // Displays "printable view" link if required
2464 if ($the_disp_mode[9] == '1') {
2466 if (!$header_shown) {
2467 echo $header;
2468 $header_shown = true;
2471 $_url_params = array(
2472 'db' => $db,
2473 'table' => $table,
2474 'printview' => '1',
2475 'sql_query' => $sql_query,
2477 $url_query = PMA_generate_common_url($_url_params);
2479 echo PMA_linkOrButton(
2480 'sql.php' . $url_query,
2481 PMA_getIcon('b_print.png', __('Print view')),
2482 '', true, true, 'print_view') . "\n";
2484 if ($_SESSION['tmp_user_values']['display_text']) {
2485 $_url_params['display_text'] = 'F';
2486 echo PMA_linkOrButton(
2487 'sql.php' . PMA_generate_common_url($_url_params),
2488 PMA_getIcon('b_print.png', __('Print view (with full texts)')),
2489 '', true, true, 'print_view') . "\n";
2490 unset($_url_params['display_text']);
2492 } // end displays "printable view"
2495 // Export link
2496 // (the url_query has extra parameters that won't be used to export)
2497 // (the single_table parameter is used in display_export.lib.php
2498 // to hide the SQL and the structure export dialogs)
2499 // If the parser found a PROCEDURE clause
2500 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2501 // display the Export link).
2502 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2503 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2504 $_url_params['single_table'] = 'true';
2506 if (!$header_shown) {
2507 echo $header;
2508 $header_shown = true;
2510 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2513 * At this point we don't know the table name; this can happen
2514 * for example with a query like
2515 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2516 * As a workaround we set in the table parameter the name of the
2517 * first table of this database, so that tbl_export.php and
2518 * the script it calls do not fail
2520 if (empty($_url_params['table']) && !empty($_url_params['db'])) {
2521 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2522 /* No result (probably no database selected) */
2523 if ($_url_params['table'] === FALSE) {
2524 unset($_url_params['table']);
2528 echo PMA_linkOrButton(
2529 'tbl_export.php' . PMA_generate_common_url($_url_params),
2530 PMA_getIcon('b_tblexport.png', __('Export')),
2531 '', true, true, '') . "\n";
2533 // show chart
2534 echo PMA_linkOrButton(
2535 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2536 PMA_getIcon('b_chart.png', __('Display chart')),
2537 '', true, true, '') . "\n";
2539 // show GIS chart
2540 $geometry_found = false;
2541 // If atleast one geometry field is found
2542 foreach ($fields_meta as $meta) {
2543 if ($meta->type == 'geometry') {
2544 $geometry_found = true;
2545 break;
2548 if ($geometry_found) {
2549 echo PMA_linkOrButton(
2550 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
2551 PMA_getIcon('b_globe.gif', __('Visualize GIS data')),
2552 '', true, true, '') . "\n";
2556 // CREATE VIEW
2559 * @todo detect privileges to create a view
2560 * (but see 2006-01-19 note in display_create_table.lib.php,
2561 * I think we cannot detect db-specific privileges reliably)
2562 * Note: we don't display a Create view link if we found a PROCEDURE clause
2564 if (!$header_shown) {
2565 echo $header;
2566 $header_shown = true;
2568 if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) {
2569 echo PMA_linkOrButton(
2570 'view_create.php' . $url_query,
2571 PMA_getIcon('b_views.png', __('Create view')),
2572 '', true, true, '') . "\n";
2574 if ($header_shown) {
2575 echo '</fieldset><br />';
2580 * Verifies what to do with non-printable contents (binary or BLOB)
2581 * in Browse mode.
2583 * @param string $category BLOB|BINARY|GEOMETRY
2584 * @param string $content the binary content
2585 * @param string $transform_function transformation function
2586 * @param string $transform_options transformation parameters
2587 * @param string $default_function default transformation function
2588 * @param object $meta the meta-information about this field
2589 * @return mixed string or float
2591 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array())
2593 $result = '[' . $category;
2594 if (is_null($content)) {
2595 $result .= ' - NULL';
2596 $size = 0;
2597 } elseif (isset($content)) {
2598 $size = strlen($content);
2599 $display_size = PMA_formatByteDown($size, 3, 1);
2600 $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
2602 $result .= ']';
2604 if (strpos($transform_function, 'octetstream')) {
2605 $result = $content;
2607 if ($size > 0) {
2608 if ($default_function != $transform_function) {
2609 $result = $transform_function($result, $transform_options, $meta);
2610 } else {
2611 $result = $default_function($result, array(), $meta);
2612 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2613 // in this case, restart from the original $content
2614 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2616 /* Create link to download */
2617 if (count($url_params) > 0) {
2618 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2622 return($result);
2626 * Prepares the displayable content of a data cell in Browse mode,
2627 * taking into account foreign key description field and transformations
2629 * @param string $class
2630 * @param string $condition_field
2631 * @param string $analyzed_sql
2632 * @param object $meta the meta-information about this field
2633 * @param string $map
2634 * @param string $data
2635 * @param string $transform_function
2636 * @param string $default_function
2637 * @param string $nowrap
2638 * @param string $where_comparison
2639 * @param bool $is_field_truncated
2640 * @return string formatted data
2642 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 )
2645 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2647 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2648 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2649 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2650 if (isset($alias) && strlen($alias)) {
2651 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2652 if ($alias == $meta->name) {
2653 // this change in the parameter does not matter
2654 // outside of the function
2655 $meta->name = $true_column;
2656 } // end if
2657 } // end if
2658 } // end foreach
2659 } // end if
2661 if (isset($map[$meta->name])) {
2662 // Field to display from the foreign table?
2663 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2664 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2665 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2666 . '.' . PMA_backquote($map[$meta->name][0])
2667 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2668 . $where_comparison;
2669 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2670 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2671 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2672 } else {
2673 $dispval = __('Link not found');
2675 @PMA_DBI_free_result($dispresult);
2676 } else {
2677 $dispval = '';
2678 } // end if... else...
2680 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2681 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2682 } else {
2684 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2685 // user chose "relational key" in the display options, so
2686 // the title contains the display field
2687 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2688 } else {
2689 $title = ' title="' . htmlspecialchars($data) . '"';
2692 $_url_params = array(
2693 'db' => $map[$meta->name][3],
2694 'table' => $map[$meta->name][0],
2695 'pos' => '0',
2696 'sql_query' => 'SELECT * FROM '
2697 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2698 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2699 . $where_comparison,
2701 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2702 . '"' . $title . '>';
2704 if ($transform_function != $default_function) {
2705 // always apply a transformation on the real data,
2706 // not on the display field
2707 $result .= $transform_function($data, $transform_options, $meta);
2708 } else {
2709 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2710 // user chose "relational display field" in the
2711 // display options, so show display field in the cell
2712 $result .= $transform_function($dispval, array(), $meta);
2713 } else {
2714 // otherwise display data in the cell
2715 $result .= $transform_function($data, array(), $meta);
2718 $result .= '</a>';
2720 } else {
2721 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2723 $result .= '</td>' . "\n";
2725 return $result;
2729 * Generates a checkbox for multi-row submits
2731 * @param string $del_url
2732 * @param array $is_display
2733 * @param string $row_no
2734 * @param string $where_clause_html
2735 * @param string $del_query
2736 * @param string $id_suffix
2737 * @param string $class
2738 * @return string the generated HTML
2741 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix, $class)
2743 $ret = '';
2744 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2745 $ret .= '<td ';
2746 if (! empty($class)) {
2747 $ret .= 'class="' . $class . '"';
2749 $ret .= ' align="center">'
2750 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2751 . ' class="multi_checkbox"'
2752 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2753 . '<input type="hidden" class="condition_array" value="' . htmlspecialchars(json_encode($condition_array)) . '" />'
2754 . ' </td>';
2756 return $ret;
2760 * Generates an Edit link
2762 * @param string $edit_url
2763 * @param string $class
2764 * @param string $edit_str
2765 * @param string $where_clause
2766 * @param string $where_clause_html
2767 * @return string the generated HTML
2769 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html)
2771 $ret = '';
2772 if (! empty($edit_url)) {
2773 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2774 . PMA_linkOrButton($edit_url, $edit_str, array(), false);
2776 * Where clause for selecting this row uniquely is provided as
2777 * a hidden input. Used by jQuery scripts for handling grid editing
2779 if (! empty($where_clause)) {
2780 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2782 $ret .= '</span></td>';
2784 return $ret;
2788 * Generates an Copy link
2790 * @param string $copy_url
2791 * @param string $copy_str
2792 * @param string $where_clause
2793 * @param string $where_clause_html
2794 * @return string the generated HTML
2796 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class)
2798 $ret = '';
2799 if (! empty($copy_url)) {
2800 $ret .= '<td ';
2801 if (! empty($class)) {
2802 $ret .= 'class="' . $class . '" ';
2804 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2805 . PMA_linkOrButton($copy_url, $copy_str, array(), false);
2807 * Where clause for selecting this row uniquely is provided as
2808 * a hidden input. Used by jQuery scripts for handling grid editing
2810 if (! empty($where_clause)) {
2811 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2813 $ret .= '</span></td>';
2815 return $ret;
2819 * Generates a Delete link
2821 * @param string $del_url
2822 * @param string $del_str
2823 * @param string $js_conf
2824 * @param string $class
2825 * @return string the generated HTML
2827 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class)
2829 $ret = '';
2830 if (! empty($del_url)) {
2831 $ret .= '<td ';
2832 if (! empty($class)) {
2833 $ret .= 'class="' . $class . '" ';
2835 $ret .= 'align="center" ' . ' >'
2836 . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
2837 . '</td>';
2839 return $ret;
2843 * Generates checkbox and links at some position (left or right)
2844 * (only called for horizontal mode)
2846 * @param string $position
2847 * @param string $del_url
2848 * @param array $is_display
2849 * @param string $row_no
2850 * @param string $where_clause
2851 * @param string $where_clause_html
2852 * @param string $del_query
2853 * @param string $id_suffix
2854 * @param string $edit_url
2855 * @param string $copy_url
2856 * @param string $class
2857 * @param string $edit_str
2858 * @param string $del_str
2859 * @param string $js_conf
2860 * @return string the generated HTML
2862 function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf)
2864 $ret = '';
2866 if ($position == 'left') {
2867 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix='_left', '', '', '');
2869 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2871 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2873 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2875 } elseif ($position == 'right') {
2876 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2878 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2880 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2882 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix='_right', '', '', '');
2883 } else { // $position == 'none'
2884 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix='_left', '', '', '');
2886 return $ret;