Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / display_tbl.lib.php
blobddcfb7a175a1d967a3cb9397e061728b5490e01f
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 echo '<input id="table_create_time" type="hidden" value="' .
582 PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
586 $vertical_display['emptypre'] = 0;
587 $vertical_display['emptyafter'] = 0;
588 $vertical_display['textbtn'] = '';
590 // Display options (if we are not in print view)
591 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
592 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
593 if ($GLOBALS['cfg']['AjaxEnable']) {
594 echo ' class="ajax" ';
596 echo '>';
597 $url_params = array(
598 'db' => $db,
599 'table' => $table,
600 'sql_query' => $sql_query,
601 'goto' => $goto,
602 'display_options_form' => 1
604 echo PMA_generate_common_hidden_inputs($url_params);
605 echo '<br />';
606 PMA_generate_slider_effect('displayoptions',__('Options'));
607 echo '<fieldset>';
609 echo '<div class="formelement">';
610 $choices = array(
611 'P' => __('Partial texts'),
612 'F' => __('Full texts')
614 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
615 echo '</div>';
617 // prepare full/partial text button or link
618 if ($_SESSION['tmp_user_values']['display_text']=='F') {
619 // currently in fulltext mode so show the opposite link
620 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
621 $tmp_txt = __('Partial texts');
622 $url_params['display_text'] = 'P';
623 } else {
624 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
625 $tmp_txt = __('Full texts');
626 $url_params['display_text'] = 'F';
629 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
630 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
631 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
632 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
635 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
636 echo '<div class="formelement">';
637 $choices = array(
638 'K' => __('Relational key'),
639 'D' => __('Relational display column')
641 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
642 echo '</div>';
645 echo '<div class="formelement">';
646 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
647 echo '<br />';
648 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
649 echo '<br />';
650 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
651 echo '</div>';
653 // I would have preferred to name this "display_transformation".
654 // This is the only way I found to be able to keep this setting sticky
655 // per SQL query, and at the same time have a default that displays
656 // the transformations.
657 echo '<div class="formelement">';
658 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
659 echo '</div>';
661 echo '<div class="formelement">';
662 $choices = array(
663 'GEOM' => __('Geometry'),
664 'WKT' => __('Well Known Text'),
665 'WKB' => __('Well Known Binary')
667 PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
668 echo '</div>';
670 echo '<div class="clearfloat"></div>';
671 echo '</fieldset>';
673 echo '<fieldset class="tblFooters">';
674 echo '<input type="submit" value="' . __('Go') . '" />';
675 echo '</fieldset>';
676 echo '</div>';
677 echo '</form>';
680 // Start of form for multi-rows edit/delete/export
682 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
683 echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
684 if ($GLOBALS['cfg']['AjaxEnable']) {
685 echo ' class="ajax" ';
687 echo '>' . "\n";
688 echo PMA_generate_common_hidden_inputs($db, $table, 1);
689 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
692 echo '<table id="table_results" class="data';
693 if ($GLOBALS['cfg']['AjaxEnable']) {
694 echo ' ajax';
696 echo '">' . "\n";
697 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
698 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
699 echo '<thead><tr>' . "\n";
702 // 1. Displays the full/partial text button (part 1)...
703 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
704 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
705 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
706 ? ' colspan="4"'
707 : '';
708 } else {
709 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
710 ? ' rowspan="4"'
711 : '';
714 // ... before the result table
715 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
716 && $is_display['text_btn'] == '1') {
717 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
718 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
719 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
721 <th colspan="<?php echo $fields_cnt; ?>"></th>
722 </tr>
723 <tr>
724 <?php
725 } // end horizontal/horizontalflipped mode
726 else {
728 <tr>
729 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
730 </tr>
731 <?php
732 } // end vertical mode
735 // ... at the left column of the result table header if possible
736 // and required
737 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
738 && $is_display['text_btn'] == '1') {
739 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
740 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
741 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
743 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
744 <?php
745 } // end horizontal/horizontalflipped mode
746 else {
747 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
748 . ' ' . "\n"
749 . ' </th>' . "\n";
750 } // end vertical mode
753 // ... elseif no button, displays empty(ies) col(s) if required
754 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
755 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
756 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
757 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
758 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
760 <td<?php echo $colspan; ?>></td>
761 <?php
762 } // end horizontal/horizontalfipped mode
763 else {
764 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
765 } // end vertical mode
768 // ... elseif display an empty column if the actions links are disabled to match the rest of the table
769 elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none' && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
770 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
771 echo '<th></th>';
774 // 2. Displays the fields' name
775 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
776 // statement (see 2.1.3)
778 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
779 // Do not show comments, if using horizontalflipped mode, because of space usage
780 if ($GLOBALS['cfg']['ShowBrowseComments']
781 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
782 $comments_map = array();
783 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
784 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
785 $tb = $tbl['table_true_name'];
786 $comments_map[$tb] = PMA_getComments($db, $tb);
787 unset($tb);
792 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
793 require_once './libraries/transformations.lib.php';
794 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
797 // See if we have to highlight any header fields of a WHERE query.
798 // Uses SQL-Parser results.
799 $highlight_columns = array();
800 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
801 isset($analyzed_sql[0]['where_clause_identifiers'])) {
803 $wi = 0;
804 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
805 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
806 $highlight_columns[$wci] = 'true';
811 if (PMA_isSelect()) {
812 // prepare to get the column order, if available
813 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
814 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
815 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
816 } else {
817 $col_order = false;
818 $col_visib = false;
821 for ($j = 0; $j < $fields_cnt; $j++) {
822 // assign $i with appropriate column order
823 $i = $col_order ? $col_order[$j] : $j;
824 // See if this column should get highlight because it's used in the
825 // where-query.
826 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
827 $condition_field = true;
828 } else {
829 $condition_field = false;
832 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
833 if (isset($comments_map) &&
834 isset($comments_map[$fields_meta[$i]->table]) &&
835 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
836 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
837 } else {
838 $comments = '';
841 // 2.1 Results can be sorted
842 if ($is_display['sort_lnk'] == '1') {
844 // 2.1.1 Checks if the table name is required; it's the case
845 // for a query with a "JOIN" statement and if the column
846 // isn't aliased, or in queries like
847 // SELECT `1`.`master_field` , `2`.`master_field`
848 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
850 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
851 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
852 } else {
853 $sort_tbl = '';
856 // 2.1.2 Checks if the current column is used to sort the
857 // results
858 // the orgname member does not exist for all MySQL versions
859 // but if found, it's the one on which to sort
860 $name_to_use_in_sort = $fields_meta[$i]->name;
861 $is_orgname = false;
862 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
863 $name_to_use_in_sort = $fields_meta[$i]->orgname;
864 $is_orgname = true;
866 // $name_to_use_in_sort might contain a space due to
867 // formatting of function expressions like "COUNT(name )"
868 // so we remove the space in this situation
869 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
871 if (empty($sort_expression)) {
872 $is_in_sort = false;
873 } else {
874 // Field name may be preceded by a space, or any number
875 // of characters followed by a dot (tablename.fieldname)
876 // so do a direct comparison for the sort expression;
877 // this avoids problems with queries like
878 // "SELECT id, count(id)..." and clicking to sort
879 // on id or on count(id).
880 // Another query to test this:
881 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
882 // (and try clicking on each column's header twice)
883 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
884 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
886 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
888 // 2.1.3 Check the field name for a bracket.
889 // If it contains one, it's probably a function column
890 // like 'COUNT(`field`)'
891 // It still might be a column name of a view. See bug #3383711
892 // Check is_orgname.
893 if (strpos($name_to_use_in_sort, '(') !== false && ! $is_orgname) {
894 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
895 } else {
896 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
898 unset($name_to_use_in_sort);
899 unset($is_orgname);
901 // 2.1.4 Do define the sorting URL
902 if (! $is_in_sort) {
903 // patch #455484 ("Smart" order)
904 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
905 if ($GLOBALS['cfg']['Order'] === 'SMART') {
906 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
907 } else {
908 $sort_order .= $GLOBALS['cfg']['Order'];
910 $order_img = '';
911 } elseif ('DESC' == $sort_direction) {
912 $sort_order .= ' ASC';
913 $order_img = ' <img class="icon ic_s_desc" src="themes/dot.gif" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
914 } else {
915 $sort_order .= ' DESC';
916 $order_img = ' <img class="icon ic_s_asc" src="themes/dot.gif" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
919 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
920 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
921 } else {
922 $sorted_sql_query = $unsorted_sql_query . $sort_order;
924 $_url_params = array(
925 'db' => $db,
926 'table' => $table,
927 'sql_query' => $sorted_sql_query,
928 'session_max_rows' => $session_max_rows
930 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
932 // 2.1.5 Displays the sorting URL
933 // enable sort order swapping for image
934 $order_link_params = array();
935 if (isset($order_img) && $order_img!='') {
936 if (strstr($order_img, 'asc')) {
937 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
938 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
939 } elseif (strstr($order_img, 'desc')) {
940 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
941 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
944 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
945 if (PMA_USR_BROWSER_AGENT == 'IE') {
946 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
947 } else {
948 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
951 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
952 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
953 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
955 $order_link_params['title'] = __('Sort');
956 $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));
957 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
959 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
960 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
961 echo '<th';
962 $th_class = array();
963 $th_class[] = 'draggable';
964 if ($col_visib && !$col_visib[$j]) {
965 $th_class[] = 'hide';
967 if ($condition_field) {
968 $th_class[] = 'condition';
970 $th_class[] = 'column_heading';
971 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
972 $th_class[] = 'pointer';
974 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
975 $th_class[] = 'marker';
977 echo ' class="' . implode(' ', $th_class) . '"';
979 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
980 echo ' valign="bottom"';
982 echo '>' . $order_link . $comments . '</th>';
984 $vertical_display['desc'][] = ' <th '
985 . 'class="draggable'
986 . ($condition_field ? ' condition' : '')
987 . '">' . "\n"
988 . $order_link . $comments . ' </th>' . "\n";
989 } // end if (2.1)
991 // 2.2 Results can't be sorted
992 else {
993 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
994 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
995 echo '<th';
996 $th_class = array();
997 $th_class[] = 'draggable';
998 if ($col_visib && !$col_visib[$j]) {
999 $th_class[] = 'hide';
1001 if ($condition_field) {
1002 $th_class[] = 'condition';
1004 echo ' class="' . implode(' ', $th_class) . '"';
1005 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1006 echo ' valign="bottom"';
1008 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1009 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
1010 echo ' style="direction: ltr; writing-mode: tb-rl;"';
1012 echo '>';
1013 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1014 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
1015 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
1016 } else {
1017 echo htmlspecialchars($fields_meta[$i]->name);
1019 echo "\n" . $comments . '</th>';
1021 $vertical_display['desc'][] = ' <th '
1022 . 'class="draggable'
1023 . ($condition_field ? ' condition"' : '')
1024 . '">' . "\n"
1025 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
1026 . $comments . ' </th>';
1027 } // end else (2.2)
1028 } // end for
1030 // 3. Displays the needed checkboxes at the right
1031 // column of the result table header if possible and required...
1032 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1033 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
1034 && $is_display['text_btn'] == '1') {
1035 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1036 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1037 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1038 echo "\n";
1040 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
1041 </th>
1042 <?php
1043 } // end horizontal/horizontalflipped mode
1044 else {
1045 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
1046 . ' ' . "\n"
1047 . ' </th>' . "\n";
1048 } // end vertical mode
1051 // ... elseif no button, displays empty columns if required
1052 // (unless coming from Browse mode print view)
1053 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1054 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
1055 && (!$GLOBALS['is_header_sent'])) {
1056 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1057 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1058 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1059 echo "\n";
1061 <td<?php echo $colspan; ?>></td>
1062 <?php
1063 } // end horizontal/horizontalflipped mode
1064 else {
1065 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
1066 } // end vertical mode
1069 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1070 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1072 </tr>
1073 </thead>
1074 <?php
1077 return true;
1078 } // end of the 'PMA_displayTableHeaders()' function
1082 * Prepares the display for a value
1084 * @param string $class class of table cell
1085 * @param bool $condition_field whether to add CSS class condition
1086 * @param string $value value to display
1088 * @return string the td
1090 function PMA_buildValueDisplay($class, $condition_field, $value)
1092 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
1096 * Prepares the display for a null value
1098 * @param string $class class of table cell
1099 * @param bool $condition_field whether to add CSS class condition
1101 * @return string the td
1103 function PMA_buildNullDisplay($class, $condition_field)
1105 // the null class is needed for grid editing
1106 return '<td align="right"' . ' class="' . $class . ($condition_field ? ' condition' : '') . ' null"><i>NULL</i></td>';
1110 * Prepares the display for an empty value
1112 * @param string $class class of table cell
1113 * @param bool $condition_field whether to add CSS class condition
1114 * @param object $meta the meta-information about this field
1115 * @param string $align cell allignment
1117 * @return string the td
1119 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '')
1121 $nowrap = ' nowrap';
1122 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1126 * Adds the relavant classes.
1128 * @param string $class class of table cell
1129 * @param bool $condition_field whether to add CSS class condition
1130 * @param object $meta the meta-information about this field
1131 * @param string $nowrap avoid wrapping
1132 * @param bool $is_field_truncated is field truncated (display ...)
1133 * @param string $transform_function transformation function
1134 * @param string $default_function default transformation function
1136 * @return string the list of classes
1138 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '')
1140 // Define classes to be added to this data field based on the type of data
1141 $enum_class = '';
1142 if (strpos($meta->flags, 'enum') !== false) {
1143 $enum_class = ' enum';
1146 $set_class = '';
1147 if (strpos($meta->flags, 'set') !== false) {
1148 $set_class = ' set';
1151 $bit_class = '';
1152 if (strpos($meta->type, 'bit') !== false) {
1153 $bit_class = ' bit';
1156 $mime_type_class = '';
1157 if (isset($meta->mimetype)) {
1158 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
1161 $result = $class . ($condition_field ? ' condition' : '') . $nowrap
1162 . ' ' . ($is_field_truncated ? ' truncated' : '')
1163 . ($transform_function != $default_function ? ' transformed' : '')
1164 . $enum_class . $set_class . $bit_class . $mime_type_class;
1166 return $result;
1169 * Displays the body of the results table
1171 * @param integer &$dt_result the link id associated to the query which results have
1172 * to be displayed
1173 * @param array &$is_display which elements to display
1174 * @param array $map the list of relations
1175 * @param array $analyzed_sql the analyzed query
1177 * @return boolean always true
1179 * @global string $db the database name
1180 * @global string $table the table name
1181 * @global string $goto the URL to go back in case of errors
1182 * @global string $sql_query the SQL query
1183 * @global array $fields_meta the list of fields properties
1184 * @global integer $fields_cnt the total number of fields returned by
1185 * the SQL query
1186 * @global array $vertical_display informations used with vertical display
1187 * mode
1188 * @global array $highlight_columns column names to highlight
1189 * @global array $row current row data
1191 * @access private
1193 * @see PMA_displayTable()
1195 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
1197 global $db, $table, $goto;
1198 global $sql_query, $fields_meta, $fields_cnt;
1199 global $vertical_display, $highlight_columns;
1200 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1202 $url_sql_query = $sql_query;
1204 // query without conditions to shorten URLs when needed, 200 is just
1205 // guess, it should depend on remaining URL length
1207 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1208 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1209 strlen($sql_query) > 200) {
1211 $url_sql_query = 'SELECT ';
1212 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1213 $url_sql_query .= ' DISTINCT ';
1215 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1216 if (!empty($analyzed_sql[0]['from_clause'])) {
1217 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1221 if (! is_array($map)) {
1222 $map = array();
1224 $row_no = 0;
1225 $vertical_display['edit'] = array();
1226 $vertical_display['copy'] = array();
1227 $vertical_display['delete'] = array();
1228 $vertical_display['data'] = array();
1229 $vertical_display['row_delete'] = array();
1230 // name of the class added to all grid editable elements
1231 $grid_edit_class = 'grid_edit';
1233 // prepare to get the column order, if available
1234 if (PMA_isSelect()) {
1235 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1236 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1237 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1238 } else {
1239 $col_order = false;
1240 $col_visib = false;
1243 // Correction University of Virginia 19991216 in the while below
1244 // Previous code assumed that all tables have keys, specifically that
1245 // the phpMyAdmin GUI should support row delete/edit only for such
1246 // tables.
1247 // Although always using keys is arguably the prescribed way of
1248 // defining a relational table, it is not required. This will in
1249 // particular be violated by the novice.
1250 // We want to encourage phpMyAdmin usage by such novices. So the code
1251 // below has been changed to conditionally work as before when the
1252 // table being displayed has one or more keys; but to display
1253 // delete/edit options correctly for tables without keys.
1255 $odd_row = true;
1256 while ($row = PMA_DBI_fetch_row($dt_result)) {
1257 // "vertical display" mode stuff
1258 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1259 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1260 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1262 echo '<tr>' . "\n";
1263 if ($vertical_display['emptypre'] > 0) {
1264 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1265 .' &nbsp;</th>' . "\n";
1266 } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1267 echo ' <th></th>' . "\n";
1270 foreach ($vertical_display['desc'] as $val) {
1271 echo $val;
1274 if ($vertical_display['emptyafter'] > 0) {
1275 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1276 .' &nbsp;</th>' . "\n";
1278 echo '</tr>' . "\n";
1279 } // end if
1281 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1282 $odd_row = ! $odd_row;
1284 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1285 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1286 // pointer code part
1287 echo '<tr class="' . $alternating_color_class . '">';
1291 // 1. Prepares the row
1292 // 1.1 Results from a "SELECT" statement -> builds the
1293 // WHERE clause to use in links (a unique key if possible)
1295 * @todo $where_clause could be empty, for example a table
1296 * with only one field and it's a BLOB; in this case,
1297 * avoid to display the delete and edit links
1299 list($where_clause, $clause_is_unique, $condition_array) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1300 $where_clause_html = urlencode($where_clause);
1302 // 1.2 Defines the URLs for the modify/delete link(s)
1304 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1305 // We need to copy the value or else the == 'both' check will always return true
1307 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1308 $iconic_spacer = '<div class="nowrap">';
1309 } else {
1310 $iconic_spacer = '';
1313 // 1.2.1 Modify link(s)
1314 if ($is_display['edit_lnk'] == 'ur') { // update row case
1315 $_url_params = array(
1316 'db' => $db,
1317 'table' => $table,
1318 'where_clause' => $where_clause,
1319 'clause_is_unique' => $clause_is_unique,
1320 'sql_query' => $url_sql_query,
1321 'goto' => 'sql.php',
1323 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1324 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1326 $edit_str = PMA_getIcon('b_edit.png', __('Edit'));
1327 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'));
1329 // Class definitions required for grid editing jQuery scripts
1330 $edit_anchor_class = "edit_row_anchor";
1331 if ( $clause_is_unique == 0) {
1332 $edit_anchor_class .= ' nonunique';
1334 } // end if (1.2.1)
1336 // 1.2.2 Delete/Kill link(s)
1337 if ($is_display['del_lnk'] == 'dr') { // delete row case
1338 $_url_params = array(
1339 'db' => $db,
1340 'table' => $table,
1341 'sql_query' => $url_sql_query,
1342 'message_to_show' => __('The row has been deleted'),
1343 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1345 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1347 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1348 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1350 $_url_params = array(
1351 'db' => $db,
1352 'table' => $table,
1353 'sql_query' => $del_query,
1354 'message_to_show' => __('The row has been deleted'),
1355 'goto' => $lnk_goto,
1357 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1359 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1360 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1361 . ($clause_is_unique ? '' : ' LIMIT 1');
1362 $del_str = PMA_getIcon('b_drop.png', __('Delete'));
1363 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1365 $_url_params = array(
1366 'db' => $db,
1367 'table' => $table,
1368 'sql_query' => $url_sql_query,
1369 'goto' => 'main.php',
1371 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1373 $_url_params = array(
1374 'db' => 'mysql',
1375 'sql_query' => 'KILL ' . $row[0],
1376 'goto' => $lnk_goto,
1378 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1379 $del_query = 'KILL ' . $row[0];
1380 $js_conf = 'KILL ' . $row[0];
1381 $del_str = PMA_getIcon('b_drop.png', __('Kill'));
1382 } // end if (1.2.2)
1384 // 1.3 Displays the links at left if required
1385 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1386 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1387 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1388 if (! isset($js_conf)) {
1389 $js_conf = '';
1391 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);
1392 } else if (($GLOBALS['cfg']['RowActionLinks'] == 'none')
1393 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1394 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1395 if (! isset($js_conf)) {
1396 $js_conf = '';
1398 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);
1399 } // end if (1.3)
1400 } // end if (1)
1402 // 2. Displays the rows' values
1404 for ($j = 0; $j < $fields_cnt; ++$j) {
1405 // assign $i with appropriate column order
1406 $i = $col_order ? $col_order[$j] : $j;
1408 $meta = $fields_meta[$i];
1409 $not_null_class = $meta->not_null ? 'not_null' : '';
1410 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1411 $hide_class = ($col_visib && !$col_visib[$j] &&
1412 // hide per <td> only if the display direction is not vertical
1413 $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ? 'hide' : '';
1414 // handle datetime-related class, for grid editing
1415 if (substr($meta->type, 0, 9) == 'timestamp' || $meta->type == 'datetime') {
1416 $field_type_class = 'datetimefield';
1417 } else if ($meta->type == 'date') {
1418 $field_type_class = 'datefield';
1419 } else {
1420 $field_type_class = '';
1422 $pointer = $i;
1423 $is_field_truncated = false;
1424 //If the previous column had blob data, we need to reset the class
1425 // to $inline_edit_class
1426 $class = 'data ' . $grid_edit_class . ' ' . $not_null_class . ' ' . $relation_class . ' ' . $hide_class . ' ' . $field_type_class; //' ' . $alternating_color_class .
1428 // See if this column should get highlight because it's used in the
1429 // where-query.
1430 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1431 $condition_field = true;
1432 } else {
1433 $condition_field = false;
1436 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1437 // the row number corresponds to a data row, not HTML table row
1438 $class .= ' row_' . $row_no;
1439 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1440 $class .= ' vpointer';
1442 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1443 $class .= ' vmarker';
1445 }// end if
1447 // Wrap MIME-transformations. [MIME]
1448 $default_function = 'default_function'; // default_function
1449 $transform_function = $default_function;
1450 $transform_options = array();
1452 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1454 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1455 $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name]['transformation']);
1457 if (file_exists('./libraries/transformations/' . $include_file)) {
1458 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1460 require_once './libraries/transformations/' . $include_file;
1462 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1463 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1464 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1465 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1467 } // end if file_exists
1468 } // end if transformation is set
1469 } // end if mime/transformation works.
1471 $_url_params = array(
1472 'db' => $db,
1473 'table' => $table,
1474 'where_clause' => $where_clause,
1475 'transform_key' => $meta->name,
1478 if (! empty($sql_query)) {
1479 $_url_params['sql_query'] = $url_sql_query;
1482 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1484 // n u m e r i c
1485 if ($meta->numeric == 1) {
1487 // if two fields have the same name (this is possible
1488 // with self-join queries, for example), using $meta->name
1489 // will show both fields NULL even if only one is NULL,
1490 // so use the $pointer
1492 if (! isset($row[$i]) || is_null($row[$i])) {
1493 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1494 } elseif ($row[$i] != '') {
1496 $nowrap = ' nowrap';
1497 $where_comparison = ' = ' . $row[$i];
1499 $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);
1500 } else {
1501 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1504 // b l o b
1506 } elseif (stristr($meta->type, 'BLOB')) {
1507 // PMA_mysql_fetch_fields returns BLOB in place of
1508 // TEXT fields type so we have to ensure it's really a BLOB
1509 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1511 if (stristr($field_flags, 'BINARY')) {
1512 // remove 'grid_edit' from $class as we can't edit binary data.
1513 $class = str_replace('grid_edit', '', $class);
1515 if (! isset($row[$i]) || is_null($row[$i])) {
1516 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1517 } else {
1518 // for blobstreaming
1519 // if valid BS reference exists
1520 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1521 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1522 } else {
1523 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1526 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1527 unset($blobtext);
1529 // not binary:
1530 } else {
1531 if (! isset($row[$i]) || is_null($row[$i])) {
1532 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1533 } elseif ($row[$i] != '') {
1534 // if a transform function for blob is set, none of these replacements will be made
1535 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1536 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1537 $is_field_truncated = true;
1539 // displays all space characters, 4 space
1540 // characters for tabulations and <cr>/<lf>
1541 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1543 if ($is_field_truncated) {
1544 $class .= ' truncated';
1547 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1548 } else {
1549 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1552 // g e o m e t r y
1553 } elseif ($meta->type == 'geometry') {
1555 // Remove 'grid_edit' from $class as we do not allow to inline-edit geometry data.
1556 $class = str_replace('grid_edit', '', $class);
1558 if (! isset($row[$i]) || is_null($row[$i])) {
1559 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1560 } elseif ($row[$i] != '') {
1561 // Display as [GEOMETRY - (size)]
1562 if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
1563 $geometry_text = PMA_handle_non_printable_contents(
1564 'GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function,
1565 $transform_options, $default_function, $meta
1567 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
1568 $class, $condition_field, $geometry_text
1571 // Display in Well Known Text(WKT) format.
1572 } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
1573 // Convert to WKT format
1574 $wktval = PMA_asWKT($row[$i]);
1576 if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
1577 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1579 $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1580 $is_field_truncated = true;
1583 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1584 $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
1585 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1588 // Display in Well Known Binary(WKB) format.
1589 } else {
1590 if ($_SESSION['tmp_user_values']['display_binary']) {
1591 if ($_SESSION['tmp_user_values']['display_binary_as_hex']
1592 && PMA_contains_nonprintable_ascii($row[$i])
1594 $wkbval = PMA_substr(bin2hex($row[$i]), 8);
1595 } else {
1596 $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1599 if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
1600 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1602 $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1603 $is_field_truncated = true;
1606 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1607 $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
1608 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1610 } else {
1611 $wkbval = PMA_handle_non_printable_contents(
1612 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
1614 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
1617 } else {
1618 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1621 // n o t n u m e r i c a n d n o t B L O B
1622 } else {
1623 if (! isset($row[$i]) || is_null($row[$i])) {
1624 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1625 } elseif ($row[$i] != '') {
1626 // support blanks in the key
1627 $relation_id = $row[$i];
1629 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1630 // (unless it's a link-type transformation)
1631 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1632 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1633 $is_field_truncated = true;
1636 // displays special characters from binaries
1637 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1638 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1639 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1640 // some results of PROCEDURE ANALYSE() are reported as
1641 // being BINARY but they are quite readable,
1642 // so don't treat them as BINARY
1643 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1644 if ($_SESSION['tmp_user_values']['display_binary']) {
1645 // user asked to see the real contents of BINARY
1646 // fields
1647 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1648 $row[$i] = bin2hex($row[$i]);
1649 } else {
1650 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1652 } else {
1653 // we show the BINARY message and field's size
1654 // (or maybe use a transformation)
1655 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1659 // transform functions may enable no-wrapping:
1660 $function_nowrap = $transform_function . '_nowrap';
1661 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1663 // do not wrap if date field type
1664 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1665 $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
1666 $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);
1668 } else {
1669 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1673 // output stored cell
1674 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1675 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1676 echo $vertical_display['data'][$row_no][$i];
1679 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1680 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1681 } else {
1682 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1684 } // end for (2)
1686 // 3. Displays the modify/delete links on the right if required
1687 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1688 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1689 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1690 if (! isset($js_conf)) {
1691 $js_conf = '';
1693 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);
1694 } // end if (3)
1696 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1697 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1699 </tr>
1700 <?php
1701 } // end if
1703 // 4. Gather links of del_urls and edit_urls in an array for later
1704 // output
1705 if (! isset($vertical_display['edit'][$row_no])) {
1706 $vertical_display['edit'][$row_no] = '';
1707 $vertical_display['copy'][$row_no] = '';
1708 $vertical_display['delete'][$row_no] = '';
1709 $vertical_display['row_delete'][$row_no] = '';
1711 $vertical_class = ' row_' . $row_no;
1712 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1713 $vertical_class .= ' vpointer';
1715 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1716 $vertical_class .= ' vmarker';
1719 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1720 $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);
1721 } else {
1722 unset($vertical_display['row_delete'][$row_no]);
1725 if (isset($edit_url)) {
1726 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1727 } else {
1728 unset($vertical_display['edit'][$row_no]);
1731 if (isset($copy_url)) {
1732 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1733 } else {
1734 unset($vertical_display['copy'][$row_no]);
1737 if (isset($del_url)) {
1738 if (! isset($js_conf)) {
1739 $js_conf = '';
1741 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1742 } else {
1743 unset($vertical_display['delete'][$row_no]);
1746 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1747 $row_no++;
1748 } // end while
1750 // this is needed by PMA_displayTable() to generate the proper param
1751 // in the multi-edit and multi-delete form
1752 return $clause_is_unique;
1753 } // end of the 'PMA_displayTableBody()' function
1757 * Do display the result table with the vertical direction mode.
1759 * @return boolean always true
1761 * @global array $vertical_display the information to display
1763 * @access private
1765 * @see PMA_displayTable()
1767 function PMA_displayVerticalTable()
1769 global $vertical_display;
1771 // Displays "multi row delete" link at top if required
1772 if (($GLOBALS['cfg']['RowActionLinks'] != 'right')
1773 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1774 echo '<tr>' . "\n";
1775 if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1776 // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
1777 echo '<th></th>' . "\n";
1779 echo $vertical_display['textbtn'];
1780 $cell_displayed = 0;
1781 foreach ($vertical_display['row_delete'] as $val) {
1782 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1783 echo '<th' .
1784 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1785 '></th>' . "\n";
1787 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1788 $cell_displayed++;
1789 } // end while
1790 echo '</tr>' . "\n";
1791 } // end if
1793 // Displays "edit" link at top if required
1794 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1795 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1796 echo '<tr>' . "\n";
1797 if (! is_array($vertical_display['row_delete'])) {
1798 echo $vertical_display['textbtn'];
1800 foreach ($vertical_display['edit'] as $val) {
1801 echo $val;
1802 } // end while
1803 echo '</tr>' . "\n";
1804 } // end if
1806 // Displays "copy" link at top if required
1807 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1808 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1809 echo '<tr>' . "\n";
1810 if (! is_array($vertical_display['row_delete'])) {
1811 echo $vertical_display['textbtn'];
1813 foreach ($vertical_display['copy'] as $val) {
1814 echo $val;
1815 } // end while
1816 echo '</tr>' . "\n";
1817 } // end if
1819 // Displays "delete" link at top if required
1820 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1821 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1822 echo '<tr>' . "\n";
1823 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1824 echo $vertical_display['textbtn'];
1826 foreach ($vertical_display['delete'] as $val) {
1827 echo $val;
1828 } // end while
1829 echo '</tr>' . "\n";
1830 } // end if
1832 if (PMA_isSelect()) {
1833 // prepare to get the column order, if available
1834 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1835 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1836 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1837 } else {
1838 $col_order = false;
1839 $col_visib = false;
1842 // Displays data
1843 foreach ($vertical_display['desc'] AS $j => $val) {
1844 // assign appropriate key with current column order
1845 $key = $col_order ? $col_order[$j] : $j;
1847 echo '<tr' . (($col_visib && !$col_visib[$j]) ? ' class="hide"' : '') . '>' . "\n";
1848 echo $val;
1850 $cell_displayed = 0;
1851 foreach ($vertical_display['rowdata'][$key] as $subval) {
1852 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1853 echo $val;
1856 echo $subval;
1857 $cell_displayed++;
1858 } // end while
1860 echo '</tr>' . "\n";
1861 } // end while
1863 // Displays "multi row delete" link at bottom if required
1864 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1865 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1866 echo '<tr>' . "\n";
1867 echo $vertical_display['textbtn'];
1868 $cell_displayed = 0;
1869 foreach ($vertical_display['row_delete'] as $val) {
1870 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1871 echo '<th' .
1872 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1873 '></th>' . "\n";
1876 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1877 $cell_displayed++;
1878 } // end while
1879 echo '</tr>' . "\n";
1880 } // end if
1882 // Displays "edit" link at bottom if required
1883 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1884 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1885 echo '<tr>' . "\n";
1886 if (! is_array($vertical_display['row_delete'])) {
1887 echo $vertical_display['textbtn'];
1889 foreach ($vertical_display['edit'] as $val) {
1890 echo $val;
1891 } // end while
1892 echo '</tr>' . "\n";
1893 } // end if
1895 // Displays "copy" link at bottom if required
1896 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1897 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1898 echo '<tr>' . "\n";
1899 if (! is_array($vertical_display['row_delete'])) {
1900 echo $vertical_display['textbtn'];
1902 foreach ($vertical_display['copy'] as $val) {
1903 echo $val;
1904 } // end while
1905 echo '</tr>' . "\n";
1906 } // end if
1908 // Displays "delete" link at bottom if required
1909 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1910 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1911 echo '<tr>' . "\n";
1912 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1913 echo $vertical_display['textbtn'];
1915 foreach ($vertical_display['delete'] as $val) {
1916 echo $val;
1917 } // end while
1918 echo '</tr>' . "\n";
1921 return true;
1922 } // end of the 'PMA_displayVerticalTable' function
1926 * @todo make maximum remembered queries configurable
1927 * @todo move/split into SQL class!?
1928 * @todo currently this is called twice unnecessary
1929 * @todo ignore LIMIT and ORDER in query!?
1931 function PMA_displayTable_checkConfigParams()
1933 $sql_md5 = md5($GLOBALS['sql_query']);
1935 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1937 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1938 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1939 unset($_REQUEST['disp_direction']);
1940 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1941 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1944 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1945 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1946 unset($_REQUEST['repeat_cells']);
1947 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1948 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1951 // as this is a form value, the type is always string so we cannot
1952 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1953 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1954 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1955 || $_REQUEST['session_max_rows'] == 'all') {
1956 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1957 unset($_REQUEST['session_max_rows']);
1958 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1959 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1962 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1963 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1964 unset($_REQUEST['pos']);
1965 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1966 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1969 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1970 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1971 unset($_REQUEST['display_text']);
1972 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1973 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1976 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1977 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1978 unset($_REQUEST['relational_display']);
1979 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1980 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1983 if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
1984 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
1985 unset($_REQUEST['geometry_display']);
1986 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
1987 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
1990 if (isset($_REQUEST['display_binary'])) {
1991 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1992 unset($_REQUEST['display_binary']);
1993 } elseif (isset($_REQUEST['display_options_form'])) {
1994 // we know that the checkbox was unchecked
1995 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1996 } else {
1997 // selected by default because some operations like OPTIMIZE TABLE
1998 // and all queries involving functions return "binary" contents,
1999 // according to low-level field flags
2000 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
2003 if (isset($_REQUEST['display_binary_as_hex'])) {
2004 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2005 unset($_REQUEST['display_binary_as_hex']);
2006 } elseif (isset($_REQUEST['display_options_form'])) {
2007 // we know that the checkbox was unchecked
2008 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
2009 } else {
2010 // display_binary_as_hex config option
2011 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
2012 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2016 if (isset($_REQUEST['display_blob'])) {
2017 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
2018 unset($_REQUEST['display_blob']);
2019 } elseif (isset($_REQUEST['display_options_form'])) {
2020 // we know that the checkbox was unchecked
2021 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
2024 if (isset($_REQUEST['hide_transformation'])) {
2025 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
2026 unset($_REQUEST['hide_transformation']);
2027 } elseif (isset($_REQUEST['display_options_form'])) {
2028 // we know that the checkbox was unchecked
2029 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
2032 // move current query to the last position, to be removed last
2033 // so only least executed query will be removed if maximum remembered queries
2034 // limit is reached
2035 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
2036 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
2037 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
2039 // do not exceed a maximum number of queries to remember
2040 if (count($_SESSION['tmp_user_values']['query']) > 10) {
2041 array_shift($_SESSION['tmp_user_values']['query']);
2042 //echo 'deleting one element ...';
2045 // populate query configuration
2046 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
2047 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
2048 $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
2049 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
2050 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
2051 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
2052 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
2053 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
2054 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
2055 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
2056 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
2059 * debugging
2060 echo '<pre>';
2061 var_dump($_SESSION['tmp_user_values']);
2062 echo '</pre>';
2067 * Displays a table of results returned by a SQL query.
2068 * This function is called by the "sql.php" script.
2070 * @param integer the link id associated to the query which results have
2071 * to be displayed
2072 * @param array the display mode
2073 * @param array the analyzed query
2075 * @global string $db the database name
2076 * @global string $table the table name
2077 * @global string $goto the URL to go back in case of errors
2078 * @global string $sql_query the current SQL query
2079 * @global integer $num_rows the total number of rows returned by the
2080 * SQL query
2081 * @global integer $unlim_num_rows the total number of rows returned by the
2082 * SQL query without any programmatically
2083 * appended "LIMIT" clause
2084 * @global array $fields_meta the list of fields properties
2085 * @global integer $fields_cnt the total number of fields returned by
2086 * the SQL query
2087 * @global array $vertical_display informations used with vertical display
2088 * mode
2089 * @global array $highlight_columns column names to highlight
2090 * @global array $cfgRelation the relation settings
2092 * @access private
2094 * @see PMA_showMessage(), PMA_setDisplayMode(),
2095 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2096 * PMA_displayTableBody(), PMA_displayResultsOperations()
2098 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
2100 global $db, $table, $goto;
2101 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
2102 global $vertical_display, $highlight_columns;
2103 global $cfgRelation;
2104 global $showtable;
2106 // why was this called here? (already called from sql.php)
2107 //PMA_displayTable_checkConfigParams();
2110 * @todo move this to a central place
2111 * @todo for other future table types
2113 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
2115 if ($is_innodb
2116 && ! isset($analyzed_sql[0]['queryflags']['union'])
2117 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
2118 && (empty($analyzed_sql[0]['where_clause'])
2119 || $analyzed_sql[0]['where_clause'] == '1 ')) {
2120 // "j u s t b r o w s i n g"
2121 $pre_count = '~';
2122 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')));
2123 } else {
2124 $pre_count = '';
2125 $after_count = '';
2128 // 1. ----- Prepares the work -----
2130 // 1.1 Gets the informations about which functionalities should be
2131 // displayed
2132 $total = '';
2133 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
2135 // 1.2 Defines offsets for the next and previous pages
2136 if ($is_display['nav_bar'] == '1') {
2137 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
2138 $pos_next = 0;
2139 $pos_prev = 0;
2140 } else {
2141 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
2142 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
2143 if ($pos_prev < 0) {
2144 $pos_prev = 0;
2147 } // end if
2149 // 1.3 Find the sort expression
2151 // we need $sort_expression and $sort_expression_nodirection
2152 // even if there are many table references
2153 if (! empty($analyzed_sql[0]['order_by_clause'])) {
2154 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
2156 * Get rid of ASC|DESC
2158 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
2159 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
2160 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
2161 unset($matches);
2162 } else {
2163 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
2166 // 1.4 Prepares display of first and last value of the sorted column
2168 if (! empty($sort_expression_nodirection)) {
2169 if (strpos($sort_expression_nodirection, '.') === false) {
2170 $sort_table = $table;
2171 $sort_column = $sort_expression_nodirection;
2172 } else {
2173 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
2175 $sort_table = PMA_unQuote($sort_table);
2176 $sort_column = PMA_unQuote($sort_column);
2177 // find the sorted column index in row result
2178 // (this might be a multi-table query)
2179 $sorted_column_index = false;
2180 foreach ($fields_meta as $key => $meta) {
2181 if ($meta->table == $sort_table && $meta->name == $sort_column) {
2182 $sorted_column_index = $key;
2183 break;
2186 if ($sorted_column_index !== false) {
2187 // fetch first row of the result set
2188 $row = PMA_DBI_fetch_row($dt_result);
2189 // initializing default arguments
2190 $default_function = 'default_function';
2191 $transform_function = $default_function;
2192 $transform_options = array();
2193 // check for non printable sorted row data
2194 $meta = $fields_meta[$sorted_column_index];
2195 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2196 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2197 } else {
2198 $column_for_first_row = $row[$sorted_column_index];
2200 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2201 // fetch last row of the result set
2202 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2203 $row = PMA_DBI_fetch_row($dt_result);
2204 // check for non printable sorted row data
2205 $meta = $fields_meta[$sorted_column_index];
2206 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2207 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2208 } else {
2209 $column_for_last_row = $row[$sorted_column_index];
2211 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2212 // reset to first row for the loop in PMA_displayTableBody()
2213 PMA_DBI_data_seek($dt_result, 0);
2214 // we could also use here $sort_expression_nodirection
2215 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2216 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2218 unset($sorted_column_index, $sort_table, $sort_column);
2221 // 2. ----- Displays the top of the page -----
2223 // 2.1 Displays a messages with position informations
2224 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2225 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2226 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2227 } else {
2228 $selectstring = '';
2230 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
2231 ? $total - 1
2232 : $pos_next - 1;
2234 if (PMA_Table::isView($db, $table)
2235 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2236 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2237 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2238 $message->addParam('[/a]');
2239 $message_view_warning = PMA_showHint($message);
2240 } else {
2241 $message_view_warning = false;
2244 $message = PMA_Message::success(__('Showing rows'));
2245 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2246 if ($message_view_warning) {
2247 $message->addMessage('...', ' - ');
2248 $message->addMessage($message_view_warning);
2249 $message->addMessage('(');
2250 } else {
2251 $message->addMessage($last_shown_rec, ' - ');
2252 $message->addMessage(' (');
2253 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2254 $message->addString(__('total'));
2255 if (!empty($after_count)) {
2256 $message->addMessage($after_count);
2258 $message->addMessage($selectstring, '');
2259 $message->addMessage(', ', '');
2262 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2263 $messagge_qt->addParam($GLOBALS['querytime']);
2265 $message->addMessage($messagge_qt, '');
2266 $message->addMessage(')', '');
2268 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2270 PMA_showMessage($message, $sql_query, 'success');
2272 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2273 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2276 // 2.3 Displays the navigation bars
2277 if (! strlen($table)) {
2278 if (isset($analyzed_sql[0]['query_type'])
2279 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2280 // table does not always contain a real table name,
2281 // for example in MySQL 5.0.x, the query SHOW STATUS
2282 // returns STATUS as a table name
2283 $table = $fields_meta[0]->table;
2284 } else {
2285 $table = '';
2289 if ($is_display['nav_bar'] == '1') {
2290 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2291 echo "\n";
2292 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2293 echo "\n" . '<br /><br />' . "\n";
2296 // 2b ----- Get field references from Database -----
2297 // (see the 'relation' configuration variable)
2299 // initialize map
2300 $map = array();
2302 // find tables
2303 $target=array();
2304 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2305 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2306 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2309 $tabs = '(\'' . join('\',\'', $target) . '\')';
2311 if (! strlen($table)) {
2312 $exist_rel = false;
2313 } else {
2314 // To be able to later display a link to the related table,
2315 // we verify both types of relations: either those that are
2316 // native foreign keys or those defined in the phpMyAdmin
2317 // configuration storage. If no PMA storage, we won't be able
2318 // to use the "column to display" notion (for example show
2319 // the name related to a numeric id).
2320 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2321 if ($exist_rel) {
2322 foreach ($exist_rel AS $master_field => $rel) {
2323 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2324 $map[$master_field] = array($rel['foreign_table'],
2325 $rel['foreign_field'],
2326 $display_field,
2327 $rel['foreign_db']);
2328 } // end while
2329 } // end if
2330 } // end if
2331 // end 2b
2333 // 3. ----- Displays the results table -----
2334 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2335 $url_query = '';
2336 echo '<tbody>' . "\n";
2337 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2338 // vertical output case
2339 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2340 PMA_displayVerticalTable();
2341 } // end if
2342 unset($vertical_display);
2343 echo '</tbody>' . "\n";
2345 </table>
2347 <?php
2348 // 4. ----- Displays the link for multi-fields edit and delete
2350 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2352 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2354 $_url_params = array(
2355 'db' => $db,
2356 'table' => $table,
2357 'sql_query' => $sql_query,
2358 'goto' => $goto,
2360 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2362 $_url_params['checkall'] = '1';
2363 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2365 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2366 $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
2367 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
2368 } else {
2369 $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
2370 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
2372 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2373 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2374 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2375 echo '<img class="selectallarrow" width="38" height="22"'
2376 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2377 .' alt="' . __('With selected:') . '" />';
2379 echo $checkall_link . "\n"
2380 .' / ' . "\n"
2381 .$uncheckall_link . "\n"
2382 .'<i>' . __('With selected:') . '</i>' . "\n";
2384 PMA_buttonOrImage('submit_mult', 'mult_submit',
2385 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2386 PMA_buttonOrImage('submit_mult', 'mult_submit',
2387 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2388 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2389 PMA_buttonOrImage('submit_mult', 'mult_submit',
2390 'submit_mult_export', __('Export'),
2391 'b_tblexport.png', 'export');
2393 echo "\n";
2395 echo '<input type="hidden" name="sql_query"'
2396 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2398 if (! empty($GLOBALS['url_query'])) {
2399 echo '<input type="hidden" name="url_query"'
2400 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2403 echo '<input type="hidden" name="clause_is_unique"'
2404 .' value="' . $clause_is_unique . '" />' . "\n";
2406 echo '</form>' . "\n";
2409 // 5. ----- Displays the navigation bar at the bottom if required -----
2411 if ($is_display['nav_bar'] == '1') {
2412 echo '<br />' . "\n";
2413 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2414 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2415 echo "\n" . '<br /><br />' . "\n";
2418 // 6. ----- Displays "Query results operations"
2419 if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2420 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2422 } // end of the 'PMA_displayTable()' function
2424 function default_function($buffer)
2426 $buffer = htmlspecialchars($buffer);
2427 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2428 str_replace(' ', ' &nbsp;', $buffer));
2429 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2431 return $buffer;
2435 * Displays operations that are available on results.
2437 * @param array the display mode
2438 * @param array the analyzed query
2440 * @global string $db the database name
2441 * @global string $table the table name
2442 * @global string $sql_query the current SQL query
2443 * @global integer $unlim_num_rows the total number of rows returned by the
2444 * SQL query without any programmatically
2445 * appended "LIMIT" clause
2447 * @access private
2449 * @see PMA_showMessage(), PMA_setDisplayMode(),
2450 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2451 * PMA_displayTableBody(), PMA_displayResultsOperations()
2453 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql)
2455 global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
2457 $header_shown = false;
2458 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2460 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2461 // Displays "printable view" link if required
2462 if ($the_disp_mode[9] == '1') {
2464 if (!$header_shown) {
2465 echo $header;
2466 $header_shown = true;
2469 $_url_params = array(
2470 'db' => $db,
2471 'table' => $table,
2472 'printview' => '1',
2473 'sql_query' => $sql_query,
2475 $url_query = PMA_generate_common_url($_url_params);
2477 echo PMA_linkOrButton(
2478 'sql.php' . $url_query,
2479 PMA_getIcon('b_print.png', __('Print view')),
2480 '', true, true, 'print_view') . "\n";
2482 if ($_SESSION['tmp_user_values']['display_text']) {
2483 $_url_params['display_text'] = 'F';
2484 echo PMA_linkOrButton(
2485 'sql.php' . PMA_generate_common_url($_url_params),
2486 PMA_getIcon('b_print.png', __('Print view (with full texts)')),
2487 '', true, true, 'print_view') . "\n";
2488 unset($_url_params['display_text']);
2490 } // end displays "printable view"
2493 // Export link
2494 // (the url_query has extra parameters that won't be used to export)
2495 // (the single_table parameter is used in display_export.lib.php
2496 // to hide the SQL and the structure export dialogs)
2497 // If the parser found a PROCEDURE clause
2498 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2499 // display the Export link).
2500 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2501 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2502 $_url_params['single_table'] = 'true';
2504 if (!$header_shown) {
2505 echo $header;
2506 $header_shown = true;
2508 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2511 * At this point we don't know the table name; this can happen
2512 * for example with a query like
2513 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2514 * As a workaround we set in the table parameter the name of the
2515 * first table of this database, so that tbl_export.php and
2516 * the script it calls do not fail
2518 if (empty($_url_params['table']) && !empty($_url_params['db'])) {
2519 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2520 /* No result (probably no database selected) */
2521 if ($_url_params['table'] === FALSE) {
2522 unset($_url_params['table']);
2526 echo PMA_linkOrButton(
2527 'tbl_export.php' . PMA_generate_common_url($_url_params),
2528 PMA_getIcon('b_tblexport.png', __('Export')),
2529 '', true, true, '') . "\n";
2531 // show chart
2532 echo PMA_linkOrButton(
2533 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2534 PMA_getIcon('b_chart.png', __('Display chart')),
2535 '', true, true, '') . "\n";
2537 // show GIS chart
2538 $geometry_found = false;
2539 // If atleast one geometry field is found
2540 foreach ($fields_meta as $meta) {
2541 if ($meta->type == 'geometry') {
2542 $geometry_found = true;
2543 break;
2546 if ($geometry_found) {
2547 echo PMA_linkOrButton(
2548 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
2549 PMA_getIcon('b_globe.gif', __('Visualize GIS data')),
2550 '', true, true, '') . "\n";
2554 // CREATE VIEW
2557 * @todo detect privileges to create a view
2558 * (but see 2006-01-19 note in display_create_table.lib.php,
2559 * I think we cannot detect db-specific privileges reliably)
2560 * Note: we don't display a Create view link if we found a PROCEDURE clause
2562 if (!$header_shown) {
2563 echo $header;
2564 $header_shown = true;
2566 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2567 echo PMA_linkOrButton(
2568 'view_create.php' . $url_query,
2569 PMA_getIcon('b_views.png', __('Create view')),
2570 '', true, true, '') . "\n";
2572 if ($header_shown) {
2573 echo '</fieldset><br />';
2578 * Verifies what to do with non-printable contents (binary or BLOB)
2579 * in Browse mode.
2581 * @param string $category BLOB|BINARY|GEOMETRY
2582 * @param string $content the binary content
2583 * @param string $transform_function transformation function
2584 * @param string $transform_options transformation parameters
2585 * @param string $default_function default transformation function
2586 * @param object $meta the meta-information about this field
2587 * @return mixed string or float
2589 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array())
2591 $result = '[' . $category;
2592 if (is_null($content)) {
2593 $result .= ' - NULL';
2594 $size = 0;
2595 } elseif (isset($content)) {
2596 $size = strlen($content);
2597 $display_size = PMA_formatByteDown($size, 3, 1);
2598 $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
2600 $result .= ']';
2602 if (strpos($transform_function, 'octetstream')) {
2603 $result = $content;
2605 if ($size > 0) {
2606 if ($default_function != $transform_function) {
2607 $result = $transform_function($result, $transform_options, $meta);
2608 } else {
2609 $result = $default_function($result, array(), $meta);
2610 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2611 // in this case, restart from the original $content
2612 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2614 /* Create link to download */
2615 if (count($url_params) > 0) {
2616 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2620 return($result);
2624 * Prepares the displayable content of a data cell in Browse mode,
2625 * taking into account foreign key description field and transformations
2627 * @param string $class
2628 * @param string $condition_field
2629 * @param string $analyzed_sql
2630 * @param object $meta the meta-information about this field
2631 * @param string $map
2632 * @param string $data
2633 * @param string $transform_function
2634 * @param string $default_function
2635 * @param string $nowrap
2636 * @param string $where_comparison
2637 * @param bool $is_field_truncated
2638 * @return string formatted data
2640 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 )
2643 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2645 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2646 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2647 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2648 if (isset($alias) && strlen($alias)) {
2649 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2650 if ($alias == $meta->name) {
2651 // this change in the parameter does not matter
2652 // outside of the function
2653 $meta->name = $true_column;
2654 } // end if
2655 } // end if
2656 } // end foreach
2657 } // end if
2659 if (isset($map[$meta->name])) {
2660 // Field to display from the foreign table?
2661 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2662 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2663 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2664 . '.' . PMA_backquote($map[$meta->name][0])
2665 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2666 . $where_comparison;
2667 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2668 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2669 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2670 } else {
2671 $dispval = __('Link not found');
2673 @PMA_DBI_free_result($dispresult);
2674 } else {
2675 $dispval = '';
2676 } // end if... else...
2678 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2679 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2680 } else {
2682 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2683 // user chose "relational key" in the display options, so
2684 // the title contains the display field
2685 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2686 } else {
2687 $title = ' title="' . htmlspecialchars($data) . '"';
2690 $_url_params = array(
2691 'db' => $map[$meta->name][3],
2692 'table' => $map[$meta->name][0],
2693 'pos' => '0',
2694 'sql_query' => 'SELECT * FROM '
2695 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2696 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2697 . $where_comparison,
2699 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2700 . '"' . $title . '>';
2702 if ($transform_function != $default_function) {
2703 // always apply a transformation on the real data,
2704 // not on the display field
2705 $result .= $transform_function($data, $transform_options, $meta);
2706 } else {
2707 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2708 // user chose "relational display field" in the
2709 // display options, so show display field in the cell
2710 $result .= $transform_function($dispval, array(), $meta);
2711 } else {
2712 // otherwise display data in the cell
2713 $result .= $transform_function($data, array(), $meta);
2716 $result .= '</a>';
2718 } else {
2719 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2721 $result .= '</td>' . "\n";
2723 return $result;
2727 * Generates a checkbox for multi-row submits
2729 * @param string $del_url
2730 * @param array $is_display
2731 * @param string $row_no
2732 * @param string $where_clause_html
2733 * @param string $del_query
2734 * @param string $id_suffix
2735 * @param string $class
2736 * @return string the generated HTML
2739 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix, $class)
2741 $ret = '';
2742 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2743 $ret .= '<td ';
2744 if (! empty($class)) {
2745 $ret .= 'class="' . $class . '"';
2747 $ret .= ' align="center">'
2748 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2749 . ' class="multi_checkbox"'
2750 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2751 . '<input type="hidden" class="condition_array" value="' . htmlspecialchars(json_encode($condition_array)) . '" />'
2752 . ' </td>';
2754 return $ret;
2758 * Generates an Edit link
2760 * @param string $edit_url
2761 * @param string $class
2762 * @param string $edit_str
2763 * @param string $where_clause
2764 * @param string $where_clause_html
2765 * @return string the generated HTML
2767 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html)
2769 $ret = '';
2770 if (! empty($edit_url)) {
2771 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2772 . PMA_linkOrButton($edit_url, $edit_str, array(), false);
2774 * Where clause for selecting this row uniquely is provided as
2775 * a hidden input. Used by jQuery scripts for handling grid editing
2777 if (! empty($where_clause)) {
2778 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2780 $ret .= '</span></td>';
2782 return $ret;
2786 * Generates an Copy link
2788 * @param string $copy_url
2789 * @param string $copy_str
2790 * @param string $where_clause
2791 * @param string $where_clause_html
2792 * @return string the generated HTML
2794 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class)
2796 $ret = '';
2797 if (! empty($copy_url)) {
2798 $ret .= '<td ';
2799 if (! empty($class)) {
2800 $ret .= 'class="' . $class . '" ';
2802 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2803 . PMA_linkOrButton($copy_url, $copy_str, array(), false);
2805 * Where clause for selecting this row uniquely is provided as
2806 * a hidden input. Used by jQuery scripts for handling grid editing
2808 if (! empty($where_clause)) {
2809 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2811 $ret .= '</span></td>';
2813 return $ret;
2817 * Generates a Delete link
2819 * @param string $del_url
2820 * @param string $del_str
2821 * @param string $js_conf
2822 * @param string $class
2823 * @return string the generated HTML
2825 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class)
2827 $ret = '';
2828 if (! empty($del_url)) {
2829 $ret .= '<td ';
2830 if (! empty($class)) {
2831 $ret .= 'class="' . $class . '" ';
2833 $ret .= 'align="center" ' . ' >'
2834 . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
2835 . '</td>';
2837 return $ret;
2841 * Generates checkbox and links at some position (left or right)
2842 * (only called for horizontal mode)
2844 * @param string $position
2845 * @param string $del_url
2846 * @param array $is_display
2847 * @param string $row_no
2848 * @param string $where_clause
2849 * @param string $where_clause_html
2850 * @param string $del_query
2851 * @param string $id_suffix
2852 * @param string $edit_url
2853 * @param string $copy_url
2854 * @param string $class
2855 * @param string $edit_str
2856 * @param string $del_str
2857 * @param string $js_conf
2858 * @return string the generated HTML
2860 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)
2862 $ret = '';
2864 if ($position == 'left') {
2865 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix='_left', '', '', '');
2867 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2869 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2871 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2873 } elseif ($position == 'right') {
2874 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2876 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2878 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2880 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix='_right', '', '', '');
2881 } else { // $position == 'none'
2882 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix='_left', '', '', '');
2884 return $ret;